Solved Command repeats itself in chat

Discussion in 'Plugin Development' started by Side8StarLite, Sep 30, 2016.

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

    Side8StarLite

    Hi, I'm a super noob in Minecraft plugin coding - I just started less than a week ago. I'm currently following this tutorial, but everytime I type in a command in-game, the command I type in chat eg /hello repeats itself in chat. This also happens through the command line. There are some pictures to better explain.
    How can I fix this? Is this related to the code itself, or the plugin.yml file? glitch1.jpg glitch2.jpg In case you were wondering, this was my code:
    Code:
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class HandlingEvents extends JavaPlugin
    {
        @Override
        public void onEnable()
        {
            getLogger().info("Plugin enabled!");
            new PlayerListener(this);
        }
       
        @Override
        public void onDisable()
        {
           
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String args[])
        {
            if (cmd.getName().equalsIgnoreCase("hello"))
            {
                if (sender instanceof Player)
                {
                    sender.sendMessage(ChatColor.BOLD.toString() + ChatColor.RED + "Hello " + ChatColor.GREEN + "World");
                    sender.sendMessage(ChatColor.GREEN + "This is a player");
                   
                }
                else
                {
                    sender.sendMessage(ChatColor.GREEN + "This is a console");
                   
                }
            }
            if (cmd.getName().equalsIgnoreCase("ab"))
            {
                if (sender instanceof Player)
                {
                    Player player = (Player) sender;
                    if (player.hasPermission("ab.broadcast"))
                    {
                        if (args[0].equalsIgnoreCase("1"))
                        {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.AQUA + "PlayerJoinMessage" + ChatColor.RED + "]" + ChatColor.BOLD + ChatColor.GREEN + " Message 1");
                        }
                        else if (args[0].equalsIgnoreCase("2"))
                        {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.AQUA + "PlayerJoinMessage" + ChatColor.RED + "]" + ChatColor.BOLD + ChatColor.GREEN + " Message 2");
                           
                        }
                        else if (args[0].equalsIgnoreCase("3"))
                        {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.AQUA + "PlayerJoinMessage" + ChatColor.RED + "]" + ChatColor.BOLD + ChatColor.GREEN + " Message 3");
                           
                        }
                        else if (args[0].equalsIgnoreCase("4"))
                        {
                            Bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.AQUA + "PlayerJoinMessage" + ChatColor.RED + "]" + ChatColor.BOLD + ChatColor.GREEN + " Message 4");
                           
                        }
                        else
                        {
                            sender.sendMessage(ChatColor.BLUE + "Usage: /ab <1,2,3,4>");
                        }
                       
                    }
                    else
                    {
                        sender.sendMessage(ChatColor.BLUE + "You do NOT have permission sorry :(");
                    }
                }
                else
                {
                    sender.sendMessage(ChatColor.RED + "You need to be in-game to perform this command");
                }
            }
            return false;
        }
    
    }
    
    And this is my plugin.yml file:
    Code:
    name: PlayerJoinMessage
    main: me.HandlingEvents
    version: 2.0
    commands:
       hello:
          description: Our first command!
          usage: /hello
       ab:
          description: Broadcasting!
          permission: ab.broadcast
          usage: /ab <1,2,3,4>
     
  2. @Side8StarLite
    If you return false in the onCommand method it shows you the usage. If you return true, it doesn't.
     
  3. Offline

    Evonoucono

    @Side8StarLite
    A few things you should know:
    -You don't need a "plugin enabled" message in your onEnable, it's done automatically
    -You don't need an on disable if there is nothing in it, when would you ever have a need for an empty method that's never used?
    -Return true when the command was a success or it's the end of the onCommand method, return false when the command was not a success, so the user knows the proper usage.
     
    Last edited by a moderator: Oct 1, 2016
  4. Offline

    Assasinsheep

    @Side8StarLite try removing the usage in the plugin.yml I had issues when creating my first plugin because of it.
     
    Last edited: Oct 1, 2016
  5. Offline

    iClipse

    Something thats not in the code which is a possibility is that in game you have /gamerule showCommands (somthin like that) true
     
  6. Offline

    Side8StarLite

    Thanks for all your replies!
     
Thread Status:
Not open for further replies.

Share This Page