Solved PlayerCommandPreprocessEvent firing twice

Discussion in 'Plugin Development' started by r0llingthund3r, Jun 17, 2014.

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

    r0llingthund3r

    So I'm working on a command spy that checks all commands used against a blacklist and alerts the staff accordingly. This is what I have so far.
    Code:
    public class CommandSpy implements Listener{
       
        public CommandSpy(ThunderSuite plugin){
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
       
        public boolean checkCommand(String message){
            for (String key : ConfigManager.get("command_blacklist.yml").getConfigurationSection("commands").getKeys(false)){
                if(message.startsWith(key)){
                    return true;
                }
            }   
            return false;
        }
       
        @EventHandler
        public void onPlayerChatEvent(PlayerCommandPreprocessEvent e){
            if(checkCommand(e.getMessage())){
                Bukkit.getServer().broadcastMessage(ChatColor.RED + "[CommandSpy] " + ChatColor.GREEN + " " + e.getPlayer().getName() + " has used the command " + e.getMessage());
            }
        }
    }
    
    Everything is working but for whatever reason PlayerCommandPreprocessEvent is firing twice when it should only be firing once resulting in this.
    Example - [CommandSpy] r0llingthund3r has used the command /op
    r0llingthund3r has used the command /op​
    I have no idea why it would be doing this.
     
  2. Offline

    1Rogue

    Check to see if you have something else re-firing a command in your code, and test with only your plugin.
     
  3. Offline

    r0llingthund3r

    I can't find anywhere in my code where it's re-firing a command and the command itself is not what is being fired twice. If I typed /op and it was found on the black list, it would alert the staff members twice but only attempt to /op once. I'm still thoroughly stumped...
     
  4. Offline

    xTigerRebornx

    r0llingthund3r I doubt the event is firing twice, have you registered your listener twice?
    Can you show your class that extends JavaPlugin?
     
  5. Offline

    r0llingthund3r

    Yup that was it. I had my listener registered twice. Thank you very much for your help.
     
Thread Status:
Not open for further replies.

Share This Page