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

How do you have multiple commands?

Comments in 'Plugin Development' started by Legoboy0215, May 15, 2015.

  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    How do you make a plugin that when you type an command, some info you set in the plugin comes out. Type in the second command, another set of info comes out. I tried to edit the xRulesx by @xFlare, but it did not work out well. If you think this is a question that is real easy and no need to ask, ask an Mod to close it. Thanks..
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You just mean Commands?
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Like typing the commands then some text appears in chat. Sorry for asking nooby questions since I started to play with plugins today...
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    public function onCommand(CommandSender $senderCommand $cmd$label, array $args) {
                switch(
    $cmd->getName()){
                    case 
    "Your command here":
                       
    //What you want, like:
                       
    $sender->sendMessage("Hey!");
                       return 
    true;
                }
    }
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    What about multiple ones? Copy and paste? i do not think so.
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    public function onCommand(CommandSender $senderCommand $cmd$label, array $args) {
                switch(
    $cmd->getName()){
                    case 
    "Your command here":
                       
    //What you want, like:
                       
    $sender->sendMessage("Hey!");
                       return 
    true;
                    case 
    "Other command here":
                       
    //What you want, like:
                       
    $sender->sendMessage("Bye!");
                       return 
    true;
                    case 
    "Other command here":
                       
    //What you want, like:
                       
    $sender->sendMessage("Hello again!");
                       return 
    true;
                }
    }
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Thanks sooooo much! You helped me with my first plugin. XD.
    BTW, I did that to another plugin by copying the case part since it looked important. It still had an error!
    But still, this worked so this is all that matters...
    I will try to place this in with config files.
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You're welcome! :)
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    How do you add perm nodes into this then?
  10. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Wait...
    What is this?
    Code:
    Error: syntax error, unexpected '?>', expecting function (T_FUNCTION)
    File: /myFirstPlugin/src/legoboy/myFirstPlugin/main
    Line: 41
    Type: E_PARSE
    
    THIS CRASH WAS CAUSED BY A PLUGIN
    
    Code:
    [32]                    //What you want, like:
    [33]                    $sender->sendMessage("Bye!");
    [34]                    return true;
    [35]                 case "hello":
    [36]                    //What you want, like:
    [37]                    $sender->sendMessage("Hello again!");
    [38]                    return true;
    [39]             }
    [40] }
    [41] ?>
    [42]
    [43]
    [44]
    [45]
    [46]
    [47]
    [48]
    [49]
    [50]
    [51]
    
    Backtrace:
    #0 /src/pocketmine/Server(0): pocketmine\Server->crashDump()
    #1 /DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader(64): BaseClassLoader->loadClass()
    #2 /DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader(64): spl_autoload_call()
    #3 /DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader(64): class_exists()
    #4 /src/pocketmine/plugin/PluginManager(152): FolderPluginLoader\FolderPluginLoader->loadPlugin()
    #5 /src/pocketmine/plugin/PluginManager(296): pocketmine\plugin\PluginManager->loadPlugin()
    #6 /DevTools_v1.10.0.phar/src/DevTools/DevTools(45): pocketmine\plugin\PluginManager->loadPlugins()
    #7 /src/pocketmine/plugin/PluginBase(86): DevTools\DevTools->onEnable()
    #8 /src/pocketmine/plugin/PharPluginLoader(123): pocketmine\plugin\PluginBase->setEnabled()
    #9 /src/pocketmine/plugin/PluginManager(559): pocketmine\plugin\PharPluginLoader->enablePlugin()
    #10 /src/pocketmine/Server(1847): pocketmine\plugin\PluginManager->enablePlugin()
    #11 /src/pocketmine/Server(1833): pocketmine\Server->enablePlugin()
    #12 /src/pocketmine/Server(1686): pocketmine\Server->enablePlugins()
    #13 /src/pocketmine/PocketMine(437): pocketmine\Server->__construct()
    #14 (1): ()
    #15 (0): {main}()
    
    PocketMine-MP version: 1.4.1dev #239 [Protocol 20; API 1.11.0]
    Git commit: 0000000000000000000000000000000000000000
    uname -a: Windows NT LEGOBOY 6.1 build 7601 (Windows 7 Home Premium Edition Service Pack 1) i586
    PHP Version: 5.6.6
    Zend version: 2.6.0
    OS : WINNT, win
    
    Loaded plugins:
    DevTools 1.10.0 by PocketMine Team for API(s) 1.3.1
    EconomyAPI 2.0.6 by onebone for API(s) 1.0.0, 1.1.0, 1.2.0, 1.2.1, 1.3.0, 1.3.1, 1.4.0, 1.4.1
    xyz 1.0.1 by unerds for API(s) 1.0.0
    My plugin:
    PHP:
    <?php

    namespace legoboy\myFirstPlugin;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\Player;

    class 
    Main extends PluginBase{

            public function 
    onLoad(){
                    
    $this->getLogger()->info("onLoad() has been called!");
            }

            public function 
    onEnable(){
                    
    $this->getLogger()->info("onEnable() has been called!");
            }

            public function 
    onDisable(){
                    
    $this->getLogger()->info("onDisable() has been called!");
            }
            public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args) {
                switch(
    $cmd->getName()){
                    case 
    "hey":
                       
    //What you want, like:
                       
    $sender->sendMessage("Hey!");
                       return 
    true;
                    case 
    "bye":
                       
    //What you want, like:
                       
    $sender->sendMessage("Bye!");
                       return 
    true;
                    case 
    "hello":
                       
    //What you want, like:
                       
    $sender->sendMessage("Hello again!");
                       return 
    true;
                }
    }
    ?>
  11. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You can add it in the code:
    PHP:
    public function onCommand(CommandSender $senderCommand $cmd$label, array $args) {
                switch(
    $cmd->getName()){
                    case 
    "Your command here":
                       if(
    $sender->hasPermission("permission-node"){
                          
    //What you want, like:
                          
    sender->sendMessage("Hey!");
                          return 
    true;
                       } else{
                            
    $sender->sendMessage("You don't have the permission to perform this command.");
                            return 
    true;
                         }
                }
    }
    Or in the plugin.yml:
    Code:
    name: Plugin name
    main: Main Path here
    version: 1.0.0
    api: 1.0.0
    author: Your name
    commands:
        command-here:
            description: "Command Description"
            usage: "/command"
    permissions:
        permission-node-here:
            default: op
            description: "Description here"
    Legoboy0215 likes this.
  12. PixelGuy75
    Offline

    PixelGuy75 Notable Member Plugin Developer

    Joined:
    Feb 9, 2014
    Posts:
    316
    Plugins:
    2
    Minecraft User:
    PixelGuy75
    You need another } at the end
    Legoboy0215 likes this.
  13. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    remove ?> at the end
  14. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    OOOps...
  15. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    It works now... YAY!
    HotFireyDeath likes this.
  16. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    I did it. @PixelGuy75 is right. I forgot to add an "}"...
    HotFireyDeath likes this.
  17. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    You forgot some brackets maybe
    Legoboy0215 and HotFireyDeath like this.
  18. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Yep....
  19. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    HotFireyDeath likes this.

Share This Page

Advertisement