Search in sources :

Example 6 with PluginCommand

use of org.bukkit.command.PluginCommand in project Essentials by drtshock.

the class AlternativeCommandsHandler method addPlugin.

public final void addPlugin(final Plugin plugin) {
    if (plugin.getDescription().getMain().contains("com.earth2me.essentials")) {
        return;
    }
    final List<Command> commands = PluginCommandYamlParser.parse(plugin);
    final String pluginName = plugin.getDescription().getName().toLowerCase(Locale.ENGLISH);
    for (Command command : commands) {
        final PluginCommand pc = (PluginCommand) command;
        final List<String> labels = new ArrayList<>(pc.getAliases());
        labels.add(pc.getName());
        PluginCommand reg = ess.getServer().getPluginCommand(pluginName + ":" + pc.getName().toLowerCase(Locale.ENGLISH));
        if (reg == null) {
            reg = ess.getServer().getPluginCommand(pc.getName().toLowerCase(Locale.ENGLISH));
        }
        if (reg == null || !reg.getPlugin().equals(plugin)) {
            continue;
        }
        for (String label : labels) {
            List<PluginCommand> plugincommands = altcommands.get(label.toLowerCase(Locale.ENGLISH));
            if (plugincommands == null) {
                plugincommands = new ArrayList<>();
                altcommands.put(label.toLowerCase(Locale.ENGLISH), plugincommands);
            }
            boolean found = false;
            for (PluginCommand pc2 : plugincommands) {
                if (pc2.getPlugin().equals(plugin)) {
                    found = true;
                }
            }
            if (!found) {
                plugincommands.add(reg);
            }
        }
    }
}
Also used : Command(org.bukkit.command.Command) PluginCommand(org.bukkit.command.PluginCommand) PluginCommand(org.bukkit.command.PluginCommand)

Example 7 with PluginCommand

use of org.bukkit.command.PluginCommand in project Bukkit by Bukkit.

the class JavaPlugin method getCommand.

/**
     * Gets the command with the given name, specific to this plugin. Commands
     * need to be registered in the {@link PluginDescriptionFile#getCommands()
     * PluginDescriptionFile} to exist at runtime.
     *
     * @param name name or alias of the command
     * @return the plugin command 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(description.getName().toLowerCase() + ":" + alias);
    }
    if (command != null && command.getPlugin() == this) {
        return command;
    } else {
        return null;
    }
}
Also used : PluginCommand(org.bukkit.command.PluginCommand)

Aggregations

PluginCommand (org.bukkit.command.PluginCommand)7 Command (org.bukkit.command.Command)3 Field (java.lang.reflect.Field)2 SimpleCommandMap (org.bukkit.command.SimpleCommandMap)2 URLClassLoader (java.net.URLClassLoader)1 Date (java.util.Date)1 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 Plugin (org.bukkit.plugin.Plugin)1 PluginManager (org.bukkit.plugin.PluginManager)1 SimplePluginManager (org.bukkit.plugin.SimplePluginManager)1