Reputation: 318
I have this command in my plugin yml:
rankup:
description: Allows to rankup through the prison ranks
aliases: [ru]
However there is a configuration file for disabling commands and if you disable this command:
rankupstrue: false
I need to keep that in the plugin yml in case this boolean is set to true in the configuration file. However, if they disable this I return on the onCommand boolean before anything happens, like so:
public boolean onCommand(CommandSender s, Command cmd, String label, String[] args){
if(main.getConfig().getBoolean("rankupstrue"))return true;
// code
}
I then enable it here in the onEnable
getCommand("rankup").setExecutor(new RankupCore(this, qm));
However if the boolean that disables this command is set to false and an alternative plugin has the same command, the alternative plugin's command will not work. To fix this I have tried to stop enabling it in the onEnable:
if(main.getConfig().getBoolean("rankupstrue"))
{
// getCommand
}
However this brings me the same result. I then default back to the plugin yml. Is there a way to remove:
rankup:
description: Allows to rankup through the prison ranks
aliases: [ru]
from the plugin yml if rankupstrue
is false?
Or is there a way to add that to the plugin yml if that boolean is true?
Or is there a way to block out this command in any way besides the plugin yml?
Upvotes: 1
Views: 1462
Reputation: 1
To answer this clearly, use the event specified PlayerCommandPreprocessEvent
and make sure that is valid using the e.getMessage()
method. What I would do is create a space "parser" to create an argument like feel.
public void onCommandEvent(PlayerCommandPreprocessEvent e) {
Player player = e.getPlayer();
String message = e.getMessage();
String[] args = message.split(" ");
if(args[0] == "command") {
print(args[1]); // Prints the first argument
}
}
Now another thing you would need to do is check the argument length with args.length() which would return an integer of the length. I didn't add this because this is only an example.
Upvotes: 0
Reputation: 318
To fix this problem you would use PlayerCommandPreprocessEvent
and check if the command is equal to the command that is doing this problem. Make sure you cancel the event after you check to make sure.
// in the event
if(e.getMessage().equalsIgnoreCase("command"))e.setCancelled(true);
Upvotes: -1
Reputation: 228
Never put the command in the YAML.
There is no true way to remove a command from the plugin.yml. You're more likely to break a lot of things instead. Listen to the PlayerCommandPreprocessEvent
and if the command has the name you want plus a true rankupstrue value, cancel the calling of the command and using the values of the event, construct your own event. Use the getPlayer()
and getMessage()
methods of the event to do this.
Upvotes: -1