Hi I have written a plugin, that should modify the output of plugins, but i don't know how i can override the existing /plugins cmd from bukkit. I testet PlayerCommandPreprocess but that dont works. Any ideas?
How could that not work, just check if the command is plugins, of one of its aliases, and if it is that, cancel the event, that should work, and after you canceled the event you just send the player your own message.
i.d.k, i use this but that dosen't works: Code: @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerCommandPreprocess(PlayerChatEvent event){ if(event.getMessage().startsWith("/plugins") || event.getMessage().startsWith("/pl") || event.getMessage().startsWith("/plug")){ String args[] = event.getMessage().replaceFirst("/plugins ", "").replaceFirst("/plugins", "").replaceFirst("/pl ", "").replaceFirst("/pl", "").replaceFirst("/plug ", "").replaceFirst("/plug", "").split(" "); //do work event.setCancelled(true); } }
I do this for one of my plugins: Code: String[] args = message.split(" "); if (Arrays.asList(args).get(0).equalsIgnoreCase("/plugins") { //Code }
If you really don't want to just take away the permission that lets players use /plugins, just use this Code: @EventHandler public void onPlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent event) { if(event.getMessage().toLowerCase().startsWith("/pl")) { event.setCancelled(true); } } Of course since you would be using startsWith(), anything else that starts with "pl" would also be canceled.
Or you could use Firefly 's code above, and use an "or" for the case of someone using /pl. That would eliminate that issue entirely, since as far as I know, /plugins and /pl are the only aliases that goes by.
Now i use this: Code: @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event){ String args[] = event.getMessage().split(" "); if(args[0].toLowerCase() == "/plugins" || args[0].toLowerCase() == "/pl"){ onCommand(event.getPlayer(), null, null, args); event.setCancelled(true); } } but i triggers the event when i type "/plgshdj" and i want only while type "/plugins" or "/pl".
Don't use toLowerCase() that often, store its result. You should use .equals() to check that... or even .equalsIgnoreCase() and you can skip the .toLowerCase() part. Also, why do you trigger onCommand() ? But why are you guys ignoring the fact that you can just revoke the permission for /plugins command like ferrybig said above ? That won't require any plugin and it's alot easier to do... just revoke "bukkit.command.plugins" permission.
Now i use the Code below but /plttt oder /plaaa .... triggers "event.setCancelled(true);" but i don't know why Code: @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event){ String args[] = event.getMessage().split(" "); if(args[0].equalsIgnoreCase("/plugins") || args[0].equalsIgnoreCase("/pl")){ //this event.setCancelled(true); } }