Is there any way to make sure the command of my plugin is being handled instead of the same command in another plugin? I'm currently experiencing conflicts on an rather unused command, and my command is being used alot on the server. Yeah, I know i can change the command in the plugin.yml, but its rather more useful to at least know how to change the priority's
I have the same problem. My plugin over9000homes uses getCommands("...").setExecutor(), but priority of my handler is less than Essentials'. So how I can fix this problem or I must rewrite this with raw onCommand?
You can't set priorities for commands, I think it depends on when the plugin loads (thus who registers the commands first). To force the command, you could use PLAYER_COMMAND_PREPROCESS-event, but that is a really bad way of doing it. So rather change the cmd-name (and use the old name as an alias), that is far easier and makes it more compatible.
Yup, I made a plugin called "area chatter" and it was run firstly. You can try to name your plugin starting with a (or a digit).
That sucks... Maybe idea with "mhome" command name and alias is the best now. P.S. I hope Bukkit Team will add priority features.
No. It's very bad way, read manuals. Um... why doesn't Bukkit support aliases for commands? My problem is still alive (sry for my bad English ), I don't want other commands like /msethome or /mhome, I want /sethome and /home, but I can't because Essentials aren't compatible. I believe that way must be. P.S. I hate plugins like Essentials (lol sry developer), that provide all the features but still many players use them. P.P.S. So maybe really use commands preprocess? Dunno... EDIT by Moderator: merged posts, please use the edit button instead of double posting.
I read the bukkit source code to understand how it deal with commands. For the aliases, first registered is the only registered. For command, if the same command is found (imagine Essentials with his /home is registered before your /home command), the command is renamed to PluginName:home. ONLY for command, there is no auto-rename for aliases. About Essentials, if he detect that a another plugin have registered the same command has it, it fallback to the plugin. Meaning, if you /home is a command, Essentials will take the "lead" see that your plugin have that command and launch YOUR command instead of its. You can easily check if your command is registered and have the priority : Code:java plugin.getServer().getPluginCommand("CommandName").equals(plugin.getCommand("CommandName")) ; You can't register or unregister command (too bad).
Strange because in the Essentials Source Code you can see that : Code:java if (!getSettings().isCommandOverridden(command.getName()) && !commandLabel.startsWith("e")) { for (Plugin p : getServer().getPluginManager().getPlugins()) { if (p.getDescription().getMain().contains("com.earth2me.essentials")) { continue; } PluginDescriptionFile desc = p.getDescription(); if (desc == null) { continue; } if (desc.getName() == null) { continue; } PluginCommand pc = getServer().getPluginCommand(desc.getName() + ":" + commandLabel); if (pc != null) { return pc.execute(sender, commandLabel, args); } } } Meaning that if you command as not be configured in Essentials to be only used with it, it's falling back to your plugin. Only if it was the same command (and not an alias)
I don't know... Here is my plugin.yml: Code: name: over9000homes main: me.uhehesh.over9000homes.over9000homes version: 1.13 commands: sethome: description: Set home. usage: /sethome (home) (player) home: description: Go home. usage: /home (home) (player) deletehome: description: Delete home. usage: /deletehome (home) (player) over9000homes: description: hehe. usage: /over9000homes transferhomes: description: transfer all homes, MultipleHomes to over9000homes. usage: /transferhomes <path> homelist: description: list all homes. usage: /homelist (page) (player) And I use getCommand(...).setExecutor(...).
I have successfully overwritten the /afk command of Essentials in my SimpleAFK Plugin. I just had to make sure that I have an additional onCommand() method in my main class (in addition to my CommandHandler class). So I am registering commands in my onEnable() method (as you can see assigned to the "sAfkCommandHandler" class which does the actual command handling): Code: public void onEnable() { ... getCommand("afk").setExecutor(new sAfkCommandHandler(this)); getCommand("isafk").setExecutor(new sAfkCommandHandler(this)); getCommand("afklist").setExecutor(new sAfkCommandHandler(this)); ... } Then I just needed another onCommand method in my Main Class which "reregisters" and executes a command. That way it runs my command instead of the Essentials one: Code: public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]) { if(cmd.getName().equalsIgnoreCase("afk") || cmd.getName().equalsIgnoreCase("isafk") || cmd.getName().equalsIgnoreCase("afklist")) { try { PluginCommand command = getCommand(cmd.getName().toLowerCase()); command.setExecutor(new sAfkCommandHandler(this)); command.execute(sender, commandLabel, args); } catch(CommandException e) { log.warning(e.getMessage()); } return true; } else { return false; } } EDIT: I know I have to optimize my code a bit so it doesn't create new CommandHandler objects all the time... Thats what I am (amongst others) currently working on
@bassfader I have an other idea that could works : Add a softdepend that don't exists (like BLAH) to your plugin, to be sure it will be the last loaded. do Code:java PluginCommand plgCmd = plugin.getServer().getPluginCommand("commandYouWantToOverride");if(plgCmd.getPlugin().getDescription().getName().equal("Essentials")) plgCmd.setExecutor(CommandExecutorClass); and then every time the Essentials command is used, it will automatically use your command instead. Because the only check done before executing the command, is to check if the owning plugin is enable. @Adamki11s : aliases is not a real solution, command have the priority on alias.
Thanks for answers! It seems that my plugin isn't conflicting with Essentials. I'll try this later on other server later.