Java Code Examples for org.bukkit.command.PluginCommand#setAliases()

The following examples show how to use org.bukkit.command.PluginCommand#setAliases() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginHelper.java    From PlayerSQL with GNU General Public License v2.0 8 votes vote down vote up
@SneakyThrows
public static void addExecutor(Plugin plugin, Command command) {
    Field f = SimplePluginManager.class.getDeclaredField("commandMap");
    f.setAccessible(true);
    CommandMap map = (CommandMap) f.get(plugin.getServer().getPluginManager());
    Constructor<PluginCommand> init = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
    init.setAccessible(true);
    PluginCommand inject = init.newInstance(command.getName(), plugin);
    inject.setExecutor((who, __, label, input) -> command.execute(who, label, input));
    inject.setAliases(command.getAliases());
    inject.setDescription(command.getDescription());
    inject.setLabel(command.getLabel());
    inject.setName(command.getName());
    inject.setPermission(command.getPermission());
    inject.setPermissionMessage(command.getPermissionMessage());
    inject.setUsage(command.getUsage());
    map.register(plugin.getName().toLowerCase(), inject);
}
 
Example 2
Source File: ScriptCommand.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
private PluginCommand setupBukkitCommand() {
	try {
		final Constructor<PluginCommand> c = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
		c.setAccessible(true);
		final PluginCommand bukkitCommand = c.newInstance(name, Skript.getInstance());
		bukkitCommand.setAliases(aliases);
		bukkitCommand.setDescription(description);
		bukkitCommand.setLabel(label);
		bukkitCommand.setPermission(permission);
		// We can only set the message if it's simple (doesn't contains expressions)
		if (permissionMessage.isSimple())
			bukkitCommand.setPermissionMessage(permissionMessage.toString(null));
		bukkitCommand.setUsage(usage);
		bukkitCommand.setExecutor(this);
		return bukkitCommand;
	} catch (final Exception e) {
		Skript.outdatedError(e);
		throw new EmptyStacktraceException();
	}
}
 
Example 3
Source File: BukkitPlugin.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
private void loadcmds()
{
    PluginCommand command;
    try
    {
        Constructor<PluginCommand> ctor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
        ctor.setAccessible(true);
        command = ctor.newInstance("bungeeperms", this);
    }
    catch (Exception e)
    {
        System.err.println("Failed to register BungeePerms command!");
        e.printStackTrace();
        return;
    }
    command.setExecutor(new CmdExec());
    command.setAliases(conf.isAliasCommand() ? Arrays.asList("bp") : new ArrayList());
    command.setPermission(null);

    getCommandMap().register("bungeeperms", command);
}
 
Example 4
Source File: CommandManager.java    From DiscordBot with Apache License 2.0 4 votes vote down vote up
public void registerCommand(String... aliases) {
	PluginCommand pluginCommand = getCommand(aliases[0], DiscordBot.getInstance());
	pluginCommand.setAliases(Arrays.asList(aliases));
	getCommandMap().register(DiscordBot.getInstance().getDescription().getName(), pluginCommand);
}