Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.jmgr2007.Reloader;
- import org.bukkit.plugin.*;
- import org.bukkit.command.*;
- import org.bukkit.event.*;
- import java.lang.reflect.*;
- import org.bukkit.*;
- import org.bukkit.permissions.*;
- import org.bukkit.entity.*;
- import java.util.*;
- import java.util.logging.*;
- import org.bukkit.configuration.file.*;
- import org.bukkit.configuration.*;
- import java.io.*;
- public class Utils
- {
- private static PluginManager pm;
- private static boolean canceled;
- public static String canceledPl;
- protected static FileConfiguration locale;
- protected static File localeFile;
- private static Plugin plugin;
- static {
- Utils.pm = Bukkit.getServer().getPluginManager();
- Utils.canceledPl = "";
- Utils.locale = null;
- Utils.localeFile = null;
- Utils.plugin = Utils.pm.getPlugin("Reloader");
- }
- public Utils(final String name, final CommandSender sender) {
- if (exempt(name)) {
- msg(sender, string("exempt", Utils.canceledPl));
- }
- Utils.canceled = exempt(name);
- }
- public Utils(final String name) {
- Utils.canceled = exempt(name);
- }
- public static void load(final String pluginName) {
- Plugin[] plugins2;
- for (int length = (plugins2 = Utils.pm.getPlugins()).length, i = 0; i < length; ++i) {
- final Plugin pl = plugins2[i];
- if (pl.getName().toLowerCase().startsWith(pluginName.toLowerCase())) {
- Utils.plugin.getLogger().info(string("loaded", pl.getName()));
- return;
- }
- }
- String name = "";
- final String path = Utils.plugin.getDataFolder().getParent();
- final File folder = new File(path);
- final ArrayList<File> files = new ArrayList<File>();
- final File[] listOfFiles = folder.listFiles();
- File[] array;
- for (int length2 = (array = listOfFiles).length, j = 0; j < length2; ++j) {
- final File compare = array[j];
- if (compare.isFile()) {
- try {
- name = ReloaderListener.plugin.getPluginLoader().getPluginDescription(compare).getName();
- }
- catch (InvalidDescriptionException e2) {
- Utils.plugin.getLogger().info(string("ErrorA", compare.getName()));
- }
- if (name.toLowerCase().startsWith(pluginName.toLowerCase())) {
- files.add(compare);
- try {
- Utils.pm.loadPlugin(compare);
- }
- catch (UnknownDependencyException e3) {
- Utils.plugin.getLogger().info(string("ErrorC", compare.getName()));
- return;
- }
- catch (InvalidPluginException e4) {
- Utils.plugin.getLogger().info(string("ErrorB", compare.getName()));
- return;
- }
- catch (InvalidDescriptionException e2) {
- Utils.plugin.getLogger().info(string("ErrorA", compare.getName()));
- return;
- }
- }
- }
- }
- final Plugin[] plugins = Utils.pm.getPlugins();
- Plugin[] array2;
- for (int length3 = (array2 = plugins).length, k = 0; k < length3; ++k) {
- final Plugin pl2 = array2[k];
- for (final File compare2 : files) {
- try {
- if (!pl2.getName().equalsIgnoreCase(ReloaderListener.plugin.getPluginLoader().getPluginDescription(compare2).getName())) {
- continue;
- }
- Utils.pm.enablePlugin(pl2);
- }
- catch (InvalidDescriptionException e) {
- e.printStackTrace();
- }
- }
- }
- }
- public static void load(final String pluginName, final CommandSender sender) {
- Plugin[] plugins2;
- for (int length = (plugins2 = Utils.pm.getPlugins()).length, i = 0; i < length; ++i) {
- final Plugin pl = plugins2[i];
- if (pl.getName().toLowerCase().startsWith(pluginName.toLowerCase())) {
- msg(sender, pl.getName());
- msg(sender, pluginName);
- msg(sender, string("loaded", pl.getName()));
- return;
- }
- }
- String name = "";
- final ArrayList<File> files = new ArrayList<File>();
- final File[] listOfFiles = new File(ReloaderListener.plugin.getDataFolder().getParent()).listFiles();
- File[] array;
- for (int length2 = (array = listOfFiles).length, j = 0; j < length2; ++j) {
- final File compare = array[j];
- if (compare.isFile() && compare.getName().toLowerCase().endsWith(".jar")) {
- try {
- name = ReloaderListener.plugin.getPluginLoader().getPluginDescription(compare).getName();
- }
- catch (InvalidDescriptionException e2) {
- msg(sender, string("ErrorA", compare.getName()));
- return;
- }
- if (name.toLowerCase().startsWith(pluginName.toLowerCase())) {
- files.add(compare);
- try {
- Utils.pm.loadPlugin(compare);
- }
- catch (UnknownDependencyException e3) {
- msg(sender, string("ErrorC", compare.getName()));
- return;
- }
- catch (InvalidPluginException e4) {
- msg(sender, string("ErrorB", compare.getName()));
- return;
- }
- catch (InvalidDescriptionException e2) {
- msg(sender, string("ErrorA", compare.getName()));
- return;
- }
- }
- }
- }
- final Plugin[] plugins = Utils.pm.getPlugins();
- Plugin[] array2;
- for (int length3 = (array2 = plugins).length, k = 0; k < length3; ++k) {
- final Plugin pl2 = array2[k];
- for (final File compare2 : files) {
- try {
- if (!pl2.getName().equalsIgnoreCase(ReloaderListener.plugin.getPluginLoader().getPluginDescription(compare2).getName())) {
- continue;
- }
- Utils.pm.enablePlugin(pl2);
- msg(sender, string("load", pl2.getName()));
- }
- catch (InvalidDescriptionException e) {
- e.printStackTrace();
- msg(sender, "");
- return;
- }
- }
- }
- }
- public static void fload(final String pluginName, final CommandSender sender) {
- Plugin[] plugins2;
- for (int length = (plugins2 = Utils.pm.getPlugins()).length, i = 0; i < length; ++i) {
- final Plugin pl = plugins2[i];
- if (pl.getName().toLowerCase().startsWith(pluginName.toLowerCase())) {
- msg(sender, string("loaded", pl.getName()));
- return;
- }
- }
- String name = "";
- final ArrayList<File> files = new ArrayList<File>();
- final File[] listOfFiles = new File(ReloaderListener.plugin.getDataFolder().getParent()).listFiles();
- File[] array;
- for (int length2 = (array = listOfFiles).length, j = 0; j < length2; ++j) {
- final File compare = array[j];
- if (compare.isFile() && compare.getName().toLowerCase().endsWith(".jar")) {
- try {
- name = ReloaderListener.plugin.getPluginLoader().getPluginDescription(compare).getName();
- }
- catch (InvalidDescriptionException e2) {
- msg(sender, string("ErrorA", compare.getName()));
- return;
- }
- if (name.toLowerCase().startsWith(pluginName.toLowerCase())) {
- files.add(compare);
- try {
- Utils.pm.loadPlugin(compare);
- }
- catch (UnknownDependencyException e3) {
- msg(sender, string("ErrorC", compare.getName()));
- return;
- }
- catch (InvalidPluginException e4) {
- msg(sender, string("ErrorB", compare.getName()));
- return;
- }
- catch (InvalidDescriptionException e2) {
- msg(sender, string("ErrorA", compare.getName()));
- return;
- }
- }
- }
- }
- final Plugin[] plugins = Utils.pm.getPlugins();
- Plugin[] array2;
- for (int length3 = (array2 = plugins).length, k = 0; k < length3; ++k) {
- final Plugin pl2 = array2[k];
- for (final File compare2 : files) {
- try {
- if (!pl2.getName().equalsIgnoreCase(Utils.plugin.getPluginLoader().getPluginDescription(compare2).getName())) {
- continue;
- }
- Utils.pm.enablePlugin(pl2);
- }
- catch (InvalidDescriptionException e) {
- e.printStackTrace();
- msg(sender, "");
- return;
- }
- }
- }
- }
- public static void unload(String pluginName) {
- if (Utils.canceled) {
- return;
- }
- pluginName = pluginName.toLowerCase().trim();
- final SimplePluginManager spm = (SimplePluginManager)Utils.pm;
- SimpleCommandMap commandMap = null;
- List<Plugin> plugins = null;
- Map<String, Plugin> lookupNames = null;
- Map<String, Command> knownCommands = null;
- Map<Event, SortedSet<RegisteredListener>> listeners = null;
- boolean reloadlisteners = true;
- try {
- if (spm != null) {
- final Field pluginsField = spm.getClass().getDeclaredField("plugins");
- pluginsField.setAccessible(true);
- plugins = (List<Plugin>)pluginsField.get(spm);
- final Field lookupNamesField = spm.getClass().getDeclaredField("lookupNames");
- lookupNamesField.setAccessible(true);
- lookupNames = (Map<String, Plugin>)lookupNamesField.get(spm);
- try {
- final Field listenersField = spm.getClass().getDeclaredField("listeners");
- listenersField.setAccessible(true);
- listeners = (Map<Event, SortedSet<RegisteredListener>>)listenersField.get(spm);
- }
- catch (Exception e5) {
- reloadlisteners = false;
- }
- final Field commandMapField = spm.getClass().getDeclaredField("commandMap");
- commandMapField.setAccessible(true);
- commandMap = (SimpleCommandMap)commandMapField.get(spm);
- final Field knownCommandsField = commandMap.getClass().getDeclaredField("knownCommands");
- knownCommandsField.setAccessible(true);
- knownCommands = (Map<String, Command>)knownCommandsField.get(commandMap);
- }
- }
- catch (IllegalArgumentException e) {
- e.printStackTrace();
- }
- catch (NoSuchFieldException e2) {
- e2.printStackTrace();
- }
- catch (SecurityException e3) {
- e3.printStackTrace();
- }
- catch (IllegalAccessException e4) {
- e4.printStackTrace();
- }
- boolean in = false;
- Plugin[] plugins2;
- for (int length = (plugins2 = Utils.pm.getPlugins()).length, i = 0; i < length; ++i) {
- final Plugin pl = plugins2[i];
- if (pl.getName().toLowerCase().startsWith(pluginName.toLowerCase())) {
- Utils.pm.disablePlugin(pl);
- if (plugins != null && plugins.contains(pl)) {
- plugins.remove(pl);
- }
- if (lookupNames != null && lookupNames.containsKey(pl.getName())) {
- lookupNames.remove(pl.getName());
- }
- if (listeners != null && reloadlisteners) {
- for (final SortedSet<RegisteredListener> set : listeners.values()) {
- final Iterator<RegisteredListener> it = set.iterator();
- while (it.hasNext()) {
- final RegisteredListener value = it.next();
- if (value.getPlugin() == pl) {
- it.remove();
- }
- }
- }
- }
- if (commandMap != null) {
- final Iterator<Map.Entry<String, Command>> it2 = knownCommands.entrySet().iterator();
- while (it2.hasNext()) {
- final Map.Entry<String, Command> entry = it2.next();
- if (entry.getValue() instanceof PluginCommand) {
- final PluginCommand c = (PluginCommand)entry.getValue();
- if (c.getPlugin() != pl) {
- continue;
- }
- c.unregister((CommandMap)commandMap);
- it2.remove();
- }
- }
- }
- Plugin[] plugins3;
- for (int length2 = (plugins3 = Utils.pm.getPlugins()).length, j = 0; j < length2; ++j) {
- final Plugin plu = plugins3[j];
- if (plu.getDescription().getDepend() != null) {
- for (final String depend : plu.getDescription().getDepend()) {
- if (depend.equalsIgnoreCase(pl.getName())) {
- unload(plu.getName());
- }
- }
- }
- }
- in = true;
- break;
- }
- }
- if (!in) {
- Bukkit.getLogger().info(string("ErrorD", pluginName));
- }
- System.gc();
- }
- public static void unload(String pluginName, final CommandSender sender) {
- if (Utils.canceled) {
- return;
- }
- pluginName = pluginName.toLowerCase().trim();
- final SimplePluginManager spm = (SimplePluginManager)Utils.pm;
- SimpleCommandMap commandMap = null;
- List<Plugin> plugins = null;
- Map<String, Plugin> lookupNames = null;
- Map<String, Command> knownCommands = null;
- Map<Event, SortedSet<RegisteredListener>> listeners = null;
- boolean reloadlisteners = true;
- try {
- if (spm != null) {
- final Field pluginsField = spm.getClass().getDeclaredField("plugins");
- pluginsField.setAccessible(true);
- plugins = (List<Plugin>)pluginsField.get(spm);
- final Field lookupNamesField = spm.getClass().getDeclaredField("lookupNames");
- lookupNamesField.setAccessible(true);
- lookupNames = (Map<String, Plugin>)lookupNamesField.get(spm);
- try {
- final Field listenersField = spm.getClass().getDeclaredField("listeners");
- listenersField.setAccessible(true);
- listeners = (Map<Event, SortedSet<RegisteredListener>>)listenersField.get(spm);
- }
- catch (Exception e5) {
- reloadlisteners = false;
- }
- final Field commandMapField = spm.getClass().getDeclaredField("commandMap");
- commandMapField.setAccessible(true);
- commandMap = (SimpleCommandMap)commandMapField.get(spm);
- final Field knownCommandsField = commandMap.getClass().getDeclaredField("knownCommands");
- knownCommandsField.setAccessible(true);
- knownCommands = (Map<String, Command>)knownCommandsField.get(commandMap);
- }
- }
- catch (IllegalArgumentException e) {
- e.printStackTrace();
- }
- catch (NoSuchFieldException e2) {
- e2.printStackTrace();
- }
- catch (SecurityException e3) {
- e3.printStackTrace();
- }
- catch (IllegalAccessException e4) {
- e4.printStackTrace();
- }
- boolean in = false;
- Plugin[] plugins2;
- for (int length = (plugins2 = Utils.pm.getPlugins()).length, i = 0; i < length; ++i) {
- final Plugin pl = plugins2[i];
- if (pl.getName().toLowerCase().startsWith(pluginName.toLowerCase())) {
- Utils.pm.disablePlugin(pl);
- if (plugins != null && plugins.contains(pl)) {
- plugins.remove(pl);
- }
- if (lookupNames != null && lookupNames.containsKey(pl.getName())) {
- lookupNames.remove(pl.getName());
- }
- if (listeners != null && reloadlisteners) {
- for (final SortedSet<RegisteredListener> set : listeners.values()) {
- final Iterator<RegisteredListener> it = set.iterator();
- while (it.hasNext()) {
- final RegisteredListener value = it.next();
- if (value.getPlugin() == pl) {
- it.remove();
- }
- }
- }
- }
- if (commandMap != null) {
- final Iterator<Map.Entry<String, Command>> it2 = knownCommands.entrySet().iterator();
- while (it2.hasNext()) {
- final Map.Entry<String, Command> entry = it2.next();
- if (entry.getValue() instanceof PluginCommand) {
- final PluginCommand c = (PluginCommand)entry.getValue();
- if (c.getPlugin() != pl) {
- continue;
- }
- c.unregister((CommandMap)commandMap);
- it2.remove();
- }
- }
- }
- Plugin[] plugins3;
- for (int length2 = (plugins3 = Utils.pm.getPlugins()).length, j = 0; j < length2; ++j) {
- final Plugin plu = plugins3[j];
- if (plu.getDescription().getDepend() != null) {
- for (final String depend : plu.getDescription().getDepend()) {
- if (depend.equalsIgnoreCase(pl.getName())) {
- unload(plu.getName());
- }
- }
- }
- }
- in = true;
- msg(sender, string("unload", pl.getName()));
- break;
- }
- }
- if (!in) {
- msg(sender, string("ErrorD", pluginName));
- }
- System.gc();
- }
- public static void disable(final String plugin) {
- if (Utils.canceled) {
- return;
- }
- final Plugin[] plugins = Utils.pm.getPlugins();
- Plugin[] array;
- for (int length = (array = plugins).length, i = 0; i < length; ++i) {
- final Plugin pl = array[i];
- if (pl.getName().toLowerCase().startsWith(plugin.toLowerCase())) {
- Utils.pm.disablePlugin(pl);
- }
- }
- }
- public static void disable(final String plugin, final CommandSender sender) {
- if (Utils.canceled) {
- return;
- }
- boolean h = false;
- final Plugin[] plugins = Utils.pm.getPlugins();
- Plugin[] array;
- for (int length = (array = plugins).length, i = 0; i < length; ++i) {
- final Plugin pl = array[i];
- if (pl.getName().toLowerCase().startsWith(plugin.toLowerCase())) {
- Utils.pm.disablePlugin(pl);
- h = true;
- msg(sender, string("disable", pl.getName()));
- }
- }
- if (!h) {
- msg(sender, string("disableError", plugin));
- }
- }
- public static void hReload() {
- Bukkit.reload();
- }
- public static void enable(final String plugin) {
- final Plugin[] plugins = Utils.pm.getPlugins();
- Plugin[] array;
- for (int length = (array = plugins).length, i = 0; i < length; ++i) {
- final Plugin pl = array[i];
- if (pl.getName().toLowerCase().startsWith(plugin.toLowerCase())) {
- Utils.pm.enablePlugin(pl);
- }
- }
- }
- public static void enable(final String plugin, final CommandSender sender) {
- final Plugin[] plugins = Utils.pm.getPlugins();
- boolean h = false;
- Plugin[] array;
- for (int length = (array = plugins).length, i = 0; i < length; ++i) {
- final Plugin pl = array[i];
- if (pl.getName().toLowerCase().startsWith(plugin.toLowerCase())) {
- Utils.pm.enablePlugin(pl);
- h = true;
- msg(sender, string("enable", pl.getName()));
- return;
- }
- }
- if (!h) {
- msg(sender, string("enableError", plugin));
- }
- }
- public static void use(String plugin, final CommandSender sender) {
- Plugin plug = null;
- if (plugin.trim() == "") {
- plugin = Utils.plugin.getName();
- }
- final Plugin[] plugins = Utils.pm.getPlugins();
- Plugin[] array;
- for (int length = (array = plugins).length, k = 0; k < length; ++k) {
- final Plugin pl = array[k];
- if (pl.getName().toLowerCase().startsWith(plugin.toLowerCase())) {
- plug = pl;
- }
- }
- if (plug == null) {
- msg(sender, string("notFound", plugin));
- return;
- }
- final ArrayList<String> out = new ArrayList<String>();
- final ArrayList<String> parsedCommands = new ArrayList<String>();
- final Map commands = plug.getDescription().getCommands();
- if (commands != null) {
- for (final Map.Entry pluginEntry : commands.entrySet()) {
- if (pluginEntry != null) {
- parsedCommands.add(pluginEntry.getKey());
- }
- }
- }
- if (!parsedCommands.isEmpty()) {
- StringBuilder commandsOut = new StringBuilder();
- msg(sender, ChatColor.RED + "Commands: ");
- for (int i = 0; i < parsedCommands.size(); ++i) {
- final String pluginCommand = parsedCommands.get(i);
- if (commandsOut.length() + pluginCommand.length() > 55) {
- msg(sender, commandsOut.toString());
- commandsOut = new StringBuilder();
- }
- if (parsedCommands.size() >= 10) {
- msg(sender, ChatColor.GREEN + parsedCommands.toString().replace("[", "").replace("]", ""));
- break;
- }
- msg(sender, ChatColor.RED + "* " + ChatColor.GREEN + "/" + pluginCommand);
- }
- out.add(commandsOut.toString());
- }
- if (plug.getDescription().getPermissions() != null) {
- final List<Permission> perms = (List<Permission>)plug.getDescription().getPermissions();
- if (perms.size() != 0) {
- msg(sender, ChatColor.RED + "Permissions:");
- if (perms.size() < 10) {
- for (int i = 0; i < perms.size(); ++i) {
- msg(sender, ChatColor.RED + "* " + ChatColor.GREEN + perms.get(i).getName());
- }
- }
- else {
- String s = perms.get(0).getName();
- for (int j = 1; j < perms.size(); ++j) {
- s = String.valueOf(s) + ", " + perms.get(j).getName();
- }
- msg(sender, ChatColor.GREEN + s);
- }
- }
- }
- }
- public static void info(final String plugin, final CommandSender sender) {
- Plugin plug = null;
- final Plugin[] plugins = Utils.pm.getPlugins();
- Plugin[] array;
- for (int length = (array = plugins).length, k = 0; k < length; ++k) {
- final Plugin pl = array[k];
- if (pl.getName().toLowerCase().startsWith(plugin.toLowerCase())) {
- plug = pl;
- }
- }
- if (plugin == "") {
- plug = Utils.plugin;
- }
- if (plug == null) {
- msg(sender, string("notFound", plugin));
- return;
- }
- if (plugin != null) {
- msg(sender, ChatColor.RED + "Plugin info: " + ChatColor.GREEN + plug.getName());
- if (plug.getDescription().getAuthors() != null && !plug.getDescription().getAuthors().isEmpty()) {
- String author = "";
- final List<String> authors = (List<String>)plug.getDescription().getAuthors();
- for (int i = 0; i < authors.size(); ++i) {
- if (i == 0) {
- author = authors.get(i);
- }
- if (i > 1) {
- author = String.valueOf(author) + ", " + authors.get(i);
- }
- }
- msg(sender, ChatColor.RED + "Author(s): " + ChatColor.GREEN + author);
- }
- if (plug.getDescription().getDescription() != null && !plug.getDescription().getDescription().isEmpty()) {
- msg(sender, ChatColor.RED + "Description: " + ChatColor.GREEN + plug.getDescription().getDescription());
- }
- if (plug.getDescription().getVersion() != null && !plug.getDescription().getVersion().isEmpty()) {
- msg(sender, ChatColor.RED + "Version: " + ChatColor.GREEN + plug.getDescription().getVersion());
- }
- if (plug.getDescription().getWebsite() != null && !plug.getDescription().getWebsite().isEmpty()) {
- msg(sender, ChatColor.RED + "Website: " + ChatColor.GREEN + plug.getDescription().getWebsite());
- }
- if (plug.getDescription().getDepend() != null && !plug.getDescription().getDepend().isEmpty()) {
- msg(sender, ChatColor.RED + "Required plugins");
- final List<String> depends = (List<String>)plug.getDescription().getDepend();
- for (int j = 0; j < depends.size(); ++j) {
- msg(sender, ChatColor.RED + "* " + ChatColor.GREEN + depends.get(j));
- }
- }
- if (plug.getDescription().getSoftDepend() != null && !plug.getDescription().getSoftDepend().isEmpty()) {
- msg(sender, ChatColor.RED + "Recommended plugins");
- final List<String> depends = (List<String>)plug.getDescription().getSoftDepend();
- for (int j = 0; j < depends.size(); ++j) {
- msg(sender, ChatColor.RED + "* " + ChatColor.GREEN + depends.get(j));
- }
- }
- }
- }
- public static boolean check(final String plugin, final CommandSender sender) {
- Plugin plug = null;
- final Plugin[] plugins = Utils.pm.getPlugins();
- Plugin[] array;
- for (int length = (array = plugins).length, i = 0; i < length; ++i) {
- final Plugin pl = array[i];
- if (pl.getName().toLowerCase().startsWith(plugin.toLowerCase())) {
- plug = pl;
- }
- }
- if (plug != null) {
- if (plug.isEnabled()) {
- msg(sender, string("enabled", plug.getName()));
- }
- else {
- msg(sender, string("disabled", plug.getName()));
- }
- return true;
- }
- msg(sender, string("notFound", plugin));
- return true;
- }
- public static boolean perm(final CommandSender sender, final String permission) {
- if (Utils.pm.getPermission(permission) == null) {
- msg(sender, string("permNotFound", permission));
- return true;
- }
- if (sender.hasPermission(permission)) {
- msg(sender, string("senderPerm", permission));
- }
- else {
- msg(sender, string("senderNoPerm", permission));
- }
- return true;
- }
- public static boolean perm(final String player, final CommandSender sender, final String permission) {
- if (Utils.pm.getPermission(permission) == null) {
- msg(sender, string("permNotFound", permission));
- return true;
- }
- if (Bukkit.getServer().getPlayer(player) != null) {
- final Player target = Bukkit.getServer().getPlayer(player);
- if (target.hasPermission(permission)) {
- msg(sender, string("userPerm", permission).replaceAll("%USER%", player));
- }
- else {
- msg(sender, string("userNoPerm", permission).replaceAll("%USER%", player));
- }
- }
- return true;
- }
- public static boolean list(final CommandSender sender) {
- final Plugin[] plugins = Utils.pm.getPlugins();
- final ArrayList<String> enabled = new ArrayList<String>();
- final ArrayList<String> disabled = new ArrayList<String>();
- Plugin[] array;
- for (int length = (array = plugins).length, j = 0; j < length; ++j) {
- final Plugin pl = array[j];
- if (pl.isEnabled()) {
- enabled.add(pl.getName());
- }
- else {
- disabled.add(pl.getName());
- }
- }
- Collections.sort(enabled, String.CASE_INSENSITIVE_ORDER);
- Collections.sort(disabled, String.CASE_INSENSITIVE_ORDER);
- if (plugins.length != 0) {
- msg(sender, new StringBuilder().append(ChatColor.GREEN).append(plugins.length).append(" plugins loaded").toString());
- }
- if (!enabled.isEmpty()) {
- msg(sender, ChatColor.GOLD + "Enabled:");
- String enable = "";
- for (int i = 0; i < enabled.size(); ++i) {
- enable = String.valueOf(enable) + ", " + enabled.get(i);
- }
- enable = enable.replaceFirst(", ", "");
- msg(sender, ChatColor.GREEN + enable);
- }
- if (!disabled.isEmpty()) {
- String disable = "";
- msg(sender, ChatColor.GOLD + "Disabled:");
- for (int i = 0; i < disabled.size(); ++i) {
- disable = String.valueOf(disable) + ", " + disabled.get(i);
- }
- disable = disable.replaceFirst(", ", "");
- msg(sender, ChatColor.RED + disable);
- }
- return true;
- }
- public static boolean vList(final CommandSender sender) {
- final Plugin[] plugins = Utils.pm.getPlugins();
- final ArrayList<String> enabled = new ArrayList<String>();
- final ArrayList<String> disabled = new ArrayList<String>();
- Plugin[] array;
- for (int length = (array = plugins).length, j = 0; j < length; ++j) {
- final Plugin pl = array[j];
- if (pl.isEnabled()) {
- enabled.add(pl.getName());
- }
- else {
- disabled.add(pl.getName());
- }
- }
- Collections.sort(enabled, String.CASE_INSENSITIVE_ORDER);
- Collections.sort(disabled, String.CASE_INSENSITIVE_ORDER);
- if (plugins.length != 0) {
- msg(sender, new StringBuilder().append(ChatColor.GREEN).append(plugins.length).append(" plugins loaded").toString());
- }
- if (!enabled.isEmpty()) {
- msg(sender, ChatColor.GOLD + "Enabled:");
- String enable = "";
- for (int i = 0; i < enabled.size(); ++i) {
- enable = String.valueOf(enable) + ChatColor.GREEN + ", " + enabled.get(i) + ChatColor.GRAY + " " + Utils.pm.getPlugin((String)enabled.get(i)).getDescription().getVersion();
- }
- enable = enable.replaceFirst(", ", "");
- msg(sender, ChatColor.GREEN + enable);
- }
- if (!disabled.isEmpty()) {
- String disable = "";
- msg(sender, ChatColor.GOLD + "Disabled:");
- for (int i = 0; i < disabled.size(); ++i) {
- disable = String.valueOf(disable) + ", " + disabled.get(i) + ChatColor.GRAY + " " + Utils.pm.getPlugin((String)disabled.get(i)).getDescription().getVersion();
- }
- disable = disable.replaceFirst(", ", "");
- msg(sender, ChatColor.RED + disable);
- }
- return true;
- }
- public static void msg(final CommandSender sender, final String msg) {
- if (sender instanceof Player) {
- sender.sendMessage(msg);
- }
- else {
- final Logger log = Bukkit.getServer().getLogger();
- log.info(msg);
- }
- }
- public static boolean help(final CommandSender sender) {
- msg(sender, string("helpHead"));
- if (permCheck(sender, "reloader.reload")) {
- msg(sender, string("helpReload"));
- }
- if (permCheck(sender, "reloader.disable")) {
- msg(sender, string("helpDisable"));
- }
- if (permCheck(sender, "reloader.enable")) {
- msg(sender, string("helpEnable"));
- }
- if (permCheck(sender, "reloader.load")) {
- msg(sender, string("helpLoad"));
- }
- if (permCheck(sender, "reloader.unload")) {
- msg(sender, string("helpUnload"));
- }
- if (permCheck(sender, "reloader.check")) {
- msg(sender, string("helpCheck"));
- }
- if (permCheck(sender, "reloader.info")) {
- msg(sender, string("helpInfo"));
- }
- if (permCheck(sender, "reloader.use")) {
- msg(sender, string("helpUse"));
- }
- if (permCheck(sender, "reloader.perm")) {
- msg(sender, string("helpPerm"));
- }
- if (permCheck(sender, "reloader.list")) {
- msg(sender, string("helpList"));
- }
- if (permCheck(sender, "reloader.list")) {
- msg(sender, string("helpListV"));
- }
- if (permCheck(sender, "reloader.config")) {
- msg(sender, string("helpConfig"));
- }
- return true;
- }
- public static boolean exempt(final String name) {
- for (final String ex : Utils.plugin.getConfig().getStringList("exempt")) {
- if (ex.toLowerCase().startsWith(name.toLowerCase())) {
- Utils.canceledPl = ex;
- return true;
- }
- }
- return false;
- }
- public static String join(final String[] args) {
- String l = "";
- for (int i = 1; i < args.length; ++i) {
- l = String.valueOf(l) + " " + args[i];
- }
- l = l.toLowerCase().trim();
- return l;
- }
- public static void scheduler() {
- if (!Utils.plugin.getConfig().getString("timer.message").isEmpty()) {
- Bukkit.getServer().broadcastMessage(Utils.plugin.getConfig().getString("timer.message").replaceAll("&(?=[0-9a-fA-FkKmMoOlLnNrR])", "§"));
- }
- final Plugin[] plugins = Utils.pm.getPlugins();
- if (Utils.plugin.getConfig().getBoolean("timer.all")) {
- Plugin[] array;
- for (int length = (array = plugins).length, i = 0; i < length; ++i) {
- final Plugin pl = array[i];
- if (!pl.getName().toLowerCase().startsWith(Utils.plugin.getName().toLowerCase()) && !exempt(pl.getName())) {
- unload(pl.getName());
- load(pl.getName());
- }
- }
- }
- else {
- for (final String li : Utils.plugin.getConfig().getStringList("timer.list")) {
- Plugin[] plugins2;
- for (int length2 = (plugins2 = Utils.pm.getPlugins()).length, j = 0; j < length2; ++j) {
- final Plugin pl2 = plugins2[j];
- if (pl2.getName().toLowerCase().startsWith(li.toLowerCase()) && !exempt(pl2.getName())) {
- unload(pl2.getName());
- load(pl2.getName());
- }
- }
- }
- }
- }
- public static void localize() {
- Utils.plugin.saveResource("locale.yml", true);
- Utils.locale = (FileConfiguration)YamlConfiguration.loadConfiguration(Utils.localeFile);
- try {
- Utils.locale.load(Utils.localeFile);
- }
- catch (IOException | InvalidConfigurationException ex2) {
- final Exception ex;
- final Exception e = ex;
- e.printStackTrace();
- }
- Utils.plugin.getServer().broadcastMessage(Utils.locale.getString("test"));
- }
- public static String string(final String s) {
- if (Utils.locale.getString(s) != null) {
- return Utils.locale.getString(s).replaceAll("&(?=[0-9a-fA-FkKmMoOlLnNrR])", "§");
- }
- return "";
- }
- public static String string(final String s, final String replac) {
- if (Utils.locale.getString(s) != null) {
- return Utils.locale.getString(s).replaceAll("&(?=[0-9a-fA-FkKmMoOlLnNrR])", "§").replaceAll("%NAME%", replac);
- }
- return "";
- }
- public static boolean permCheck(final CommandSender sender, final String perm) {
- return sender.hasPermission(perm);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement