diff options
author | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-02-28 01:35:03 +0000 |
---|---|---|
committer | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-02-28 01:35:03 +0000 |
commit | 2b1dc975f1d21c0cc3db363f53699380a85d2638 (patch) | |
tree | 1a5b76ba6dd6f60837d16457c1f7cf55e9ad589d /src/main/java | |
parent | f2d19008c986d833c55db1a5c6d6f6dcf698a0f1 (diff) | |
download | bukkit-2b1dc975f1d21c0cc3db363f53699380a85d2638.tar bukkit-2b1dc975f1d21c0cc3db363f53699380a85d2638.tar.gz bukkit-2b1dc975f1d21c0cc3db363f53699380a85d2638.tar.lz bukkit-2b1dc975f1d21c0cc3db363f53699380a85d2638.tar.xz bukkit-2b1dc975f1d21c0cc3db363f53699380a85d2638.zip |
Added JavaPlugin.getCommand
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/bukkit/command/PluginCommand.java | 9 | ||||
-rw-r--r-- | src/main/java/org/bukkit/plugin/java/JavaPlugin.java | 25 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/command/PluginCommand.java b/src/main/java/org/bukkit/command/PluginCommand.java index 33e1a9b6..22087ff9 100644 --- a/src/main/java/org/bukkit/command/PluginCommand.java +++ b/src/main/java/org/bukkit/command/PluginCommand.java @@ -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; + } }
\ No newline at end of file diff --git a/src/main/java/org/bukkit/plugin/java/JavaPlugin.java b/src/main/java/org/bukkit/plugin/java/JavaPlugin.java index da78e91c..5a59f976 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPlugin.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPlugin.java @@ -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; + } + } } |