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

Commands do nothing

Comments in 'Plugin Development' started by Comedyman937, Aug 14, 2014.

  1. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    Im working on a plugin called MultiversePE and Right now Im working on commands. For some odd reason' when I try to run the command on the console it does nothing at all. No errors, messages, nothing. Does anyone see what I did wrong?

    Main.php:
    PHP:
    <?php
    namespace MultiversePE;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\ConsoleCommandSender;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\ConsoleCommandExecutor;
    use 
    pocketmine\Player;

    class 
    Main extends PluginBase implements CommandExecutor{
        public function 
    onEnable(){
            
    $this->saveDefaultConfig();
            
    $this->getResource("config.yml");
            
    $this->getLogger()->info("MultiversePE Loaded!");
        }
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args){
            switch(
    $cmd->getName()){
                case 
    "multiversepe":
                    if(!isset(
    $args[0])){
                        
    $sender->sendMessage("[MultiversePE] Need help? Use /multiversepe help");
                        return 
    true;
                    }else{
                        if(
    $args[0] == "help"){
                            
    $sender->sendMessage("");
                        }
                    }
                break;
                case 
    "tpw":
                    if(!
    $sender instanceof Player){
                        
    $sender->sendMessage("[MultiversePE] You can only use this command in-game!");
                        return 
    true;
                    }else{
                        if(!isset(
    $args[0])){
                            
    $sender->sendMessage("[MultiversePE] You must specify a world!");
                        }else{
                            
    $level $sender->getServer()->getLevel()->getName($args[0]);
                            
    $pos = new Position($level->getSafeX(), $level->getSafeY(), $level->getSafeZ(), $level);
                            
    $sender->teleport($pos);
                            
    $sender->sendMessage("[MultiversePE] Teleported you to " $level "!");
                            return 
    true;
                        }
                    }
            }
        }
        public function 
    onDisable(){
            
    $this->getLogger()->info("MultiversePE Unloaded!");
        }
    }
    ?>
    plugin.yml:
    Code:
    name: MultiversePE
    main: MultiversePE\Main
    version: 1.0.0
    api: [1.2.0]
    load: STARTUP
    authors: [Comedyman937]
    description: Multiple world management for PocketMine-MP!
    commands:
        multiversepe:
          description: "Multiverse Admin Commands!"
          usage: "/multiversepe <create>"
          aliases: [mv, multiv, mverse, multiversepe, mvpe, multivpe, mversepe]
          permission: multiversepe.admin
        tpw:
          description: "Teleport to other worlds!"
          usage: "/tpw <world>"
          aliases: [tpworld, wtp, worldtp]
          permission: multiversepe.teleport
    permissions:
        multiversepe.admin:
           description: "Allows players to use the MultiversePE-Worlds commands!"
           default: op
        multiversepe.teleport:
          description: "Allows players to teleport to other worlds!"
          default: op
    
    Console output:
    Code:
    08:29:00 [INFO] Done (1.453s)! For help, type "help" or "?"
    multiversepe
    tpw
    
    (There might be regular errors on the Main.php file... Havent been able to debug yet because of this issue)
    Last edited: Aug 14, 2014
  2. ZenCloud
    Offline

    ZenCloud Active Member

    Joined:
    May 14, 2014
    Posts:
    61
    Minecraft User:
    ZenCloud
    If I know how to make plugins i wouldve answered
  3. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Do other commands work?
  4. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    Yes. Every other command works. (Including commands from other plugins)
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    And if you don't, shut up.
    iiRushii, HotFireyDeath, Tuff and 5 others like this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You should use parentheses.
    if(!($sender instanceof Player)){ do_something(); }

    Otherwise it won't work.
  7. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    Didnt change anything. Same output.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It may not be related, but check your control flow.
    Check.
  9. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    Nope. Still nothing.... Heres the current code (Its been slightly changed)
    PHP:
    <?php
    namespace MultiversePE;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\ConsoleCommandSender;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\ConsoleCommandExecutor;
    use 
    pocketmine\Player;

    class 
    Main extends PluginBase implements CommandExecutor{
        public function 
    onEnable(){
            
    $this->saveDefaultConfig();
            
    $this->getResource("config.yml");
            
    $this->getLogger()->info("MultiversePE Loaded!");
        }
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args){
            switch(
    $cmd->getName()){
                case 
    "multiversepe":
                    if(!(isset(
    $args[0]))){
                        
    $sender->sendMessage("[MultiversePE] Need help? Use /multiversepe help");
                        return 
    true;
                    }else{
                        if(
    $args[0] == "help"){
                            
    $sender->sendMessage("Command list for MultiversePE");
                            
    $sender->sendMessage("/multiversepe help - MultiversePE Help");
                            
    $sender->sendMessage("/multiversepe create - Create a new world");
                            
    $sender->sendMessage("/tpw <world> - Teleport to a world");
                            return 
    true;
                        }
                    }
                break;
                case 
    "tpw":
                    if(!(
    $sender instanceof Player)){
                        
    $sender->sendMessage("[MultiversePE] You can only use this command in-game!");
                        return 
    true;
                    }else{
                        if(!(isset(
    $args[0]))){
                            
    $sender->sendMessage("[MultiversePE] You must specify a world!");
                            return 
    true;
                        }else{
                            
    $level $sender->getServer()->getLevel()->getName($args[0]);
                            
    $pos = new Position($level->getSafeX(), $level->getSafeY(), $level->getSafeZ(), $level);
                            
    $sender->teleport($pos);
                            
    $sender->sendMessage("[MultiversePE] Teleported you to " $level "!");
                            return 
    true;
                        }
                    }
                break;
            }
        }

        public function 
    onDisable(){
            
    $this->getLogger()->info("MultiversePE Unloaded!");
        }
    }
    ?>
    I also tried putting return true; right before the break; which again, nothing...
  10. SpiderPig
    Offline

    SpiderPig Active Member

    Joined:
    Sep 21, 2013
    Posts:
    128
    Minecraft User:
    SpiderPig
    I can't test but it should work now!
    PHP:
    <?php
    namespace MultiversePE;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\ConsoleCommandSender;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\ConsoleCommandExecutor;
    use 
    pocketmine\Player;

    class 
    Main extends PluginBase implements CommandExecutor{

     public function 
    onEnable(){
     
    $this->saveDefaultConfig();
     
    $this->getResource("config.yml");
     
    $this->getLogger()->info("MultiversePE Loaded!");
     }

     public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args){
     switch(
    $cmd->getName()){
     case 
    "multiversepe":
    switch (
    strtolower(array_shift($args))) {
     case 
    "help":
     
    $sender->sendMessage("Testing.....");
    break;
     }
    return 
    true;
    default:
    $sender->sendMessage("It should work!");
     break;
     }
     }

     public function 
    onDisable(){
     
    $this->getLogger()->info("MultiversePE Unloaded!");
     }
    }
    ?>
  11. PluginMastered
    Offline

    PluginMastered Active Member

    Joined:
    Mar 1, 2014
    Posts:
    161
    Minecraft User:
    Flexa33
    PHP:
    switch ($cmd) {
    i always use this. I don't know if it still works your way :D.
  12. SpiderPig
    Offline

    SpiderPig Active Member

    Joined:
    Sep 21, 2013
    Posts:
    128
    Minecraft User:
    SpiderPig
    That's old API now you need to use

    PHP:
    switch ($command->getName()){
    //Code here
    }
    PluginMastered and Comedyman937 like this.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $cmd = $command->getName();

    Problem resolved! :)
  14. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    No because $command is already set to $cmd here:
    PHP:
    onCommand(CommandSender $senderCommand $cmd$label, array $args)
    Tuff likes this.
  15. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    That doesnt work either :'(
  16. PluginMastered
    Offline

    PluginMastered Active Member

    Joined:
    Mar 1, 2014
    Posts:
    161
    Minecraft User:
    Flexa33
    This is wierd does it load when you turn on your server?
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I was just answering @SpiderPig, not you.
    SpiderPig and Comedyman937 like this.
  18. Jon
    Offline

    Jon Active Member Plugin Developer

    Joined:
    Sep 1, 2013
    Posts:
    201
    Plugins:
    3
    Minecraft User:
    Heromine14
    Maybe two plugins can't work with each other.
    -maybe-
    I know this because this happened to my plugin and @PEMapModder knows it :p
    Last edited: Aug 14, 2014
  19. PluginMastered
    Offline

    PluginMastered Active Member

    Joined:
    Mar 1, 2014
    Posts:
    161
    Minecraft User:
    Flexa33
    Translations :

    Maybe two plugins can't work with each other.
    -maybe-
    I know this because this happened to my plugin and @PEMapModder knows it :p
    Last edited: Aug 14, 2014
    PEMapModder and Jon like this.
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It won't. There is the fallback prefix that fixes it.
    Jon and PluginMastered like this.

Share This Page

Advertisement