Collection<Command> commands = server.getCommandMap().getCommands();
@Override public List<MCCommand> getCommands() { List<MCCommand> cmds = new ArrayList<>(); for(Command c : scm.getCommands()) { cmds.add(new BukkitMCCommand(c)); } return cmds; }
public Collection<org.bukkit.command.Command> getServerCommands() { CommandMap commandMap = ReflectionUtil.getField(CommandBook.server().getPluginManager(), "commandMap"); if (commandMap == null) { return Collections.emptySet(); } Set<org.bukkit.command.Command> cmds = new HashSet<org.bukkit.command.Command>(); cmds.addAll(((SimpleCommandMap)commandMap).getCommands()); return cmds; }
/** * Get all Command instances, that NCP can get hold of. Attempt to get a SimpleCommandMap instance from the server to get the actually registered commands, but also get commands from JavaPlugin instances. * @return */ public static Collection<Command> getCommands() { final Collection<Command> commands = new LinkedHashSet<Command>(500); // All (?) commands from the SimpleCommandMap of the server, if available. final CommandMap commandMap = getCommandMap(); if (commandMap != null && commandMap instanceof SimpleCommandMap) { commands.addAll(((SimpleCommandMap) commandMap).getCommands()); } // TODO: Fall-back for Vanilla / CB commands? [Fall-back should be altering permission defaults, though negating permissions is the right way.] // Fall-back: plugin commands. for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) { if (plugin instanceof JavaPlugin) { final JavaPlugin javaPlugin = (JavaPlugin) plugin; final Map<String, Map<String, Object>> map = javaPlugin.getDescription().getCommands(); if (map != null) { for (String label : map.keySet()) { Command command = javaPlugin.getCommand(label); if (command != null) { commands.add(command); } } } } } return commands; }
+ "Please note that it does not include vanilla server commands.")); final Collection<Command> knownCommands = ((SimpleCommandMap) map).getCommands(); final Map<String, List<Command>> commandsByPlugin = new HashMap<>();
public static Map<String, MonitorRecord> getCommandTimingsByPlugin(Plugin plg) { Map<String, MonitorRecord> record = new HashMap<>(); if (plg == null) { return record; } try { SimpleCommandMap simpleCommandMap = Reflection.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class).get(Bukkit.getPluginManager()); for (Command command : simpleCommandMap.getCommands()) { if (command instanceof PluginCommand) { PluginCommand pluginCommand = (PluginCommand) command; if (plg.equals(pluginCommand.getPlugin())) { FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class, "executor", CommandExecutor.class); CommandExecutor executor = commandField.get(pluginCommand); if (executor instanceof CommandInjector) { CommandInjector commandInjector = (CommandInjector) executor; record = mergeRecordMap(record, commandInjector.getMonitorRecordMap()); } } } } } catch (Exception e) { e.printStackTrace(); } return record; }
public static void inject(Plugin plg) { if (plg != null) { try { SimpleCommandMap simpleCommandMap = Reflection.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class).get(Bukkit.getPluginManager()); for (Command command : simpleCommandMap.getCommands()) { if (command instanceof PluginCommand) { PluginCommand pluginCommand = (PluginCommand) command; if (plg.equals(pluginCommand.getPlugin())) { FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class, "executor", CommandExecutor.class); FieldAccessor<TabCompleter> tabField = Reflection.getField(PluginCommand.class, "completer", TabCompleter.class); CommandInjector commandInjector = new CommandInjector(plg, commandField.get(pluginCommand), tabField.get(pluginCommand)); commandField.set(pluginCommand, commandInjector); tabField.set(pluginCommand, commandInjector); } } } } catch (Exception e) { e.printStackTrace(); } } }
public static void uninject(Plugin plg) { if (plg != null) { try { SimpleCommandMap simpleCommandMap = Reflection.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class).get(Bukkit.getPluginManager()); for (Command command : simpleCommandMap.getCommands()) { if (command instanceof PluginCommand) { PluginCommand pluginCommand = (PluginCommand) command; if (plg.equals(pluginCommand.getPlugin())) { FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class, "executor", CommandExecutor.class); FieldAccessor<TabCompleter> tabField = Reflection.getField(PluginCommand.class, "completer", TabCompleter.class); CommandExecutor executor = commandField.get(pluginCommand); if (executor instanceof CommandInjector) { commandField.set(pluginCommand, ((CommandInjector) executor).getCommandExecutor()); } TabCompleter completer = tabField.get(pluginCommand); if (completer instanceof CommandInjector) { tabField.set(pluginCommand, ((CommandInjector) completer).getTabCompleter()); } } } } } catch (Exception e) { e.printStackTrace(); } } }