Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

I want lern how make plugins.

Comments in 'Plugin Development' started by michal16, Nov 25, 2013.

Thread Status:
Not open for further replies.
  1. michal16
    Offline

    michal16 New Member

    Joined:
    Aug 27, 2013
    Posts:
    26
    Minecraft User:
    mister_magister
    Hi! I want lern how make plugins. On the pocketmine.net is API but not all. Can you show me full API and how use it and how make plugins?

    I want make plugin to protect area against pvp, build, and chest access. Commands:
    /protect (pos1|pos2) [nick]
    /flag [chest|build|pvp]
    /expand [up] [down]

    I know this look like privateareaprotector and Areaugard but i need it.

    Let's start:
    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=ProtectPlugin
    version=0.0.1
    author=michal16
    class=protect
    apiversion=10
    */

    class ExamplePlugin implements Plugin{
        private 
    $api;
        private 
    $user;
        private 
    $pos1;
        private 
    $pos2;
        private 
    $player;
        public function 
    __construct(ServerAPI $api$server false){
            
    $this->api $api;
        }
       
        public function 
    init(){
            
    $this->api->console->register("protect""Protect", array($this"handleCommand"));
        }
       
        public function 
    __destruct(){
       
        }
       
        public function 
    handleCommand($cmd$arg){
            
    $player =$issuer->nickname;
            switch(
    $cmd){
                case 
    "protect":
                    
    $this->user =$arg;
                    
    $mode =array_shift($arg);
                    switch(
    $mode){
                        case 
    "pos1":
                            
    pos1[$user] = //how get coordinates of $player?
                        
    break;
                        case 
    "pos2":
                            
    pos2[$user] = //the same
                        
    break;
                        default:
                            
    console("area "pos1[$user], pos2[$user]);
                    break;
            }
        }

    }
  2. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    That is pretty complicated for your first plugin :)
  3. michal16
    Offline

    michal16 New Member

    Joined:
    Aug 27, 2013
    Posts:
    26
    Minecraft User:
    mister_magister
    so what i have to make for first plugin? fan you give me example?
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Maybe a command which sends the player a message
  5. michal16
    Offline

    michal16 New Member

    Joined:
    Aug 27, 2013
    Posts:
    26
    Minecraft User:
    mister_magister
    This is easy
    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=ProtectPlugin
    version=0.0.1
    author=michal16
    class=protect
    apiversion=10
    */

    class ExamplePlugin implements Plugin{
        private 
    $api;
        private 
    $user;
        public function 
    __construct(ServerAPI $api$server false){
            
    $this->api $api;
        }
     
        public function 
    init(){
            
    $this->api->console->register("hi""Hi player", array($this"handleCommand"));
        }
     
        public function 
    __destruct(){
     
        }
     
        public function 
    handleCommand($cmd$prm){
            
    $this->user =array_shift($prm);
            switch(
    $cmd){
                case 
    "hi":
                            
    sendTo(console,"Hi "$user$prm);
                    break;
            }
        }
    }
  6. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    But you got it wrong :)
    The easiest way to send a message in a command is by using the player object:
    PHP:
    $issuer->sendChat("Example");
    You could also use sendTo but that takes up more space and is called by:
    PHP:
    $this->api->chat->sendTo(*What you put above*);
    michal16 likes this.
  7. michal16
    Offline

    michal16 New Member

    Joined:
    Aug 27, 2013
    Posts:
    26
    Minecraft User:
    mister_magister
    Ok thanks. Next challenge please ;)
    Falk likes this.
  8. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Block use of the chat, pretty easy but requires use of event handling
  9. michal16
    Offline

    michal16 New Member

    Joined:
    Aug 27, 2013
    Posts:
    26
    Minecraft User:
    mister_magister
    I don't understand. Block use of the chat
  10. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Whenever someone sends a chat message nothing will happen. So like muting everyone.
  11. JassperBeastHD
    Offline

    JassperBeastHD Banned

    Joined:
    Aug 27, 2013
    Posts:
    436
    Minecraft User:
    JassperBeastHD
    $issuer->disableChat = true; easy but neeed more code improvement
  12. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    That isn't part of the player object.
  13. JassperBeastHD
    Offline

    JassperBeastHD Banned

    Joined:
    Aug 27, 2013
    Posts:
    436
    Minecraft User:
    JassperBeastHD
    If you change src xD
  14. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Yes, but plugins shouldn't change the src
  15. JassperBeastHD
    Offline

    JassperBeastHD Banned

    Joined:
    Aug 27, 2013
    Posts:
    436
    Minecraft User:
    JassperBeastHD
    LoL okay whats your method o.o
  16. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Get every player and then send to everyone who has the chat not disabled, what I was asking as a challenge though was a lot simpler.
  17. JassperBeastHD
    Offline

    JassperBeastHD Banned

    Joined:
    Aug 27, 2013
    Posts:
    436
    Minecraft User:
    JassperBeastHD
    Your talking about muting a player so they cant talk, But im saying that Your Player or You disablet your chat(you cant chat & you cant recieve chat) thats what i ment ur talking about something else
  18. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    No, I am telling you how I would accomplish what you are talking about. My challenge was to prevent cheating though.
  19. JassperBeastHD
    Offline

    JassperBeastHD Banned

    Joined:
    Aug 27, 2013
    Posts:
    436
    Minecraft User:
    JassperBeastHD
    Your challenge was blockingnsomeone chating
  20. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Yes
Thread Status:
Not open for further replies.

Share This Page

Advertisement