Solved Command echoing, don't know why.

Discussion in 'Plugin Development' started by ipodtouch0218, May 23, 2016.

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

    ipodtouch0218

  2. Offline

    Zombie_Striker

    @ipodtouch0218
    You forgot to add else if statements for every time you check the args length. Currently, you are testing if there are 0 args and then if there is 1 arg, even if there is only no arg. After that, you check if there two args even if there are no args, or if there is just one arg, and if the length is any number that is not 2, it will run the else statement. That is why if/else statements exist.

    To fix your problem:
    After creating an if statement checking for one length, make the following if statements "if/else" statements.
     
  3. Offline

    ipodtouch0218

    @Zombie_Striker

    I've added the if/else for args.length (also noticed that the length should have been 3 not 2 for one,) but the problem still exists. Any other things that may seem wrong?

    EDIT: forgot the link
    http://pastebin.com/6up3HTX0
     
    Last edited: May 24, 2016
  4. Offline

    Zombie_Striker

    @ipodtouch0218
    Can you show which lines are echoing? To do this, add an "ID", extra string, or some sort of notifier at the end of each message to show which messages where sent.
     
  5. Offline

    ipodtouch0218

    Code:
            if (cmd.getName().equalsIgnoreCase("votecoins")) {
                prefix = ChatColor.translateAlternateColorCodes('&', prefix);
                receiveCredits = ChatColor.translateAlternateColorCodes('&', receiveCredits);
                sender.sendMessage("ID 1");
                if (args.length == 0) {
                    sender.sendMessage("ID 2");
                    if (!(sender instanceof Player)) {
                        Bukkit.getConsoleSender().sendMessage(prefix + ChatColor.RED + " Only players can use that command!");
                        return true;
                    }
                    if (sender.hasPermission("votecoins.bal")) {
                        sender.sendMessage("ID 3");
                        Player player = (Player) sender;
                        int playerBalance = balConfig.getInt("" + player.getUniqueId());
                        sender.sendMessage(prefix + ChatColor.GREEN + " You have " + ChatColor.YELLOW + playerBalance + ChatColor.GREEN + " VoteCoins");
                        return true;
                    }
    No messages were sent. This was ran through a player, not a console.

    I did it after:
    1. Command Name Check
    2. Argument Check
    3. Permissions Check
     
  6. Offline

    Zombie_Striker

    @ipodtouch0218
    If no messages were sent, then the command "votecoins" was either not registered, or another plugin is canceling the command from running.
     
  7. Offline

    ipodtouch0218

    @Zombie_Striker

    But they were registered in the Plugin.YML correctly?
    http://pastebin.com/X21i2y02

    I'm running it on a blank server with no other plugin except Essentials.
    The command appears in /help... soo...
     
  8. Offline

    Zombie_Striker

    @ipodtouch0218
    Looking at your code again, it seems your constructor is wrong.
    Code:
     public boolean onCommand(CommandSender sender, Command cmd, String[] args, String label) {
    It should instead be like the following:
    Code:
     public boolean onCommand(CommandSender sender, Command cmd,  String label, String[] args) {
    The args have to come after the label. This should fix your problem.
     
    ipodtouch0218 likes this.
  9. Offline

    ipodtouch0218

  10. Offline

    Zombie_Striker

    @ipodtouch0218
    If your problem has been solved mark this thread as solved.
     
  11. Offline

    ipodtouch0218

Thread Status:
Not open for further replies.

Share This Page