use of org.bukkit.command.Command in project TotalFreedomMod by TotalFreedom.
the class Muter method onPlayerCommandPreprocess.
@EventHandler(priority = EventPriority.LOW)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
FPlayer fPlayer = plugin.pl.getPlayer(event.getPlayer());
// Block commands if player is muted
if (!fPlayer.isMuted()) {
return;
}
String message = event.getMessage();
if (plugin.al.isAdmin(player)) {
fPlayer.setMuted(false);
return;
}
String cmdName = message.split(" ")[0].toLowerCase();
if (cmdName.startsWith("/")) {
cmdName = cmdName.substring(1);
}
Command command = server.getPluginCommand(cmdName);
if (command != null) {
cmdName = command.getName().toLowerCase();
}
if (MUTE_COMMANDS.contains(cmdName)) {
player.sendMessage(ChatColor.RED + "That command is blocked while you are muted.");
event.setCancelled(true);
return;
}
// TODO: Should this go here?
if (ConfigEntry.ENABLE_PREPROCESS_LOG.getBoolean()) {
FLog.info(String.format("[PREPROCESS_COMMAND] %s(%s): %s", player.getName(), ChatColor.stripColor(player.getDisplayName()), message), true);
}
}
use of org.bukkit.command.Command 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.Command 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;
}
use of org.bukkit.command.Command in project SpaciousLib by anhcraft.
the class CommandManager method unregister.
/**
* Unregisters a specific plugin command
* @param plugin the plugin which owned that command
* @param command the command
*/
public static void unregister(JavaPlugin plugin, PluginCommand command) {
try {
Class<?> craftServerClass = Class.forName("org.bukkit.craftbukkit." + GameVersion.getVersion().toString() + ".CraftServer");
Object craftServer = craftServerClass.cast(Bukkit.getServer());
Field commandMapField = craftServerClass.getDeclaredField("commandMap");
commandMapField.setAccessible(true);
SimpleCommandMap commandMap = (SimpleCommandMap) commandMapField.get(craftServer);
Field knownCommandsField = commandMap.getClass().getDeclaredField("knownCommands");
knownCommandsField.setAccessible(true);
Map<String, Command> knownCommands = (Map<String, Command>) knownCommandsField.get(commandMap);
knownCommands.remove(plugin.getName() + ":" + command.getName());
for (String alias : command.getAliases()) {
alias = plugin.getName() + ":" + alias;
if (knownCommands.containsKey(alias) && knownCommands.get(alias).toString().contains(command.getName())) {
knownCommands.remove(alias);
}
}
knownCommandsField.set(commandMap, knownCommands);
commandMapField.set(craftServer, commandMap);
Field simplePluginManagerField = craftServerClass.getDeclaredField("pluginManager");
simplePluginManagerField.setAccessible(true);
SimplePluginManager simplePluginManager = (SimplePluginManager) simplePluginManagerField.get(craftServer);
Field commandMapPluginManagerField = SimplePluginManager.class.getDeclaredField("commandMap");
commandMapPluginManagerField.setAccessible(true);
SimpleCommandMap commandPluginManagerMap = (SimpleCommandMap) commandMapPluginManagerField.get(simplePluginManager);
Field knownCommandsPluginManagerField = commandPluginManagerMap.getClass().getDeclaredField("knownCommands");
knownCommandsPluginManagerField.setAccessible(true);
Map<String, Command> knownCommandsPluginManager = (Map<String, Command>) knownCommandsPluginManagerField.get(commandPluginManagerMap);
knownCommandsPluginManager.remove(plugin.getName() + ":" + command.getName());
for (String alias : command.getAliases()) {
alias = plugin.getName() + ":" + alias;
if (knownCommandsPluginManager.containsKey(alias) && knownCommandsPluginManager.get(alias).toString().contains(command.getName())) {
knownCommandsPluginManager.remove(alias);
}
}
knownCommandsPluginManagerField.set(commandPluginManagerMap, knownCommandsPluginManager);
commandMapPluginManagerField.set(simplePluginManager, commandPluginManagerMap);
simplePluginManagerField.set(craftServer, simplePluginManager);
} catch (IllegalAccessException | NoSuchFieldException | ClassNotFoundException e) {
e.printStackTrace();
}
}
use of org.bukkit.command.Command in project MassiveCore by MassiveCraft.
the class TypeStringCommand method getTabList.
@Override
public Collection<String> getTabList(CommandSender sender, String arg) {
// Split the arg into a list of args #inception-the-movie!
String[] args = argAsArgs(arg);
// Tab completion of base commands
if (args.length <= 1)
return getKnownCommands().keySet();
// Get command alias and subargs
String alias = args[0];
// Attempt using the tab completion of that command.
Command command = getCommandSmart(alias);
if (command == null)
return Collections.emptySet();
List<String> subcompletions = command.tabComplete(sender, alias, Arrays.copyOfRange(args, 1, args.length));
String prefix = Txt.implode(Arrays.copyOfRange(args, 0, args.length - 1), " ") + " ";
List<String> ret = new MassiveList<>();
for (String subcompletion : subcompletions) {
String completion = prefix + subcompletion;
ret.add(completion);
}
return ret;
}
Aggregations