use of org.bukkit.command.SimpleCommandMap 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.SimpleCommandMap in project SpaciousLib by anhcraft.
the class SPlugin method unloadPlugin.
public static boolean unloadPlugin(Plugin plugin) throws NoSuchFieldException, IllegalAccessException, IOException {
String name = plugin.getName();
PluginManager pluginManager = Bukkit.getPluginManager();
SimpleCommandMap commandMap = null;
List<Plugin> plugins = null;
Map<String, Plugin> names = null;
Map<String, Command> commands = null;
disablePlugin(plugin);
if (pluginManager != null) {
Field pluginsField = Bukkit.getPluginManager().getClass().getDeclaredField("plugins");
Field lookupNamesField = Bukkit.getPluginManager().getClass().getDeclaredField("lookupNames");
Field commandMapField = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");
Field commandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
commandsField.setAccessible(true);
pluginsField.setAccessible(true);
commandMapField.setAccessible(true);
lookupNamesField.setAccessible(true);
commandMap = (SimpleCommandMap) commandMapField.get(pluginManager);
commands = (Map<String, Command>) commandsField.get(commandMap);
plugins = (List<Plugin>) pluginsField.get(pluginManager);
names = (Map<String, Plugin>) lookupNamesField.get(pluginManager);
}
if (plugins != null && plugins.contains(plugin)) {
plugins.remove(plugin);
}
if (names != null && names.containsKey(name)) {
names.remove(name);
}
if (commandMap != null) {
for (Iterator<Map.Entry<String, Command>> it = commands.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, Command> entry = it.next();
if (entry.getValue() instanceof PluginCommand) {
PluginCommand c = (PluginCommand) entry.getValue();
if (c.getPlugin() == plugin) {
c.unregister(commandMap);
it.remove();
}
}
}
}
ClassLoader cl = plugin.getClass().getClassLoader();
if (cl instanceof URLClassLoader) {
((URLClassLoader) cl).close();
}
System.gc();
return true;
}
Aggregations