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

subCommand switch

Comments in 'Plugin Development' started by Guillaume351, Mar 6, 2014.

  1. Guillaume351
    Offline

    Guillaume351 Active Member Plugin Developer

    Joined:
    Oct 11, 2013
    Posts:
    150
    Plugins:
    1
    Minecraft User:
    Guillaume351
    Why when I do /tntrun on or /tntrun off it doesn't display anything at all in the console ?
    Thank you

    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=TNTRun
    description=When a player steps on a tnt, it disappear
    version=1.0
    author=Guillaume351
    class=tntrun
    apiversion=12
    */

    class tntrun 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)."config.txt"CONFIG_YAML, array('TNTRun' =>true,));
            
    $this->api->event("entity.move", array($this"tntcheck"));
            
    $this->api->console->register("tntrun""tntrun [ON/OFF]", array($this"commandHandler"));      


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

    switch(
    $subCmd){
        case 
    "on":
            
    console("on");
            break;
        case 
    "off":
            
    console("off");
            break;
    }


      
      
        }
        public function 
    tntcheck($data){
            
    $check $this->config->get('TNTRun');
            
    $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. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    PHP:
    public function commandHandler($args,$issuer,$cmd){$here = ($this->api->plugin->configPath($this). "config.txt");$arguments $args[0];$subCmd strtolower(array_shift($args));

    switch(
    $subCmd){
     case 
    "on":console("on");
     break;
     case 
    "off":console("off");
     break;
    }
    }
  3. Guillaume351
    Offline

    Guillaume351 Active Member Plugin Developer

    Joined:
    Oct 11, 2013
    Posts:
    150
    Plugins:
    1
    Minecraft User:
    Guillaume351
    ? What is different ? Thank you.
  4. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Added another bracket
  5. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    You also need to change it from "($args,$issuer,$cmd)" to "($cmd,$args,$issuer)". The order does matter. ;)
  6. Guillaume351
    Offline

    Guillaume351 Active Member Plugin Developer

    Joined:
    Oct 11, 2013
    Posts:
    150
    Plugins:
    1
    Minecraft User:
    Guillaume351
  7. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    So then this may work?
    Code:
    <?php
    
    /*
    __PocketMine Plugin__
    name=Test
    description=Just an example
    version=1.0
    author=iksaku
    class=test
    apiversion=12
    */
    
    class test implements Plugin {
         private $api;
    
         public function __construct(ServerAPI $api, $server = false) {
              $this->api = $api;
         }
    
         public function init() {
              $this->api->console->register("test", "[1/2]", array($this, "test"));     
         }
    
         public function test($cmd,$args,$issuer){
              $arguments = $args[0];
              $subCmd = strtolower(array_shift($args));
    
              switch($subCmd){
                   case "1":
                        $this->api->chat->broadcast("Test message 1");
                   break;
                   case "2":
                        $this->api->chat->broadcast("Test message 2");
                   break;
         }
    
         public function __destruct(){
         }
    }
  8. SuperChipsLP
    Offline

    SuperChipsLP Active Member Plugin Developer

    Joined:
    Sep 15, 2013
    Posts:
    204
    Plugins:
    5
    Minecraft User:
    Redmol
    You can make it easier. Just do a function like
    Code:
    public function commandHandler($cmd, $params, $issuer, $args){
    switch($params[0]){
    case "test":
    break;
    }
    }
  9. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    Hahaha thanks, but I already saw your plugin "Death Swap" and read the source :D
    MrJaK likes this.

Share This Page

Advertisement