diff --git a/paper-api/src/main/java/org/bukkit/command/PluginCommand.java b/paper-api/src/main/java/org/bukkit/command/PluginCommand.java index 33e1a9b67a..22087ff913 100644 --- a/paper-api/src/main/java/org/bukkit/command/PluginCommand.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/plugin/java/JavaPlugin.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPlugin.java index da78e91cab..5a59f9766e 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPlugin.java +++ b/paper-api/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; + } + } }