public PluginNameConversationPrefix(Plugin plugin, String separator, ChatColor prefixColor) { this.separator = separator; this.prefixColor = prefixColor; this.plugin = plugin; cachedPrefix = prefixColor + plugin.getDescription().getName() + separator + ChatColor.WHITE; }
@Override public String getDetectionMessage() { return "Using plugin '" + this.plugin.getDescription().getName() + "' for permissions."; }
@Override public String toString() { StringBuilder stringBuilder = new StringBuilder(super.toString()); stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append(", ").append(owningPlugin.getDescription().getFullName()).append(')'); return stringBuilder.toString(); } }
public PermissionAttachment(Plugin plugin, Permissible Permissible) { if (plugin == null) { throw new IllegalArgumentException("Plugin cannot be null"); } else if (!plugin.isEnabled()) { throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is disabled"); } this.permissible = Permissible; this.plugin = plugin; }
/** * Creates a new PluginLogger that extracts the name from a plugin. * * @param context A reference to the plugin */ public PluginLogger(Plugin context) { super(context.getClass().getCanonicalName(), null); String prefix = context.getDescription().getPrefix(); pluginName = prefix != null ? new StringBuilder().append("[").append(prefix).append("] ").toString() : "[" + context.getDescription().getName() + "] "; setParent(context.getServer().getLogger()); setLevel(Level.ALL); }
private String getPluginList() { StringBuilder pluginList = new StringBuilder(); Plugin[] plugins = Bukkit.getPluginManager().getPlugins(); for (Plugin plugin : plugins) { if (pluginList.length() > 0) { pluginList.append(ChatColor.WHITE); pluginList.append(", "); } pluginList.append(plugin.isEnabled() ? ChatColor.GREEN : ChatColor.RED); pluginList.append(plugin.getDescription().getName()); } return "(" + plugins.length + "): " + pluginList.toString(); } }
public PermissionAttachment addAttachment(Plugin plugin) { if (plugin == null) { throw new IllegalArgumentException("Plugin cannot be null"); } else if (!plugin.isEnabled()) { throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is disabled"); } PermissionAttachment result = new PermissionAttachment(plugin, parent); attachments.add(result); recalculatePermissions(); return result; }
@EventHandler public void onPluginEnable(PluginEnableEvent event) { Plugin plugin = event.getPlugin(); String name = plugin.getDescription().getName(); if (plugin instanceof PermissionsProvider) { setPluginPermissionsResolver(plugin); } else if ("permissions".equalsIgnoreCase(name) || "permissionsex".equalsIgnoreCase(name) || "bpermissions".equalsIgnoreCase(name) || "groupmanager".equalsIgnoreCase(name) || "vault".equalsIgnoreCase(name)) { load(); } }
@EventHandler public void onPluginDisable(PluginDisableEvent event) { String name = event.getPlugin().getDescription().getName(); if (event.getPlugin() instanceof PermissionsProvider || "permissions".equalsIgnoreCase(name) || "permissionsex".equalsIgnoreCase(name) || "bpermissions".equalsIgnoreCase(name) || "groupmanager".equalsIgnoreCase(name) || "vault".equalsIgnoreCase(name)) { load(); } }
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) { if (name == null) { throw new IllegalArgumentException("Permission name cannot be null"); } else if (plugin == null) { throw new IllegalArgumentException("Plugin cannot be null"); } else if (!plugin.isEnabled()) { throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is disabled"); } PermissionAttachment result = addAttachment(plugin, ticks); if (result != null) { result.setPermission(name, value); } return result; }
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) { if (name == null) { throw new IllegalArgumentException("Permission name cannot be null"); } else if (plugin == null) { throw new IllegalArgumentException("Plugin cannot be null"); } else if (!plugin.isEnabled()) { throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is disabled"); } PermissionAttachment result = addAttachment(plugin); result.setPermission(name, value); recalculatePermissions(); return result; }
public void enablePlugin(final Plugin plugin) { if (!plugin.isEnabled()) { List<Command> pluginCommands = PluginCommandYamlParser.parse(plugin); if (!pluginCommands.isEmpty()) { commandMap.registerAll(plugin.getDescription().getName(), pluginCommands); } try { plugin.getPluginLoader().enablePlugin(plugin); } catch (Throwable ex) { server.getLogger().log(Level.SEVERE, "Error occurred (in the plugin loader) while enabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex); } HandlerList.bakeAll(); } }
public PermissionAttachment addAttachment(Plugin plugin, int ticks) { if (plugin == null) { throw new IllegalArgumentException("Plugin cannot be null"); } else if (!plugin.isEnabled()) { throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is disabled"); } PermissionAttachment result = addAttachment(plugin); if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RemoveAttachmentRunnable(result), ticks) == -1) { Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add PermissionAttachment to " + parent + " for plugin " + plugin.getDescription().getFullName() + ": Scheduler returned -1"); result.remove(); return null; } else { return result; } }
/** * Executes the command, returning its success * * @param sender Source object which is executing this command * @param commandLabel The alias of the command used * @param args All arguments passed to the command, split via ' ' * @return true if the command was successful, otherwise false */ @Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { boolean success = false; if (!owningPlugin.isEnabled()) { return false; } if (!testPermission(sender)) { return true; } try { success = executor.onCommand(sender, this, commandLabel, args); } catch (Throwable ex) { throw new CommandException("Unhandled exception executing command '" + commandLabel + "' in plugin " + owningPlugin.getDescription().getFullName(), ex); } if (!success && usageMessage.length() > 0) { for (String line : usageMessage.replace("<command>", commandLabel).split("\n")) { sender.sendMessage(line); } } return success; }
public void enablePlugin(final Plugin plugin) { Validate.isTrue(plugin instanceof JavaPlugin, "Plugin is not associated with this PluginLoader"); if (!plugin.isEnabled()) { plugin.getLogger().info("Enabling " + plugin.getDescription().getFullName()); JavaPlugin jPlugin = (JavaPlugin) plugin; String pluginName = jPlugin.getDescription().getName(); if (!loaders.containsKey(pluginName)) { loaders.put(pluginName, (PluginClassLoader) jPlugin.getClassLoader()); } try { jPlugin.setEnabled(true); } catch (Throwable ex) { server.getLogger().log(Level.SEVERE, "Error occurred while enabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex); } // Perhaps abort here, rather than continue going, but as it stands, // an abort is not possible the way it's currently written server.getPluginManager().callEvent(new PluginEnableEvent(plugin)); } }
private void fireEvent(Event event) { HandlerList handlers = event.getHandlers(); RegisteredListener[] listeners = handlers.getRegisteredListeners(); for (RegisteredListener registration : listeners) { if (!registration.getPlugin().isEnabled()) { continue; } try { registration.callEvent(event); } catch (AuthorNagException ex) { Plugin plugin = registration.getPlugin(); if (plugin.isNaggable()) { plugin.setNaggable(false); server.getLogger().log(Level.SEVERE, String.format( "Nag author(s): '%s' of '%s' about the following: %s", plugin.getDescription().getAuthors(), plugin.getDescription().getFullName(), ex.getMessage() )); } } catch (Throwable ex) { server.getLogger().log(Level.SEVERE, "Could not pass event " + event.getEventName() + " to " + registration.getPlugin().getDescription().getFullName(), ex); } } }
String message = String.format("Disabling %s", plugin.getDescription().getFullName()); plugin.getLogger().info(message); jPlugin.setEnabled(false); } catch (Throwable ex) { server.getLogger().log(Level.SEVERE, "Error occurred while disabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
public CommandMap getCommandMap() { CommandMap commandMap = ReflectionUtil.getField(plugin.getServer().getPluginManager(), "commandMap"); if (commandMap == null) { if (fallbackCommands != null) { commandMap = fallbackCommands; } else { Bukkit.getServer().getLogger().severe(plugin.getDescription().getName() + ": Could not retrieve server CommandMap, using fallback instead!"); fallbackCommands = commandMap = new SimpleCommandMap(Bukkit.getServer()); Bukkit.getServer().getPluginManager().registerEvents(new FallbackRegistrationListener(fallbackCommands), plugin); } } return commandMap; }
private void describeToSender(Plugin plugin, CommandSender sender) { PluginDescriptionFile desc = plugin.getDescription(); sender.sendMessage(ChatColor.GREEN + desc.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + desc.getVersion()); if (desc.getDescription() != null) { sender.sendMessage(desc.getDescription()); } if (desc.getWebsite() != null) { sender.sendMessage("Website: " + ChatColor.GREEN + desc.getWebsite()); } if (!desc.getAuthors().isEmpty()) { if (desc.getAuthors().size() == 1) { sender.sendMessage("Author: " + getAuthors(desc)); } else { sender.sendMessage("Authors: " + getAuthors(desc)); } } }
public boolean register(List<CommandInfo> registered) { CommandMap commandMap = getCommandMap(); if (registered == null || commandMap == null) { return false; } for (CommandInfo command : registered) { DynamicPluginCommand cmd = new DynamicPluginCommand(command.getAliases(), command.getDesc(), "/" + command.getAliases()[0] + " " + command.getUsage(), executor, command.getRegisteredWith(), plugin); cmd.setPermissions(command.getPermissions()); commandMap.register(plugin.getDescription().getName(), cmd); } return true; }