public boolean register(List<CommandInfo> registered) { CommandMap commandMap = getCommandMap(); if (registered == null || commandMap == null) { return false; } for (CommandInfo command : registered) { DynamicPluginCommand cmd = new DynamicPluginCommand(command.getAliases(), command.getDesc(), "/" + command.getAliases()[0] + " " + command.getUsage(), executor, command.getRegisteredWith(), plugin); cmd.setPermissions(command.getPermissions()); commandMap.register(plugin.getDescription().getName(), cmd); } return true; }
@Override public boolean register(String fallbackPrefix, Command command) { if (isOurCommand(command)) { return super.register(fallbackPrefix, command); } else { return proxied.register(fallbackPrefix, command); } }
@Override public boolean register(String label, String fallbackPrefix, Command command) { if (isOurCommand(command)) { return super.register(label, fallbackPrefix, command); } else { return proxied.register(label, fallbackPrefix, command); } }
/** * Registerd one command * * @param command */ public void registerCommand(Command command) { try { Class<?> clazz = ReflectionUtil.reflectCraftClazz(".CraftServer"); CommandMap commandMap; if (clazz != null) commandMap = (CommandMap) clazz.getMethod("getCommandMap").invoke(Bukkit.getServer()); else commandMap = (CommandMap) Class.forName("net.glowstone.GlowServer").getMethod("getCommandMap").invoke(Bukkit.getServer()); commandMap.register("cloudnet", command); } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException | ClassNotFoundException e) { e.printStackTrace(); } }
public void register() throws NoSuchFieldException, IllegalAccessException { if (getName() == null || getDescription() == null || registered) return; final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap"); bukkitCommandMap.setAccessible(true); CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer()); commandMap.register(plugin.getDescription().getName(), this); registered = true; }
public void registerCommand(@NonNull CompositeCommand command) { commands.put(command.getLabel(), command); // Use reflection to obtain the commandMap method in Bukkit's server. try{ Field commandMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap"); commandMapField.setAccessible(true); CommandMap commandMap = (CommandMap) commandMapField.get(Bukkit.getServer()); String commandPrefix = "bentobox"; if (command.getAddon() != null) { commandPrefix = command.getAddon().getDescription().getName().toLowerCase(Locale.ENGLISH); } commandMap.register(commandPrefix, command); } catch(Exception exception){ Bukkit.getLogger().severe("Bukkit server commandMap method is not there! This means no commands can be registered!"); } }
/** * Registers a CommandExecutor with the server * * @param plugin the plugin instance * @param command the command instance * @param aliases the command aliases * @param <T> the command executor class type * @return the command executor */ @Nonnull public static <T extends CommandExecutor> T registerCommand(@Nonnull Plugin plugin, @Nonnull T command, @Nonnull String... aliases) { Preconditions.checkArgument(aliases.length != 0, "No aliases"); for (String alias : aliases) { try { PluginCommand cmd = COMMAND_CONSTRUCTOR.newInstance(alias, plugin); getCommandMap().register(plugin.getDescription().getName(), cmd); getKnownCommandMap().put(plugin.getDescription().getName().toLowerCase() + ":" + alias.toLowerCase(), cmd); getKnownCommandMap().put(alias.toLowerCase(), cmd); cmd.setLabel(alias.toLowerCase()); cmd.setExecutor(command); if (command instanceof TabCompleter) { cmd.setTabCompleter((TabCompleter) command); } } catch (Exception e) { e.printStackTrace(); } } return command; }
private void register() { if (pluginCommand == null) return; plugin.debug("Registering command " + name); try { Field f = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap"); f.setAccessible(true); Object commandMapObject = f.get(Bukkit.getPluginManager()); if (commandMapObject instanceof CommandMap) { CommandMap commandMap = (CommandMap) commandMapObject; commandMap.register(plugin.getName(), pluginCommand); } } catch (NoSuchFieldException | IllegalAccessException e) { plugin.getLogger().severe("Failed to register command"); plugin.debug("Failed to register plugin command"); plugin.debug(e); } }
/** * Registers a CommandExecutor with the server * * @param plugin the plugin instance * @param command the command instance * @param aliases the command aliases * @param <T> the command executor class type * @return the command executor */ @Nonnull public static <T extends CommandExecutor> T registerCommand(@Nonnull Plugin plugin, @Nonnull T command, @Nonnull String... aliases) { Preconditions.checkArgument(aliases.length != 0, "No aliases"); for (String alias : aliases) { try { PluginCommand cmd = COMMAND_CONSTRUCTOR.newInstance(alias, plugin); getCommandMap().register(plugin.getDescription().getName(), cmd); getKnownCommandMap().put(plugin.getDescription().getName().toLowerCase() + ":" + alias.toLowerCase(), cmd); getKnownCommandMap().put(alias.toLowerCase(), cmd); cmd.setLabel(alias.toLowerCase()); cmd.setExecutor(command); if (command instanceof TabCompleter) { cmd.setTabCompleter((TabCompleter) command); } } catch (Exception e) { e.printStackTrace(); } } return command; }
commandMap.register(commandName, plugin, bukkitCommand);
private void register() { try { Performer p = new Performer(this.overriding); if (this.aliases != null) { p.setAliases(this.aliases); } p.setPermissionMessage(Messages.getInstance().permission); Field f = Bukkit.getServer().getClass().getDeclaredField("commandMap"); f.setAccessible(true); CommandMap cmap = (CommandMap) f.get(Bukkit.getServer()); cmap.register("", p); p.setExecutor(this); } catch (Exception e) { if (FunnyGuildsLogger.exception(e.getCause())) { e.printStackTrace(); } } }
public static void registerCommand(String... aliases) { if (aliases != null) { PluginCommand command = getCommand(aliases[0], SimpleClans.getInstance()); if (command != null) { command.setAliases(Arrays.asList(aliases)); getCommandMap().register(SimpleClans.getInstance().getDescription().getName(), command); } } }
public boolean register(List<CommandInfo> registered) { CommandMap commandMap = getCommandMap(); if (registered == null || commandMap == null) { return false; } for (CommandInfo command : registered) { DynamicPluginCommand cmd = new DynamicPluginCommand(command.getAliases(), command.getDesc(), "/" + command.getAliases()[0] + " " + command.getUsage(), executor, completer, command.getRegisteredWith(), plugin); cmd.setPermissions(command.getPermissions()); commandMap.register(plugin.getDescription().getName(), cmd); } return true; }