Solved Command Spy failing.

Discussion in 'Spigot Plugin Development' started by DecisionsYT, May 12, 2016.

Thread Status:
Not open for further replies.
  1. Hey!

    This is the command spy. When I do /cmdspy on it works perfectly, however it doesn't show me the commands that players run. Any suggestions?


    Code (Text):
    package ChatFilter;

    import java.util.ArrayList;
    import java.util.List;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerCommandPreprocessEvent;

    import me.DecisionsYT.Main;

    public class CmdSpy implements Listener, CommandExecutor {
    Main plugin;
        public CmdSpy(Main passedPlugin) {
            this.plugin = passedPlugin;

        List<Player> spyActivated = new ArrayList<Player>();
          public void onCmdSpy(PlayerCommandPreprocessEvent ev) {
            for (Player p : this.spyActivated) {
              p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Format").replace("{player}", ev.getPlayer().getName()).replace("{command}", ev.getMessage())));

      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        Player player = (Player)sender;
        if (args.length == 0) {
            sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Usage")));
        else if (args.length == 1) {
            if (player.hasPermission("ChatX.CmdSpy")) {
                if (args[0].equalsIgnoreCase("On")) {
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Enabled")));
        if (args.length == 1) {
        if (args[0].equalsIgnoreCase("Off")) {
                if (player.hasPermission("ChatX.CmdSpy")) {
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Disabled")));
            if (!player.hasPermission("ChatX.CmdSpy")) {
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("No-Perm-Message")));
        return true;
  2. Have you registered the event? And have you tried adding debug messages around your code to make sure the event is actually getting triggered?
  3. I'll do some debug messages and the event is registered

    Sent from my iPod touch using Tapatalk
  4. Privacy invading command spys :(
  5. ??

    Sent from my iPod touch using Tapatalk
  6. Like @Hunky524 mentioned: have you registered the listener? You passed in a plugin instance, so I'd assume you'd like to register it within your constructor using that instance?
  7. Correct

    Sent from my iPod touch using Tapatalk
  8. Okay, having done debugging messages, These are the results as follows:

    /Cmdspy - Works perfectly fine
    /Cmdspy on - NOT triggering the event
    /Cmdspy off - NOT triggering the event
  9. Your indentation and spacing makes it impossible to read
  10. Not impossible if these people can read it :p
  11. Error in console?
  12. Nope, the /cmdspy (ON and OFF) are not linking to the event
  13. What event?
  14. Code (Text):
          public void onCmdSpy(PlayerCommandPreprocessEvent e) {
            for (Player player : this.spyActivated) {
              player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Format").replace("{player}", e.getPlayer().getName()).replace("{command}", e.getMessage())));

    Look just below the imports
  15. Any suggestions anybody??
  16. I would have helped if you weren't so impatient :p you're not allowed any less than a 1 day bump, and definitely not an 8 minute one.
  17. Sozies
  18. t'is alright. but in response to the original thread, you need to register the listener in an onEnable method :p
  19. That event will be fired when anything is executed that looks like a command. You yourself need to process it. Example usage shown here.
Thread Status:
Not open for further replies.