Solved Event name being denied...

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

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

    When doing this event, the name (onCommand) is being denied and giving me the error of: http://prntscr.com/b382ch

    Why is the name being denied and why is the "e" at the end of that same line being denied. Any suggestions?
     
  2. you'll need to post more code. the most likely problem is that it's being encompassed by another method, either by wrong placement or by missing brackets.
     
  3. Not sure why, but I think You can just change the name of the event to something else, would be easier to truble shoot with more code
     
  4. It doesn't matter what name it is, it still has the same effect.
     
  5. 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.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    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();

      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         
        Player player = (Player)sender;
       
        @EventHandler
        public void commandEvent(PlayerCommandPreprocessEvent e) {
            for (Player staff : this.spyActivated)
              if (!staff.equals(e.getPlayer())) staff.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Format").replace("{player}", e.getPlayer().getName().replace("{command}", e.getMessage()))));
          }

       
       
       
       
        if (args.length == 0) {
            sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Usage")));
        }
       
        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 (player.hasPermission("ChatX.CmdSpy")) {
                if (args[0].equalsIgnoreCase("Off")) {
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Enabled")));
               
                }
            }
        }
       
       
       
       
       
        return true;
      }
    }
     
  6. Why are you passing an event inside a command?
     
  7. Why do you call this twice?

    Code (Text):
        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 (player.hasPermission("ChatX.CmdSpy")) {
                if (args[0].equalsIgnoreCase("Off")) {
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Enabled")));
           
                }
            }
        }
    And istead of alot of if statements down you should you else if


    This
     
  8. it's because it's placed inside the onCommand() method, which is not allowed by java standards.
    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.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    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();

      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")));
        }
     
        if (args.length == 1) {
            if (player.hasPermission("ChatX.CmdSpy")) {
                if (args[0].equalsIgnoreCase("On")) {
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Enabled")));
                     spyActivated.add(player.getUniqueId());
                }
            }
        }
     
        if (args.length == 1) {
            if (player.hasPermission("ChatX.CmdSpy")) {
                if (args[0].equalsIgnoreCase("Off")) {
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Enabled")));
                    spyActivated.remove(player.getUniqueId());
                }
            }
        }
     
     
     
     
     
        return true;
      }

      @EventHandler
        public void commandEvent(PlayerCommandPreprocessEvent e) {
            for (Player staff : this.spyActivated)
              if (!staff.equals(e.getPlayer())) staff.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("CmdSpy-Format").replace("{player}", e.getPlayer().getName().replace("{command}", e.getMessage()))));
          }
    }
     
  9. Yeah, I already questioned him doing that, it's weird...
     
  10. *Face Palm*

    Thanks!
     
  11. yep, ninja'd me :)
     
Thread Status:
Not open for further replies.