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

[Old API] [Tutorial] Plugin Making Section 2

Comments in 'Plugin Development' started by Glitchmaster_PE, Nov 12, 2013.

?

Like the second part?

  1. Yes

    40 vote(s)
    93.0%
  2. No

    3 vote(s)
    7.0%
  1. Glitchmaster_PE
    Offline

    Glitchmaster_PE Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    834
    Plugins:
    8
    Minecraft User:
    Glitchmaster_PE
    This second part of my plugin tutorial will focus mainly on some key functions and handlers other than the basic format of the plugin! You can get all the functions to use here. Like if you enjoy, and here we go:

    Part 3:

    This will focus on some other important functions. Here are the functions I will go over: ban, kick, broadcast, alias and run.

    Ban:

    This is used to ban a user. So let's say you own a server where you ban any one who asks for OP. You would use this function:

    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=OPMe
    version=1.0
    description=Bans people asking for OP!
    author=YOU!
    class=OP
    apiversion=10
    */

    class OP implements Plugin{

    private 
    $api;

    public function 
    __construct(ServerAPI $api$server false){
    $this->api $api;
    }

    public function 
    init(){
    $this->api->console->register("opme","OPs you!",array($this"OPMe"));
    $this->api->ban->cmdWhitelist("opme");
    }

    public function 
    OPMe($cmd$issuer){
    $this->api->ban->ban($issuer);
    }

    public function 
    __destruct(){
    }
    }
    ?>
    The only thing I added that you should not know, is the $this->api->ban->ban($issuer); . This function will ban the user inside the parenthesizes.

    Kick:

    You can use this function to kick a user. So let's say you want to kick any user asking for OP, but not ban them. You would do this:

    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=OPMe
    version=1.0
    description=Kicks people asking for OP!
    author=YOU!
    class=OP
    apiversion=10
    */

    class OP implements Plugin{

    private 
    $api;

    public function 
    __construct(ServerAPI $api$server false){
    $this->api $api;
    }

    public function 
    init(){
    $this->api->console->register("opme","OPs you!",array($this"OPMe"));
    $this->api->ban->cmdWhitelist("opme");
    }

    public function 
    OPMe($cmd$issuer){
    $this->api->ban->kick($issuer,"Asking for OP!!!!!");
    }

    public function 
    __destruct(){
    }
    }
    ?>
    Ok, so this time the function you don't know is: $this->api->ban->kick($issuer,"Asking for OP!!!!!"); . You will notice the second parameter (Asking for OP!!!!!) this is the reason for kicking the player, if left blank, the player will be kicked for "No Reason".

    Broadcast:

    This function broadcasts a message to a server. Let's say for instance you want to embarrass someone asking for OP, here is what you would do:

    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=OPMe
    version=1.0
    description=Embarrasses people asking for OP!
    author=YOU!
    class=OP
    apiversion=10
    */

    class OP implements Plugin{

    private 
    $api;

    public function 
    __construct(ServerAPI $api$server false){
    $this->api $api;
    }

    public function 
    init(){
    $this->api->console->register("opme","OPs you!",array($this"OPMe"));
    $this->api->ban->cmdWhitelist("opme");
    }

    public function 
    OPMe($cmd$issuer){
    $this->api->chat->broadcast($issuer " is desperate and is asking for OP! XD!!!");
    }

    public function 
    __destruct(){
    }
    }
    ?>

    That will broadcast a message throughout the server saying "User is desperate and is asking for OP! XD!!!". You will notice a put a period between $issuer and the string, you must do this whenever separating strings.

    Alias:

    Alias is used to call a command by another name. This can be useful if you have a long command and want to make it shorter. You would do:

    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=HelloWorld
    version=1.0
    description=Says Hello World in two commands!
    author=YOU!
    class=Hello
    apiversion=10
    */

    class Hello implements Plugin{
    private 
    $api;

    public function 
    __construct(ServerAPI $api$server false){
    $this->api $api;
    }

    public function 
    init(){
    $this->api->console->register("hello","Broadcasts Hello World!",array($this"Hello");
    $this->api->ban->cmdWhitelist("hello");
    $this->api->console->alias("hi","hello");
    }

    public function 
    Hello($cmd$issuer){
    $this->api->chat->broadcast("Hello World!");
    }

    public function 
    __desctruct(){
    }
    }
    ?>


    I added one thing in this, $this->api->console->alias("hi","hello"); . This makes it so you can get the same results when doing /hello as you would in doing /hi.

    Run:

    This is one of my favorites, this is the run function. You can use to run any command whenever the command is done! Here is an example. Let's say you are a nicer owner than all those others, and you just want to kill a player for asking for OP, here is how:

    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=OPMe
    version=1.0
    description=Kills people asking for OP!
    author=YOU!
    class=OP
    apiversion=10
    */

    class OP implements Plugin{

    private 
    $api;

    public function 
    __construct(ServerAPI $api$server false){
    $this->api $api;
    }

    public function 
    init(){
    $this->api->console->register("opme","OPs you!",array($this"OPMe"));
    $this->api->ban->cmdWhitelist("opme");
    }

    public function 
    OPMe($cmd$issuer){
    $username $issuer->username;
    $this->api->console->run("kill " $username);
    }

    public function 
    __destruct(){
    }
    }
    ?>
    You will notice that I did $issuer->username = $username; and then used $username to kill the player. This is because when you do the /kill command, the next argument/parameter is the players username, not just them. Also, I did not put a "/" before the kill command, this is because the commands are run as if the person doing them is the console, and you do not put a "/" before console commands.

    I will start talking about Handlers soon :)
    Last edited: Nov 27, 2013
  2. alkurian
    Offline

    alkurian New Member

    Joined:
    Oct 15, 2013
    Posts:
    21
    Minecraft User:
    LaVerge
    i love it lol
  3. Glitchmaster_PE
    Offline

    Glitchmaster_PE Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    834
    Plugins:
    8
    Minecraft User:
    Glitchmaster_PE
    not done yet, but maybe today :)
    egg and Syriamanal like this.
  4. Syriamanal
    Offline

    Syriamanal Ban Evader Banned

    Joined:
    Oct 2, 2013
    Posts:
    221
    Minecraft User:
    Syriamanal
    do everything you know i just learnt more thanks:p
  5. Glitchmaster_PE
    Offline

    Glitchmaster_PE Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    834
    Plugins:
    8
    Minecraft User:
    Glitchmaster_PE
    Updated main post
  6. Ilia_plav
    Offline

    Ilia_plav New Member Plugin Developer

    Joined:
    Nov 9, 2013
    Posts:
    19
    Plugins:
    1
    Minecraft User:
    Ilia_plav
    Thinks !
    You did VERY GOOD MANUAL
    It VERY NEEd for people,for me too :)
  7. alkurian
    Offline

    alkurian New Member

    Joined:
    Oct 15, 2013
    Posts:
    21
    Minecraft User:
    LaVerge
    sad to see someone took the example and submitted as thier own

    is it evil i get a kick out of opme everytime is see it?
  8. JassperBeastHD
    Offline

    JassperBeastHD Banned

    Joined:
    Aug 27, 2013
    Posts:
    436
    Minecraft User:
    JassperBeastHD
    The /opme is from me -.- but nice tutorial thoe Awesome :)
  9. Glitchmaster_PE
    Offline

    Glitchmaster_PE Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    834
    Plugins:
    8
    Minecraft User:
    Glitchmaster_PE
    btw, I did not take any example code from you, I just used your OPMe idea for my tutorial ;) Thanks though!
  10. Glitchmaster_PE
    Offline

    Glitchmaster_PE Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    834
    Plugins:
    8
    Minecraft User:
    Glitchmaster_PE
    I updated main post
  11. JassperBeastHD
    Offline

    JassperBeastHD Banned

    Joined:
    Aug 27, 2013
    Posts:
    436
    Minecraft User:
    JassperBeastHD
    I dont care;) and another nice awesome tutorial
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    A better way to do this is event("player.chat") and if the message contains "op me".
  13. Glitchmaster_PE
    Offline

    Glitchmaster_PE Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    834
    Plugins:
    8
    Minecraft User:
    Glitchmaster_PE
    Yes, but I am demonstrating different functions, not the best way to do the "OP Me" plugin :p
    PEMapModder likes this.
  14. JassperBeastHD
    Offline

    JassperBeastHD Banned

    Joined:
    Aug 27, 2013
    Posts:
    436
    Minecraft User:
    JassperBeastHD
    I updated opme(2.0) and it has player.chat thanks To FALK
  15. Syriamanal
    Offline

    Syriamanal Ban Evader Banned

    Joined:
    Oct 2, 2013
    Posts:
    221
    Minecraft User:
    Syriamanal
    can i do this llol pleas tell me $this->api->ban->op();
  16. Glitchmaster_PE
    Offline

    Glitchmaster_PE Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    834
    Plugins:
    8
    Minecraft User:
    Glitchmaster_PE
    I don't think so
  17. Syriamanal
    Offline

    Syriamanal Ban Evader Banned

    Joined:
    Oct 2, 2013
    Posts:
    221
    Minecraft User:
    Syriamanal
    How about this $this->api->ban->isop(@user);
  18. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    754
    Plugins:
    2
    Minecraft User:
    Darunia18
    I've been reading through different plugins' code and I keep seeing "handlers", but I kind of have no idea what they are and how they work. Are you going to be updating this soon to explain that more? And thank you for your tutorials. They're really starting to make all of this make sense to me :D
  19. Glitchmaster_PE
    Offline

    Glitchmaster_PE Notable Member Plugin Developer

    Joined:
    Aug 31, 2013
    Posts:
    834
    Plugins:
    8
    Minecraft User:
    Glitchmaster_PE
    That is the goal of it :D I may add handlers soon, I just need some time ;)
  20. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    754
    Plugins:
    2
    Minecraft User:
    Darunia18
    Quick response! :D I'm looking forward to it. When I first read through the tutorial, it didn't make much sense. Then I started to try to write a simple, but different, plugin next to it and trying to see what things would be necessary and how it would work with my own plugin, and it started making sense! :D

Share This Page

Advertisement