From 530a636df76a0af9c92866ead31c31aebc97a37c Mon Sep 17 00:00:00 2001 From: sleak Date: Fri, 9 Dec 2011 20:14:28 -0800 Subject: [PATCH] added vault.admin permission - and an upate check during login --- src/net/milkbowl/vault/Vault.java | 558 ++++++++++++++++-------------- 1 file changed, 293 insertions(+), 265 deletions(-) diff --git a/src/net/milkbowl/vault/Vault.java b/src/net/milkbowl/vault/Vault.java index 35aa01b..b87806c 100644 --- a/src/net/milkbowl/vault/Vault.java +++ b/src/net/milkbowl/vault/Vault.java @@ -56,6 +56,10 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; +import org.bukkit.event.Event.Priority; +import org.bukkit.event.Event.Type; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerListener; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.ServicePriority; import org.bukkit.plugin.java.JavaPlugin; @@ -66,309 +70,333 @@ import org.w3c.dom.NodeList; public class Vault extends JavaPlugin { - private static final Logger log = Logger.getLogger("Minecraft"); + private static final Logger log = Logger.getLogger("Minecraft"); + private Permission perms; + + @Override + public void onDisable() { + // Remove all Service Registrations + getServer().getServicesManager().unregisterAll(this); - @Override - public void onDisable() { - // Remove all Service Registrations - getServer().getServicesManager().unregisterAll(this); + log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion())); + } - log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion())); - } + @Override + public void onEnable() { + try { + String newVersion = updateCheck(); + String oldVersion = getDescription().getVersion().substring(0, 5); + if (!oldVersion.equalsIgnoreCase(newVersion)) { + log.warning(newVersion + " is out! You are running " + oldVersion); + log.warning("Update Vault at: http://dev.bukkit.org/server-mods/vault"); + } + } catch (Exception e) { + // ignore exceptions + } + // Load Vault Addons + loadEconomy(); + loadPermission(); + loadChat(); - @Override - public void onEnable() { - try { - updateCheck(); - } catch (Exception e) { - // ignore exceptions - } - // Load Vault Addons - loadEconomy(); - loadPermission(); - loadChat(); + getCommand("vault-info").setExecutor(this); + getCommand("vault-reload").setExecutor(this); + this.getServer().getPluginManager().registerEvent(Type.PLAYER_JOIN, new VaultPlayerListener(), Priority.Monitor, this); + log.info(String.format("[%s] Enabled Version %s", getDescription().getName(), getDescription().getVersion())); + } - getCommand("vault-info").setExecutor(this); - getCommand("vault-reload").setExecutor(this); - log.info(String.format("[%s] Enabled Version %s", getDescription().getName(), getDescription().getVersion())); - } + /** + * Attempts to load Chat Addons + */ + private void loadChat() { + // Try to load PermissionsEx + if (packageExists(new String[] { "ru.tehkode.permissions.bukkit.PermissionsEx" })) { + Chat eChat = new Chat_PermissionsEx(this, perms); + getServer().getServicesManager().register(Chat.class, eChat, this, ServicePriority.Highest); + log.info(String.format("[%s][Chat] PermissionsEx found: %s", getDescription().getName(), eChat.isEnabled() ? "Loaded" : "Waiting")); + } - /** - * Attempts to load Chat Addons - */ - private void loadChat() { - Permission perms = getServer().getServicesManager().getRegistration(Permission.class).getProvider(); - // Try to load PermissionsEx - if (packageExists(new String[] { "ru.tehkode.permissions.bukkit.PermissionsEx" })) { - Chat eChat = new Chat_PermissionsEx(this, perms); - getServer().getServicesManager().register(Chat.class, eChat, this, ServicePriority.Highest); - log.info(String.format("[%s][Chat] PermissionsEx found: %s", getDescription().getName(), eChat.isEnabled() ? "Loaded" : "Waiting")); - } + //Try loading mChat + if (packageExists(new String[] {"net.D3GN.MiracleM4n.mChat"} )) { + Chat mChat = new Chat_mChat(this, perms); + getServer().getServicesManager().register(Chat.class, mChat, this, ServicePriority.Highest); + log.info(String.format("[%s][Chat] mChat found: %s", getDescription().getName(), mChat.isEnabled() ? "Loaded" : "Waiting")); + } - //Try loading mChat - if (packageExists(new String[] {"net.D3GN.MiracleM4n.mChat"} )) { - Chat mChat = new Chat_mChat(this, perms); - getServer().getServicesManager().register(Chat.class, mChat, this, ServicePriority.Highest); - log.info(String.format("[%s][Chat] mChat found: %s", getDescription().getName(), mChat.isEnabled() ? "Loaded" : "Waiting")); - } + //try loading bPermissions + if (packageExists(new String[] {"de.bananaco.permissions.worlds.WorldPermissionsManager"})) { + Chat bPerms = new Chat_bPermissions(this, perms); + getServer().getServicesManager().register(Chat.class, bPerms, this, ServicePriority.High); + log.info(String.format("[%s][Chat] bPermissions found: %s", getDescription().getName(), bPerms.isEnabled() ? "Loaded" : "Waiting")); + } - //try loading bPermissions - if (packageExists(new String[] {"de.bananaco.permissions.worlds.WorldPermissionsManager"})) { - Chat bPerms = new Chat_bPermissions(this, perms); - getServer().getServicesManager().register(Chat.class, bPerms, this, ServicePriority.High); - log.info(String.format("[%s][Chat] bPermissions found: %s", getDescription().getName(), bPerms.isEnabled() ? "Loaded" : "Waiting")); - } + // Try to load GroupManager + if (packageExists(new String[] { "org.anjocaido.groupmanager.GroupManager" })) { + Chat gPerms = new Chat_GroupManager(this, perms); + getServer().getServicesManager().register(Chat.class, gPerms, this, ServicePriority.High); + log.info(String.format("[%s][Chat] GroupManager found: %s", getDescription().getName(), gPerms.isEnabled() ? "Loaded" : "Waiting")); + } - // Try to load GroupManager - if (packageExists(new String[] { "org.anjocaido.groupmanager.GroupManager" })) { - Chat gPerms = new Chat_GroupManager(this, perms); - getServer().getServicesManager().register(Chat.class, gPerms, this, ServicePriority.High); - log.info(String.format("[%s][Chat] GroupManager found: %s", getDescription().getName(), gPerms.isEnabled() ? "Loaded" : "Waiting")); - } + // Try to load Permissions 3 (Yeti) + if (packageExists(new String[] { "com.nijiko.permissions.ModularControl" })) { + Chat nPerms = new Chat_Permissions3(this, perms); + getServer().getServicesManager().register(Chat.class, nPerms, this, ServicePriority.High); + log.info(String.format("[%s][Chat] Permissions 3 (Yeti) found: %s", getDescription().getName(), nPerms.isEnabled() ? "Loaded" : "Waiting")); + } - // Try to load Permissions 3 (Yeti) - if (packageExists(new String[] { "com.nijiko.permissions.ModularControl" })) { - Chat nPerms = new Chat_Permissions3(this, perms); - getServer().getServicesManager().register(Chat.class, nPerms, this, ServicePriority.High); - log.info(String.format("[%s][Chat] Permissions 3 (Yeti) found: %s", getDescription().getName(), nPerms.isEnabled() ? "Loaded" : "Waiting")); - } + // Try to load iChat + if (packageExists(new String[] { "net.TheDgtl.iChat.iChat" })) { + Chat iChat = new Chat_iChat(this, perms); + getServer().getServicesManager().register(Chat.class, iChat, this, ServicePriority.Lowest); + log.info(String.format("[%s][Chat] PermissionsEx found: %s", getDescription().getName(), iChat.isEnabled() ? "Loaded" : "Waiting")); + } + } - // Try to load iChat - if (packageExists(new String[] { "net.TheDgtl.iChat.iChat" })) { - Chat iChat = new Chat_iChat(this, perms); - getServer().getServicesManager().register(Chat.class, iChat, this, ServicePriority.Lowest); - log.info(String.format("[%s][Chat] PermissionsEx found: %s", getDescription().getName(), iChat.isEnabled() ? "Loaded" : "Waiting")); - } - } + /** + * Attempts to load Economy Addons + */ + private void loadEconomy() { + // Try to load MultiCurrency + if (packageExists(new String[] { "me.ashtheking.currency.Currency", "me.ashtheking.currency.CurrencyList" })) { + Economy econ = new Economy_MultiCurrency(this); + getServer().getServicesManager().register(Economy.class, econ, this, ServicePriority.Normal); + log.info(String.format("[%s][Economy] MultiCurrency found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); + } - /** - * Attempts to load Economy Addons - */ - private void loadEconomy() { - // Try to load MultiCurrency - if (packageExists(new String[] { "me.ashtheking.currency.Currency", "me.ashtheking.currency.CurrencyList" })) { - Economy econ = new Economy_MultiCurrency(this); - getServer().getServicesManager().register(Economy.class, econ, this, ServicePriority.Normal); - log.info(String.format("[%s][Economy] MultiCurrency found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); - } + //Try Loading MineConomy + if (packageExists(new String[] { "me.mjolnir.mineconomy.MineConomy" })) { + Economy econ = new Economy_MineConomy(this); + getServer().getServicesManager().register(Economy.class, econ, this, ServicePriority.Normal); + log.info(String.format("[%s][Economy] MineConomy found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); - //Try Loading MineConomy - if (packageExists(new String[] { "me.mjolnir.mineconomy.MineConomy" })) { - Economy econ = new Economy_MineConomy(this); - getServer().getServicesManager().register(Economy.class, econ, this, ServicePriority.Normal); - log.info(String.format("[%s][Economy] MineConomy found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); + } - } + //Try loading eWallet + if (packageExists(new String[] { "me.ethan.eWallet.ECO" })) { + Economy econ = new Economy_eWallet(this); + getServer().getServicesManager().register(Economy.class, econ, this, ServicePriority.Normal); + log.info(String.format("[%s][Economy] eWallet found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); + } - //Try loading eWallet - if (packageExists(new String[] { "me.ethan.eWallet.ECO" })) { - Economy econ = new Economy_eWallet(this); - getServer().getServicesManager().register(Economy.class, econ, this, ServicePriority.Normal); - log.info(String.format("[%s][Economy] eWallet found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); - } + // Try to load 3co + if (packageExists(new String[] { "me.ic3d.eco.ECO" })) { + Economy econ = new Economy_3co(this); + getServer().getServicesManager().register(Economy.class, econ, this, ServicePriority.Normal); + log.info(String.format("[%s][Economy] 3co found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); + } - // Try to load 3co - if (packageExists(new String[] { "me.ic3d.eco.ECO" })) { - Economy econ = new Economy_3co(this); - getServer().getServicesManager().register(Economy.class, econ, this, ServicePriority.Normal); - log.info(String.format("[%s][Economy] 3co found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); - } + // Try to load BOSEconomy + if (packageExists(new String[] { "cosine.boseconomy.BOSEconomy", "cosine.boseconomy.CommandManager" })) { + Economy bose6 = new Economy_BOSE6(this); + getServer().getServicesManager().register(Economy.class, bose6, this, ServicePriority.Normal); + log.info(String.format("[%s][Economy] BOSEconomy6 found: %s", getDescription().getName(), bose6.isEnabled() ? "Loaded" : "Waiting")); + } - // Try to load BOSEconomy - if (packageExists(new String[] { "cosine.boseconomy.BOSEconomy", "cosine.boseconomy.CommandManager" })) { - Economy bose6 = new Economy_BOSE6(this); - getServer().getServicesManager().register(Economy.class, bose6, this, ServicePriority.Normal); - log.info(String.format("[%s][Economy] BOSEconomy6 found: %s", getDescription().getName(), bose6.isEnabled() ? "Loaded" : "Waiting")); - } + // Try to load BOSEconomy + if (packageExists(new String[] { "cosine.boseconomy.BOSEconomy", "cosine.boseconomy.CommandHandler" })) { + Economy bose7 = new Economy_BOSE7(this); + getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, bose7, this, ServicePriority.Normal); + log.info(String.format("[%s][Economy] BOSEconomy7 found: %s", getDescription().getName(), bose7.isEnabled() ? "Loaded" : "Waiting")); + } - // Try to load BOSEconomy - if (packageExists(new String[] { "cosine.boseconomy.BOSEconomy", "cosine.boseconomy.CommandHandler" })) { - Economy bose7 = new Economy_BOSE7(this); - getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, bose7, this, ServicePriority.Normal); - log.info(String.format("[%s][Economy] BOSEconomy7 found: %s", getDescription().getName(), bose7.isEnabled() ? "Loaded" : "Waiting")); - } + // Try to load Essentials Economy + if (packageExists(new String[] { "com.earth2me.essentials.api.Economy", "com.earth2me.essentials.api.NoLoanPermittedException", "com.earth2me.essentials.api.UserDoesNotExistException" })) { + Economy essentials = new Economy_Essentials(this); + getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, essentials, this, ServicePriority.Low); + log.info(String.format("[%s][Economy] Essentials Economy found: %s", getDescription().getName(), essentials.isEnabled() ? "Loaded" : "Waiting")); + } - // Try to load Essentials Economy - if (packageExists(new String[] { "com.earth2me.essentials.api.Economy", "com.earth2me.essentials.api.NoLoanPermittedException", "com.earth2me.essentials.api.UserDoesNotExistException" })) { - Economy essentials = new Economy_Essentials(this); - getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, essentials, this, ServicePriority.Low); - log.info(String.format("[%s][Economy] Essentials Economy found: %s", getDescription().getName(), essentials.isEnabled() ? "Loaded" : "Waiting")); - } + // Try to load iConomy 4 + if (packageExists(new String[] { "com.nijiko.coelho.iConomy.iConomy", "com.nijiko.coelho.iConomy.system.Account" })) { + Economy icon4 = new Economy_iConomy4(this); + getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, icon4, this, ServicePriority.High); + log.info(String.format("[%s][Economy] iConomy 4 found: ", getDescription().getName(), icon4.isEnabled() ? "Loaded" : "Waiting")); + } - // Try to load iConomy 4 - if (packageExists(new String[] { "com.nijiko.coelho.iConomy.iConomy", "com.nijiko.coelho.iConomy.system.Account" })) { - Economy icon4 = new Economy_iConomy4(this); - getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, icon4, this, ServicePriority.High); - log.info(String.format("[%s][Economy] iConomy 4 found: ", getDescription().getName(), icon4.isEnabled() ? "Loaded" : "Waiting")); - } + // Try to load iConomy 5 + if (packageExists(new String[] { "com.iConomy.iConomy", "com.iConomy.system.Account", "com.iConomy.system.Holdings" })) { + Economy icon5 = new Economy_iConomy5(this); + getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, icon5, this, ServicePriority.High); + log.info(String.format("[%s][Economy] iConomy 5 found: %s", getDescription().getName(), icon5.isEnabled() ? "Loaded" : "Waiting")); + } - // Try to load iConomy 5 - if (packageExists(new String[] { "com.iConomy.iConomy", "com.iConomy.system.Account", "com.iConomy.system.Holdings" })) { - Economy icon5 = new Economy_iConomy5(this); - getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, icon5, this, ServicePriority.High); - log.info(String.format("[%s][Economy] iConomy 5 found: %s", getDescription().getName(), icon5.isEnabled() ? "Loaded" : "Waiting")); - } + // Try to load iConomy 6 + if (packageExists(new String[] { "com.iCo6.iConomy" })) { + Economy icon6 = new Economy_iConomy6(this); + getServer().getServicesManager().register(Economy.class, icon6, this, ServicePriority.High); + log.info(String.format("[%s][Economy] iConomy 6 found: %s", getDescription().getName(), icon6.isEnabled() ? "Loaded" : "Waiting")); + } - // Try to load iConomy 6 - if (packageExists(new String[] { "com.iCo6.iConomy" })) { - Economy icon6 = new Economy_iConomy6(this); - getServer().getServicesManager().register(Economy.class, icon6, this, ServicePriority.High); - log.info(String.format("[%s][Economy] iConomy 6 found: %s", getDescription().getName(), icon6.isEnabled() ? "Loaded" : "Waiting")); - } - - //Try loading EconXP + //Try loading EconXP if (packageExists(new String[] { "ca.agnate.EconXP.EconXP" })) { Economy econ = new Economy_EconXP(this); getServer().getServicesManager().register(Economy.class, econ, this, ServicePriority.Normal); log.info(String.format("[%s][Economy] EconXP found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); } - } + } - /** - * Attempts to load Permission Addons - */ - private void loadPermission() { - // Try to load PermissionsEx - if (packageExists(new String[] { "ru.tehkode.permissions.bukkit.PermissionsEx" })) { - Permission ePerms = new Permission_PermissionsEx(this); - getServer().getServicesManager().register(Permission.class, ePerms, this, ServicePriority.Highest); - log.info(String.format("[%s][Permission] PermissionsEx found: %s", getDescription().getName(), ePerms.isEnabled() ? "Loaded" : "Waiting")); - log.info(String.format("[%s] - Warning Using PEX can cause SuperPerms compatibility issues with non-Vault enabled plugins.", getDescription().getName())); - } + /** + * Attempts to load Permission Addons + */ + private void loadPermission() { + // Try to load PermissionsEx + if (packageExists(new String[] { "ru.tehkode.permissions.bukkit.PermissionsEx" })) { + Permission ePerms = new Permission_PermissionsEx(this); + getServer().getServicesManager().register(Permission.class, ePerms, this, ServicePriority.Highest); + log.info(String.format("[%s][Permission] PermissionsEx found: %s", getDescription().getName(), ePerms.isEnabled() ? "Loaded" : "Waiting")); + log.info(String.format("[%s] - Warning Using PEX can cause SuperPerms compatibility issues with non-Vault enabled plugins.", getDescription().getName())); + } - //Try loading PermissionsBukkit - if (packageExists(new String[] {"com.platymuus.bukkit.permissions.PermissionsPlugin"} )) { - Permission pPerms = new Permission_PermissionsBukkit(this); - getServer().getServicesManager().register(Permission.class, pPerms, this, ServicePriority.Highest); - log.info(String.format("[%s][Permission] PermissionsBukkit found: %s", getDescription().getName(), pPerms.isEnabled() ? "Loaded" : "Waiting")); - } + //Try loading PermissionsBukkit + if (packageExists(new String[] {"com.platymuus.bukkit.permissions.PermissionsPlugin"} )) { + Permission pPerms = new Permission_PermissionsBukkit(this); + getServer().getServicesManager().register(Permission.class, pPerms, this, ServicePriority.Highest); + log.info(String.format("[%s][Permission] PermissionsBukkit found: %s", getDescription().getName(), pPerms.isEnabled() ? "Loaded" : "Waiting")); + } - //Try to load bPermissions - if (packageExists(new String[] {"de.bananaco.permissions.worlds.WorldPermissionsManager"} )) { - Permission bPerms = new Permission_bPermissions(this); - getServer().getServicesManager().register(Permission.class, bPerms, this, ServicePriority.Highest); - log.info(String.format("[%s][Permission] bPermissions found: %s", getDescription().getName(), bPerms.isEnabled() ? "Loaded" : "Waiting")); - } + //Try to load bPermissions + if (packageExists(new String[] {"de.bananaco.permissions.worlds.WorldPermissionsManager"} )) { + Permission bPerms = new Permission_bPermissions(this); + getServer().getServicesManager().register(Permission.class, bPerms, this, ServicePriority.Highest); + log.info(String.format("[%s][Permission] bPermissions found: %s", getDescription().getName(), bPerms.isEnabled() ? "Loaded" : "Waiting")); + } - // Try to load GroupManager - if (packageExists(new String[] { "org.anjocaido.groupmanager.GroupManager" })) { - Permission gPerms = new Permission_GroupManager(this); - getServer().getServicesManager().register(Permission.class, gPerms, this, ServicePriority.High); - log.info(String.format("[%s][Permission] GroupManager found: %s", getDescription().getName(), gPerms.isEnabled() ? "Loaded" : "Waiting")); - } - // Try to load Permissions 3 (Yeti) - if (packageExists(new String[] { "com.nijiko.permissions.ModularControl" })) { - Permission nPerms = new Permission_Permissions3(this); - getServer().getServicesManager().register(Permission.class, nPerms, this, ServicePriority.High); - log.info(String.format("[%s][Permission] Permissions 3 (Yeti) found: %s", getDescription().getName(), nPerms.isEnabled() ? "Loaded" : "Waiting")); - } + // Try to load GroupManager + if (packageExists(new String[] { "org.anjocaido.groupmanager.GroupManager" })) { + Permission gPerms = new Permission_GroupManager(this); + getServer().getServicesManager().register(Permission.class, gPerms, this, ServicePriority.High); + log.info(String.format("[%s][Permission] GroupManager found: %s", getDescription().getName(), gPerms.isEnabled() ? "Loaded" : "Waiting")); + } + // Try to load Permissions 3 (Yeti) + if (packageExists(new String[] { "com.nijiko.permissions.ModularControl" })) { + Permission nPerms = new Permission_Permissions3(this); + getServer().getServicesManager().register(Permission.class, nPerms, this, ServicePriority.High); + log.info(String.format("[%s][Permission] Permissions 3 (Yeti) found: %s", getDescription().getName(), nPerms.isEnabled() ? "Loaded" : "Waiting")); + } - Permission perms = new Permission_SuperPerms(this); - getServer().getServicesManager().register(Permission.class, perms, this, ServicePriority.Lowest); - log.info(String.format("[%s][Permission] SuperPermissions loaded as backup permission system.", getDescription().getName())); + Permission perms = new Permission_SuperPerms(this); + getServer().getServicesManager().register(Permission.class, perms, this, ServicePriority.Lowest); + log.info(String.format("[%s][Permission] SuperPermissions loaded as backup permission system.", getDescription().getName())); + + this.perms = getServer().getServicesManager().getRegistration(Permission.class).getProvider(); + } - } + @Override + public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { + if (sender instanceof Player) { + // Check if Player + // If so, ignore command if player is not Op + Player p = (Player) sender; + if (!p.isOp()) { + return true; + } + } else if (!(sender instanceof ConsoleCommandSender)) { + // Check if NOT console + // Ignore it if not originated from Console! + return true; + } - @Override - public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { - if (sender instanceof Player) { - // Check if Player - // If so, ignore command if player is not Op - Player p = (Player) sender; - if (!p.isOp()) { - return true; - } - } else if (!(sender instanceof ConsoleCommandSender)) { - // Check if NOT console - // Ignore it if not originated from Console! - return true; - } + if (command.getLabel().equals("vault-info")) { - if (command.getLabel().equals("vault-info")) { + // Get String of Registered Economy Services + String registeredEcons = null; + Collection> econs = this.getServer().getServicesManager().getRegistrations(Economy.class); + for (RegisteredServiceProvider econ : econs) { + Economy e = econ.getProvider(); + if (registeredEcons == null) { + registeredEcons = e.getName(); + } else { + registeredEcons += ", " + e.getName(); + } + } - // Get String of Registered Economy Services - String registeredEcons = null; - Collection> econs = this.getServer().getServicesManager().getRegistrations(Economy.class); - for (RegisteredServiceProvider econ : econs) { - Economy e = econ.getProvider(); - if (registeredEcons == null) { - registeredEcons = e.getName(); - } else { - registeredEcons += ", " + e.getName(); - } - } + // Get String of Registered Permission Services + String registeredPerms = null; + Collection> perms = this.getServer().getServicesManager().getRegistrations(Permission.class); + for (RegisteredServiceProvider perm : perms) { + Permission p = perm.getProvider(); + if (registeredPerms == null) { + registeredPerms = p.getName(); + } else { + registeredPerms += ", " + p.getName(); + } + } - // Get String of Registered Permission Services - String registeredPerms = null; - Collection> perms = this.getServer().getServicesManager().getRegistrations(Permission.class); - for (RegisteredServiceProvider perm : perms) { - Permission p = perm.getProvider(); - if (registeredPerms == null) { - registeredPerms = p.getName(); - } else { - registeredPerms += ", " + p.getName(); - } - } + // Get Economy & Permission primary Services + Economy econ = getServer().getServicesManager().getRegistration(Economy.class).getProvider(); + Permission perm = getServer().getServicesManager().getRegistration(Permission.class).getProvider(); - // Get Economy & Permission primary Services - Economy econ = getServer().getServicesManager().getRegistration(Economy.class).getProvider(); - Permission perm = getServer().getServicesManager().getRegistration(Permission.class).getProvider(); + // Send user some info! + sender.sendMessage(String.format("[%s] Vault v%s Information", getDescription().getName(), getDescription().getVersion())); + sender.sendMessage(String.format("[%s] Economy: %s [%s]", getDescription().getName(), econ.getName(), registeredEcons)); + sender.sendMessage(String.format("[%s] Permission: %s [%s]", getDescription().getName(), perm.getName(), registeredPerms)); + return true; + } else { + // Show help + sender.sendMessage("Vault Commands:"); + sender.sendMessage(" /vault-info - Displays information about Vault"); + return true; + } + } - // Send user some info! - sender.sendMessage(String.format("[%s] Vault v%s Information", getDescription().getName(), getDescription().getVersion())); - sender.sendMessage(String.format("[%s] Economy: %s [%s]", getDescription().getName(), econ.getName(), registeredEcons)); - sender.sendMessage(String.format("[%s] Permission: %s [%s]", getDescription().getName(), perm.getName(), registeredPerms)); - return true; - } else { - // Show help - sender.sendMessage("Vault Commands:"); - sender.sendMessage(" /vault-info - Displays information about Vault"); - return true; - } - } + /** + * Determines if all packages in a String array are within the Classpath + * This is the best way to determine if a specific plugin exists and will be + * loaded. If the plugin package isn't loaded, we shouldn't bother waiting + * for it! + * @param packages String Array of package names to check + * @return Success or Failure + */ + private static boolean packageExists(String[] packages) { + try { + for (String pkg : packages) { + Class.forName(pkg); + } + return true; + } catch (Exception e) { + return false; + } + } - /** - * Determines if all packages in a String array are within the Classpath - * This is the best way to determine if a specific plugin exists and will be - * loaded. If the plugin package isn't loaded, we shouldn't bother waiting - * for it! - * @param packages String Array of package names to check - * @return Success or Failure - */ - private static boolean packageExists(String[] packages) { - try { - for (String pkg : packages) { - Class.forName(pkg); - } - return true; - } catch (Exception e) { - return false; - } - } - - public void updateCheck() throws Exception { - String pluginUrlString = "http://dev.bukkit.org/server-mods/vault/files.rss"; - try { - URL url = new URL(pluginUrlString); - Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(url.openConnection().getInputStream()); - doc.getDocumentElement().normalize(); - NodeList nodes = doc.getElementsByTagName("item"); - Node firstNode = nodes.item(0); - if (firstNode.getNodeType() == 1) { - Element firstElement = (Element)firstNode; - NodeList firstElementTagName = firstElement.getElementsByTagName("title"); - Element firstNameElement = (Element) firstElementTagName.item(0); - NodeList firstNodes = firstNameElement.getChildNodes(); - String newVersion = firstNodes.item(0).getNodeValue(); - String oldVersion = getDescription().getVersion().substring(0, 5); - if (!newVersion.contains(oldVersion)) { - log.warning(newVersion + " is out! You are running v" + oldVersion); - log.warning("Update Vault at: http://dev.bukkit.org/server-mods/vault"); - } - } - } - catch (Exception localException) { - } - } + public String updateCheck() throws Exception { + String pluginUrlString = "http://dev.bukkit.org/server-mods/vault/files.rss"; + try { + URL url = new URL(pluginUrlString); + Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(url.openConnection().getInputStream()); + doc.getDocumentElement().normalize(); + NodeList nodes = doc.getElementsByTagName("item"); + Node firstNode = nodes.item(0); + if (firstNode.getNodeType() == 1) { + Element firstElement = (Element)firstNode; + NodeList firstElementTagName = firstElement.getElementsByTagName("title"); + Element firstNameElement = (Element) firstElementTagName.item(0); + NodeList firstNodes = firstNameElement.getChildNodes(); + return firstNodes.item(0).getNodeValue(); + } + } + catch (Exception localException) { + return getDescription().getVersion().substring(0, 5); + } + return getDescription().getVersion().substring(0, 5); + } + + public class VaultPlayerListener extends PlayerListener { + + @Override + public void onPlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + if (perms.has(player, "vault.admin")) { + try { + String newVersion = updateCheck(); + String oldVersion = getDescription().getVersion().substring(0, 5); + if (!newVersion.contains(oldVersion)) { + player.sendMessage(newVersion + " is out! You are running " + oldVersion); + player.sendMessage("Update Vault at: http://dev.bukkit.org/server-mods/vault"); + } + } catch (Exception e) { + // Ignore exceptions + } + } + } + } }