use of org.bukkit.command.Command in project TotalFreedomMod by TotalFreedom.
the class Command_wildcard method run.
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0) {
return false;
}
Command runCmd = server.getPluginCommand(args[0]);
if (runCmd == null) {
msg("Unknown command: " + args[0], ChatColor.RED);
return true;
}
if (BLOCKED_COMMANDS.contains(runCmd.getName())) {
msg("Did you really think that was going to work?", ChatColor.RED);
return true;
}
String baseCommand = StringUtils.join(args, " ");
if (plugin.cb.isCommandBlocked(baseCommand, sender)) {
// CommandBlocker handles messages and broadcasts
return true;
}
for (Player player : server.getOnlinePlayers()) {
String runCommand = baseCommand.replaceAll("\\x3f", player.getName());
msg("Running Command: " + runCommand);
server.dispatchCommand(sender, runCommand);
}
return true;
}
use of org.bukkit.command.Command in project TotalFreedomMod by TotalFreedom.
the class CommandBlocker method load.
public void load() {
entryList.clear();
unknownCommands.clear();
final CommandMap commandMap = CommandReflection.getCommandMap();
if (commandMap == null) {
FLog.severe("Error loading commandMap.");
return;
}
@SuppressWarnings("unchecked") List<String> blockedCommands = (List<String>) ConfigEntry.BLOCKED_COMMANDS.getList();
for (String rawEntry : blockedCommands) {
final String[] parts = rawEntry.split(":");
if (parts.length < 3 || parts.length > 4) {
FLog.warning("Invalid command blocker entry: " + rawEntry);
continue;
}
final CommandBlockerRank rank = CommandBlockerRank.fromToken(parts[0]);
final CommandBlockerAction action = CommandBlockerAction.fromToken(parts[1]);
String commandName = parts[2].toLowerCase().substring(1);
final String message = (parts.length > 3 ? parts[3] : null);
if (rank == null || action == null || commandName == null || commandName.isEmpty()) {
FLog.warning("Invalid command blocker entry: " + rawEntry);
continue;
}
final String[] commandParts = commandName.split(" ");
String subCommand = null;
if (commandParts.length > 1) {
commandName = commandParts[0];
subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).trim().toLowerCase();
}
final Command command = commandMap.getCommand(commandName);
// Obtain command from alias
if (command == null) {
unknownCommands.add(commandName);
} else {
commandName = command.getName().toLowerCase();
}
if (entryList.containsKey(commandName)) {
FLog.warning("Not blocking: /" + commandName + " - Duplicate entry exists!");
continue;
}
final CommandBlockerEntry blockedCommandEntry = new CommandBlockerEntry(rank, action, commandName, subCommand, message);
entryList.put(blockedCommandEntry.getCommand(), blockedCommandEntry);
if (command != null) {
for (String alias : command.getAliases()) {
entryList.put(alias.toLowerCase(), blockedCommandEntry);
}
}
}
FLog.info("Loaded " + blockedCommands.size() + " blocked commands (" + (blockedCommands.size() - unknownCommands.size()) + " known).");
}
use of org.bukkit.command.Command in project Essentials by drtshock.
the class AlternativeCommandsHandler method addPlugin.
public final void addPlugin(final Plugin plugin) {
if (plugin.getDescription().getMain().contains("com.earth2me.essentials")) {
return;
}
final List<Command> commands = PluginCommandYamlParser.parse(plugin);
final String pluginName = plugin.getDescription().getName().toLowerCase(Locale.ENGLISH);
for (Command command : commands) {
final PluginCommand pc = (PluginCommand) command;
final List<String> labels = new ArrayList<>(pc.getAliases());
labels.add(pc.getName());
PluginCommand reg = ess.getServer().getPluginCommand(pluginName + ":" + pc.getName().toLowerCase(Locale.ENGLISH));
if (reg == null) {
reg = ess.getServer().getPluginCommand(pc.getName().toLowerCase(Locale.ENGLISH));
}
if (reg == null || !reg.getPlugin().equals(plugin)) {
continue;
}
for (String label : labels) {
List<PluginCommand> plugincommands = altcommands.get(label.toLowerCase(Locale.ENGLISH));
if (plugincommands == null) {
plugincommands = new ArrayList<>();
altcommands.put(label.toLowerCase(Locale.ENGLISH), plugincommands);
}
boolean found = false;
for (PluginCommand pc2 : plugincommands) {
if (pc2.getPlugin().equals(plugin)) {
found = true;
}
}
if (!found) {
plugincommands.add(reg);
}
}
}
}
use of org.bukkit.command.Command in project commands by aikar.
the class BukkitCommandManager method unregisterCommand.
/**
* @deprecated Use unregisterCommand(BaseCommand) - this will be visibility reduced later.
* @param command
*/
@Deprecated
public void unregisterCommand(BukkitRootCommand command) {
final String plugin = this.plugin.getName().toLowerCase();
command.unregister(commandMap);
String key = command.getName();
Command registered = knownCommands.get(key);
if (command.equals(registered)) {
knownCommands.remove(key);
}
knownCommands.remove(plugin + ":" + key);
}
use of org.bukkit.command.Command in project DiscordSRV by Scarsz.
the class PluginUtil method unloadPlugin.
public static void unloadPlugin(Plugin plugin) {
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;
Map<Event, SortedSet<RegisteredListener>> listeners = null;
boolean reloadListeners = true;
pluginManager.disablePlugin(plugin);
try {
Field pluginsField = Bukkit.getPluginManager().getClass().getDeclaredField("plugins");
pluginsField.setAccessible(true);
plugins = (List<Plugin>) pluginsField.get(pluginManager);
Field lookupNamesField = Bukkit.getPluginManager().getClass().getDeclaredField("lookupNames");
lookupNamesField.setAccessible(true);
names = (Map<String, Plugin>) lookupNamesField.get(pluginManager);
try {
Field listenersField = Bukkit.getPluginManager().getClass().getDeclaredField("listeners");
listenersField.setAccessible(true);
listeners = (Map<Event, SortedSet<RegisteredListener>>) listenersField.get(pluginManager);
} catch (Exception e) {
reloadListeners = false;
}
Field commandMapField = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");
commandMapField.setAccessible(true);
commandMap = (SimpleCommandMap) commandMapField.get(pluginManager);
Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
knownCommandsField.setAccessible(true);
commands = (Map<String, Command>) knownCommandsField.get(commandMap);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
pluginManager.disablePlugin(plugin);
if (plugins != null && plugins.contains(plugin))
plugins.remove(plugin);
if (names != null && names.containsKey(name))
names.remove(name);
if (listeners != null && reloadListeners) {
for (SortedSet<RegisteredListener> set : listeners.values()) {
set.removeIf(value -> value.getPlugin() == plugin);
}
}
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) {
try {
((URLClassLoader) cl).close();
} catch (IOException ex) {
Logger.getLogger(PluginUtil.class.getName()).log(Level.SEVERE, null, ex);
}
}
System.gc();
}
Aggregations