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

Commands not doing anything

Comments in 'Plugin Development' started by xBeastMode, Nov 28, 2015.

  1. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    Hello, I need help with my chat plugin. I have made the code for the "private chat" part in my plugin. The problem is that when the command is ran nothing happens, I have looked in the code an I don't see anything that stops it from working. If you see anything please reply ASAP, please and thank you.

    notice: I use PHPStorm for my plugins.

    PHP:
    /**
         * @param CommandSender $s
         * @param Command $c
         * @param $label
         * @param array $args
         */
        
    public function onCommand(CommandSender $sCommand $c$label, array $args){
            switch(
    strtolower($c->getName())){
                case 
    'group':
                    if(
    $s->hasPermission("cc.groups.all")) {
                        if(
    $s instanceof Player) {
                            if (
    $args[0] === "create") {
                                
    $group $args[1];
                                
    $this->cc->createGroup($group$s);
                                
    $c_group = new PlayerJoinGroupEvent($s->getName(), $group);
                                
    $this->cc->getServer()->getPluginManager()->callEvent($c_group);
                                
    $s->sendMessage(TXT::GREEN "Successfully created '" $group "'!");
                            } elseif (
    $args[0] === "delete") {
                                
    $group $args[1];
                                
    $d_group = new PlayerLeaveGroupEvent($s->getName(), $group);
                                
    $this->cc->getServer()->getPluginManager()->callEvent($d_group);
                                if (
    $this->cc->isLeader($group$s) && $this->cc->groupExists($group)) {
                                    
    $this->cc->deleteGroup($group$s);
                                } elseif (!
    $this->cc->isLeader($group$s)) {
                                    
    $s->sendMessage(TXT::RED "You are not the owner of this group!");
                                } elseif (!
    $this->cc->groupExists($group)) {
                                    
    $s->sendMessage(TXT::RED "The group '" $group "' does not exist.");
                                }
                            } elseif (
    $args[0] === "changeleader") {
                                
    $group $args[2];
                                if (
    $this->cc->isLeader($group$s)) {

                                }
                            } elseif (
    $args[0] === "add") {
                                
    $group $args[1];
                                
    $player $this->getServer()->getPlayerExact($args[2]);
                                if (
    $player !== null) {
                                    
    $a_member = new PlayerJoinGroupEvent($player$group);
                                    
    $this->cc->getServer()->getPluginManager()->callEvent($a_member);
                                    
    $this->cc->addMember($group$player);
                                    
    $s->sendMessage(TXT::GREEN "Successfully added player " $player "!");
                                } else {
                                    
    $s->sendMessage(TXT::RED $args[2] . " is not online.");
                                }
                            } elseif (
    $args[0] === "remove") {
                                
    $group $args[1];
                                
    $player $this->getServer()->getPlayerExact($args[2]);
                                if (
    $player !== null) {
                                    
    $d_member = new PlayerLeaveGroupEvent($player$group);
                                    
    $this->cc->getServer()->getPluginManager()->callEvent($d_member);
                                    
    $this->cc->removeMember($group$player);
                                    
    $s->sendMessage(TXT::GREEN "Successfully removed player " $player "!");
                                } else {
                                    
    $s->sendMessage(TXT::RED $args[2] . " is not online.");
                                }
                            } elseif (
    $args[0] === "help") {
                                
    $this->cc->helpList($s);
                            }
                            if (empty(
    $args[0]) || empty($args[1])) {
                                
    $s->sendMessage(TXT::RED "For help, please use: /group help");
                            } else {
                                return;
                            }
                        }else{
                            
    $s->sendMessage(TXT::RED "Please run this command in-game.");
                        }
                    }
                break;
                case 
    'sgm':
                    if(
    $s->hasPermission("cc.groups.send.message")){
                        if(
    $s instanceof Player){
                        if(
    $this->cc->groupExists($args[0])){
                            
    $group $args[0];
                            
    $message array_slice($args2);
                            if(!empty(
    $message)){
                                
    $this->cc->sendGroupMessage($message$s$group);
                                
    $s->sendMessage($message);
                            }else{
                                
    $s->sendMessage(TXT::RED "Please enter a longer message.\nUsage: /sgm <group> <message>");
                            }
                        }
                        }else{
                            
    $s->sendMessage(TXT::RED "Please run this command in-game.");
                        }
                    }
                break;
                case 
    'hop':
                    if(
    $s->hasPermission("cc.op.help")) {
                        if(
    $s instanceof Player){
                        foreach (
    $args as $message) {
                            foreach (
    $this->getServer()->getOnlinePlayers() as $p) {
                                if (
    $p->isOp() && $p !== null) {
                                    
    $default $this->cc->getConfig()->getNested("OP.help-message");
                                    
    $p->sendMessage(str_replace(["{PLAYER}""{MESSAGE}"], [$s$args], $default));
                                    
    $s->sendMessage($this->cc->getConfig()->getNested("OP.message-sent"));
                                }else{
                                    
    $s->sendMessage($this->cc->getConfig()->getNested("OP.no-op-online-message"));
                                }
                            }
                        }
                            if(empty(
    $args))
                            {
                                
    $s->sendMessage(TXT::RED "Please enter a longer message. Usage: /hop <message>");
                            }
                        }else{
                            
    $s->sendMessage(TXT::RED "Please run this command in-game.");
                        }
                    }
                break;
            }
        }
    Code:
    commands:
      group:
        description: "access to all group commands"
        permission: cc.groups.all
      sgm:
        description: "send group messages"
        permission: cc.groups.send.message
      hop:
        description: "get instant help from ops"
        permission: cc.op.help
    
    permissions:
      cc.groups.all:
        default: true
        description: "access to all group commands"
      cc.groups.send.message:
        default: true
        description: "send group messages"
      cc.op.help:
        default: true
        description: "get instant help from ops"
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    hm use debug like
    PHP:
    var_dump($cmd->getName());
    or if command is "group"
    PHP:
    echo "group";
    and test where is the problem
    hoyinm14mc likes this.
  3. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    Still wont work. I might have to rewrite the entire code. *full rage*
  4. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    is onCommand() function called?
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    and is called case "group" ?
  6. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    Did you look at the code? Can you try it yourself and see if it works?
  7. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Hey! I am experiencing the same thing on my plugin DynMapPE!
    My command is registered, i know that.
    But it seems not to get fired in ANY WAY! https://github.com/ImagicalCorp/DynMapPE
    On /dynmaprefresh not even any output ;(
  8. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    check your github, I made a pull request on the command function.
  9. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    1st that did nothing. 2nd why should it even do anything different? You just only used another case break thing then i did
  10. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    What??I never said it would do something, just made a pull request to the command function
  11. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Check your onEnable function, the plugin might have encountered an error when loading
  12. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Now works.. maybe the doubled braces in the if has permission part.

    For you:
    Code:
    commands:
      group:
        description: "access to all group commands"
        permission: cc.groups.all
      sgm:
        description: "send group messages"
        permission: cc.groups.send.message
      hop:
        description: "get instant help from ops"
        permission: cc.op.help
    permissions:
      cc.groups.all:
        description: "access to all group commands"
        default: true
      cc.groups.send.message:
        description: "send group messages"
        default: true
      cc.op.help:
        description: "get instant help from ops"
        default: true
    Check, if that works
    Legoboy0215 likes this.
  13. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    Does not work. I will figure it out.

    I don't see anything wrong.
    PHP:
    public function onEnable(){
            
    $log $this->getLogger();
            
    $log->info("BeastPvP chat enabled!");
            
    $this->muted = array();
            
    $this->msg = array();
            
    $this->pfx "[ChatControl]";
            
    $this->seconds $this->getConfig()->getNested("Chat.spam-check-seconds");
            
    $this->sbu $this->seconds;
            
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new Broadcaster($this), 20);
            
    $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
            @
    mkdir($this->getDataFolder());
            @
    mkdir($this->getDataFolder() . "Groups/");
            if(!
    file_exists($this->getDataFolder() . "config.yml")){
                
    $this->saveDefaultConfig();
            }
        }
  14. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    You should write after every { a sendMessage code tp check when it doesnt work anymore, also do some else commands
  15. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Your onCommand works on my side, and the onEnable function looks good, are there any error messages displayed on console?
  16. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    None. I have no clue what it could be.

Share This Page

Advertisement