mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-02 17:32:03 +01:00
Added JavaPlugin.getCommand
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
3eb015141a
commit
9c2782bea7
2 changed files with 34 additions and 0 deletions
|
@ -32,4 +32,13 @@ public final class PluginCommand extends Command {
|
|||
public void setExecutor(CommandExecutor executor) {
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the owner of this PluginCommand
|
||||
*
|
||||
* @return Plugin that owns this command
|
||||
*/
|
||||
public Plugin getPlugin() {
|
||||
return owningPlugin;
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import org.bukkit.Server;
|
|||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginLoader;
|
||||
|
@ -158,7 +159,31 @@ public abstract class JavaPlugin implements Plugin {
|
|||
return initialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the command with the given name, specific to this plugin
|
||||
*
|
||||
* @param name Name or alias of the command
|
||||
* @return PluginCommand if found, otherwise null
|
||||
*/
|
||||
public PluginCommand getCommand(String name) {
|
||||
String alias = name.toLowerCase();
|
||||
PluginCommand command = getServer().getPluginCommand(alias);
|
||||
|
||||
if ((command != null) && (command.getPlugin() != this)) {
|
||||
command = getServer().getPluginCommand(getDescription().getName().toLowerCase() + ":" + alias);
|
||||
}
|
||||
|
||||
if ((command != null) && (command.getPlugin() == this)) {
|
||||
return command;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue