Added JavaPlugin.getCommand

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2011-02-28 01:35:03 +00:00
parent 3eb015141a
commit 9c2782bea7
2 changed files with 34 additions and 0 deletions

View file

@ -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;
}
}

View file

@ -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;
}
}
}