Solved Removing the message sent to a player after they use a command

Discussion in 'Plugin Development' started by TheKingElessar, Jul 19, 2018.

Thread Status:
Not open for further replies.
  1. Offline

    TheKingElessar

    The title is the best I could get - I had trouble effectively describing it for a title.

    I made a plugin where a player can type a command (the /mimic command below) causing the server to broadcast text. However, when a player uses the command a message is sent to the player (and only that player, since it's not in the server logs) that just contains the commands "usage" text in the plugin.yml file. This message is unintended.

    It only happens with a certain command - I made a second one (the /potato command below) in order to see if it would happen, but it doesn't.

    Server log when the commands are issued:
    upload_2018-7-19_12-26-52.png

    Clientside view when the commands are issued:
    [​IMG]
    The "Potato command recognized" affirms that the second command I made works. The "jeb_ joined the game" is working as intended. However, the "/mimic <join> <player>" shouldn't be there.

    The code relating to the commands:
    Code:
    switch (lowerCmd) {
        case "mimic":
                       
            switch (args[0]) {
                case "join":
                    String playerToJoin = args[1];
                    Bukkit.broadcastMessage(ChatColor.YELLOW + playerToJoin + " joined the game");
    
            default:
                return false;
            }
                       
        case "potato":
            player.getPlayer().sendMessage("Potato command recognized.");
                       
    default:
        return true;
    }
    
    If I should post more of my code just say so - I thought this part was the most likely to be causing a problem, since only one of the commands has this problem.

    I can't find any other post or anything related to this on any forums.

    Just a note - I'm pretty new at Java, and am creating this plugin to apply what I'm learning in the tutorials I'm following to learn Java. I'd appreciate the help, and if it's a "stupid" question sorry.

    I know the plugin idea is unoriginal :)
     

    Attached Files:

  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    TheKingElessar

    @timtower Okay, I changed the "false" to "true" and it now works as intended. If you are able to, could you briefly explain why it did that? I hadn't realized the return false would ever be reached by the command (as long as there was "join" as the first argument).

    Why did it do that?
     
  4. Online

    timtower Administrator Administrator Moderator

    @TheKingElessar The oncommand has to return true when the plugin handled the command correctly
     
  5. Offline

    TheKingElessar

    @timtower Oh, okay. That makes a lot of sense. Thanks for your help on this!
     
  6. Offline

    KarimAKL

  7. Offline

    CriticaMobs

Thread Status:
Not open for further replies.

Share This Page