I know Im probably doing this wrong..as only commands I register in my plugin.yml is noticed by the plugin. Im guessing it would need "public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)" but not sure the way to use it correctly. what Im attempting to do is change my guest plugin..that promote people on the command /village..to include kicking people on using /give /fly ect.. here is a snippet of what I have as an example: Code: public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) { Player player = (Player)cs; String user1 = player.getName(); if (cmd.getName().equalsIgnoreCase("village")) { if (args.length != 0) { return false; } else { SetRank(cs); } } if (cmd.getName().equalsIgnoreCase("give")) { if (player.hasPermission("cmd.exempt")) { return false; } else { player.kickPlayer("Tried to use /GIVE"); } } the /village works well of course because Im calling out village in my plugin.yml. what would be the correct way to catch commands not defined in my plugin, and to preform actions when it sees it? for example /give /gamemode are all valid commands admin/ops can use. but wish to catch others trying it, and kick them to give them the idea that spamming that command 400 times wont help
Not sure but i think something like this: Code:java @EventHandlerpublic void cmd(PlayerCommandPreprocessEvent event) {if(event.getMessage() == "give") {event.setCancelled(true);event.getPlayer().kickPlayer("Tried to use /GIVE");}} would work... by the way u need: getServer().getPluginManager().registerEvents(this, this); in your onEnable if my code will be in your main class, but if it will be in another class add getServer().getPluginManager().registerEvents(new nameofotherclass(), this); to your onEnable and implements Listener in the public class part like this: http://wiki.bukkit.org/Introduction...em#Registering_Events_with_Plugin_as_Listener
would that work also the command was a full give command? like "/give 1 1 0" or only if they did the "/give" what I had also tried, trying to get it to work, kind of worked. but it looked for give in any command, even if someone did: "/msg bob hey bob can you give me a pickaxe?" it would see 'give' in the string of the command and kick them. which was bad, so dont seem I was doing it right that way either so if what you put would work for a command with arg long as it 'started' with /give that might be what I need! Think its getting closer but its not noticing the command name in the IF, no matter what I put Code:java @EventHandler public void cmd(PlayerCommandPreprocessEvent event) { Player player = event.getPlayer(); String cmd = event.getMessage(); player.sendMessage("CHECK " + cmd); if(event.getMessage() == "give") { player.sendMessage("PASSED"); event.setCancelled(true); event.getPlayer().kickPlayer("Tried to use /GIVE"); } } the above code gives the 'CHECK /give" response, so I know its checking it..but can try /give, /give dxwarlock 1 1, etc and it never makes it to the 'PASSED" remark. Figured out what I needed, need to do a split to get the first command sent..if anyone else needs it Code:java @EventHandlerpublic void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e){Player p = e.getPlayer();String user1 = p.getName();String[] cmd = e.getMessage().split(" ");if(!p.hasPermission("dx.cmd")) {if(cmd[0].equalsIgnoreCase("/give")){e.setCancelled(true);p.kickPlayer("Tried to use /GIVE");Bukkit.getServer().broadcastMessage(user1 + ChatColor.RED + " used command " + e.getMessage());}}} EDIT by Moderator: merged posts, please use the edit button instead of double posting.