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. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    opme?
  2. -elfin-
    Offline

    -elfin- New Member

    Joined:
    Mar 19, 2014
    Posts:
    29
    Minecraft User:
    elfin_ARC
    <?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(){
    }
    }
    ?>

    I copied that, still not working...
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Never make the class name two characters.
    jython234 likes this.
  4. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    Paste the entire server log.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Your problem is, OPMe(...) has a problem. Follow the example. You should put three parameters for that function. Also, that function name can be everything as long as the callable (array($this, "xxxx")) = the function name (public function xxxx(...){...})
  6. -elfin-
    Offline

    -elfin- New Member

    Joined:
    Mar 19, 2014
    Posts:
    29
    Minecraft User:
    elfin_ARC
    Umm... What you mean?
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Class names are unique in PHP code. If it is too short, there is a high risk of duplication. If everyone does that, there are at most 676 combinations only, which means you have 1/676 chance of duplicating, which is a high value.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Like, if someone makes an opme plugin, then another makes an IP op plugin, if they use the same class name (OP), it will create an error "cannot redeclare class "op"".
  9. -elfin-
    Offline

    -elfin- New Member

    Joined:
    Mar 19, 2014
    Posts:
    29
    Minecraft User:
    elfin_ARC
    Now it says [ERROR] failed loading Plugin: class already exist.
  10. -elfin-
    Offline

    -elfin- New Member

    Joined:
    Mar 19, 2014
    Posts:
    29
    Minecraft User:
    elfin_ARC
    Now i changed name and class but the same problem came Back... Unexpected "{" on line 13
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Idk... Strange.

    P.S. the name can be anything as long as the plugin reviewers like @Humerus approves it, but the class name is a sense of moral conscience.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes. Therefore, use a class name like "OpmePlugin".
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Please post your code again. Also, this time please enclose your code [php]here[/php].
  14. -elfin-
    Offline

    -elfin- New Member

    Joined:
    Mar 19, 2014
    Posts:
    29
    Minecraft User:
    elfin_ARC
    <?php
    /*
    __PocketMine Plugin__
    name=OPMe
    version=1.0
    description=Embarrasses people asking for OP!
    author=YOU!
    class=OpmePlugin
    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(){
    }
    }
    ?>
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Try removing the ?>
    Last edited: Jul 3, 2014
  16. -elfin-
    Offline

    -elfin- New Member

    Joined:
    Mar 19, 2014
    Posts:
    29
    Minecraft User:
    elfin_ARC
    I removed ?> But still says unexpected "{" on line 12
  17. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    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(){
    }
    }
    Try this
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What is changed?
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Wait... You didn't change everything in the class name.
  20. -elfin-
    Offline

    -elfin- New Member

    Joined:
    Mar 19, 2014
    Posts:
    29
    Minecraft User:
    elfin_ARC
    So what i do?
    PEMapModder likes this.

Share This Page

Advertisement