Hi guys ! I want to detect a command send by my other plugin, i tried the event "ServerCommandEvent" but it doesn't works. The code with the command: Code (Text): Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5286,81,3775"); my detection event: Code (Text): @EventHandler public void onBossCommandSummon(ServerCommandEvent event) throws IOException{ CommandSender s = event.getSender(); String c = event.getCommand(); Bukkit.broadcastMessage(" who is the sender: try :The sender is : " + s.getName() + " "); Bukkit.broadcastMessage("first step"); if (c.contains("mm mobs spawn Herobrine")){ Bukkit.broadcastMessage("2nde step"); Config.setValeur(true); } } } May you help me please, i don't find an other event for that :/
use PlayerCommandPreprocessEvent https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerCommandPreprocessEvent.html
I can't , the command is sending by the console, not by a player. Code (Text): @EventHandler public void onmort(EntityDeathEvent event){ Entity p = event.getEntity(); if (p instanceof PigZombie){ if (p.isCustomNameVisible()){ if (p.getWorld().getName().equals("world")){ Random r = new Random(); int aléatoire = r.nextInt(4); switch(aléatoire){ case 0: Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5286,81,3775"); String m = Bukkit.getConsoleSender().getName(); Bukkit.broadcastMessage(" " + m + " "); break; case 1: Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5286,81,3778"); break; case 2: Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5289,81,3778"); break; case 3: Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5289,81,3775"); break; case 4: Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5289,81,3775"); break; default:; break;
I wouldn't recommend doing it that way. A better way would be to create your own Event, call it when your command is executed, and then listen for that event in your plugin. The not-recommended way would be to listen to the PlayerCommandPreProcessEvent, which is called before the command is executed (meaning you have to check whether or not it was successful within your command and your listener). HIGHLY recommend using the method I suggested first.
I can't, cause i can't detect if my command is executed or not, the way with Code (Text): Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mm mobs spawn Herobrine 1 world,5286,81,3775"); doesn't works, i think the command is send by the plugin and not by the console, so i can't detect this command. I can't create an event too because the command is sending an other plugin, the detection event is in an other plugin. Could I not rather send a command directly from the console ?
Yes, because you're executing the command as the console it won't call the PlayerCommandPreProcessEvent. Use the method I suggested above, that's your best option.
i can't create an event cause the plugin detection is not the same with the plugin who send the command. "Yes, because you're executing the command as the console it won't call the PlayerCommandPreProcessEvent. Use the method I suggested above, that's your best option." No, my event is ServerCommandEvent, not PlayerCommandPreProcessEvent, that's not the same.
From the Java docs: "Example of incorrect uses are: Using this event to run command logic". The way you're trying to accomplish your goal doesn't fit with the standards defined by the API you're using. If you want our help, I suggest you conform to those standards and try implementing methods that fit within them.