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

TNT run code but there is an issue pls help

Comments in 'Plugin Development' started by jerlegoman, May 18, 2014.

  1. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    Hi my name is jerlegoman I was coding a tnt run code but there was an error with the code and the server stoped pls help!
    Here Is The Code:
    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=TNTRUN
    description=Try not to fall!
    version=1.0
    author=jerlegoman
    class=TNT
    apiversion=10,11,12
    */

    class TNT implements Plugin {
    private 
    $api;

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

    public function 
    init() {
    $this->config = new Config($this->api->plugin->configPath($this)."TNTproperties.yml"CONFIG_YAML, array('TNTon/off' =>true,));
    $this->api->event("entity.move", array($this"tntsetting"));
    $this->api->addHandler("player.join", array($this"eventHandler"), 100);
    $this->api->console->register("tnt""tnt on/off", array($this"commandHandler"));


    }
    public function 
    commandHandler($args,$issuer,$cmd){
    $here = ($this->api->plugin->configPath($this). "TNTproperties.yml");
    $arguments $args[0];
    $subCmd strtolower(array_shift($args));

    switch(
    $subCmd){
    case 
    "on":
    $this->api->chat->sendTo(false"on");
    break;
    case 
    "off":
    $this->api->chat->sendTo(false"off");
    break;
    }

    public function 
    eventHandler($data$event)
    {
    switch(
    $event)
    {
    case 
    "player.join":
    $data->sendChat("** Welcome to TNT RUN!");
    $data->sendChat("** Players: ".count($this->api->player->getAll())."/".$this->server->maxClients);
    $data->sendChat("** Have Fun and BE CARE FULL!");
    break;
    }
    }

    public function 
    tntsetting($data){
    $check $this->config->get('TNTon/off');
    $block $data->level->getBlock(new Vector3($data->x, ($data->-1), $data->z));
    if (
    $check == true){

    if(
    $block->getID() == 46){

    $data->level->setBlock(new Vector3($data->x$data->y-1$data->z,$data->level), new AirBlock());
    }}
    else{}
    }

    public function 
    __destruct(){
    }
    }
    ?>
  2. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    392
    You forgot to close the method commandHandler with }
    jerlegoman likes this.
  3. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    392
    And $this->api->chat->sendTo(false, "on");
    needs to be $issuer->sendChat('on');
    jerlegoman likes this.
  4. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    392
    And you switched the arguments in the method commandHandler.

    public function commandHandler($args,$issuer,$cmd){
    needs to be:
    public function commandHandler($cmd, $args, $issuer){
    jerlegoman likes this.
  5. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    392
    And these 2 lines are not needed:
    $here = ($this->api->plugin->configPath($this). "TNTproperties.yml");
    $arguments = $args[0];
    jerlegoman likes this.
  6. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    392
    And the tnt on/off command doesn't turn anything on or off.
    Is this the whole code?
  7. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    392
    And this is not needed: else{}

    I can go on forever xD
    64FF00 and Falk like this.
  8. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    I added the corrections but when I ran the server it had another error
    here is the error:
    Parse error: syntax error, unexpected 'switch' (T_SWITCH), expecting function (T_FUNCTION) in C:\Users\Jeremy Haft\Desktop\PocketMine-MP use only\plugins\TNTrunV1.php on line 31

    here is the code with your corrections:
    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=TNTRUN
    description=Try not to fall!
    version=1.0
    author=jerlegoman
    class=TNT
    apiversion=10,11,12
    */

    class TNT implements Plugin {
    private 
    $api;

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

    public function 
    init() {
    $this->config = new Config($this->api->plugin->configPath($this)."TNTproperties.yml"CONFIG_YAML, array('TNTon/off' =>true,));
    $this->api->event("entity.move", array($this"tntsetting"));
    $this->api->addHandler("player.join", array($this"eventHandler"), 100);
    $this->api->console->register("tnt""tnt on/off", array($this"commandHandler"));


    }
    public function 
    commandHandler($cmd$args$issuer){
    $subCmd strtolower(array_shift($args));
    }
    switch(
    $subCmd){
    case 
    "on":
    $issuer->sendChat('on');
    break;
    case 
    "off":
    $issuer->sendChat('off');
    break;
    }

    public function 
    eventHandler($data$event)
    {
    switch(
    $event)
    {
    case 
    "player.join":
    $data->sendChat("** Welcome to TNT RUN!");
    $data->sendChat("** Players: ".count($this->api->player->getAll())."/".$this->server->maxClients);
    $data->sendChat("** Have Fun and BE CARE FULL!");
    break;
    }
    }

    public function 
    tntsetting($data){
    $check $this->config->get('TNTon/off');
    $block $data->level->getBlock(new Vector3($data->x, ($data->-1), $data->z));
    if (
    $check == true){

    if(
    $block->getID() == 46){

    $data->level->setBlock(new Vector3($data->x$data->y-1$data->z,$data->level), new AirBlock());
    }}
    else{}
    }

    public function 
    __destruct(){
    }
    }
    ?>
  9. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    392
    Add the closing bracked after the end of the switch, not after $subCmd = ...
  10. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    there was another error:
    Parse error: syntax error, unexpected 'public' (T_PUBLIC) in C:\Users\Jeremy Haft\Desktop\PocketMine-MP use only\plugins\TNTrunV1.php on line 41
    here is the code:
    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=TNTRUN
    description=Try not to fall!
    version=1.0
    author=jerlegoman
    class=TNT
    apiversion=10,11,12
    */

    class TNT implements Plugin {
    private 
    $api;

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

    public function 
    init() {
    $this->config = new Config($this->api->plugin->configPath($this)."TNTproperties.yml"CONFIG_YAML, array('TNTon/off' =>true,));
    $this->api->event("entity.move", array($this"tntsetting"));
    $this->api->addHandler("player.join", array($this"eventHandler"), 100);
    $this->api->console->register("tnt""tnt on/off", array($this"commandHandler"));


    }
    public function 
    commandHandler($cmd$args$issuer){
    $subCmd strtolower(array_shift($args));

    switch(
    $subCmd){
    case 
    "on":
    $issuer->sendChat('on');
    break;
    case 
    "off":
    $issuer->sendChat('off');
    break;
    }
    {

    public function 
    eventHandler($data$event)
    {
    switch(
    $event)
    {
    case 
    "player.join":
    $data->sendChat("** Welcome to TNT RUN!");
    $data->sendChat("** Players: ".count($this->api->player->getAll())."/".$this->server->maxClients);
    $data->sendChat("** Have Fun and BE CARE FULL!");
    break;
    }
    }

    public function 
    tntsetting($data){
    $check $this->config->get('TNTon/off');
    $block $data->level->getBlock(new Vector3($data->x, ($data->-1), $data->z));
    if (
    $check == true){

    if(
    $block->getID() == 46){

    $data->level->setBlock(new Vector3($data->x$data->y-1$data->z,$data->level), new AirBlock());
    }}
    }

    public function 
    __destruct(){
    }
    }
    ?>
  11. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    You have the wrong brace at the end of commandHandler().
    64FF00 and jerlegoman like this.
  12. Spurs_Man321
    Offline

    Spurs_Man321 Active Member

    Joined:
    Apr 7, 2014
    Posts:
    52
    Minecraft User:
    spursman321
    Hey falk just write ir for him XD
    64FF00 likes this.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Note that lag could bypass some TNT blocks.
    64FF00 and iJoshuaHD like this.
  14. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    755
    Plugins:
    2
    Minecraft User:
    Darunia18
    By the way, just a suggestion, maybe make the class something more complex like TNT. You can make it TNTRun if you want, because there could be other plugins that involve TNT that use TNT as the class name and then some issues would happen (if you plan to release this publicly, of course).
    64FF00, jerlegoman and PEMapModder like this.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What I have been trying to convince everyone since from months ago...
    Last edited: May 19, 2014
  16. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    Where should I put the () to because there are many places it says commandhandler can you pls highlight the location of the commandhandler
  17. jerlegoman
    Offline

    jerlegoman Active Member

    Joined:
    Dec 10, 2013
    Posts:
    120
    Minecraft User:
    jeremy647
    Hello?
  18. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    If you don't know where to put the parentheses then you need to go learn PHP.
    hoyinm14mc and PEMapModder like this.

Share This Page

Advertisement