public static boolean isFakeNijiPerms(Plugin plugin) { PluginCommand permsCommand = Bukkit.getServer().getPluginCommand("permissions"); return permsCommand == null || !(permsCommand.getPlugin().equals(plugin)); }
/** * 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; } }
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; } }
@Override public MCPlugin getPlugin() { if(!(cmd instanceof PluginCommand)) { return null; } Plugin plugin = ((PluginCommand) cmd).getPlugin(); if(plugin == null) { return null; } return new BukkitMCPlugin(plugin); }
private void disguisedPlugin() { linkClasses.forEach(clazz -> disguisedPlugin(clazz, (JavaPlugin) registerCommand.getPlugin())); }
/** * Gets all of the aliases known for the given command. * * <p>This will include the main label, as well as defined aliases, and * aliases including the fallback prefix added by Bukkit.</p> * * @param command the command * @return the aliases */ static Collection<String> getAliases(Command command) { Stream<String> aliasesStream = Stream.concat( Stream.of(command.getLabel()), command.getAliases().stream() ); if (command instanceof PluginCommand) { String fallbackPrefix = ((PluginCommand) command).getPlugin().getName().toLowerCase().trim(); aliasesStream = aliasesStream.flatMap(alias -> Stream.of( alias, fallbackPrefix + ":" + alias )); } return aliasesStream.distinct().collect(Collectors.toList()); }
/** * 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; } }
TabooLib.debug("Registered " + (methods.size() + fields.size()) + " sub-command with " + baseMainCommand.getRegisterCommand().getName() + " (" + baseMainCommand.getRegisterCommand().getPlugin().getName() + ")");
if (entry.getValue() instanceof PluginCommand) { PluginCommand c = (PluginCommand) entry.getValue(); if (c.getPlugin() == plugin) { c.unregister(commandMap); it.remove();
if (entry.getValue() instanceof PluginCommand) { PluginCommand c = (PluginCommand) entry.getValue(); if (c.getPlugin() == plugin) { c.unregister(commandMap); it.remove();
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 void printCommandHelp(CommandSender sender, org.bukkit.command.Command cmd) { sender.sendMessage(ChatColor.YELLOW + "Command: " + cmd.getName()); final String aliases = cmd.getAliases().toString().replaceAll("\\[(.*)\\]", "$1"); if (aliases.length() > 0) { sender.sendMessage(ChatColor.YELLOW + "Aliases: " + aliases); } sender.sendMessage(ChatColor.YELLOW + "Description: " + cmd.getDescription()); sender.sendMessage(ChatColor.YELLOW + "Usage: " + cmd.getUsage()); if (cmd instanceof PluginCommand) { sender.sendMessage(ChatColor.YELLOW + "Plugin: " + ((PluginCommand)cmd).getPlugin().getDescription().getName()); } else if (cmd instanceof DynamicPluginCommand) { sender.sendMessage(ChatColor.YELLOW + "Owner: " + ((DynamicPluginCommand) cmd).getOwner().getClass().getSimpleName()); } else if (cmd instanceof VanillaCommand) { sender.sendMessage(ChatColor.YELLOW + "Vanilla command"); } }
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(); } } }