use of org.bukkit.command.PluginIdentifiableCommand in project TotalFreedomMod by TotalFreedom.
the class Module_help method getBody.
@Override
public String getBody() {
final CommandMap map = CommandReflection.getCommandMap();
if (map == null || !(map instanceof SimpleCommandMap)) {
return paragraph("Error loading commands.");
}
final StringBuilder responseBody = new StringBuilder().append(heading("Command Help", 1)).append(paragraph("This page is an automatically generated listing of all plugin commands that are currently live on the server. " + "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<>();
for (Command command : knownCommands) {
String pluginName = "Bukkit";
if (command instanceof PluginIdentifiableCommand) {
pluginName = ((PluginIdentifiableCommand) command).getPlugin().getName();
}
List<Command> pluginCommands = commandsByPlugin.get(pluginName);
if (pluginCommands == null) {
pluginCommands = Lists.newArrayList();
commandsByPlugin.put(pluginName, pluginCommands);
}
pluginCommands.add(command);
}
final Iterator<Map.Entry<String, List<Command>>> it = commandsByPlugin.entrySet().iterator();
while (it.hasNext()) {
final Map.Entry<String, List<Command>> entry = it.next();
final String pluginName = entry.getKey();
final List<Command> commands = entry.getValue();
Collections.sort(commands, new CommandComparator());
responseBody.append(heading(pluginName, 2)).append("<ul>\r\n");
Displayable lastTfmCommandLevel = null;
for (Command command : commands) {
if (!TotalFreedomMod.pluginName.equals(pluginName)) {
responseBody.append(buildDescription(command));
continue;
}
Displayable tfmCommandLevel = FreedomCommand.getFrom(command).getPerms().level();
if (lastTfmCommandLevel == null || lastTfmCommandLevel != tfmCommandLevel) {
responseBody.append("</ul>\r\n").append(heading(tfmCommandLevel.getName(), 3)).append("<ul>\r\n");
}
lastTfmCommandLevel = tfmCommandLevel;
responseBody.append(buildDescription(command));
}
responseBody.append("</ul>\r\n");
}
return responseBody.toString();
}
use of org.bukkit.command.PluginIdentifiableCommand in project commands by aikar.
the class BukkitCommandManager method registerCommand.
public void registerCommand(BaseCommand command, boolean force) {
final String plugin = this.plugin.getName().toLowerCase();
command.onRegister(this);
for (Map.Entry<String, RootCommand> entry : command.registeredCommands.entrySet()) {
String commandName = entry.getKey().toLowerCase();
BukkitRootCommand bukkitCommand = (BukkitRootCommand) entry.getValue();
if (!bukkitCommand.isRegistered) {
Command oldCommand = commandMap.getCommand(commandName);
if (oldCommand instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) oldCommand).getPlugin() == this.plugin) {
knownCommands.remove(commandName);
oldCommand.unregister(commandMap);
} else if (oldCommand != null && force) {
knownCommands.remove(commandName);
for (Map.Entry<String, Command> ce : knownCommands.entrySet()) {
String key = ce.getKey();
Command value = ce.getValue();
if (key.contains(":") && oldCommand.equals(value)) {
String[] split = ACFPatterns.COLON.split(key, 2);
if (split.length > 1) {
oldCommand.unregister(commandMap);
oldCommand.setLabel(split[0] + ":" + command.getName());
oldCommand.register(commandMap);
}
}
}
}
commandMap.register(commandName, plugin, bukkitCommand);
}
bukkitCommand.isRegistered = true;
registeredCommands.put(commandName, bukkitCommand);
}
}
Aggregations