diff --git a/.travis.yml b/.travis.yml index d4ad8593..fbd2ecb1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: java -jdk: [ openjdk8 ] -sudo: false +jdk: [ openjdk18 ] +os: linux +dist: xenial env: global: - secure: "WGObsHmjnqn5e0nbXLGetwpUHU0UgvNk02+f0m3jIS7hSdBy5m1JK2K6NXV13brY0C9i0DLy0e7JKabqmqTxI94dT0LrYBxcvfmtZ/7PujOn/D9CzVimGj6g20hBDYwAXL6KAIR7JL8qexQBwIkVZPdwaA+k+UHLM9XVoIQdFgU=" diff --git a/.utility/do-build.sh b/.utility/do-build.sh index 1a77ab62..14ef8bd4 100755 --- a/.utility/do-build.sh +++ b/.utility/do-build.sh @@ -1,11 +1,10 @@ #!/bin/bash -if [[ "$TRAVIS_REPO_SLUG" != "MilkBowl/Vault" ]] -then +if [[ "${TRAVIS_REPO_SLUG}" != "MilkBowl/Vault" ]]; then echo 'Travis can only publish docs for release builds.' return 0 fi -if [[ $TRAVIS_PULL_REQUEST == true || "$TRAVIS_BRANCH" != "master" ]] -then + +if [[ "${TRAVIS_PULL_REQUEST}" == "true" || "${TRAVIS_BRANCH}" != "master" ]]; then mvn test else mvn clean deploy --settings .utility/settings.xml diff --git a/README.md b/README.md index 866ac592..2221cb67 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,43 @@ # Vault - Abstraction Library for Bukkit - [![](https://travis-ci.org/MilkBowl/Vault.svg?branch=master)](https://travis-ci.org/MilkBowl/Vault) ## For Developers: -Please see the [VaultAPI](http://www.github.com/MilkBowl/VaultAPI) page for -information on developing with Vault's API. In the past you would use the same -artifact as servers installed, but the API has now been split from the main -project and is under a different artifact name. Please make sure you accommodate -for this change in your build process. +Please see the [VaultAPI](https://www.github.com/MilkBowl/VaultAPI) page for +information on developing with Vault's API. In the past, you would use the same +artifact as servers installed, but the API has now been split from the main +project and is under a different artifact name. Please make sure you accommodate +this change in your build process. ## Installing Installing Vault is as simple as copying the provided "Vault.jar" to your -"/plugins" directory and the rest is automatic! If you +"/plugins" directory, and the rest is automatic! If you wish to perform configuration changes, this can be done via a configuration -file but should not be necessary in most cases. See the "Advanced +file but should not be necessary in most cases. See the "Advanced Configuration" section for more information. ## Why Vault? I have no preference which library suits your plugin and development efforts -best. Really, I thought a central suite (rather...Vault) of solutions was the -the proper avenue than focusing on a single category of plugin. That's where +best. Really, I thought a central suite (rather...Vault) of solutions was the +proper avenue than focusing on a single category of plugin. That's where the idea for Vault came into play. So, what features do I _think_ you'll like the most? - * No need to include my source code in your plugin - All of Vault is run in its own plugin, so all you need to do is obtain an - instance of it! This simplifies issues with multiple plugins using the same - namespaces. Just simply add Vault.jar to your download zip file! - * Broad range of supported plugins - I wanted an abstraction layer not only for Economic plugins but also - Permission plugins as well. - * Choice! - That's half the fun of Bukkit, we get to choose what to use! More choice - has never hurt developers so here's to choice! +* No need to include my source code in your plugin + All of Vault is run in its own plugin, so all you need to do is obtain an + instance of it! This simplifies issues with multiple plugins using the same + namespaces. Just simply add Vault.jar to your download zip file! +* Broad range of supported plugins + I wanted an abstraction layer not only for Economic plugins but also + Permission plugins as well. +* Choice! + That's half the fun of Bukkit! We get to choose what to use! More choice + has never hurt developers, so here's to choice! ## Permissions - * vault.admin - - Determines if a player should recieve the update notices +* vault.admin + - Determines if a player should receive the update notices ## License Copyright (C) 2011-2018 Morgan Humes @@ -49,11 +49,11 @@ the Free Software Foundation, either version 3 of the License, or Vault is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License -along with Vault. If not, see . +with Vault. If not, see . ## Building Vault comes with all libraries needed to build from the current branch and @@ -63,74 +63,69 @@ also comes with an Apache Ant build file (build.xml) and a Maven build file ## Dependencies Because Vault provides a bridge to other plugins, their binaries will be -required to build from. To ease this, they have been included in the lib -folder and will be updated from time to time. For plugin developers, it -is not necessary to use these libraries when implementing Vault. You will +required to build from. To ease this, they have been included in the lib +folder and will be updated from time to time. For plugin developers, it +is not necessary to use these libraries when implementing Vault. You will only need to compile against Vault. ## Supported Plugins -Vault provides abstraction for the following categories and plugins. If -you have your own plugin that you believe should be supported you'll need +Vault provides abstraction for the following categories and plugins. If +you have your own plugin that you believe should be supported, you'll need to add your own connector within your plugin as Vault no longer maintains new plugin connectors. * Economy - - 3co (http://forums.bukkit.org/threads/22461/) - - AEco - - BOSEconomy 6 (http://forums.bukkit.org/threads/19025/) - - BOSEconomy 7 - - CommandsEX Economy (http://dev.bukkit.org/projects/commandsex) - - CraftConomy2 (http://dev.bukkit.org/projects/craftconomy) - - CraftConomy3 (http://dev.bukkit.org/projects/craftconomy) - - CurrencyCore (http://dev.bukkit.org/projects/currency) - - Dosh - - EconXP (http://dev.bukkit.org/projects/econxp) - - Essentials Economy (http://forums.bukkit.org/threads/15312/) - - eWallet (http://dev.bukkit.org/projects/ewallet) - - GoldIsMoney - - GoldIsMoney2 - - Gringotts - - iConomy 4 (http://forums.bukkit.org/threads/40/) - - iConomy 5 (http://forums.bukkit.org/threads/40/) - - iConomy 6 (http://forums.bukkit.org/threads/40/) - - McMoney - - Miconomy - - MineConomy (http://dev.bukkit.org/projects/mineconomy) - - MineFaconomy2 - - MultiCurrency - - SDFEconomy - - TAEcon - - XPBank + - BOSEconomy 6 (https://forums.bukkit.org/threads/19025/) + - BOSEconomy 7 + - CommandsEX Economy (https://dev.bukkit.org/projects/commandsex) + - CraftConomy2 (https://dev.bukkit.org/projects/craftconomy) + - CraftConomy3 (https://dev.bukkit.org/projects/craftconomy) + - CurrencyCore (https://dev.bukkit.org/projects/currency) + - Dosh + - EconXP (https://dev.bukkit.org/projects/econxp) + - Essentials Economy (https://forums.bukkit.org/threads/15312/) + - eWallet (https://dev.bukkit.org/projects/ewallet) + - GoldIsMoney + - GoldIsMoney2 + - Gringotts + - iConomy 4 (https://forums.bukkit.org/threads/40/) + - iConomy 5 (https://forums.bukkit.org/threads/40/) + - iConomy 6 (https://forums.bukkit.org/threads/40/) + - Miconomy + - MineConomy (https://dev.bukkit.org/projects/mineconomy) + - MultiCurrency + - SDFEconomy + - TAEcon + - XPBank * Permissions - - bPermissions - - bPermissions 2 (http://dev.bukkit.org/projects/bpermissions) - - DroxPerms - - Group Manager (Essentials) (http://forums.bukkit.org/threads/15312/) - - LuckPerms (https://www.spigotmc.org/resources/luckperms-an-advanced-permissions-plugin.28140/) - - OverPermissions (http://dev.bukkit.org/projects/overpermissions) - - Permissions 3 (http://forums.bukkit.org/threads/18430/) - - PermissionsBukkit - - Permissions Ex (PEX) (http://forums.bukkit.org/threads/18140/) - - Privileges - - rscPermissions - - SimplyPerms - - SuperPerms (Bukkit's default) - - TotalPermissions (http://dev.bukkit.org/projects/totalpermissions) - - XPerms - - zPermissions + - bPermissions + - bPermissions 2 (https://dev.bukkit.org/projects/bpermissions) + - Group Manager (Essentials) (https://forums.bukkit.org/threads/15312/) + - LuckPerms (https://www.spigotmc.org/resources/luckperms-an-advanced-permissions-plugin.28140/) + - OverPermissions (https://dev.bukkit.org/projects/overpermissions) + - Permissions 3 (https://forums.bukkit.org/threads/18430/) + - PermissionsBukkit + - Permissions Ex (PEX) (https://forums.bukkit.org/threads/18140/) + - Privileges + - rscPermissions + - SimplyPerms + - SuperPerms (Bukkit's default) + - TotalPermissions (https://dev.bukkit.org/projects/totalpermissions) + - XPerms + - zPermissions * Chat - - bPermissions - - Group Manager (Essentials) (http://forums.bukkit.org/threads/15312/) - - iChat - - LuckPerms (https://www.spigotmc.org/resources/luckperms-an-advanced-permissions-plugin.28140/) - - mChat - - mChatSuite - - OverPermissions (http://dev.bukkit.org/projects/overpermissions) - - Permissions 3 (http://forums.bukkit.org/threads/18430/) - - Permissions Ex (PEX) (http://forums.bukkit.org/threads/18140/) - - rscPermissions - - TotalPermissions (http://dev.bukkit.org/projects/totalpermissions) - - zPermissions + - bPermissions + - Group Manager (Essentials) (https://forums.bukkit.org/threads/15312/) + - iChat + - LuckPerms (https://www.spigotmc.org/resources/luckperms-an-advanced-permissions-plugin.28140/) + - mChat + - mChatSuite + - OverPermissions (https://dev.bukkit.org/projects/overpermissions) + - Permissions 3 (https://forums.bukkit.org/threads/18430/) + - Permissions Ex (PEX) (https://forums.bukkit.org/threads/18140/) + - rscPermissions + - TotalPermissions (https://dev.bukkit.org/projects/totalpermissions) + - zPermissions diff --git a/build.xml b/build.xml index 14c82abc..10292e8b 100644 --- a/build.xml +++ b/build.xml @@ -7,15 +7,15 @@ - + Building and Archiving the Javadocs - + Building the .jar file. - + Cleaning @@ -25,14 +25,14 @@ - + Compiling - + Compressing @@ -42,7 +42,7 @@ - + - - + + diff --git a/plugin.yml b/plugin.yml index 8591ddcc..759117e3 100644 --- a/plugin.yml +++ b/plugin.yml @@ -3,14 +3,14 @@ version: ${project.version}-b${env.TRAVIS_BUILD_NUMBER} description: ${project.description} authors: [cereal, Sleaker, mung3r] website: ${project.url} -api-version: 1.13 +api-version: 1.19 main: ${mainClass} -load: startup +load: STARTUP commands: vault-info: - description: Displays information about Vault + description: Displays information about Vault usage: | / - Displays Vault information permission: vault.admin diff --git a/pom.xml b/pom.xml index 5b8a6dfd..1a580c2e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,12 +1,14 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 UTF-8 - 1.13.1-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT ${project.groupId}.${project.artifactId} 1.7 + 18 + 18 @@ -42,12 +44,12 @@ Vault currently supports the following: Permissions 3, PEX, GroupManager, bPerms pub-repo Public Releases - http://nexus.hc.to/content/repositories/pub_releases/ + https://nexus.hc.to/content/repositories/pub_releases/ pub-repo Public Snapshots - http://nexus.hc.to/content/repositories/pub_snapshots/ + https://nexus.hc.to/content/repositories/pub_snapshots/ @@ -55,27 +57,38 @@ Vault currently supports the following: Permissions 3, PEX, GroupManager, bPerms pub-repo Public Releases - http://nexus.hc.to/content/repositories/pub_releases/ - - - spigot-repo - https://hub.spigotmc.org/nexus/content/groups/public/ + https://nexus.hc.to/content/repositories/pub_releases/ escapecraft-repo - http://dev.escapecraft.com/maven + https://dev.escapecraft.com/maven codemc-repo https://repo.codemc.org/repository/maven-public + + papermc + https://repo.papermc.io/repository/maven-public/ + + + localrepository + file://${project.basedir}/lib/ + - org.bukkit - bukkit - ${bukkitVersion} + org.projectlombok + lombok + 1.18.24 + provided + + + io.papermc.paper + paper-api + ${paperVersion} + provided net.milkbowl.vault @@ -85,7 +98,7 @@ Vault currently supports the following: Permissions 3, PEX, GroupManager, bPerms org.bstats bstats-bukkit - 1.5 + 3.0.0 com.gmail.bleedobsidian.miconomy @@ -322,7 +335,7 @@ Vault currently supports the following: Permissions 3, PEX, GroupManager, bPerms com.greatmancode craftconomy3 - 3.2.2-SNAPSHOT + 3.3.1 true diff --git a/src/net/milkbowl/vault/Vault.java b/src/net/milkbowl/vault/Vault.java index 30f6f17f..1eba8a3d 100644 --- a/src/net/milkbowl/vault/Vault.java +++ b/src/net/milkbowl/vault/Vault.java @@ -15,68 +15,13 @@ */ package net.milkbowl.vault; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLConnection; -import java.util.Collection; -import java.util.concurrent.Callable; -import java.util.logging.Logger; - +import com.nijikokun.register.payment.Methods; import net.milkbowl.vault.chat.Chat; -import net.milkbowl.vault.chat.plugins.Chat_DroxPerms; -import net.milkbowl.vault.chat.plugins.Chat_GroupManager; -import net.milkbowl.vault.chat.plugins.Chat_OverPermissions; -import net.milkbowl.vault.chat.plugins.Chat_Permissions3; -import net.milkbowl.vault.chat.plugins.Chat_PermissionsEx; -import net.milkbowl.vault.chat.plugins.Chat_Privileges; -import net.milkbowl.vault.chat.plugins.Chat_bPermissions; -import net.milkbowl.vault.chat.plugins.Chat_bPermissions2; -import net.milkbowl.vault.chat.plugins.Chat_iChat; -import net.milkbowl.vault.chat.plugins.Chat_mChat; -import net.milkbowl.vault.chat.plugins.Chat_mChatSuite; -import net.milkbowl.vault.chat.plugins.Chat_rscPermissions; +import net.milkbowl.vault.chat.plugins.*; import net.milkbowl.vault.economy.Economy; -import net.milkbowl.vault.economy.plugins.Economy_BOSE7; -import net.milkbowl.vault.economy.plugins.Economy_CommandsEX; -import net.milkbowl.vault.economy.plugins.Economy_Craftconomy3; -import net.milkbowl.vault.economy.plugins.Economy_CurrencyCore; -import net.milkbowl.vault.economy.plugins.Economy_DigiCoin; -import net.milkbowl.vault.economy.plugins.Economy_Dosh; -import net.milkbowl.vault.economy.plugins.Economy_EconXP; -import net.milkbowl.vault.economy.plugins.Economy_Essentials; -import net.milkbowl.vault.economy.plugins.Economy_GoldIsMoney2; -import net.milkbowl.vault.economy.plugins.Economy_GoldenChestEconomy; -import net.milkbowl.vault.economy.plugins.Economy_Gringotts; -import net.milkbowl.vault.economy.plugins.Economy_McMoney; -import net.milkbowl.vault.economy.plugins.Economy_MineConomy; -import net.milkbowl.vault.economy.plugins.Economy_MultiCurrency; -import net.milkbowl.vault.economy.plugins.Economy_TAEcon; -import net.milkbowl.vault.economy.plugins.Economy_XPBank; -import net.milkbowl.vault.economy.plugins.Economy_eWallet; -import net.milkbowl.vault.economy.plugins.Economy_iConomy6; -import net.milkbowl.vault.economy.plugins.Economy_SDFEconomy; -import net.milkbowl.vault.economy.plugins.Economy_Minefaconomy; +import net.milkbowl.vault.economy.plugins.*; import net.milkbowl.vault.permission.Permission; -import net.milkbowl.vault.permission.plugins.Permission_DroxPerms; -import net.milkbowl.vault.permission.plugins.Permission_GroupManager; -import net.milkbowl.vault.permission.plugins.Permission_OverPermissions; -import net.milkbowl.vault.permission.plugins.Permission_Permissions3; -import net.milkbowl.vault.permission.plugins.Permission_PermissionsBukkit; -import net.milkbowl.vault.permission.plugins.Permission_PermissionsEx; -import net.milkbowl.vault.permission.plugins.Permission_Privileges; -import net.milkbowl.vault.permission.plugins.Permission_SimplyPerms; -import net.milkbowl.vault.permission.plugins.Permission_Starburst; -import net.milkbowl.vault.permission.plugins.Permission_SuperPerms; -import net.milkbowl.vault.permission.plugins.Permission_Xperms; -import net.milkbowl.vault.permission.plugins.Permission_bPermissions; -import net.milkbowl.vault.permission.plugins.Permission_bPermissions2; -import net.milkbowl.vault.permission.plugins.Permission_TotalPermissions; -import net.milkbowl.vault.permission.plugins.Permission_rscPermissions; -import net.milkbowl.vault.permission.plugins.Permission_KPerms; - +import net.milkbowl.vault.permission.plugins.*; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -94,14 +39,19 @@ import org.bukkit.plugin.ServicePriority; import org.bukkit.plugin.ServicesManager; import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.JSONValue; -import com.nijikokun.register.payment.Methods; - -import net.milkbowl.vault.chat.plugins.Chat_TotalPermissions; -import net.milkbowl.vault.economy.plugins.Economy_MiConomy; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLConnection; +import java.util.Collection; +import java.util.logging.Logger; public class Vault extends JavaPlugin { @@ -109,8 +59,8 @@ public class Vault extends JavaPlugin { private static Logger log; private Permission perms; private String newVersionTitle = ""; - private double newVersion = 0; - private double currentVersion = 0; + private double newVersion; + private double currentVersion; private String currentVersionTitle = ""; private ServicesManager sm; private Vault plugin; @@ -118,77 +68,67 @@ public class Vault extends JavaPlugin { @Override public void onDisable() { // Remove all Service Registrations - getServer().getServicesManager().unregisterAll(this); + this.getServer().getServicesManager().unregisterAll(this); Bukkit.getScheduler().cancelTasks(this); } @Override public void onEnable() { - plugin = this; - log = this.getLogger(); - currentVersionTitle = getDescription().getVersion().split("-")[0]; - currentVersion = Double.valueOf(currentVersionTitle.replaceFirst("\\.", "")); - sm = getServer().getServicesManager(); + this.plugin = this; + Vault.log = getLogger(); + this.currentVersionTitle = this.getDescription().getVersion().split("-")[0]; + this.currentVersion = Double.parseDouble(this.currentVersionTitle.replaceFirst("\\.", "")); + this.sm = this.getServer().getServicesManager(); // set defaults - getConfig().addDefault("update-check", true); - getConfig().options().copyDefaults(true); - saveConfig(); + this.getConfig().addDefault("update-check", true); + this.getConfig().options().copyDefaults(true); + this.saveConfig(); // Load Vault Addons - loadEconomy(); - loadPermission(); - loadChat(); - - getCommand("vault-info").setExecutor(this); - getCommand("vault-convert").setExecutor(this); - getServer().getPluginManager().registerEvents(new VaultListener(), this); - // Schedule to check the version every 30 minutes for an update. This is to update the most recent + this.loadEconomy(); + this.loadPermission(); + this.loadChat(); + + this.getCommand("vault-info").setExecutor(this); + this.getCommand("vault-convert").setExecutor(this); + this.getServer().getPluginManager().registerEvents(new VaultListener(), this); + // Schedule to check the version every 30 minutes for an update. This is to update the most recent // version so if an admin reconnects they will be warned about newer versions. - this.getServer().getScheduler().runTask(this, new Runnable() { - - @Override - public void run() { - // Programmatically set the default permission value cause Bukkit doesn't handle plugin.yml properly for Load order STARTUP plugins - org.bukkit.permissions.Permission perm = getServer().getPluginManager().getPermission("vault.update"); - if (perm == null) - { - perm = new org.bukkit.permissions.Permission("vault.update"); - perm.setDefault(PermissionDefault.OP); - plugin.getServer().getPluginManager().addPermission(perm); - } - perm.setDescription("Allows a user or the console to check for vault updates"); - - getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { - - @Override - public void run() { - if (getServer().getConsoleSender().hasPermission("vault.update") && getConfig().getBoolean("update-check", true)) { - try { - log.info("Checking for Updates ... "); - newVersion = updateCheck(currentVersion); - if (newVersion > currentVersion) { - log.warning("Stable Version: " + newVersionTitle + " is out!" + " You are still running version: " + currentVersionTitle); - log.warning("Update at: https://dev.bukkit.org/projects/vault"); - } else if (currentVersion > newVersion) { - log.info("Stable Version: " + newVersionTitle + " | Current Version: " + currentVersionTitle); - } else { - log.info("No new version available"); - } - } catch (Exception e) { - // ignore exceptions - } + getServer().getScheduler().runTask(this, () -> { + // Programmatically set the default permission value cause Bukkit doesn't handle plugin.yml properly for Load order STARTUP plugins + org.bukkit.permissions.Permission perm = this.getServer().getPluginManager().getPermission("vault.update"); + if (perm == null) { + perm = new org.bukkit.permissions.Permission("vault.update"); + perm.setDefault(PermissionDefault.OP); + this.plugin.getServer().getPluginManager().addPermission(perm); + } + perm.setDescription("Allows a user or the console to check for vault updates"); + + this.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, () -> { + if (this.getServer().getConsoleSender().hasPermission("vault.update") && this.getConfig().getBoolean("update-check", true)) { + try { + Vault.log.info("Checking for Updates ... "); + this.newVersion = this.updateCheck(this.currentVersion); + if (this.newVersion > this.currentVersion) { + Vault.log.warning("Stable Version: " + this.newVersionTitle + " is out!" + " You are still running version: " + this.currentVersionTitle); + Vault.log.warning("Update at: https://dev.bukkit.org/projects/vault"); + } else if (this.currentVersion > this.newVersion) { + Vault.log.info("Stable Version: " + this.newVersionTitle + " | Current Version: " + this.currentVersionTitle); + } else { + Vault.log.info("No new version available"); } + } catch (final Exception e) { + // ignore exceptions } - }, 0, 432000); - - } + } + }, 0, 432000); }); // Load up the Plugin metrics - Metrics metrics = new Metrics(this); - findCustomData(metrics); + final Metrics metrics = new Metrics(this, 0); // TODO: Get the correct serviceId + this.findCustomData(metrics); - log.info(String.format("Enabled Version %s", getDescription().getVersion())); + Vault.log.info(String.format("Enabled Version %s", this.getDescription().getVersion())); } /** @@ -196,43 +136,43 @@ public void run() { */ private void loadChat() { // Try to load PermissionsEx - hookChat("PermissionsEx", Chat_PermissionsEx.class, ServicePriority.Highest, "ru.tehkode.permissions.bukkit.PermissionsEx"); + this.hookChat("PermissionsEx", Chat_PermissionsEx.class, ServicePriority.Highest, "ru.tehkode.permissions.bukkit.PermissionsEx"); // Try to load mChatSuite - hookChat("mChatSuite", Chat_mChatSuite.class, ServicePriority.Highest, "in.mDev.MiracleM4n.mChatSuite.mChatSuite"); + this.hookChat("mChatSuite", Chat_mChatSuite.class, ServicePriority.Highest, "in.mDev.MiracleM4n.mChatSuite.mChatSuite"); // Try to load mChat - hookChat("mChat", Chat_mChat.class, ServicePriority.Highest, "net.D3GN.MiracleM4n.mChat"); + this.hookChat("mChat", Chat_mChat.class, ServicePriority.Highest, "net.D3GN.MiracleM4n.mChat"); // Try to load OverPermissions - hookChat("OverPermissions", Chat_OverPermissions.class, ServicePriority.Highest, "com.overmc.overpermissions.internal.OverPermissions"); + this.hookChat("OverPermissions", Chat_OverPermissions.class, ServicePriority.Highest, "com.overmc.overpermissions.internal.OverPermissions"); // Try to load DroxPerms Chat - hookChat("DroxPerms", Chat_DroxPerms.class, ServicePriority.Lowest, "de.hydrox.bukkit.DroxPerms.DroxPerms"); + this.hookChat("DroxPerms", Chat_DroxPerms.class, ServicePriority.Lowest, "de.hydrox.bukkit.DroxPerms.DroxPerms"); // Try to load bPermssions 2 - hookChat("bPermssions2", Chat_bPermissions2.class, ServicePriority.Highest, "de.bananaco.bpermissions.api.ApiLayer"); + this.hookChat("bPermssions2", Chat_bPermissions2.class, ServicePriority.Highest, "de.bananaco.bpermissions.api.ApiLayer"); // Try to load bPermissions 1 - hookChat("bPermissions", Chat_bPermissions.class, ServicePriority.Normal, "de.bananaco.permissions.info.InfoReader"); + this.hookChat("bPermissions", Chat_bPermissions.class, ServicePriority.Normal, "de.bananaco.permissions.info.InfoReader"); // Try to load GroupManager - hookChat("GroupManager", Chat_GroupManager.class, ServicePriority.Normal, "org.anjocaido.groupmanager.GroupManager"); + this.hookChat("GroupManager", Chat_GroupManager.class, ServicePriority.Normal, "org.anjocaido.groupmanager.GroupManager"); // Try to load Permissions 3 (Yeti) - hookChat("Permissions3", Chat_Permissions3.class, ServicePriority.Normal, "com.nijiko.permissions.ModularControl"); + this.hookChat("Permissions3", Chat_Permissions3.class, ServicePriority.Normal, "com.nijiko.permissions.ModularControl"); // Try to load iChat - hookChat("iChat", Chat_iChat.class, ServicePriority.Low, "net.TheDgtl.iChat.iChat"); + this.hookChat("iChat", Chat_iChat.class, ServicePriority.Low, "net.TheDgtl.iChat.iChat"); // Try to load Privileges - hookChat("Privileges", Chat_Privileges.class, ServicePriority.Normal, "net.krinsoft.privileges.Privileges"); + this.hookChat("Privileges", Chat_Privileges.class, ServicePriority.Normal, "net.krinsoft.privileges.Privileges"); // Try to load rscPermissions - hookChat("rscPermissions", Chat_rscPermissions.class, ServicePriority.Normal, "ru.simsonic.rscPermissions.MainPluginClass"); + this.hookChat("rscPermissions", Chat_rscPermissions.class, ServicePriority.Normal, "ru.simsonic.rscPermissions.MainPluginClass"); //Try to load TotalPermissions - hookChat("TotalPermissions", Chat_TotalPermissions.class, ServicePriority.Normal, "net.ar97.totalpermissions.TotalPermissions"); + this.hookChat("TotalPermissions", Chat_TotalPermissions.class, ServicePriority.Normal, "net.ar97.totalpermissions.TotalPermissions"); } /** @@ -240,67 +180,67 @@ private void loadChat() { */ private void loadEconomy() { // Try to load MiConomy - hookEconomy("MiConomy", Economy_MiConomy.class, ServicePriority.Normal, "com.gmail.bleedobsidian.miconomy.Main"); + this.hookEconomy("MiConomy", Economy_MiConomy.class, ServicePriority.Normal, "com.gmail.bleedobsidian.miconomy.Main"); // Try to load MiFaConomy - hookEconomy("MineFaConomy", Economy_Minefaconomy.class, ServicePriority.Normal, "me.coniin.plugins.minefaconomy.Minefaconomy"); + this.hookEconomy("MineFaConomy", Economy_Minefaconomy.class, ServicePriority.Normal, "me.coniin.plugins.minefaconomy.Minefaconomy"); // Try to load MultiCurrency - hookEconomy("MultiCurrency", Economy_MultiCurrency.class, ServicePriority.Normal, "me.ashtheking.currency.Currency", "me.ashtheking.currency.CurrencyList"); + this.hookEconomy("MultiCurrency", Economy_MultiCurrency.class, ServicePriority.Normal, "me.ashtheking.currency.Currency", "me.ashtheking.currency.CurrencyList"); // Try to load MineConomy - hookEconomy("MineConomy", Economy_MineConomy.class, ServicePriority.Normal, "me.mjolnir.mineconomy.MineConomy"); + this.hookEconomy("MineConomy", Economy_MineConomy.class, ServicePriority.Normal, "me.mjolnir.mineconomy.MineConomy"); // Try to load McMoney - hookEconomy("McMoney", Economy_McMoney.class, ServicePriority.Normal, "boardinggamer.mcmoney.McMoneyAPI"); + this.hookEconomy("McMoney", Economy_McMoney.class, ServicePriority.Normal, "boardinggamer.mcmoney.McMoneyAPI"); // Try to load Craftconomy3 - hookEconomy("CraftConomy3", Economy_Craftconomy3.class, ServicePriority.Normal, "com.greatmancode.craftconomy3.tools.interfaces.BukkitLoader"); + this.hookEconomy("CraftConomy3", Economy_Craftconomy3.class, ServicePriority.Normal, "com.greatmancode.craftconomy3.tools.interfaces.BukkitLoader"); // Try to load eWallet - hookEconomy("eWallet", Economy_eWallet.class, ServicePriority.Normal, "me.ethan.eWallet.ECO"); + this.hookEconomy("eWallet", Economy_eWallet.class, ServicePriority.Normal, "me.ethan.eWallet.ECO"); // Try to load BOSEconomy 7 - hookEconomy("BOSEconomy7", Economy_BOSE7.class, ServicePriority.Normal, "cosine.boseconomy.BOSEconomy", "cosine.boseconomy.CommandHandler"); + this.hookEconomy("BOSEconomy7", Economy_BOSE7.class, ServicePriority.Normal, "cosine.boseconomy.BOSEconomy", "cosine.boseconomy.CommandHandler"); // Try to load CurrencyCore - hookEconomy("CurrencyCore", Economy_CurrencyCore.class, ServicePriority.Normal, "is.currency.Currency"); + this.hookEconomy("CurrencyCore", Economy_CurrencyCore.class, ServicePriority.Normal, "is.currency.Currency"); // Try to load Gringotts - hookEconomy("Gringotts", Economy_Gringotts.class, ServicePriority.Normal, "org.gestern.gringotts.Gringotts"); + this.hookEconomy("Gringotts", Economy_Gringotts.class, ServicePriority.Normal, "org.gestern.gringotts.Gringotts"); // Try to load Essentials Economy - hookEconomy("Essentials Economy", Economy_Essentials.class, ServicePriority.Low, "com.earth2me.essentials.api.Economy", "com.earth2me.essentials.api.NoLoanPermittedException", "com.earth2me.essentials.api.UserDoesNotExistException"); + this.hookEconomy("Essentials Economy", Economy_Essentials.class, ServicePriority.Low, "com.earth2me.essentials.api.Economy", "com.earth2me.essentials.api.NoLoanPermittedException", "com.earth2me.essentials.api.UserDoesNotExistException"); // Try to load iConomy 6 - hookEconomy("iConomy 6", Economy_iConomy6.class, ServicePriority.High, "com.iCo6.iConomy"); + this.hookEconomy("iConomy 6", Economy_iConomy6.class, ServicePriority.High, "com.iCo6.iConomy"); // Try to load EconXP - hookEconomy("EconXP", Economy_EconXP.class, ServicePriority.Normal, "ca.agnate.EconXP.EconXP"); + this.hookEconomy("EconXP", Economy_EconXP.class, ServicePriority.Normal, "ca.agnate.EconXP.EconXP"); // Try to load GoldIsMoney2 - hookEconomy("GoldIsMoney2", Economy_GoldIsMoney2.class, ServicePriority.Normal, "com.flobi.GoldIsMoney2.GoldIsMoney"); + this.hookEconomy("GoldIsMoney2", Economy_GoldIsMoney2.class, ServicePriority.Normal, "com.flobi.GoldIsMoney2.GoldIsMoney"); // Try to load GoldenChestEconomy - hookEconomy("GoldenChestEconomy", Economy_GoldenChestEconomy.class, ServicePriority.Normal, "me.igwb.GoldenChest.GoldenChestEconomy"); + this.hookEconomy("GoldenChestEconomy", Economy_GoldenChestEconomy.class, ServicePriority.Normal, "me.igwb.GoldenChest.GoldenChestEconomy"); // Try to load Dosh - hookEconomy("Dosh", Economy_Dosh.class, ServicePriority.Normal, "com.gravypod.Dosh.Dosh"); + this.hookEconomy("Dosh", Economy_Dosh.class, ServicePriority.Normal, "com.gravypod.Dosh.Dosh"); // Try to load CommandsEX Economy - hookEconomy("CommandsEX", Economy_CommandsEX.class, ServicePriority.Normal, "com.github.zathrus_writer.commandsex.api.EconomyAPI"); + this.hookEconomy("CommandsEX", Economy_CommandsEX.class, ServicePriority.Normal, "com.github.zathrus_writer.commandsex.api.EconomyAPI"); // Try to load SDFEconomy Economy - hookEconomy("SDFEconomy", Economy_SDFEconomy.class, ServicePriority.Normal, "com.github.omwah.SDFEconomy.SDFEconomy"); + this.hookEconomy("SDFEconomy", Economy_SDFEconomy.class, ServicePriority.Normal, "com.github.omwah.SDFEconomy.SDFEconomy"); // Try to load XPBank - hookEconomy("XPBank", Economy_XPBank.class, ServicePriority.Normal, "com.gmail.mirelatrue.xpbank.XPBank"); + this.hookEconomy("XPBank", Economy_XPBank.class, ServicePriority.Normal, "com.gmail.mirelatrue.xpbank.XPBank"); // Try to load TAEcon - hookEconomy("TAEcon", Economy_TAEcon.class, ServicePriority.Normal, "net.teamalpha.taecon.TAEcon"); + this.hookEconomy("TAEcon", Economy_TAEcon.class, ServicePriority.Normal, "net.teamalpha.taecon.TAEcon"); // Try to load DigiCoin - hookEconomy("DigiCoin", Economy_DigiCoin.class, ServicePriority.Normal, "co.uk.silvania.cities.digicoin.DigiCoin"); + this.hookEconomy("DigiCoin", Economy_DigiCoin.class, ServicePriority.Normal, "co.uk.silvania.cities.digicoin.DigiCoin"); } /** @@ -308,105 +248,105 @@ private void loadEconomy() { */ private void loadPermission() { // Try to load Starburst - hookPermission("Starburst", Permission_Starburst.class, ServicePriority.Highest, "com.dthielke.starburst.StarburstPlugin"); + this.hookPermission("Starburst", Permission_Starburst.class, ServicePriority.Highest, "com.dthielke.starburst.StarburstPlugin"); // Try to load PermissionsEx - hookPermission("PermissionsEx", Permission_PermissionsEx.class, ServicePriority.Highest, "ru.tehkode.permissions.bukkit.PermissionsEx"); + this.hookPermission("PermissionsEx", Permission_PermissionsEx.class, ServicePriority.Highest, "ru.tehkode.permissions.bukkit.PermissionsEx"); // Try to load OverPermissions - hookPermission("OverPermissions", Permission_OverPermissions.class, ServicePriority.Highest, "com.overmc.overpermissions.internal.OverPermissions"); + this.hookPermission("OverPermissions", Permission_OverPermissions.class, ServicePriority.Highest, "com.overmc.overpermissions.internal.OverPermissions"); // Try to load PermissionsBukkit - hookPermission("PermissionsBukkit", Permission_PermissionsBukkit.class, ServicePriority.Normal, "com.platymuus.bukkit.permissions.PermissionsPlugin"); + this.hookPermission("PermissionsBukkit", Permission_PermissionsBukkit.class, ServicePriority.Normal, "com.platymuus.bukkit.permissions.PermissionsPlugin"); // Try to load DroxPerms - hookPermission("DroxPerms", Permission_DroxPerms.class, ServicePriority.High, "de.hydrox.bukkit.DroxPerms.DroxPerms"); + this.hookPermission("DroxPerms", Permission_DroxPerms.class, ServicePriority.High, "de.hydrox.bukkit.DroxPerms.DroxPerms"); // Try to load SimplyPerms - hookPermission("SimplyPerms", Permission_SimplyPerms.class, ServicePriority.Highest, "net.crystalyx.bukkit.simplyperms.SimplyPlugin"); + this.hookPermission("SimplyPerms", Permission_SimplyPerms.class, ServicePriority.Highest, "net.crystalyx.bukkit.simplyperms.SimplyPlugin"); // Try to load bPermissions2 - hookPermission("bPermissions 2", Permission_bPermissions2.class, ServicePriority.Highest, "de.bananaco.bpermissions.api.WorldManager"); + this.hookPermission("bPermissions 2", Permission_bPermissions2.class, ServicePriority.Highest, "de.bananaco.bpermissions.api.WorldManager"); // Try to load Privileges - hookPermission("Privileges", Permission_Privileges.class, ServicePriority.Highest, "net.krinsoft.privileges.Privileges"); + this.hookPermission("Privileges", Permission_Privileges.class, ServicePriority.Highest, "net.krinsoft.privileges.Privileges"); // Try to load bPermissions - hookPermission("bPermissions", Permission_bPermissions.class, ServicePriority.High, "de.bananaco.permissions.SuperPermissionHandler"); + this.hookPermission("bPermissions", Permission_bPermissions.class, ServicePriority.High, "de.bananaco.permissions.SuperPermissionHandler"); // Try to load GroupManager - hookPermission("GroupManager", Permission_GroupManager.class, ServicePriority.High, "org.anjocaido.groupmanager.GroupManager"); + this.hookPermission("GroupManager", Permission_GroupManager.class, ServicePriority.High, "org.anjocaido.groupmanager.GroupManager"); // Try to load Permissions 3 (Yeti) - hookPermission("Permissions 3 (Yeti)", Permission_Permissions3.class, ServicePriority.Normal, "com.nijiko.permissions.ModularControl"); + this.hookPermission("Permissions 3 (Yeti)", Permission_Permissions3.class, ServicePriority.Normal, "com.nijiko.permissions.ModularControl"); // Try to load Xperms - hookPermission("Xperms", Permission_Xperms.class, ServicePriority.Low, "com.github.sebc722.Xperms"); + this.hookPermission("Xperms", Permission_Xperms.class, ServicePriority.Low, "com.github.sebc722.Xperms"); //Try to load TotalPermissions - hookPermission("TotalPermissions", Permission_TotalPermissions.class, ServicePriority.Normal, "net.ae97.totalpermissions.TotalPermissions"); + this.hookPermission("TotalPermissions", Permission_TotalPermissions.class, ServicePriority.Normal, "net.ae97.totalpermissions.TotalPermissions"); // Try to load rscPermissions - hookPermission("rscPermissions", Permission_rscPermissions.class, ServicePriority.Normal, "ru.simsonic.rscPermissions.MainPluginClass"); + this.hookPermission("rscPermissions", Permission_rscPermissions.class, ServicePriority.Normal, "ru.simsonic.rscPermissions.MainPluginClass"); // Try to load KPerms - hookPermission("KPerms", Permission_KPerms.class, ServicePriority.Normal, "com.lightniinja.kperms.KPermsPlugin"); + this.hookPermission("KPerms", Permission_KPerms.class, ServicePriority.Normal, "com.lightniinja.kperms.KPermsPlugin"); - Permission perms = new Permission_SuperPerms(this); - sm.register(Permission.class, perms, this, ServicePriority.Lowest); - log.info(String.format("[Permission] SuperPermissions loaded as backup permission system.")); + final Permission perms = new Permission_SuperPerms(this); + this.sm.register(Permission.class, perms, this, ServicePriority.Lowest); + Vault.log.info("[Permission] SuperPermissions loaded as backup permission system."); - this.perms = sm.getRegistration(Permission.class).getProvider(); + this.perms = this.sm.getRegistration(Permission.class).getProvider(); } - private void hookChat (String name, Class hookClass, ServicePriority priority, String...packages) { + private void hookChat(final String name, final Class hookClass, final ServicePriority priority, final String... packages) { try { - if (packagesExists(packages)) { - Chat chat = hookClass.getConstructor(Plugin.class, Permission.class).newInstance(this, perms); - sm.register(Chat.class, chat, this, priority); - log.info(String.format("[Chat] %s found: %s", name, chat.isEnabled() ? "Loaded" : "Waiting")); + if (Vault.packagesExists(packages)) { + final Chat chat = hookClass.getConstructor(Plugin.class, Permission.class).newInstance(this, this.perms); + this.sm.register(Chat.class, chat, this, priority); + Vault.log.info(String.format("[Chat] %s found: %s", name, chat.isEnabled() ? "Loaded" : "Waiting")); } - } catch (Exception e) { - log.severe(String.format("[Chat] There was an error hooking %s - check to make sure you're using a compatible version!", name)); + } catch (final Exception e) { + Vault.log.severe(String.format("[Chat] There was an error hooking %s - check to make sure you're using a compatible version!", name)); } } - private void hookEconomy (String name, Class hookClass, ServicePriority priority, String...packages) { + private void hookEconomy(final String name, final Class hookClass, final ServicePriority priority, final String... packages) { try { - if (packagesExists(packages)) { - Economy econ = hookClass.getConstructor(Plugin.class).newInstance(this); - sm.register(Economy.class, econ, this, priority); - log.info(String.format("[Economy] %s found: %s", name, econ.isEnabled() ? "Loaded" : "Waiting")); + if (Vault.packagesExists(packages)) { + final Economy econ = hookClass.getConstructor(Plugin.class).newInstance(this); + this.sm.register(Economy.class, econ, this, priority); + Vault.log.info(String.format("[Economy] %s found: %s", name, econ.isEnabled() ? "Loaded" : "Waiting")); } - } catch (Exception e) { - log.severe(String.format("[Economy] There was an error hooking %s - check to make sure you're using a compatible version!", name)); + } catch (final Exception e) { + Vault.log.severe(String.format("[Economy] There was an error hooking %s - check to make sure you're using a compatible version!", name)); } } - private void hookPermission (String name, Class hookClass, ServicePriority priority, String...packages) { + private void hookPermission(final String name, final Class hookClass, final ServicePriority priority, final String... packages) { try { - if (packagesExists(packages)) { - Permission perms = hookClass.getConstructor(Plugin.class).newInstance(this); - sm.register(Permission.class, perms, this, priority); - log.info(String.format("[Permission] %s found: %s", name, perms.isEnabled() ? "Loaded" : "Waiting")); + if (Vault.packagesExists(packages)) { + final Permission perms = hookClass.getConstructor(Plugin.class).newInstance(this); + this.sm.register(Permission.class, perms, this, priority); + Vault.log.info(String.format("[Permission] %s found: %s", name, perms.isEnabled() ? "Loaded" : "Waiting")); } - } catch (Exception e) { - log.severe(String.format("[Permission] There was an error hooking %s - check to make sure you're using a compatible version!", name)); + } catch (final Exception e) { + Vault.log.severe(String.format("[Permission] There was an error hooking %s - check to make sure you're using a compatible version!", name)); } } @Override - public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { + public boolean onCommand(final CommandSender sender, @NotNull final Command command, @NotNull final String commandLabel, final String[] args) { if (!sender.hasPermission("vault.admin")) { sender.sendMessage("You do not have permission to use that command!"); return true; } if (command.getName().equalsIgnoreCase("vault-info")) { - infoCommand(sender); + this.infoCommand(sender); return true; } else if (command.getName().equalsIgnoreCase("vault-convert")) { - convertCommand(sender, args); + this.convertCommand(sender, args); return true; } else { // Show help @@ -417,8 +357,8 @@ public boolean onCommand(CommandSender sender, Command command, String commandLa } } - private void convertCommand(CommandSender sender, String[] args) { - Collection> econs = this.getServer().getServicesManager().getRegistrations(Economy.class); + private void convertCommand(final CommandSender sender, final String[] args) { + final Collection> econs = getServer().getServicesManager().getRegistrations(Economy.class); if (econs == null || econs.size() < 2) { sender.sendMessage("You must have at least 2 economies loaded to convert."); return; @@ -428,18 +368,18 @@ private void convertCommand(CommandSender sender, String[] args) { } Economy econ1 = null; Economy econ2 = null; - String economies = ""; - for (RegisteredServiceProvider econ : econs) { - String econName = econ.getProvider().getName().replace(" ", ""); + final StringBuilder economies = new StringBuilder(); + for (final RegisteredServiceProvider econ : econs) { + final String econName = econ.getProvider().getName().replace(" ", ""); if (econName.equalsIgnoreCase(args[0])) { econ1 = econ.getProvider(); } else if (econName.equalsIgnoreCase(args[1])) { econ2 = econ.getProvider(); } if (economies.length() > 0) { - economies += ", "; + economies.append(", "); } - economies += econName; + economies.append(econName); } if (econ1 == null) { @@ -453,81 +393,81 @@ private void convertCommand(CommandSender sender, String[] args) { } sender.sendMessage("This may take some time to convert, expect server lag."); - for (OfflinePlayer op : Bukkit.getServer().getOfflinePlayers()) { + for (final OfflinePlayer op : Bukkit.getServer().getOfflinePlayers()) { if (econ1.hasAccount(op)) { if (econ2.hasAccount(op)) { continue; } econ2.createPlayerAccount(op); - double diff = econ1.getBalance(op) - econ2.getBalance(op); + final double diff = econ1.getBalance(op) - econ2.getBalance(op); if (diff > 0) { - econ2.depositPlayer(op, diff); + econ2.depositPlayer(op, diff); } else if (diff < 0) { - econ2.withdrawPlayer(op, -diff); + econ2.withdrawPlayer(op, -diff); } - + } } sender.sendMessage("Converson complete, please verify the data before using it."); } - private void infoCommand(CommandSender sender) { + private void infoCommand(final CommandSender sender) { // 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(); + StringBuilder registeredEcons = null; + final Collection> econs = getServer().getServicesManager().getRegistrations(Economy.class); + for (final RegisteredServiceProvider econ : econs) { + final Economy e = econ.getProvider(); if (registeredEcons == null) { - registeredEcons = e.getName(); + registeredEcons = new StringBuilder(e.getName()); } else { - registeredEcons += ", " + e.getName(); + registeredEcons.append(", ").append(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(); + StringBuilder registeredPerms = null; + final Collection> perms = getServer().getServicesManager().getRegistrations(Permission.class); + for (final RegisteredServiceProvider perm : perms) { + final Permission p = perm.getProvider(); if (registeredPerms == null) { - registeredPerms = p.getName(); + registeredPerms = new StringBuilder(p.getName()); } else { - registeredPerms += ", " + p.getName(); + registeredPerms.append(", ").append(p.getName()); } } - String registeredChats = null; - Collection> chats = this.getServer().getServicesManager().getRegistrations(Chat.class); - for (RegisteredServiceProvider chat : chats) { - Chat c = chat.getProvider(); + StringBuilder registeredChats = null; + final Collection> chats = getServer().getServicesManager().getRegistrations(Chat.class); + for (final RegisteredServiceProvider chat : chats) { + final Chat c = chat.getProvider(); if (registeredChats == null) { - registeredChats = c.getName(); + registeredChats = new StringBuilder(c.getName()); } else { - registeredChats += ", " + c.getName(); + registeredChats.append(", ").append(c.getName()); } } // Get Economy & Permission primary Services - RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); + final RegisteredServiceProvider rsp = this.getServer().getServicesManager().getRegistration(Economy.class); Economy econ = null; if (rsp != null) { econ = rsp.getProvider(); } Permission perm = null; - RegisteredServiceProvider rspp = getServer().getServicesManager().getRegistration(Permission.class); + final RegisteredServiceProvider rspp = this.getServer().getServicesManager().getRegistration(Permission.class); if (rspp != null) { perm = rspp.getProvider(); } Chat chat = null; - RegisteredServiceProvider rspc = getServer().getServicesManager().getRegistration(Chat.class); + final RegisteredServiceProvider rspc = this.getServer().getServicesManager().getRegistration(Chat.class); if (rspc != null) { chat = rspc.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 == null ? "None" : econ.getName(), registeredEcons)); - sender.sendMessage(String.format("[%s] Permission: %s [%s]", getDescription().getName(), perm == null ? "None" : perm.getName(), registeredPerms)); - sender.sendMessage(String.format("[%s] Chat: %s [%s]", getDescription().getName(), chat == null ? "None" : chat.getName(), registeredChats)); + sender.sendMessage(String.format("[%s] Vault v%s Information", this.getDescription().getName(), this.getDescription().getVersion())); + sender.sendMessage(String.format("[%s] Economy: %s [%s]", this.getDescription().getName(), econ == null ? "None" : econ.getName(), registeredEcons.toString())); + sender.sendMessage(String.format("[%s] Permission: %s [%s]", this.getDescription().getName(), perm == null ? "None" : perm.getName(), registeredPerms.toString())); + sender.sendMessage(String.format("[%s] Chat: %s [%s]", this.getDescription().getName(), chat == null ? "None" : chat.getName(), registeredChats.toString())); } /** @@ -535,123 +475,103 @@ private void infoCommand(CommandSender sender) { * 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 packagesExists(String...packages) { + private static boolean packagesExists(final String... packages) { try { - for (String pkg : packages) { + for (final String pkg : packages) { Class.forName(pkg); } return true; - } catch (Exception e) { + } catch (final Exception e) { return false; } } - public double updateCheck(double currentVersion) { + public double updateCheck(final double currentVersion) { try { - URL url = new URL("https://api.curseforge.com/servermods/files?projectids=33184"); - URLConnection conn = url.openConnection(); + final URL url = new URL("https://api.curseforge.com/servermods/files?projectids=33184"); + final URLConnection conn = url.openConnection(); conn.setReadTimeout(5000); conn.addRequestProperty("User-Agent", "Vault Update Checker"); conn.setDoOutput(true); - final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); - final String response = reader.readLine(); - final JSONArray array = (JSONArray) JSONValue.parse(response); + BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); + String response = reader.readLine(); + JSONArray array = (JSONArray) JSONValue.parse(response); if (array.size() == 0) { - this.getLogger().warning("No files found, or Feed URL is bad."); + getLogger().warning("No files found, or Feed URL is bad."); return currentVersion; } // Pull the last version from the JSON - newVersionTitle = ((String) ((JSONObject) array.get(array.size() - 1)).get("name")).replace("Vault", "").trim(); - return Double.valueOf(newVersionTitle.replaceFirst("\\.", "").trim()); - } catch (Exception e) { - log.info("There was an issue attempting to check for the latest version."); + this.newVersionTitle = ((String) ((JSONObject) array.get(array.size() - 1)).get("name")).replace("Vault", "").trim(); + return Double.parseDouble(this.newVersionTitle.replaceFirst("\\.", "").trim()); + } catch (final Exception e) { + Vault.log.info("There was an issue attempting to check for the latest version."); } return currentVersion; } - private void findCustomData(Metrics metrics) { + private void findCustomData(final Metrics metrics) { // Create our Economy Graph and Add our Economy plotters - RegisteredServiceProvider rspEcon = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); + final RegisteredServiceProvider rspEcon = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); Economy econ = null; if (rspEcon != null) { econ = rspEcon.getProvider(); } - final String econName = econ != null ? econ.getName() : "No Economy"; - metrics.addCustomChart(new Metrics.SimplePie("economy", new Callable() { - @Override - public String call() { - return econName; - } - })); + String econName = econ != null ? econ.getName() : "No Economy"; + // TODO: Find out if you can do this right (no org.bstats.charts) + metrics.addCustomChart(new org.bstats.charts.SimplePie("economy", () -> econName)); // Create our Permission Graph and Add our permission Plotters - final String permName = Bukkit.getServer().getServicesManager().getRegistration(Permission.class).getProvider().getName(); - metrics.addCustomChart(new Metrics.SimplePie("permission", new Callable() { - @Override - public String call() { - return permName; - } - })); + String permName = Bukkit.getServer().getServicesManager().getRegistration(Permission.class).getProvider().getName(); + metrics.addCustomChart(new org.bstats.charts.SimplePie("permission", () -> permName)); // Create our Chat Graph and Add our chat Plotters - RegisteredServiceProvider rspChat = Bukkit.getServer().getServicesManager().getRegistration(Chat.class); + final RegisteredServiceProvider rspChat = Bukkit.getServer().getServicesManager().getRegistration(Chat.class); Chat chat = null; if (rspChat != null) { chat = rspChat.getProvider(); } - final String chatName = chat != null ? chat.getName() : "No Chat"; - metrics.addCustomChart(new Metrics.SimplePie("chat", new Callable() { - @Override - public String call() { - return chatName; - } - })); + String chatName = chat != null ? chat.getName() : "No Chat"; + metrics.addCustomChart(new org.bstats.charts.SimplePie("chat", () -> chatName)); } public class VaultListener implements Listener { @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - if (perms.has(player, "vault.update")) { + public void onPlayerJoin(final PlayerJoinEvent event) { + final Player player = event.getPlayer(); + if (Vault.this.perms.has(player, "vault.update")) { try { - if (newVersion > currentVersion) { - player.sendMessage("Vault " + newVersionTitle + " is out! You are running " + currentVersionTitle); - player.sendMessage("Update Vault at: " + VAULT_BUKKIT_URL); + if (Vault.this.newVersion > Vault.this.currentVersion) { + player.sendMessage("Vault " + Vault.this.newVersionTitle + " is out! You are running " + Vault.this.currentVersionTitle); + player.sendMessage("Update Vault at: " + Vault.VAULT_BUKKIT_URL); } - } catch (Exception e) { + } catch (final Exception e) { // Ignore exceptions } } } @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (event.getPlugin().getDescription().getName().equals("Register") && packagesExists("com.nijikokun.register.payment.Methods")) { + public void onPluginEnable(final PluginEnableEvent event) { + if (event.getPlugin().getDescription().getName().equals("Register") && Vault.packagesExists("com.nijikokun.register.payment.Methods")) { if (!Methods.hasMethod()) { try { - Method m = Methods.class.getMethod("addMethod", Methods.class); + final Method m = Methods.class.getMethod("addMethod", Methods.class); m.setAccessible(true); m.invoke(null, "Vault", new net.milkbowl.vault.VaultEco()); if (!Methods.setPreferred("Vault")) { - log.info("Unable to hook register"); + Vault.log.info("Unable to hook register"); } else { - log.info("[Vault] - Successfully injected Vault methods into Register."); + Vault.log.info("[Vault] - Successfully injected Vault methods into Register."); } - } catch (SecurityException e) { - log.info("Unable to hook register"); - } catch (NoSuchMethodException e) { - log.info("Unable to hook register"); - } catch (IllegalArgumentException e) { - log.info("Unable to hook register"); - } catch (IllegalAccessException e) { - log.info("Unable to hook register"); - } catch (InvocationTargetException e) { - log.info("Unable to hook register"); + } catch (final SecurityException | InvocationTargetException | IllegalAccessException | + IllegalArgumentException | NoSuchMethodException e) { + Vault.log.info("Unable to hook register"); } } } diff --git a/src/net/milkbowl/vault/VaultEco.java b/src/net/milkbowl/vault/VaultEco.java index 6e9f3029..112ce35a 100644 --- a/src/net/milkbowl/vault/VaultEco.java +++ b/src/net/milkbowl/vault/VaultEco.java @@ -15,229 +15,226 @@ */ package net.milkbowl.vault; -import net.milkbowl.vault.Vault; +import com.nijikokun.register.payment.Method; import net.milkbowl.vault.economy.Economy; - import org.bukkit.plugin.Plugin; import org.bukkit.plugin.RegisteredServiceProvider; -import com.nijikokun.register.payment.Method; - @SuppressWarnings("deprecation") public class VaultEco implements Method { - - private Vault vault; - private Economy economy; - - public Vault getPlugin() { - return this.vault; - } - - + + private Vault vault; + private Economy economy; + + public Vault getPlugin() { + return vault; + } + + @Override - public boolean createAccount(String name, Double amount) { - if(!this.economy.createBank(name, "").transactionSuccess()) { - return false; - } - return this.economy.bankDeposit(name, amount).transactionSuccess(); - } - - public String getName() { - return this.vault.getDescription().getName(); - } - - public String getVersion() { - return this.vault.getDescription().getVersion(); - } - - public int fractionalDigits() { - return this.economy.fractionalDigits(); - } - - public String format(double amount) { - return this.economy.format(amount); - } - - public boolean hasBanks() { - return this.economy.hasBankSupport(); - } - - public boolean hasBank(String bank) { - return this.economy.getBanks().contains(bank); - } - - public boolean hasAccount(String name) { - return this.economy.hasAccount(name); - } - - public boolean hasBankAccount(String bank, String name) { - return this.economy.isBankOwner(bank, name).transactionSuccess() || this.economy.isBankMember(bank, name).transactionSuccess(); - } - - public boolean createAccount(String name) { - return this.economy.createPlayerAccount(name); - } - - public MethodAccount getAccount(String name) { - if(!hasAccount(name)) { - return null; - } - - return new VaultAccount(name, this.economy); - } - - public MethodBankAccount getBankAccount(String bank, String name) { - if(!hasBankAccount(bank, name)) { - return null; - } - - return new VaultBankAccount(bank, economy); - } - - public boolean isCompatible(Plugin plugin) { - return plugin instanceof Vault; - } - - public void setPlugin(Plugin plugin) { - this.vault = (Vault) plugin; - RegisteredServiceProvider economyProvider = this.vault.getServer().getServicesManager().getRegistration(Economy.class); - if (economyProvider != null) { - this.economy = economyProvider.getProvider(); - } - } - - public class VaultAccount implements MethodAccount { - private final String name; - private final Economy economy; - - public VaultAccount(String name, Economy economy) { - this.name = name; - this.economy = economy; - } - - public double balance() { - return this.economy.getBalance(this.name); - } - - public boolean set(double amount) { - if(!this.economy.withdrawPlayer(this.name, this.balance()).transactionSuccess()) { - return false; - } - - if(amount == 0) { - return true; - } - return this.economy.depositPlayer(this.name, amount).transactionSuccess(); - } - - public boolean add(double amount) { - return this.economy.depositPlayer(this.name, amount).transactionSuccess(); - } - - public boolean subtract(double amount) { - return this.economy.withdrawPlayer(this.name, amount).transactionSuccess(); - } - - public boolean multiply(double amount) { - double balance = this.balance(); - return this.set(balance * amount); - } - - public boolean divide(double amount) { - double balance = this.balance(); - return this.set(balance / amount); - } - - public boolean hasEnough(double amount) { - return (this.balance() >= amount); - } - - public boolean hasOver(double amount) { - return (this.balance() > amount); - } - - public boolean hasUnder(double amount) { - return (this.balance() < amount); - } - - public boolean isNegative() { - return (this.balance() < 0); - } - - public boolean remove() { - return this.set(0.0); - } - } - - public class VaultBankAccount implements MethodBankAccount { - - private final String bank; - private final Economy economy; - - public VaultBankAccount(String bank, Economy economy) { - this.bank = bank; - this.economy = economy; - } - - public String getBankName() { - return this.bank; - } - - public int getBankId() { - return -1; - } - - public double balance() { - return this.economy.bankBalance(this.bank).balance; - } - - public boolean set(double amount) { - if(!this.economy.bankWithdraw(this.bank, this.balance()).transactionSuccess()) { - return false; - } - if(amount == 0) { - return true; - } - return this.economy.bankDeposit(this.bank, amount).transactionSuccess(); - } - - public boolean add(double amount) { - return this.economy.bankDeposit(this.bank, amount).transactionSuccess(); - } - - public boolean subtract(double amount) { - return this.economy.bankWithdraw(this.bank, amount).transactionSuccess(); - } - - public boolean multiply(double amount) { - double balance = this.balance(); - return this.set(balance * amount); - } - - public boolean divide(double amount) { - double balance = this.balance(); - return this.set(balance / amount); - } - - public boolean hasEnough(double amount) { - return (this.balance() >= amount); - } - - public boolean hasOver(double amount) { - return (this.balance() > amount); - } - - public boolean hasUnder(double amount) { - return (this.balance() < amount); - } - - public boolean isNegative() { - return (this.balance() < 0); - } - - public boolean remove() { - return this.set(0.0); - } - - } + public boolean createAccount(final String name, final Double amount) { + if (!economy.createBank(name, "").transactionSuccess()) { + return false; + } + return economy.bankDeposit(name, amount).transactionSuccess(); + } + + public String getName() { + return vault.getDescription().getName(); + } + + public String getVersion() { + return vault.getDescription().getVersion(); + } + + public int fractionalDigits() { + return economy.fractionalDigits(); + } + + public String format(final double amount) { + return economy.format(amount); + } + + public boolean hasBanks() { + return economy.hasBankSupport(); + } + + public boolean hasBank(final String bank) { + return economy.getBanks().contains(bank); + } + + public boolean hasAccount(final String name) { + return economy.hasAccount(name); + } + + public boolean hasBankAccount(final String bank, final String name) { + return economy.isBankOwner(bank, name).transactionSuccess() || economy.isBankMember(bank, name).transactionSuccess(); + } + + public boolean createAccount(final String name) { + return economy.createPlayerAccount(name); + } + + public Method.MethodAccount getAccount(final String name) { + if (!this.hasAccount(name)) { + return null; + } + + return new VaultAccount(name, economy); + } + + public Method.MethodBankAccount getBankAccount(final String bank, final String name) { + if (!this.hasBankAccount(bank, name)) { + return null; + } + + return new VaultBankAccount(bank, this.economy); + } + + public boolean isCompatible(final Plugin plugin) { + return plugin instanceof Vault; + } + + public void setPlugin(final Plugin plugin) { + vault = (Vault) plugin; + final RegisteredServiceProvider economyProvider = vault.getServer().getServicesManager().getRegistration(Economy.class); + if (economyProvider != null) { + economy = economyProvider.getProvider(); + } + } + + public static class VaultAccount implements Method.MethodAccount { + private final String name; + private final Economy economy; + + public VaultAccount(final String name, final Economy economy) { + this.name = name; + this.economy = economy; + } + + public double balance() { + return economy.getBalance(name); + } + + public boolean set(final double amount) { + if (!economy.withdrawPlayer(name, balance()).transactionSuccess()) { + return false; + } + + if (amount == 0) { + return true; + } + return economy.depositPlayer(name, amount).transactionSuccess(); + } + + public boolean add(final double amount) { + return economy.depositPlayer(name, amount).transactionSuccess(); + } + + public boolean subtract(final double amount) { + return economy.withdrawPlayer(name, amount).transactionSuccess(); + } + + public boolean multiply(final double amount) { + final double balance = balance(); + return set(balance * amount); + } + + public boolean divide(final double amount) { + final double balance = balance(); + return set(balance / amount); + } + + public boolean hasEnough(final double amount) { + return (balance() >= amount); + } + + public boolean hasOver(final double amount) { + return (balance() > amount); + } + + public boolean hasUnder(final double amount) { + return (balance() < amount); + } + + public boolean isNegative() { + return (balance() < 0); + } + + public boolean remove() { + return set(0.0); + } + } + + public static class VaultBankAccount implements Method.MethodBankAccount { + + private final String bank; + private final Economy economy; + + public VaultBankAccount(final String bank, final Economy economy) { + this.bank = bank; + this.economy = economy; + } + + public String getBankName() { + return bank; + } + + public int getBankId() { + return -1; + } + + public double balance() { + return economy.bankBalance(bank).balance; + } + + public boolean set(final double amount) { + if (!economy.bankWithdraw(bank, balance()).transactionSuccess()) { + return false; + } + if (amount == 0) { + return true; + } + return economy.bankDeposit(bank, amount).transactionSuccess(); + } + + public boolean add(final double amount) { + return economy.bankDeposit(bank, amount).transactionSuccess(); + } + + public boolean subtract(final double amount) { + return economy.bankWithdraw(bank, amount).transactionSuccess(); + } + + public boolean multiply(final double amount) { + final double balance = balance(); + return set(balance * amount); + } + + public boolean divide(final double amount) { + final double balance = balance(); + return set(balance / amount); + } + + public boolean hasEnough(final double amount) { + return (balance() >= amount); + } + + public boolean hasOver(final double amount) { + return (balance() > amount); + } + + public boolean hasUnder(final double amount) { + return (balance() < amount); + } + + public boolean isNegative() { + return (balance() < 0); + } + + public boolean remove() { + return set(0.0); + } + + } } \ No newline at end of file diff --git a/src/net/milkbowl/vault/chat/plugins/Chat_DroxPerms.java b/src/net/milkbowl/vault/chat/plugins/Chat_DroxPerms.java index 6766f4d4..94827459 100644 --- a/src/net/milkbowl/vault/chat/plugins/Chat_DroxPerms.java +++ b/src/net/milkbowl/vault/chat/plugins/Chat_DroxPerms.java @@ -1,10 +1,9 @@ package net.milkbowl.vault.chat.plugins; -import java.util.logging.Logger; - +import de.hydrox.bukkit.DroxPerms.DroxPerms; +import de.hydrox.bukkit.DroxPerms.DroxPermsAPI; import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -12,228 +11,227 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import de.hydrox.bukkit.DroxPerms.DroxPerms; -import de.hydrox.bukkit.DroxPerms.DroxPermsAPI; +import java.util.logging.Logger; public class Chat_DroxPerms extends Chat { - - private final Logger log; - private final String name = "DroxPerms"; - private Plugin plugin; - private DroxPermsAPI API; - - public Chat_DroxPerms(Plugin plugin, Permission perms) { - super(perms); - this.plugin = plugin; - this.log = plugin.getLogger(); - - // Load Plugin in case it was loaded before - if (API == null) { - DroxPerms p = (DroxPerms) plugin.getServer().getPluginManager().getPlugin("DroxPerms"); - if (p != null) { - API = p.getAPI(); - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), name)); - } - } - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); - } - - public class PermissionServerListener implements Listener { - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (API == null) { - Plugin permPlugin = event.getPlugin(); - if (permPlugin.getDescription().getName().equals("DroxPerms")) { - API = ((DroxPerms) permPlugin).getAPI(); - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - } - - @Override - public String getName() { - return this.name; - } - - @Override - public boolean isEnabled() { - return true; - } - - @Override - public String getPlayerPrefix(String world, String player) { - String prefix = API.getPlayerInfo(player, "prefix"); - if (prefix == null) { - String prigroup = API.getPlayerGroup(player); - prefix = API.getGroupInfo(prigroup, "prefix"); - } - return prefix; - } - - @Override - public void setPlayerPrefix(String world, String player, String prefix) { - API.setPlayerInfo(player, "prefix", prefix); - } - - @Override - public String getPlayerSuffix(String world, String player) { - return API.getPlayerInfo(player, "suffix"); - } - - @Override - public void setPlayerSuffix(String world, String player, String suffix) { - API.setPlayerInfo(player, "suffix", suffix); - } - - @Override - public String getGroupPrefix(String world, String group) { - return API.getGroupInfo(group, "prefix"); - } - - @Override - public void setGroupPrefix(String world, String group, String prefix) { - API.setGroupInfo(group, "prefix", prefix); - } - - @Override - public String getGroupSuffix(String world, String group) { - return API.getGroupInfo(group, "suffix"); - } - - @Override - public void setGroupSuffix(String world, String group, String suffix) { - API.setGroupInfo(group, "suffix", suffix); - } - - @Override - public int getPlayerInfoInteger(String world, String player, String node, int defaultValue) { - String s = getPlayerInfoString(world, player, node, null); - if (s == null) { - return defaultValue; - } - - try { - return Integer.valueOf(s); - } catch (NumberFormatException e) { - return defaultValue; - } - } - - @Override - public void setPlayerInfoInteger(String world, String player, String node, int value) { - API.setPlayerInfo(player, node, String.valueOf(value)); - } - - @Override - public int getGroupInfoInteger(String world, String group, String node, int defaultValue) { - String s = getGroupInfoString(world, group, node, null); - if (s == null) { - return defaultValue; - } - - try { - return Integer.valueOf(s); - } catch (NumberFormatException e) { - return defaultValue; - } - } - - @Override - public void setGroupInfoInteger(String world, String group, String node, int value) { - API.setGroupInfo(group, node, String.valueOf(value)); - } - - @Override - public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) { - String s = getPlayerInfoString(world, player, node, null); - if (s == null) { - return defaultValue; - } - - try { - return Double.valueOf(s); - } catch (NumberFormatException e) { - return defaultValue; - } - } - - @Override - public void setPlayerInfoDouble(String world, String player, String node, double value) { - API.setPlayerInfo(player, node, String.valueOf(value)); - } - - @Override - public double getGroupInfoDouble(String world, String group, String node, double defaultValue) { - String s = getGroupInfoString(world, group, node, null); - if (s == null) { - return defaultValue; - } - - try { - return Double.valueOf(s); - } catch (NumberFormatException e) { - return defaultValue; - } - } - - @Override - public void setGroupInfoDouble(String world, String group, String node, double value) { - API.setGroupInfo(group, node, String.valueOf(value)); - } - - @Override - public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) { - String s = getPlayerInfoString(world, player, node, null); - if (s == null) { - return defaultValue; - } else { - Boolean val = Boolean.valueOf(s); - return val != null ? val : defaultValue; - } - } - - @Override - public void setPlayerInfoBoolean(String world, String player, String node, boolean value) { - API.setPlayerInfo(player, node, String.valueOf(value)); - } - - @Override - public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) { - String s = getGroupInfoString(world, group, node, null); - if (s == null) { - return defaultValue; - } else { - Boolean val = Boolean.valueOf(s); - return val != null ? val : defaultValue; - } - } - - @Override - public void setGroupInfoBoolean(String world, String group, String node, boolean value) { - API.setGroupInfo(group, node, String.valueOf(value)); - } - - @Override - public String getPlayerInfoString(String world, String player, String node, String defaultValue) { - String val = API.getPlayerInfo(player, node); - return val != null ? val : defaultValue; - } - - @Override - public void setPlayerInfoString(String world, String player, String node, String value) { - API.setPlayerInfo(player, node, value); - } - - @Override - public String getGroupInfoString(String world, String group, String node, String defaultValue) { - String val = API.getGroupInfo(group, node); - return val != null ? val : defaultValue; - } - - @Override - public void setGroupInfoString(String world, String group, String node, String value) { - API.setGroupInfo(group, node, value); - } - + + private final Logger log; + private final String name = "DroxPerms"; + private final Plugin plugin; + private DroxPermsAPI API; + + public Chat_DroxPerms(final Plugin plugin, final Permission perms) { + super(perms); + this.plugin = plugin; + log = plugin.getLogger(); + + // Load Plugin in case it was loaded before + if (this.API == null) { + final DroxPerms p = (DroxPerms) plugin.getServer().getPluginManager().getPlugin("DroxPerms"); + if (p != null) { + this.API = p.getAPI(); + this.log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), this.name)); + } + } + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); + } + + public class PermissionServerListener implements Listener { + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (Chat_DroxPerms.this.API == null) { + final Plugin permPlugin = event.getPlugin(); + if (permPlugin.getDescription().getName().equals("DroxPerms")) { + Chat_DroxPerms.this.API = ((DroxPerms) permPlugin).getAPI(); + Chat_DroxPerms.this.log.info(String.format("[%s][Chat] %s hooked.", Chat_DroxPerms.this.plugin.getDescription().getName(), Chat_DroxPerms.this.name)); + } + } + } + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public String getPlayerPrefix(final String world, final String player) { + String prefix = this.API.getPlayerInfo(player, "prefix"); + if (prefix == null) { + final String prigroup = this.API.getPlayerGroup(player); + prefix = this.API.getGroupInfo(prigroup, "prefix"); + } + return prefix; + } + + @Override + public void setPlayerPrefix(final String world, final String player, final String prefix) { + this.API.setPlayerInfo(player, "prefix", prefix); + } + + @Override + public String getPlayerSuffix(final String world, final String player) { + return this.API.getPlayerInfo(player, "suffix"); + } + + @Override + public void setPlayerSuffix(final String world, final String player, final String suffix) { + this.API.setPlayerInfo(player, "suffix", suffix); + } + + @Override + public String getGroupPrefix(final String world, final String group) { + return this.API.getGroupInfo(group, "prefix"); + } + + @Override + public void setGroupPrefix(final String world, final String group, final String prefix) { + this.API.setGroupInfo(group, "prefix", prefix); + } + + @Override + public String getGroupSuffix(final String world, final String group) { + return this.API.getGroupInfo(group, "suffix"); + } + + @Override + public void setGroupSuffix(final String world, final String group, final String suffix) { + this.API.setGroupInfo(group, "suffix", suffix); + } + + @Override + public int getPlayerInfoInteger(final String world, final String player, final String node, final int defaultValue) { + final String s = this.getPlayerInfoString(world, player, node, null); + if (s == null) { + return defaultValue; + } + + try { + return Integer.parseInt(s); + } catch (final NumberFormatException e) { + return defaultValue; + } + } + + @Override + public void setPlayerInfoInteger(final String world, final String player, final String node, final int value) { + this.API.setPlayerInfo(player, node, String.valueOf(value)); + } + + @Override + public int getGroupInfoInteger(final String world, final String group, final String node, final int defaultValue) { + final String s = this.getGroupInfoString(world, group, node, null); + if (s == null) { + return defaultValue; + } + + try { + return Integer.parseInt(s); + } catch (final NumberFormatException e) { + return defaultValue; + } + } + + @Override + public void setGroupInfoInteger(final String world, final String group, final String node, final int value) { + this.API.setGroupInfo(group, node, String.valueOf(value)); + } + + @Override + public double getPlayerInfoDouble(final String world, final String player, final String node, final double defaultValue) { + final String s = this.getPlayerInfoString(world, player, node, null); + if (s == null) { + return defaultValue; + } + + try { + return Double.parseDouble(s); + } catch (final NumberFormatException e) { + return defaultValue; + } + } + + @Override + public void setPlayerInfoDouble(final String world, final String player, final String node, final double value) { + this.API.setPlayerInfo(player, node, String.valueOf(value)); + } + + @Override + public double getGroupInfoDouble(final String world, final String group, final String node, final double defaultValue) { + final String s = this.getGroupInfoString(world, group, node, null); + if (s == null) { + return defaultValue; + } + + try { + return Double.parseDouble(s); + } catch (final NumberFormatException e) { + return defaultValue; + } + } + + @Override + public void setGroupInfoDouble(final String world, final String group, final String node, final double value) { + this.API.setGroupInfo(group, node, String.valueOf(value)); + } + + @Override + public boolean getPlayerInfoBoolean(final String world, final String player, final String node, final boolean defaultValue) { + final String s = this.getPlayerInfoString(world, player, node, null); + if (s == null) { + return defaultValue; + } else { + final Boolean val = Boolean.valueOf(s); + return val != null ? val : defaultValue; + } + } + + @Override + public void setPlayerInfoBoolean(final String world, final String player, final String node, final boolean value) { + this.API.setPlayerInfo(player, node, String.valueOf(value)); + } + + @Override + public boolean getGroupInfoBoolean(final String world, final String group, final String node, final boolean defaultValue) { + final String s = this.getGroupInfoString(world, group, node, null); + if (s == null) { + return defaultValue; + } else { + final Boolean val = Boolean.valueOf(s); + return val != null ? val : defaultValue; + } + } + + @Override + public void setGroupInfoBoolean(final String world, final String group, final String node, final boolean value) { + this.API.setGroupInfo(group, node, String.valueOf(value)); + } + + @Override + public String getPlayerInfoString(final String world, final String player, final String node, final String defaultValue) { + final String val = this.API.getPlayerInfo(player, node); + return val != null ? val : defaultValue; + } + + @Override + public void setPlayerInfoString(final String world, final String player, final String node, final String value) { + this.API.setPlayerInfo(player, node, value); + } + + @Override + public String getGroupInfoString(final String world, final String group, final String node, final String defaultValue) { + final String val = this.API.getGroupInfo(group, node); + return val != null ? val : defaultValue; + } + + @Override + public void setGroupInfoString(final String world, final String group, final String node, final String value) { + this.API.setGroupInfo(group, node, value); + } + } \ No newline at end of file diff --git a/src/net/milkbowl/vault/chat/plugins/Chat_GroupManager.java b/src/net/milkbowl/vault/chat/plugins/Chat_GroupManager.java index bb99bc33..d8f474e4 100644 --- a/src/net/milkbowl/vault/chat/plugins/Chat_GroupManager.java +++ b/src/net/milkbowl/vault/chat/plugins/Chat_GroupManager.java @@ -15,11 +15,8 @@ */ package net.milkbowl.vault.chat.plugins; -import java.util.logging.Logger; - import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.permission.Permission; - import org.anjocaido.groupmanager.GroupManager; import org.anjocaido.groupmanager.data.Group; import org.anjocaido.groupmanager.data.User; @@ -33,336 +30,338 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -public class Chat_GroupManager extends Chat { - - private final Logger log; - private final String name = "GroupManager - Chat"; - private Plugin plugin = null; - private GroupManager groupManager; - - public Chat_GroupManager(Plugin plugin, Permission perms) { - super(perms); - this.plugin = plugin; - this.log = plugin.getLogger(); - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); - - // Load Plugin in case it was loaded before - if (groupManager == null) { - Plugin chat = plugin.getServer().getPluginManager().getPlugin("GroupManager"); - if (chat != null) { - if (chat.isEnabled()) { - groupManager = (GroupManager) chat; - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - } - - public class PermissionServerListener implements Listener { - - Chat_GroupManager chat = null; - - public PermissionServerListener(Chat_GroupManager chat) { - this.chat = chat; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (chat.groupManager == null) { - Plugin perms = event.getPlugin(); - - if (perms.getDescription().getName().equals("GroupManager")) { - chat.groupManager = (GroupManager) perms; - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), chat.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (chat.groupManager != null) { - if (event.getPlugin().getDescription().getName().equals("GroupManager")) { - chat.groupManager = null; - log.info(String.format("[%s][Chat] %s un-hooked.", plugin.getDescription().getName(), chat.name)); - } - } - } - } - - @Override - public String getName() { - return this.name; - } - - @Override - public boolean isEnabled() { - if (groupManager == null) { - return false; - } else { - return groupManager.isEnabled(); - } - } - - @Override - public int getPlayerInfoInteger(String worldName, String playerName, String node, int defaultValue) { - AnjoPermissionsHandler handler; - if (worldName == null) { - handler = groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); - } else { - handler = groupManager.getWorldsHolder().getWorldPermissions(worldName); - } - if (handler == null) { - return defaultValue; - } - Integer val = handler.getUserPermissionInteger(playerName, node); - return val != null ? val : defaultValue; - } - - @Override - public void setPlayerInfoInteger(String worldName, String playerName, String node, int value) { - setPlayerValue(worldName, playerName, node, value); - } - - @Override - public int getGroupInfoInteger(String worldName, String groupName, String node, int defaultValue) { - AnjoPermissionsHandler handler; - if (worldName == null) { - handler = groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler(); - } else { - handler = groupManager.getWorldsHolder().getWorldPermissions(worldName); - } - if (handler == null) { - return defaultValue; - } - Integer val = handler.getGroupPermissionInteger(groupName, node); - return val != null ? val : defaultValue; - } - - @Override - public void setGroupInfoInteger(String worldName, String groupName, String node, int value) { - setGroupValue(worldName, groupName, node, value); - } - - @Override - public double getPlayerInfoDouble(String worldName, String playerName, String node, double defaultValue) { - AnjoPermissionsHandler handler; - if (worldName == null) { - handler = groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); - } else { - handler = groupManager.getWorldsHolder().getWorldPermissions(worldName); - } - if (handler == null) { - return defaultValue; - } - Double val = handler.getUserPermissionDouble(playerName, node); - return val != null ? val : defaultValue; - } - - @Override - public void setPlayerInfoDouble(String worldName, String playerName, String node, double value) { - setPlayerValue(worldName, playerName, node, value); - } - - @Override - public double getGroupInfoDouble(String worldName, String groupName, String node, double defaultValue) { - AnjoPermissionsHandler handler; - if (worldName == null) { - handler = groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler(); - } else { - handler = groupManager.getWorldsHolder().getWorldPermissions(worldName); - } - if (handler == null) { - return defaultValue; - } - Double val = handler.getGroupPermissionDouble(groupName, node); - return val != null ? val : defaultValue; - } - - @Override - public void setGroupInfoDouble(String worldName, String groupName, String node, double value) { - setGroupValue(worldName, groupName, node, value); - } - - @Override - public boolean getPlayerInfoBoolean(String worldName, String playerName, String node, boolean defaultValue) { - AnjoPermissionsHandler handler; - if (worldName == null) { - handler = groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); - } else { - handler = groupManager.getWorldsHolder().getWorldPermissions(worldName); - } - if (handler == null) { - return defaultValue; - } - Boolean val = handler.getUserPermissionBoolean(playerName, node); - return val != null ? val : defaultValue; - } - - @Override - public void setPlayerInfoBoolean(String worldName, String playerName, String node, boolean value) { - setPlayerValue(worldName, playerName, node, value); - } - - @Override - public boolean getGroupInfoBoolean(String worldName, String groupName, String node, boolean defaultValue) { - AnjoPermissionsHandler handler; - if (worldName == null) { - handler = groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler(); - } else { - handler = groupManager.getWorldsHolder().getWorldPermissions(worldName); - } - if (handler == null) { - return defaultValue; - } - Boolean val = handler.getGroupPermissionBoolean(groupName, node); - return val != null ? val : defaultValue; - } - - @Override - public void setGroupInfoBoolean(String worldName, String groupName, String node, boolean value) { - setGroupValue(worldName, groupName, node, value); - } - - @Override - public String getPlayerInfoString(String worldName, String playerName, String node, String defaultValue) { - AnjoPermissionsHandler handler; - if (worldName == null) { - handler = groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); - } else { - handler = groupManager.getWorldsHolder().getWorldPermissions(worldName); - } - if (handler == null) { - return defaultValue; - } - String val = handler.getUserPermissionString(playerName, node); - return val != null ? val : defaultValue; - } - - @Override - public void setPlayerInfoString(String worldName, String playerName, String node, String value) { - setPlayerValue(worldName, playerName, node, value); - } - - @Override - public String getGroupInfoString(String worldName, String groupName, String node, String defaultValue) { - AnjoPermissionsHandler handler; - if (worldName == null) { - handler = groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler(); - } else { - handler = groupManager.getWorldsHolder().getWorldPermissions(worldName); - } - if (handler == null) { - return defaultValue; - } - String val = handler.getGroupPermissionString(groupName, node); - return val != null ? val : defaultValue; - } - - @Override - public void setGroupInfoString(String worldName, String groupName, String node, String value) { - setGroupValue(worldName, groupName, node, value); - } - - @Override - public String getPlayerPrefix(String worldName, String playerName) { - AnjoPermissionsHandler handler; - if (worldName == null) { - handler = groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); - } else { - handler = groupManager.getWorldsHolder().getWorldPermissions(worldName); - } - if (handler == null) { - return ""; - } - return handler.getUserPrefix(playerName); - } - - @Override - public String getPlayerSuffix(String worldName, String playerName) { - AnjoPermissionsHandler handler; - if (worldName == null) { - handler = groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); - } else { - handler = groupManager.getWorldsHolder().getWorldPermissions(worldName); - } - if (handler == null) { - return ""; - } - return handler.getUserSuffix(playerName); - } - - @Override - public void setPlayerSuffix(String worldName, String player, String suffix) { - setPlayerInfoString(worldName, player, "suffix", suffix); - } - - @Override - public void setPlayerPrefix(String worldName, String player, String prefix) { - setPlayerInfoString(worldName, player, "prefix", prefix); - } - - @Override - public String getGroupPrefix(String worldName, String group) { - return getGroupInfoString(worldName, group, "prefix", ""); - } - - @Override - public void setGroupPrefix(String worldName, String group, String prefix) { - setGroupInfoString(worldName, group, "prefix", prefix); - } - - @Override - public String getGroupSuffix(String worldName, String group) { - return getGroupInfoString(worldName, group, "suffix", ""); - } - - @Override - public void setGroupSuffix(String worldName, String group, String suffix) { - setGroupInfoString(worldName, group, "suffix", suffix); - } - - @Override - public String getPrimaryGroup(String worldName, String playerName) { - AnjoPermissionsHandler handler; - if (worldName == null) { - handler = groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); - } else { - handler = groupManager.getWorldsHolder().getWorldPermissions(worldName); - } - return handler.getGroup(playerName); - } - - private void setPlayerValue(String worldName, String playerName, String node, Object value) { - OverloadedWorldHolder owh; - if (worldName == null) { - owh = groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName); - } else { - owh = groupManager.getWorldsHolder().getWorldData(worldName); - } - if (owh == null) { - return; - } - User user = owh.getUser(playerName); - if (user == null) { - return; - } - user.getVariables().addVar(node, value); - } +import java.util.logging.Logger; - private void setGroupValue(String worldName, String groupName, String node, Object value) { - OverloadedWorldHolder owh; - if (worldName == null) { - owh = groupManager.getWorldsHolder().getDefaultWorld(); - } else { - owh = groupManager.getWorldsHolder().getWorldData(worldName); - } - if (owh == null) { - return; - } - Group group = owh.getGroup(groupName); - if (group == null) { - return; - } - group.getVariables().addVar(node, value); - } +public class Chat_GroupManager extends Chat { + + private final Logger log; + private final String name = "GroupManager - Chat"; + private final Plugin plugin; + private GroupManager groupManager; + + public Chat_GroupManager(final Plugin plugin, final Permission perms) { + super(perms); + this.plugin = plugin; + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); + + // Load Plugin in case it was loaded before + if (this.groupManager == null) { + final Plugin chat = plugin.getServer().getPluginManager().getPlugin("GroupManager"); + if (chat != null) { + if (chat.isEnabled()) { + this.groupManager = (GroupManager) chat; + this.log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), this.name)); + } + } + } + } + + public class PermissionServerListener implements Listener { + + final Chat_GroupManager chat; + + public PermissionServerListener(final Chat_GroupManager chat) { + this.chat = chat; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.chat.groupManager == null) { + final Plugin perms = event.getPlugin(); + + if (perms.getDescription().getName().equals("GroupManager")) { + this.chat.groupManager = (GroupManager) perms; + Chat_GroupManager.this.log.info(String.format("[%s][Chat] %s hooked.", Chat_GroupManager.this.plugin.getDescription().getName(), this.chat.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.chat.groupManager != null) { + if (event.getPlugin().getDescription().getName().equals("GroupManager")) { + this.chat.groupManager = null; + Chat_GroupManager.this.log.info(String.format("[%s][Chat] %s un-hooked.", Chat_GroupManager.this.plugin.getDescription().getName(), this.chat.name)); + } + } + } + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean isEnabled() { + if (this.groupManager == null) { + return false; + } else { + return this.groupManager.isEnabled(); + } + } + + @Override + public int getPlayerInfoInteger(final String worldName, final String playerName, final String node, final int defaultValue) { + final AnjoPermissionsHandler handler; + if (worldName == null) { + handler = this.groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); + } else { + handler = this.groupManager.getWorldsHolder().getWorldPermissions(worldName); + } + if (handler == null) { + return defaultValue; + } + final Integer val = handler.getUserPermissionInteger(playerName, node); + return val != null ? val : defaultValue; + } + + @Override + public void setPlayerInfoInteger(final String worldName, final String playerName, final String node, final int value) { + this.setPlayerValue(worldName, playerName, node, value); + } + + @Override + public int getGroupInfoInteger(final String worldName, final String groupName, final String node, final int defaultValue) { + final AnjoPermissionsHandler handler; + if (worldName == null) { + handler = this.groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler(); + } else { + handler = this.groupManager.getWorldsHolder().getWorldPermissions(worldName); + } + if (handler == null) { + return defaultValue; + } + final Integer val = handler.getGroupPermissionInteger(groupName, node); + return val != null ? val : defaultValue; + } + + @Override + public void setGroupInfoInteger(final String worldName, final String groupName, final String node, final int value) { + this.setGroupValue(worldName, groupName, node, value); + } + + @Override + public double getPlayerInfoDouble(final String worldName, final String playerName, final String node, final double defaultValue) { + final AnjoPermissionsHandler handler; + if (worldName == null) { + handler = this.groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); + } else { + handler = this.groupManager.getWorldsHolder().getWorldPermissions(worldName); + } + if (handler == null) { + return defaultValue; + } + final Double val = handler.getUserPermissionDouble(playerName, node); + return val != null ? val : defaultValue; + } + + @Override + public void setPlayerInfoDouble(final String worldName, final String playerName, final String node, final double value) { + this.setPlayerValue(worldName, playerName, node, value); + } + + @Override + public double getGroupInfoDouble(final String worldName, final String groupName, final String node, final double defaultValue) { + final AnjoPermissionsHandler handler; + if (worldName == null) { + handler = this.groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler(); + } else { + handler = this.groupManager.getWorldsHolder().getWorldPermissions(worldName); + } + if (handler == null) { + return defaultValue; + } + final Double val = handler.getGroupPermissionDouble(groupName, node); + return val != null ? val : defaultValue; + } + + @Override + public void setGroupInfoDouble(final String worldName, final String groupName, final String node, final double value) { + this.setGroupValue(worldName, groupName, node, value); + } + + @Override + public boolean getPlayerInfoBoolean(final String worldName, final String playerName, final String node, final boolean defaultValue) { + final AnjoPermissionsHandler handler; + if (worldName == null) { + handler = this.groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); + } else { + handler = this.groupManager.getWorldsHolder().getWorldPermissions(worldName); + } + if (handler == null) { + return defaultValue; + } + final Boolean val = handler.getUserPermissionBoolean(playerName, node); + return val != null ? val : defaultValue; + } + + @Override + public void setPlayerInfoBoolean(final String worldName, final String playerName, final String node, final boolean value) { + this.setPlayerValue(worldName, playerName, node, value); + } + + @Override + public boolean getGroupInfoBoolean(final String worldName, final String groupName, final String node, final boolean defaultValue) { + final AnjoPermissionsHandler handler; + if (worldName == null) { + handler = this.groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler(); + } else { + handler = this.groupManager.getWorldsHolder().getWorldPermissions(worldName); + } + if (handler == null) { + return defaultValue; + } + final Boolean val = handler.getGroupPermissionBoolean(groupName, node); + return val != null ? val : defaultValue; + } + + @Override + public void setGroupInfoBoolean(final String worldName, final String groupName, final String node, final boolean value) { + this.setGroupValue(worldName, groupName, node, value); + } + + @Override + public String getPlayerInfoString(final String worldName, final String playerName, final String node, final String defaultValue) { + final AnjoPermissionsHandler handler; + if (worldName == null) { + handler = this.groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); + } else { + handler = this.groupManager.getWorldsHolder().getWorldPermissions(worldName); + } + if (handler == null) { + return defaultValue; + } + final String val = handler.getUserPermissionString(playerName, node); + return val != null ? val : defaultValue; + } + + @Override + public void setPlayerInfoString(final String worldName, final String playerName, final String node, final String value) { + this.setPlayerValue(worldName, playerName, node, value); + } + + @Override + public String getGroupInfoString(final String worldName, final String groupName, final String node, final String defaultValue) { + final AnjoPermissionsHandler handler; + if (worldName == null) { + handler = this.groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler(); + } else { + handler = this.groupManager.getWorldsHolder().getWorldPermissions(worldName); + } + if (handler == null) { + return defaultValue; + } + final String val = handler.getGroupPermissionString(groupName, node); + return val != null ? val : defaultValue; + } + + @Override + public void setGroupInfoString(final String worldName, final String groupName, final String node, final String value) { + this.setGroupValue(worldName, groupName, node, value); + } + + @Override + public String getPlayerPrefix(final String worldName, final String playerName) { + final AnjoPermissionsHandler handler; + if (worldName == null) { + handler = this.groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); + } else { + handler = this.groupManager.getWorldsHolder().getWorldPermissions(worldName); + } + if (handler == null) { + return ""; + } + return handler.getUserPrefix(playerName); + } + + @Override + public String getPlayerSuffix(final String worldName, final String playerName) { + final AnjoPermissionsHandler handler; + if (worldName == null) { + handler = this.groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); + } else { + handler = this.groupManager.getWorldsHolder().getWorldPermissions(worldName); + } + if (handler == null) { + return ""; + } + return handler.getUserSuffix(playerName); + } + + @Override + public void setPlayerSuffix(final String worldName, final String player, final String suffix) { + this.setPlayerInfoString(worldName, player, "suffix", suffix); + } + + @Override + public void setPlayerPrefix(final String worldName, final String player, final String prefix) { + this.setPlayerInfoString(worldName, player, "prefix", prefix); + } + + @Override + public String getGroupPrefix(final String worldName, final String group) { + return this.getGroupInfoString(worldName, group, "prefix", ""); + } + + @Override + public void setGroupPrefix(final String worldName, final String group, final String prefix) { + this.setGroupInfoString(worldName, group, "prefix", prefix); + } + + @Override + public String getGroupSuffix(final String worldName, final String group) { + return this.getGroupInfoString(worldName, group, "suffix", ""); + } + + @Override + public void setGroupSuffix(final String worldName, final String group, final String suffix) { + this.setGroupInfoString(worldName, group, "suffix", suffix); + } + + @Override + public String getPrimaryGroup(final String worldName, final String playerName) { + final AnjoPermissionsHandler handler; + if (worldName == null) { + handler = this.groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); + } else { + handler = this.groupManager.getWorldsHolder().getWorldPermissions(worldName); + } + return handler.getGroup(playerName); + } + + private void setPlayerValue(final String worldName, final String playerName, final String node, final Object value) { + final OverloadedWorldHolder owh; + if (worldName == null) { + owh = this.groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName); + } else { + owh = this.groupManager.getWorldsHolder().getWorldData(worldName); + } + if (owh == null) { + return; + } + final User user = owh.getUser(playerName); + if (user == null) { + return; + } + user.getVariables().addVar(node, value); + } + + private void setGroupValue(final String worldName, final String groupName, final String node, final Object value) { + final OverloadedWorldHolder owh; + if (worldName == null) { + owh = this.groupManager.getWorldsHolder().getDefaultWorld(); + } else { + owh = this.groupManager.getWorldsHolder().getWorldData(worldName); + } + if (owh == null) { + return; + } + final Group group = owh.getGroup(groupName); + if (group == null) { + return; + } + group.getVariables().addVar(node, value); + } } diff --git a/src/net/milkbowl/vault/chat/plugins/Chat_OverPermissions.java b/src/net/milkbowl/vault/chat/plugins/Chat_OverPermissions.java index b3e572aa..6f7596d0 100644 --- a/src/net/milkbowl/vault/chat/plugins/Chat_OverPermissions.java +++ b/src/net/milkbowl/vault/chat/plugins/Chat_OverPermissions.java @@ -12,9 +12,13 @@ */ package net.milkbowl.vault.chat.plugins; +import com.overmc.overpermissions.api.GroupManager; +import com.overmc.overpermissions.api.PermissionGroup; +import com.overmc.overpermissions.api.PermissionUser; +import com.overmc.overpermissions.api.UserManager; +import com.overmc.overpermissions.internal.OverPermissions; import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.permission.Permission; - import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -22,296 +26,286 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import com.overmc.overpermissions.api.GroupManager; -import com.overmc.overpermissions.api.PermissionGroup; -import com.overmc.overpermissions.api.PermissionUser; -import com.overmc.overpermissions.api.UserManager; -import com.overmc.overpermissions.internal.OverPermissions; - public class Chat_OverPermissions extends Chat { - protected final Plugin plugin; - private OverPermissions overPerms; - private UserManager userManager; - private GroupManager groupManager; - - public Chat_OverPermissions(Plugin plugin, Permission perms) { - super(perms); - this.plugin = plugin; - - plugin.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); - - if (overPerms == null) { - Plugin p = plugin.getServer().getPluginManager().getPlugin("OverPermissions"); - if (p != null) { - overPerms = (OverPermissions) p; - userManager = overPerms.getUserManager(); - groupManager = overPerms.getGroupManager(); - plugin.getLogger().info(String.format("[%s][Chat] %s hooked.", new Object[] {plugin.getDescription().getName(), "OverPermissions"})); - } - } - } - - @Override - public String getName( ) { - return "OverPermissions_Chat"; - } - - @Override - public boolean isEnabled( ) { - return overPerms != null; - } - - @Override - public String getPlayerPrefix(String world, String player) { - return getPlayerInfoString(world, player, "prefix", ""); - } - - @Override - public void setPlayerPrefix(String world, String player, String prefix) { - setPlayerInfoString(world, player, "prefix", prefix); - } - - @Override - public String getPlayerSuffix(String world, String player) { - return getPlayerInfoString(world, player, "suffix", ""); - } - - @Override - public void setPlayerSuffix(String world, String player, String suffix) { - setPlayerInfoString(world, player, "suffix", suffix); - } - - @Override - public String getGroupPrefix(String world, String group) { - return getGroupInfoString(world, group, "prefix", ""); - } - - @Override - public void setGroupPrefix(String world, String group, String prefix) { - setGroupInfoString(world, group, "prefix", prefix); - } - - @Override - public String getGroupSuffix(String world, String group) { - return getGroupInfoString(world, group, "suffix", ""); - } - - @Override - public void setGroupSuffix(String world, String group, String suffix) { - setGroupInfoString(world, group, "prefix", suffix); - } - - @Override - public int getPlayerInfoInteger(String world, String player, String node, int defaultValue) { - String s = getPlayerInfoString(world, player, node, null); - if (s == null) { - return defaultValue; - } - try - { - return Integer.valueOf(s).intValue(); - } catch (NumberFormatException e) { - } - return defaultValue; - } - - @Override - public void setPlayerInfoInteger(String world, String player, String node, int value) { - setPlayerInfoString(world, player, node, String.valueOf(value)); - } - - @Override - public int getGroupInfoInteger(String world, String group, String node, int defaultValue) { - String s = getGroupInfoString(world, group, node, null); - if (s == null) { - return defaultValue; - } - try - { - return Integer.valueOf(s).intValue(); - } catch (NumberFormatException e) { - } - return defaultValue; - } - - @Override - public void setGroupInfoInteger(String world, String group, String node, int value) { - setGroupInfoString(world, group, node, String.valueOf(value)); - } - - @Override - public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) { - String s = getPlayerInfoString(world, player, node, null); - if (s == null) { - return defaultValue; - } - try - { - return Double.valueOf(s).doubleValue(); - } catch (NumberFormatException e) { - } - return defaultValue; - } - - @Override - public void setPlayerInfoDouble(String world, String player, String node, double value) { - setPlayerInfoString(world, player, node, String.valueOf(value)); - } - - @Override - public double getGroupInfoDouble(String world, String group, String node, double defaultValue) { - String s = getGroupInfoString(world, group, node, null); - if (s == null) { - return defaultValue; - } - try - { - return Double.valueOf(s).doubleValue(); - } catch (NumberFormatException e) { - } - return defaultValue; - } - - @Override - public void setGroupInfoDouble(String world, String group, String node, double value) { - setGroupInfoString(world, group, node, String.valueOf(value)); - } - - @Override - public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) { - String s = getPlayerInfoString(world, player, node, null); - if (s == null) { - return defaultValue; - } - Boolean val = Boolean.valueOf(s); - return val != null ? val.booleanValue() : defaultValue; - } - - @Override - public void setPlayerInfoBoolean(String world, String player, String node, boolean value) { - setPlayerInfoString(world, player, node, String.valueOf(value)); - } - - @Override - public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) { - String s = getGroupInfoString(world, group, node, null); - if (s == null) { - return defaultValue; - } - Boolean val = Boolean.valueOf(s); - return val != null ? val.booleanValue() : defaultValue; - } - - @Override - public void setGroupInfoBoolean(String world, String group, String node, boolean value) { - setGroupInfoString(world, group, node, String.valueOf(value)); - } - - @Override - public String getPlayerInfoString(String world, String playerName, String node, String defaultValue) { - if (!userManager.doesUserExist(playerName)) { - return defaultValue; - } - PermissionUser user = userManager.getPermissionUser(playerName); - if (world == null) { // Retrieve meta from the global store. - if (!user.hasGlobalMeta(node)) { - return defaultValue; - } - return user.getGlobalMeta(node); - } else { - if (!user.hasMeta(node, world)) { - return defaultValue; - } - return user.getMeta(node, world); - } - } - - @Override - public void setPlayerInfoString(String world, String playerName, String node, String value) { - if (!userManager.canUserExist(playerName)) { - return; - } - PermissionUser user = userManager.getPermissionUser(playerName); - if (world != null) { - if (value == null) { - user.removeMeta(node, world); - } else { - user.setMeta(node, value, world); - } - } else { - if (value == null) { - user.removeGlobalMeta(node); - } else { - user.setGlobalMeta(node, value); - } - } - } - - @Override - public String getGroupInfoString(String world, String groupName, String node, String defaultValue) { - if (!groupManager.doesGroupExist(groupName)) { - return defaultValue; - } - PermissionGroup group = overPerms.getGroupManager().getGroup(groupName); - if (world == null) { // Retrieve from the global store. - if (!group.hasGlobalMeta(node)) { - return defaultValue; - } - return group.getGlobalMeta(node); - } else { - if (!group.hasMeta(node, world)) { - return defaultValue; - } - return group.getMeta(node, world); - } - } - - @Override - public void setGroupInfoString(String world, String groupName, String node, String value) { - if (!overPerms.getGroupManager().doesGroupExist(groupName)) { - return; - } - PermissionGroup group = overPerms.getGroupManager().getGroup(groupName); - if (world != null) { - if (value == null) { - group.removeMeta(node, world); - } else { - group.setMeta(node, value, world); - } - } else { - if (value == null) { - group.removeGlobalMeta(node); - } else { - group.setGlobalMeta(node, value); - } - } - } - - public class PermissionServerListener implements Listener { - Chat_OverPermissions chat = null; - - public PermissionServerListener(Chat_OverPermissions chat) { - this.chat = chat; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (chat.overPerms == null) { - Plugin chat = plugin.getServer().getPluginManager().getPlugin("OverPermissions"); - if (chat != null) { - this.chat.overPerms = (OverPermissions) chat; - plugin.getLogger().info(String.format("[%s][Chat] %s hooked.", new Object[] {plugin.getDescription().getName(), getName()})); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if ((chat.overPerms != null) && - (event.getPlugin().getDescription().getName().equals("OverPermissions"))) { - chat.overPerms = null; - plugin.getLogger().info(String.format("[%s][Chat] %s un-hooked.", new Object[] {plugin.getDescription().getName(), getName()})); - } - } - } + protected final Plugin plugin; + private OverPermissions overPerms; + private UserManager userManager; + private GroupManager groupManager; + + public Chat_OverPermissions(final Plugin plugin, final Permission perms) { + super(perms); + this.plugin = plugin; + + plugin.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); + + if (this.overPerms == null) { + final Plugin p = plugin.getServer().getPluginManager().getPlugin("OverPermissions"); + if (p != null) { + this.overPerms = (OverPermissions) p; + this.userManager = this.overPerms.getUserManager(); + this.groupManager = this.overPerms.getGroupManager(); + plugin.getLogger().info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "OverPermissions")); + } + } + } + + @Override + public String getName() { + return "OverPermissions_Chat"; + } + + @Override + public boolean isEnabled() { + return this.overPerms != null; + } + + @Override + public String getPlayerPrefix(final String world, final String player) { + return this.getPlayerInfoString(world, player, "prefix", ""); + } + + @Override + public void setPlayerPrefix(final String world, final String player, final String prefix) { + this.setPlayerInfoString(world, player, "prefix", prefix); + } + + @Override + public String getPlayerSuffix(final String world, final String player) { + return this.getPlayerInfoString(world, player, "suffix", ""); + } + + @Override + public void setPlayerSuffix(final String world, final String player, final String suffix) { + this.setPlayerInfoString(world, player, "suffix", suffix); + } + + @Override + public String getGroupPrefix(final String world, final String group) { + return this.getGroupInfoString(world, group, "prefix", ""); + } + + @Override + public void setGroupPrefix(final String world, final String group, final String prefix) { + this.setGroupInfoString(world, group, "prefix", prefix); + } + + @Override + public String getGroupSuffix(final String world, final String group) { + return this.getGroupInfoString(world, group, "suffix", ""); + } + + @Override + public void setGroupSuffix(final String world, final String group, final String suffix) { + this.setGroupInfoString(world, group, "prefix", suffix); + } + + @Override + public int getPlayerInfoInteger(final String world, final String player, final String node, final int defaultValue) { + final String s = this.getPlayerInfoString(world, player, node, null); + if (s == null) { + return defaultValue; + } + try { + return Integer.parseInt(s); + } catch (final NumberFormatException ignored) { + } + return defaultValue; + } + + @Override + public void setPlayerInfoInteger(final String world, final String player, final String node, final int value) { + this.setPlayerInfoString(world, player, node, String.valueOf(value)); + } + + @Override + public int getGroupInfoInteger(final String world, final String group, final String node, final int defaultValue) { + final String s = this.getGroupInfoString(world, group, node, null); + if (s == null) { + return defaultValue; + } + try { + return Integer.parseInt(s); + } catch (final NumberFormatException ignored) { + } + return defaultValue; + } + + @Override + public void setGroupInfoInteger(final String world, final String group, final String node, final int value) { + this.setGroupInfoString(world, group, node, String.valueOf(value)); + } + + @Override + public double getPlayerInfoDouble(final String world, final String player, final String node, final double defaultValue) { + final String s = this.getPlayerInfoString(world, player, node, null); + if (s == null) { + return defaultValue; + } + try { + return Double.parseDouble(s); + } catch (final NumberFormatException ignored) { + } + return defaultValue; + } + + @Override + public void setPlayerInfoDouble(final String world, final String player, final String node, final double value) { + this.setPlayerInfoString(world, player, node, String.valueOf(value)); + } + + @Override + public double getGroupInfoDouble(final String world, final String group, final String node, final double defaultValue) { + final String s = this.getGroupInfoString(world, group, node, null); + if (s == null) { + return defaultValue; + } + try { + return Double.parseDouble(s); + } catch (final NumberFormatException ignored) { + } + return defaultValue; + } + + @Override + public void setGroupInfoDouble(final String world, final String group, final String node, final double value) { + this.setGroupInfoString(world, group, node, String.valueOf(value)); + } + + @Override + public boolean getPlayerInfoBoolean(final String world, final String player, final String node, final boolean defaultValue) { + final String s = this.getPlayerInfoString(world, player, node, null); + if (s == null) { + return defaultValue; + } + final Boolean val = Boolean.valueOf(s); + return val != null ? val : defaultValue; + } + + @Override + public void setPlayerInfoBoolean(final String world, final String player, final String node, final boolean value) { + this.setPlayerInfoString(world, player, node, String.valueOf(value)); + } + + @Override + public boolean getGroupInfoBoolean(final String world, final String group, final String node, final boolean defaultValue) { + final String s = this.getGroupInfoString(world, group, node, null); + if (s == null) { + return defaultValue; + } + final Boolean val = Boolean.valueOf(s); + return val != null ? val : defaultValue; + } + + @Override + public void setGroupInfoBoolean(final String world, final String group, final String node, final boolean value) { + this.setGroupInfoString(world, group, node, String.valueOf(value)); + } + + @Override + public String getPlayerInfoString(final String world, final String playerName, final String node, final String defaultValue) { + if (!this.userManager.doesUserExist(playerName)) { + return defaultValue; + } + final PermissionUser user = this.userManager.getPermissionUser(playerName); + if (world == null) { // Retrieve meta from the global store. + if (!user.hasGlobalMeta(node)) { + return defaultValue; + } + return user.getGlobalMeta(node); + } else { + if (!user.hasMeta(node, world)) { + return defaultValue; + } + return user.getMeta(node, world); + } + } + + @Override + public void setPlayerInfoString(final String world, final String playerName, final String node, final String value) { + if (!this.userManager.canUserExist(playerName)) { + return; + } + final PermissionUser user = this.userManager.getPermissionUser(playerName); + if (world != null) { + if (value == null) { + user.removeMeta(node, world); + } else { + user.setMeta(node, value, world); + } + } else { + if (value == null) { + user.removeGlobalMeta(node); + } else { + user.setGlobalMeta(node, value); + } + } + } + + @Override + public String getGroupInfoString(final String world, final String groupName, final String node, final String defaultValue) { + if (!this.groupManager.doesGroupExist(groupName)) { + return defaultValue; + } + final PermissionGroup group = this.overPerms.getGroupManager().getGroup(groupName); + if (world == null) { // Retrieve from the global store. + if (!group.hasGlobalMeta(node)) { + return defaultValue; + } + return group.getGlobalMeta(node); + } else { + if (!group.hasMeta(node, world)) { + return defaultValue; + } + return group.getMeta(node, world); + } + } + + @Override + public void setGroupInfoString(final String world, final String groupName, final String node, final String value) { + if (!this.overPerms.getGroupManager().doesGroupExist(groupName)) { + return; + } + final PermissionGroup group = this.overPerms.getGroupManager().getGroup(groupName); + if (world != null) { + if (value == null) { + group.removeMeta(node, world); + } else { + group.setMeta(node, value, world); + } + } else { + if (value == null) { + group.removeGlobalMeta(node); + } else { + group.setGlobalMeta(node, value); + } + } + } + + public class PermissionServerListener implements Listener { + final Chat_OverPermissions chat; + + public PermissionServerListener(final Chat_OverPermissions chat) { + this.chat = chat; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.chat.overPerms == null) { + final Plugin chat = Chat_OverPermissions.this.plugin.getServer().getPluginManager().getPlugin("OverPermissions"); + if (chat != null) { + this.chat.overPerms = (OverPermissions) chat; + Chat_OverPermissions.this.plugin.getLogger().info(String.format("[%s][Chat] %s hooked.", Chat_OverPermissions.this.plugin.getDescription().getName(), Chat_OverPermissions.this.getName())); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if ((this.chat.overPerms != null) && + (event.getPlugin().getDescription().getName().equals("OverPermissions"))) { + this.chat.overPerms = null; + Chat_OverPermissions.this.plugin.getLogger().info(String.format("[%s][Chat] %s un-hooked.", Chat_OverPermissions.this.plugin.getDescription().getName(), Chat_OverPermissions.this.getName())); + } + } + } } \ No newline at end of file diff --git a/src/net/milkbowl/vault/chat/plugins/Chat_Permissions3.java b/src/net/milkbowl/vault/chat/plugins/Chat_Permissions3.java index 1f39946c..30f1f83b 100644 --- a/src/net/milkbowl/vault/chat/plugins/Chat_Permissions3.java +++ b/src/net/milkbowl/vault/chat/plugins/Chat_Permissions3.java @@ -15,11 +15,10 @@ */ package net.milkbowl.vault.chat.plugins; -import java.util.logging.Logger; - +import com.nijiko.permissions.PermissionHandler; +import com.nijikokun.bukkit.Permissions.Permissions; import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -28,214 +27,214 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import com.nijiko.permissions.PermissionHandler; -import com.nijikokun.bukkit.Permissions.Permissions; +import java.util.logging.Logger; public class Chat_Permissions3 extends Chat { - - private final Logger log; - private String name = "Permissions 3 (Yeti) - Chat"; - private PermissionHandler perms; - private Plugin plugin = null; - private Permissions chat = null; - - public Chat_Permissions3(Plugin plugin, Permission perms) { - super(perms); - this.plugin = plugin; - this.log = plugin.getLogger(); - - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); - - // Load Plugin in case it was loaded before - if (chat == null) { - Plugin p = plugin.getServer().getPluginManager().getPlugin("Permissions"); - if (p == null) { - plugin.getServer().getPluginManager().getPlugin("vPerms"); - name = "vPerms - Chat"; - } - if (p != null) { - if (p.isEnabled() && p.getDescription().getVersion().startsWith("3")) { - chat = (Permissions) p; - this.perms = chat.getHandler(); - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - } - - public class PermissionServerListener implements Listener { - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (chat == null) { - Plugin permChat = event.getPlugin(); - if((permChat.getDescription().getName().equals("Permissions") || permChat.getDescription().getName().equals("vPerms")) && permChat.getDescription().getVersion().startsWith("3")) { - if (permChat.isEnabled()) { - chat = (Permissions) permChat; - perms = chat.getHandler(); - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (chat != null) { - if (event.getPlugin().getDescription().getName().equals("Permissions") || event.getPlugin().getDescription().getName().equals("vPerms")) { - chat = null; - perms = null; - log.info(String.format("[%s][Chat] %s un-hooked.", plugin.getDescription().getName(), name)); - } - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean isEnabled() { - if (chat == null) { - return false; - } else { - return chat.isEnabled(); - } - } - @Override - public int getPlayerInfoInteger(String world, String playerName, String node, int defaultValue) { - Integer i = this.perms.getPermissionInteger(world, playerName, node); - return (i == null) ? defaultValue : i; - } - - @Override - public double getPlayerInfoDouble(String world, String playerName, String node, double defaultValue) { - Double d = this.perms.getPermissionDouble(world, playerName, node); - return (d == null) ? defaultValue : d; - } - - @Override - public boolean getPlayerInfoBoolean(String world, String playerName, String node, boolean defaultValue) { - Boolean b = this.perms.getPermissionBoolean(world, playerName, node); - return (b == null) ? defaultValue : b; - } - - @Override - public String getPlayerInfoString(String world, String playerName, String node, String defaultValue) { - String s = this.perms.getPermissionString(world, playerName, node); - return (s == null) ? defaultValue : s; - } - - @Override - public String getPlayerPrefix(String world, String playerName) { - return getPlayerInfoString(world, playerName, "prefix", null); - } - - @Override - public String getPlayerSuffix(String world, String playerName) { - return getPlayerInfoString(world, playerName, "suffix", null); - } - - @Override - public void setPlayerSuffix(String world, String player, String suffix) { - } - - @Override - public void setPlayerPrefix(String world, String player, String prefix) { - //this.perms.addUserInfo(world, player, "prefix", prefix); - } - - public void setPlayerInfo(String world, String playerName, String node, Object value) { - //this.perms.addUserInfo(world, playerName, node, value); - } - - @Override - public void setPlayerInfoInteger(String world, String playerName, String node, int value) { - setPlayerInfo(world, playerName, node, value); - } - - @Override - public void setPlayerInfoDouble(String world, String playerName, String node, double value) { - setPlayerInfo(world, playerName, node, value); - } - - @Override - public void setPlayerInfoBoolean(String world, String playerName, String node, boolean value) { - setPlayerInfo(world, playerName, node, value); - } - - @Override - public void setPlayerInfoString(String world, String playerName, String node, String value) { - setPlayerInfo(world, playerName, node, value); - } - - @Override - public int getGroupInfoInteger(String world, String groupName, String node, int defaultValue) { - int i = this.perms.getGroupPermissionInteger(world, groupName, node); - return i != -1 ? i : defaultValue; - } - - - public void setGroupInfo(String world, String groupName, String node, Object value) { - this.perms.addGroupInfo(world, groupName, node, value); - } - - @Override - public void setGroupInfoInteger(String world, String groupName, String node, int value) { - setGroupInfo(world, groupName, node, value); - } - - @Override - public double getGroupInfoDouble(String world, String groupName, String node, double defaultValue) { - double d = this.perms.getGroupPermissionDouble(world, groupName, node); - return d != -1.0d ? d : defaultValue; - } - - @Override - public void setGroupInfoDouble(String world, String groupName, String node, double value) { - setGroupInfo(world, groupName, node, value); - } - - @Override - public boolean getGroupInfoBoolean(String world, String groupName, String node, boolean defaultValue) { - return this.perms.getGroupPermissionBoolean(world, groupName, node); - } - - @Override - public void setGroupInfoBoolean(String world, String groupName, String node, boolean value) { - setGroupInfo(world, groupName, node, value); - } - - @Override - public String getGroupInfoString(String world, String groupName, String node, String defaultValue) { - String s = this.perms.getGroupPermissionString(world, groupName, node); - return s != null ? s : defaultValue; - } - - @Override - public void setGroupInfoString(String world, String groupName, String node, String value) { - setGroupInfo(world, groupName, node, value); - } - - @Override - public String getGroupPrefix(String world, String group) { - return this.perms.getGroupPrefix(world, group); - } - - @Override - public void setGroupPrefix(String world, String group, String prefix) { - this.perms.addGroupInfo(world, group, "prefix", prefix); - } - - @Override - public String getGroupSuffix(String world, String group) { - return this.perms.getGroupSuffix(world, group); - } - - @Override - public void setGroupSuffix(String world, String group, String suffix) { - this.perms.addGroupInfo(world, group, "suffix", suffix); - } + + private final Logger log; + private String name = "Permissions 3 (Yeti) - Chat"; + private PermissionHandler perms; + private final Plugin plugin; + private Permissions chat; + + public Chat_Permissions3(final Plugin plugin, final Permission perms) { + super(perms); + this.plugin = plugin; + log = plugin.getLogger(); + + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); + + // Load Plugin in case it was loaded before + if (this.chat == null) { + final Plugin p = plugin.getServer().getPluginManager().getPlugin("Permissions"); + if (p == null) { + plugin.getServer().getPluginManager().getPlugin("vPerms"); + this.name = "vPerms - Chat"; + } + if (p != null) { + if (p.isEnabled() && p.getDescription().getVersion().startsWith("3")) { + this.chat = (Permissions) p; + this.perms = this.chat.getHandler(); + this.log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), this.name)); + } + } + } + } + + public class PermissionServerListener implements Listener { + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (Chat_Permissions3.this.chat == null) { + final Plugin permChat = event.getPlugin(); + if ((permChat.getDescription().getName().equals("Permissions") || permChat.getDescription().getName().equals("vPerms")) && permChat.getDescription().getVersion().startsWith("3")) { + if (permChat.isEnabled()) { + Chat_Permissions3.this.chat = (Permissions) permChat; + Chat_Permissions3.this.perms = Chat_Permissions3.this.chat.getHandler(); + Chat_Permissions3.this.log.info(String.format("[%s][Chat] %s hooked.", Chat_Permissions3.this.plugin.getDescription().getName(), Chat_Permissions3.this.name)); + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (Chat_Permissions3.this.chat != null) { + if (event.getPlugin().getDescription().getName().equals("Permissions") || event.getPlugin().getDescription().getName().equals("vPerms")) { + Chat_Permissions3.this.chat = null; + Chat_Permissions3.this.perms = null; + Chat_Permissions3.this.log.info(String.format("[%s][Chat] %s un-hooked.", Chat_Permissions3.this.plugin.getDescription().getName(), Chat_Permissions3.this.name)); + } + } + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean isEnabled() { + if (this.chat == null) { + return false; + } else { + return this.chat.isEnabled(); + } + } + + @Override + public int getPlayerInfoInteger(final String world, final String playerName, final String node, final int defaultValue) { + final Integer i = perms.getPermissionInteger(world, playerName, node); + return (i == null) ? defaultValue : i; + } + + @Override + public double getPlayerInfoDouble(final String world, final String playerName, final String node, final double defaultValue) { + final Double d = perms.getPermissionDouble(world, playerName, node); + return (d == null) ? defaultValue : d; + } + + @Override + public boolean getPlayerInfoBoolean(final String world, final String playerName, final String node, final boolean defaultValue) { + final Boolean b = perms.getPermissionBoolean(world, playerName, node); + return (b == null) ? defaultValue : b; + } + + @Override + public String getPlayerInfoString(final String world, final String playerName, final String node, final String defaultValue) { + final String s = perms.getPermissionString(world, playerName, node); + return (s == null) ? defaultValue : s; + } + + @Override + public String getPlayerPrefix(final String world, final String playerName) { + return this.getPlayerInfoString(world, playerName, "prefix", null); + } + + @Override + public String getPlayerSuffix(final String world, final String playerName) { + return this.getPlayerInfoString(world, playerName, "suffix", null); + } + + @Override + public void setPlayerSuffix(final String world, final String player, final String suffix) { + } + + @Override + public void setPlayerPrefix(final String world, final String player, final String prefix) { + //this.perms.addUserInfo(world, player, "prefix", prefix); + } + + public void setPlayerInfo(final String world, final String playerName, final String node, final Object value) { + //this.perms.addUserInfo(world, playerName, node, value); + } + + @Override + public void setPlayerInfoInteger(final String world, final String playerName, final String node, final int value) { + this.setPlayerInfo(world, playerName, node, value); + } + + @Override + public void setPlayerInfoDouble(final String world, final String playerName, final String node, final double value) { + this.setPlayerInfo(world, playerName, node, value); + } + + @Override + public void setPlayerInfoBoolean(final String world, final String playerName, final String node, final boolean value) { + this.setPlayerInfo(world, playerName, node, value); + } + + @Override + public void setPlayerInfoString(final String world, final String playerName, final String node, final String value) { + this.setPlayerInfo(world, playerName, node, value); + } + + @Override + public int getGroupInfoInteger(final String world, final String groupName, final String node, final int defaultValue) { + final int i = perms.getGroupPermissionInteger(world, groupName, node); + return i != -1 ? i : defaultValue; + } + + + public void setGroupInfo(final String world, final String groupName, final String node, final Object value) { + perms.addGroupInfo(world, groupName, node, value); + } + + @Override + public void setGroupInfoInteger(final String world, final String groupName, final String node, final int value) { + this.setGroupInfo(world, groupName, node, value); + } + + @Override + public double getGroupInfoDouble(final String world, final String groupName, final String node, final double defaultValue) { + final double d = perms.getGroupPermissionDouble(world, groupName, node); + return d != -1.0d ? d : defaultValue; + } + + @Override + public void setGroupInfoDouble(final String world, final String groupName, final String node, final double value) { + this.setGroupInfo(world, groupName, node, value); + } + + @Override + public boolean getGroupInfoBoolean(final String world, final String groupName, final String node, final boolean defaultValue) { + return perms.getGroupPermissionBoolean(world, groupName, node); + } + + @Override + public void setGroupInfoBoolean(final String world, final String groupName, final String node, final boolean value) { + this.setGroupInfo(world, groupName, node, value); + } + + @Override + public String getGroupInfoString(final String world, final String groupName, final String node, final String defaultValue) { + final String s = perms.getGroupPermissionString(world, groupName, node); + return s != null ? s : defaultValue; + } + + @Override + public void setGroupInfoString(final String world, final String groupName, final String node, final String value) { + this.setGroupInfo(world, groupName, node, value); + } + + @Override + public String getGroupPrefix(final String world, final String group) { + return perms.getGroupPrefix(world, group); + } + + @Override + public void setGroupPrefix(final String world, final String group, final String prefix) { + perms.addGroupInfo(world, group, "prefix", prefix); + } + + @Override + public String getGroupSuffix(final String world, final String group) { + return perms.getGroupSuffix(world, group); + } + + @Override + public void setGroupSuffix(final String world, final String group, final String suffix) { + perms.addGroupInfo(world, group, "suffix", suffix); + } } diff --git a/src/net/milkbowl/vault/chat/plugins/Chat_PermissionsEx.java b/src/net/milkbowl/vault/chat/plugins/Chat_PermissionsEx.java index faac2fe1..f384fba1 100644 --- a/src/net/milkbowl/vault/chat/plugins/Chat_PermissionsEx.java +++ b/src/net/milkbowl/vault/chat/plugins/Chat_PermissionsEx.java @@ -15,11 +15,8 @@ */ package net.milkbowl.vault.chat.plugins; -import java.util.logging.Logger; - import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.event.EventHandler; @@ -28,368 +25,365 @@ import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; - import ru.tehkode.permissions.PermissionGroup; import ru.tehkode.permissions.PermissionUser; import ru.tehkode.permissions.bukkit.PermissionsEx; -public class Chat_PermissionsEx extends Chat { - private final Logger log; - private final String name = "PermissionsEx_Chat"; - - private Plugin plugin = null; - private PermissionsEx chat = null; - - public Chat_PermissionsEx(Plugin plugin, Permission perms) { - super(perms); - this.plugin = plugin; - this.log = plugin.getLogger(); - - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); - - // Load Plugin in case it was loaded before - if (chat == null) { - Plugin p = plugin.getServer().getPluginManager().getPlugin("PermissionsEx"); - if (p != null) { - if (p.isEnabled()) { - chat = (PermissionsEx) p; - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - } - - public class PermissionServerListener implements Listener { - Chat_PermissionsEx chat = null; - - public PermissionServerListener(Chat_PermissionsEx chat) { - this.chat = chat; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (chat.chat == null) { - Plugin perms = event.getPlugin(); - - if (perms.getDescription().getName().equals("PermissionsEx")) { - if (perms.isEnabled()) { - chat.chat = (PermissionsEx) perms; - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), chat.name)); - } - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (chat.chat != null) { - if (event.getPlugin().getDescription().getName().equals("PermissionsEx")) { - chat.chat = null; - log.info(String.format("[%s][Chat] %s un-hooked.", plugin.getDescription().getName(), chat.name)); - } - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean isEnabled() { - if (chat == null) - return false; - else - return chat.isEnabled(); - } - - private PermissionUser getUser(OfflinePlayer op) { - return PermissionsEx.getPermissionManager().getUser(op.getUniqueId()); - } - - private PermissionUser getUser(String playerName) { - return PermissionsEx.getPermissionManager().getUser(playerName); - } - - @Override - public int getPlayerInfoInteger(String world, String playerName, String node, int defaultValue) { - return getUser(playerName).getOptionInteger(node, world, defaultValue); - } - - @Override - public double getPlayerInfoDouble(String world, String playerName, String node, double defaultValue) { - return getUser(playerName).getOptionDouble(node, world, defaultValue); - } - - @Override - public boolean getPlayerInfoBoolean(String world, String playerName, String node, boolean defaultValue) { - return getUser(playerName).getOptionBoolean(node, world, defaultValue); - } - - @Override - public String getPlayerInfoString(String world, String playerName, String node, String defaultValue) { - return getUser(playerName).getOption(node, world, defaultValue); - } - - public int getPlayerInfoInteger(String world, OfflinePlayer op, String node, int defaultValue) { - return getUser(op).getOptionInteger(node, world, defaultValue); - } - - public double getPlayerInfoDouble(String world, OfflinePlayer op, String node, double defaultValue) { - return getUser(op).getOptionDouble(node, world, defaultValue); - } - - public boolean getPlayerInfoBoolean(String world, OfflinePlayer op, String node, boolean defaultValue) { - return getUser(op).getOptionBoolean(node, world, defaultValue); - } - - public String getPlayerInfoString(String world, OfflinePlayer op, String node, String defaultValue) { - return getUser(op).getOption(node, world, defaultValue); - } - - public void setPlayerInfoInteger(String world, OfflinePlayer op, String node, int value) { - PermissionUser user = getUser(op); - if (user != null) { - user.setOption(node, String.valueOf(value), world); - } - } - - public void setPlayerInfoDouble(String world, OfflinePlayer op, String node, double value) { - PermissionUser user = getUser(op); - if (user != null) { - user.setOption(node, String.valueOf(value), world); - } - } - - public void setPlayerInfoBoolean(String world, OfflinePlayer op, String node, boolean value) { - PermissionUser user = getUser(op); - if (user != null) { - user.setOption(node, String.valueOf(value), world); - } - } - - public void setPlayerInfoString(String world, OfflinePlayer op, String node, String value) { - PermissionUser user = getUser(op); - if (user != null) { - user.setOption(node, String.valueOf(value), world); - } - } - - @Override - public void setPlayerInfoInteger(String world, String playerName, String node, int value) { - PermissionUser user = getUser(playerName); - if (user != null) { - user.setOption(node, String.valueOf(value), world); - } - } - - @Override - public void setPlayerInfoDouble(String world, String playerName, String node, double value) { - PermissionUser user = getUser(playerName); - if (user != null) { - user.setOption(node, String.valueOf(value), world); - } - } - - @Override - public void setPlayerInfoBoolean(String world, String playerName, String node, boolean value) { - PermissionUser user = getUser(playerName); - if (user != null) { - user.setOption(node, String.valueOf(value), world); - } - } - - @Override - public void setPlayerInfoString(String world, String playerName, String node, String value) { - PermissionUser user = getUser(playerName); - if (user != null) { - user.setOption(node, String.valueOf(value), world); - } - } - - @Override - public int getGroupInfoInteger(String world, String groupName, String node, int defaultValue) { - PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); - if (group == null) { - return defaultValue; - } else { - return group.getOptionInteger(node, world, defaultValue); - } - } - - @Override - public void setGroupInfoInteger(String world, String groupName, String node, int value) { - PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); - if (group == null) { - return; - } else { - group.setOption(node, world, String.valueOf(value)); - } - } - - @Override - public double getGroupInfoDouble(String world, String groupName, String node, double defaultValue) { - PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); - if (group == null) { - return defaultValue; - } else { - return group.getOptionDouble(node, world, defaultValue); - } - } - - @Override - public void setGroupInfoDouble(String world, String groupName, String node, double value) { - PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); - if (group == null) { - return; - } else { - group.setOption(node, world, String.valueOf(value)); - } - } - - @Override - public boolean getGroupInfoBoolean(String world, String groupName, String node, boolean defaultValue) { - PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); - if (group == null) { - return defaultValue; - } else { - return group.getOptionBoolean(node, world, defaultValue); - } - } - - @Override - public void setGroupInfoBoolean(String world, String groupName, String node, boolean value) { - PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); - if (group == null) { - return; - } else { - group.setOption(node, world, String.valueOf(value)); - } - } - - @Override - public String getGroupInfoString(String world, String groupName, String node, String defaultValue) { - PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); - if (group == null) { - return defaultValue; - } else { - return group.getOption(node, world, defaultValue); - } - } - - @Override - public void setGroupInfoString(String world, String groupName, String node, String value) { - PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); - if (group == null) { - return; - } else { - group.setOption(node, world, value); - } - } - - public String getPlayerPrefix(String world, OfflinePlayer op) { - PermissionUser user = getUser(op); - if (user != null) { - return user.getPrefix(world); - } else { - return null; - } - } - - public String getPlayerSuffix(String world, OfflinePlayer op) { - PermissionUser user = getUser(op); - if (user != null) { - return user.getSuffix(world); - } else { - return null; - } - } - - public void setPlayerSuffix(String world, OfflinePlayer player, String suffix) { - PermissionUser user = getUser(player); - if (user != null) { - user.setSuffix(suffix, world); - } - } - - public void setPlayerPrefix(String world, OfflinePlayer player, String prefix) { - PermissionUser user = getUser(player); - if (user != null) { - user.setPrefix(prefix, world); - } - } - - @Override - public String getPlayerPrefix(String world, String playerName) { - PermissionUser user = getUser(playerName); - if (user != null) { - return user.getPrefix(world); - } else { - return null; - } - } - - @Override - public String getPlayerSuffix(String world, String playerName) { - PermissionUser user = getUser(playerName); - if (user != null) { - return user.getSuffix(world); - } else { - return null; - } - } - - @Override - public void setPlayerSuffix(String world, String player, String suffix) { - PermissionUser user = getUser(player); - if (user != null) { - user.setSuffix(suffix, world); - } - } - - @Override - public void setPlayerPrefix(String world, String player, String prefix) { - PermissionUser user = getUser(player); - if (user != null) { - user.setPrefix(prefix, world); - } - } - - @Override - public String getGroupPrefix(String world, String group) { - PermissionGroup pGroup = PermissionsEx.getPermissionManager().getGroup(group); - if (group != null) { - return pGroup.getPrefix(world); - } else { - return null; - } - } - - @Override - public void setGroupPrefix(String world, String group, String prefix) { - PermissionGroup pGroup = PermissionsEx.getPermissionManager().getGroup(group); - if (group != null) { - pGroup.setPrefix(prefix, world); - } - - } - - @Override - public String getGroupSuffix(String world, String group) { - PermissionGroup pGroup = PermissionsEx.getPermissionManager().getGroup(group); - if (group != null) { - return pGroup.getSuffix(world); - } else { - return null; - } - } +import java.util.logging.Logger; - @Override - public void setGroupSuffix(String world, String group, String suffix) { - PermissionGroup pGroup = PermissionsEx.getPermissionManager().getGroup(group); - if (group != null) { - pGroup.setSuffix(suffix, world); - } - } +public class Chat_PermissionsEx extends Chat { + private final Logger log; + private final String name = "PermissionsEx_Chat"; + + private final Plugin plugin; + private PermissionsEx chat; + + public Chat_PermissionsEx(final Plugin plugin, final Permission perms) { + super(perms); + this.plugin = plugin; + log = plugin.getLogger(); + + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); + + // Load Plugin in case it was loaded before + if (this.chat == null) { + final Plugin p = plugin.getServer().getPluginManager().getPlugin("PermissionsEx"); + if (p != null) { + if (p.isEnabled()) { + this.chat = (PermissionsEx) p; + this.log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), this.name)); + } + } + } + } + + public class PermissionServerListener implements Listener { + final Chat_PermissionsEx chat; + + public PermissionServerListener(final Chat_PermissionsEx chat) { + this.chat = chat; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.chat.chat == null) { + final Plugin perms = event.getPlugin(); + + if (perms.getDescription().getName().equals("PermissionsEx")) { + if (perms.isEnabled()) { + this.chat.chat = (PermissionsEx) perms; + Chat_PermissionsEx.this.log.info(String.format("[%s][Chat] %s hooked.", Chat_PermissionsEx.this.plugin.getDescription().getName(), this.chat.name)); + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.chat.chat != null) { + if (event.getPlugin().getDescription().getName().equals("PermissionsEx")) { + this.chat.chat = null; + Chat_PermissionsEx.this.log.info(String.format("[%s][Chat] %s un-hooked.", Chat_PermissionsEx.this.plugin.getDescription().getName(), this.chat.name)); + } + } + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean isEnabled() { + if (this.chat == null) + return false; + else + return this.chat.isEnabled(); + } + + private PermissionUser getUser(final OfflinePlayer op) { + return PermissionsEx.getPermissionManager().getUser(op.getUniqueId()); + } + + private PermissionUser getUser(final String playerName) { + return PermissionsEx.getPermissionManager().getUser(playerName); + } + + @Override + public int getPlayerInfoInteger(final String world, final String playerName, final String node, final int defaultValue) { + return this.getUser(playerName).getOptionInteger(node, world, defaultValue); + } + + @Override + public double getPlayerInfoDouble(final String world, final String playerName, final String node, final double defaultValue) { + return this.getUser(playerName).getOptionDouble(node, world, defaultValue); + } + + @Override + public boolean getPlayerInfoBoolean(final String world, final String playerName, final String node, final boolean defaultValue) { + return this.getUser(playerName).getOptionBoolean(node, world, defaultValue); + } + + @Override + public String getPlayerInfoString(final String world, final String playerName, final String node, final String defaultValue) { + return this.getUser(playerName).getOption(node, world, defaultValue); + } + + public int getPlayerInfoInteger(final String world, final OfflinePlayer op, final String node, final int defaultValue) { + return this.getUser(op).getOptionInteger(node, world, defaultValue); + } + + public double getPlayerInfoDouble(final String world, final OfflinePlayer op, final String node, final double defaultValue) { + return this.getUser(op).getOptionDouble(node, world, defaultValue); + } + + public boolean getPlayerInfoBoolean(final String world, final OfflinePlayer op, final String node, final boolean defaultValue) { + return this.getUser(op).getOptionBoolean(node, world, defaultValue); + } + + public String getPlayerInfoString(final String world, final OfflinePlayer op, final String node, final String defaultValue) { + return this.getUser(op).getOption(node, world, defaultValue); + } + + public void setPlayerInfoInteger(final String world, final OfflinePlayer op, final String node, final int value) { + final PermissionUser user = this.getUser(op); + if (user != null) { + user.setOption(node, String.valueOf(value), world); + } + } + + public void setPlayerInfoDouble(final String world, final OfflinePlayer op, final String node, final double value) { + final PermissionUser user = this.getUser(op); + if (user != null) { + user.setOption(node, String.valueOf(value), world); + } + } + + public void setPlayerInfoBoolean(final String world, final OfflinePlayer op, final String node, final boolean value) { + final PermissionUser user = this.getUser(op); + if (user != null) { + user.setOption(node, String.valueOf(value), world); + } + } + + public void setPlayerInfoString(final String world, final OfflinePlayer op, final String node, final String value) { + final PermissionUser user = this.getUser(op); + if (user != null) { + user.setOption(node, String.valueOf(value), world); + } + } + + @Override + public void setPlayerInfoInteger(final String world, final String playerName, final String node, final int value) { + final PermissionUser user = this.getUser(playerName); + if (user != null) { + user.setOption(node, String.valueOf(value), world); + } + } + + @Override + public void setPlayerInfoDouble(final String world, final String playerName, final String node, final double value) { + final PermissionUser user = this.getUser(playerName); + if (user != null) { + user.setOption(node, String.valueOf(value), world); + } + } + + @Override + public void setPlayerInfoBoolean(final String world, final String playerName, final String node, final boolean value) { + final PermissionUser user = this.getUser(playerName); + if (user != null) { + user.setOption(node, String.valueOf(value), world); + } + } + + @Override + public void setPlayerInfoString(final String world, final String playerName, final String node, final String value) { + final PermissionUser user = this.getUser(playerName); + if (user != null) { + user.setOption(node, String.valueOf(value), world); + } + } + + @Override + public int getGroupInfoInteger(final String world, final String groupName, final String node, final int defaultValue) { + final PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); + if (group == null) { + return defaultValue; + } else { + return group.getOptionInteger(node, world, defaultValue); + } + } + + @Override + public void setGroupInfoInteger(final String world, final String groupName, final String node, final int value) { + final PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); + if (group == null) { + } else { + group.setOption(node, world, String.valueOf(value)); + } + } + + @Override + public double getGroupInfoDouble(final String world, final String groupName, final String node, final double defaultValue) { + final PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); + if (group == null) { + return defaultValue; + } else { + return group.getOptionDouble(node, world, defaultValue); + } + } + + @Override + public void setGroupInfoDouble(final String world, final String groupName, final String node, final double value) { + final PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); + if (group == null) { + } else { + group.setOption(node, world, String.valueOf(value)); + } + } + + @Override + public boolean getGroupInfoBoolean(final String world, final String groupName, final String node, final boolean defaultValue) { + final PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); + if (group == null) { + return defaultValue; + } else { + return group.getOptionBoolean(node, world, defaultValue); + } + } + + @Override + public void setGroupInfoBoolean(final String world, final String groupName, final String node, final boolean value) { + final PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); + if (group == null) { + } else { + group.setOption(node, world, String.valueOf(value)); + } + } + + @Override + public String getGroupInfoString(final String world, final String groupName, final String node, final String defaultValue) { + final PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); + if (group == null) { + return defaultValue; + } else { + return group.getOption(node, world, defaultValue); + } + } + + @Override + public void setGroupInfoString(final String world, final String groupName, final String node, final String value) { + final PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); + if (group == null) { + } else { + group.setOption(node, world, value); + } + } + + public String getPlayerPrefix(final String world, final OfflinePlayer op) { + final PermissionUser user = this.getUser(op); + if (user != null) { + return user.getPrefix(world); + } else { + return null; + } + } + + public String getPlayerSuffix(final String world, final OfflinePlayer op) { + final PermissionUser user = this.getUser(op); + if (user != null) { + return user.getSuffix(world); + } else { + return null; + } + } + + public void setPlayerSuffix(final String world, final OfflinePlayer player, final String suffix) { + final PermissionUser user = this.getUser(player); + if (user != null) { + user.setSuffix(suffix, world); + } + } + + public void setPlayerPrefix(final String world, final OfflinePlayer player, final String prefix) { + final PermissionUser user = this.getUser(player); + if (user != null) { + user.setPrefix(prefix, world); + } + } + + @Override + public String getPlayerPrefix(final String world, final String playerName) { + final PermissionUser user = this.getUser(playerName); + if (user != null) { + return user.getPrefix(world); + } else { + return null; + } + } + + @Override + public String getPlayerSuffix(final String world, final String playerName) { + final PermissionUser user = this.getUser(playerName); + if (user != null) { + return user.getSuffix(world); + } else { + return null; + } + } + + @Override + public void setPlayerSuffix(final String world, final String player, final String suffix) { + final PermissionUser user = this.getUser(player); + if (user != null) { + user.setSuffix(suffix, world); + } + } + + @Override + public void setPlayerPrefix(final String world, final String player, final String prefix) { + final PermissionUser user = this.getUser(player); + if (user != null) { + user.setPrefix(prefix, world); + } + } + + @Override + public String getGroupPrefix(final String world, final String group) { + final PermissionGroup pGroup = PermissionsEx.getPermissionManager().getGroup(group); + if (group != null) { + return pGroup.getPrefix(world); + } else { + return null; + } + } + + @Override + public void setGroupPrefix(final String world, final String group, final String prefix) { + final PermissionGroup pGroup = PermissionsEx.getPermissionManager().getGroup(group); + if (group != null) { + pGroup.setPrefix(prefix, world); + } + + } + + @Override + public String getGroupSuffix(final String world, final String group) { + final PermissionGroup pGroup = PermissionsEx.getPermissionManager().getGroup(group); + if (group != null) { + return pGroup.getSuffix(world); + } else { + return null; + } + } + + @Override + public void setGroupSuffix(final String world, final String group, final String suffix) { + final PermissionGroup pGroup = PermissionsEx.getPermissionManager().getGroup(group); + if (group != null) { + pGroup.setSuffix(suffix, world); + } + } } diff --git a/src/net/milkbowl/vault/chat/plugins/Chat_Privileges.java b/src/net/milkbowl/vault/chat/plugins/Chat_Privileges.java index 7e2bbf74..8facaebe 100644 --- a/src/net/milkbowl/vault/chat/plugins/Chat_Privileges.java +++ b/src/net/milkbowl/vault/chat/plugins/Chat_Privileges.java @@ -27,205 +27,205 @@ import org.bukkit.plugin.Plugin; public class Chat_Privileges extends Chat { - private static final String FRIENDLY_NAME = "Privileges - Chat"; - private static final String PLUGIN_NAME = "Privileges"; - private static final String CHAT_PREFIX_KEY = "prefix"; - private static final String CHAT_SUFFIX_KEY = "suffix"; - - private Privileges privs; - private final Plugin plugin; - - public Chat_Privileges(Plugin plugin, Permission perms) { - super(perms); - this.plugin = plugin; - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); - // Load service in case it was loaded before - if (privs == null) { - Plugin privsPlugin = plugin.getServer().getPluginManager().getPlugin(PLUGIN_NAME); - if (privsPlugin != null && privsPlugin.isEnabled()) { - this.privs = (Privileges) privsPlugin; - plugin.getLogger().info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), FRIENDLY_NAME)); - } - } - } - - @Override - public String getName() { - return FRIENDLY_NAME; - } - - @Override - public boolean isEnabled() { - return privs != null && privs.isEnabled(); - } - - private String getPlayerOrGroupInfoString(String world, String player, String key, String defaultValue) { - String value = getPlayerInfoString(world, player, key, null); - if (value != null) return value; - - value = getGroupInfoString(world, getPrimaryGroup(world, player), key, null); - if (value != null) return value; - - return defaultValue; - } - - private void worldCheck(String world) { - if (world != null && !world.isEmpty()) { - throw new UnsupportedOperationException("Privileges does not support multiple worlds for player/group metadata."); - } - } - - @Override - public String getPlayerPrefix(String world, String player) { - return getPlayerOrGroupInfoString(world, player, CHAT_PREFIX_KEY, null); - } - - @Override - public void setPlayerPrefix(String world, String player, String prefix) { - setPlayerInfoString(world, player, CHAT_PREFIX_KEY, prefix); - } - - @Override - public String getPlayerSuffix(String world, String player) { - return getPlayerOrGroupInfoString(world, player, CHAT_SUFFIX_KEY, null); - } - - @Override - public void setPlayerSuffix(String world, String player, String suffix) { - setPlayerInfoString(world, player, CHAT_SUFFIX_KEY, suffix); - } - - @Override - public String getGroupPrefix(String world, String group) { - return getGroupInfoString(world, group, CHAT_PREFIX_KEY, null); - } - - @Override - public void setGroupPrefix(String world, String group, String prefix) { - setGroupInfoString(world, group, CHAT_PREFIX_KEY, prefix); - } - - @Override - public String getGroupSuffix(String world, String group) { - return getGroupInfoString(world, group, CHAT_SUFFIX_KEY, null); - } - - @Override - public void setGroupSuffix(String world, String group, String suffix) { - setGroupInfoString(world, group, CHAT_SUFFIX_KEY, suffix); - } - - @Override - public int getPlayerInfoInteger(String world, String player, String node, int defaultValue) { - return privs.getUserNode(player).getInt(node, defaultValue); - } - - @Override - public void setPlayerInfoInteger(String world, String player, String node, int value) { - worldCheck(world); - privs.getUserNode(player).set(node, value); - } - - @Override - public int getGroupInfoInteger(String world, String group, String node, int defaultValue) { - return privs.getGroupNode(group).getInt(node, defaultValue); - } - - @Override - public void setGroupInfoInteger(String world, String group, String node, int value) { - worldCheck(world); - privs.getGroupNode(group).set(node, value); - } - - @Override - public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) { - return privs.getUserNode(player).getDouble(node, defaultValue); - } - - @Override - public void setPlayerInfoDouble(String world, String player, String node, double value) { - worldCheck(world); - privs.getUserNode(player).set(node, value); - } - - @Override - public double getGroupInfoDouble(String world, String group, String node, double defaultValue) { - return privs.getGroupNode(group).getDouble(node, defaultValue); - } - - @Override - public void setGroupInfoDouble(String world, String group, String node, double value) { - worldCheck(world); - privs.getGroupNode(group).set(node, value); - } - - @Override - public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) { - return privs.getUserNode(player).getBoolean(node, defaultValue); - } - - @Override - public void setPlayerInfoBoolean(String world, String player, String node, boolean value) { - worldCheck(world); - privs.getUserNode(player).set(node, value); - } - - @Override - public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) { - return privs.getGroupNode(group).getBoolean(node, defaultValue); - } - - @Override - public void setGroupInfoBoolean(String world, String group, String node, boolean value) { - worldCheck(world); - privs.getGroupNode(group).set(node, value); - } - - @Override - public String getPlayerInfoString(String world, String player, String node, String defaultValue) { - return privs.getUserNode(player).getString(node, defaultValue); - } - - @Override - public void setPlayerInfoString(String world, String player, String node, String value) { - worldCheck(world); - privs.getUserNode(player).set(node, value); - } - - @Override - public String getGroupInfoString(String world, String group, String node, String defaultValue) { - return privs.getGroupNode(group).getString(node, defaultValue); - } - - @Override - public void setGroupInfoString(String world, String group, String node, String value) { - worldCheck(world); - privs.getGroupNode(group).set(node, value); - } - - public class PermissionServerListener implements Listener { - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (privs == null) { - Plugin permChat = event.getPlugin(); - if (PLUGIN_NAME.equals(permChat.getDescription().getName())) { - if (permChat.isEnabled()) { - privs = (Privileges) permChat; - plugin.getLogger().info(String.format("[Chat] %s hooked.", FRIENDLY_NAME)); - } - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (privs != null) { - if (PLUGIN_NAME.equals(event.getPlugin().getDescription().getName())) { - privs = null; - plugin.getLogger().info(String.format("[Chat] %s un-hooked.", FRIENDLY_NAME)); - } - } - } - } + private static final String FRIENDLY_NAME = "Privileges - Chat"; + private static final String PLUGIN_NAME = "Privileges"; + private static final String CHAT_PREFIX_KEY = "prefix"; + private static final String CHAT_SUFFIX_KEY = "suffix"; + + private Privileges privs; + private final Plugin plugin; + + public Chat_Privileges(final Plugin plugin, final Permission perms) { + super(perms); + this.plugin = plugin; + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); + // Load service in case it was loaded before + if (this.privs == null) { + final Plugin privsPlugin = plugin.getServer().getPluginManager().getPlugin(Chat_Privileges.PLUGIN_NAME); + if (privsPlugin != null && privsPlugin.isEnabled()) { + privs = (Privileges) privsPlugin; + plugin.getLogger().info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), Chat_Privileges.FRIENDLY_NAME)); + } + } + } + + @Override + public String getName() { + return Chat_Privileges.FRIENDLY_NAME; + } + + @Override + public boolean isEnabled() { + return this.privs != null && this.privs.isEnabled(); + } + + private String getPlayerOrGroupInfoString(final String world, final String player, final String key) { + String value = this.getPlayerInfoString(world, player, key, null); + if (value != null) return value; + + value = this.getGroupInfoString(world, this.getPrimaryGroup(world, player), key, null); + if (value != null) return value; + + return null; + } + + private void worldCheck(final String world) { + if (world != null && !world.isEmpty()) { + throw new UnsupportedOperationException("Privileges does not support multiple worlds for player/group metadata."); + } + } + + @Override + public String getPlayerPrefix(final String world, final String player) { + return this.getPlayerOrGroupInfoString(world, player, Chat_Privileges.CHAT_PREFIX_KEY); + } + + @Override + public void setPlayerPrefix(final String world, final String player, final String prefix) { + this.setPlayerInfoString(world, player, Chat_Privileges.CHAT_PREFIX_KEY, prefix); + } + + @Override + public String getPlayerSuffix(final String world, final String player) { + return this.getPlayerOrGroupInfoString(world, player, Chat_Privileges.CHAT_SUFFIX_KEY); + } + + @Override + public void setPlayerSuffix(final String world, final String player, final String suffix) { + this.setPlayerInfoString(world, player, Chat_Privileges.CHAT_SUFFIX_KEY, suffix); + } + + @Override + public String getGroupPrefix(final String world, final String group) { + return this.getGroupInfoString(world, group, Chat_Privileges.CHAT_PREFIX_KEY, null); + } + + @Override + public void setGroupPrefix(final String world, final String group, final String prefix) { + this.setGroupInfoString(world, group, Chat_Privileges.CHAT_PREFIX_KEY, prefix); + } + + @Override + public String getGroupSuffix(final String world, final String group) { + return this.getGroupInfoString(world, group, Chat_Privileges.CHAT_SUFFIX_KEY, null); + } + + @Override + public void setGroupSuffix(final String world, final String group, final String suffix) { + this.setGroupInfoString(world, group, Chat_Privileges.CHAT_SUFFIX_KEY, suffix); + } + + @Override + public int getPlayerInfoInteger(final String world, final String player, final String node, final int defaultValue) { + return this.privs.getUserNode(player).getInt(node, defaultValue); + } + + @Override + public void setPlayerInfoInteger(final String world, final String player, final String node, final int value) { + this.worldCheck(world); + this.privs.getUserNode(player).set(node, value); + } + + @Override + public int getGroupInfoInteger(final String world, final String group, final String node, final int defaultValue) { + return this.privs.getGroupNode(group).getInt(node, defaultValue); + } + + @Override + public void setGroupInfoInteger(final String world, final String group, final String node, final int value) { + this.worldCheck(world); + this.privs.getGroupNode(group).set(node, value); + } + + @Override + public double getPlayerInfoDouble(final String world, final String player, final String node, final double defaultValue) { + return this.privs.getUserNode(player).getDouble(node, defaultValue); + } + + @Override + public void setPlayerInfoDouble(final String world, final String player, final String node, final double value) { + this.worldCheck(world); + this.privs.getUserNode(player).set(node, value); + } + + @Override + public double getGroupInfoDouble(final String world, final String group, final String node, final double defaultValue) { + return this.privs.getGroupNode(group).getDouble(node, defaultValue); + } + + @Override + public void setGroupInfoDouble(final String world, final String group, final String node, final double value) { + this.worldCheck(world); + this.privs.getGroupNode(group).set(node, value); + } + + @Override + public boolean getPlayerInfoBoolean(final String world, final String player, final String node, final boolean defaultValue) { + return this.privs.getUserNode(player).getBoolean(node, defaultValue); + } + + @Override + public void setPlayerInfoBoolean(final String world, final String player, final String node, final boolean value) { + this.worldCheck(world); + this.privs.getUserNode(player).set(node, value); + } + + @Override + public boolean getGroupInfoBoolean(final String world, final String group, final String node, final boolean defaultValue) { + return this.privs.getGroupNode(group).getBoolean(node, defaultValue); + } + + @Override + public void setGroupInfoBoolean(final String world, final String group, final String node, final boolean value) { + this.worldCheck(world); + this.privs.getGroupNode(group).set(node, value); + } + + @Override + public String getPlayerInfoString(final String world, final String player, final String node, final String defaultValue) { + return this.privs.getUserNode(player).getString(node, defaultValue); + } + + @Override + public void setPlayerInfoString(final String world, final String player, final String node, final String value) { + this.worldCheck(world); + this.privs.getUserNode(player).set(node, value); + } + + @Override + public String getGroupInfoString(final String world, final String group, final String node, final String defaultValue) { + return this.privs.getGroupNode(group).getString(node, defaultValue); + } + + @Override + public void setGroupInfoString(final String world, final String group, final String node, final String value) { + this.worldCheck(world); + this.privs.getGroupNode(group).set(node, value); + } + + public class PermissionServerListener implements Listener { + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (Chat_Privileges.this.privs == null) { + final Plugin permChat = event.getPlugin(); + if (Chat_Privileges.PLUGIN_NAME.equals(permChat.getDescription().getName())) { + if (permChat.isEnabled()) { + Chat_Privileges.this.privs = (Privileges) permChat; + Chat_Privileges.this.plugin.getLogger().info(String.format("[Chat] %s hooked.", Chat_Privileges.FRIENDLY_NAME)); + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (Chat_Privileges.this.privs != null) { + if (Chat_Privileges.PLUGIN_NAME.equals(event.getPlugin().getDescription().getName())) { + Chat_Privileges.this.privs = null; + Chat_Privileges.this.plugin.getLogger().info(String.format("[Chat] %s un-hooked.", Chat_Privileges.FRIENDLY_NAME)); + } + } + } + } } diff --git a/src/net/milkbowl/vault/chat/plugins/Chat_TotalPermissions.java b/src/net/milkbowl/vault/chat/plugins/Chat_TotalPermissions.java index 72feddd5..07bd057a 100644 --- a/src/net/milkbowl/vault/chat/plugins/Chat_TotalPermissions.java +++ b/src/net/milkbowl/vault/chat/plugins/Chat_TotalPermissions.java @@ -31,257 +31,255 @@ import org.bukkit.plugin.Plugin; /** - * @version 1.0 * @author Lord_Ralex + * @version 1.0 */ public class Chat_TotalPermissions extends Chat { - - private final Plugin plugin; - private TotalPermissions totalPermissions; - private final String name = "TotalPermissions-Chat"; - - public Chat_TotalPermissions(Plugin plugin, Permission perms) { - super(perms); - this.plugin = plugin; - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); - - if (totalPermissions == null) { - Plugin chat = plugin.getServer().getPluginManager().getPlugin("TotalPermissions"); - if (chat != null) { - if (chat.isEnabled()) { - totalPermissions = (TotalPermissions) chat; - plugin.getLogger().info(String.format("[Chat] %s hooked.", name)); - } - } - } - } - - public class PermissionServerListener implements Listener { - - Chat_TotalPermissions chat = null; - - public PermissionServerListener(Chat_TotalPermissions chat) { - this.chat = chat; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (chat.totalPermissions == null) { - Plugin perms = event.getPlugin(); - - if (perms != null) { - if (perms.getDescription().getName().equals("TotalPermissions")) { - if (perms.isEnabled()) { - chat.totalPermissions = (TotalPermissions) perms; - plugin.getLogger().info(String.format("[Chat] %s hooked.", chat.getName())); - } - } - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (chat.totalPermissions != null) { - if (event.getPlugin().getDescription().getName().equals("TotalPermissions")) { - chat.totalPermissions = null; - plugin.getLogger().info(String.format("[Chat] %s un-hooked.", chat.name)); - } - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean isEnabled() { - return (totalPermissions == null ? false : totalPermissions.isEnabled()); - } - - @Override - public String getPlayerPrefix(String world, String player) { - return this.getPlayerInfoString(world, player, "prefix", null); - } - - @Override - public void setPlayerPrefix(String world, String player, String prefix) { - this.setPlayerInfoString(world, player, "prefix", prefix); - } - - @Override - public String getPlayerSuffix(String world, String player) { - return this.getPlayerInfoString(world, player, "suffix", null); - } - - @Override - public void setPlayerSuffix(String world, String player, String suffix) { - this.setPlayerInfoString(world, player, "suffix", suffix); - } - - @Override - public String getGroupPrefix(String world, String group) { - return this.getGroupInfoString(world, group, "prefix", null); - } - - @Override - public void setGroupPrefix(String world, String group, String prefix) { - this.setGroupInfoString(world, group, "prefix", prefix); - } - - @Override - public String getGroupSuffix(String world, String group) { - return this.getGroupInfoString(world, group, "suffix", null); - } - - @Override - public void setGroupSuffix(String world, String group, String suffix) { - this.setGroupInfoString(world, group, "suffix", suffix); - } - - @Override - public int getPlayerInfoInteger(String world, String player, String node, int defaultValue) { - Object pre = getPlayerInfo(world, player, node); - if (pre instanceof Integer) { - return (Integer) pre; - } - return defaultValue; - } - - @Override - public void setPlayerInfoInteger(String world, String player, String node, int value) { - setPlayerInfo(world, player, node, value); - } - - @Override - public int getGroupInfoInteger(String world, String group, String node, int defaultValue) { - Object pre = getGroupInfo(world, group, node); - if (pre instanceof Integer) { - return (Integer) pre; - } - return defaultValue; - } - - @Override - public void setGroupInfoInteger(String world, String group, String node, int value) { - setGroupInfo(world, group, node, value); - } - - @Override - public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) { - Object pre = getPlayerInfo(world, player, node); - if (pre instanceof Double) { - return (Double) pre; - } - return defaultValue; - } - - @Override - public void setPlayerInfoDouble(String world, String player, String node, double value) { - setPlayerInfo(world, player, node, value); - } - - @Override - public double getGroupInfoDouble(String world, String group, String node, double defaultValue) { - Object pre = getGroupInfo(world, group, node); - if (pre instanceof Double) { - return (Double) pre; - } - return defaultValue; - } - - @Override - public void setGroupInfoDouble(String world, String group, String node, double value) { - setGroupInfo(world, group, node, value); - } - - @Override - public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) { - Object pre = getPlayerInfo(world, player, node); - if (pre instanceof Boolean) { - return (Boolean) pre; - } - return defaultValue; - } - - @Override - public void setPlayerInfoBoolean(String world, String player, String node, boolean value) { - setPlayerInfo(world, player, node, value); - } - - @Override - public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) { - Object pre = getGroupInfo(world, group, node); - if (pre instanceof Boolean) { - return (Boolean) pre; - } - return defaultValue; - } - - @Override - public void setGroupInfoBoolean(String world, String group, String node, boolean value) { - setGroupInfo(world, group, node, value); - } - - @Override - public String getPlayerInfoString(String world, String player, String node, String defaultValue) { - Object pre = getPlayerInfo(world, player, node); - if (pre instanceof String) { - return (String) pre; - } - return defaultValue; - } - - @Override - public void setPlayerInfoString(String world, String player, String node, String value) { - setPlayerInfo(world, player, node, value); - } - - @Override - public String getGroupInfoString(String world, String group, String node, String defaultValue) { - Object pre = getGroupInfo(world, group, node); - if (pre instanceof String) { - return (String) pre; - } - return defaultValue; - } - - @Override - public void setGroupInfoString(String world, String group, String node, String value) { - setGroupInfo(world, group, node, value); - } - - private PermissionUser getUser(String name) { - PermissionManager manager = totalPermissions.getManager(); - PermissionUser user = manager.getUser(name); - return user; - } - - private PermissionGroup getGroup(String name) { - PermissionManager manager = totalPermissions.getManager(); - PermissionGroup group = manager.getGroup(name); - return group; - } - - private void setPlayerInfo(String world, String player, String node, Object value) { - PermissionBase base = getUser(player); - base.setOption(node, value, world); - } - - private void setGroupInfo(String world, String group, String node, Object value) { - PermissionBase base = getGroup(group); - base.setOption(node, value, world); - } - - private Object getPlayerInfo(String world, String player, String node) { - PermissionBase base = getUser(player); - return base.getOption(node); - } - - private Object getGroupInfo(String world, String group, String node) { - PermissionBase base = getUser(group); - return base.getOption(node); - } + + private final Plugin plugin; + private TotalPermissions totalPermissions; + private final String name = "TotalPermissions-Chat"; + + public Chat_TotalPermissions(final Plugin plugin, final Permission perms) { + super(perms); + this.plugin = plugin; + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); + + if (this.totalPermissions == null) { + final Plugin chat = plugin.getServer().getPluginManager().getPlugin("TotalPermissions"); + if (chat != null) { + if (chat.isEnabled()) { + this.totalPermissions = (TotalPermissions) chat; + plugin.getLogger().info(String.format("[Chat] %s hooked.", this.name)); + } + } + } + } + + public class PermissionServerListener implements Listener { + + final Chat_TotalPermissions chat; + + public PermissionServerListener(final Chat_TotalPermissions chat) { + this.chat = chat; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.chat.totalPermissions == null) { + final Plugin perms = event.getPlugin(); + + if (perms != null) { + if (perms.getDescription().getName().equals("TotalPermissions")) { + if (perms.isEnabled()) { + this.chat.totalPermissions = (TotalPermissions) perms; + Chat_TotalPermissions.this.plugin.getLogger().info(String.format("[Chat] %s hooked.", this.chat.getName())); + } + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.chat.totalPermissions != null) { + if (event.getPlugin().getDescription().getName().equals("TotalPermissions")) { + this.chat.totalPermissions = null; + Chat_TotalPermissions.this.plugin.getLogger().info(String.format("[Chat] %s un-hooked.", this.chat.name)); + } + } + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean isEnabled() { + return (this.totalPermissions != null && this.totalPermissions.isEnabled()); + } + + @Override + public String getPlayerPrefix(final String world, final String player) { + return getPlayerInfoString(world, player, "prefix", null); + } + + @Override + public void setPlayerPrefix(final String world, final String player, final String prefix) { + setPlayerInfoString(world, player, "prefix", prefix); + } + + @Override + public String getPlayerSuffix(final String world, final String player) { + return getPlayerInfoString(world, player, "suffix", null); + } + + @Override + public void setPlayerSuffix(final String world, final String player, final String suffix) { + setPlayerInfoString(world, player, "suffix", suffix); + } + + @Override + public String getGroupPrefix(final String world, final String group) { + return getGroupInfoString(world, group, "prefix", null); + } + + @Override + public void setGroupPrefix(final String world, final String group, final String prefix) { + setGroupInfoString(world, group, "prefix", prefix); + } + + @Override + public String getGroupSuffix(final String world, final String group) { + return getGroupInfoString(world, group, "suffix", null); + } + + @Override + public void setGroupSuffix(final String world, final String group, final String suffix) { + setGroupInfoString(world, group, "suffix", suffix); + } + + @Override + public int getPlayerInfoInteger(final String world, final String player, final String node, final int defaultValue) { + final Object pre = this.getPlayerInfo(world, player, node); + if (pre instanceof Integer) { + return (Integer) pre; + } + return defaultValue; + } + + @Override + public void setPlayerInfoInteger(final String world, final String player, final String node, final int value) { + this.setPlayerInfo(world, player, node, value); + } + + @Override + public int getGroupInfoInteger(final String world, final String group, final String node, final int defaultValue) { + final Object pre = this.getGroupInfo(world, group, node); + if (pre instanceof Integer) { + return (Integer) pre; + } + return defaultValue; + } + + @Override + public void setGroupInfoInteger(final String world, final String group, final String node, final int value) { + this.setGroupInfo(world, group, node, value); + } + + @Override + public double getPlayerInfoDouble(final String world, final String player, final String node, final double defaultValue) { + final Object pre = this.getPlayerInfo(world, player, node); + if (pre instanceof Double) { + return (Double) pre; + } + return defaultValue; + } + + @Override + public void setPlayerInfoDouble(final String world, final String player, final String node, final double value) { + this.setPlayerInfo(world, player, node, value); + } + + @Override + public double getGroupInfoDouble(final String world, final String group, final String node, final double defaultValue) { + final Object pre = this.getGroupInfo(world, group, node); + if (pre instanceof Double) { + return (Double) pre; + } + return defaultValue; + } + + @Override + public void setGroupInfoDouble(final String world, final String group, final String node, final double value) { + this.setGroupInfo(world, group, node, value); + } + + @Override + public boolean getPlayerInfoBoolean(final String world, final String player, final String node, final boolean defaultValue) { + final Object pre = this.getPlayerInfo(world, player, node); + if (pre instanceof Boolean) { + return (Boolean) pre; + } + return defaultValue; + } + + @Override + public void setPlayerInfoBoolean(final String world, final String player, final String node, final boolean value) { + this.setPlayerInfo(world, player, node, value); + } + + @Override + public boolean getGroupInfoBoolean(final String world, final String group, final String node, final boolean defaultValue) { + final Object pre = this.getGroupInfo(world, group, node); + if (pre instanceof Boolean) { + return (Boolean) pre; + } + return defaultValue; + } + + @Override + public void setGroupInfoBoolean(final String world, final String group, final String node, final boolean value) { + this.setGroupInfo(world, group, node, value); + } + + @Override + public String getPlayerInfoString(final String world, final String player, final String node, final String defaultValue) { + final Object pre = this.getPlayerInfo(world, player, node); + if (pre instanceof String) { + return (String) pre; + } + return defaultValue; + } + + @Override + public void setPlayerInfoString(final String world, final String player, final String node, final String value) { + this.setPlayerInfo(world, player, node, value); + } + + @Override + public String getGroupInfoString(final String world, final String group, final String node, final String defaultValue) { + final Object pre = this.getGroupInfo(world, group, node); + if (pre instanceof String) { + return (String) pre; + } + return defaultValue; + } + + @Override + public void setGroupInfoString(final String world, final String group, final String node, final String value) { + this.setGroupInfo(world, group, node, value); + } + + private PermissionUser getUser(final String name) { + final PermissionManager manager = this.totalPermissions.getManager(); + return manager.getUser(name); + } + + private PermissionGroup getGroup(final String name) { + final PermissionManager manager = this.totalPermissions.getManager(); + return manager.getGroup(name); + } + + private void setPlayerInfo(final String world, final String player, final String node, final Object value) { + final PermissionBase base = this.getUser(player); + base.setOption(node, value, world); + } + + private void setGroupInfo(final String world, final String group, final String node, final Object value) { + final PermissionBase base = this.getGroup(group); + base.setOption(node, value, world); + } + + private Object getPlayerInfo(final String world, final String player, final String node) { + final PermissionBase base = this.getUser(player); + return base.getOption(node); + } + + private Object getGroupInfo(final String world, final String group, final String node) { + final PermissionBase base = this.getUser(group); + return base.getOption(node); + } } diff --git a/src/net/milkbowl/vault/chat/plugins/Chat_bPermissions.java b/src/net/milkbowl/vault/chat/plugins/Chat_bPermissions.java index 9ea5b9a6..bded7bb8 100644 --- a/src/net/milkbowl/vault/chat/plugins/Chat_bPermissions.java +++ b/src/net/milkbowl/vault/chat/plugins/Chat_bPermissions.java @@ -15,11 +15,10 @@ */ package net.milkbowl.vault.chat.plugins; -import java.util.logging.Logger; - +import de.bananaco.permissions.Permissions; +import de.bananaco.permissions.info.InfoReader; import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -28,237 +27,232 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import de.bananaco.permissions.Permissions; -import de.bananaco.permissions.info.InfoReader; +import java.util.logging.Logger; public class Chat_bPermissions extends Chat { - private final String name = "bInfo"; private final Logger log; - private Plugin plugin = null; + private final Plugin plugin; InfoReader chat; - - public Chat_bPermissions(Plugin plugin, Permission perms) { + + public Chat_bPermissions(final Plugin plugin, final Permission perms) { super(perms); this.plugin = plugin; - this.log = plugin.getLogger(); + log = plugin.getLogger(); Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); - + // Load Plugin in case it was loaded before - if (chat == null) { - Plugin p = plugin.getServer().getPluginManager().getPlugin("bPermissions"); + if (this.chat == null) { + final Plugin p = plugin.getServer().getPluginManager().getPlugin("bPermissions"); if (p != null) { - chat = Permissions.getInfoReader(); - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "bPermissions")); + this.chat = Permissions.getInfoReader(); + this.log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "bPermissions")); } } } - + public class PermissionServerListener implements Listener { - Chat_bPermissions chat = null; - - public PermissionServerListener(Chat_bPermissions chat) { + final Chat_bPermissions chat; + + public PermissionServerListener(final Chat_bPermissions chat) { this.chat = chat; } - + @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (this.chat.chat == null) { - Plugin chat = event.getPlugin(); + public void onPluginEnable(final PluginEnableEvent event) { + if (chat.chat == null) { + final Plugin chat = event.getPlugin(); if (chat.getDescription().getName().equals("bPermissions")) { - this.chat.chat = Permissions.getInfoReader(); - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "bPermissions")); + this.chat.chat = Permissions.getInfoReader(); + Chat_bPermissions.this.log.info(String.format("[%s][Chat] %s hooked.", Chat_bPermissions.this.plugin.getDescription().getName(), "bPermissions")); } } } - + @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (this.chat.chat != null) { + public void onPluginDisable(final PluginDisableEvent event) { + if (chat.chat != null) { if (event.getPlugin().getDescription().getName().equals("bPermissions")) { - this.chat.chat = null; - log.info(String.format("[%s][Chat] %s un-hooked.", plugin.getDescription().getName(), "bPermissions")); + chat.chat = null; + Chat_bPermissions.this.log.info(String.format("[%s][Chat] %s un-hooked.", Chat_bPermissions.this.plugin.getDescription().getName(), "bPermissions")); } } } } + @Override public String getName() { - return name; + return "bInfo"; } - + @Override public boolean isEnabled() { - return chat != null; + return this.chat != null; } - + @Override - public String getPlayerPrefix(String world, String player) { - return chat.getPrefix(player, world); + public String getPlayerPrefix(final String world, final String player) { + return this.chat.getPrefix(player, world); } - + @Override - public void setPlayerPrefix(String world, String player, String prefix) { + public void setPlayerPrefix(final String world, final String player, final String prefix) { throw new UnsupportedOperationException("bPermissions does not support altering info nodes"); } - + @Override - public String getPlayerSuffix(String world, String player) { - return chat.getSuffix(player, world); + public String getPlayerSuffix(final String world, final String player) { + return this.chat.getSuffix(player, world); } - + @Override - public void setPlayerSuffix(String world, String player, String suffix) { + public void setPlayerSuffix(final String world, final String player, final String suffix) { throw new UnsupportedOperationException("bPermissions does not support altering info nodes"); } - + @Override - public String getGroupPrefix(String world, String group) { - return chat.getGroupPrefix(group, world); + public String getGroupPrefix(final String world, final String group) { + return this.chat.getGroupPrefix(group, world); } - + @Override - public void setGroupPrefix(String world, String group, String prefix) { + public void setGroupPrefix(final String world, final String group, final String prefix) { throw new UnsupportedOperationException("bPermissions does not support altering info nodes"); } - + @Override - public String getGroupSuffix(String world, String group) { - return chat.getGroupSuffix(group, world); + public String getGroupSuffix(final String world, final String group) { + return this.chat.getGroupSuffix(group, world); } - + @Override - public void setGroupSuffix(String world, String group, String suffix) { + public void setGroupSuffix(final String world, final String group, final String suffix) { throw new UnsupportedOperationException("bPermissions does not support altering info nodes"); } - + @Override - public int getPlayerInfoInteger(String world, String player, String node, int defaultValue) { - String s = getPlayerInfoString(world, player, node, null); + public int getPlayerInfoInteger(final String world, final String player, final String node, final int defaultValue) { + final String s = this.getPlayerInfoString(world, player, node, null); if (s == null) { return defaultValue; } try { - int i = Integer.valueOf(s); - return i; - } catch (NumberFormatException e) { + return Integer.parseInt(s); + } catch (final NumberFormatException e) { return defaultValue; } } - + @Override - public void setPlayerInfoInteger(String world, String player, String node, int value) { + public void setPlayerInfoInteger(final String world, final String player, final String node, final int value) { throw new UnsupportedOperationException("bPermissions does not support altering info nodes"); } - + @Override - public int getGroupInfoInteger(String world, String group, String node, int defaultValue) { - String s = getGroupInfoString(world, group, node, null); + public int getGroupInfoInteger(final String world, final String group, final String node, final int defaultValue) { + final String s = this.getGroupInfoString(world, group, node, null); if (s == null) { return defaultValue; } try { - int i = Integer.valueOf(s); - return i; - } catch (NumberFormatException e) { + return Integer.parseInt(s); + } catch (final NumberFormatException e) { return defaultValue; } } - + @Override - public void setGroupInfoInteger(String world, String group, String node, int value) { + public void setGroupInfoInteger(final String world, final String group, final String node, final int value) { throw new UnsupportedOperationException("bPermissions does not support altering info nodes"); } - + @Override - public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) { - String s = getPlayerInfoString(world, player, node, null); + public double getPlayerInfoDouble(final String world, final String player, final String node, final double defaultValue) { + final String s = this.getPlayerInfoString(world, player, node, null); if (s == null) { return defaultValue; } try { - double d = Double.valueOf(s); - return d; - } catch (NumberFormatException e) { + return Double.parseDouble(s); + } catch (final NumberFormatException e) { return defaultValue; } } - + @Override - public void setPlayerInfoDouble(String world, String player, String node, double value) { + public void setPlayerInfoDouble(final String world, final String player, final String node, final double value) { throw new UnsupportedOperationException("bPermissions does not support altering info nodes"); } - + @Override - public double getGroupInfoDouble(String world, String group, String node, double defaultValue) { - String s = getGroupInfoString(world, group, node, null); + public double getGroupInfoDouble(final String world, final String group, final String node, final double defaultValue) { + final String s = this.getGroupInfoString(world, group, node, null); if (s == null) { return defaultValue; } try { - double d = Double.valueOf(s); - return d; - } catch (NumberFormatException e) { + return Double.parseDouble(s); + } catch (final NumberFormatException e) { return defaultValue; } } - + @Override - public void setGroupInfoDouble(String world, String group, String node, double value) { + public void setGroupInfoDouble(final String world, final String group, final String node, final double value) { throw new UnsupportedOperationException("bPermissions does not support altering info nodes"); } - + @Override - public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) { - String s = getPlayerInfoString(world, player, node, null); + public boolean getPlayerInfoBoolean(final String world, final String player, final String node, final boolean defaultValue) { + final String s = this.getPlayerInfoString(world, player, node, null); if (s == null) { return defaultValue; } else { - Boolean val = Boolean.valueOf(s); - return val != null ? val : defaultValue; + final Boolean val = Boolean.valueOf(s); + return val != null ? val : defaultValue; } } - + @Override - public void setPlayerInfoBoolean(String world, String player, String node, boolean value) { + public void setPlayerInfoBoolean(final String world, final String player, final String node, final boolean value) { throw new UnsupportedOperationException("bPermissions does not support altering info nodes"); } - + @Override - public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) { - String s = getGroupInfoString(world, group, node, null); + public boolean getGroupInfoBoolean(final String world, final String group, final String node, final boolean defaultValue) { + final String s = this.getGroupInfoString(world, group, node, null); if (s == null) { return defaultValue; } else { - Boolean val = Boolean.valueOf(s); - return val != null ? val : defaultValue; + final Boolean val = Boolean.valueOf(s); + return val != null ? val : defaultValue; } } - + @Override - public void setGroupInfoBoolean(String world, String group, String node, boolean value) { + public void setGroupInfoBoolean(final String world, final String group, final String node, final boolean value) { throw new UnsupportedOperationException("bPermissions does not support altering info nodes"); } - + @Override - public String getPlayerInfoString(String world, String player, String node, String defaultValue) { - String val = chat.getValue(player, world, node); - return (val == null || val == "BLANKWORLD") ? defaultValue : val; + public String getPlayerInfoString(final String world, final String player, final String node, final String defaultValue) { + final String val = this.chat.getValue(player, world, node); + return (val == null || val.equals("BLANKWORLD")) ? defaultValue : val; } - + @Override - public void setPlayerInfoString(String world, String player, String node, String value) { + public void setPlayerInfoString(final String world, final String player, final String node, final String value) { throw new UnsupportedOperationException("bPermissions does not support altering info nodes"); } - + @Override - public String getGroupInfoString(String world, String group, String node, String defaultValue) { - String val = chat.getGroupValue(group, world, node); - return (val == null || val == "BLANKWORLD") ? defaultValue : val; + public String getGroupInfoString(final String world, final String group, final String node, final String defaultValue) { + final String val = this.chat.getGroupValue(group, world, node); + return (val == null || val.equals("BLANKWORLD")) ? defaultValue : val; } - + @Override - public void setGroupInfoString(String world, String group, String node, String value) { + public void setGroupInfoString(final String world, final String group, final String node, final String value) { throw new UnsupportedOperationException("bPermissions does not support altering info nodes"); } } diff --git a/src/net/milkbowl/vault/chat/plugins/Chat_bPermissions2.java b/src/net/milkbowl/vault/chat/plugins/Chat_bPermissions2.java index 61bba212..628949f9 100644 --- a/src/net/milkbowl/vault/chat/plugins/Chat_bPermissions2.java +++ b/src/net/milkbowl/vault/chat/plugins/Chat_bPermissions2.java @@ -15,11 +15,10 @@ */ package net.milkbowl.vault.chat.plugins; -import java.util.logging.Logger; - +import de.bananaco.bpermissions.api.ApiLayer; +import de.bananaco.bpermissions.api.CalculableType; import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -28,238 +27,233 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import de.bananaco.bpermissions.api.ApiLayer; -import de.bananaco.bpermissions.api.CalculableType; +import java.util.logging.Logger; public class Chat_bPermissions2 extends Chat { - private final Logger log; - private final String name = "bInfo"; - private Plugin plugin = null; - private boolean hooked = false; - - public Chat_bPermissions2(Plugin plugin, Permission perms) { - super(perms); - this.plugin = plugin; - this.log = plugin.getLogger(); - - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); - - // Load Plugin in case it was loaded before - if (!hooked) { - Plugin p = plugin.getServer().getPluginManager().getPlugin("bPermissions"); - if (p != null) { - hooked = true; - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "bPermissions2")); - } - } - } - - public class PermissionServerListener implements Listener { - Chat_bPermissions2 chat = null; - - public PermissionServerListener(Chat_bPermissions2 chat) { - this.chat = chat; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (!hooked) { - Plugin chat = event.getPlugin(); - if (chat.getDescription().getName().equals("bPermissions")) { - hooked = true; - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "bPermissions2")); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (hooked) { - if (event.getPlugin().getDescription().getName().equals("bPermissions")) { - hooked = false; - log.info(String.format("[%s][Chat] %s un-hooked.", plugin.getDescription().getName(), "bPermissions2")); - } - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean isEnabled() { - return hooked; - } - - @Override - public String getPlayerPrefix(String world, String player) { - return ApiLayer.getValue(world, CalculableType.USER, player, "prefix"); - } - - @Override - public void setPlayerPrefix(String world, String player, String prefix) { - ApiLayer.setValue(world, CalculableType.USER, player, "prefix", prefix); - } - - @Override - public String getPlayerSuffix(String world, String player) { - return ApiLayer.getValue(world, CalculableType.USER, player, "suffix"); - } - - @Override - public void setPlayerSuffix(String world, String player, String suffix) { - ApiLayer.setValue(world, CalculableType.USER, player, "suffix", suffix); - } - - @Override - public String getGroupPrefix(String world, String group) { - return ApiLayer.getValue(world, CalculableType.GROUP, group, "prefix"); - } - - @Override - public void setGroupPrefix(String world, String group, String prefix) { - ApiLayer.setValue(world, CalculableType.GROUP, group, "prefix", prefix); - } - - @Override - public String getGroupSuffix(String world, String group) { - return ApiLayer.getValue(world, CalculableType.GROUP, group, "suffix"); - } - - @Override - public void setGroupSuffix(String world, String group, String suffix) { - ApiLayer.setValue(world, CalculableType.GROUP, group, "suffix", suffix); - } - - @Override - public int getPlayerInfoInteger(String world, String player, String node, int defaultValue) { - String s = getPlayerInfoString(world, player, node, null); - if (s == null) { - return defaultValue; - } - try { - int i = Integer.valueOf(s); - return i; - } catch (NumberFormatException e) { - return defaultValue; - } - } - - @Override - public void setPlayerInfoInteger(String world, String player, String node, int value) { - ApiLayer.setValue(world, CalculableType.USER, player, node, String.valueOf(value)); - } - - @Override - public int getGroupInfoInteger(String world, String group, String node, int defaultValue) { - String s = getGroupInfoString(world, group, node, null); - if (s == null) { - return defaultValue; - } - try { - int i = Integer.valueOf(s); - return i; - } catch (NumberFormatException e) { - return defaultValue; - } - } - - @Override - public void setGroupInfoInteger(String world, String group, String node, int value) { - ApiLayer.setValue(world, CalculableType.GROUP, group, node, String.valueOf(value)); - } - - @Override - public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) { - String s = getPlayerInfoString(world, player, node, null); - if (s == null) { - return defaultValue; - } - try { - double d = Double.valueOf(s); - return d; - } catch (NumberFormatException e) { - return defaultValue; - } - } - - @Override - public void setPlayerInfoDouble(String world, String player, String node, double value) { - ApiLayer.setValue(world, CalculableType.USER, player, node, String.valueOf(value)); - } - - @Override - public double getGroupInfoDouble(String world, String group, String node, double defaultValue) { - String s = getGroupInfoString(world, group, node, null); - if (s == null) { - return defaultValue; - } - try { - double d = Double.valueOf(s); - return d; - } catch (NumberFormatException e) { - return defaultValue; - } - } - - @Override - public void setGroupInfoDouble(String world, String group, String node, double value) { - ApiLayer.setValue(world, CalculableType.GROUP, group, node, String.valueOf(value)); - } - - @Override - public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) { - String s = getPlayerInfoString(world, player, node, null); - if (s == null) { - return defaultValue; - } else { - Boolean val = Boolean.valueOf(s); - return val != null ? val : defaultValue; - } - } - - @Override - public void setPlayerInfoBoolean(String world, String player, String node, boolean value) { - ApiLayer.setValue(world, CalculableType.USER, player, node, String.valueOf(value)); - } - - @Override - public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) { - String s = getGroupInfoString(world, group, node, null); - if (s == null) { - return defaultValue; - } else { - Boolean val = Boolean.valueOf(s); - return val != null ? val : defaultValue; - } - } - - @Override - public void setGroupInfoBoolean(String world, String group, String node, boolean value) { - ApiLayer.setValue(world, CalculableType.GROUP, group, node, String.valueOf(value));; - } - - @Override - public String getPlayerInfoString(String world, String player, String node, String defaultValue) { - String val = ApiLayer.getValue(world, CalculableType.USER, player, node); - return (val == null || val == "BLANKWORLD" || val == "") ? defaultValue : val; - } - - @Override - public void setPlayerInfoString(String world, String player, String node, String value) { - ApiLayer.setValue(world, CalculableType.USER, player, node, value); - } - - @Override - public String getGroupInfoString(String world, String group, String node, String defaultValue) { - String val = ApiLayer.getValue(world, CalculableType.GROUP, group, node); - return (val == null || val == "BLANKWORLD" || val == "") ? defaultValue : val; - } - - @Override - public void setGroupInfoString(String world, String group, String node, String value) { - ApiLayer.setValue(world, CalculableType.GROUP, group, node, value); - } + private final Logger log; + private final Plugin plugin; + private boolean hooked; + + public Chat_bPermissions2(final Plugin plugin, final Permission perms) { + super(perms); + this.plugin = plugin; + log = plugin.getLogger(); + + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); + + // Load Plugin in case it was loaded before + if (!this.hooked) { + final Plugin p = plugin.getServer().getPluginManager().getPlugin("bPermissions"); + if (p != null) { + this.hooked = true; + this.log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "bPermissions2")); + } + } + } + + public class PermissionServerListener implements Listener { + final Chat_bPermissions2 chat; + + public PermissionServerListener(final Chat_bPermissions2 chat) { + this.chat = chat; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (!Chat_bPermissions2.this.hooked) { + final Plugin chat = event.getPlugin(); + if (chat.getDescription().getName().equals("bPermissions")) { + Chat_bPermissions2.this.hooked = true; + Chat_bPermissions2.this.log.info(String.format("[%s][Chat] %s hooked.", Chat_bPermissions2.this.plugin.getDescription().getName(), "bPermissions2")); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (Chat_bPermissions2.this.hooked) { + if (event.getPlugin().getDescription().getName().equals("bPermissions")) { + Chat_bPermissions2.this.hooked = false; + Chat_bPermissions2.this.log.info(String.format("[%s][Chat] %s un-hooked.", Chat_bPermissions2.this.plugin.getDescription().getName(), "bPermissions2")); + } + } + } + } + + @Override + public String getName() { + String name = "bInfo"; + return name; + } + + @Override + public boolean isEnabled() { + return this.hooked; + } + + @Override + public String getPlayerPrefix(final String world, final String player) { + return ApiLayer.getValue(world, CalculableType.USER, player, "prefix"); + } + + @Override + public void setPlayerPrefix(final String world, final String player, final String prefix) { + ApiLayer.setValue(world, CalculableType.USER, player, "prefix", prefix); + } + + @Override + public String getPlayerSuffix(final String world, final String player) { + return ApiLayer.getValue(world, CalculableType.USER, player, "suffix"); + } + + @Override + public void setPlayerSuffix(final String world, final String player, final String suffix) { + ApiLayer.setValue(world, CalculableType.USER, player, "suffix", suffix); + } + + @Override + public String getGroupPrefix(final String world, final String group) { + return ApiLayer.getValue(world, CalculableType.GROUP, group, "prefix"); + } + + @Override + public void setGroupPrefix(final String world, final String group, final String prefix) { + ApiLayer.setValue(world, CalculableType.GROUP, group, "prefix", prefix); + } + + @Override + public String getGroupSuffix(final String world, final String group) { + return ApiLayer.getValue(world, CalculableType.GROUP, group, "suffix"); + } + + @Override + public void setGroupSuffix(final String world, final String group, final String suffix) { + ApiLayer.setValue(world, CalculableType.GROUP, group, "suffix", suffix); + } + + @Override + public int getPlayerInfoInteger(final String world, final String player, final String node, final int defaultValue) { + final String s = this.getPlayerInfoString(world, player, node, null); + if (s == null) { + return defaultValue; + } + try { + return Integer.parseInt(s); + } catch (final NumberFormatException e) { + return defaultValue; + } + } + + @Override + public void setPlayerInfoInteger(final String world, final String player, final String node, final int value) { + ApiLayer.setValue(world, CalculableType.USER, player, node, String.valueOf(value)); + } + + @Override + public int getGroupInfoInteger(final String world, final String group, final String node, final int defaultValue) { + final String s = this.getGroupInfoString(world, group, node, null); + if (s == null) { + return defaultValue; + } + try { + return Integer.parseInt(s); + } catch (final NumberFormatException e) { + return defaultValue; + } + } + + @Override + public void setGroupInfoInteger(final String world, final String group, final String node, final int value) { + ApiLayer.setValue(world, CalculableType.GROUP, group, node, String.valueOf(value)); + } + + @Override + public double getPlayerInfoDouble(final String world, final String player, final String node, final double defaultValue) { + final String s = this.getPlayerInfoString(world, player, node, null); + if (s == null) { + return defaultValue; + } + try { + return Double.parseDouble(s); + } catch (final NumberFormatException e) { + return defaultValue; + } + } + + @Override + public void setPlayerInfoDouble(final String world, final String player, final String node, final double value) { + ApiLayer.setValue(world, CalculableType.USER, player, node, String.valueOf(value)); + } + + @Override + public double getGroupInfoDouble(final String world, final String group, final String node, final double defaultValue) { + final String s = this.getGroupInfoString(world, group, node, null); + if (s == null) { + return defaultValue; + } + try { + return Double.parseDouble(s); + } catch (final NumberFormatException e) { + return defaultValue; + } + } + + @Override + public void setGroupInfoDouble(final String world, final String group, final String node, final double value) { + ApiLayer.setValue(world, CalculableType.GROUP, group, node, String.valueOf(value)); + } + + @Override + public boolean getPlayerInfoBoolean(final String world, final String player, final String node, final boolean defaultValue) { + final String s = this.getPlayerInfoString(world, player, node, null); + if (s == null) { + return defaultValue; + } else { + final Boolean val = Boolean.valueOf(s); + return val != null ? val : defaultValue; + } + } + + @Override + public void setPlayerInfoBoolean(final String world, final String player, final String node, final boolean value) { + ApiLayer.setValue(world, CalculableType.USER, player, node, String.valueOf(value)); + } + + @Override + public boolean getGroupInfoBoolean(final String world, final String group, final String node, final boolean defaultValue) { + final String s = this.getGroupInfoString(world, group, node, null); + if (s == null) { + return defaultValue; + } else { + final Boolean val = Boolean.valueOf(s); + return val != null ? val : defaultValue; + } + } + + @Override + public void setGroupInfoBoolean(final String world, final String group, final String node, final boolean value) { + ApiLayer.setValue(world, CalculableType.GROUP, group, node, String.valueOf(value)); + } + + @Override + public String getPlayerInfoString(final String world, final String player, final String node, final String defaultValue) { + final String val = ApiLayer.getValue(world, CalculableType.USER, player, node); + return (val == null || val.equals("BLANKWORLD") || val.equals("")) ? defaultValue : val; + } + + @Override + public void setPlayerInfoString(final String world, final String player, final String node, final String value) { + ApiLayer.setValue(world, CalculableType.USER, player, node, value); + } + + @Override + public String getGroupInfoString(final String world, final String group, final String node, final String defaultValue) { + final String val = ApiLayer.getValue(world, CalculableType.GROUP, group, node); + return (val == null || val.equals("BLANKWORLD") || val.equals("")) ? defaultValue : val; + } + + @Override + public void setGroupInfoString(final String world, final String group, final String node, final String value) { + ApiLayer.setValue(world, CalculableType.GROUP, group, node, value); + } } \ No newline at end of file diff --git a/src/net/milkbowl/vault/chat/plugins/Chat_iChat.java b/src/net/milkbowl/vault/chat/plugins/Chat_iChat.java index 7ad49a4f..8d57d62a 100644 --- a/src/net/milkbowl/vault/chat/plugins/Chat_iChat.java +++ b/src/net/milkbowl/vault/chat/plugins/Chat_iChat.java @@ -15,13 +15,10 @@ */ package net.milkbowl.vault.chat.plugins; -import java.util.logging.Logger; - import net.TheDgtl.iChat.iChat; import net.TheDgtl.iChat.iChatAPI; import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -31,244 +28,246 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -public class Chat_iChat extends Chat { +import java.util.logging.Logger; +public class Chat_iChat extends Chat { + private final Logger log; - private final String name = "iChat"; - private Plugin plugin = null; - private iChatAPI iChat = null; - - public Chat_iChat(Plugin plugin, Permission perms) { + private final Plugin plugin; + private iChatAPI iChat; + + public Chat_iChat(final Plugin plugin, final Permission perms) { super(perms); this.plugin = plugin; - this.log = plugin.getLogger(); - + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); - + // Load Plugin in case it was loaded before - if (iChat == null) { - Plugin chat = plugin.getServer().getPluginManager().getPlugin("iChat"); + if (this.iChat == null) { + final Plugin chat = plugin.getServer().getPluginManager().getPlugin("iChat"); if (chat != null) { - iChat = ((iChat) chat).API; - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "iChat")); + this.iChat = ((iChat) chat).API; + this.log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "iChat")); } } } - + public class PermissionServerListener implements Listener { - Chat_iChat chat = null; - - public PermissionServerListener(Chat_iChat chat) { + final Chat_iChat chat; + + public PermissionServerListener(final Chat_iChat chat) { this.chat = chat; } - + @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (this.chat.iChat == null) { - Plugin chat = event.getPlugin(); + public void onPluginEnable(final PluginEnableEvent event) { + if (chat.iChat == null) { + final Plugin chat = event.getPlugin(); if (chat.getDescription().getName().equals("iChat")) { this.chat.iChat = ((iChat) chat).API; - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "iChat")); + Chat_iChat.this.log.info(String.format("[%s][Chat] %s hooked.", Chat_iChat.this.plugin.getDescription().getName(), "iChat")); } } } - + @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (this.chat.iChat != null) { + public void onPluginDisable(final PluginDisableEvent event) { + if (chat.iChat != null) { if (event.getPlugin().getDescription().getName().equals("iChat")) { - this.chat.iChat = null; - log.info(String.format("[%s][Chat] %s un-hooked.", plugin.getDescription().getName(), "iChat")); + chat.iChat = null; + Chat_iChat.this.log.info(String.format("[%s][Chat] %s un-hooked.", Chat_iChat.this.plugin.getDescription().getName(), "iChat")); } } } } - + @Override public String getName() { + String name = "iChat"; return name; } - + @Override public boolean isEnabled() { - return iChat != null; + return this.iChat != null; } - + @Override - public String getPlayerPrefix(String world, String player) { - Player p = plugin.getServer().getPlayer(player); + public String getPlayerPrefix(final String world, final String player) { + final Player p = this.plugin.getServer().getPlayer(player); if (p == null) { throw new UnsupportedOperationException("iChat does not support offline player info nodes!"); } - + if (!p.getWorld().getName().equals(world)) { return null; } - - return iChat.getPrefix(p); + + return this.iChat.getPrefix(p); } - + @Override - public void setPlayerPrefix(String world, String player, String prefix) { + public void setPlayerPrefix(final String world, final String player, final String prefix) { throw new UnsupportedOperationException("iChat does not support mutable info nodes!"); } - + @Override - public String getPlayerSuffix(String world, String player) { - Player p = plugin.getServer().getPlayer(player); + public String getPlayerSuffix(final String world, final String player) { + final Player p = this.plugin.getServer().getPlayer(player); if (p == null) { throw new UnsupportedOperationException("iChat does not support offline player info nodes!"); } - + if (!p.getWorld().getName().equals(world)) { return null; } - - return iChat.getSuffix(p); + + return this.iChat.getSuffix(p); } - + @Override - public void setPlayerSuffix(String world, String player, String suffix) { + public void setPlayerSuffix(final String world, final String player, final String suffix) { throw new UnsupportedOperationException("iChat does not support mutable info nodes!"); } - + @Override - public String getGroupPrefix(String world, String group) { + public String getGroupPrefix(final String world, final String group) { throw new UnsupportedOperationException("iChat does not support group info nodes!"); } - + @Override - public void setGroupPrefix(String world, String group, String prefix) { + public void setGroupPrefix(final String world, final String group, final String prefix) { throw new UnsupportedOperationException("iChat does not support mutable info nodes!"); } - + @Override - public String getGroupSuffix(String world, String group) { + public String getGroupSuffix(final String world, final String group) { throw new UnsupportedOperationException("iChat does not support group info nodes!"); } - + @Override - public void setGroupSuffix(String world, String group, String suffix) { + public void setGroupSuffix(final String world, final String group, final String suffix) { throw new UnsupportedOperationException("iChat does not support mutable info nodes!"); } - + @Override - public int getPlayerInfoInteger(String world, String player, String node, int defaultValue) { - String val = getPlayerInfoString(world, player, node, null); + public int getPlayerInfoInteger(final String world, final String player, final String node, final int defaultValue) { + final String val = this.getPlayerInfoString(world, player, node, null); if (val == null) { return defaultValue; } - - Integer i = defaultValue; + + int i; try { - i = Integer.valueOf(val); + i = Integer.parseInt(val); return i; - } catch (NumberFormatException e) { + } catch (final NumberFormatException e) { return defaultValue; } } - + @Override - public void setPlayerInfoInteger(String world, String player, String node, int value) { + public void setPlayerInfoInteger(final String world, final String player, final String node, final int value) { throw new UnsupportedOperationException("iChat does not support mutable info nodes!"); } - + @Override - public int getGroupInfoInteger(String world, String group, String node, int defaultValue) { + public int getGroupInfoInteger(final String world, final String group, final String node, final int defaultValue) { throw new UnsupportedOperationException("iChat does not support group info nodes!"); } - + @Override - public void setGroupInfoInteger(String world, String group, String node, int value) { + public void setGroupInfoInteger(final String world, final String group, final String node, final int value) { throw new UnsupportedOperationException("iChat does not support mutable info nodes!"); } - + @Override - public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) { - String val = getPlayerInfoString(world, player, node, null); + public double getPlayerInfoDouble(final String world, final String player, final String node, final double defaultValue) { + final String val = this.getPlayerInfoString(world, player, node, null); if (val == null) { return defaultValue; } - - double d = defaultValue; + + double d; try { - d = Double.valueOf(val); + d = Double.parseDouble(val); return d; - } catch (NumberFormatException e) { + } catch (final NumberFormatException e) { return defaultValue; } } - + @Override - public void setPlayerInfoDouble(String world, String player, String node, double value) { + public void setPlayerInfoDouble(final String world, final String player, final String node, final double value) { throw new UnsupportedOperationException("iChat does not support mutable info nodes!"); } - + @Override - public double getGroupInfoDouble(String world, String group, String node, double defaultValue) { + public double getGroupInfoDouble(final String world, final String group, final String node, final double defaultValue) { throw new UnsupportedOperationException("iChat does not support group info nodes!"); } - + @Override - public void setGroupInfoDouble(String world, String group, String node, double value) { + public void setGroupInfoDouble(final String world, final String group, final String node, final double value) { throw new UnsupportedOperationException("iChat does not support mutable info nodes!"); } - + @Override - public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) { - String val = getPlayerInfoString(world, player, node, null); + public boolean getPlayerInfoBoolean(final String world, final String player, final String node, final boolean defaultValue) { + final String val = this.getPlayerInfoString(world, player, node, null); if (val == null) { return defaultValue; } else { - Boolean v = Boolean.valueOf(val); - return v != null ? v : defaultValue; + final Boolean v = Boolean.valueOf(val); + return v != null ? v : defaultValue; } } - + @Override - public void setPlayerInfoBoolean(String world, String player, String node, boolean value) { + public void setPlayerInfoBoolean(final String world, final String player, final String node, final boolean value) { throw new UnsupportedOperationException("iChat does not support mutable info nodes!"); } - + @Override - public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) { - throw new UnsupportedOperationException("iChat does not support group info nodes!"); + public boolean getGroupInfoBoolean(final String world, final String group, final String node, final boolean defaultValue) { + throw new UnsupportedOperationException("iChat does not support group info nodes!"); } - + @Override - public void setGroupInfoBoolean(String world, String group, String node, boolean value) { + public void setGroupInfoBoolean(final String world, final String group, final String node, final boolean value) { throw new UnsupportedOperationException("iChat does not support mutable info nodes!"); } - + @Override - public String getPlayerInfoString(String world, String player, String node, String defaultValue) { - Player p = plugin.getServer().getPlayer(player); + public String getPlayerInfoString(final String world, final String player, final String node, final String defaultValue) { + final Player p = this.plugin.getServer().getPlayer(player); if (p == null) { throw new UnsupportedOperationException("iChat does not support offline player info nodes!"); } - + if (!p.getWorld().getName().equals(world)) { return null; } - - String val = iChat.getInfo(p, node); - + + final String val = this.iChat.getInfo(p, node); + return val != null ? val : defaultValue; } - + @Override - public void setPlayerInfoString(String world, String player, String node, String value) { + public void setPlayerInfoString(final String world, final String player, final String node, final String value) { throw new UnsupportedOperationException("iChat does not support mutable info nodes!"); } - + @Override - public String getGroupInfoString(String world, String group, String node, String defaultValue) { + public String getGroupInfoString(final String world, final String group, final String node, final String defaultValue) { throw new UnsupportedOperationException("iChat does not support group info nodes!"); } - + @Override - public void setGroupInfoString(String world, String group, String node, String value) { + public void setGroupInfoString(final String world, final String group, final String node, final String value) { throw new UnsupportedOperationException("iChat does not support mutable info nodes!"); } } diff --git a/src/net/milkbowl/vault/chat/plugins/Chat_mChat.java b/src/net/milkbowl/vault/chat/plugins/Chat_mChat.java index 21d5ba67..b2cbf568 100644 --- a/src/net/milkbowl/vault/chat/plugins/Chat_mChat.java +++ b/src/net/milkbowl/vault/chat/plugins/Chat_mChat.java @@ -15,12 +15,9 @@ */ package net.milkbowl.vault.chat.plugins; -import java.util.logging.Logger; - import net.D3GN.MiracleM4n.mChat.mChatAPI; import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -30,222 +27,224 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -public class Chat_mChat extends Chat { - private final Logger log; - private final String name = "mChat"; - private Plugin plugin = null; - private mChatAPI mChat = null; - - public Chat_mChat(Plugin plugin, Permission perms) { - super(perms); - this.plugin = plugin; - this.log = plugin.getLogger(); - - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); - - // Load Plugin in case it was loaded before - if (mChat == null) { - Plugin chat = plugin.getServer().getPluginManager().getPlugin("mChat"); - if (chat != null) { - mChat = net.D3GN.MiracleM4n.mChat.mChat.API; - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "mChat")); - } - } - } - - public class PermissionServerListener implements Listener { - Chat_mChat chat = null; - - public PermissionServerListener(Chat_mChat chat) { - this.chat = chat; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (this.chat.mChat == null) { - Plugin chat = event.getPlugin(); - if (chat.getDescription().getName().equals("mChat")) { - this.chat.mChat = net.D3GN.MiracleM4n.mChat.mChat.API; - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "mChat")); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (this.chat.mChat != null) { - if (event.getPlugin().getDescription().getName().equals("mChat")) { - this.chat.mChat = null; - log.info(String.format("[%s][Chat] %s un-hooked.", plugin.getDescription().getName(), "mChat")); - } - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean isEnabled() { - return mChat != null; - } - - @Override - public String getPlayerPrefix(String world, String player) { - Player p = Bukkit.getServer().getPlayer(player); - if (p ==null) { - throw new UnsupportedOperationException("mChat does not support offline player prefixes"); - } - return mChat.getPrefix(p); - } - - @Override - public void setPlayerPrefix(String world, String player, String prefix) { - throw new UnsupportedOperationException("mChat does not support setting info nodes"); - } - - @Override - public String getPlayerSuffix(String world, String player) { - Player p = Bukkit.getServer().getPlayer(player); - if (p ==null) { - throw new UnsupportedOperationException("mChat does not support offline player prefixes"); - } - return mChat.getSuffix(p); - } - - @Override - public void setPlayerSuffix(String world, String player, String suffix) { - throw new UnsupportedOperationException("mChat does not support setting info nodes"); - } - - @Override - public String getGroupPrefix(String world, String group) { - throw new UnsupportedOperationException("mChat does not support group info nodes"); - } - - @Override - public void setGroupPrefix(String world, String group, String prefix) { - throw new UnsupportedOperationException("mChat does not support group info nodes"); - } - - @Override - public String getGroupSuffix(String world, String group) { - throw new UnsupportedOperationException("mChat does not support group info nodes"); - } - - @Override - public void setGroupSuffix(String world, String group, String suffix) { - throw new UnsupportedOperationException("mChat does not support group info nodes"); - } - - @Override - public int getPlayerInfoInteger(String world, String player, String node, int defaultValue) { - String s = getPlayerInfoString(world, player, node, null); - if (s == null) { - return defaultValue; - } - - try { - return Integer.valueOf(s); - } catch (NumberFormatException e) { - return defaultValue; - } - } - - @Override - public void setPlayerInfoInteger(String world, String player, String node, int value) { - throw new UnsupportedOperationException("mChat does not support setting info nodes"); - } - - @Override - public int getGroupInfoInteger(String world, String group, String node, int defaultValue) { - throw new UnsupportedOperationException("mChat does not support group info nodes"); - } - - @Override - public void setGroupInfoInteger(String world, String group, String node, int value) { - throw new UnsupportedOperationException("mChat does not support group info nodes"); - } - - @Override - public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) { - String s = getPlayerInfoString(world, player, node, null); - if (s == null) { - return defaultValue; - } - - try { - return Double.valueOf(s); - } catch (NumberFormatException e) { - return defaultValue; - } - } - - @Override - public void setPlayerInfoDouble(String world, String player, String node, double value) { - throw new UnsupportedOperationException("mChat does not support setting info nodes"); - } - - @Override - public double getGroupInfoDouble(String world, String group, String node,double defaultValue) { - throw new UnsupportedOperationException("mChat does not support group info nodes"); - } - - @Override - public void setGroupInfoDouble(String world, String group, String node, double value) { - throw new UnsupportedOperationException("mChat does not support group info nodes"); - } - - @Override - public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) { - String s = getPlayerInfoString(world, player, node, null); - if (s == null) { - return defaultValue; - } else { - Boolean val = Boolean.valueOf(s); - return val != null ? val : defaultValue; - } - } - - @Override - public void setPlayerInfoBoolean(String world, String player, String node, boolean value) { - throw new UnsupportedOperationException("mChat does not support setting info nodes"); - } - - @Override - public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) { - throw new UnsupportedOperationException("mChat does not support group info nodes"); - } - - @Override - public void setGroupInfoBoolean(String world, String group, String node, boolean value) { - throw new UnsupportedOperationException("mChat does not support group info nodes"); - } - - @Override - public String getPlayerInfoString(String world, String player, String node, String defaultValue) { - Player p = Bukkit.getServer().getPlayer(player); - if (p ==null) { - throw new UnsupportedOperationException("mChat does not support offline player prefixes"); - } - String s = mChat.getInfo(p, node); - return s == null ? defaultValue : s; - } - - @Override - public void setPlayerInfoString(String world, String player, String node, String value) { - throw new UnsupportedOperationException("mChat does not support setting info nodes"); - } - - @Override - public String getGroupInfoString(String world, String group, String node, String defaultValue) { - throw new UnsupportedOperationException("mChat does not support group info nodes"); - } +import java.util.logging.Logger; - @Override - public void setGroupInfoString(String world, String group, String node, String value) { - throw new UnsupportedOperationException("mChat does not support group info nodes"); - } +public class Chat_mChat extends Chat { + private final Logger log; + private final Plugin plugin; + private mChatAPI mChat; + + public Chat_mChat(final Plugin plugin, final Permission perms) { + super(perms); + this.plugin = plugin; + log = plugin.getLogger(); + + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); + + // Load Plugin in case it was loaded before + if (this.mChat == null) { + final Plugin chat = plugin.getServer().getPluginManager().getPlugin("mChat"); + if (chat != null) { + this.mChat = net.D3GN.MiracleM4n.mChat.mChat.API; + this.log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "mChat")); + } + } + } + + public class PermissionServerListener implements Listener { + final Chat_mChat chat; + + public PermissionServerListener(final Chat_mChat chat) { + this.chat = chat; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (chat.mChat == null) { + final Plugin chat = event.getPlugin(); + if (chat.getDescription().getName().equals("mChat")) { + this.chat.mChat = net.D3GN.MiracleM4n.mChat.mChat.API; + Chat_mChat.this.log.info(String.format("[%s][Chat] %s hooked.", Chat_mChat.this.plugin.getDescription().getName(), "mChat")); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (chat.mChat != null) { + if (event.getPlugin().getDescription().getName().equals("mChat")) { + chat.mChat = null; + Chat_mChat.this.log.info(String.format("[%s][Chat] %s un-hooked.", Chat_mChat.this.plugin.getDescription().getName(), "mChat")); + } + } + } + } + + @Override + public String getName() { + String name = "mChat"; + return name; + } + + @Override + public boolean isEnabled() { + return this.mChat != null; + } + + @Override + public String getPlayerPrefix(final String world, final String player) { + final Player p = Bukkit.getServer().getPlayer(player); + if (p == null) { + throw new UnsupportedOperationException("mChat does not support offline player prefixes"); + } + return this.mChat.getPrefix(p); + } + + @Override + public void setPlayerPrefix(final String world, final String player, final String prefix) { + throw new UnsupportedOperationException("mChat does not support setting info nodes"); + } + + @Override + public String getPlayerSuffix(final String world, final String player) { + final Player p = Bukkit.getServer().getPlayer(player); + if (p == null) { + throw new UnsupportedOperationException("mChat does not support offline player prefixes"); + } + return this.mChat.getSuffix(p); + } + + @Override + public void setPlayerSuffix(final String world, final String player, final String suffix) { + throw new UnsupportedOperationException("mChat does not support setting info nodes"); + } + + @Override + public String getGroupPrefix(final String world, final String group) { + throw new UnsupportedOperationException("mChat does not support group info nodes"); + } + + @Override + public void setGroupPrefix(final String world, final String group, final String prefix) { + throw new UnsupportedOperationException("mChat does not support group info nodes"); + } + + @Override + public String getGroupSuffix(final String world, final String group) { + throw new UnsupportedOperationException("mChat does not support group info nodes"); + } + + @Override + public void setGroupSuffix(final String world, final String group, final String suffix) { + throw new UnsupportedOperationException("mChat does not support group info nodes"); + } + + @Override + public int getPlayerInfoInteger(final String world, final String player, final String node, final int defaultValue) { + final String s = this.getPlayerInfoString(world, player, node, null); + if (s == null) { + return defaultValue; + } + + try { + return Integer.parseInt(s); + } catch (final NumberFormatException e) { + return defaultValue; + } + } + + @Override + public void setPlayerInfoInteger(final String world, final String player, final String node, final int value) { + throw new UnsupportedOperationException("mChat does not support setting info nodes"); + } + + @Override + public int getGroupInfoInteger(final String world, final String group, final String node, final int defaultValue) { + throw new UnsupportedOperationException("mChat does not support group info nodes"); + } + + @Override + public void setGroupInfoInteger(final String world, final String group, final String node, final int value) { + throw new UnsupportedOperationException("mChat does not support group info nodes"); + } + + @Override + public double getPlayerInfoDouble(final String world, final String player, final String node, final double defaultValue) { + final String s = this.getPlayerInfoString(world, player, node, null); + if (s == null) { + return defaultValue; + } + + try { + return Double.parseDouble(s); + } catch (final NumberFormatException e) { + return defaultValue; + } + } + + @Override + public void setPlayerInfoDouble(final String world, final String player, final String node, final double value) { + throw new UnsupportedOperationException("mChat does not support setting info nodes"); + } + + @Override + public double getGroupInfoDouble(final String world, final String group, final String node, final double defaultValue) { + throw new UnsupportedOperationException("mChat does not support group info nodes"); + } + + @Override + public void setGroupInfoDouble(final String world, final String group, final String node, final double value) { + throw new UnsupportedOperationException("mChat does not support group info nodes"); + } + + @Override + public boolean getPlayerInfoBoolean(final String world, final String player, final String node, final boolean defaultValue) { + final String s = this.getPlayerInfoString(world, player, node, null); + if (s == null) { + return defaultValue; + } else { + final Boolean val = Boolean.valueOf(s); + return val != null ? val : defaultValue; + } + } + + @Override + public void setPlayerInfoBoolean(final String world, final String player, final String node, final boolean value) { + throw new UnsupportedOperationException("mChat does not support setting info nodes"); + } + + @Override + public boolean getGroupInfoBoolean(final String world, final String group, final String node, final boolean defaultValue) { + throw new UnsupportedOperationException("mChat does not support group info nodes"); + } + + @Override + public void setGroupInfoBoolean(final String world, final String group, final String node, final boolean value) { + throw new UnsupportedOperationException("mChat does not support group info nodes"); + } + + @Override + public String getPlayerInfoString(final String world, final String player, final String node, final String defaultValue) { + final Player p = Bukkit.getServer().getPlayer(player); + if (p == null) { + throw new UnsupportedOperationException("mChat does not support offline player prefixes"); + } + final String s = this.mChat.getInfo(p, node); + return s == null ? defaultValue : s; + } + + @Override + public void setPlayerInfoString(final String world, final String player, final String node, final String value) { + throw new UnsupportedOperationException("mChat does not support setting info nodes"); + } + + @Override + public String getGroupInfoString(final String world, final String group, final String node, final String defaultValue) { + throw new UnsupportedOperationException("mChat does not support group info nodes"); + } + + @Override + public void setGroupInfoString(final String world, final String group, final String node, final String value) { + throw new UnsupportedOperationException("mChat does not support group info nodes"); + } } diff --git a/src/net/milkbowl/vault/chat/plugins/Chat_mChatSuite.java b/src/net/milkbowl/vault/chat/plugins/Chat_mChatSuite.java index b008560b..9b951aa8 100644 --- a/src/net/milkbowl/vault/chat/plugins/Chat_mChatSuite.java +++ b/src/net/milkbowl/vault/chat/plugins/Chat_mChatSuite.java @@ -19,12 +19,8 @@ import com.miraclem4n.mchat.api.Writer; import com.miraclem4n.mchat.types.InfoType; import in.mDev.MiracleM4n.mChatSuite.mChatSuite; - -import java.util.logging.Logger; - import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -33,253 +29,256 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -public class Chat_mChatSuite extends Chat { - private final Logger log; - private final String name = "mChatSuite"; - private Plugin plugin = null; - private mChatSuite mChat = null; - - public Chat_mChatSuite(Plugin plugin, Permission perms) { - super(perms); - this.plugin = plugin; - this.log = plugin.getLogger(); - - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); - - // Load Plugin in case it was loaded before - if (mChat == null) { - Plugin chat = plugin.getServer().getPluginManager().getPlugin("mChatSuite"); - if (chat != null && chat.isEnabled()) { - mChat = (mChatSuite) chat; - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "mChatSuite")); - } - } - } - - public class PermissionServerListener implements Listener { - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (mChat == null) { - Plugin chat = event.getPlugin(); - if (chat.getDescription().getName().equals("mChatSuite")) { - mChat = (mChatSuite) chat; - log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "mChatSuite")); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (mChat != null) { - if (event.getPlugin().getDescription().getName().equals("mChatSuite")) { - mChat = null; - log.info(String.format("[%s][Chat] %s un-hooked.", plugin.getDescription().getName(), "mChatSuite")); - } - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean isEnabled() { - return mChat != null && mChat.isEnabled(); - } - - @Override - public String getPlayerPrefix(String world, String player) { - return Reader.getPrefix(player, InfoType.USER, world); - } - - @Override - public void setPlayerPrefix(String world, String player, String prefix) { - setPlayerInfoValue(world, player, "prefix", prefix); - } - - @Override - public String getPlayerSuffix(String world, String player) { - return Reader.getSuffix(player, InfoType.USER, world); - } - - @Override - public void setPlayerSuffix(String world, String player, String suffix) { - setPlayerInfoValue(world, player, "suffix", suffix); - } - - @Override - public String getGroupPrefix(String world, String group) { - return Reader.getPrefix(group, InfoType.GROUP, world); - } - - @Override - public void setGroupPrefix(String world, String group, String prefix) { - setGroupInfoValue(world, group, "prefix", prefix); - } - - @Override - public String getGroupSuffix(String world, String group) { - return Reader.getSuffix(group, InfoType.GROUP, world); - } - - @Override - public void setGroupSuffix(String world, String group, String suffix) { - setGroupInfoValue(world, group, "suffix", suffix); - } - - @Override - public int getPlayerInfoInteger(String world, String player, String node, int defaultValue) { - String val = getPlayerInfoValue(world, player, node); - if (val == null || val.equals("")) { - return defaultValue; - } - try { - return Integer.parseInt(val); - } catch (NumberFormatException e) { - return defaultValue; - } - } - - @Override - public void setPlayerInfoInteger(String world, String player, String node, int value) { - setPlayerInfoValue(world, player, node, value); - } - - @Override - public int getGroupInfoInteger(String world, String group, String node, int defaultValue) { - String val = getGroupInfoValue(world, group, node); - if (val == null || val.equals("")) { - return defaultValue; - } - try { - return Integer.parseInt(val); - } catch (NumberFormatException e) { - return defaultValue; - } - } - - @Override - public void setGroupInfoInteger(String world, String group, String node, int value) { - setGroupInfoValue(world, group, node, value); - } - - @Override - public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) { - String val = getPlayerInfoValue(world, player, node); - if (val == null || val.equals("")) { - return defaultValue; - } - try { - return Double.parseDouble(val); - } catch (NumberFormatException e) { - return defaultValue; - } - } - - @Override - public void setPlayerInfoDouble(String world, String player, String node, double value) { - setPlayerInfoValue(world, player, node, value); - } - - @Override - public double getGroupInfoDouble(String world, String group, String node,double defaultValue) { - String val = getGroupInfoValue(world, group, node); - if (val == null || val.equals("")) { - return defaultValue; - } - try { - return Double.parseDouble(val); - } catch (NumberFormatException e) { - return defaultValue; - } - } - - @Override - public void setGroupInfoDouble(String world, String group, String node, double value) { - setGroupInfoValue(world, group, node, value); - } - - @Override - public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) { - String val = getPlayerInfoValue(world, player, node); - if (val == null || val.equals("")) { - return defaultValue; - } - return Boolean.parseBoolean(val); - } - - @Override - public void setPlayerInfoBoolean(String world, String player, String node, boolean value) { - setPlayerInfoValue(world, player, node, value); - } - - @Override - public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) { - String val = getGroupInfoValue(world, group, node); - if (val == null || val.equals("")) { - return defaultValue; - } - return Boolean.valueOf(val); - } - - @Override - public void setGroupInfoBoolean(String world, String group, String node, boolean value) { - setGroupInfoValue(world, group, node, value); - } - - @Override - public String getPlayerInfoString(String world, String player, String node, String defaultValue) { - String val = getPlayerInfoValue(world, player, node); - if (val == null) { - return defaultValue; - } else { - return val; - } - } - - @Override - public void setPlayerInfoString(String world, String player, String node, String value) { - setPlayerInfoValue(world, player, node, value); - } - - @Override - public String getGroupInfoString(String world, String group, String node, String defaultValue) { - String val = getGroupInfoValue(world, group, node); - if (val == null) { - return defaultValue; - } else { - return val; - } - } - - @Override - public void setGroupInfoString(String world, String group, String node, String value) { - setGroupInfoValue(world, group, node, value); - } - - private void setPlayerInfoValue(String world, String player, String node, Object value) { - if (world != null) { - Writer.setWorldVar(player, InfoType.USER, world, node, value.toString()); - } else { - Writer.setInfoVar(player, InfoType.USER, node, value.toString()); - } - } - - private void setGroupInfoValue(String world, String group, String node, Object value) { - if (world != null) { - Writer.setWorldVar(group, InfoType.GROUP, world, node, value); - } else { - Writer.setInfoVar(group, InfoType.GROUP, node, value); - } - } - private String getPlayerInfoValue(String world, String player, String node) { - return Reader.getInfo(player, InfoType.USER, world, node); - } +import java.util.logging.Logger; - private String getGroupInfoValue(String world, String group, String node) { - return Reader.getInfo(group, InfoType.GROUP, world, node); - } +public class Chat_mChatSuite extends Chat { + private final Logger log; + private final Plugin plugin; + private mChatSuite mChat; + + public Chat_mChatSuite(final Plugin plugin, final Permission perms) { + super(perms); + this.plugin = plugin; + log = plugin.getLogger(); + + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); + + // Load Plugin in case it was loaded before + if (this.mChat == null) { + final Plugin chat = plugin.getServer().getPluginManager().getPlugin("mChatSuite"); + if (chat != null && chat.isEnabled()) { + this.mChat = (mChatSuite) chat; + this.log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "mChatSuite")); + } + } + } + + public class PermissionServerListener implements Listener { + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (Chat_mChatSuite.this.mChat == null) { + final Plugin chat = event.getPlugin(); + if (chat.getDescription().getName().equals("mChatSuite")) { + Chat_mChatSuite.this.mChat = (mChatSuite) chat; + Chat_mChatSuite.this.log.info(String.format("[%s][Chat] %s hooked.", Chat_mChatSuite.this.plugin.getDescription().getName(), "mChatSuite")); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (Chat_mChatSuite.this.mChat != null) { + if (event.getPlugin().getDescription().getName().equals("mChatSuite")) { + Chat_mChatSuite.this.mChat = null; + Chat_mChatSuite.this.log.info(String.format("[%s][Chat] %s un-hooked.", Chat_mChatSuite.this.plugin.getDescription().getName(), "mChatSuite")); + } + } + } + } + + @Override + public String getName() { + String name = "mChatSuite"; + return name; + } + + @Override + public boolean isEnabled() { + return this.mChat != null && this.mChat.isEnabled(); + } + + @Override + public String getPlayerPrefix(final String world, final String player) { + return Reader.getPrefix(player, InfoType.USER, world); + } + + @Override + public void setPlayerPrefix(final String world, final String player, final String prefix) { + this.setPlayerInfoValue(world, player, "prefix", prefix); + } + + @Override + public String getPlayerSuffix(final String world, final String player) { + return Reader.getSuffix(player, InfoType.USER, world); + } + + @Override + public void setPlayerSuffix(final String world, final String player, final String suffix) { + this.setPlayerInfoValue(world, player, "suffix", suffix); + } + + @Override + public String getGroupPrefix(final String world, final String group) { + return Reader.getPrefix(group, InfoType.GROUP, world); + } + + @Override + public void setGroupPrefix(final String world, final String group, final String prefix) { + this.setGroupInfoValue(world, group, "prefix", prefix); + } + + @Override + public String getGroupSuffix(final String world, final String group) { + return Reader.getSuffix(group, InfoType.GROUP, world); + } + + @Override + public void setGroupSuffix(final String world, final String group, final String suffix) { + this.setGroupInfoValue(world, group, "suffix", suffix); + } + + @Override + public int getPlayerInfoInteger(final String world, final String player, final String node, final int defaultValue) { + final String val = this.getPlayerInfoValue(world, player, node); + if (val == null || val.equals("")) { + return defaultValue; + } + try { + return Integer.parseInt(val); + } catch (final NumberFormatException e) { + return defaultValue; + } + } + + @Override + public void setPlayerInfoInteger(final String world, final String player, final String node, final int value) { + this.setPlayerInfoValue(world, player, node, value); + } + + @Override + public int getGroupInfoInteger(final String world, final String group, final String node, final int defaultValue) { + final String val = this.getGroupInfoValue(world, group, node); + if (val == null || val.equals("")) { + return defaultValue; + } + try { + return Integer.parseInt(val); + } catch (final NumberFormatException e) { + return defaultValue; + } + } + + @Override + public void setGroupInfoInteger(final String world, final String group, final String node, final int value) { + this.setGroupInfoValue(world, group, node, value); + } + + @Override + public double getPlayerInfoDouble(final String world, final String player, final String node, final double defaultValue) { + final String val = this.getPlayerInfoValue(world, player, node); + if (val == null || val.equals("")) { + return defaultValue; + } + try { + return Double.parseDouble(val); + } catch (final NumberFormatException e) { + return defaultValue; + } + } + + @Override + public void setPlayerInfoDouble(final String world, final String player, final String node, final double value) { + this.setPlayerInfoValue(world, player, node, value); + } + + @Override + public double getGroupInfoDouble(final String world, final String group, final String node, final double defaultValue) { + final String val = this.getGroupInfoValue(world, group, node); + if (val == null || val.equals("")) { + return defaultValue; + } + try { + return Double.parseDouble(val); + } catch (final NumberFormatException e) { + return defaultValue; + } + } + + @Override + public void setGroupInfoDouble(final String world, final String group, final String node, final double value) { + this.setGroupInfoValue(world, group, node, value); + } + + @Override + public boolean getPlayerInfoBoolean(final String world, final String player, final String node, final boolean defaultValue) { + final String val = this.getPlayerInfoValue(world, player, node); + if (val == null || val.equals("")) { + return defaultValue; + } + return Boolean.parseBoolean(val); + } + + @Override + public void setPlayerInfoBoolean(final String world, final String player, final String node, final boolean value) { + this.setPlayerInfoValue(world, player, node, value); + } + + @Override + public boolean getGroupInfoBoolean(final String world, final String group, final String node, final boolean defaultValue) { + final String val = this.getGroupInfoValue(world, group, node); + if (val == null || val.equals("")) { + return defaultValue; + } + return Boolean.parseBoolean(val); + } + + @Override + public void setGroupInfoBoolean(final String world, final String group, final String node, final boolean value) { + this.setGroupInfoValue(world, group, node, value); + } + + @Override + public String getPlayerInfoString(final String world, final String player, final String node, final String defaultValue) { + final String val = this.getPlayerInfoValue(world, player, node); + if (val == null) { + return defaultValue; + } else { + return val; + } + } + + @Override + public void setPlayerInfoString(final String world, final String player, final String node, final String value) { + this.setPlayerInfoValue(world, player, node, value); + } + + @Override + public String getGroupInfoString(final String world, final String group, final String node, final String defaultValue) { + final String val = this.getGroupInfoValue(world, group, node); + if (val == null) { + return defaultValue; + } else { + return val; + } + } + + @Override + public void setGroupInfoString(final String world, final String group, final String node, final String value) { + this.setGroupInfoValue(world, group, node, value); + } + + private void setPlayerInfoValue(final String world, final String player, final String node, final Object value) { + if (world != null) { + Writer.setWorldVar(player, InfoType.USER, world, node, value.toString()); + } else { + Writer.setInfoVar(player, InfoType.USER, node, value.toString()); + } + } + + private void setGroupInfoValue(final String world, final String group, final String node, final Object value) { + if (world != null) { + Writer.setWorldVar(group, InfoType.GROUP, world, node, value); + } else { + Writer.setInfoVar(group, InfoType.GROUP, node, value); + } + } + + private String getPlayerInfoValue(final String world, final String player, final String node) { + return Reader.getInfo(player, InfoType.USER, world, node); + } + + private String getGroupInfoValue(final String world, final String group, final String node) { + return Reader.getInfo(group, InfoType.GROUP, world, node); + } } diff --git a/src/net/milkbowl/vault/chat/plugins/Chat_rscPermissions.java b/src/net/milkbowl/vault/chat/plugins/Chat_rscPermissions.java index 4489d4d8..3738bd1b 100644 --- a/src/net/milkbowl/vault/chat/plugins/Chat_rscPermissions.java +++ b/src/net/milkbowl/vault/chat/plugins/Chat_rscPermissions.java @@ -15,11 +15,8 @@ */ package net.milkbowl.vault.chat.plugins; -import java.util.logging.Logger; - import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -27,189 +24,191 @@ import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; - import ru.simsonic.rscPermissions.MainPluginClass; -public class Chat_rscPermissions extends Chat { - - private final Logger log; - private final Plugin vault; - private ru.simsonic.rscPermissions.MainPluginClass rscp; - private ru.simsonic.rscPermissions.rscpAPI rscpAPI; - - public Chat_rscPermissions(Plugin plugin, Permission perm) { - super(perm); - this.vault = plugin; - this.log = plugin.getLogger(); - Bukkit.getServer().getPluginManager().registerEvents(new ChatServerListener(this), vault); - if (rscp == null) { - Plugin perms = plugin.getServer().getPluginManager().getPlugin("rscPermissions"); - if (perms != null && perms.isEnabled()) { - this.rscp = (MainPluginClass) perms; - rscpAPI = rscp.API; - plugin.getLogger().info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "rscPermissions")); - } - } - } - - private class ChatServerListener implements Listener { - - private final Chat_rscPermissions bridge; - public ChatServerListener(Chat_rscPermissions bridge) { - this.bridge = bridge; - } - - @EventHandler(priority = EventPriority.MONITOR) - private void onPluginEnable(PluginEnableEvent event) { - if(bridge.rscp == null) { - Plugin plugin = event.getPlugin(); - if (plugin.getDescription().getName().equals("rscPermissions")) { - bridge.rscp = (MainPluginClass) plugin; - bridge.rscpAPI = bridge.rscp.API; - log.info(String.format("[%s][Chat] %s hooked.", vault.getDescription().getName(), "rscPermissions")); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if(bridge.rscpAPI != null) { - if(event.getPlugin().getDescription().getName().equals(bridge.rscpAPI.getName())) { - bridge.rscpAPI = null; - bridge.rscp = null; - log.info(String.format("[%s][Chat] %s un-hooked.", vault.getDescription().getName(), "rscPermissions")); - } - } - } - } - - @Override - public String getName() { - return "rscPermissions"; - } - - @Override - public boolean isEnabled() { - return rscpAPI != null && rscpAPI.isEnabled(); - } - - @Override - public String getPlayerPrefix(String world, String player) { - return rscpAPI.getPlayerPrefix(world, player); - } - - @Override - public String getPlayerSuffix(String world, String player) { - return rscpAPI.getPlayerSuffix(world, player); - } - - @Override - public String getGroupPrefix(String world, String group) { - return rscpAPI.getGroupPrefix(world, group); - } - - @Override - public String getGroupSuffix(String world, String group) { - return rscpAPI.getGroupSuffix(world, group); - } - - @Override - public void setPlayerPrefix(String world, String player, String prefix) { - rscpAPI.setPlayerPrefix(world, player, prefix); - } - - @Override - public void setPlayerSuffix(String world, String player, String suffix) { - rscpAPI.setPlayerSuffix(world, player, suffix); - } - - @Override - public void setGroupPrefix(String world, String group, String prefix) { - rscpAPI.setGroupPrefix(world, group, prefix); - } - - @Override - public void setGroupSuffix(String world, String group, String suffix) { - rscpAPI.setGroupSuffix(world, group, suffix); - } - - @Override - public int getPlayerInfoInteger(String world, String player, String node, int defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } - - @Override - public void setPlayerInfoInteger(String world, String player, String node, int defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } - - @Override - public int getGroupInfoInteger(String world, String group, String node, int defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } - - @Override - public void setGroupInfoInteger(String world, String group, String node, int defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } - - @Override - public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } - - @Override - public void setPlayerInfoDouble(String world, String player, String node, double defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } - - @Override - public double getGroupInfoDouble(String world, String group, String node, double defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } - - @Override - public void setGroupInfoDouble(String world, String group, String node, double defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } - - @Override - public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } - - @Override - public void setPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } - - @Override - public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } - - @Override - public void setGroupInfoBoolean(String world, String group, String node, boolean defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } - - @Override - public String getPlayerInfoString(String world, String player, String node, String defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } - - @Override - public void setPlayerInfoString(String world, String player, String node, String defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } - - @Override - public String getGroupInfoString(String world, String group, String node, String defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } +import java.util.logging.Logger; - @Override - public void setGroupInfoString(String world, String group, String node, String defaultValue) { - throw new UnsupportedOperationException("rscPermissions does not support info nodes"); - } +public class Chat_rscPermissions extends Chat { + + private final Logger log; + private final Plugin vault; + private ru.simsonic.rscPermissions.MainPluginClass rscp; + private ru.simsonic.rscPermissions.rscpAPI rscpAPI; + + public Chat_rscPermissions(final Plugin plugin, final Permission perm) { + super(perm); + vault = plugin; + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new ChatServerListener(this), this.vault); + if (this.rscp == null) { + final Plugin perms = plugin.getServer().getPluginManager().getPlugin("rscPermissions"); + if (perms != null && perms.isEnabled()) { + rscp = (MainPluginClass) perms; + this.rscpAPI = this.rscp.API; + plugin.getLogger().info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "rscPermissions")); + } + } + } + + private class ChatServerListener implements Listener { + + private final Chat_rscPermissions bridge; + + public ChatServerListener(final Chat_rscPermissions bridge) { + this.bridge = bridge; + } + + @EventHandler(priority = EventPriority.MONITOR) + private void onPluginEnable(final PluginEnableEvent event) { + if (this.bridge.rscp == null) { + final Plugin plugin = event.getPlugin(); + if (plugin.getDescription().getName().equals("rscPermissions")) { + this.bridge.rscp = (MainPluginClass) plugin; + this.bridge.rscpAPI = this.bridge.rscp.API; + Chat_rscPermissions.this.log.info(String.format("[%s][Chat] %s hooked.", Chat_rscPermissions.this.vault.getDescription().getName(), "rscPermissions")); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.bridge.rscpAPI != null) { + if (event.getPlugin().getDescription().getName().equals(this.bridge.rscpAPI.getName())) { + this.bridge.rscpAPI = null; + this.bridge.rscp = null; + Chat_rscPermissions.this.log.info(String.format("[%s][Chat] %s un-hooked.", Chat_rscPermissions.this.vault.getDescription().getName(), "rscPermissions")); + } + } + } + } + + @Override + public String getName() { + return "rscPermissions"; + } + + @Override + public boolean isEnabled() { + return this.rscpAPI != null && this.rscpAPI.isEnabled(); + } + + @Override + public String getPlayerPrefix(final String world, final String player) { + return this.rscpAPI.getPlayerPrefix(world, player); + } + + @Override + public String getPlayerSuffix(final String world, final String player) { + return this.rscpAPI.getPlayerSuffix(world, player); + } + + @Override + public String getGroupPrefix(final String world, final String group) { + return this.rscpAPI.getGroupPrefix(world, group); + } + + @Override + public String getGroupSuffix(final String world, final String group) { + return this.rscpAPI.getGroupSuffix(world, group); + } + + @Override + public void setPlayerPrefix(final String world, final String player, final String prefix) { + this.rscpAPI.setPlayerPrefix(world, player, prefix); + } + + @Override + public void setPlayerSuffix(final String world, final String player, final String suffix) { + this.rscpAPI.setPlayerSuffix(world, player, suffix); + } + + @Override + public void setGroupPrefix(final String world, final String group, final String prefix) { + this.rscpAPI.setGroupPrefix(world, group, prefix); + } + + @Override + public void setGroupSuffix(final String world, final String group, final String suffix) { + this.rscpAPI.setGroupSuffix(world, group, suffix); + } + + @Override + public int getPlayerInfoInteger(final String world, final String player, final String node, final int defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } + + @Override + public void setPlayerInfoInteger(final String world, final String player, final String node, final int defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } + + @Override + public int getGroupInfoInteger(final String world, final String group, final String node, final int defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } + + @Override + public void setGroupInfoInteger(final String world, final String group, final String node, final int defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } + + @Override + public double getPlayerInfoDouble(final String world, final String player, final String node, final double defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } + + @Override + public void setPlayerInfoDouble(final String world, final String player, final String node, final double defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } + + @Override + public double getGroupInfoDouble(final String world, final String group, final String node, final double defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } + + @Override + public void setGroupInfoDouble(final String world, final String group, final String node, final double defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } + + @Override + public boolean getPlayerInfoBoolean(final String world, final String player, final String node, final boolean defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } + + @Override + public void setPlayerInfoBoolean(final String world, final String player, final String node, final boolean defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } + + @Override + public boolean getGroupInfoBoolean(final String world, final String group, final String node, final boolean defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } + + @Override + public void setGroupInfoBoolean(final String world, final String group, final String node, final boolean defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } + + @Override + public String getPlayerInfoString(final String world, final String player, final String node, final String defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } + + @Override + public void setPlayerInfoString(final String world, final String player, final String node, final String defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } + + @Override + public String getGroupInfoString(final String world, final String group, final String node, final String defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } + + @Override + public void setGroupInfoString(final String world, final String group, final String node, final String defaultValue) { + throw new UnsupportedOperationException("rscPermissions does not support info nodes"); + } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_CommandsEX.java b/src/net/milkbowl/vault/economy/plugins/Economy_CommandsEX.java index bc4d6c51..d5e78ab3 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_CommandsEX.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_CommandsEX.java @@ -1,9 +1,9 @@ package net.milkbowl.vault.economy.plugins; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; - +import com.github.zathrus_writer.commandsex.CommandsEX; +import com.github.zathrus_writer.commandsex.api.economy.Economy; +import net.milkbowl.vault.economy.AbstractEconomy; +import net.milkbowl.vault.economy.EconomyResponse; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -12,223 +12,218 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import com.github.zathrus_writer.commandsex.CommandsEX; -import com.github.zathrus_writer.commandsex.api.economy.Economy; - -import net.milkbowl.vault.economy.AbstractEconomy; -import net.milkbowl.vault.economy.EconomyResponse; -import net.milkbowl.vault.economy.EconomyResponse.ResponseType; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; public class Economy_CommandsEX extends AbstractEconomy { private final Logger log; private final String name = "CommandsEX Economy"; - private Plugin plugin = null; - private CommandsEX economy = null; - - public Economy_CommandsEX(Plugin plugin){ - this.plugin = plugin; - this.log = plugin.getLogger(); + private CommandsEX economy; + + public Economy_CommandsEX(final Plugin plugin) { + log = plugin.getLogger(); Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - if (economy == null) { - Plugin commandsex = plugin.getServer().getPluginManager().getPlugin("CommandsEX"); - - if (commandsex != null && commandsex.isEnabled()) { - economy = (CommandsEX) commandsex; - log.info(String.format("[Economy] %s hooked.", name)); - } - } + if (this.economy == null) { + final Plugin commandsex = plugin.getServer().getPluginManager().getPlugin("CommandsEX"); + + if (commandsex != null && commandsex.isEnabled()) { + this.economy = (CommandsEX) commandsex; + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } } public class EconomyServerListener implements Listener { - Economy_CommandsEX economy = null; - - public EconomyServerListener(Economy_CommandsEX economy) { - this.economy = economy; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (economy.economy == null) { - Plugin cex = event.getPlugin(); - - if (cex.getDescription().getName().equals("CommandsEX")) { - economy.economy = (CommandsEX) cex; - log.info(String.format("[Economy] %s hooked.", economy.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (economy.economy != null) { - if (event.getPlugin().getDescription().getName().equals("CommandsEX")) { - economy.economy = null; - log.info(String.format("[Economy] %s unhooked.", economy.name)); - } - } - } - } + final Economy_CommandsEX economy; + + public EconomyServerListener(final Economy_CommandsEX economy) { + this.economy = economy; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.economy.economy == null) { + final Plugin cex = event.getPlugin(); + + if (cex.getDescription().getName().equals("CommandsEX")) { + this.economy.economy = (CommandsEX) cex; + Economy_CommandsEX.this.log.info(String.format("[Economy] %s hooked.", this.economy.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.economy.economy != null) { + if (event.getPlugin().getDescription().getName().equals("CommandsEX")) { + this.economy.economy = null; + Economy_CommandsEX.this.log.info(String.format("[Economy] %s unhooked.", this.economy.name)); + } + } + } + } @Override public boolean isEnabled() { - if (economy == null){ + if (this.economy == null) { return false; } else { return Economy.isEnabled(); } } - + @Override public String getName() { - return name; + return this.name; } - + @Override public boolean hasBankSupport() { return false; } - + @Override public int fractionalDigits() { return 2; } - + @Override - public String format(double amount) { + public String format(final double amount) { return Economy.getCurrencySymbol() + amount; } - + @Override public String currencyNamePlural() { return Economy.getCurrencyPlural(); } - + @Override public String currencyNameSingular() { return Economy.getCurrencySingular(); } - + @Override - public boolean hasAccount(String playerName) { + public boolean hasAccount(final String playerName) { return Economy.hasAccount(playerName); } - + @Override - public double getBalance(String playerName) { + public double getBalance(final String playerName) { return Economy.getBalance(playerName); } - + @Override - public boolean has(String playerName, double amount) { + public boolean has(final String playerName, final double amount) { return Economy.has(playerName, amount); } - + @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - ResponseType rt; - String message; + public EconomyResponse withdrawPlayer(final String playerName, final double amount) { + final EconomyResponse.ResponseType rt; + final String message; - if (Economy.has(playerName, amount)){ + if (Economy.has(playerName, amount)) { Economy.withdraw(playerName, amount); - rt = ResponseType.SUCCESS; + rt = EconomyResponse.ResponseType.SUCCESS; message = null; } else { - rt = ResponseType.FAILURE; + rt = EconomyResponse.ResponseType.FAILURE; message = "Not enough money"; } return new EconomyResponse(amount, Economy.getBalance(playerName), rt, message); } - + @Override - public EconomyResponse depositPlayer(String playerName, double amount) { + public EconomyResponse depositPlayer(final String playerName, final double amount) { Economy.deposit(playerName, amount); - return new EconomyResponse(amount, Economy.getBalance(playerName), ResponseType.SUCCESS, "Successfully deposited"); + return new EconomyResponse(amount, Economy.getBalance(playerName), EconomyResponse.ResponseType.SUCCESS, "Successfully deposited"); } - + @Override - public EconomyResponse createBank(String name, String player) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); + public EconomyResponse createBank(final String name, final String player) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); } - + @Override - public EconomyResponse deleteBank(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); + public EconomyResponse deleteBank(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); } - + @Override - public EconomyResponse bankBalance(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); + public EconomyResponse bankBalance(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); } - + @Override - public EconomyResponse bankHas(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); + public EconomyResponse bankHas(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); } - + @Override - public EconomyResponse bankWithdraw(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); + public EconomyResponse bankWithdraw(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); } - + @Override - public EconomyResponse bankDeposit(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); + public EconomyResponse bankDeposit(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); } - + @Override - public EconomyResponse isBankOwner(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); + public EconomyResponse isBankOwner(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); } - + @Override - public EconomyResponse isBankMember(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); + public EconomyResponse isBankMember(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "CommandsEX Economy does not support bank accounts"); } - + @Override public List getBanks() { - return new ArrayList(); + return new ArrayList<>(); } - + @Override - public boolean createPlayerAccount(String playerName) { - if (Economy.hasAccount(playerName)){ + public boolean createPlayerAccount(final String playerName) { + if (Economy.hasAccount(playerName)) { return false; } else { Economy.createAccount(playerName); return true; } } - - @Override - public boolean hasAccount(String playerName, String worldName) { - return hasAccount(playerName); - } - - @Override - public double getBalance(String playerName, String world) { - return getBalance(playerName); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - return depositPlayer(playerName, amount); - } - - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return createPlayerAccount(playerName); - } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return this.hasAccount(playerName); + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + return this.createPlayerAccount(playerName); + } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_Craftconomy3.java b/src/net/milkbowl/vault/economy/plugins/Economy_Craftconomy3.java index 8a3acc77..cc6e2db3 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_Craftconomy3.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_Craftconomy3.java @@ -15,13 +15,13 @@ */ package net.milkbowl.vault.economy.plugins; -import java.util.List; -import java.util.logging.Logger; - +import com.greatmancode.craftconomy3.Cause; +import com.greatmancode.craftconomy3.Common; +import com.greatmancode.craftconomy3.account.Account; +import com.greatmancode.craftconomy3.groups.WorldGroupsManager; +import com.greatmancode.craftconomy3.tools.interfaces.BukkitLoader; import net.milkbowl.vault.economy.AbstractEconomy; import net.milkbowl.vault.economy.EconomyResponse; -import net.milkbowl.vault.economy.EconomyResponse.ResponseType; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -30,290 +30,285 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import com.greatmancode.craftconomy3.Cause; -import com.greatmancode.craftconomy3.Common; -import com.greatmancode.craftconomy3.account.Account; -import com.greatmancode.craftconomy3.groups.WorldGroupsManager; -import com.greatmancode.craftconomy3.tools.interfaces.BukkitLoader; +import java.util.List; +import java.util.logging.Logger; public class Economy_Craftconomy3 extends AbstractEconomy { private final Logger log; private final String name = "Craftconomy3"; - private Plugin plugin = null; - protected BukkitLoader economy = null; - - public Economy_Craftconomy3(Plugin plugin) { - this.plugin = plugin; - this.log = plugin.getLogger(); + protected BukkitLoader economy; + + public Economy_Craftconomy3(final Plugin plugin) { + log = plugin.getLogger(); Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - + // Load Plugin in case it was loaded before - if (economy == null) { - Plugin ec = plugin.getServer().getPluginManager().getPlugin("Craftconomy3"); + if (this.economy == null) { + final Plugin ec = plugin.getServer().getPluginManager().getPlugin("Craftconomy3"); if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.greatmancode.craftconomy3.BukkitLoader")) { - economy = (BukkitLoader) ec; - log.info(String.format("[Economy] %s hooked.", name)); + this.economy = (BukkitLoader) ec; + this.log.info(String.format("[Economy] %s hooked.", this.name)); } } } - + public class EconomyServerListener implements Listener { - Economy_Craftconomy3 economy = null; - - public EconomyServerListener(Economy_Craftconomy3 economy) { + final Economy_Craftconomy3 economy; + + public EconomyServerListener(final Economy_Craftconomy3 economy) { this.economy = economy; } - + @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (economy.economy == null) { - Plugin ec = event.getPlugin(); - + public void onPluginEnable(final PluginEnableEvent event) { + if (this.economy.economy == null) { + final Plugin ec = event.getPlugin(); + if (ec.getDescription().getName().equals("Craftconomy3") && ec.getClass().getName().equals("com.greatmancode.craftconomy3.tools.interfaces.BukkitLoader")) { - economy.economy = (BukkitLoader) ec; - log.info(String.format("[Economy] %s hooked.", economy.name)); + this.economy.economy = (BukkitLoader) ec; + Economy_Craftconomy3.this.log.info(String.format("[Economy] %s hooked.", this.economy.name)); } } } - + @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (economy.economy != null) { + public void onPluginDisable(final PluginDisableEvent event) { + if (this.economy.economy != null) { if (event.getPlugin().getDescription().getName().equals("Craftconomy3")) { - economy.economy = null; - log.info(String.format("[Economy] %s unhooked.", economy.name)); + this.economy.economy = null; + Economy_Craftconomy3.this.log.info(String.format("[Economy] %s unhooked.", this.economy.name)); } } } } - + @Override public boolean isEnabled() { - if (economy == null) { + if (this.economy == null) { return false; } else { - return economy.isEnabled(); + return this.economy.isEnabled(); } } - + @Override public String getName() { - return name; + return this.name; } - + @Override - public String format(double amount) { + public String format(final double amount) { return Common.getInstance().format(null, Common.getInstance().getCurrencyManager().getDefaultCurrency(), amount); } - + @Override public String currencyNameSingular() { return Common.getInstance().getCurrencyManager().getDefaultCurrency().getName(); } - + @Override public String currencyNamePlural() { return Common.getInstance().getCurrencyManager().getDefaultCurrency().getPlural(); } - + @Override - public double getBalance(String playerName) { - return getBalance(playerName, WorldGroupsManager.DEFAULT_GROUP_NAME); + public double getBalance(final String playerName) { + return this.getBalance(playerName, WorldGroupsManager.DEFAULT_GROUP_NAME); } - + @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - return withdrawPlayer(playerName, WorldGroupsManager.DEFAULT_GROUP_NAME, amount); + public EconomyResponse withdrawPlayer(final String playerName, final double amount) { + return this.withdrawPlayer(playerName, WorldGroupsManager.DEFAULT_GROUP_NAME, amount); } - + @Override - public EconomyResponse depositPlayer(String playerName, double amount) { - return depositPlayer(playerName, WorldGroupsManager.DEFAULT_GROUP_NAME, amount); + public EconomyResponse depositPlayer(final String playerName, final double amount) { + return this.depositPlayer(playerName, WorldGroupsManager.DEFAULT_GROUP_NAME, amount); } - + @Override - public boolean has(String playerName, double amount) { - return has(playerName, WorldGroupsManager.DEFAULT_GROUP_NAME, amount); + public boolean has(final String playerName, final double amount) { + return this.has(playerName, WorldGroupsManager.DEFAULT_GROUP_NAME, amount); } - + @Override - public EconomyResponse createBank(String name, String player) { + public EconomyResponse createBank(final String name, final String player) { boolean success = false; if (!Common.getInstance().getAccountManager().exist(name, true)) { - Common.getInstance().getAccountManager().getAccount(name,true).getAccountACL().set(player, true, true, true, true, true); + Common.getInstance().getAccountManager().getAccount(name, true).getAccountACL().set(player, true, true, true, true, true); success = true; } if (success) { - return new EconomyResponse(0, 0, ResponseType.SUCCESS, ""); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, ""); } - - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Unable to create that bank account. It already exists!"); + + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Unable to create that bank account. It already exists!"); } - + @Override - public EconomyResponse deleteBank(String name) { - boolean success = Common.getInstance().getAccountManager().delete(name, true); + public EconomyResponse deleteBank(final String name) { + final boolean success = Common.getInstance().getAccountManager().delete(name, true); if (success) { - return new EconomyResponse(0, 0, ResponseType.SUCCESS, ""); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, ""); } - - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Unable to delete that bank account."); + + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Unable to delete that bank account."); } - + @Override - public EconomyResponse bankHas(String name, double amount) { - + public EconomyResponse bankHas(final String name, final double amount) { + if (Common.getInstance().getAccountManager().exist(name, true)) { - Account account = Common.getInstance().getAccountManager().getAccount(name, true); + final Account account = Common.getInstance().getAccountManager().getAccount(name, true); if (account.hasEnough(amount, Common.getInstance().getServerCaller().getDefaultWorld(), Common.getInstance().getCurrencyManager().getDefaultCurrency().getName())) { - return new EconomyResponse(0, bankBalance(name).balance, ResponseType.SUCCESS, ""); + return new EconomyResponse(0, this.bankBalance(name).balance, EconomyResponse.ResponseType.SUCCESS, ""); } else { - return new EconomyResponse(0, bankBalance(name).balance, ResponseType.FAILURE, "The bank does not have enough money!"); + return new EconomyResponse(0, this.bankBalance(name).balance, EconomyResponse.ResponseType.FAILURE, "The bank does not have enough money!"); } } - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That bank does not exist!"); } - + @Override - public EconomyResponse bankWithdraw(String name, double amount) { + public EconomyResponse bankWithdraw(final String name, final double amount) { if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds"); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot withdraw negative funds"); } - - EconomyResponse er = bankHas(name, amount); + + final EconomyResponse er = this.bankHas(name, amount); if (!er.transactionSuccess()) { return er; } else { if (Common.getInstance().getAccountManager().exist(name, true)) { - return new EconomyResponse(0, Common.getInstance().getAccountManager().getAccount(name, true).withdraw(amount,WorldGroupsManager.DEFAULT_GROUP_NAME, Common.getInstance().getCurrencyManager().getDefaultBankCurrency().getName(), Cause.VAULT, null), ResponseType.SUCCESS, ""); + return new EconomyResponse(0, Common.getInstance().getAccountManager().getAccount(name, true).withdraw(amount, WorldGroupsManager.DEFAULT_GROUP_NAME, Common.getInstance().getCurrencyManager().getDefaultBankCurrency().getName(), Cause.VAULT, null), EconomyResponse.ResponseType.SUCCESS, ""); } - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That bank does not exist!"); } } - + @Override - public EconomyResponse bankDeposit(String name, double amount) { + public EconomyResponse bankDeposit(final String name, final double amount) { if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds"); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot desposit negative funds"); } - + if (Common.getInstance().getAccountManager().exist(name, true)) { - return new EconomyResponse(0, Common.getInstance().getAccountManager().getAccount(name, true).deposit(amount,WorldGroupsManager.DEFAULT_GROUP_NAME, Common.getInstance().getCurrencyManager().getDefaultBankCurrency().getName(), Cause.VAULT, null), ResponseType.SUCCESS, ""); + return new EconomyResponse(0, Common.getInstance().getAccountManager().getAccount(name, true).deposit(amount, WorldGroupsManager.DEFAULT_GROUP_NAME, Common.getInstance().getCurrencyManager().getDefaultBankCurrency().getName(), Cause.VAULT, null), EconomyResponse.ResponseType.SUCCESS, ""); } - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That bank does not exist!"); } - + @Override - public EconomyResponse isBankOwner(String name, String playerName) { + public EconomyResponse isBankOwner(final String name, final String playerName) { if (Common.getInstance().getAccountManager().exist(name, true)) { if (Common.getInstance().getAccountManager().getAccount(name, true).getAccountACL().isOwner(playerName)) { - return new EconomyResponse(0, bankBalance(name).balance, ResponseType.SUCCESS, ""); + return new EconomyResponse(0, this.bankBalance(name).balance, EconomyResponse.ResponseType.SUCCESS, ""); } - return new EconomyResponse(0, 0, ResponseType.FAILURE, "This player is not the owner of the bank!"); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "This player is not the owner of the bank!"); } - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That bank does not exist!"); } - + @Override - public EconomyResponse isBankMember(String name, String playerName) { - + public EconomyResponse isBankMember(final String name, final String playerName) { + // Basicly here if the user have access to deposit & withdraw he's a member - EconomyResponse er = isBankOwner(name, playerName); + final EconomyResponse er = this.isBankOwner(name, playerName); if (er.transactionSuccess()) { return er; } else { if (Common.getInstance().getAccountManager().exist(name, true)) { - Account account = Common.getInstance().getAccountManager().getAccount(name, true); + final Account account = Common.getInstance().getAccountManager().getAccount(name, true); if (account.getAccountACL().canDeposit(playerName) && account.getAccountACL().canWithdraw(playerName)) { - return new EconomyResponse(0, bankBalance(name).balance, ResponseType.SUCCESS, ""); + return new EconomyResponse(0, this.bankBalance(name).balance, EconomyResponse.ResponseType.SUCCESS, ""); } } - return new EconomyResponse(0, 0, ResponseType.FAILURE, "This player is not a member of the bank!"); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "This player is not a member of the bank!"); } } - + @Override - public EconomyResponse bankBalance(String name) { + public EconomyResponse bankBalance(final String name) { if (Common.getInstance().getAccountManager().exist(name, true)) { - return new EconomyResponse(0, Common.getInstance().getAccountManager().getAccount(name, true).getBalance(WorldGroupsManager.DEFAULT_GROUP_NAME, Common.getInstance().getCurrencyManager().getDefaultBankCurrency().getName()), ResponseType.SUCCESS, ""); + return new EconomyResponse(0, Common.getInstance().getAccountManager().getAccount(name, true).getBalance(WorldGroupsManager.DEFAULT_GROUP_NAME, Common.getInstance().getCurrencyManager().getDefaultBankCurrency().getName()), EconomyResponse.ResponseType.SUCCESS, ""); } - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That bank does not exist!"); } - + @Override public List getBanks() { return Common.getInstance().getAccountManager().getAllAccounts(true); } - + @Override public boolean hasBankSupport() { return true; } - + @Override - public boolean hasAccount(String playerName) { + public boolean hasAccount(final String playerName) { return Common.getInstance().getAccountManager().exist(playerName, false); } - + @Override - public boolean createPlayerAccount(String playerName) { + public boolean createPlayerAccount(final String playerName) { if (Common.getInstance().getAccountManager().exist(playerName, false)) { return false; } Common.getInstance().getAccountManager().getAccount(playerName, false); return true; } - + @Override public int fractionalDigits() { return -1; } - + @Override - public boolean hasAccount(String playerName, String worldName) { - return hasAccount(playerName); + public boolean hasAccount(final String playerName, final String worldName) { + return this.hasAccount(playerName); } - + @Override - public double getBalance(String playerName, String world) { + public double getBalance(final String playerName, final String world) { return Common.getInstance().getAccountManager().getAccount(playerName, false).getBalance(world, Common.getInstance().getCurrencyManager().getDefaultCurrency().getName()); } - + @Override - public boolean has(String playerName, String worldName, double amount) { + public boolean has(final String playerName, final String worldName, final double amount) { return Common.getInstance().getAccountManager().getAccount(playerName, false).hasEnough(amount, worldName, Common.getInstance().getCurrencyManager().getDefaultCurrency().getName()); } - + @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { if (amount < 0) { - return new EconomyResponse(0, getBalance(playerName, worldName), ResponseType.FAILURE, "Cannot withdraw negative funds"); + return new EconomyResponse(0, this.getBalance(playerName, worldName), EconomyResponse.ResponseType.FAILURE, "Cannot withdraw negative funds"); } - - double balance; - Account account = Common.getInstance().getAccountManager().getAccount(playerName, false); + + final double balance; + final Account account = Common.getInstance().getAccountManager().getAccount(playerName, false); if (account.hasEnough(amount, worldName, Common.getInstance().getCurrencyManager().getDefaultCurrency().getName())) { balance = account.withdraw(amount, worldName, Common.getInstance().getCurrencyManager().getDefaultCurrency().getName(), Cause.VAULT, null); - return new EconomyResponse(amount, balance, ResponseType.SUCCESS, ""); + return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.SUCCESS, ""); } else { - return new EconomyResponse(0, getBalance(playerName, worldName), ResponseType.FAILURE, "Insufficient funds"); + return new EconomyResponse(0, this.getBalance(playerName, worldName), EconomyResponse.ResponseType.FAILURE, "Insufficient funds"); } } - + @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { if (amount < 0) { - return new EconomyResponse(0, getBalance(playerName, worldName), ResponseType.FAILURE, "Cannot desposit negative funds"); + return new EconomyResponse(0, this.getBalance(playerName, worldName), EconomyResponse.ResponseType.FAILURE, "Cannot desposit negative funds"); } - - Account account = Common.getInstance().getAccountManager().getAccount(playerName, false); - - double balance = account.deposit(amount, worldName, Common.getInstance().getCurrencyManager().getDefaultCurrency().getName(), Cause.VAULT, null); - return new EconomyResponse(amount, balance, ResponseType.SUCCESS, null); + + final Account account = Common.getInstance().getAccountManager().getAccount(playerName, false); + + final double balance = account.deposit(amount, worldName, Common.getInstance().getCurrencyManager().getDefaultCurrency().getName(), Cause.VAULT, null); + return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.SUCCESS, null); } - + @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return createPlayerAccount(playerName); + public boolean createPlayerAccount(final String playerName, final String worldName) { + return this.createPlayerAccount(playerName); } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_CurrencyCore.java b/src/net/milkbowl/vault/economy/plugins/Economy_CurrencyCore.java index 698b3e38..3169083c 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_CurrencyCore.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_CurrencyCore.java @@ -17,14 +17,8 @@ import is.currency.Currency; import is.currency.syst.AccountContext; - -import java.util.List; -import java.util.logging.Logger; - import net.milkbowl.vault.economy.AbstractEconomy; import net.milkbowl.vault.economy.EconomyResponse; -import net.milkbowl.vault.economy.EconomyResponse.ResponseType; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -33,273 +27,274 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -public class Economy_CurrencyCore extends AbstractEconomy { - - private Currency currency; - private final Logger log; - private final Plugin plugin; - private final String name = "CurrencyCore"; - - public Economy_CurrencyCore(Plugin plugin) { - this.plugin = plugin; - this.log = plugin.getLogger(); - Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - - // Load Plugin in case it was loaded before - if(currency == null) { - Plugin currencyPlugin = plugin.getServer().getPluginManager().getPlugin("CurrencyCore"); - if(currencyPlugin != null && currencyPlugin.getClass().getName().equals("is.currency.Currency")) { - this.currency = (Currency) currencyPlugin; - log.info(String.format("[Economy] %s hooked.", name)); - } - } - } - - public class EconomyServerListener implements Listener { - - private Economy_CurrencyCore economy = null; - - public EconomyServerListener(Economy_CurrencyCore economy) { - this.economy = economy; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if(this.economy.currency == null) { - Plugin currencyPlugin = event.getPlugin(); - - if(currencyPlugin.getDescription().getName().equals("CurrencyCore") && currencyPlugin.getClass().getName().equals("is.currency.Currency")) { - this.economy.currency = (Currency) currencyPlugin; - log.info(String.format("[Economy] %s hooked.", this.economy.getName())); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (this.economy.currency != null) { - if (event.getPlugin().getDescription().getName().equals("CurrencyCore")) { - this.economy.currency = null; - log.info(String.format("[Economy] %s unhooked.", this.economy.getName())); - } - } - } - } - - @Override - public boolean isEnabled() { - return currency != null; - } - - @Override - public String getName() { - return name; - } - - @Override - public String format(double amount) { - return this.currency.getFormatHelper().format(amount); - } - - @Override - public String currencyNamePlural() { - return currency.getCurrencyConfig().getCurrencyMajor().get(1); - } - - @Override - public String currencyNameSingular() { - return currency.getCurrencyConfig().getCurrencyMajor().get(0); - } - - @Override - public double getBalance(String playerName) { - AccountContext account = this.currency.getAccountManager().getAccount(playerName); - if (account == null) { - return 0.0; - } - - return account.getBalance(); - } - - @Override - public boolean has(String playerName, double amount) { - AccountContext account = this.currency.getAccountManager().getAccount(playerName); - if (account == null) { - return false; - } else { - return account.hasBalance(amount); - } - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds"); - } - - AccountContext account = this.currency.getAccountManager().getAccount(playerName); - if (account == null) { - return new EconomyResponse(0.0, 0.0, ResponseType.FAILURE, "That account does not exist"); - } else if (!account.hasBalance(amount)) { - return new EconomyResponse(0.0, account.getBalance(), ResponseType.FAILURE, "Insufficient funds"); - } else { - account.subtractBalance(amount); - return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, ""); - } - } - - @Override - public EconomyResponse depositPlayer(String playerName, double amount) { - if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds"); - } - - AccountContext account = this.currency.getAccountManager().getAccount(playerName); - if (account == null) { - return new EconomyResponse(0.0, 0.0, ResponseType.FAILURE, "That account does not exist"); - } - account.addBalance(amount); - return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, ""); - } - - @Override - public EconomyResponse createBank(String name, String player) { - if (this.currency.getAccountManager().hasAccount(name)) { - return new EconomyResponse(0, currency.getAccountManager().getAccount(name).getBalance(), ResponseType.FAILURE, "That account already exists."); - } - this.currency.getAccountManager().createAccount(name); - return new EconomyResponse(0, 0, ResponseType.SUCCESS, ""); - } - - @Override - public EconomyResponse deleteBank(String name) { - if (this.currency.getAccountManager().hasAccount(name)) { - this.currency.getAccountManager().deleteAccount(name); - return new EconomyResponse(0, 0, ResponseType.SUCCESS, ""); - } - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exist!"); - } - - @Override - public EconomyResponse bankBalance(String name) { - AccountContext account = this.currency.getAccountManager().getAccount(name); - - if (account == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exists."); - } - return new EconomyResponse(0, account.getBalance(), ResponseType.SUCCESS, ""); - } - - @Override - public EconomyResponse bankHas(String name, double amount) { - AccountContext account = this.currency.getAccountManager().getAccount(name); - if (account == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exist!"); - } else if (!account.hasBalance(amount)) { - return new EconomyResponse(0, account.getBalance(), ResponseType.FAILURE, "That account does not have enough!"); - } else { - return new EconomyResponse(0, account.getBalance(), ResponseType.SUCCESS, ""); - } - } - - @Override - public EconomyResponse bankWithdraw(String name, double amount) { - if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds"); - } - - AccountContext account = this.currency.getAccountManager().getAccount(name); - if (account == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exist!"); - } else if (!account.hasBalance(amount)) { - return new EconomyResponse(0, account.getBalance(), ResponseType.FAILURE, "That account does not have enough!"); - } else { - account.subtractBalance(amount); - return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, ""); - } - } - - @Override - public EconomyResponse bankDeposit(String name, double amount) { - if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds"); - } - - AccountContext account = this.currency.getAccountManager().getAccount(name); - if (account == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That account does not exist!"); - } else { - account.addBalance(amount); - return new EconomyResponse(amount, account.getBalance(), ResponseType.SUCCESS, ""); - } - } - - @Override - public EconomyResponse isBankOwner(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Currency does not support Bank members."); - } - - @Override - public EconomyResponse isBankMember(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Currency does not support Bank members."); - } - - @Override - public List getBanks() { - return this.currency.getAccountManager().getAccountList(); - } - - @Override - public boolean hasBankSupport() { - return true; - } - - @Override - public boolean hasAccount(String playerName) { - return this.currency.getAccountManager().getAccount(playerName) != null; - } - - @Override - public boolean createPlayerAccount(String playerName) { - if (this.currency.getAccountManager().getAccount(playerName) != null) { - return false; - } - this.currency.getAccountManager().createAccount(playerName); - return true; - } +import java.util.List; +import java.util.logging.Logger; +public class Economy_CurrencyCore extends AbstractEconomy { + + private Currency currency; + private final Logger log; + private final String name = "CurrencyCore"; + + public Economy_CurrencyCore(final Plugin plugin) { + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + + // Load Plugin in case it was loaded before + if (this.currency == null) { + final Plugin currencyPlugin = plugin.getServer().getPluginManager().getPlugin("CurrencyCore"); + if (currencyPlugin != null && currencyPlugin.getClass().getName().equals("is.currency.Currency")) { + currency = (Currency) currencyPlugin; + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } + } + + public class EconomyServerListener implements Listener { + + private final Economy_CurrencyCore economy; + + public EconomyServerListener(final Economy_CurrencyCore economy) { + this.economy = economy; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (economy.currency == null) { + final Plugin currencyPlugin = event.getPlugin(); + + if (currencyPlugin.getDescription().getName().equals("CurrencyCore") && currencyPlugin.getClass().getName().equals("is.currency.Currency")) { + economy.currency = (Currency) currencyPlugin; + Economy_CurrencyCore.this.log.info(String.format("[Economy] %s hooked.", economy.getName())); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (economy.currency != null) { + if (event.getPlugin().getDescription().getName().equals("CurrencyCore")) { + economy.currency = null; + Economy_CurrencyCore.this.log.info(String.format("[Economy] %s unhooked.", economy.getName())); + } + } + } + } + + @Override + public boolean isEnabled() { + return this.currency != null; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public String format(final double amount) { + return currency.getFormatHelper().format(amount); + } + + @Override + public String currencyNamePlural() { + return this.currency.getCurrencyConfig().getCurrencyMajor().get(1); + } + + @Override + public String currencyNameSingular() { + return this.currency.getCurrencyConfig().getCurrencyMajor().get(0); + } + + @Override + public double getBalance(final String playerName) { + final AccountContext account = currency.getAccountManager().getAccount(playerName); + if (account == null) { + return 0.0; + } + + return account.getBalance(); + } + + @Override + public boolean has(final String playerName, final double amount) { + final AccountContext account = currency.getAccountManager().getAccount(playerName); + if (account == null) { + return false; + } else { + return account.hasBalance(amount); + } + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final double amount) { + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot withdraw negative funds"); + } + + final AccountContext account = currency.getAccountManager().getAccount(playerName); + if (account == null) { + return new EconomyResponse(0.0, 0.0, EconomyResponse.ResponseType.FAILURE, "That account does not exist"); + } else if (!account.hasBalance(amount)) { + return new EconomyResponse(0.0, account.getBalance(), EconomyResponse.ResponseType.FAILURE, "Insufficient funds"); + } else { + account.subtractBalance(amount); + return new EconomyResponse(amount, account.getBalance(), EconomyResponse.ResponseType.SUCCESS, ""); + } + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final double amount) { + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot desposit negative funds"); + } + + final AccountContext account = currency.getAccountManager().getAccount(playerName); + if (account == null) { + return new EconomyResponse(0.0, 0.0, EconomyResponse.ResponseType.FAILURE, "That account does not exist"); + } + account.addBalance(amount); + return new EconomyResponse(amount, account.getBalance(), EconomyResponse.ResponseType.SUCCESS, ""); + } + + @Override + public EconomyResponse createBank(final String name, final String player) { + if (currency.getAccountManager().hasAccount(name)) { + return new EconomyResponse(0, this.currency.getAccountManager().getAccount(name).getBalance(), EconomyResponse.ResponseType.FAILURE, "That account already exists."); + } + currency.getAccountManager().createAccount(name); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, ""); + } + + @Override + public EconomyResponse deleteBank(final String name) { + if (currency.getAccountManager().hasAccount(name)) { + currency.getAccountManager().deleteAccount(name); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, ""); + } + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That account does not exist!"); + } + + @Override + public EconomyResponse bankBalance(final String name) { + final AccountContext account = currency.getAccountManager().getAccount(name); + + if (account == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That account does not exists."); + } + return new EconomyResponse(0, account.getBalance(), EconomyResponse.ResponseType.SUCCESS, ""); + } + + @Override + public EconomyResponse bankHas(final String name, final double amount) { + final AccountContext account = currency.getAccountManager().getAccount(name); + if (account == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That account does not exist!"); + } else if (!account.hasBalance(amount)) { + return new EconomyResponse(0, account.getBalance(), EconomyResponse.ResponseType.FAILURE, "That account does not have enough!"); + } else { + return new EconomyResponse(0, account.getBalance(), EconomyResponse.ResponseType.SUCCESS, ""); + } + } + + @Override + public EconomyResponse bankWithdraw(final String name, final double amount) { + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot withdraw negative funds"); + } + + final AccountContext account = currency.getAccountManager().getAccount(name); + if (account == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That account does not exist!"); + } else if (!account.hasBalance(amount)) { + return new EconomyResponse(0, account.getBalance(), EconomyResponse.ResponseType.FAILURE, "That account does not have enough!"); + } else { + account.subtractBalance(amount); + return new EconomyResponse(amount, account.getBalance(), EconomyResponse.ResponseType.SUCCESS, ""); + } + } + + @Override + public EconomyResponse bankDeposit(final String name, final double amount) { + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot desposit negative funds"); + } + + final AccountContext account = currency.getAccountManager().getAccount(name); + if (account == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That account does not exist!"); + } else { + account.addBalance(amount); + return new EconomyResponse(amount, account.getBalance(), EconomyResponse.ResponseType.SUCCESS, ""); + } + } + + @Override + public EconomyResponse isBankOwner(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Currency does not support Bank members."); + } + + @Override + public EconomyResponse isBankMember(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Currency does not support Bank members."); + } + + @Override + public List getBanks() { + return currency.getAccountManager().getAccountList(); + } + + @Override + public boolean hasBankSupport() { + return true; + } + + @Override + public boolean hasAccount(final String playerName) { + return currency.getAccountManager().getAccount(playerName) != null; + } + + @Override + public boolean createPlayerAccount(final String playerName) { + if (currency.getAccountManager().getAccount(playerName) != null) { + return false; + } + currency.getAccountManager().createAccount(playerName); + return true; + } + @Override public int fractionalDigits() { return -1; } - - @Override - public boolean hasAccount(String playerName, String worldName) { - return hasAccount(playerName); - } - - @Override - public double getBalance(String playerName, String world) { - return getBalance(playerName); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - return depositPlayer(playerName, amount); - } - - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return createPlayerAccount(playerName); - } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return this.hasAccount(playerName); + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + return this.createPlayerAccount(playerName); + } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_DigiCoin.java b/src/net/milkbowl/vault/economy/plugins/Economy_DigiCoin.java index b4ee9794..b6ceb267 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_DigiCoin.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_DigiCoin.java @@ -15,10 +15,9 @@ */ package net.milkbowl.vault.economy.plugins; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; - +import co.uk.silvania.cities.digicoin.DigiCoin; +import net.milkbowl.vault.economy.AbstractEconomy; +import net.milkbowl.vault.economy.EconomyResponse; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -27,225 +26,222 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import co.uk.silvania.cities.digicoin.DigiCoin; -import net.milkbowl.vault.economy.AbstractEconomy; -import net.milkbowl.vault.economy.EconomyResponse; -import net.milkbowl.vault.economy.EconomyResponse.ResponseType; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; public class Economy_DigiCoin extends AbstractEconomy { - private final Logger log; - private final String name = "DigiCoin"; - private Plugin plugin = null; - private DigiCoin economy = null; - - public Economy_DigiCoin(Plugin plugin){ - this.plugin = plugin; - this.log = plugin.getLogger(); - Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - - if (economy == null) { - Plugin digicoin = plugin.getServer().getPluginManager().getPlugin(name); - - if (digicoin != null && digicoin.isEnabled()) { - economy = (DigiCoin) digicoin; - log.info(String.format("[Economy] %s hooked.", name)); - } - } - } - - public class EconomyServerListener implements Listener { - Economy_DigiCoin economy = null; - - public EconomyServerListener(Economy_DigiCoin economy) { - this.economy = economy; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (economy.economy == null) { - Plugin digicoin = event.getPlugin(); - - if (digicoin.getDescription().getName().equals(economy.name)) { - economy.economy = (DigiCoin) digicoin; - log.info(String.format("[Economy] %s hooked.", economy.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (economy.economy != null) { - if (event.getPlugin().getDescription().getName().equals(economy.name)) { - economy.economy = null; - log.info(String.format("[Economy] %s unhooked.", economy.name)); - } - } - } - } - - @Override - public boolean isEnabled() { - return economy != null; - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean hasBankSupport() { - return false; - } - - @Override - public int fractionalDigits() { - return -1; - } - - @Override - public String format(double amount) { - if (amount == 1.0) { - return String.format("%d %s", amount, currencyNameSingular()); - } else { - return String.format("%d %s", amount, currencyNamePlural()); - } - } - - @Override - public String currencyNamePlural() { - return "coins"; - } - - @Override - public String currencyNameSingular() { - return "coin"; - } - - @Override - public boolean hasAccount(String playerName) { - return true; - } - - @Override - public double getBalance(String playerName) { - return economy.getBalance(playerName); - } - - @Override - public boolean has(String playerName, double amount) { - return getBalance(playerName) >= amount; - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - ResponseType rt; - String message; - - if (economy.removeBalance(playerName, amount)) { - rt = ResponseType.SUCCESS; - message = null; - } else { - rt = ResponseType.FAILURE; - message = "Not enough money."; - } - - return new EconomyResponse(amount, getBalance(playerName), rt, message); - } - - @Override - public EconomyResponse depositPlayer(String playerName, double amount) { - ResponseType rt; - String message; - - if (economy.addBalance(playerName, amount)) { - rt = ResponseType.SUCCESS; - message = null; - } else { - rt = ResponseType.FAILURE; - message = "Failed to deposit balance."; - } - - return new EconomyResponse(amount, getBalance(playerName), rt, message); - } - - @Override - public EconomyResponse createBank(String name, String player) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); - } - - @Override - public EconomyResponse deleteBank(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); - } - - @Override - public EconomyResponse bankBalance(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); - } - - @Override - public EconomyResponse bankHas(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); - } - - @Override - public EconomyResponse bankWithdraw(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); - } - - @Override - public EconomyResponse bankDeposit(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); - } - - @Override - public EconomyResponse isBankOwner(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); - } - - @Override - public EconomyResponse isBankMember(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); - } - - @Override - public List getBanks() { - return new ArrayList(); - } - - @Override - public boolean createPlayerAccount(String playerName) { - return false; - } - - @Override - public boolean hasAccount(String playerName, String worldName) { - return true; - } - - @Override - public double getBalance(String playerName, String world) { - return getBalance(playerName); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - return depositPlayer(playerName, amount); - } - - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return false; - } + private final Logger log; + private final String name = "DigiCoin"; + private DigiCoin economy; + + public Economy_DigiCoin(final Plugin plugin) { + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + + if (this.economy == null) { + final Plugin digicoin = plugin.getServer().getPluginManager().getPlugin(this.name); + + if (digicoin != null && digicoin.isEnabled()) { + this.economy = (DigiCoin) digicoin; + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } + } + + public class EconomyServerListener implements Listener { + final Economy_DigiCoin economy; + + public EconomyServerListener(final Economy_DigiCoin economy) { + this.economy = economy; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.economy.economy == null) { + final Plugin digicoin = event.getPlugin(); + + if (digicoin.getDescription().getName().equals(this.economy.name)) { + this.economy.economy = (DigiCoin) digicoin; + Economy_DigiCoin.this.log.info(String.format("[Economy] %s hooked.", this.economy.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.economy.economy != null) { + if (event.getPlugin().getDescription().getName().equals(this.economy.name)) { + this.economy.economy = null; + Economy_DigiCoin.this.log.info(String.format("[Economy] %s unhooked.", this.economy.name)); + } + } + } + } + + @Override + public boolean isEnabled() { + return this.economy != null; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean hasBankSupport() { + return false; + } + + @Override + public int fractionalDigits() { + return -1; + } + + @Override + public String format(final double amount) { + if (amount == 1.0) { + return String.format("%d %s", 1.0, this.currencyNameSingular()); + } else { + return String.format("%d %s", amount, this.currencyNamePlural()); + } + } + + @Override + public String currencyNamePlural() { + return "coins"; + } + + @Override + public String currencyNameSingular() { + return "coin"; + } + + @Override + public boolean hasAccount(final String playerName) { + return true; + } + + @Override + public double getBalance(final String playerName) { + return this.economy.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final double amount) { + return this.getBalance(playerName) >= amount; + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final double amount) { + final EconomyResponse.ResponseType rt; + final String message; + + if (this.economy.removeBalance(playerName, amount)) { + rt = EconomyResponse.ResponseType.SUCCESS; + message = null; + } else { + rt = EconomyResponse.ResponseType.FAILURE; + message = "Not enough money."; + } + + return new EconomyResponse(amount, this.getBalance(playerName), rt, message); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final double amount) { + final EconomyResponse.ResponseType rt; + final String message; + + if (this.economy.addBalance(playerName, amount)) { + rt = EconomyResponse.ResponseType.SUCCESS; + message = null; + } else { + rt = EconomyResponse.ResponseType.FAILURE; + message = "Failed to deposit balance."; + } + + return new EconomyResponse(amount, this.getBalance(playerName), rt, message); + } + + @Override + public EconomyResponse createBank(final String name, final String player) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); + } + + @Override + public EconomyResponse deleteBank(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); + } + + @Override + public EconomyResponse bankBalance(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); + } + + @Override + public EconomyResponse bankHas(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); + } + + @Override + public EconomyResponse bankWithdraw(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); + } + + @Override + public EconomyResponse bankDeposit(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); + } + + @Override + public EconomyResponse isBankOwner(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); + } + + @Override + public EconomyResponse isBankMember(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "DigiCoin does not support bank accounts"); + } + + @Override + public List getBanks() { + return new ArrayList<>(); + } + + @Override + public boolean createPlayerAccount(final String playerName) { + return false; + } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return true; + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + return false; + } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_Dosh.java b/src/net/milkbowl/vault/economy/plugins/Economy_Dosh.java index f37d97d7..cc9c09a4 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_Dosh.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_Dosh.java @@ -15,181 +15,178 @@ */ package net.milkbowl.vault.economy.plugins; -import java.util.List; - -import org.bukkit.plugin.Plugin; - import com.gravypod.Dosh.Dosh; import com.gravypod.Dosh.MoneyUtils; - import net.milkbowl.vault.economy.AbstractEconomy; import net.milkbowl.vault.economy.EconomyResponse; +import org.bukkit.plugin.Plugin; +import java.util.List; -public class Economy_Dosh extends AbstractEconomy { - - - Plugin plugin; - Dosh doshPlugin; - DoshAPIHandler apiHandle; - - public Economy_Dosh(Plugin _plugin) { - plugin = _plugin; - - if (plugin.getServer().getPluginManager().isPluginEnabled("Dosh")) { - doshPlugin = (Dosh) plugin.getServer().getPluginManager().getPlugin("Dosh"); - apiHandle = new DoshAPIHandler(); - } else { - return; - } - } - - @Override - public boolean isEnabled() { - return apiHandle != null; - } - - @Override - public String getName() { - return "Dosh"; - } - - @Override - public boolean hasBankSupport() { - return false; - } - - @Override - public int fractionalDigits() { - return 0; - } - - @Override - public String format(double amount) { - return null; - } - - @Override - public String currencyNamePlural() { - return Dosh.getSettings().moneyName + "s"; - } - - @Override - public String currencyNameSingular() { - return Dosh.getSettings().moneyName; - } - - @Override - public boolean hasAccount(String playerName) { - return true; - } - - @Override - public double getBalance(String playerName) { - return DoshAPIHandler.getUserBal(playerName); - } - - @Override - public boolean has(String playerName, double amount) { - return (getBalance(playerName) - amount) > 0; - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - - if (DoshAPIHandler.subtractMoney(playerName, amount)) { - return new EconomyResponse(amount, getBalance(playerName), EconomyResponse.ResponseType.SUCCESS, "Worked!"); - } - - return new EconomyResponse(amount, getBalance(playerName), EconomyResponse.ResponseType.FAILURE, "Didnt work!"); - - } - - @Override - public EconomyResponse depositPlayer(String playerName, double amount) { - DoshAPIHandler.addUserBal(playerName, amount); - return new EconomyResponse(amount, getBalance(playerName), EconomyResponse.ResponseType.SUCCESS, "It worked!"); - } - - @Override - public EconomyResponse createBank(String name, String player) { - return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "We do not use banks!"); - } - - @Override - public EconomyResponse deleteBank(String name) { - return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "We do not use banks!"); - } - - @Override - public EconomyResponse bankBalance(String name) { - return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "We do not use banks!"); - } - - @Override - public EconomyResponse bankHas(String name, double amount) { - return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "We do not use banks!"); - } - - @Override - public EconomyResponse bankWithdraw(String name, double amount) { - return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "We do not use banks!"); - } - - @Override - public EconomyResponse bankDeposit(String name, double amount) { - return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "We do not use banks!"); - } - - @Override - public EconomyResponse isBankOwner(String name, String playerName) { - return null; - } - - @Override - public EconomyResponse isBankMember(String name, String playerName) { - return null; - } - - @Override - public List getBanks() { - return null; - } - - @Override - public boolean createPlayerAccount(String playerName) { - return false; - } - - public class DoshAPIHandler extends MoneyUtils {} - - @Override - public boolean hasAccount(String playerName, String worldName) { - return hasAccount(playerName); - } - - @Override - public double getBalance(String playerName, String world) { - return getBalance(playerName); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - return depositPlayer(playerName, amount); - } - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return createPlayerAccount(playerName); - } +public class Economy_Dosh extends AbstractEconomy { + + + final Plugin plugin; + Dosh doshPlugin; + DoshAPIHandler apiHandle; + + public Economy_Dosh(final Plugin _plugin) { + this.plugin = _plugin; + + if (this.plugin.getServer().getPluginManager().isPluginEnabled("Dosh")) { + this.doshPlugin = (Dosh) this.plugin.getServer().getPluginManager().getPlugin("Dosh"); + this.apiHandle = new DoshAPIHandler(); + } + } + + @Override + public boolean isEnabled() { + return this.apiHandle != null; + } + + @Override + public String getName() { + return "Dosh"; + } + + @Override + public boolean hasBankSupport() { + return false; + } + + @Override + public int fractionalDigits() { + return 0; + } + + @Override + public String format(final double amount) { + return null; + } + + @Override + public String currencyNamePlural() { + return Dosh.getSettings().moneyName + "s"; + } + + @Override + public String currencyNameSingular() { + return Dosh.getSettings().moneyName; + } + + @Override + public boolean hasAccount(final String playerName) { + return true; + } + + @Override + public double getBalance(final String playerName) { + return MoneyUtils.getUserBal(playerName); + } + + @Override + public boolean has(final String playerName, final double amount) { + return (this.getBalance(playerName) - amount) > 0; + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final double amount) { + + if (MoneyUtils.subtractMoney(playerName, amount)) { + return new EconomyResponse(amount, this.getBalance(playerName), EconomyResponse.ResponseType.SUCCESS, "Worked!"); + } + + return new EconomyResponse(amount, this.getBalance(playerName), EconomyResponse.ResponseType.FAILURE, "Didnt work!"); + + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final double amount) { + MoneyUtils.addUserBal(playerName, amount); + return new EconomyResponse(amount, this.getBalance(playerName), EconomyResponse.ResponseType.SUCCESS, "It worked!"); + } + + @Override + public EconomyResponse createBank(final String name, final String player) { + return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "We do not use banks!"); + } + + @Override + public EconomyResponse deleteBank(final String name) { + return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "We do not use banks!"); + } + + @Override + public EconomyResponse bankBalance(final String name) { + return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "We do not use banks!"); + } + + @Override + public EconomyResponse bankHas(final String name, final double amount) { + return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "We do not use banks!"); + } + + @Override + public EconomyResponse bankWithdraw(final String name, final double amount) { + return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "We do not use banks!"); + } + + @Override + public EconomyResponse bankDeposit(final String name, final double amount) { + return new EconomyResponse(0D, 0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "We do not use banks!"); + } + + @Override + public EconomyResponse isBankOwner(final String name, final String playerName) { + return null; + } + + @Override + public EconomyResponse isBankMember(final String name, final String playerName) { + return null; + } + + @Override + public List getBanks() { + return null; + } + + @Override + public boolean createPlayerAccount(final String playerName) { + return false; + } + + public static class DoshAPIHandler extends MoneyUtils { + } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return this.hasAccount(playerName); + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + return this.createPlayerAccount(playerName); + } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_EconXP.java b/src/net/milkbowl/vault/economy/plugins/Economy_EconXP.java index b273c8d9..9fb61ca8 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_EconXP.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_EconXP.java @@ -15,15 +15,9 @@ */ package net.milkbowl.vault.economy.plugins; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - +import ca.agnate.EconXP.EconXP; import net.milkbowl.vault.economy.AbstractEconomy; import net.milkbowl.vault.economy.EconomyResponse; -import net.milkbowl.vault.economy.EconomyResponse.ResponseType; - import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.event.EventHandler; @@ -33,245 +27,250 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import ca.agnate.EconXP.EconXP; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; public class Economy_EconXP extends AbstractEconomy { - private final Logger log; - - private final String name = "EconXP"; - private Plugin plugin = null; - private EconXP econ = null; - - public Economy_EconXP(Plugin plugin) { - this.plugin = plugin; - this.log = plugin.getLogger(); - Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - log.log(Level.WARNING, "EconXP is an integer only economy, you may notice inconsistencies with accounts if you do not setup your other econ using plugins accordingly!"); - // Load Plugin in case it was loaded before - if (econ == null) { - Plugin econ = plugin.getServer().getPluginManager().getPlugin("EconXP"); - if (econ != null && econ.isEnabled()) { - this.econ = (EconXP) econ; - log.info(String.format("[Economy] %s hooked.", name)); - } - } - } - - public class EconomyServerListener implements Listener { - Economy_EconXP economy = null; - - public EconomyServerListener(Economy_EconXP economy) { - this.economy = economy; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (economy.econ == null) { - Plugin eco = event.getPlugin(); - - if (eco.getDescription().getName().equals("EconXP")) { - economy.econ = (EconXP) eco; - log.info(String.format("[Economy] %s hooked.", economy.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (economy.econ != null) { - if (event.getPlugin().getDescription().getName().equals("EconXP")) { - economy.econ = null; - log.info(String.format("[Economy] %s unhooked.", economy.name)); - } - } - } - } - - @Override - public boolean isEnabled() { - return this.econ != null; - } - - @Override - public String getName() { - return name; - } - - @Override - public String format(double amount) { - amount = Math.ceil(amount); - - return String.format("%d %s", (int)amount, "experience"); - } - - @Override - public String currencyNamePlural() { - return "experience"; - } - - @Override - public String currencyNameSingular() { - return "experience"; - } - - @Override - public double getBalance(String playerName) { - OfflinePlayer player = econ.getPlayer(playerName); - - if ( player == null ) { return 0; } - - return econ.getExp(player); - } - - @Override - public boolean has(String playerName, double amount) { - OfflinePlayer player = econ.getPlayer(playerName); - - if ( player == null ) { return false; } - - return econ.hasExp(player, (int) Math.ceil(amount) ); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - OfflinePlayer player = econ.getPlayer(playerName); - - if ( player == null ) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Player does not exist"); - } - - double balance = econ.getExp(player); - amount = Math.ceil(amount); - - if (amount < 0) { - return new EconomyResponse(0, balance, ResponseType.FAILURE, "Cannot withdraw negative funds"); - } - - if ( econ.hasExp(player, (int) amount) == false ) { - return new EconomyResponse(0, balance, ResponseType.FAILURE, "Insufficient funds"); - } - - econ.removeExp(player, (int) amount); - - double finalBalance = econ.getExp(player); - - return new EconomyResponse(amount, finalBalance, ResponseType.SUCCESS, null); - } - - @Override - public EconomyResponse depositPlayer(String playerName, double amount) { - OfflinePlayer player = econ.getPlayer(playerName); - - if ( player == null ) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Player does not exist"); - } - - double balance = econ.getExp(player); - amount = Math.ceil(amount); - - if (amount < 0) { - return new EconomyResponse(0, balance, ResponseType.FAILURE, "Cannot withdraw negative funds"); - } - - econ.addExp(player, (int) amount ); - balance = econ.getExp(player); - - return new EconomyResponse(amount, balance, ResponseType.SUCCESS, null); - } - - @Override - public EconomyResponse createBank(String name, String player) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); - } - - @Override - public EconomyResponse deleteBank(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); - } - - @Override - public EconomyResponse bankHas(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); - } - - @Override - public EconomyResponse bankWithdraw(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); - } - - @Override - public EconomyResponse bankDeposit(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); - } - - @Override - public EconomyResponse isBankOwner(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); - } - - @Override - public EconomyResponse isBankMember(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); - } - - @Override - public EconomyResponse bankBalance(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); - } - - @Override - public List getBanks() { - return new ArrayList(); - } - - @Override - public boolean hasBankSupport() { - return false; - } - - @Override - public boolean hasAccount(String playerName) { - return econ.getPlayer(playerName) != null; - } - - @Override - public boolean createPlayerAccount(String playerName) { - return false; - } - + private final Logger log; + + private final String name = "EconXP"; + private EconXP econ; + + public Economy_EconXP(final Plugin plugin) { + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + this.log.log(Level.WARNING, "EconXP is an integer only economy, you may notice inconsistencies with accounts if you do not setup your other econ using plugins accordingly!"); + // Load Plugin in case it was loaded before + if (this.econ == null) { + final Plugin econ = plugin.getServer().getPluginManager().getPlugin("EconXP"); + if (econ != null && econ.isEnabled()) { + this.econ = (EconXP) econ; + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } + } + + public class EconomyServerListener implements Listener { + final Economy_EconXP economy; + + public EconomyServerListener(final Economy_EconXP economy) { + this.economy = economy; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.economy.econ == null) { + final Plugin eco = event.getPlugin(); + + if (eco.getDescription().getName().equals("EconXP")) { + this.economy.econ = (EconXP) eco; + Economy_EconXP.this.log.info(String.format("[Economy] %s hooked.", this.economy.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.economy.econ != null) { + if (event.getPlugin().getDescription().getName().equals("EconXP")) { + this.economy.econ = null; + Economy_EconXP.this.log.info(String.format("[Economy] %s unhooked.", this.economy.name)); + } + } + } + } + + @Override + public boolean isEnabled() { + return econ != null; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public String format(double amount) { + amount = Math.ceil(amount); + + return String.format("%d %s", (int) amount, "experience"); + } + + @Override + public String currencyNamePlural() { + return "experience"; + } + + @Override + public String currencyNameSingular() { + return "experience"; + } + + @Override + public double getBalance(final String playerName) { + final OfflinePlayer player = this.econ.getPlayer(playerName); + + if (player == null) { + return 0; + } + + return this.econ.getExp(player); + } + + @Override + public boolean has(final String playerName, final double amount) { + final OfflinePlayer player = this.econ.getPlayer(playerName); + + if (player == null) { + return false; + } + + return this.econ.hasExp(player, (int) Math.ceil(amount)); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, double amount) { + final OfflinePlayer player = this.econ.getPlayer(playerName); + + if (player == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Player does not exist"); + } + + final double balance = this.econ.getExp(player); + amount = Math.ceil(amount); + + if (amount < 0) { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, "Cannot withdraw negative funds"); + } + + if (!this.econ.hasExp(player, (int) amount)) { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, "Insufficient funds"); + } + + this.econ.removeExp(player, (int) amount); + + final double finalBalance = this.econ.getExp(player); + + return new EconomyResponse(amount, finalBalance, EconomyResponse.ResponseType.SUCCESS, null); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, double amount) { + final OfflinePlayer player = this.econ.getPlayer(playerName); + + if (player == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Player does not exist"); + } + + double balance = this.econ.getExp(player); + amount = Math.ceil(amount); + + if (amount < 0) { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, "Cannot withdraw negative funds"); + } + + this.econ.addExp(player, (int) amount); + balance = this.econ.getExp(player); + + return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.SUCCESS, null); + } + + @Override + public EconomyResponse createBank(final String name, final String player) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); + } + + @Override + public EconomyResponse deleteBank(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); + } + + @Override + public EconomyResponse bankHas(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); + } + + @Override + public EconomyResponse bankWithdraw(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); + } + + @Override + public EconomyResponse bankDeposit(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); + } + + @Override + public EconomyResponse isBankOwner(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); + } + + @Override + public EconomyResponse isBankMember(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); + } + + @Override + public EconomyResponse bankBalance(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "EconXP does not support bank accounts!"); + } + + @Override + public List getBanks() { + return new ArrayList<>(); + } + + @Override + public boolean hasBankSupport() { + return false; + } + + @Override + public boolean hasAccount(final String playerName) { + return this.econ.getPlayer(playerName) != null; + } + + @Override + public boolean createPlayerAccount(final String playerName) { + return false; + } + @Override public int fractionalDigits() { return 0; } - - @Override - public boolean hasAccount(String playerName, String worldName) { - return hasAccount(playerName); - } - - @Override - public double getBalance(String playerName, String world) { - return getBalance(playerName); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - return depositPlayer(playerName, amount); - } - - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return createPlayerAccount(playerName); - } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return this.hasAccount(playerName); + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + return this.createPlayerAccount(playerName); + } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_Essentials.java b/src/net/milkbowl/vault/economy/plugins/Economy_Essentials.java index c82267e8..2d15e2cf 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_Essentials.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_Essentials.java @@ -15,14 +15,11 @@ */ package net.milkbowl.vault.economy.plugins; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; - +import com.earth2me.essentials.Essentials; +import com.earth2me.essentials.api.NoLoanPermittedException; +import com.earth2me.essentials.api.UserDoesNotExistException; import net.milkbowl.vault.economy.AbstractEconomy; import net.milkbowl.vault.economy.EconomyResponse; -import net.milkbowl.vault.economy.EconomyResponse.ResponseType; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -31,302 +28,300 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import com.earth2me.essentials.Essentials; -import com.earth2me.essentials.api.NoLoanPermittedException; -import com.earth2me.essentials.api.UserDoesNotExistException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; public class Economy_Essentials extends AbstractEconomy { - - private final String name = "Essentials Economy"; - private final Logger log; - private Plugin plugin = null; - private Essentials ess = null; - - public Economy_Essentials(Plugin plugin) { - this.plugin = plugin; - this.log = plugin.getLogger(); - Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - - // Load Plugin in case it was loaded before - if (ess == null) { - Plugin essentials = plugin.getServer().getPluginManager().getPlugin("Essentials"); - if (essentials != null && essentials.isEnabled()) { - ess = (Essentials) essentials; - log.info(String.format("[Economy] %s hooked.", name)); - } - } - } - - @Override - public boolean isEnabled() { - if (ess == null) { - return false; - } else { - return ess.isEnabled(); - } - } - - @Override - public String getName() { - return name; - } - - @Override - public double getBalance(String playerName) { - double balance; - - try { - balance = com.earth2me.essentials.api.Economy.getMoney(playerName); - } catch (UserDoesNotExistException e) { - createPlayerAccount(playerName); - balance = 0; - } - - return balance; - } - - @Override - public boolean createPlayerAccount(String playerName) { - if (hasAccount(playerName)) { - return false; - } - return com.earth2me.essentials.api.Economy.createNPC(playerName); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - if (playerName == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Player name can not be null."); - } - if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds"); - } - - double balance; - EconomyResponse.ResponseType type; - String errorMessage = null; - - try { - com.earth2me.essentials.api.Economy.subtract(playerName, amount); - balance = com.earth2me.essentials.api.Economy.getMoney(playerName); - type = EconomyResponse.ResponseType.SUCCESS; - } catch (UserDoesNotExistException e) { - if (createPlayerAccount(playerName)) { - return withdrawPlayer(playerName, amount); - } else { - amount = 0; - balance = 0; - type = EconomyResponse.ResponseType.FAILURE; - errorMessage = "User does not exist"; - } - } catch (NoLoanPermittedException e) { - try { - balance = com.earth2me.essentials.api.Economy.getMoney(playerName); - amount = 0; - type = EconomyResponse.ResponseType.FAILURE; - errorMessage = "Loan was not permitted"; - } catch (UserDoesNotExistException e1) { - amount = 0; - balance = 0; - type = EconomyResponse.ResponseType.FAILURE; - errorMessage = "User does not exist"; - } - } - - return new EconomyResponse(amount, balance, type, errorMessage); - } - - public EconomyResponse tryDepositPlayer(String playerName, double amount, int tries) { - if (playerName == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Player name can not be null."); - } - if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds"); - } - if (tries <= 0) { - return new EconomyResponse(amount, 0, ResponseType.FAILURE, "Failed to deposit amount."); - } - - double balance; - EconomyResponse.ResponseType type; - String errorMessage = null; - - try { - com.earth2me.essentials.api.Economy.add(playerName, amount); - balance = com.earth2me.essentials.api.Economy.getMoney(playerName); - type = ResponseType.SUCCESS; - } catch (UserDoesNotExistException e) { - if (createPlayerAccount(playerName)) { - return tryDepositPlayer(playerName, amount, tries--); - } else { - amount = 0; - balance = 0; - type = ResponseType.FAILURE; - errorMessage = "User does not exist"; - } - } catch (NoLoanPermittedException e) { - try { - balance = com.earth2me.essentials.api.Economy.getMoney(playerName); - amount = 0; - type = ResponseType.FAILURE; - errorMessage = "Loan was not permitted"; - } catch (UserDoesNotExistException e1) { - balance = 0; - amount = 0; - type = ResponseType.FAILURE; - errorMessage = "Loan was not permitted"; - } - } - - return new EconomyResponse(amount, balance, type, errorMessage); - } - - @Override - public EconomyResponse depositPlayer(String playerName, double amount) { - return tryDepositPlayer(playerName, amount, 2); - } - - public class EconomyServerListener implements Listener { - Economy_Essentials economy = null; - - public EconomyServerListener(Economy_Essentials economy) { - this.economy = economy; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (economy.ess == null) { - Plugin essentials = event.getPlugin(); - - if (essentials.getDescription().getName().equals("Essentials")) { - economy.ess = (Essentials) essentials; - log.info(String.format("[Economy] %s hooked.", economy.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (economy.ess != null) { - if (event.getPlugin().getDescription().getName().equals("Essentials")) { - economy.ess = null; - log.info(String.format("[Economy] %s unhooked.", economy.name)); - } - } - } - } - - @Override - public String format(double amount) { - return com.earth2me.essentials.api.Economy.format(amount); - } - - @Override - public String currencyNameSingular() { - return ""; - } - - @Override - public String currencyNamePlural() { - return ""; - } - - @Override - public boolean has(String playerName, double amount) { - try { - return com.earth2me.essentials.api.Economy.hasEnough(playerName, amount); - } catch (UserDoesNotExistException e) { - return false; - } - } - - @Override - public EconomyResponse createBank(String name, String player) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); - } - - @Override - public EconomyResponse deleteBank(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); - } - - @Override - public EconomyResponse bankHas(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); - } - - @Override - public EconomyResponse bankWithdraw(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); - } - - @Override - public EconomyResponse bankDeposit(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); - } - - @Override - public EconomyResponse isBankOwner(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); - } - - @Override - public EconomyResponse isBankMember(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); - } - - @Override - public EconomyResponse bankBalance(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); - } - - @Override - public List getBanks() { - return new ArrayList(); - } - - @Override - public boolean hasBankSupport() { - return false; - } - - @Override - public boolean hasAccount(String playerName) { - return com.earth2me.essentials.api.Economy.playerExists(playerName); - } - + + private final String name = "Essentials Economy"; + private final Logger log; + private Essentials ess; + + public Economy_Essentials(final Plugin plugin) { + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + + // Load Plugin in case it was loaded before + if (this.ess == null) { + final Plugin essentials = plugin.getServer().getPluginManager().getPlugin("Essentials"); + if (essentials != null && essentials.isEnabled()) { + this.ess = (Essentials) essentials; + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } + } + + @Override + public boolean isEnabled() { + if (this.ess == null) { + return false; + } else { + return this.ess.isEnabled(); + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public double getBalance(final String playerName) { + double balance; + + try { + balance = com.earth2me.essentials.api.Economy.getMoney(playerName); + } catch (final UserDoesNotExistException e) { + this.createPlayerAccount(playerName); + balance = 0; + } + + return balance; + } + + @Override + public boolean createPlayerAccount(final String playerName) { + if (this.hasAccount(playerName)) { + return false; + } + return com.earth2me.essentials.api.Economy.createNPC(playerName); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, double amount) { + if (playerName == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Player name can not be null."); + } + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot withdraw negative funds"); + } + + double balance; + EconomyResponse.ResponseType type; + String errorMessage = null; + + try { + com.earth2me.essentials.api.Economy.subtract(playerName, amount); + balance = com.earth2me.essentials.api.Economy.getMoney(playerName); + type = EconomyResponse.ResponseType.SUCCESS; + } catch (final UserDoesNotExistException e) { + if (this.createPlayerAccount(playerName)) { + return this.withdrawPlayer(playerName, amount); + } else { + amount = 0; + balance = 0; + type = EconomyResponse.ResponseType.FAILURE; + errorMessage = "User does not exist"; + } + } catch (final NoLoanPermittedException e) { + try { + balance = com.earth2me.essentials.api.Economy.getMoney(playerName); + amount = 0; + type = EconomyResponse.ResponseType.FAILURE; + errorMessage = "Loan was not permitted"; + } catch (final UserDoesNotExistException e1) { + amount = 0; + balance = 0; + type = EconomyResponse.ResponseType.FAILURE; + errorMessage = "User does not exist"; + } + } + + return new EconomyResponse(amount, balance, type, errorMessage); + } + + public EconomyResponse tryDepositPlayer(final String playerName, double amount, int tries) { + if (playerName == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Player name can not be null."); + } + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot desposit negative funds"); + } + if (tries <= 0) { + return new EconomyResponse(amount, 0, EconomyResponse.ResponseType.FAILURE, "Failed to deposit amount."); + } + + double balance; + EconomyResponse.ResponseType type; + String errorMessage = null; + + try { + com.earth2me.essentials.api.Economy.add(playerName, amount); + balance = com.earth2me.essentials.api.Economy.getMoney(playerName); + type = EconomyResponse.ResponseType.SUCCESS; + } catch (final UserDoesNotExistException e) { + if (this.createPlayerAccount(playerName)) { + return this.tryDepositPlayer(playerName, amount, tries--); + } else { + amount = 0; + balance = 0; + type = EconomyResponse.ResponseType.FAILURE; + errorMessage = "User does not exist"; + } + } catch (final NoLoanPermittedException e) { + try { + balance = com.earth2me.essentials.api.Economy.getMoney(playerName); + amount = 0; + type = EconomyResponse.ResponseType.FAILURE; + errorMessage = "Loan was not permitted"; + } catch (final UserDoesNotExistException e1) { + balance = 0; + amount = 0; + type = EconomyResponse.ResponseType.FAILURE; + errorMessage = "Loan was not permitted"; + } + } + + return new EconomyResponse(amount, balance, type, errorMessage); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final double amount) { + return this.tryDepositPlayer(playerName, amount, 2); + } + + public class EconomyServerListener implements Listener { + final Economy_Essentials economy; + + public EconomyServerListener(final Economy_Essentials economy) { + this.economy = economy; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.economy.ess == null) { + final Plugin essentials = event.getPlugin(); + + if (essentials.getDescription().getName().equals("Essentials")) { + this.economy.ess = (Essentials) essentials; + Economy_Essentials.this.log.info(String.format("[Economy] %s hooked.", this.economy.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.economy.ess != null) { + if (event.getPlugin().getDescription().getName().equals("Essentials")) { + this.economy.ess = null; + Economy_Essentials.this.log.info(String.format("[Economy] %s unhooked.", this.economy.name)); + } + } + } + } + + @Override + public String format(final double amount) { + return com.earth2me.essentials.api.Economy.format(amount); + } + + @Override + public String currencyNameSingular() { + return ""; + } + + @Override + public String currencyNamePlural() { + return ""; + } + + @Override + public boolean has(final String playerName, final double amount) { + try { + return com.earth2me.essentials.api.Economy.hasEnough(playerName, amount); + } catch (final UserDoesNotExistException e) { + return false; + } + } + + @Override + public EconomyResponse createBank(final String name, final String player) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); + } + + @Override + public EconomyResponse deleteBank(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); + } + + @Override + public EconomyResponse bankHas(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); + } + + @Override + public EconomyResponse bankWithdraw(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); + } + + @Override + public EconomyResponse bankDeposit(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); + } + + @Override + public EconomyResponse isBankOwner(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); + } + + @Override + public EconomyResponse isBankMember(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); + } + + @Override + public EconomyResponse bankBalance(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Essentials Eco does not support bank accounts!"); + } + + @Override + public List getBanks() { + return new ArrayList<>(); + } + + @Override + public boolean hasBankSupport() { + return false; + } + + @Override + public boolean hasAccount(final String playerName) { + return com.earth2me.essentials.api.Economy.playerExists(playerName); + } + @Override public int fractionalDigits() { return -1; } - @Override - public boolean hasAccount(String playerName, String worldName) { - return hasAccount(playerName); - } - - @Override - public double getBalance(String playerName, String world) { - return getBalance(playerName); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - return depositPlayer(playerName, amount); - } - - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return createPlayerAccount(playerName); - } + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return this.hasAccount(playerName); + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + return this.createPlayerAccount(playerName); + } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_GoldIsMoney2.java b/src/net/milkbowl/vault/economy/plugins/Economy_GoldIsMoney2.java index e497d45b..c070fe6b 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_GoldIsMoney2.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_GoldIsMoney2.java @@ -15,13 +15,9 @@ */ package net.milkbowl.vault.economy.plugins; -import java.util.List; -import java.util.logging.Logger; - +import com.flobi.GoldIsMoney2.GoldIsMoney; import net.milkbowl.vault.economy.AbstractEconomy; import net.milkbowl.vault.economy.EconomyResponse; -import net.milkbowl.vault.economy.EconomyResponse.ResponseType; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -30,56 +26,55 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import com.flobi.GoldIsMoney2.GoldIsMoney; +import java.util.List; +import java.util.logging.Logger; public class Economy_GoldIsMoney2 extends AbstractEconomy { private final Logger log; private final String name = "GoldIsMoney"; - private Plugin plugin = null; - protected GoldIsMoney economy = null; + protected GoldIsMoney economy; - public Economy_GoldIsMoney2(Plugin plugin) { - this.plugin = plugin; - this.log = plugin.getLogger(); - Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - // Load Plugin in case it was loaded before - if (economy == null) { - Plugin ec = plugin.getServer().getPluginManager().getPlugin("GoldIsMoney"); - - if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.flobi.GoldIsMoney2.GoldIsMoney")) { - economy = (GoldIsMoney) ec; - log.info(String.format("[Economy] %s hooked.", name)); - } - } + public Economy_GoldIsMoney2(final Plugin plugin) { + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + // Load Plugin in case it was loaded before + if (this.economy == null) { + final Plugin ec = plugin.getServer().getPluginManager().getPlugin("GoldIsMoney"); + + if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.flobi.GoldIsMoney2.GoldIsMoney")) { + this.economy = (GoldIsMoney) ec; + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } } @Override public boolean isEnabled() { - if (economy == null) { - return false; - } else { - return economy.isEnabled(); - } + if (this.economy == null) { + return false; + } else { + return this.economy.isEnabled(); + } } @Override public String getName() { - return name; + return this.name; } @Override public boolean hasBankSupport() { - return GoldIsMoney.hasBankSupport(); + return GoldIsMoney.hasBankSupport(); } - + @Override public int fractionalDigits() { return GoldIsMoney.fractionalDigits(); } @Override - public String format(double amount) { - return GoldIsMoney.format(amount); + public String format(final double amount) { + return GoldIsMoney.format(amount); } @Override @@ -93,224 +88,224 @@ public String currencyNameSingular() { } @Override - public boolean hasAccount(String playerName) { - return GoldIsMoney.hasAccount(playerName); + public boolean hasAccount(final String playerName) { + return GoldIsMoney.hasAccount(playerName); } @Override - public double getBalance(String playerName) { - return GoldIsMoney.getBalance(playerName); + public double getBalance(final String playerName) { + return GoldIsMoney.getBalance(playerName); } @Override - public boolean has(String playerName, double amount) { - return GoldIsMoney.has(playerName, amount); + public boolean has(final String playerName, final double amount) { + return GoldIsMoney.has(playerName, amount); } @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds!"); - } - if (!GoldIsMoney.hasAccount(playerName)) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That player does not have an account!"); - } - if (!GoldIsMoney.has(playerName, amount)) { - return new EconomyResponse(0, GoldIsMoney.getBalance(playerName), ResponseType.FAILURE, "Insufficient funds"); - } - if (!GoldIsMoney.withdrawPlayer(playerName, amount)) { - return new EconomyResponse(0, GoldIsMoney.getBalance(playerName), ResponseType.FAILURE, "Unable to withdraw funds!"); - } - return new EconomyResponse(amount, GoldIsMoney.getBalance(playerName), ResponseType.SUCCESS, null); + public EconomyResponse withdrawPlayer(final String playerName, final double amount) { + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot withdraw negative funds!"); + } + if (!GoldIsMoney.hasAccount(playerName)) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That player does not have an account!"); + } + if (!GoldIsMoney.has(playerName, amount)) { + return new EconomyResponse(0, GoldIsMoney.getBalance(playerName), EconomyResponse.ResponseType.FAILURE, "Insufficient funds"); + } + if (!GoldIsMoney.withdrawPlayer(playerName, amount)) { + return new EconomyResponse(0, GoldIsMoney.getBalance(playerName), EconomyResponse.ResponseType.FAILURE, "Unable to withdraw funds!"); + } + return new EconomyResponse(amount, GoldIsMoney.getBalance(playerName), EconomyResponse.ResponseType.SUCCESS, null); } @Override - public EconomyResponse depositPlayer(String playerName, double amount) { - if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds!"); - } - if (!GoldIsMoney.hasAccount(playerName)) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That player does not have an account!"); - } - if (!GoldIsMoney.depositPlayer(playerName, amount)) { - return new EconomyResponse(0, GoldIsMoney.getBalance(playerName), ResponseType.FAILURE, "Unable to deposit funds!"); - } - return new EconomyResponse(amount, GoldIsMoney.getBalance(playerName), ResponseType.SUCCESS, null); + public EconomyResponse depositPlayer(final String playerName, final double amount) { + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot desposit negative funds!"); + } + if (!GoldIsMoney.hasAccount(playerName)) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That player does not have an account!"); + } + if (!GoldIsMoney.depositPlayer(playerName, amount)) { + return new EconomyResponse(0, GoldIsMoney.getBalance(playerName), EconomyResponse.ResponseType.FAILURE, "Unable to deposit funds!"); + } + return new EconomyResponse(amount, GoldIsMoney.getBalance(playerName), EconomyResponse.ResponseType.SUCCESS, null); } @Override - public EconomyResponse createBank(String name, String player) { + public EconomyResponse createBank(final String name, final String player) { if (!GoldIsMoney.hasBankSupport()) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + } + if (!GoldIsMoney.createBank(name, player)) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Unable to create bank account."); } - if (!GoldIsMoney.createBank(name, player)) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Unable to create bank account."); - } - return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.SUCCESS, ""); + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), EconomyResponse.ResponseType.SUCCESS, ""); } @Override - public EconomyResponse deleteBank(String name) { + public EconomyResponse deleteBank(final String name) { if (!GoldIsMoney.hasBankSupport()) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); } - if (!GoldIsMoney.deleteBank(name)) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Unable to remove bank account."); - } - return new EconomyResponse(0, 0, ResponseType.SUCCESS, ""); + if (!GoldIsMoney.deleteBank(name)) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Unable to remove bank account."); + } + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, ""); } @Override - public EconomyResponse bankBalance(String name) { + public EconomyResponse bankBalance(final String name) { if (!GoldIsMoney.hasBankSupport()) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + } + if (!GoldIsMoney.bankExists(name)) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That bank does not exist!"); } - if (!GoldIsMoney.bankExists(name)) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); - } - return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.SUCCESS, ""); + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), EconomyResponse.ResponseType.SUCCESS, ""); } @Override - public EconomyResponse bankHas(String name, double amount) { + public EconomyResponse bankHas(final String name, final double amount) { if (!GoldIsMoney.hasBankSupport()) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); - } - if (!GoldIsMoney.bankExists(name)) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); - } - if (GoldIsMoney.bankHas(name, amount)) { - return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.FAILURE, "The bank does not have enough money!"); - } - return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.SUCCESS, ""); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + } + if (!GoldIsMoney.bankExists(name)) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That bank does not exist!"); + } + if (GoldIsMoney.bankHas(name, amount)) { + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), EconomyResponse.ResponseType.FAILURE, "The bank does not have enough money!"); + } + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), EconomyResponse.ResponseType.SUCCESS, ""); } @Override - public EconomyResponse bankWithdraw(String name, double amount) { + public EconomyResponse bankWithdraw(final String name, final double amount) { if (!GoldIsMoney.hasBankSupport()) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); - } - if (!GoldIsMoney.bankExists(name)) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); - } - if (!GoldIsMoney.bankHas(name, amount)) { - return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.FAILURE, "The bank does not have enough money!"); - } - if (!GoldIsMoney.bankWithdraw(name, amount)) { - return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.FAILURE, "Unable to withdraw from that bank account!"); - } - return new EconomyResponse(amount, GoldIsMoney.bankBalance(name), ResponseType.SUCCESS, ""); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + } + if (!GoldIsMoney.bankExists(name)) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That bank does not exist!"); + } + if (!GoldIsMoney.bankHas(name, amount)) { + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), EconomyResponse.ResponseType.FAILURE, "The bank does not have enough money!"); + } + if (!GoldIsMoney.bankWithdraw(name, amount)) { + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), EconomyResponse.ResponseType.FAILURE, "Unable to withdraw from that bank account!"); + } + return new EconomyResponse(amount, GoldIsMoney.bankBalance(name), EconomyResponse.ResponseType.SUCCESS, ""); } @Override - public EconomyResponse bankDeposit(String name, double amount) { + public EconomyResponse bankDeposit(final String name, final double amount) { if (!GoldIsMoney.hasBankSupport()) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); - } - if (!GoldIsMoney.bankExists(name)) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); - } - if (!GoldIsMoney.bankDeposit(name, amount)) { - return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.FAILURE, "Unable to deposit to that bank account!"); - } - return new EconomyResponse(amount, GoldIsMoney.bankBalance(name), ResponseType.SUCCESS, ""); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + } + if (!GoldIsMoney.bankExists(name)) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That bank does not exist!"); + } + if (!GoldIsMoney.bankDeposit(name, amount)) { + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), EconomyResponse.ResponseType.FAILURE, "Unable to deposit to that bank account!"); + } + return new EconomyResponse(amount, GoldIsMoney.bankBalance(name), EconomyResponse.ResponseType.SUCCESS, ""); } @Override - public EconomyResponse isBankOwner(String name, String playerName) { + public EconomyResponse isBankOwner(final String name, final String playerName) { if (!GoldIsMoney.hasBankSupport()) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); - } - if (!GoldIsMoney.bankExists(name)) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); - } - if (!GoldIsMoney.isBankOwner(name, playerName)) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That player does not own that bank!"); - } - return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.SUCCESS, ""); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + } + if (!GoldIsMoney.bankExists(name)) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That bank does not exist!"); + } + if (!GoldIsMoney.isBankOwner(name, playerName)) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That player does not own that bank!"); + } + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), EconomyResponse.ResponseType.SUCCESS, ""); } @Override - public EconomyResponse isBankMember(String name, String playerName) { + public EconomyResponse isBankMember(final String name, final String playerName) { if (!GoldIsMoney.hasBankSupport()) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); - } - if (!GoldIsMoney.bankExists(name)) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank does not exist!"); - } - if (!GoldIsMoney.isBankMember(name, playerName)) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That player is not a member of that bank!"); - } - return new EconomyResponse(0, GoldIsMoney.bankBalance(name), ResponseType.SUCCESS, ""); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "GoldIsMoney bank support is disabled!"); + } + if (!GoldIsMoney.bankExists(name)) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That bank does not exist!"); + } + if (!GoldIsMoney.isBankMember(name, playerName)) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That player is not a member of that bank!"); + } + return new EconomyResponse(0, GoldIsMoney.bankBalance(name), EconomyResponse.ResponseType.SUCCESS, ""); } @Override public List getBanks() { - return GoldIsMoney.getBanks(); + return GoldIsMoney.getBanks(); } @Override - public boolean createPlayerAccount(String playerName) { - return GoldIsMoney.createPlayerAccount(playerName); + public boolean createPlayerAccount(final String playerName) { + return GoldIsMoney.createPlayerAccount(playerName); } public class EconomyServerListener implements Listener { - Economy_GoldIsMoney2 economy = null; - - public EconomyServerListener(Economy_GoldIsMoney2 economy_GoldIsMoney2) { - this.economy = economy_GoldIsMoney2; + final Economy_GoldIsMoney2 economy; + + public EconomyServerListener(final Economy_GoldIsMoney2 economy_GoldIsMoney2) { + economy = economy_GoldIsMoney2; } - + @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (economy.economy == null) { - Plugin ec = event.getPlugin(); - + public void onPluginEnable(final PluginEnableEvent event) { + if (this.economy.economy == null) { + final Plugin ec = event.getPlugin(); + if (ec.getClass().getName().equals("com.flobi.GoldIsMoney2.GoldIsMoney")) { - economy.economy = (GoldIsMoney) ec; - log.info(String.format("[Economy] %s hooked.", economy.name)); + this.economy.economy = (GoldIsMoney) ec; + Economy_GoldIsMoney2.this.log.info(String.format("[Economy] %s hooked.", this.economy.name)); } } } - + @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (economy.economy != null) { + public void onPluginDisable(final PluginDisableEvent event) { + if (this.economy.economy != null) { if (event.getPlugin().getDescription().getName().equals("GoldIsMoney")) { - economy.economy = null; - log.info(String.format("[Economy] %s unhooked.", economy.name)); + this.economy.economy = null; + Economy_GoldIsMoney2.this.log.info(String.format("[Economy] %s unhooked.", this.economy.name)); } } } } - - @Override - public boolean hasAccount(String playerName, String worldName) { - return hasAccount(playerName); - } - - @Override - public double getBalance(String playerName, String world) { - return getBalance(playerName); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - return depositPlayer(playerName, amount); - } - - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return createPlayerAccount(playerName); - } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return this.hasAccount(playerName); + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + return this.createPlayerAccount(playerName); + } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_GoldenChestEconomy.java b/src/net/milkbowl/vault/economy/plugins/Economy_GoldenChestEconomy.java index cb5af1c4..4434373e 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_GoldenChestEconomy.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_GoldenChestEconomy.java @@ -15,9 +15,9 @@ */ package net.milkbowl.vault.economy.plugins; -import java.util.List; -import java.util.logging.Logger; - +import me.igwb.GoldenChest.GoldenChestEconomy; +import net.milkbowl.vault.economy.AbstractEconomy; +import net.milkbowl.vault.economy.EconomyResponse; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -26,223 +26,219 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import me.igwb.GoldenChest.GoldenChestEconomy; -import net.milkbowl.vault.economy.AbstractEconomy; -import net.milkbowl.vault.economy.EconomyResponse; -import net.milkbowl.vault.economy.EconomyResponse.ResponseType; +import java.util.List; +import java.util.logging.Logger; public class Economy_GoldenChestEconomy extends AbstractEconomy { - private final Logger log; - - private final String name = "GoldenChestEconomy"; - private Plugin plugin = null; - private GoldenChestEconomy economy = null; - - - public Economy_GoldenChestEconomy (Plugin plugin) { - this.plugin = plugin; - this.log = plugin.getLogger(); - Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - // Load Plugin in case it was loaded before - if (economy == null) { - Plugin ec = plugin.getServer().getPluginManager().getPlugin("GoldenChestEconomy"); - if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("me.igwb.GoldenChest.GoldenChestEconomy")) { - economy = (GoldenChestEconomy) ec; - log.info(String.format("[Economy] %s hooked.", name)); - } - } - } - - public class EconomyServerListener implements Listener { - Economy_GoldenChestEconomy economy = null; - - public EconomyServerListener(Economy_GoldenChestEconomy economy_GoldenChestEconomy) { - this.economy = economy_GoldenChestEconomy; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (economy.economy == null) { - Plugin ec = event.getPlugin(); - - if (ec.getDescription().getName().equals("GoldenChestEconomy") && ec.getClass().getName().equals("me.igwb.GoldenChest.GoldenChestEconomy")) { - economy.economy = (GoldenChestEconomy) ec; - log.info(String.format("[Economy] %s hooked.", economy.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (economy.economy != null) { - if (event.getPlugin().getDescription().getName().equals("GoldenChestEconomy")) { - economy.economy = null; - log.info(String.format("[Economy] %s unhooked.", economy.name)); - } - } - } - } - - - @Override - public boolean isEnabled() { - if (economy == null) { - return false; - } else { - return economy.isEnabled(); - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean hasBankSupport() { - return false; - } - - @Override - public int fractionalDigits() { - return economy.getVaultConnector().fractionalDigits(); - } - - @Override - public String format(double amount) { - return economy.getVaultConnector().format(amount); - } - - @Override - public String currencyNamePlural() { - return economy.getVaultConnector().currencyNamePlural(); - } - - @Override - public String currencyNameSingular() { - return economy.getVaultConnector().currencyNameSingular(); - } - - @Override - public boolean hasAccount(String playerName) { - return economy.getVaultConnector().hasAccount(playerName); - } - - @Override - public boolean hasAccount(String playerName, String worldName) { - return economy.getVaultConnector().hasAccount(playerName, worldName); - } - - @Override - public double getBalance(String playerName) { - return economy.getVaultConnector().getBalance(playerName); - } - - @Override - public double getBalance(String playerName, String world) { - return economy.getVaultConnector().getBalance(playerName, world); - } - - @Override - public boolean has(String playerName, double amount) { - return economy.getVaultConnector().has(playerName, amount); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return economy.getVaultConnector().has(playerName, worldName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - - if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds"); - } - - if (has(playerName, amount)) { - economy.getVaultConnector().withdrawPlayer(playerName, amount); - return new EconomyResponse(amount, getBalance(playerName), ResponseType.SUCCESS, null); - } else { - return new EconomyResponse(0, getBalance(playerName), ResponseType.FAILURE, "Insufficient funds"); - } - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, - double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, double amount) { - if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds"); - } - - economy.getVaultConnector().depositPlayer(playerName, amount); - return new EconomyResponse(amount, getBalance(playerName), EconomyResponse.ResponseType.SUCCESS, null); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, - double amount) { - return depositPlayer(playerName, amount); - } - - @Override - public EconomyResponse createBank(String name, String player) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); - } - - @Override - public EconomyResponse deleteBank(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); - } - - @Override - public EconomyResponse bankBalance(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); - } - - @Override - public EconomyResponse bankHas(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); - } - - @Override - public EconomyResponse bankWithdraw(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); - } - - @Override - public EconomyResponse bankDeposit(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); - } - - @Override - public EconomyResponse isBankOwner(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); - } - - @Override - public EconomyResponse isBankMember(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); - } - - @Override - public List getBanks() { - return null; - } - - @Override - public boolean createPlayerAccount(String playerName) { - return economy.getVaultConnector().createPlayerAccount(playerName); - } - - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return economy.getVaultConnector().createPlayerAccount(playerName, worldName); - } - + private final Logger log; + + private final String name = "GoldenChestEconomy"; + private GoldenChestEconomy economy; + + + public Economy_GoldenChestEconomy(final Plugin plugin) { + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + // Load Plugin in case it was loaded before + if (this.economy == null) { + final Plugin ec = plugin.getServer().getPluginManager().getPlugin("GoldenChestEconomy"); + if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("me.igwb.GoldenChest.GoldenChestEconomy")) { + this.economy = (GoldenChestEconomy) ec; + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } + } + + public class EconomyServerListener implements Listener { + final Economy_GoldenChestEconomy economy; + + public EconomyServerListener(final Economy_GoldenChestEconomy economy_GoldenChestEconomy) { + economy = economy_GoldenChestEconomy; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.economy.economy == null) { + final Plugin ec = event.getPlugin(); + + if (ec.getDescription().getName().equals("GoldenChestEconomy") && ec.getClass().getName().equals("me.igwb.GoldenChest.GoldenChestEconomy")) { + this.economy.economy = (GoldenChestEconomy) ec; + Economy_GoldenChestEconomy.this.log.info(String.format("[Economy] %s hooked.", this.economy.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.economy.economy != null) { + if (event.getPlugin().getDescription().getName().equals("GoldenChestEconomy")) { + this.economy.economy = null; + Economy_GoldenChestEconomy.this.log.info(String.format("[Economy] %s unhooked.", this.economy.name)); + } + } + } + } + + + @Override + public boolean isEnabled() { + if (this.economy == null) { + return false; + } else { + return this.economy.isEnabled(); + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean hasBankSupport() { + return false; + } + + @Override + public int fractionalDigits() { + return this.economy.getVaultConnector().fractionalDigits(); + } + + @Override + public String format(final double amount) { + return this.economy.getVaultConnector().format(amount); + } + + @Override + public String currencyNamePlural() { + return this.economy.getVaultConnector().currencyNamePlural(); + } + + @Override + public String currencyNameSingular() { + return this.economy.getVaultConnector().currencyNameSingular(); + } + + @Override + public boolean hasAccount(final String playerName) { + return this.economy.getVaultConnector().hasAccount(playerName); + } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return this.economy.getVaultConnector().hasAccount(playerName, worldName); + } + + @Override + public double getBalance(final String playerName) { + return this.economy.getVaultConnector().getBalance(playerName); + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.economy.getVaultConnector().getBalance(playerName, world); + } + + @Override + public boolean has(final String playerName, final double amount) { + return this.economy.getVaultConnector().has(playerName, amount); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.economy.getVaultConnector().has(playerName, worldName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final double amount) { + + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot withdraw negative funds"); + } + + if (this.has(playerName, amount)) { + this.economy.getVaultConnector().withdrawPlayer(playerName, amount); + return new EconomyResponse(amount, this.getBalance(playerName), EconomyResponse.ResponseType.SUCCESS, null); + } else { + return new EconomyResponse(0, this.getBalance(playerName), EconomyResponse.ResponseType.FAILURE, "Insufficient funds"); + } + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, + final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final double amount) { + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot desposit negative funds"); + } + + this.economy.getVaultConnector().depositPlayer(playerName, amount); + return new EconomyResponse(amount, this.getBalance(playerName), EconomyResponse.ResponseType.SUCCESS, null); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, + final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public EconomyResponse createBank(final String name, final String player) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); + } + + @Override + public EconomyResponse deleteBank(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); + } + + @Override + public EconomyResponse bankBalance(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); + } + + @Override + public EconomyResponse bankHas(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); + } + + @Override + public EconomyResponse bankWithdraw(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); + } + + @Override + public EconomyResponse bankDeposit(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); + } + + @Override + public EconomyResponse isBankOwner(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); + } + + @Override + public EconomyResponse isBankMember(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Banks are not supported!"); + } + + @Override + public List getBanks() { + return null; + } + + @Override + public boolean createPlayerAccount(final String playerName) { + return this.economy.getVaultConnector().createPlayerAccount(playerName); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + return this.economy.getVaultConnector().createPlayerAccount(playerName, worldName); + } + } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_Gringotts.java b/src/net/milkbowl/vault/economy/plugins/Economy_Gringotts.java index b91bdbfe..0aa87379 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_Gringotts.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_Gringotts.java @@ -15,14 +15,8 @@ */ package net.milkbowl.vault.economy.plugins; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; - import net.milkbowl.vault.economy.AbstractEconomy; import net.milkbowl.vault.economy.EconomyResponse; -import net.milkbowl.vault.economy.EconomyResponse.ResponseType; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -34,239 +28,241 @@ import org.gestern.gringotts.AccountHolder; import org.gestern.gringotts.Gringotts; -public class Economy_Gringotts extends AbstractEconomy { - - private final Logger log; - - private final String name = "Gringotts"; - private Plugin plugin = null; - private Gringotts gringotts = null; - - public Economy_Gringotts(Plugin plugin) { - this.plugin = plugin; - this.log = plugin.getLogger(); - Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - // Load Plugin in case it was loaded before - if (gringotts == null) { - Plugin grngts = plugin.getServer().getPluginManager().getPlugin("Gringotts"); - if (grngts != null && grngts.isEnabled()) { - gringotts = (Gringotts) grngts; - log.info(String.format("[Economy] %s hooked.", name)); - } - } - } - - public class EconomyServerListener implements Listener { - Economy_Gringotts economy = null; - - public EconomyServerListener(Economy_Gringotts economy_Gringotts) { - this.economy = economy_Gringotts; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (economy.gringotts == null) { - Plugin grngts = event.getPlugin(); - - if (grngts.getDescription().getName().equals("Gringotts")) { - economy.gringotts = (Gringotts) grngts; - log.info(String.format("[Economy] %s hooked.", economy.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (economy.gringotts != null) { - if (event.getPlugin().getDescription().getName().equals("Gringotts")) { - economy.gringotts = null; - log.info(String.format("[Economy] %s unhooked.", economy.name)); - } - } - } - } - - @Override - public boolean isEnabled(){ - return gringotts != null && gringotts.isEnabled(); - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean hasBankSupport(){ - return false; - } - - @Override - public int fractionalDigits(){ - return 2; - } - - @Override - public String format(double amount) { - return Double.toString(amount); - } - - @Override - public String currencyNamePlural(){ - return org.gestern.gringotts.Configuration.config.currencyNamePlural; - } - - @Override - public String currencyNameSingular(){ - return org.gestern.gringotts.Configuration.config.currencyNameSingular; - } - - @Override - public boolean hasAccount(String playerName) { - AccountHolder owner = gringotts.accountHolderFactory.getAccount(playerName); - if (owner == null) { - return false; - } - - return gringotts.accounting.getAccount(owner) != null; - } - - @Override - public double getBalance(String playerName){ - AccountHolder owner = gringotts.accountHolderFactory.getAccount(playerName); - if (owner == null) { - return 0; - } - Account account = gringotts.accounting.getAccount(owner); - return account.balance(); - } - - @Override - public boolean has(String playerName, double amount) { - return getBalance(playerName) >= amount; - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - - if( amount < 0 ) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw a negative amount."); - } - - AccountHolder accountHolder = gringotts.accountHolderFactory.getAccount(playerName); - if (accountHolder == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, playerName + " is not a valid account holder."); - } - - Account account = gringotts.accounting.getAccount( accountHolder ); - - if(account.balance() >= amount && account.remove(amount)) { - //We has mulah! - return new EconomyResponse(amount, account.balance(), ResponseType.SUCCESS, null); - } else { - //Not enough money to withdraw this much. - return new EconomyResponse(0, account.balance(), ResponseType.FAILURE, "Insufficient funds"); - } - - } - - @Override - public EconomyResponse depositPlayer(String playerName, double amount){ - if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds"); - } - - AccountHolder accountHolder = gringotts.accountHolderFactory.getAccount(playerName); - if (accountHolder == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, playerName + " is not a valid account holder."); - } - - Account account = gringotts.accounting.getAccount( accountHolder ); - - if (account.add(amount)) { - return new EconomyResponse( amount, account.balance(), ResponseType.SUCCESS, null); - } else { - return new EconomyResponse( 0, account.balance(), ResponseType.FAILURE, "Not enough capacity to store that amount!"); - } - } - - @Override - public EconomyResponse createBank(String name, String player) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); - } - - @Override - public EconomyResponse deleteBank(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); - } - - @Override - public EconomyResponse bankBalance(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); - } - - @Override - public EconomyResponse bankHas(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); - } - - @Override - public EconomyResponse bankWithdraw(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); - } - - @Override - public EconomyResponse bankDeposit(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); - } - - @Override - public EconomyResponse isBankOwner(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); - } - - @Override - public EconomyResponse isBankMember(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); - } - - @Override - public List getBanks() { - return new ArrayList(); - } - - @Override - public boolean createPlayerAccount(String playerName) { - return hasAccount(playerName); - } - - @Override - public boolean hasAccount(String playerName, String worldName) { - return hasAccount(playerName); - } - - @Override - public double getBalance(String playerName, String world) { - return getBalance(playerName); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - return depositPlayer(playerName, amount); - } +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return createPlayerAccount(playerName); - } +public class Economy_Gringotts extends AbstractEconomy { + + private final Logger log; + + private final String name = "Gringotts"; + private Gringotts gringotts; + + public Economy_Gringotts(final Plugin plugin) { + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + // Load Plugin in case it was loaded before + if (this.gringotts == null) { + final Plugin grngts = plugin.getServer().getPluginManager().getPlugin("Gringotts"); + if (grngts != null && grngts.isEnabled()) { + this.gringotts = (Gringotts) grngts; + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } + } + + public class EconomyServerListener implements Listener { + final Economy_Gringotts economy; + + public EconomyServerListener(final Economy_Gringotts economy_Gringotts) { + economy = economy_Gringotts; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.economy.gringotts == null) { + final Plugin grngts = event.getPlugin(); + + if (grngts.getDescription().getName().equals("Gringotts")) { + this.economy.gringotts = (Gringotts) grngts; + Economy_Gringotts.this.log.info(String.format("[Economy] %s hooked.", this.economy.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.economy.gringotts != null) { + if (event.getPlugin().getDescription().getName().equals("Gringotts")) { + this.economy.gringotts = null; + Economy_Gringotts.this.log.info(String.format("[Economy] %s unhooked.", this.economy.name)); + } + } + } + } + + @Override + public boolean isEnabled() { + return this.gringotts != null && this.gringotts.isEnabled(); + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean hasBankSupport() { + return false; + } + + @Override + public int fractionalDigits() { + return 2; + } + + @Override + public String format(final double amount) { + return Double.toString(amount); + } + + @Override + public String currencyNamePlural() { + return org.gestern.gringotts.Configuration.config.currencyNamePlural; + } + + @Override + public String currencyNameSingular() { + return org.gestern.gringotts.Configuration.config.currencyNameSingular; + } + + @Override + public boolean hasAccount(final String playerName) { + final AccountHolder owner = this.gringotts.accountHolderFactory.getAccount(playerName); + if (owner == null) { + return false; + } + + return this.gringotts.accounting.getAccount(owner) != null; + } + + @Override + public double getBalance(final String playerName) { + final AccountHolder owner = this.gringotts.accountHolderFactory.getAccount(playerName); + if (owner == null) { + return 0; + } + final Account account = this.gringotts.accounting.getAccount(owner); + return account.balance(); + } + + @Override + public boolean has(final String playerName, final double amount) { + return this.getBalance(playerName) >= amount; + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final double amount) { + + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot withdraw a negative amount."); + } + + final AccountHolder accountHolder = this.gringotts.accountHolderFactory.getAccount(playerName); + if (accountHolder == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, playerName + " is not a valid account holder."); + } + + final Account account = this.gringotts.accounting.getAccount(accountHolder); + + if (account.balance() >= amount && account.remove(amount)) { + //We has mulah! + return new EconomyResponse(amount, account.balance(), EconomyResponse.ResponseType.SUCCESS, null); + } else { + //Not enough money to withdraw this much. + return new EconomyResponse(0, account.balance(), EconomyResponse.ResponseType.FAILURE, "Insufficient funds"); + } + + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final double amount) { + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot desposit negative funds"); + } + + final AccountHolder accountHolder = this.gringotts.accountHolderFactory.getAccount(playerName); + if (accountHolder == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, playerName + " is not a valid account holder."); + } + + final Account account = this.gringotts.accounting.getAccount(accountHolder); + + if (account.add(amount)) { + return new EconomyResponse(amount, account.balance(), EconomyResponse.ResponseType.SUCCESS, null); + } else { + return new EconomyResponse(0, account.balance(), EconomyResponse.ResponseType.FAILURE, "Not enough capacity to store that amount!"); + } + } + + @Override + public EconomyResponse createBank(final String name, final String player) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); + } + + @Override + public EconomyResponse deleteBank(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); + } + + @Override + public EconomyResponse bankBalance(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); + } + + @Override + public EconomyResponse bankHas(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); + } + + @Override + public EconomyResponse bankWithdraw(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); + } + + @Override + public EconomyResponse bankDeposit(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); + } + + @Override + public EconomyResponse isBankOwner(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); + } + + @Override + public EconomyResponse isBankMember(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Gringotts does not support bank accounts!"); + } + + @Override + public List getBanks() { + return new ArrayList<>(); + } + + @Override + public boolean createPlayerAccount(final String playerName) { + return this.hasAccount(playerName); + } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return this.hasAccount(playerName); + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + return this.createPlayerAccount(playerName); + } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_MiConomy.java b/src/net/milkbowl/vault/economy/plugins/Economy_MiConomy.java index 34cfdd6e..82de0fc5 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_MiConomy.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_MiConomy.java @@ -17,14 +17,8 @@ import com.gmail.bleedobsidian.miconomy.Main; import com.gmail.bleedobsidian.miconomy.MiConomy; - -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; - import net.milkbowl.vault.economy.AbstractEconomy; import net.milkbowl.vault.economy.EconomyResponse; - import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.World; @@ -35,336 +29,336 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -public class Economy_MiConomy extends AbstractEconomy { - private final Logger log; - - private final String name = "MiConomy"; - - private Plugin plugin; - private MiConomy economy; - private Main miConomy; - - public Economy_MiConomy(Plugin plugin) { - this.plugin = plugin; - this.log = plugin.getLogger(); - Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - - // Load Plugin in case it was loaded before - if (miConomy == null) { - Plugin miConomyPlugin = plugin.getServer().getPluginManager().getPlugin("MiConomy"); - - if (miConomy != null) { - miConomy = (Main) miConomyPlugin; - economy = miConomy.getInstance(); - log.info(String.format("[Economy] %s hooked.", name)); - } - } - } - - @Override - public boolean isEnabled() { - if(miConomy == null) { - return false; - } else { - return miConomy.isEnabled(); - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean hasBankSupport() { - return true; - } - - @Override - public int fractionalDigits() { - return 2; - } - - @Override - public String format(double amount) { - return economy.getFormattedValue(amount); - } - - @Override - public String currencyNamePlural() { - return miConomy.getPluginConfig().MoneyNamePlural; - } - - @Override - public String currencyNameSingular() { - return miConomy.getPluginConfig().MoneyName; - } - - @Override - public boolean hasAccount(String playerName) { - List worlds = plugin.getServer().getWorlds(); - - return hasAccount(playerName, worlds.get(0).getName()); - } - - @Override - public boolean hasAccount(String playerName, String worldName) { - OfflinePlayer player = plugin.getServer().getOfflinePlayer(playerName); - World world = plugin.getServer().getWorld(worldName); - - return economy.isAccountCreated(player, world); - } - - @Override - public double getBalance(String playerName) { - List worlds = plugin.getServer().getWorlds(); - - return getBalance(playerName, worlds.get(0).getName()); - } - - @Override - public double getBalance(String playerName, String worldName) { - OfflinePlayer player = plugin.getServer().getOfflinePlayer(playerName); - World world = plugin.getServer().getWorld(worldName); - - return economy.getAccountBalance(player, world); - } - - @Override - public boolean has(String playerName, double amount) { - List worlds = plugin.getServer().getWorlds(); - - return has(playerName, worlds.get(0).getName(), amount); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - OfflinePlayer player = plugin.getServer().getOfflinePlayer(playerName); - World world = plugin.getServer().getWorld(worldName); - - double playerBalance = economy.getAccountBalance(player, world); - - if(playerBalance >= amount) { - return true; - } else { - return false; - } - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - List worlds = plugin.getServer().getWorlds(); - - return withdrawPlayer(playerName, worlds.get(0).getName(), amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - OfflinePlayer player = plugin.getServer().getOfflinePlayer(playerName); - World world = plugin.getServer().getWorld(worldName); - - double balance = economy.getAccountBalance(player, world); - - if(getBalance(playerName, worldName) < amount) { - return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, "Insufficient funds"); - } else { - if(economy.removeAccountBalance(player, amount, world)) { - balance = economy.getAccountBalance(player, world); - - return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.SUCCESS, ""); - } else { - return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, "Failed to remove funds from account"); - } - } - } - - @Override - public EconomyResponse depositPlayer(String playerName, double amount) { - List worlds = plugin.getServer().getWorlds(); - - return depositPlayer(playerName, worlds.get(0).getName(), amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - OfflinePlayer player = plugin.getServer().getOfflinePlayer(playerName); - World world = plugin.getServer().getWorld(worldName); - - double balance = economy.getAccountBalance(player, world); - - if(economy.addAccountBalance(player, amount, world)) { - balance = economy.getAccountBalance(player, world); - - return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.SUCCESS, ""); - } else { - return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, "Failed to add funds to account"); - } - } - - @Override - public EconomyResponse createBank(String name, String player) { - OfflinePlayer owner = plugin.getServer().getOfflinePlayer(player); - - ArrayList owners = new ArrayList(); - owners.add(owner); - - if(!economy.isBankCreated(name)) { - economy.createBank(name, owners, new ArrayList(), false); - return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, ""); - } else { - return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "A bank with this name already exists"); - } - } - - @Override - public EconomyResponse deleteBank(String name) { - if(economy.isBankCreated(name)) { - economy.deleteBank(name); - return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, ""); - } else { - return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Bank doesn't exist"); - } - } - - @Override - public EconomyResponse bankBalance(String name) { - if(economy.isBankCreated(name)) { - double balance = economy.getBankBalance(name); - return new EconomyResponse(0, balance, EconomyResponse.ResponseType.SUCCESS, ""); - } else { - return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Bank doesn't exist"); - } - } - - @Override - public EconomyResponse bankHas(String name, double amount) { - if(economy.isBankCreated(name)) { - double balance = economy.getBankBalance(name); - - if(balance >= amount) { - return new EconomyResponse(0, balance, EconomyResponse.ResponseType.SUCCESS, ""); - } else { - return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, "The bank does not have enough money!"); - } - } else { - return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Bank doesn't exist"); - } - } - - @Override - public EconomyResponse bankWithdraw(String name, double amount) { - if(economy.isBankCreated(name)) { - economy.removeBankBalance(name, amount); - - double balance = economy.getBankBalance(name); - - return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.SUCCESS, ""); - } else { - return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Bank doesn't exist"); - } - } - - @Override - public EconomyResponse bankDeposit(String name, double amount) { - if(economy.isBankCreated(name)) { - economy.addBankBalance(name, amount); - - double balance = economy.getBankBalance(name); - - return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.SUCCESS, ""); - } else { - return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Bank doesn't exist"); - } - } - - @Override - public EconomyResponse isBankOwner(String name, String playerName) { - OfflinePlayer owner = plugin.getServer().getOfflinePlayer(playerName); - - if(economy.isBankCreated(name)) { - if(economy.isPlayerBankOwner(name, owner)) { - return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, ""); - } else { - return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "The player is not a bank owner"); - } - } else { - return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Bank doesn't exist"); - } - } - - @Override - public EconomyResponse isBankMember(String name, String playerName) { - OfflinePlayer owner = plugin.getServer().getOfflinePlayer(playerName); - - if(economy.isBankCreated(name)) { - if(economy.isPlayerBankMember(name, owner)) { - return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, ""); - } else { - return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "The player is not a bank member"); - } - } else { - return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Bank doesn't exist"); - } - } - - @Override - public List getBanks() { - return economy.getBanks(); - } - - @Override - public boolean createPlayerAccount(String playerName) { - List worlds = plugin.getServer().getWorlds(); - - return createPlayerAccount(playerName, worlds.get(0).getName()); - } - - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - OfflinePlayer player = plugin.getServer().getOfflinePlayer(playerName); - World world = plugin.getServer().getWorld(worldName); - - if(!economy.isAccountCreated(player, world)) { - economy.createAccount(player, 0, world); - - return true; - } else { - return false; - } - } - - public class EconomyServerListener implements Listener { - Economy_MiConomy economy = null; - - public EconomyServerListener(Economy_MiConomy economy) { - this.economy = economy; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (economy.economy == null) { - Plugin miConomyPlugin = event.getPlugin(); - - if (miConomyPlugin.getDescription().getName().equals("MiConomy")) { - economy.miConomy = (Main) miConomyPlugin; - - economy.economy = miConomy.getInstance(); - - log.info(String.format("[Economy] %s hooked.", name)); - } - } - } +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (economy.economy != null) { - if (event.getPlugin().getDescription().getName().equals("MiConomy")) { - economy.miConomy = null; - economy.economy = null; - - log.info(String.format("[Economy] %s unhooked.", economy.name)); - } - } - } - } +public class Economy_MiConomy extends AbstractEconomy { + private final Logger log; + + private final String name = "MiConomy"; + + private final Plugin plugin; + private MiConomy economy; + private Main miConomy; + + public Economy_MiConomy(final Plugin plugin) { + this.plugin = plugin; + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + + // Load Plugin in case it was loaded before + if (this.miConomy == null) { + final Plugin miConomyPlugin = plugin.getServer().getPluginManager().getPlugin("MiConomy"); + + if (this.miConomy != null) { + this.miConomy = (Main) miConomyPlugin; + this.economy = this.miConomy.getInstance(); + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } + } + + @Override + public boolean isEnabled() { + if (this.miConomy == null) { + return false; + } else { + return this.miConomy.isEnabled(); + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean hasBankSupport() { + return true; + } + + @Override + public int fractionalDigits() { + return 2; + } + + @Override + public String format(final double amount) { + return this.economy.getFormattedValue(amount); + } + + @Override + public String currencyNamePlural() { + return this.miConomy.getPluginConfig().MoneyNamePlural; + } + + @Override + public String currencyNameSingular() { + return this.miConomy.getPluginConfig().MoneyName; + } + + @Override + public boolean hasAccount(final String playerName) { + final List worlds = this.plugin.getServer().getWorlds(); + + return this.hasAccount(playerName, worlds.get(0).getName()); + } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + final OfflinePlayer player = this.plugin.getServer().getOfflinePlayer(playerName); + final World world = this.plugin.getServer().getWorld(worldName); + + return this.economy.isAccountCreated(player, world); + } + + @Override + public double getBalance(final String playerName) { + final List worlds = this.plugin.getServer().getWorlds(); + + return this.getBalance(playerName, worlds.get(0).getName()); + } + + @Override + public double getBalance(final String playerName, final String worldName) { + final OfflinePlayer player = this.plugin.getServer().getOfflinePlayer(playerName); + final World world = this.plugin.getServer().getWorld(worldName); + + return this.economy.getAccountBalance(player, world); + } + + @Override + public boolean has(final String playerName, final double amount) { + final List worlds = this.plugin.getServer().getWorlds(); + + return this.has(playerName, worlds.get(0).getName(), amount); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + final OfflinePlayer player = this.plugin.getServer().getOfflinePlayer(playerName); + final World world = this.plugin.getServer().getWorld(worldName); + + final double playerBalance = this.economy.getAccountBalance(player, world); + + return playerBalance >= amount; + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final double amount) { + final List worlds = this.plugin.getServer().getWorlds(); + + return this.withdrawPlayer(playerName, worlds.get(0).getName(), amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + final OfflinePlayer player = this.plugin.getServer().getOfflinePlayer(playerName); + final World world = this.plugin.getServer().getWorld(worldName); + + double balance = this.economy.getAccountBalance(player, world); + + if (this.getBalance(playerName, worldName) < amount) { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, "Insufficient funds"); + } else { + if (this.economy.removeAccountBalance(player, amount, world)) { + balance = this.economy.getAccountBalance(player, world); + + return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.SUCCESS, ""); + } else { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, "Failed to remove funds from account"); + } + } + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final double amount) { + final List worlds = this.plugin.getServer().getWorlds(); + + return this.depositPlayer(playerName, worlds.get(0).getName(), amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + final OfflinePlayer player = this.plugin.getServer().getOfflinePlayer(playerName); + final World world = this.plugin.getServer().getWorld(worldName); + + double balance = this.economy.getAccountBalance(player, world); + + if (this.economy.addAccountBalance(player, amount, world)) { + balance = this.economy.getAccountBalance(player, world); + + return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.SUCCESS, ""); + } else { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, "Failed to add funds to account"); + } + } + + @Override + public EconomyResponse createBank(final String name, final String player) { + final OfflinePlayer owner = this.plugin.getServer().getOfflinePlayer(player); + + final ArrayList owners = new ArrayList<>(); + owners.add(owner); + + if (!this.economy.isBankCreated(name)) { + this.economy.createBank(name, owners, new ArrayList<>(), false); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, ""); + } else { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "A bank with this name already exists"); + } + } + + @Override + public EconomyResponse deleteBank(final String name) { + if (this.economy.isBankCreated(name)) { + this.economy.deleteBank(name); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, ""); + } else { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Bank doesn't exist"); + } + } + + @Override + public EconomyResponse bankBalance(final String name) { + if (this.economy.isBankCreated(name)) { + final double balance = this.economy.getBankBalance(name); + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.SUCCESS, ""); + } else { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Bank doesn't exist"); + } + } + + @Override + public EconomyResponse bankHas(final String name, final double amount) { + if (this.economy.isBankCreated(name)) { + final double balance = this.economy.getBankBalance(name); + + if (balance >= amount) { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.SUCCESS, ""); + } else { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, "The bank does not have enough money!"); + } + } else { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Bank doesn't exist"); + } + } + + @Override + public EconomyResponse bankWithdraw(final String name, final double amount) { + if (this.economy.isBankCreated(name)) { + this.economy.removeBankBalance(name, amount); + + final double balance = this.economy.getBankBalance(name); + + return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.SUCCESS, ""); + } else { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Bank doesn't exist"); + } + } + + @Override + public EconomyResponse bankDeposit(final String name, final double amount) { + if (this.economy.isBankCreated(name)) { + this.economy.addBankBalance(name, amount); + + final double balance = this.economy.getBankBalance(name); + + return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.SUCCESS, ""); + } else { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Bank doesn't exist"); + } + } + + @Override + public EconomyResponse isBankOwner(final String name, final String playerName) { + final OfflinePlayer owner = this.plugin.getServer().getOfflinePlayer(playerName); + + if (this.economy.isBankCreated(name)) { + if (this.economy.isPlayerBankOwner(name, owner)) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, ""); + } else { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "The player is not a bank owner"); + } + } else { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Bank doesn't exist"); + } + } + + @Override + public EconomyResponse isBankMember(final String name, final String playerName) { + final OfflinePlayer owner = this.plugin.getServer().getOfflinePlayer(playerName); + + if (this.economy.isBankCreated(name)) { + if (this.economy.isPlayerBankMember(name, owner)) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, ""); + } else { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "The player is not a bank member"); + } + } else { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Bank doesn't exist"); + } + } + + @Override + public List getBanks() { + return this.economy.getBanks(); + } + + @Override + public boolean createPlayerAccount(final String playerName) { + final List worlds = this.plugin.getServer().getWorlds(); + + return this.createPlayerAccount(playerName, worlds.get(0).getName()); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + final OfflinePlayer player = this.plugin.getServer().getOfflinePlayer(playerName); + final World world = this.plugin.getServer().getWorld(worldName); + + if (!this.economy.isAccountCreated(player, world)) { + this.economy.createAccount(player, 0, world); + + return true; + } else { + return false; + } + } + + public class EconomyServerListener implements Listener { + final Economy_MiConomy economy; + + public EconomyServerListener(final Economy_MiConomy economy) { + this.economy = economy; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.economy.economy == null) { + final Plugin miConomyPlugin = event.getPlugin(); + + if (miConomyPlugin.getDescription().getName().equals("MiConomy")) { + this.economy.miConomy = (Main) miConomyPlugin; + + this.economy.economy = Economy_MiConomy.this.miConomy.getInstance(); + + Economy_MiConomy.this.log.info(String.format("[Economy] %s hooked.", Economy_MiConomy.this.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.economy.economy != null) { + if (event.getPlugin().getDescription().getName().equals("MiConomy")) { + this.economy.miConomy = null; + this.economy.economy = null; + + Economy_MiConomy.this.log.info(String.format("[Economy] %s unhooked.", this.economy.name)); + } + } + } + } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_MineConomy.java b/src/net/milkbowl/vault/economy/plugins/Economy_MineConomy.java index 3b301ec9..a406bd11 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_MineConomy.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_MineConomy.java @@ -15,10 +15,6 @@ */ package net.milkbowl.vault.economy.plugins; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; - import me.mjolnir.mineconomy.MineConomy; import me.mjolnir.mineconomy.exceptions.AccountNameConflictException; import me.mjolnir.mineconomy.exceptions.NoAccountException; @@ -26,8 +22,6 @@ import me.mjolnir.mineconomy.internal.util.MCFormat; import net.milkbowl.vault.economy.AbstractEconomy; import net.milkbowl.vault.economy.EconomyResponse; -import net.milkbowl.vault.economy.EconomyResponse.ResponseType; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -36,237 +30,236 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -public class Economy_MineConomy extends AbstractEconomy { - private final Logger log; - private final String name = "MineConomy"; - private Plugin plugin = null; - private MineConomy econ = null; - - public Economy_MineConomy(Plugin plugin) { - this.plugin = plugin; - this.log = plugin.getLogger(); - Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - - // Load Plugin in case it was loaded before - if (econ == null) { - Plugin econ = plugin.getServer().getPluginManager().getPlugin("MineConomy"); - if (econ != null && econ.isEnabled()) { - this.econ = (MineConomy) econ; - log.info(String.format("[Economy] %s hooked.", name)); - } - } - } - - public class EconomyServerListener implements Listener { - Economy_MineConomy economy = null; - - public EconomyServerListener(Economy_MineConomy economy) { - this.economy = economy; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (economy.econ == null) { - Plugin eco = event.getPlugin(); - - if (eco.getDescription().getName().equals("MineConomy")) { - economy.econ = (MineConomy) eco; - log.info(String.format("[Economy] %s hooked.", economy.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (economy.econ != null) { - if (event.getPlugin().getDescription().getName().equals("MineConomy")) { - economy.econ = null; - log.info(String.format("[Economy] %s unhooked.", economy.name)); - } - } - } - } - - public boolean isEnabled() { - return econ != null; - } - - public String getName() { - return "MineConomy"; - } - - public String format(double amount) { - return MCFormat.format(amount); - } - - public String currencyNameSingular() { - return MCCom.getDefaultCurrency(); - } - - public String currencyNamePlural() { - return MCCom.getDefaultCurrency(); - } - - public double getBalance(String playerName) { - try - { - return MCCom.getExternalBalance(playerName); - } - catch (NoAccountException e) - { - MCCom.create(playerName); - return MCCom.getExternalBalance(playerName); - } - } - - @Override - public boolean has(String playerName, double amount) { - try { - return MCCom.canExternalAfford(playerName, amount); - } catch(NoAccountException e) { - MCCom.create(playerName); - return MCCom.canExternalAfford(playerName, amount); - } - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - double balance; - try { - balance = MCCom.getExternalBalance(playerName); - } catch (NoAccountException e) { - MCCom.create(playerName); - balance = MCCom.getExternalBalance(playerName); - } - - if(amount < 0.0D) { - return new EconomyResponse(0.0D, balance, ResponseType.FAILURE, "Cannot withdraw negative funds"); - } - - if(balance >= amount) { - double finalBalance = balance - amount; - MCCom.setExternalBalance(playerName, finalBalance); - return new EconomyResponse(amount, finalBalance, ResponseType.SUCCESS, null); - } else { - return new EconomyResponse(0.0D, balance, ResponseType.FAILURE, "Insufficient funds"); - } - } - - @Override - public EconomyResponse depositPlayer(String playerName, double amount) { - double balance; - try { - balance = MCCom.getExternalBalance(playerName); - } catch (NoAccountException e) { - MCCom.create(playerName); - balance = MCCom.getExternalBalance(playerName); - } - if(amount < 0.0D) { - return new EconomyResponse(0.0D, 0.0, ResponseType.FAILURE, "Cannot deposit negative funds"); - } - - balance += amount; - MCCom.setExternalBalance(playerName, balance); - return new EconomyResponse(amount, balance, ResponseType.SUCCESS, null); - - } - - @Override - public EconomyResponse createBank(String name, String player) { - return new EconomyResponse(0.0D, 0.0D, ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); - } - - @Override - public EconomyResponse deleteBank(String name) { - return new EconomyResponse(0.0D, 0.0D, ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); - } - - @Override - public EconomyResponse bankHas(String name, double amount) { - return new EconomyResponse(0.0D, 0.0D, ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); - } - - @Override - public EconomyResponse bankWithdraw(String name, double amount) { - return new EconomyResponse(0.0D, 0.0D, ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); - } - - @Override - public EconomyResponse bankDeposit(String name, double amount) { - return new EconomyResponse(0.0D, 0.0D, ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); - } - - @Override - public EconomyResponse isBankOwner(String name, String playerName) { - return new EconomyResponse(0.0D, 0.0D, ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); - } - - @Override - public EconomyResponse isBankMember(String name, String playerName) { - return new EconomyResponse(0.0D, 0.0D, ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); - } - - @Override - public EconomyResponse bankBalance(String name) { - return new EconomyResponse(0.0D, 0.0D, ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); - } - - @Override - public List getBanks() { - return new ArrayList(); - } - - @Override - public boolean hasBankSupport() { - return false; - } - - @Override - public boolean hasAccount(String playerName) { - return MCCom.exists(playerName); - } - - public boolean createPlayerAccount(String playerName) { - try { - MCCom.create(playerName); - return true; - } catch(AccountNameConflictException e) { - return false; - } - } - - @Override - public int fractionalDigits() { - return 2; - } - - @Override - public boolean hasAccount(String playerName, String worldName) { - return hasAccount(playerName); - } - - @Override - public double getBalance(String playerName, String world) { - return getBalance(playerName); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - return depositPlayer(playerName, amount); - } +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return createPlayerAccount(playerName); - } +public class Economy_MineConomy extends AbstractEconomy { + private final Logger log; + private final String name = "MineConomy"; + private MineConomy econ; + + public Economy_MineConomy(final Plugin plugin) { + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + + // Load Plugin in case it was loaded before + if (this.econ == null) { + final Plugin econ = plugin.getServer().getPluginManager().getPlugin("MineConomy"); + if (econ != null && econ.isEnabled()) { + this.econ = (MineConomy) econ; + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } + } + + public class EconomyServerListener implements Listener { + final Economy_MineConomy economy; + + public EconomyServerListener(final Economy_MineConomy economy) { + this.economy = economy; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.economy.econ == null) { + final Plugin eco = event.getPlugin(); + + if (eco.getDescription().getName().equals("MineConomy")) { + this.economy.econ = (MineConomy) eco; + Economy_MineConomy.this.log.info(String.format("[Economy] %s hooked.", this.economy.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.economy.econ != null) { + if (event.getPlugin().getDescription().getName().equals("MineConomy")) { + this.economy.econ = null; + Economy_MineConomy.this.log.info(String.format("[Economy] %s unhooked.", this.economy.name)); + } + } + } + } + + public boolean isEnabled() { + return this.econ != null; + } + + public String getName() { + return "MineConomy"; + } + + public String format(final double amount) { + return MCFormat.format(amount); + } + + public String currencyNameSingular() { + return MCCom.getDefaultCurrency(); + } + + public String currencyNamePlural() { + return MCCom.getDefaultCurrency(); + } + + public double getBalance(final String playerName) { + try { + return MCCom.getExternalBalance(playerName); + } catch (final NoAccountException e) { + MCCom.create(playerName); + return MCCom.getExternalBalance(playerName); + } + } + + @Override + public boolean has(final String playerName, final double amount) { + try { + return MCCom.canExternalAfford(playerName, amount); + } catch (final NoAccountException e) { + MCCom.create(playerName); + return MCCom.canExternalAfford(playerName, amount); + } + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final double amount) { + double balance; + try { + balance = MCCom.getExternalBalance(playerName); + } catch (final NoAccountException e) { + MCCom.create(playerName); + balance = MCCom.getExternalBalance(playerName); + } + + if (amount < 0.0D) { + return new EconomyResponse(0.0D, balance, EconomyResponse.ResponseType.FAILURE, "Cannot withdraw negative funds"); + } + + if (balance >= amount) { + final double finalBalance = balance - amount; + MCCom.setExternalBalance(playerName, finalBalance); + return new EconomyResponse(amount, finalBalance, EconomyResponse.ResponseType.SUCCESS, null); + } else { + return new EconomyResponse(0.0D, balance, EconomyResponse.ResponseType.FAILURE, "Insufficient funds"); + } + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final double amount) { + double balance; + try { + balance = MCCom.getExternalBalance(playerName); + } catch (final NoAccountException e) { + MCCom.create(playerName); + balance = MCCom.getExternalBalance(playerName); + } + if (amount < 0.0D) { + return new EconomyResponse(0.0D, 0.0, EconomyResponse.ResponseType.FAILURE, "Cannot deposit negative funds"); + } + + balance += amount; + MCCom.setExternalBalance(playerName, balance); + return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.SUCCESS, null); + + } + + @Override + public EconomyResponse createBank(final String name, final String player) { + return new EconomyResponse(0.0D, 0.0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); + } + + @Override + public EconomyResponse deleteBank(final String name) { + return new EconomyResponse(0.0D, 0.0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); + } + + @Override + public EconomyResponse bankHas(final String name, final double amount) { + return new EconomyResponse(0.0D, 0.0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); + } + + @Override + public EconomyResponse bankWithdraw(final String name, final double amount) { + return new EconomyResponse(0.0D, 0.0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); + } + + @Override + public EconomyResponse bankDeposit(final String name, final double amount) { + return new EconomyResponse(0.0D, 0.0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); + } + + @Override + public EconomyResponse isBankOwner(final String name, final String playerName) { + return new EconomyResponse(0.0D, 0.0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); + } + + @Override + public EconomyResponse isBankMember(final String name, final String playerName) { + return new EconomyResponse(0.0D, 0.0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); + } + + @Override + public EconomyResponse bankBalance(final String name) { + return new EconomyResponse(0.0D, 0.0D, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MineConomy does not support bank accounts!"); + } + + @Override + public List getBanks() { + return new ArrayList<>(); + } + + @Override + public boolean hasBankSupport() { + return false; + } + + @Override + public boolean hasAccount(final String playerName) { + return MCCom.exists(playerName); + } + + public boolean createPlayerAccount(final String playerName) { + try { + MCCom.create(playerName); + return true; + } catch (final AccountNameConflictException e) { + return false; + } + } + + @Override + public int fractionalDigits() { + return 2; + } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return this.hasAccount(playerName); + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + return this.createPlayerAccount(playerName); + } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_MultiCurrency.java b/src/net/milkbowl/vault/economy/plugins/Economy_MultiCurrency.java index 04de619e..fb0e0b1c 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_MultiCurrency.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_MultiCurrency.java @@ -15,16 +15,10 @@ */ package net.milkbowl.vault.economy.plugins; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; - import me.ashtheking.currency.Currency; import me.ashtheking.currency.CurrencyList; import net.milkbowl.vault.economy.AbstractEconomy; import net.milkbowl.vault.economy.EconomyResponse; -import net.milkbowl.vault.economy.EconomyResponse.ResponseType; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -33,262 +27,263 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -public class Economy_MultiCurrency extends AbstractEconomy { - private final Logger log; - private final String name = "MultiCurrency"; - private Plugin plugin = null; - private Currency economy = null; - - public Economy_MultiCurrency(Plugin plugin) { - this.plugin = plugin; - this.log = plugin.getLogger(); - Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - - // Load Plugin in case it was loaded before - if (economy == null) { - Plugin multiCurrency = plugin.getServer().getPluginManager().getPlugin("MultiCurrency"); - if (multiCurrency != null && multiCurrency.isEnabled()) { - economy = (Currency) multiCurrency; - log.info(String.format("[Economy] %s hooked.", name)); - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean isEnabled() { - if (economy == null) { - return false; - } else { - return economy.isEnabled(); - } - } - - @Override - public double getBalance(String playerName) { - final double balance; - - balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); - - final double fBalance = balance; - return fBalance; - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - double balance; - EconomyResponse.ResponseType type; - String errorMessage = null; - - if (amount < 0) { - errorMessage = "Cannot withdraw negative funds"; - type = EconomyResponse.ResponseType.FAILURE; - amount = 0; - balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); - - return new EconomyResponse(amount, balance, type, errorMessage); - } - - if (!CurrencyList.hasEnough(playerName, amount)) { - errorMessage = "Insufficient funds"; - type = EconomyResponse.ResponseType.FAILURE; - amount = 0; - balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); - - return new EconomyResponse(amount, balance, type, errorMessage); - } - - if (CurrencyList.subtract(playerName, amount)) { - type = EconomyResponse.ResponseType.SUCCESS; - balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); - - return new EconomyResponse(amount, balance, type, errorMessage); - } else { - errorMessage = "Error withdrawing funds"; - type = EconomyResponse.ResponseType.FAILURE; - amount = 0; - balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); - - return new EconomyResponse(amount, balance, type, errorMessage); - } - } - - @Override - public EconomyResponse depositPlayer(String playerName, double amount) { - double balance; - EconomyResponse.ResponseType type; - String errorMessage = null; - - if (amount < 0) { - errorMessage = "Cannot deposit negative funds"; - type = EconomyResponse.ResponseType.FAILURE; - amount = 0; - balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); - - return new EconomyResponse(amount, balance, type, errorMessage); - } - - if (CurrencyList.add(playerName, amount)) { - type = EconomyResponse.ResponseType.SUCCESS; - balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); - - return new EconomyResponse(amount, balance, type, errorMessage); - } else { - errorMessage = "Error withdrawing funds"; - type = EconomyResponse.ResponseType.FAILURE; - amount = 0; - balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); - - return new EconomyResponse(amount, balance, type, errorMessage); - } - } - - public class EconomyServerListener implements Listener { - Economy_MultiCurrency economy = null; - - public EconomyServerListener(Economy_MultiCurrency economy) { - this.economy = economy; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (economy.economy == null) { - Plugin mcur = event.getPlugin(); - - if (mcur.getDescription().getName().equals("MultiCurrency")) { - economy.economy = (Currency) mcur; - log.info(String.format("[Economy] %s hooked.", economy.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (economy.economy != null) { - if (event.getPlugin().getDescription().getName().equals("MultiCurrency")) { - economy.economy = null; - log.info(String.format("[Economy] %s unhooked.", economy.name)); - } - } - } - } - - @Override - public String format(double amount) { - return String.format("%.2f %s", amount, "currency"); - } - - @Override - public String currencyNameSingular() { - return "currency"; - } - - @Override - public String currencyNamePlural() { - return "currency"; - } - - @Override - public boolean has(String playerName, double amount) { - return getBalance(playerName) >= amount; - } - - @Override - public EconomyResponse createBank(String name, String player) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts"); - } - - @Override - public EconomyResponse deleteBank(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts!"); - } - - @Override - public EconomyResponse bankHas(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts"); - } - - @Override - public EconomyResponse bankWithdraw(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts"); - } - - @Override - public EconomyResponse bankDeposit(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts"); - } - - @Override - public EconomyResponse isBankOwner(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts"); - } - - @Override - public EconomyResponse isBankMember(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts"); - } - - @Override - public EconomyResponse bankBalance(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts"); - } - - @Override - public List getBanks() { - return new ArrayList(); - } - - @Override - public boolean hasBankSupport() { - return false; - } - - @Override - public boolean hasAccount(String playerName) { - return true; - } - - @Override - public boolean createPlayerAccount(String playerName) { - return false; - } +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; +public class Economy_MultiCurrency extends AbstractEconomy { + private final Logger log; + private final String name = "MultiCurrency"; + private Currency economy; + + public Economy_MultiCurrency(final Plugin plugin) { + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + + // Load Plugin in case it was loaded before + if (this.economy == null) { + final Plugin multiCurrency = plugin.getServer().getPluginManager().getPlugin("MultiCurrency"); + if (multiCurrency != null && multiCurrency.isEnabled()) { + this.economy = (Currency) multiCurrency; + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean isEnabled() { + if (this.economy == null) { + return false; + } else { + return this.economy.isEnabled(); + } + } + + @Override + public double getBalance(final String playerName) { + double balance; + + balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); + + return balance; + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, double amount) { + final double balance; + final EconomyResponse.ResponseType type; + String errorMessage = null; + + if (amount < 0) { + errorMessage = "Cannot withdraw negative funds"; + type = EconomyResponse.ResponseType.FAILURE; + amount = 0; + balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); + + return new EconomyResponse(amount, balance, type, errorMessage); + } + + if (!CurrencyList.hasEnough(playerName, amount)) { + errorMessage = "Insufficient funds"; + type = EconomyResponse.ResponseType.FAILURE; + amount = 0; + balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); + + return new EconomyResponse(amount, balance, type, errorMessage); + } + + if (CurrencyList.subtract(playerName, amount)) { + type = EconomyResponse.ResponseType.SUCCESS; + balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); + + return new EconomyResponse(amount, balance, type, errorMessage); + } else { + errorMessage = "Error withdrawing funds"; + type = EconomyResponse.ResponseType.FAILURE; + amount = 0; + balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); + + return new EconomyResponse(amount, balance, type, errorMessage); + } + } + + @Override + public EconomyResponse depositPlayer(final String playerName, double amount) { + final double balance; + final EconomyResponse.ResponseType type; + String errorMessage = null; + + if (amount < 0) { + errorMessage = "Cannot deposit negative funds"; + type = EconomyResponse.ResponseType.FAILURE; + amount = 0; + balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); + + return new EconomyResponse(amount, balance, type, errorMessage); + } + + if (CurrencyList.add(playerName, amount)) { + type = EconomyResponse.ResponseType.SUCCESS; + balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); + + return new EconomyResponse(amount, balance, type, errorMessage); + } else { + errorMessage = "Error withdrawing funds"; + type = EconomyResponse.ResponseType.FAILURE; + amount = 0; + balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName); + + return new EconomyResponse(amount, balance, type, errorMessage); + } + } + + public class EconomyServerListener implements Listener { + final Economy_MultiCurrency economy; + + public EconomyServerListener(final Economy_MultiCurrency economy) { + this.economy = economy; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.economy.economy == null) { + final Plugin mcur = event.getPlugin(); + + if (mcur.getDescription().getName().equals("MultiCurrency")) { + this.economy.economy = (Currency) mcur; + Economy_MultiCurrency.this.log.info(String.format("[Economy] %s hooked.", this.economy.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.economy.economy != null) { + if (event.getPlugin().getDescription().getName().equals("MultiCurrency")) { + this.economy.economy = null; + Economy_MultiCurrency.this.log.info(String.format("[Economy] %s unhooked.", this.economy.name)); + } + } + } + } + + @Override + public String format(final double amount) { + return String.format("%.2f %s", amount, "currency"); + } + + @Override + public String currencyNameSingular() { + return "currency"; + } + + @Override + public String currencyNamePlural() { + return "currency"; + } + + @Override + public boolean has(final String playerName, final double amount) { + return this.getBalance(playerName) >= amount; + } + + @Override + public EconomyResponse createBank(final String name, final String player) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts"); + } + + @Override + public EconomyResponse deleteBank(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts!"); + } + + @Override + public EconomyResponse bankHas(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts"); + } + + @Override + public EconomyResponse bankWithdraw(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts"); + } + + @Override + public EconomyResponse bankDeposit(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts"); + } + + @Override + public EconomyResponse isBankOwner(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts"); + } + + @Override + public EconomyResponse isBankMember(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts"); + } + + @Override + public EconomyResponse bankBalance(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "MultiCurrency does not support bank accounts"); + } + + @Override + public List getBanks() { + return new ArrayList<>(); + } + + @Override + public boolean hasBankSupport() { + return false; + } + + @Override + public boolean hasAccount(final String playerName) { + return true; + } + + @Override + public boolean createPlayerAccount(final String playerName) { + return false; + } + @Override public int fractionalDigits() { return -1; } - - @Override - public boolean hasAccount(String playerName, String worldName) { - return hasAccount(playerName); - } - - @Override - public double getBalance(String playerName, String world) { - return getBalance(playerName); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - return depositPlayer(playerName, amount); - } - - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return createPlayerAccount(playerName); - } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return this.hasAccount(playerName); + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + return this.createPlayerAccount(playerName); + } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_SDFEconomy.java b/src/net/milkbowl/vault/economy/plugins/Economy_SDFEconomy.java index f6317c8c..119c5ac2 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_SDFEconomy.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_SDFEconomy.java @@ -15,214 +15,212 @@ */ package net.milkbowl.vault.economy.plugins; -import java.util.List; -import java.util.logging.Logger; - -import org.bukkit.plugin.Plugin; +import com.github.omwah.SDFEconomy.SDFEconomy; +import com.github.omwah.SDFEconomy.SDFEconomyAPI; +import net.milkbowl.vault.economy.AbstractEconomy; +import net.milkbowl.vault.economy.EconomyResponse; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; +import org.bukkit.plugin.Plugin; -import com.github.omwah.SDFEconomy.SDFEconomy; -import com.github.omwah.SDFEconomy.SDFEconomyAPI; - -import net.milkbowl.vault.economy.AbstractEconomy; -import net.milkbowl.vault.economy.EconomyResponse; +import java.util.List; +import java.util.logging.Logger; public class Economy_SDFEconomy extends AbstractEconomy { - private final Logger log; - private final String name = "SDFEconomy"; - private Plugin plugin = null; - private SDFEconomyAPI api = null; - - public Economy_SDFEconomy(Plugin plugin) { - this.plugin = plugin; - this.log = plugin.getLogger(); - // Register a listener to wait for plugin being loaded - plugin.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - - // Try and Load API in case plugin was loaded before Vault - load_api(); - } - - public void load_api() { - SDFEconomy pluginSDF = (SDFEconomy) plugin.getServer().getPluginManager().getPlugin("SDFEconomy"); - if(!isEnabled() && pluginSDF != null) { - api = pluginSDF.getAPI(); - log.info(String.format("[Economy] %s hooked.", name)); - } - } - - public void unload_api() { - SDFEconomy pluginSDF = (SDFEconomy) plugin.getServer().getPluginManager().getPlugin("SDFEconomy"); - if(isEnabled() && pluginSDF != null) { - api = null; - log.info(String.format("[Economy] %s unhooked.", name)); - } - } - - public class EconomyServerListener implements Listener { - Economy_SDFEconomy economy = null; - - public EconomyServerListener(Economy_SDFEconomy economy) { - this.economy = economy; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (event.getPlugin().getDescription().getName().equals("SDFEconomy")) { - economy.load_api(); - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (event.getPlugin().getDescription().getName().equals("SDFEconomy")) { - economy.unload_api(); - } - } - } - - - @Override - public boolean isEnabled() { - return api != null; - } - - @Override - public String getName() { - return "SDFEconomy"; - } - - @Override - public boolean hasBankSupport() { - return api.hasBankSupport(); - } - - @Override - public int fractionalDigits() { - return api.fractionalDigits(); - } - - @Override - public String format(double amount) { - return api.format(amount); - } - - @Override - public String currencyNamePlural() { - return api.currencyNamePlural(); - } - - @Override - public String currencyNameSingular() { - return api.currencyNameSingular(); - } - - @Override - public boolean hasAccount(String playerName) { - return api.hasAccount(playerName); - } - - @Override - public double getBalance(String playerName) { - return api.getBalance(playerName); - } - - @Override - public boolean has(String playerName, double amount) { - return api.has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - return api.withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, double amount) { - return api.depositPlayer(playerName, amount); - } - - @Override - public EconomyResponse createBank(String name, String player) { - return api.createBank(name, player); - } - - @Override - public EconomyResponse deleteBank(String name) { - return api.deleteBank(name); - } - - @Override - public EconomyResponse bankBalance(String name) { - return api.bankBalance(name); - } - - @Override - public EconomyResponse bankHas(String name, double amount) { - return api.bankHas(name, amount); - } - - @Override - public EconomyResponse bankWithdraw(String name, double amount) { - return api.bankWithdraw(name, amount); - } - - @Override - public EconomyResponse bankDeposit(String name, double amount) { - return api.bankDeposit(name, amount); - } - - @Override - public EconomyResponse isBankOwner(String name, String playerName) { - return api.isBankOwner(name, playerName); - } - - @Override - public EconomyResponse isBankMember(String name, String playerName) { - return api.isBankMember(name, playerName); - } - - @Override - public List getBanks() { - return api.getBankNames(); - } - - @Override - public boolean createPlayerAccount(String playerName) { - return api.createPlayerAccount(playerName); - } - - @Override - public boolean hasAccount(String playerName, String worldName) { - return hasAccount(playerName); - } - - @Override - public double getBalance(String playerName, String world) { - return getBalance(playerName); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - return depositPlayer(playerName, amount); - } - - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return createPlayerAccount(playerName); - } + private final Logger log; + private final String name = "SDFEconomy"; + private final Plugin plugin; + private SDFEconomyAPI api; + + public Economy_SDFEconomy(final Plugin plugin) { + this.plugin = plugin; + log = plugin.getLogger(); + // Register a listener to wait for plugin being loaded + plugin.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + + // Try and Load API in case plugin was loaded before Vault + this.load_api(); + } + + public void load_api() { + final SDFEconomy pluginSDF = (SDFEconomy) this.plugin.getServer().getPluginManager().getPlugin("SDFEconomy"); + if (!this.isEnabled() && pluginSDF != null) { + this.api = pluginSDF.getAPI(); + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } + + public void unload_api() { + final SDFEconomy pluginSDF = (SDFEconomy) this.plugin.getServer().getPluginManager().getPlugin("SDFEconomy"); + if (this.isEnabled() && pluginSDF != null) { + this.api = null; + this.log.info(String.format("[Economy] %s unhooked.", this.name)); + } + } + + public static class EconomyServerListener implements Listener { + final Economy_SDFEconomy economy; + + public EconomyServerListener(final Economy_SDFEconomy economy) { + this.economy = economy; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (event.getPlugin().getDescription().getName().equals("SDFEconomy")) { + this.economy.load_api(); + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (event.getPlugin().getDescription().getName().equals("SDFEconomy")) { + this.economy.unload_api(); + } + } + } + + + @Override + public boolean isEnabled() { + return this.api != null; + } + + @Override + public String getName() { + return "SDFEconomy"; + } + + @Override + public boolean hasBankSupport() { + return this.api.hasBankSupport(); + } + + @Override + public int fractionalDigits() { + return this.api.fractionalDigits(); + } + + @Override + public String format(final double amount) { + return this.api.format(amount); + } + + @Override + public String currencyNamePlural() { + return this.api.currencyNamePlural(); + } + + @Override + public String currencyNameSingular() { + return this.api.currencyNameSingular(); + } + + @Override + public boolean hasAccount(final String playerName) { + return this.api.hasAccount(playerName); + } + + @Override + public double getBalance(final String playerName) { + return this.api.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final double amount) { + return this.api.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final double amount) { + return this.api.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final double amount) { + return this.api.depositPlayer(playerName, amount); + } + + @Override + public EconomyResponse createBank(final String name, final String player) { + return this.api.createBank(name, player); + } + + @Override + public EconomyResponse deleteBank(final String name) { + return this.api.deleteBank(name); + } + + @Override + public EconomyResponse bankBalance(final String name) { + return this.api.bankBalance(name); + } + + @Override + public EconomyResponse bankHas(final String name, final double amount) { + return this.api.bankHas(name, amount); + } + + @Override + public EconomyResponse bankWithdraw(final String name, final double amount) { + return this.api.bankWithdraw(name, amount); + } + + @Override + public EconomyResponse bankDeposit(final String name, final double amount) { + return this.api.bankDeposit(name, amount); + } + + @Override + public EconomyResponse isBankOwner(final String name, final String playerName) { + return this.api.isBankOwner(name, playerName); + } + + @Override + public EconomyResponse isBankMember(final String name, final String playerName) { + return this.api.isBankMember(name, playerName); + } + + @Override + public List getBanks() { + return this.api.getBankNames(); + } + + @Override + public boolean createPlayerAccount(final String playerName) { + return this.api.createPlayerAccount(playerName); + } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return this.hasAccount(playerName); + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + return this.createPlayerAccount(playerName); + } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_TAEcon.java b/src/net/milkbowl/vault/economy/plugins/Economy_TAEcon.java index e2c55aca..f42d0994 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_TAEcon.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_TAEcon.java @@ -15,10 +15,9 @@ */ package net.milkbowl.vault.economy.plugins; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; - +import net.milkbowl.vault.economy.AbstractEconomy; +import net.milkbowl.vault.economy.EconomyResponse; +import net.teamalpha.taecon.TAEcon; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -27,233 +26,230 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import net.milkbowl.vault.economy.AbstractEconomy; -import net.milkbowl.vault.economy.EconomyResponse; -import net.milkbowl.vault.economy.EconomyResponse.ResponseType; -import net.teamalpha.taecon.TAEcon; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; public class Economy_TAEcon extends AbstractEconomy { private final Logger log; private final String name = "TAEcon"; - private Plugin plugin = null; - private TAEcon economy = null; - - public Economy_TAEcon(Plugin plugin){ - this.plugin = plugin; - this.log = plugin.getLogger(); + private TAEcon economy; + + public Economy_TAEcon(final Plugin plugin) { + log = plugin.getLogger(); Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - if (economy == null) { - Plugin taecon = plugin.getServer().getPluginManager().getPlugin(name); - - if (taecon != null && taecon.isEnabled()) { - economy = (TAEcon) taecon; - log.info(String.format("[Economy] %s hooked.", name)); - } - } + if (this.economy == null) { + final Plugin taecon = plugin.getServer().getPluginManager().getPlugin(this.name); + + if (taecon != null && taecon.isEnabled()) { + this.economy = (TAEcon) taecon; + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } } public class EconomyServerListener implements Listener { - Economy_TAEcon economy = null; - - public EconomyServerListener(Economy_TAEcon economy) { - this.economy = economy; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (economy.economy == null) { - Plugin taecon = event.getPlugin(); - - if (taecon.getDescription().getName().equals(economy.name)) { - economy.economy = (TAEcon) taecon; - log.info(String.format("[Economy] %s hooked.", economy.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (economy.economy != null) { - if (event.getPlugin().getDescription().getName().equals(economy.name)) { - economy.economy = null; - log.info(String.format("[Economy] %s unhooked.", economy.name)); - } - } - } - } + final Economy_TAEcon economy; + + public EconomyServerListener(final Economy_TAEcon economy) { + this.economy = economy; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.economy.economy == null) { + final Plugin taecon = event.getPlugin(); + + if (taecon.getDescription().getName().equals(this.economy.name)) { + this.economy.economy = (TAEcon) taecon; + Economy_TAEcon.this.log.info(String.format("[Economy] %s hooked.", this.economy.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.economy.economy != null) { + if (event.getPlugin().getDescription().getName().equals(this.economy.name)) { + this.economy.economy = null; + Economy_TAEcon.this.log.info(String.format("[Economy] %s unhooked.", this.economy.name)); + } + } + } + } @Override public boolean isEnabled() { - return economy != null; + return this.economy != null; } - + @Override public String getName() { - return name; + return this.name; } - + @Override public boolean hasBankSupport() { return false; } - + @Override public int fractionalDigits() { return 0; } - + @Override public String format(double amount) { - amount = Math.ceil(amount); - if (amount == 1) { - return String.format("%d %s", (int)amount, currencyNameSingular()); - } else { - return String.format("%d %s", (int)amount, currencyNamePlural()); - } - } - + amount = Math.ceil(amount); + if (amount == 1) { + return String.format("%d %s", 1, this.currencyNameSingular()); + } else { + return String.format("%d %s", (int) amount, this.currencyNamePlural()); + } + } + @Override public String currencyNamePlural() { - return economy.getCurrencyName(true); + return this.economy.getCurrencyName(true); } - + @Override public String currencyNameSingular() { - return economy.getCurrencyName(false); + return this.economy.getCurrencyName(false); } - + @Override - public boolean hasAccount(String playerName) { + public boolean hasAccount(final String playerName) { return true; } - + @Override - public double getBalance(String playerName) { - return economy.getBalance(playerName); + public double getBalance(final String playerName) { + return this.economy.getBalance(playerName); } - + @Override - public boolean has(String playerName, double amount) { - return getBalance(playerName) >= amount; + public boolean has(final String playerName, final double amount) { + return this.getBalance(playerName) >= amount; } - + @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - ResponseType rt; - String message; - int iamount = (int)Math.ceil(amount); + public EconomyResponse withdrawPlayer(final String playerName, final double amount) { + final EconomyResponse.ResponseType rt; + final String message; + final int iamount = (int) Math.ceil(amount); - if (has(playerName, amount)) { - if (economy.removeBalance(playerName, iamount)) { - rt = ResponseType.SUCCESS; + if (this.has(playerName, amount)) { + if (this.economy.removeBalance(playerName, iamount)) { + rt = EconomyResponse.ResponseType.SUCCESS; message = null; } else { - rt = ResponseType.SUCCESS; + rt = EconomyResponse.ResponseType.SUCCESS; message = "ERROR"; } } else { - rt = ResponseType.FAILURE; + rt = EconomyResponse.ResponseType.FAILURE; message = "Not enough money"; } - return new EconomyResponse(iamount, getBalance(playerName), rt, message); + return new EconomyResponse(iamount, this.getBalance(playerName), rt, message); } - + @Override - public EconomyResponse depositPlayer(String playerName, double amount) { - ResponseType rt; - String message; - int iamount = (int)Math.floor(amount); + public EconomyResponse depositPlayer(final String playerName, final double amount) { + final EconomyResponse.ResponseType rt; + final String message; + final int iamount = (int) Math.floor(amount); - if (economy.addBalance(playerName, iamount)) { - rt = ResponseType.SUCCESS; + if (this.economy.addBalance(playerName, iamount)) { + rt = EconomyResponse.ResponseType.SUCCESS; message = null; } else { - rt = ResponseType.SUCCESS; + rt = EconomyResponse.ResponseType.SUCCESS; message = "ERROR"; } - return new EconomyResponse(iamount, getBalance(playerName), rt, message); + return new EconomyResponse(iamount, this.getBalance(playerName), rt, message); } - + @Override - public EconomyResponse createBank(String name, String player) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); + public EconomyResponse createBank(final String name, final String player) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); } - + @Override - public EconomyResponse deleteBank(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); + public EconomyResponse deleteBank(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); } - + @Override - public EconomyResponse bankBalance(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); + public EconomyResponse bankBalance(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); } - + @Override - public EconomyResponse bankHas(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); + public EconomyResponse bankHas(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); } - + @Override - public EconomyResponse bankWithdraw(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); + public EconomyResponse bankWithdraw(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); } - + @Override - public EconomyResponse bankDeposit(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); + public EconomyResponse bankDeposit(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); } - + @Override - public EconomyResponse isBankOwner(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); + public EconomyResponse isBankOwner(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); } - + @Override - public EconomyResponse isBankMember(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); + public EconomyResponse isBankMember(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "TAEcon does not support bank accounts"); } - + @Override public List getBanks() { - return new ArrayList(); + return new ArrayList<>(); } - + @Override - public boolean createPlayerAccount(String playerName) { + public boolean createPlayerAccount(final String playerName) { + return false; + } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return true; + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { return false; } - - @Override - public boolean hasAccount(String playerName, String worldName) { - return true; - } - - @Override - public double getBalance(String playerName, String world) { - return getBalance(playerName); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - return depositPlayer(playerName, amount); - } - - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return false; - } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_XPBank.java b/src/net/milkbowl/vault/economy/plugins/Economy_XPBank.java index 1f2e533a..4eaaadd9 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_XPBank.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_XPBank.java @@ -16,13 +16,12 @@ package net.milkbowl.vault.economy.plugins; -import java.util.List; -import java.util.logging.Logger; - +import com.gmail.mirelatrue.xpbank.API; +import com.gmail.mirelatrue.xpbank.Account; +import com.gmail.mirelatrue.xpbank.GroupBank; +import com.gmail.mirelatrue.xpbank.XPBank; import net.milkbowl.vault.economy.AbstractEconomy; import net.milkbowl.vault.economy.EconomyResponse; -import net.milkbowl.vault.economy.EconomyResponse.ResponseType; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -31,358 +30,346 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import com.gmail.mirelatrue.xpbank.API; -import com.gmail.mirelatrue.xpbank.Account; -import com.gmail.mirelatrue.xpbank.GroupBank; -import com.gmail.mirelatrue.xpbank.XPBank; +import java.util.List; +import java.util.logging.Logger; public class Economy_XPBank extends AbstractEconomy { - - private final Logger log; - private final String name = "XPBank"; - private Plugin plugin = null; - private XPBank XPB = null; - private API api = null; - - public Economy_XPBank (Plugin plugin) { - this.plugin = plugin; - this.log = plugin.getLogger(); - Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - - // Load Plugin in case it was loaded before - if (XPB == null) { - Plugin economy = plugin.getServer().getPluginManager().getPlugin("XPBank"); - if (economy != null && economy.isEnabled()) { - XPB = (XPBank) economy; - api = XPB.getAPI(); - log.info(String.format("[Economy] %s hooked.", name)); - } - } - } - - public class EconomyServerListener implements Listener { - Economy_XPBank economy = null; - - public EconomyServerListener (Economy_XPBank economy_XPBank) { - this.economy = economy_XPBank; - } - - @EventHandler (priority = EventPriority.MONITOR) - public void onPluginEnable (PluginEnableEvent event) { - if (economy.XPB == null) { - Plugin eco = event.getPlugin(); - - if (eco.getDescription().getName().equals("XPBank")) { - economy.XPB = (XPBank) eco; - api = XPB.getAPI(); - log.info(String.format("[Economy] %s hooked.", economy.name)); - } - } - } - - @EventHandler (priority = EventPriority.MONITOR) - public void onPluginDisable (PluginDisableEvent event) { - if (economy.XPB != null) { - if (event.getPlugin().getDescription().getName().equals("XPBank")) { - economy.XPB = null; - log.info(String.format("[Economy] %s unhooked.", economy.name)); - } - } - } - } - - @Override - public boolean isEnabled () { - return this.XPB != null; - } - - @Override - public String getName () { - return name; - } - - @Override - public boolean hasBankSupport () { - return true; - } - - @Override - public int fractionalDigits () { - return 0; - } - - @Override - public String format (double amount) { - return String.format("%d %s", (int) amount, api.currencyName((int) amount)); - } - - @Override - public String currencyNamePlural () { - return api.getMsg("CurrencyNamePlural"); - } - - @Override - public String currencyNameSingular () { - return api.getMsg("currencyName"); - } - - @Override - public boolean hasAccount (String playerName) { - Account account = api.getAccount(playerName); - - if (account != null) { - return true; - } - - return false; - } - - @Override - public double getBalance (String playerName) { - Account account = api.getAccount(playerName); - - return account.getBalance(); - } - - @Override - public boolean has (String playerName, double amount) { - Account account = api.getAccount(playerName); - - if (account.getBalance() >= (int) amount) { - return true; - } - - return false; - } - - @Override - public EconomyResponse withdrawPlayer (String playerName, double amount) { - Account account = api.getAccount(playerName); - - if (account == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("Player doesn't exist.")); - } - - int value = (int) amount; - int balance = account.getBalance(); - - if (value < 1) { - return new EconomyResponse(0, balance, ResponseType.FAILURE, api.getMsg("LessThanZero")); - } - - if (value > balance) { - return new EconomyResponse(0, balance, ResponseType.FAILURE, String.format(api.getMsg("InsufficientXP"), api.currencyName(value))); - } - - account.modifyBalance(-value); - - return new EconomyResponse(value, balance - value, ResponseType.SUCCESS, null); - } - - @Override - public EconomyResponse depositPlayer (String playerName, double amount) { - Account account = api.getAccount(playerName); - - if (account == null) { - // Stupid plugins that use fake players without creating them first... - // return new EconomyResponse(0, 0, ResponseType.FAILURE, "Player doesn't exist"); - this.createPlayerAccount(playerName); - } - - int value = (int) amount; - int balance = account.getBalance(); - - if (value < 1) { - return new EconomyResponse(0, balance, ResponseType.FAILURE, api.getMsg("LessThanZero")); - } - - account.addTaxableIncome(value); - - return new EconomyResponse(value, balance + value, ResponseType.SUCCESS, null); - } - - @Override - public EconomyResponse createBank (String name, String player) { - GroupBank groupBank = api.getGroupBank(name); - - if (groupBank != null) { - return new EconomyResponse(0, groupBank.getBalance(), ResponseType.FAILURE, String.format(api.getMsg("GroupBankExists"), name)); - } - - Account account = api.getAccount(player); - - groupBank = api.createGroupBank(name, account); - - return new EconomyResponse(0, groupBank.getBalance(), ResponseType.SUCCESS, null); - } - - @Override - public EconomyResponse deleteBank (String name) { - GroupBank groupBank = api.getGroupBank(name); - - if (groupBank == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("GroupBankNotExists")); - } - - api.deleteGroupBank(groupBank, String.format(api.getMsg("Disbanded"), groupBank.getName())); - - return new EconomyResponse(0, 0, ResponseType.SUCCESS, null); - } - - @Override - public EconomyResponse bankBalance (String name) { - GroupBank groupBank = api.getGroupBank(name); - - if (groupBank == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("GroupBankNotExists")); - } - - return new EconomyResponse(0, groupBank.getBalance(), ResponseType.SUCCESS, null); - } - - @Override - public EconomyResponse bankHas (String name, double amount) { - GroupBank groupBank = api.getGroupBank(name); - - if (groupBank == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("GroupBankNotExists")); - } - - int value = (int) amount; - int balance = groupBank.getBalance(); - - if (balance >= value) { - return new EconomyResponse(0, balance, ResponseType.SUCCESS, null); - } - - return new EconomyResponse(0, balance, ResponseType.FAILURE, String.format(api.getMsg("InsufficientXP"), api.currencyName(value))); - } - - @Override - public EconomyResponse bankWithdraw (String name, double amount) { - GroupBank groupBank = api.getGroupBank(name); - - if (groupBank == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("GroupBankNotExists")); - } - - int value = (int) amount; - int balance = groupBank.getBalance(); - - if (value < 1) { - return new EconomyResponse(0, balance, ResponseType.FAILURE, api.getMsg("LessThanZero")); - } - - if (value > balance) { - return new EconomyResponse(0, balance, ResponseType.FAILURE, String.format(api.getMsg("InsufficientXP"), api.currencyName(value))); - } - - groupBank.modifyBalance(-value); - - return new EconomyResponse(value, balance - value, ResponseType.SUCCESS, null); - } - - @Override - public EconomyResponse bankDeposit (String name, double amount) { - GroupBank groupBank = api.getGroupBank(name); - - if (groupBank == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("GroupBankNotExists")); - } - - int value = (int) amount; - int balance = groupBank.getBalance(); - - if (value < 1) { - return new EconomyResponse(0, balance, ResponseType.FAILURE, api.getMsg("LessThanZero")); - } - - groupBank.modifyBalance(value); - - return new EconomyResponse(value, balance + value, ResponseType.SUCCESS, null); - } - - @Override - public EconomyResponse isBankOwner (String name, String playerName) { - GroupBank groupBank = api.getGroupBank(name); - - if (groupBank == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("GroupBankNotExists")); - } - - Account account = api.getAccount(name); - - if (account == null) { - return new EconomyResponse(0, groupBank.getBalance(), ResponseType.FAILURE, api.getMsg("PlayerNotExist")); - } - - if (groupBank.getOwner().equalsIgnoreCase(name)) { - return new EconomyResponse(0, groupBank.getBalance(), ResponseType.SUCCESS, null); - } - - return new EconomyResponse(0, groupBank.getBalance(), ResponseType.FAILURE, String.format(api.getMsg("PlayerNotOwner"), account.getName(), groupBank.getName())); - } - - @Override - public EconomyResponse isBankMember (String name, String playerName) { - GroupBank groupBank = api.getGroupBank(name); - - if (groupBank == null) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("GroupBankNotExists")); - } - - Account account = api.getAccount(name); - - if (account == null) { - return new EconomyResponse(0, groupBank.getBalance(), ResponseType.FAILURE, api.getMsg("PlayerNotExist")); - } - - if (groupBank.groupMembers.getMembers().containsKey(playerName)) { - return new EconomyResponse(0, groupBank.getBalance(), ResponseType.SUCCESS, null); - } - - return new EconomyResponse(0, groupBank.getBalance(), ResponseType.FAILURE, String.format(api.getMsg("NotAMemberOf"), groupBank.getName(), account.getName())); - } - - @Override - public List getBanks () { - return api.getAllGroupBanks(); - } - - @Override - public boolean createPlayerAccount (String playerName) { - api.createAccount(playerName); - - return true; - } - - @Override - public boolean hasAccount(String playerName, String worldName) { - return hasAccount(playerName); - } - - @Override - public double getBalance(String playerName, String world) { - return getBalance(playerName); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - return depositPlayer(playerName, amount); - } - - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return createPlayerAccount(playerName); - } + + private final Logger log; + private final String name = "XPBank"; + private XPBank XPB; + private API api; + + public Economy_XPBank(final Plugin plugin) { + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + + // Load Plugin in case it was loaded before + if (this.XPB == null) { + final Plugin economy = plugin.getServer().getPluginManager().getPlugin("XPBank"); + if (economy != null && economy.isEnabled()) { + this.XPB = (XPBank) economy; + this.api = this.XPB.getAPI(); + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } + } + + public class EconomyServerListener implements Listener { + final Economy_XPBank economy; + + public EconomyServerListener(final Economy_XPBank economy_XPBank) { + economy = economy_XPBank; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.economy.XPB == null) { + final Plugin eco = event.getPlugin(); + + if (eco.getDescription().getName().equals("XPBank")) { + this.economy.XPB = (XPBank) eco; + Economy_XPBank.this.api = Economy_XPBank.this.XPB.getAPI(); + Economy_XPBank.this.log.info(String.format("[Economy] %s hooked.", this.economy.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.economy.XPB != null) { + if (event.getPlugin().getDescription().getName().equals("XPBank")) { + this.economy.XPB = null; + Economy_XPBank.this.log.info(String.format("[Economy] %s unhooked.", this.economy.name)); + } + } + } + } + + @Override + public boolean isEnabled() { + return XPB != null; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean hasBankSupport() { + return true; + } + + @Override + public int fractionalDigits() { + return 0; + } + + @Override + public String format(final double amount) { + return String.format("%d %s", (int) amount, this.api.currencyName((int) amount)); + } + + @Override + public String currencyNamePlural() { + return this.api.getMsg("CurrencyNamePlural"); + } + + @Override + public String currencyNameSingular() { + return this.api.getMsg("currencyName"); + } + + @Override + public boolean hasAccount(final String playerName) { + final Account account = this.api.getAccount(playerName); + + return account != null; + } + + @Override + public double getBalance(final String playerName) { + final Account account = this.api.getAccount(playerName); + + return account.getBalance(); + } + + @Override + public boolean has(final String playerName, final double amount) { + final Account account = this.api.getAccount(playerName); + + return account.getBalance() >= (int) amount; + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final double amount) { + final Account account = this.api.getAccount(playerName); + + if (account == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, this.api.getMsg("Player doesn't exist.")); + } + + final int value = (int) amount; + final int balance = account.getBalance(); + + if (value < 1) { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, this.api.getMsg("LessThanZero")); + } + + if (value > balance) { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, String.format(this.api.getMsg("InsufficientXP"), this.api.currencyName(value))); + } + + account.modifyBalance(-value); + + return new EconomyResponse(value, balance - value, EconomyResponse.ResponseType.SUCCESS, null); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final double amount) { + final Account account = this.api.getAccount(playerName); + + if (account == null) { + // Stupid plugins that use fake players without creating them first... + // return new EconomyResponse(0, 0, ResponseType.FAILURE, "Player doesn't exist"); + createPlayerAccount(playerName); + } + + final int value = (int) amount; + final int balance = account.getBalance(); + + if (value < 1) { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, this.api.getMsg("LessThanZero")); + } + + account.addTaxableIncome(value); + + return new EconomyResponse(value, balance + value, EconomyResponse.ResponseType.SUCCESS, null); + } + + @Override + public EconomyResponse createBank(final String name, final String player) { + GroupBank groupBank = this.api.getGroupBank(name); + + if (groupBank != null) { + return new EconomyResponse(0, groupBank.getBalance(), EconomyResponse.ResponseType.FAILURE, String.format(this.api.getMsg("GroupBankExists"), name)); + } + + final Account account = this.api.getAccount(player); + + groupBank = this.api.createGroupBank(name, account); + + return new EconomyResponse(0, groupBank.getBalance(), EconomyResponse.ResponseType.SUCCESS, null); + } + + @Override + public EconomyResponse deleteBank(final String name) { + final GroupBank groupBank = this.api.getGroupBank(name); + + if (groupBank == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, this.api.getMsg("GroupBankNotExists")); + } + + this.api.deleteGroupBank(groupBank, String.format(this.api.getMsg("Disbanded"), groupBank.getName())); + + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, null); + } + + @Override + public EconomyResponse bankBalance(final String name) { + final GroupBank groupBank = this.api.getGroupBank(name); + + if (groupBank == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, this.api.getMsg("GroupBankNotExists")); + } + + return new EconomyResponse(0, groupBank.getBalance(), EconomyResponse.ResponseType.SUCCESS, null); + } + + @Override + public EconomyResponse bankHas(final String name, final double amount) { + final GroupBank groupBank = this.api.getGroupBank(name); + + if (groupBank == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, this.api.getMsg("GroupBankNotExists")); + } + + final int value = (int) amount; + final int balance = groupBank.getBalance(); + + if (balance >= value) { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.SUCCESS, null); + } + + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, String.format(this.api.getMsg("InsufficientXP"), this.api.currencyName(value))); + } + + @Override + public EconomyResponse bankWithdraw(final String name, final double amount) { + final GroupBank groupBank = this.api.getGroupBank(name); + + if (groupBank == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, this.api.getMsg("GroupBankNotExists")); + } + + final int value = (int) amount; + final int balance = groupBank.getBalance(); + + if (value < 1) { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, this.api.getMsg("LessThanZero")); + } + + if (value > balance) { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, String.format(this.api.getMsg("InsufficientXP"), this.api.currencyName(value))); + } + + groupBank.modifyBalance(-value); + + return new EconomyResponse(value, balance - value, EconomyResponse.ResponseType.SUCCESS, null); + } + + @Override + public EconomyResponse bankDeposit(final String name, final double amount) { + final GroupBank groupBank = this.api.getGroupBank(name); + + if (groupBank == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, this.api.getMsg("GroupBankNotExists")); + } + + final int value = (int) amount; + final int balance = groupBank.getBalance(); + + if (value < 1) { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, this.api.getMsg("LessThanZero")); + } + + groupBank.modifyBalance(value); + + return new EconomyResponse(value, balance + value, EconomyResponse.ResponseType.SUCCESS, null); + } + + @Override + public EconomyResponse isBankOwner(final String name, final String playerName) { + final GroupBank groupBank = this.api.getGroupBank(name); + + if (groupBank == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, this.api.getMsg("GroupBankNotExists")); + } + + final Account account = this.api.getAccount(name); + + if (account == null) { + return new EconomyResponse(0, groupBank.getBalance(), EconomyResponse.ResponseType.FAILURE, this.api.getMsg("PlayerNotExist")); + } + + if (groupBank.getOwner().equalsIgnoreCase(name)) { + return new EconomyResponse(0, groupBank.getBalance(), EconomyResponse.ResponseType.SUCCESS, null); + } + + return new EconomyResponse(0, groupBank.getBalance(), EconomyResponse.ResponseType.FAILURE, String.format(this.api.getMsg("PlayerNotOwner"), account.getName(), groupBank.getName())); + } + + @Override + public EconomyResponse isBankMember(final String name, final String playerName) { + final GroupBank groupBank = this.api.getGroupBank(name); + + if (groupBank == null) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, this.api.getMsg("GroupBankNotExists")); + } + + final Account account = this.api.getAccount(name); + + if (account == null) { + return new EconomyResponse(0, groupBank.getBalance(), EconomyResponse.ResponseType.FAILURE, this.api.getMsg("PlayerNotExist")); + } + + if (groupBank.groupMembers.getMembers().containsKey(playerName)) { + return new EconomyResponse(0, groupBank.getBalance(), EconomyResponse.ResponseType.SUCCESS, null); + } + + return new EconomyResponse(0, groupBank.getBalance(), EconomyResponse.ResponseType.FAILURE, String.format(this.api.getMsg("NotAMemberOf"), groupBank.getName(), account.getName())); + } + + @Override + public List getBanks() { + return this.api.getAllGroupBanks(); + } + + @Override + public boolean createPlayerAccount(final String playerName) { + this.api.createAccount(playerName); + + return true; + } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return this.hasAccount(playerName); + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + return this.createPlayerAccount(playerName); + } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_eWallet.java b/src/net/milkbowl/vault/economy/plugins/Economy_eWallet.java index 335ec8a5..296a492d 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_eWallet.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_eWallet.java @@ -15,15 +15,9 @@ */ package net.milkbowl.vault.economy.plugins; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; - import me.ethan.eWallet.ECO; import net.milkbowl.vault.economy.AbstractEconomy; import net.milkbowl.vault.economy.EconomyResponse; -import net.milkbowl.vault.economy.EconomyResponse.ResponseType; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -32,223 +26,225 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -public class Economy_eWallet extends AbstractEconomy { - private final Logger log; - - private final String name = "eWallet"; - private Plugin plugin = null; - private ECO econ = null; - - public Economy_eWallet(Plugin plugin) { - this.plugin = plugin; - this.log = plugin.getLogger(); - Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - - // Load Plugin in case it was loaded before - if (econ == null) { - Plugin econ = plugin.getServer().getPluginManager().getPlugin("eWallet"); - if (econ != null && econ.isEnabled()) { - this.econ = (ECO) econ; - log.info(String.format("[Economy] %s hooked.", name)); - } - } - } - - public class EconomyServerListener implements Listener { - Economy_eWallet economy = null; - - public EconomyServerListener(Economy_eWallet economy) { - this.economy = economy; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (economy.econ == null) { - Plugin eco = event.getPlugin(); - - if (eco.getDescription().getName().equals("eWallet")) { - economy.econ = (ECO) eco; - log.info(String.format("[Economy] %s hooked.", economy.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (economy.econ != null) { - if (event.getPlugin().getDescription().getName().equals("eWallet")) { - economy.econ = null; - log.info(String.format("[Economy] %s unhooked.", economy.name)); - } - } - } - } - - @Override - public boolean isEnabled() { - return this.econ != null; - } - - @Override - public String getName() { - return name; - } - - @Override - public String format(double amount) { - amount = Math.ceil(amount); - if (amount == 1) { - return String.format("%d %s", (int)amount, econ.singularCurrency); - } else { - return String.format("%d %s", (int)amount, econ.pluralCurrency); - } - } - - @Override - public String currencyNameSingular() { - return econ.singularCurrency; - } - - @Override - public String currencyNamePlural() { - return econ.pluralCurrency; - } - - @Override - public double getBalance(String playerName) { - Integer i = econ.getMoney(playerName); - return i == null ? 0 : i; - } - - @Override - public boolean has(String playerName, double amount) { - return getBalance(playerName) >= Math.ceil(amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - double balance = getBalance(playerName); - amount = Math.ceil(amount); - if (amount < 0) { - return new EconomyResponse(0, balance, ResponseType.FAILURE, "Cannot withdraw negative funds"); - } else if (balance >= amount) { - double finalBalance = balance - amount; - econ.takeMoney(playerName, (int) amount); - return new EconomyResponse(amount, finalBalance, ResponseType.SUCCESS, null); - } else { - return new EconomyResponse(0, balance, ResponseType.FAILURE, "Insufficient funds"); - } - } - - @Override - public EconomyResponse depositPlayer(String playerName, double amount) { - double balance = getBalance(playerName); - amount = Math.ceil(amount); - if (amount < 0) { - return new EconomyResponse(0, balance, ResponseType.FAILURE, "Cannot deposit negative funds"); - } else { - balance += amount; - econ.giveMoney(playerName, (int) amount); - return new EconomyResponse(amount, balance, ResponseType.SUCCESS, null); - } - } - - @Override - public EconomyResponse createBank(String name, String player) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); - } - - @Override - public EconomyResponse deleteBank(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); - } - - @Override - public EconomyResponse bankHas(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); - } - - @Override - public EconomyResponse bankWithdraw(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); - } - - @Override - public EconomyResponse bankDeposit(String name, double amount) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); - } - - @Override - public EconomyResponse isBankOwner(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); - } - - @Override - public EconomyResponse isBankMember(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); - } - - @Override - public EconomyResponse bankBalance(String name) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); - } - - @Override - public List getBanks() { - return new ArrayList(); - } - - @Override - public boolean hasBankSupport() { - return false; - } - - @Override - public boolean hasAccount(String playerName) { - return econ.hasAccount(playerName); - } - - @Override - public boolean createPlayerAccount(String playerName) { - if (hasAccount(playerName)) { - return false; - } - econ.createAccount(playerName, 0); - return true; - } +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; +public class Economy_eWallet extends AbstractEconomy { + private final Logger log; + + private final String name = "eWallet"; + private ECO econ; + + public Economy_eWallet(final Plugin plugin) { + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + + // Load Plugin in case it was loaded before + if (this.econ == null) { + final Plugin econ = plugin.getServer().getPluginManager().getPlugin("eWallet"); + if (econ != null && econ.isEnabled()) { + this.econ = (ECO) econ; + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } + } + + public class EconomyServerListener implements Listener { + final Economy_eWallet economy; + + public EconomyServerListener(final Economy_eWallet economy) { + this.economy = economy; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.economy.econ == null) { + final Plugin eco = event.getPlugin(); + + if (eco.getDescription().getName().equals("eWallet")) { + this.economy.econ = (ECO) eco; + Economy_eWallet.this.log.info(String.format("[Economy] %s hooked.", this.economy.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.economy.econ != null) { + if (event.getPlugin().getDescription().getName().equals("eWallet")) { + this.economy.econ = null; + Economy_eWallet.this.log.info(String.format("[Economy] %s unhooked.", this.economy.name)); + } + } + } + } + + @Override + public boolean isEnabled() { + return econ != null; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public String format(double amount) { + amount = Math.ceil(amount); + if (amount == 1) { + return String.format("%d %s", 1, this.econ.singularCurrency); + } else { + return String.format("%d %s", (int) amount, this.econ.pluralCurrency); + } + } + + @Override + public String currencyNameSingular() { + return this.econ.singularCurrency; + } + + @Override + public String currencyNamePlural() { + return this.econ.pluralCurrency; + } + + @Override + public double getBalance(final String playerName) { + final Integer i = this.econ.getMoney(playerName); + return i == null ? 0 : i; + } + + @Override + public boolean has(final String playerName, final double amount) { + return this.getBalance(playerName) >= Math.ceil(amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, double amount) { + final double balance = this.getBalance(playerName); + amount = Math.ceil(amount); + if (amount < 0) { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, "Cannot withdraw negative funds"); + } else if (balance >= amount) { + final double finalBalance = balance - amount; + this.econ.takeMoney(playerName, (int) amount); + return new EconomyResponse(amount, finalBalance, EconomyResponse.ResponseType.SUCCESS, null); + } else { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, "Insufficient funds"); + } + } + + @Override + public EconomyResponse depositPlayer(final String playerName, double amount) { + double balance = this.getBalance(playerName); + amount = Math.ceil(amount); + if (amount < 0) { + return new EconomyResponse(0, balance, EconomyResponse.ResponseType.FAILURE, "Cannot deposit negative funds"); + } else { + balance += amount; + this.econ.giveMoney(playerName, (int) amount); + return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.SUCCESS, null); + } + } + + @Override + public EconomyResponse createBank(final String name, final String player) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); + } + + @Override + public EconomyResponse deleteBank(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); + } + + @Override + public EconomyResponse bankHas(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); + } + + @Override + public EconomyResponse bankWithdraw(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); + } + + @Override + public EconomyResponse bankDeposit(final String name, final double amount) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); + } + + @Override + public EconomyResponse isBankOwner(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); + } + + @Override + public EconomyResponse isBankMember(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); + } + + @Override + public EconomyResponse bankBalance(final String name) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "eWallet does not support bank accounts!"); + } + + @Override + public List getBanks() { + return new ArrayList<>(); + } + + @Override + public boolean hasBankSupport() { + return false; + } + + @Override + public boolean hasAccount(final String playerName) { + return this.econ.hasAccount(playerName); + } + + @Override + public boolean createPlayerAccount(final String playerName) { + if (this.hasAccount(playerName)) { + return false; + } + this.econ.createAccount(playerName, 0); + return true; + } + @Override public int fractionalDigits() { return 0; } - - @Override - public boolean hasAccount(String playerName, String worldName) { - return hasAccount(playerName); - } - - @Override - public double getBalance(String playerName, String world) { - return getBalance(playerName); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - return depositPlayer(playerName, amount); - } - - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return createPlayerAccount(playerName); - } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return this.hasAccount(playerName); + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + return this.createPlayerAccount(playerName); + } } diff --git a/src/net/milkbowl/vault/economy/plugins/Economy_iConomy6.java b/src/net/milkbowl/vault/economy/plugins/Economy_iConomy6.java index 69ef59dd..d13e4026 100644 --- a/src/net/milkbowl/vault/economy/plugins/Economy_iConomy6.java +++ b/src/net/milkbowl/vault/economy/plugins/Economy_iConomy6.java @@ -15,13 +15,12 @@ */ package net.milkbowl.vault.economy.plugins; -import java.util.List; -import java.util.logging.Logger; - +import com.iCo6.Constants; +import com.iCo6.iConomy; +import com.iCo6.system.Accounts; +import com.iCo6.system.Holdings; import net.milkbowl.vault.economy.AbstractEconomy; import net.milkbowl.vault.economy.EconomyResponse; -import net.milkbowl.vault.economy.EconomyResponse.ResponseType; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -30,264 +29,260 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import com.iCo6.Constants; -import com.iCo6.iConomy; -import com.iCo6.system.Accounts; -import com.iCo6.system.Holdings; +import java.util.List; +import java.util.logging.Logger; public class Economy_iConomy6 extends AbstractEconomy { - private final Logger log; - - private String name = "iConomy "; - private Plugin plugin = null; - protected iConomy economy = null; - private Accounts accounts; - - public Economy_iConomy6(Plugin plugin) { - this.plugin = plugin; - this.log = plugin.getLogger(); - Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); - log.warning("iConomy - If you are using Flatfile storage be aware that versions 6, 7 and 8 have a CRITICAL bug which can wipe ALL iconomy data."); - log.warning("if you're using Votifier, or any other plugin which handles economy data in a threaded manner your server is at risk!"); - log.warning("it is highly suggested to use SQL with iCo6 or to use an alternative economy plugin!"); - // Load Plugin in case it was loaded before - if (economy == null) { - Plugin ec = plugin.getServer().getPluginManager().getPlugin("iConomy"); - if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.iCo6.iConomy")) { - String version = ec.getDescription().getVersion().split("\\.")[0]; - name += version; - economy = (iConomy) ec; - accounts = new Accounts(); - log.info(String.format("[Economy] %s hooked.", name)); - } - } - } - - public class EconomyServerListener implements Listener { - Economy_iConomy6 economy = null; - - public EconomyServerListener(Economy_iConomy6 economy) { - this.economy = economy; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (economy.economy == null) { - Plugin ec = event.getPlugin(); - if (ec.getClass().getName().equals("com.iCo6.iConomy")) { - String version = ec.getDescription().getVersion().split("\\.")[0]; - name += version; - economy.economy = (iConomy) ec; - accounts = new Accounts(); - log.info(String.format("[Economy] %s hooked.", economy.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (economy.economy != null) { - if (event.getPlugin().getDescription().getName().equals("iConomy")) { - economy.economy = null; - log.info(String.format("[Economy] %s unhooked.", economy.name)); - } - } - } - } - - @Override - public boolean isEnabled() { - if (economy == null) { - return false; - } else { - return economy.isEnabled(); - } - } - - @Override - public String getName() { - return name; - } - - @Override - public String format(double amount) { - return iConomy.format(amount); - } - - @Override - public String currencyNameSingular() { - return Constants.Nodes.Major.getStringList().get(0); - } - - @Override - public String currencyNamePlural() { - return Constants.Nodes.Major.getStringList().get(1); - } - - @Override - public double getBalance(String playerName) { - if (accounts.exists(playerName)) { - return accounts.get(playerName).getHoldings().getBalance(); - } else { - return 0; - } - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, double amount) { - if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds"); - } - - Holdings holdings = accounts.get(playerName).getHoldings(); - if (holdings.hasEnough(amount)) { - holdings.subtract(amount); - return new EconomyResponse(amount, holdings.getBalance(), ResponseType.SUCCESS, null); - } else { - return new EconomyResponse(0, holdings.getBalance(), ResponseType.FAILURE, "Insufficient funds"); - } - } - - @Override - public EconomyResponse depositPlayer(String playerName, double amount) { - if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds"); - } - - Holdings holdings = accounts.get(playerName).getHoldings(); - holdings.add(amount); - return new EconomyResponse(amount, holdings.getBalance(), ResponseType.SUCCESS, null); - } - - @Override - public boolean has(String playerName, double amount) { - return getBalance(playerName) >= amount; - } - - @Override - public EconomyResponse createBank(String name, String player) { - if (accounts.exists(name)) { - return new EconomyResponse(0, accounts.get(name).getHoldings().getBalance(), ResponseType.FAILURE, "That account already exists."); - } - boolean created = accounts.create(name); - if (created) { - return new EconomyResponse(0, 0, ResponseType.SUCCESS, ""); - } else { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "There was an error creating the account"); - } - - } - - @Override - public EconomyResponse deleteBank(String name) { - if (accounts.exists(name)) { - accounts.remove(name); - return new EconomyResponse(0, 0, ResponseType.SUCCESS, ""); - } - return new EconomyResponse(0, 0, ResponseType.FAILURE, "That bank account does not exist."); - } - - @Override - public EconomyResponse bankHas(String name, double amount) { - if (has(name, amount)) { - return new EconomyResponse(0, amount, ResponseType.SUCCESS, ""); - } else { - return new EconomyResponse(0, accounts.get(name).getHoldings().getBalance(), ResponseType.FAILURE, "The account does not have enough!"); - } - } - - @Override - public EconomyResponse bankWithdraw(String name, double amount) { - if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds"); - } - - return withdrawPlayer(name, amount); - } - - @Override - public EconomyResponse bankDeposit(String name, double amount) { - if (amount < 0) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds"); - } - - return depositPlayer(name, amount); - } - - @Override - public EconomyResponse isBankOwner(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy 6 does not support Bank owners."); - } - - @Override - public EconomyResponse isBankMember(String name, String playerName) { - return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "iConomy 6 does not support Bank members."); - } - - @Override - public EconomyResponse bankBalance(String name) { - if (!accounts.exists(name)) { - return new EconomyResponse(0, 0, ResponseType.FAILURE, "There is no bank account with that name"); - } else { - return new EconomyResponse(0, accounts.get(name).getHoldings().getBalance(), ResponseType.SUCCESS, null); - } - } - - @Override - public List getBanks() { - throw new UnsupportedOperationException("iConomy does not support listing of bank accounts"); - } - - @Override - public boolean hasBankSupport() { - return true; - } - - @Override - public boolean hasAccount(String playerName) { - return accounts.exists(playerName); - } - - @Override - public boolean createPlayerAccount(String playerName) { - if (hasAccount(playerName)) { - return false; - } - return accounts.create(playerName); - } - + private final Logger log; + + private String name = "iConomy "; + protected iConomy economy; + private Accounts accounts; + + public Economy_iConomy6(final Plugin plugin) { + log = plugin.getLogger(); + Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); + this.log.warning("iConomy - If you are using Flatfile storage be aware that versions 6, 7 and 8 have a CRITICAL bug which can wipe ALL iconomy data."); + this.log.warning("if you're using Votifier, or any other plugin which handles economy data in a threaded manner your server is at risk!"); + this.log.warning("it is highly suggested to use SQL with iCo6 or to use an alternative economy plugin!"); + // Load Plugin in case it was loaded before + if (this.economy == null) { + final Plugin ec = plugin.getServer().getPluginManager().getPlugin("iConomy"); + if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.iCo6.iConomy")) { + final String version = ec.getDescription().getVersion().split("\\.")[0]; + this.name += version; + this.economy = (iConomy) ec; + this.accounts = new Accounts(); + this.log.info(String.format("[Economy] %s hooked.", this.name)); + } + } + } + + public class EconomyServerListener implements Listener { + final Economy_iConomy6 economy; + + public EconomyServerListener(final Economy_iConomy6 economy) { + this.economy = economy; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.economy.economy == null) { + final Plugin ec = event.getPlugin(); + if (ec.getClass().getName().equals("com.iCo6.iConomy")) { + final String version = ec.getDescription().getVersion().split("\\.")[0]; + Economy_iConomy6.this.name += version; + this.economy.economy = (iConomy) ec; + Economy_iConomy6.this.accounts = new Accounts(); + Economy_iConomy6.this.log.info(String.format("[Economy] %s hooked.", this.economy.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.economy.economy != null) { + if (event.getPlugin().getDescription().getName().equals("iConomy")) { + this.economy.economy = null; + Economy_iConomy6.this.log.info(String.format("[Economy] %s unhooked.", this.economy.name)); + } + } + } + } + + @Override + public boolean isEnabled() { + if (this.economy == null) { + return false; + } else { + return this.economy.isEnabled(); + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public String format(final double amount) { + return iConomy.format(amount); + } + + @Override + public String currencyNameSingular() { + return Constants.Nodes.Major.getStringList().get(0); + } + + @Override + public String currencyNamePlural() { + return Constants.Nodes.Major.getStringList().get(1); + } + + @Override + public double getBalance(final String playerName) { + if (this.accounts.exists(playerName)) { + return this.accounts.get(playerName).getHoldings().getBalance(); + } else { + return 0; + } + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final double amount) { + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot withdraw negative funds"); + } + + final Holdings holdings = this.accounts.get(playerName).getHoldings(); + if (holdings.hasEnough(amount)) { + holdings.subtract(amount); + return new EconomyResponse(amount, holdings.getBalance(), EconomyResponse.ResponseType.SUCCESS, null); + } else { + return new EconomyResponse(0, holdings.getBalance(), EconomyResponse.ResponseType.FAILURE, "Insufficient funds"); + } + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final double amount) { + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot desposit negative funds"); + } + + final Holdings holdings = this.accounts.get(playerName).getHoldings(); + holdings.add(amount); + return new EconomyResponse(amount, holdings.getBalance(), EconomyResponse.ResponseType.SUCCESS, null); + } + + @Override + public boolean has(final String playerName, final double amount) { + return this.getBalance(playerName) >= amount; + } + + @Override + public EconomyResponse createBank(final String name, final String player) { + if (this.accounts.exists(name)) { + return new EconomyResponse(0, this.accounts.get(name).getHoldings().getBalance(), EconomyResponse.ResponseType.FAILURE, "That account already exists."); + } + final boolean created = this.accounts.create(name); + if (created) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, ""); + } else { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "There was an error creating the account"); + } + + } + + @Override + public EconomyResponse deleteBank(final String name) { + if (this.accounts.exists(name)) { + this.accounts.remove(name); + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.SUCCESS, ""); + } + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That bank account does not exist."); + } + + @Override + public EconomyResponse bankHas(final String name, final double amount) { + if (this.has(name, amount)) { + return new EconomyResponse(0, amount, EconomyResponse.ResponseType.SUCCESS, ""); + } else { + return new EconomyResponse(0, this.accounts.get(name).getHoldings().getBalance(), EconomyResponse.ResponseType.FAILURE, "The account does not have enough!"); + } + } + + @Override + public EconomyResponse bankWithdraw(final String name, final double amount) { + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot withdraw negative funds"); + } + + return this.withdrawPlayer(name, amount); + } + + @Override + public EconomyResponse bankDeposit(final String name, final double amount) { + if (amount < 0) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Cannot desposit negative funds"); + } + + return this.depositPlayer(name, amount); + } + + @Override + public EconomyResponse isBankOwner(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "iConomy 6 does not support Bank owners."); + } + + @Override + public EconomyResponse isBankMember(final String name, final String playerName) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "iConomy 6 does not support Bank members."); + } + + @Override + public EconomyResponse bankBalance(final String name) { + if (!this.accounts.exists(name)) { + return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "There is no bank account with that name"); + } else { + return new EconomyResponse(0, this.accounts.get(name).getHoldings().getBalance(), EconomyResponse.ResponseType.SUCCESS, null); + } + } + + @Override + public List getBanks() { + throw new UnsupportedOperationException("iConomy does not support listing of bank accounts"); + } + + @Override + public boolean hasBankSupport() { + return true; + } + + @Override + public boolean hasAccount(final String playerName) { + return this.accounts.exists(playerName); + } + + @Override + public boolean createPlayerAccount(final String playerName) { + if (this.hasAccount(playerName)) { + return false; + } + return this.accounts.create(playerName); + } + @Override public int fractionalDigits() { return -1; } - - @Override - public boolean hasAccount(String playerName, String worldName) { - return hasAccount(playerName); - } - - @Override - public double getBalance(String playerName, String world) { - return getBalance(playerName); - } - - @Override - public boolean has(String playerName, String worldName, double amount) { - return has(playerName, amount); - } - - @Override - public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { - return withdrawPlayer(playerName, amount); - } - - @Override - public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { - return depositPlayer(playerName, amount); - } - - @Override - public boolean createPlayerAccount(String playerName, String worldName) { - return createPlayerAccount(playerName); - } + + @Override + public boolean hasAccount(final String playerName, final String worldName) { + return this.hasAccount(playerName); + } + + @Override + public double getBalance(final String playerName, final String world) { + return this.getBalance(playerName); + } + + @Override + public boolean has(final String playerName, final String worldName, final double amount) { + return this.has(playerName, amount); + } + + @Override + public EconomyResponse withdrawPlayer(final String playerName, final String worldName, final double amount) { + return this.withdrawPlayer(playerName, amount); + } + + @Override + public EconomyResponse depositPlayer(final String playerName, final String worldName, final double amount) { + return this.depositPlayer(playerName, amount); + } + + @Override + public boolean createPlayerAccount(final String playerName, final String worldName) { + return this.createPlayerAccount(playerName); + } } diff --git a/src/net/milkbowl/vault/permission/plugins/Permission_GroupManager.java b/src/net/milkbowl/vault/permission/plugins/Permission_GroupManager.java index 3682148d..3814f5ca 100644 --- a/src/net/milkbowl/vault/permission/plugins/Permission_GroupManager.java +++ b/src/net/milkbowl/vault/permission/plugins/Permission_GroupManager.java @@ -15,10 +15,7 @@ */ package net.milkbowl.vault.permission.plugins; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - +import net.milkbowl.vault.permission.Permission; import org.anjocaido.groupmanager.GroupManager; import org.anjocaido.groupmanager.data.Group; import org.anjocaido.groupmanager.data.User; @@ -34,328 +31,329 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import net.milkbowl.vault.permission.Permission; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; public class Permission_GroupManager extends Permission { - - private final String name = "GroupManager"; - private GroupManager groupManager; - - public Permission_GroupManager(Plugin plugin) { - this.plugin = plugin; - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); - - // Load Plugin in case it was loaded before - if (groupManager == null) { - Plugin perms = plugin.getServer().getPluginManager().getPlugin("GroupManager"); - if (perms != null && perms.isEnabled()) { - groupManager = (GroupManager) perms; - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - - public class PermissionServerListener implements Listener { - Permission_GroupManager permission = null; - - public PermissionServerListener(Permission_GroupManager permission) { - this.permission = permission; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (permission.groupManager == null) { - Plugin p = event.getPlugin(); - if (p.getDescription().getName().equals("GroupManager")) { - permission.groupManager = (GroupManager) p; - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (permission.groupManager != null) { - if (event.getPlugin().getDescription().getName().equals("GroupManager")) { - permission.groupManager = null; - log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name)); - } - } - } - } - - @Override - public String getName() { - return this.name; - } - - @Override - public boolean isEnabled() { - return groupManager != null && groupManager.isEnabled(); - } - - @Override - public boolean playerHas(String worldName, String playerName, String permission) { - AnjoPermissionsHandler handler; - if (worldName == null) { - handler = groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); - } - else { - handler = groupManager.getWorldsHolder().getWorldPermissions(worldName); - } - if (handler == null) { - return false; - } - return handler.permission(playerName, permission); - } - - @Override - public boolean playerAdd(String worldName, String playerName, String permission) { - OverloadedWorldHolder owh; - if (worldName == null) { - owh = groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName); - } else { - owh = groupManager.getWorldsHolder().getWorldData(worldName); - } - if (owh == null) { - return false; - } - - User user = owh.getUser(playerName); - if (user == null) { - return false; - } - - user.addPermission(permission); - Player p = Bukkit.getPlayer(playerName); - if (p != null) { - GroupManager.BukkitPermissions.updatePermissions(p); - } - return true; - } - - @Override - public boolean playerRemove(String worldName, String playerName, String permission) { - OverloadedWorldHolder owh; - if (worldName == null) { - owh = groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName); - } else { - owh = groupManager.getWorldsHolder().getWorldData(worldName); - } - if (owh == null) { - return false; - } - - User user = owh.getUser(playerName); - if (user == null) { - return false; - } - - user.removePermission(permission); - Player p = Bukkit.getPlayer(playerName); - if (p != null) { - GroupManager.BukkitPermissions.updatePermissions(p); - } - return true; - } - - @Override - public boolean groupHas(String worldName, String groupName, String permission) { - OverloadedWorldHolder owh; - if (worldName == null) { - owh = groupManager.getWorldsHolder().getDefaultWorld(); - } else { - owh = groupManager.getWorldsHolder().getWorldData(worldName); - } - if (owh == null) { - return false; - } - - Group group = owh.getGroup(groupName); - if (group == null) { - return false; - } - - return group.hasSamePermissionNode(permission); - } - - @Override - public boolean groupAdd(String worldName, String groupName, String permission) { - OverloadedWorldHolder owh; - if (worldName == null) { - owh = groupManager.getWorldsHolder().getDefaultWorld(); - } else { - owh = groupManager.getWorldsHolder().getWorldData(worldName); - } - if (owh == null) { - return false; - } - - Group group = owh.getGroup(groupName); - if (group == null) { - return false; - } - - group.addPermission(permission); - return true; - } - - @Override - public boolean groupRemove(String worldName, String groupName, String permission) { - OverloadedWorldHolder owh; - if (worldName == null) { - owh = groupManager.getWorldsHolder().getDefaultWorld(); - } else { - owh = groupManager.getWorldsHolder().getWorldData(worldName); - } - if (owh == null) { - return false; - } - - Group group = owh.getGroup(groupName); - if (group == null) { - return false; - } - - group.removePermission(permission); - return true; - } - - @Override - public boolean playerInGroup(String worldName, String playerName, String groupName) { - AnjoPermissionsHandler handler; - if (worldName == null) { - handler = groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); - } else { - handler = groupManager.getWorldsHolder().getWorldPermissions(worldName); - } - if (handler == null) { - return false; - } - return handler.inGroup(playerName, groupName); - } - - @Override - public boolean playerAddGroup(String worldName, String playerName, String groupName) { - OverloadedWorldHolder owh; - if (worldName == null) { - owh = groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName); - } else { - owh = groupManager.getWorldsHolder().getWorldData(worldName); - } - if (owh == null) { - return false; - } - User user = owh.getUser(playerName); - if (user == null) { - return false; - } - Group group = owh.getGroup(groupName); - if (group == null) { - return false; - } - if (user.getGroup().equals(owh.getDefaultGroup())) { - user.setGroup(group); - } else if (group.getInherits().contains(user.getGroup().getName().toLowerCase())) { - user.setGroup(group); - } else { - user.addSubGroup(group); - } - Player p = Bukkit.getPlayer(playerName); - if (p != null) { - GroupManager.BukkitPermissions.updatePermissions(p); - } - return true; - } - - @Override - public boolean playerRemoveGroup(String worldName, String playerName, String groupName) { - OverloadedWorldHolder owh; - if (worldName == null) { - owh = groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName); - } else { - owh = groupManager.getWorldsHolder().getWorldData(worldName); - } - if (owh == null) { - return false; - } - User user = owh.getUser(playerName); - if (user == null) { - return false; - } - boolean success = false; - if (user.getGroup().getName().equalsIgnoreCase(groupName)) { - user.setGroup(owh.getDefaultGroup()); - success = true; - } else { - Group group = owh.getGroup(groupName); - if (group != null) { - success = user.removeSubGroup(group); - } - } - if (success) { - Player p = Bukkit.getPlayer(playerName); - if (p != null) { - GroupManager.BukkitPermissions.updatePermissions(p); - } - } - return success; - } - - @Override - public String[] getPlayerGroups(String worldName, String playerName) { - AnjoPermissionsHandler handler; - if (worldName == null) { - handler = groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); - } else { - handler = groupManager.getWorldsHolder().getWorldPermissions(worldName); - } - if (handler == null) { - return null; - } - return handler.getGroups(playerName); - } - - @Override - public String getPrimaryGroup(String worldName, String playerName) { - AnjoPermissionsHandler handler; - if (worldName == null) { - handler = groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); - } else { - handler = groupManager.getWorldsHolder().getWorldPermissions(worldName); - } - if (handler == null) { - return null; - } - return handler.getGroup(playerName); - } - - @Override - public String[] getGroups() { - Set groupNames = new HashSet(); - for (World world : Bukkit.getServer().getWorlds()) { - OverloadedWorldHolder owh = groupManager.getWorldsHolder().getWorldData(world.getName()); - if (owh == null) { - continue; - } - Collection groups = owh.getGroupList(); - if (groups == null) { - continue; - } - for (Group group : groups) { - groupNames.add(group.getName()); - } - } - return groupNames.toArray(new String[0]); - } - - @Override - public boolean hasSuperPermsCompat() { - return true; - } - - @Override - public boolean hasGroupSupport() { - return true; - } + + private final String name = "GroupManager"; + private GroupManager groupManager; + + public Permission_GroupManager(final Plugin plugin) { + this.plugin = plugin; + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); + + // Load Plugin in case it was loaded before + if (this.groupManager == null) { + final Plugin perms = plugin.getServer().getPluginManager().getPlugin("GroupManager"); + if (perms != null && perms.isEnabled()) { + this.groupManager = (GroupManager) perms; + Permission.log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), this.name)); + } + } + } + + public class PermissionServerListener implements Listener { + final Permission_GroupManager permission; + + public PermissionServerListener(final Permission_GroupManager permission) { + this.permission = permission; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.permission.groupManager == null) { + final Plugin p = event.getPlugin(); + if (p.getDescription().getName().equals("GroupManager")) { + this.permission.groupManager = (GroupManager) p; + Permission.log.info(String.format("[%s][Permission] %s hooked.", Permission_GroupManager.this.plugin.getDescription().getName(), this.permission.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.permission.groupManager != null) { + if (event.getPlugin().getDescription().getName().equals("GroupManager")) { + this.permission.groupManager = null; + Permission.log.info(String.format("[%s][Permission] %s un-hooked.", Permission_GroupManager.this.plugin.getDescription().getName(), this.permission.name)); + } + } + } + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean isEnabled() { + return this.groupManager != null && this.groupManager.isEnabled(); + } + + @Override + public boolean playerHas(final String worldName, final String playerName, final String permission) { + final AnjoPermissionsHandler handler; + if (worldName == null) { + handler = this.groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); + } else { + handler = this.groupManager.getWorldsHolder().getWorldPermissions(worldName); + } + if (handler == null) { + return false; + } + return handler.permission(playerName, permission); + } + + @Override + public boolean playerAdd(final String worldName, final String playerName, final String permission) { + final OverloadedWorldHolder owh; + if (worldName == null) { + owh = this.groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName); + } else { + owh = this.groupManager.getWorldsHolder().getWorldData(worldName); + } + if (owh == null) { + return false; + } + + final User user = owh.getUser(playerName); + if (user == null) { + return false; + } + + user.addPermission(permission); + final Player p = Bukkit.getPlayer(playerName); + if (p != null) { + GroupManager.BukkitPermissions.updatePermissions(p); + } + return true; + } + + @Override + public boolean playerRemove(final String worldName, final String playerName, final String permission) { + final OverloadedWorldHolder owh; + if (worldName == null) { + owh = this.groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName); + } else { + owh = this.groupManager.getWorldsHolder().getWorldData(worldName); + } + if (owh == null) { + return false; + } + + final User user = owh.getUser(playerName); + if (user == null) { + return false; + } + + user.removePermission(permission); + final Player p = Bukkit.getPlayer(playerName); + if (p != null) { + GroupManager.BukkitPermissions.updatePermissions(p); + } + return true; + } + + @Override + public boolean groupHas(final String worldName, final String groupName, final String permission) { + final OverloadedWorldHolder owh; + if (worldName == null) { + owh = this.groupManager.getWorldsHolder().getDefaultWorld(); + } else { + owh = this.groupManager.getWorldsHolder().getWorldData(worldName); + } + if (owh == null) { + return false; + } + + final Group group = owh.getGroup(groupName); + if (group == null) { + return false; + } + + return group.hasSamePermissionNode(permission); + } + + @Override + public boolean groupAdd(final String worldName, final String groupName, final String permission) { + final OverloadedWorldHolder owh; + if (worldName == null) { + owh = this.groupManager.getWorldsHolder().getDefaultWorld(); + } else { + owh = this.groupManager.getWorldsHolder().getWorldData(worldName); + } + if (owh == null) { + return false; + } + + final Group group = owh.getGroup(groupName); + if (group == null) { + return false; + } + + group.addPermission(permission); + return true; + } + + @Override + public boolean groupRemove(final String worldName, final String groupName, final String permission) { + final OverloadedWorldHolder owh; + if (worldName == null) { + owh = this.groupManager.getWorldsHolder().getDefaultWorld(); + } else { + owh = this.groupManager.getWorldsHolder().getWorldData(worldName); + } + if (owh == null) { + return false; + } + + final Group group = owh.getGroup(groupName); + if (group == null) { + return false; + } + + group.removePermission(permission); + return true; + } + + @Override + public boolean playerInGroup(final String worldName, final String playerName, final String groupName) { + final AnjoPermissionsHandler handler; + if (worldName == null) { + handler = this.groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); + } else { + handler = this.groupManager.getWorldsHolder().getWorldPermissions(worldName); + } + if (handler == null) { + return false; + } + return handler.inGroup(playerName, groupName); + } + + @Override + public boolean playerAddGroup(final String worldName, final String playerName, final String groupName) { + final OverloadedWorldHolder owh; + if (worldName == null) { + owh = this.groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName); + } else { + owh = this.groupManager.getWorldsHolder().getWorldData(worldName); + } + if (owh == null) { + return false; + } + final User user = owh.getUser(playerName); + if (user == null) { + return false; + } + final Group group = owh.getGroup(groupName); + if (group == null) { + return false; + } + if (user.getGroup().equals(owh.getDefaultGroup())) { + user.setGroup(group); + } else if (group.getInherits().contains(user.getGroup().getName().toLowerCase())) { + user.setGroup(group); + } else { + user.addSubGroup(group); + } + final Player p = Bukkit.getPlayer(playerName); + if (p != null) { + GroupManager.BukkitPermissions.updatePermissions(p); + } + return true; + } + + @Override + public boolean playerRemoveGroup(final String worldName, final String playerName, final String groupName) { + final OverloadedWorldHolder owh; + if (worldName == null) { + owh = this.groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName); + } else { + owh = this.groupManager.getWorldsHolder().getWorldData(worldName); + } + if (owh == null) { + return false; + } + final User user = owh.getUser(playerName); + if (user == null) { + return false; + } + boolean success = false; + if (user.getGroup().getName().equalsIgnoreCase(groupName)) { + user.setGroup(owh.getDefaultGroup()); + success = true; + } else { + final Group group = owh.getGroup(groupName); + if (group != null) { + success = user.removeSubGroup(group); + } + } + if (success) { + final Player p = Bukkit.getPlayer(playerName); + if (p != null) { + GroupManager.BukkitPermissions.updatePermissions(p); + } + } + return success; + } + + @Override + public String[] getPlayerGroups(final String worldName, final String playerName) { + final AnjoPermissionsHandler handler; + if (worldName == null) { + handler = this.groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); + } else { + handler = this.groupManager.getWorldsHolder().getWorldPermissions(worldName); + } + if (handler == null) { + return null; + } + return handler.getGroups(playerName); + } + + @Override + public String getPrimaryGroup(final String worldName, final String playerName) { + final AnjoPermissionsHandler handler; + if (worldName == null) { + handler = this.groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName); + } else { + handler = this.groupManager.getWorldsHolder().getWorldPermissions(worldName); + } + if (handler == null) { + return null; + } + return handler.getGroup(playerName); + } + + @Override + public String[] getGroups() { + final Set groupNames = new HashSet<>(); + for (final World world : Bukkit.getServer().getWorlds()) { + final OverloadedWorldHolder owh = this.groupManager.getWorldsHolder().getWorldData(world.getName()); + if (owh == null) { + continue; + } + final Collection groups = owh.getGroupList(); + if (groups == null) { + continue; + } + for (final Group group : groups) { + groupNames.add(group.getName()); + } + } + return groupNames.toArray(new String[0]); + } + + @Override + public boolean hasSuperPermsCompat() { + return true; + } + + @Override + public boolean hasGroupSupport() { + return true; + } } diff --git a/src/net/milkbowl/vault/permission/plugins/Permission_KPerms.java b/src/net/milkbowl/vault/permission/plugins/Permission_KPerms.java index 4cc24b80..1f264072 100644 --- a/src/net/milkbowl/vault/permission/plugins/Permission_KPerms.java +++ b/src/net/milkbowl/vault/permission/plugins/Permission_KPerms.java @@ -15,8 +15,11 @@ */ package net.milkbowl.vault.permission.plugins; +import com.lightniinja.kperms.KGroup; +import com.lightniinja.kperms.KPermsPlugin; +import com.lightniinja.kperms.KPlayer; +import com.lightniinja.kperms.Utilities; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -27,138 +30,132 @@ import java.util.List; -import com.lightniinja.kperms.KPlayer; -import com.lightniinja.kperms.KGroup; -import com.lightniinja.kperms.Utilities; -import com.lightniinja.kperms.KPermsPlugin; - public class Permission_KPerms extends Permission { - - private final Plugin vault; - private KPermsPlugin kperms = null; - - public Permission_KPerms(Plugin plugin) { - super(); - this.vault = plugin; - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), vault); - if (kperms == null) { - Plugin perms = plugin.getServer().getPluginManager().getPlugin("KPerms"); - if (perms != null && perms.isEnabled()) { - this.kperms = (KPermsPlugin) perms; - plugin.getLogger().info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), "KPerms")); - } - } - } - - private class PermissionServerListener implements Listener { - private final Permission_KPerms bridge; - - public PermissionServerListener(Permission_KPerms bridge) { - this.bridge = bridge; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if(bridge.kperms == null) { - Plugin plugin = event.getPlugin(); - if (plugin.getDescription().getName().equals("KPerms")) { - bridge.kperms = (KPermsPlugin) plugin; - log.info(String.format("[%s][Permission] %s hooked.", vault.getDescription().getName(), "KPerms")); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if(bridge.kperms != null){ - if(event.getPlugin().getDescription().getName().equals(bridge.kperms.getName())) { - bridge.kperms = null; - log.info(String.format("[%s][Permission] %s un-hooked.", vault.getDescription().getName(), "KPerms")); - } - } - } - } - - @Override - public String getName() { - return "KPerms"; - } - - @Override - public boolean isEnabled() { - return kperms.isEnabled(); - } - - @Override - public boolean hasSuperPermsCompat() { - return true; - } - - @Override - public boolean hasGroupSupport() { - return true; - } - - @Override - public boolean playerHas(String world, String player, String permission) { - return new KPlayer(player, kperms).hasPermission(permission); - } - - @Override - public boolean playerAdd(String world, String player, String permission) { - return new KPlayer(player, kperms).addPermission(permission); - } - - @Override - public boolean playerRemove(String world, String player, String permission) { - return new KPlayer(player, kperms).removePermission(permission); - } - - @Override - public boolean groupHas(String world, String group, String permission) { - return new KGroup(group, kperms).hasPermission(permission); - } - - @Override - public boolean groupAdd(String world, String group, String permission) { - return new KGroup(group, kperms).addPermission(permission); - } - - @Override - public boolean groupRemove(String world, String group, String permission) { - return new KGroup(group, kperms).removePermission(permission); - } - - @Override - public boolean playerInGroup(String world, String player, String group) { - return new KPlayer(player, kperms).isMemberOfGroup(group); - } - - @Override - public boolean playerAddGroup(String world, String player, String group) { - return new KPlayer(player, kperms).addGroup(group); - } - - @Override - public boolean playerRemoveGroup(String world, String player, String group) { - return new KPlayer(player, kperms).removeGroup(group); - } - - @Override - public String[] getPlayerGroups(String world, String player) { - List groups = new KPlayer(player, kperms).getGroups(); - String[] gr = new String[groups.size()]; - gr = groups.toArray(gr); - return gr; - } - - @Override - public String getPrimaryGroup(String world, String player) { - return new KPlayer(player, kperms).getPrimaryGroup(); - } - - @Override - public String[] getGroups() { - return new Utilities(kperms).getGroups(); - } + + private final Plugin vault; + private KPermsPlugin kperms; + + public Permission_KPerms(final Plugin plugin) { + vault = plugin; + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), this.vault); + if (this.kperms == null) { + final Plugin perms = plugin.getServer().getPluginManager().getPlugin("KPerms"); + if (perms != null && perms.isEnabled()) { + kperms = (KPermsPlugin) perms; + plugin.getLogger().info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), "KPerms")); + } + } + } + + private class PermissionServerListener implements Listener { + private final Permission_KPerms bridge; + + public PermissionServerListener(final Permission_KPerms bridge) { + this.bridge = bridge; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.bridge.kperms == null) { + final Plugin plugin = event.getPlugin(); + if (plugin.getDescription().getName().equals("KPerms")) { + this.bridge.kperms = (KPermsPlugin) plugin; + Permission.log.info(String.format("[%s][Permission] %s hooked.", Permission_KPerms.this.vault.getDescription().getName(), "KPerms")); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.bridge.kperms != null) { + if (event.getPlugin().getDescription().getName().equals(this.bridge.kperms.getName())) { + this.bridge.kperms = null; + Permission.log.info(String.format("[%s][Permission] %s un-hooked.", Permission_KPerms.this.vault.getDescription().getName(), "KPerms")); + } + } + } + } + + @Override + public String getName() { + return "KPerms"; + } + + @Override + public boolean isEnabled() { + return this.kperms.isEnabled(); + } + + @Override + public boolean hasSuperPermsCompat() { + return true; + } + + @Override + public boolean hasGroupSupport() { + return true; + } + + @Override + public boolean playerHas(final String world, final String player, final String permission) { + return new KPlayer(player, this.kperms).hasPermission(permission); + } + + @Override + public boolean playerAdd(final String world, final String player, final String permission) { + return new KPlayer(player, this.kperms).addPermission(permission); + } + + @Override + public boolean playerRemove(final String world, final String player, final String permission) { + return new KPlayer(player, this.kperms).removePermission(permission); + } + + @Override + public boolean groupHas(final String world, final String group, final String permission) { + return new KGroup(group, this.kperms).hasPermission(permission); + } + + @Override + public boolean groupAdd(final String world, final String group, final String permission) { + return new KGroup(group, this.kperms).addPermission(permission); + } + + @Override + public boolean groupRemove(final String world, final String group, final String permission) { + return new KGroup(group, this.kperms).removePermission(permission); + } + + @Override + public boolean playerInGroup(final String world, final String player, final String group) { + return new KPlayer(player, this.kperms).isMemberOfGroup(group); + } + + @Override + public boolean playerAddGroup(final String world, final String player, final String group) { + return new KPlayer(player, this.kperms).addGroup(group); + } + + @Override + public boolean playerRemoveGroup(final String world, final String player, final String group) { + return new KPlayer(player, this.kperms).removeGroup(group); + } + + @Override + public String[] getPlayerGroups(final String world, final String player) { + final List groups = new KPlayer(player, this.kperms).getGroups(); + String[] gr = new String[groups.size()]; + gr = groups.toArray(gr); + return gr; + } + + @Override + public String getPrimaryGroup(final String world, final String player) { + return new KPlayer(player, this.kperms).getPrimaryGroup(); + } + + @Override + public String[] getGroups() { + return new Utilities(this.kperms).getGroups(); + } } diff --git a/src/net/milkbowl/vault/permission/plugins/Permission_OverPermissions.java b/src/net/milkbowl/vault/permission/plugins/Permission_OverPermissions.java index d3d977cc..c893be97 100644 --- a/src/net/milkbowl/vault/permission/plugins/Permission_OverPermissions.java +++ b/src/net/milkbowl/vault/permission/plugins/Permission_OverPermissions.java @@ -12,10 +12,12 @@ */ package net.milkbowl.vault.permission.plugins; -import java.util.ArrayList; - +import com.overmc.overpermissions.api.GroupManager; +import com.overmc.overpermissions.api.PermissionGroup; +import com.overmc.overpermissions.api.PermissionUser; +import com.overmc.overpermissions.api.UserManager; +import com.overmc.overpermissions.internal.OverPermissions; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -24,201 +26,196 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import com.overmc.overpermissions.api.GroupManager; -import com.overmc.overpermissions.api.PermissionGroup; -import com.overmc.overpermissions.api.PermissionUser; -import com.overmc.overpermissions.api.UserManager; -import com.overmc.overpermissions.internal.OverPermissions; +import java.util.ArrayList; public class Permission_OverPermissions extends Permission { - private OverPermissions overPerms; - private UserManager userManager; - private GroupManager groupManager; - - public Permission_OverPermissions(Plugin plugin) { - super.plugin = plugin; - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); - - if (overPerms == null) { - Plugin perms = plugin.getServer().getPluginManager().getPlugin("OverPermissions"); - if ((perms != null) && (perms.isEnabled())) { - overPerms = ((OverPermissions) perms); - userManager = overPerms.getUserManager(); - groupManager = overPerms.getGroupManager(); - log.info(String.format("[%s][Permission] %s hooked.", new Object[] {plugin.getDescription().getName(), "OverPermissions"})); - } - } - } - - @Override - public String getName( ) { - return "OverPermissions"; - } - - @Override - public boolean isEnabled( ) { - return (overPerms != null) && (overPerms.isEnabled()); - } - - @Override - public boolean playerHas(String worldName, String playerName, String permission) { - if (!userManager.doesUserExist(playerName)) { - return false; - } - return userManager.getPermissionUser(playerName).getPermission(permission, worldName); - } - - @Override - public boolean playerAdd(String worldName, String playerName, String permission) { - if (!userManager.canUserExist(playerName)) { - return false; - } - return userManager.getPermissionUser(playerName).addPermissionNode(permission, worldName); - } - - @Override - public boolean playerRemove(String worldName, String playerName, String permission) { - if (!userManager.canUserExist(playerName)) { - return false; - } - return userManager.getPermissionUser(playerName).removePermissionNode(permission, worldName); - } - - @Override - public boolean groupHas(String worldName, String groupName, String permission) { - if (!groupManager.doesGroupExist(groupName)) { - return false; - } - return groupManager.getGroup(groupName).getPermission(permission, worldName); - } - - @Override - public boolean groupAdd(String worldName, String groupName, String permission) { - if (!groupManager.doesGroupExist(groupName)) { - return false; - } - if (worldName == null) { - return groupManager.getGroup(groupName).addGlobalPermissionNode(permission); - } else { - return groupManager.getGroup(groupName).addPermissionNode(permission, worldName); - } - } - - @Override - public boolean groupRemove(String worldName, String groupName, String permission) { - if (!groupManager.doesGroupExist(groupName)) { - return false; - } - if (worldName == null) { - return groupManager.getGroup(groupName).removeGlobalPermissionNode(permission); - } else { - return groupManager.getGroup(groupName).removePermissionNode(permission, worldName); - } - } - - @Override - public boolean playerInGroup(String worldName, String playerName, String groupName) { - if (!groupManager.doesGroupExist(groupName)) { - return false; - } - if (!userManager.doesUserExist(playerName)) { - return false; - } - return userManager.getPermissionUser(playerName).getAllParents().contains(groupManager.getGroup(groupName)); - } - - @Override - public boolean playerAddGroup(String worldName, String playerName, String groupName) { - if (!groupManager.doesGroupExist(groupName)) { - return false; - } - if (!userManager.canUserExist(playerName)) { - return false; - } - return userManager.getPermissionUser(playerName).addParent(groupManager.getGroup(groupName)); - } - - @Override - public boolean playerRemoveGroup(String worldName, String playerName, String groupName) { - if (!groupManager.doesGroupExist(groupName)) { - return false; - } - if (!userManager.canUserExist(playerName)) { - return false; - } - return userManager.getPermissionUser(playerName).removeParent(groupManager.getGroup(groupName)); - } - - @Override - public String[] getPlayerGroups(String worldName, String playerName) { - ArrayList ret = new ArrayList(); - if (!userManager.doesUserExist(playerName)) { - return new String[0]; - } - PermissionUser user = userManager.getPermissionUser(playerName); - for (PermissionGroup parent : user.getAllParents()) { - ret.add(parent.getName()); - } - return ret.toArray(new String[ret.size()]); - } - - @Override - public String getPrimaryGroup(String worldName, String playerName) { - String[] playerGroups = getPlayerGroups(worldName, playerName); - if (playerGroups.length == 0) { - return null; - } - return playerGroups[0]; - } - - @Override - public String[] getGroups( ) { - ArrayList groupNames = new ArrayList(); - for (PermissionGroup s : groupManager.getGroups()) { - groupNames.add(s.getName()); - } - return groupNames.toArray(new String[groupNames.size()]); - } - - @Override - public boolean hasSuperPermsCompat( ) { - return true; - } - - @Override - public boolean hasGroupSupport( ) { - return true; - } - - public class PermissionServerListener - implements Listener { - Permission_OverPermissions permission = null; - - public PermissionServerListener(Permission_OverPermissions permission) { - this.permission = permission; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (permission.overPerms == null) { - Plugin perms = Permission_OverPermissions.this.plugin.getServer().getPluginManager().getPlugin("OverPermissions"); - if (perms != null) { - permission.overPerms = ((OverPermissions) perms); - Permission_OverPermissions.log.info(String - .format("[%s][Permission] %s hooked.", new Object[] {Permission_OverPermissions.this.plugin.getDescription().getName(), "OverPermissions"})); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) - { - if ((permission.overPerms != null) && - (event.getPlugin().getDescription().getName().equals("OverPermissions"))) { - permission.overPerms = null; - Permission_OverPermissions.log.info(String - .format("[%s][Permission] %s un-hooked.", new Object[] {Permission_OverPermissions.this.plugin.getDescription().getName(), "OverPermissions"})); - } - } - } + private OverPermissions overPerms; + private UserManager userManager; + private GroupManager groupManager; + + public Permission_OverPermissions(final Plugin plugin) { + super.plugin = plugin; + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); + + if (this.overPerms == null) { + final Plugin perms = plugin.getServer().getPluginManager().getPlugin("OverPermissions"); + if ((perms != null) && (perms.isEnabled())) { + this.overPerms = ((OverPermissions) perms); + this.userManager = this.overPerms.getUserManager(); + this.groupManager = this.overPerms.getGroupManager(); + Permission.log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), "OverPermissions")); + } + } + } + + @Override + public String getName() { + return "OverPermissions"; + } + + @Override + public boolean isEnabled() { + return (this.overPerms != null) && (this.overPerms.isEnabled()); + } + + @Override + public boolean playerHas(final String worldName, final String playerName, final String permission) { + if (!this.userManager.doesUserExist(playerName)) { + return false; + } + return this.userManager.getPermissionUser(playerName).getPermission(permission, worldName); + } + + @Override + public boolean playerAdd(final String worldName, final String playerName, final String permission) { + if (!this.userManager.canUserExist(playerName)) { + return false; + } + return this.userManager.getPermissionUser(playerName).addPermissionNode(permission, worldName); + } + + @Override + public boolean playerRemove(final String worldName, final String playerName, final String permission) { + if (!this.userManager.canUserExist(playerName)) { + return false; + } + return this.userManager.getPermissionUser(playerName).removePermissionNode(permission, worldName); + } + + @Override + public boolean groupHas(final String worldName, final String groupName, final String permission) { + if (!this.groupManager.doesGroupExist(groupName)) { + return false; + } + return this.groupManager.getGroup(groupName).getPermission(permission, worldName); + } + + @Override + public boolean groupAdd(final String worldName, final String groupName, final String permission) { + if (!this.groupManager.doesGroupExist(groupName)) { + return false; + } + if (worldName == null) { + return this.groupManager.getGroup(groupName).addGlobalPermissionNode(permission); + } else { + return this.groupManager.getGroup(groupName).addPermissionNode(permission, worldName); + } + } + + @Override + public boolean groupRemove(final String worldName, final String groupName, final String permission) { + if (!this.groupManager.doesGroupExist(groupName)) { + return false; + } + if (worldName == null) { + return this.groupManager.getGroup(groupName).removeGlobalPermissionNode(permission); + } else { + return this.groupManager.getGroup(groupName).removePermissionNode(permission, worldName); + } + } + + @Override + public boolean playerInGroup(final String worldName, final String playerName, final String groupName) { + if (!this.groupManager.doesGroupExist(groupName)) { + return false; + } + if (!this.userManager.doesUserExist(playerName)) { + return false; + } + return this.userManager.getPermissionUser(playerName).getAllParents().contains(this.groupManager.getGroup(groupName)); + } + + @Override + public boolean playerAddGroup(final String worldName, final String playerName, final String groupName) { + if (!this.groupManager.doesGroupExist(groupName)) { + return false; + } + if (!this.userManager.canUserExist(playerName)) { + return false; + } + return this.userManager.getPermissionUser(playerName).addParent(this.groupManager.getGroup(groupName)); + } + + @Override + public boolean playerRemoveGroup(final String worldName, final String playerName, final String groupName) { + if (!this.groupManager.doesGroupExist(groupName)) { + return false; + } + if (!this.userManager.canUserExist(playerName)) { + return false; + } + return this.userManager.getPermissionUser(playerName).removeParent(this.groupManager.getGroup(groupName)); + } + + @Override + public String[] getPlayerGroups(final String worldName, final String playerName) { + final ArrayList ret = new ArrayList<>(); + if (!this.userManager.doesUserExist(playerName)) { + return new String[0]; + } + final PermissionUser user = this.userManager.getPermissionUser(playerName); + for (final PermissionGroup parent : user.getAllParents()) { + ret.add(parent.getName()); + } + return ret.toArray(new String[0]); + } + + @Override + public String getPrimaryGroup(final String worldName, final String playerName) { + final String[] playerGroups = this.getPlayerGroups(worldName, playerName); + if (playerGroups.length == 0) { + return null; + } + return playerGroups[0]; + } + + @Override + public String[] getGroups() { + final ArrayList groupNames = new ArrayList<>(); + for (final PermissionGroup s : this.groupManager.getGroups()) { + groupNames.add(s.getName()); + } + return groupNames.toArray(new String[0]); + } + + @Override + public boolean hasSuperPermsCompat() { + return true; + } + + @Override + public boolean hasGroupSupport() { + return true; + } + + public class PermissionServerListener + implements Listener { + final Permission_OverPermissions permission; + + public PermissionServerListener(final Permission_OverPermissions permission) { + this.permission = permission; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.permission.overPerms == null) { + final Plugin perms = plugin.getServer().getPluginManager().getPlugin("OverPermissions"); + if (perms != null) { + this.permission.overPerms = ((OverPermissions) perms); + Permission.log.info(String + .format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), "OverPermissions")); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if ((this.permission.overPerms != null) && + (event.getPlugin().getDescription().getName().equals("OverPermissions"))) { + this.permission.overPerms = null; + Permission.log.info(String + .format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), "OverPermissions")); + } + } + } } diff --git a/src/net/milkbowl/vault/permission/plugins/Permission_Permissions3.java b/src/net/milkbowl/vault/permission/plugins/Permission_Permissions3.java index 960f4e74..18f22c1d 100644 --- a/src/net/milkbowl/vault/permission/plugins/Permission_Permissions3.java +++ b/src/net/milkbowl/vault/permission/plugins/Permission_Permissions3.java @@ -15,11 +15,10 @@ */ package net.milkbowl.vault.permission.plugins; -import java.util.HashSet; -import java.util.Set; - +import com.nijiko.permissions.Group; +import com.nijiko.permissions.ModularControl; +import com.nijikokun.bukkit.Permissions.Permissions; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.command.CommandSender; @@ -31,265 +30,264 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import com.nijiko.permissions.Group; -import com.nijiko.permissions.ModularControl; -import com.nijikokun.bukkit.Permissions.Permissions; +import java.util.HashSet; +import java.util.Set; public class Permission_Permissions3 extends Permission { - - private String name = "Permissions3"; - private ModularControl perms; - private Permissions permission = null; - - public Permission_Permissions3(Plugin plugin) { - this.plugin = plugin; - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); - - // Load Plugin in case it was loaded before - if (permission == null) { - Plugin perms = plugin.getServer().getPluginManager().getPlugin("Permissions"); - if (perms == null) { - plugin.getServer().getPluginManager().getPlugin("vPerms"); - name = "vPerms"; - } - if (perms != null) { - if (perms.isEnabled() && perms.getDescription().getVersion().startsWith("3")) { - permission = (Permissions) perms; - this.perms = (ModularControl) permission.getHandler(); - log.severe("Your permission system is outdated and no longer fully supported! It is highly advised to update!"); - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - } - - @Override - public boolean isEnabled() { - if (permission == null) { - return false; - } else { - return permission.isEnabled(); - } - } - - @Override - public boolean playerInGroup(String worldName, String playerName, String groupName) { - return this.permission.getHandler().inGroup(worldName, playerName, groupName); - } - - public class PermissionServerListener implements Listener { - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (permission == null) { - Plugin permi = event.getPlugin(); - if((permi.getDescription().getName().equals("Permissions") || permi.getDescription().getName().equals("vPerms")) && permi.getDescription().getVersion().startsWith("3")) { - if (permi.isEnabled()) { - permission = (Permissions) permi; - perms = (ModularControl) permission.getHandler(); - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (permission != null) { - if (event.getPlugin().getDescription().getName().equals("Permissions") || event.getPlugin().getDescription().getName().equals("vPerms")) { - permission = null; - perms = null; - log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), name)); - } - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean has(CommandSender sender, String permission) { - if (sender.isOp() || !(sender instanceof Player)) { - return true; - } else { - return has(((Player) sender).getWorld().getName(), sender.getName(), permission); - } - } - - @Override - public boolean has(Player player, String permission) { - return has(player.getWorld().getName(), player.getName(), permission); - } - - public boolean playerAddGroup(String worldName, String playerName, String groupName) { - if (worldName == null) { - worldName = "*"; - } - - Group g = perms.getGroupObject(worldName, groupName); - if (g == null) { - return false; - } - try { - perms.safeGetUser(worldName, playerName).addParent(g); - } catch (Exception e) { - e.printStackTrace(); - return false; - } - return true; - } - - @Override - public boolean playerRemoveGroup(String worldName, String playerName, String groupName) { - if (worldName == null) { - worldName = "*"; - } - - Group g = perms.getGroupObject(worldName, groupName); - if (g == null) { - return false; - } - try { - perms.safeGetUser(worldName, playerName).removeParent(g); - } catch (Exception e) { - e.printStackTrace(); - return false; - } - return true; - } - - @Override - public boolean playerAdd(String worldName, String playerName, String permission) { - this.perms.addUserPermission(worldName, playerName, permission); - return true; - } - - @Override - public boolean playerRemove(String worldName, String playerName, String permission) { - this.perms.removeUserPermission(worldName, playerName, permission); - return true; - } - - @Override - public boolean groupAdd(String worldName, String groupName, String permission) { - if (worldName == null) { - worldName = "*"; - } - - perms.addGroupPermission(worldName, groupName, permission); - return true; - } - - @Override - public boolean groupRemove(String worldName, String groupName, String permission) { - if (worldName == null) { - worldName = "*"; - } - perms.removeGroupPermission(worldName, groupName, permission); - return true; - } - - @Override - public boolean groupHas(String worldName, String groupName, String permission) { - if (worldName == null) { - worldName = "*"; - } - try { - return perms.safeGetGroup(worldName, groupName).hasPermission(permission); - } catch (Exception e) { - e.printStackTrace(); - return false; - } - } - - @Override - public String[] getPlayerGroups(String world, String playerName) { - return this.perms.getGroups(world, playerName); - } - - public String getPrimaryGroup(String world, String playerName) { - return getPlayerGroups(world, playerName)[0]; - } - - @Override - public boolean playerHas(String worldName, String playerName, String permission) { - Player p = plugin.getServer().getPlayer(playerName); - if (p != null) { - if (p.hasPermission(permission)) - return true; - } - return this.perms.has(worldName, playerName, permission); - } - - @Override - public boolean playerAddTransient(Player player, String permission) { - return playerAddTransient(null, player.getName(), permission); - } - - @Override - public boolean playerAddTransient(String worldName, Player player, String permission) { - return playerAddTransient(worldName, player.getName(), permission); - } - - private boolean playerAddTransient(String worldName, String player, String permission) { - if (worldName == null) { - worldName = "*"; - } - try { - perms.safeGetUser(worldName, player).addTransientPermission(permission); - return true; - } catch(Exception e) { - return false; - } - } - - - @Override - public boolean playerRemoveTransient(Player player, String permission) { - return pRemoveTransient(null, player.getName(), permission); - } - - @Override - public boolean playerRemoveTransient(String worldName, Player player, String permission) { - return pRemoveTransient(worldName, player.getName(), permission); - } - - @Override - public String[] getGroups() { - - Set groupNames = new HashSet(); - for (World world : Bukkit.getServer().getWorlds()) { - for (Group group : perms.getGroups(world.getName())) { - groupNames.add(group.getName()); - } - } - return groupNames.toArray(new String[0]); - } - - @Override - public boolean hasSuperPermsCompat() { - return false; - } - - @Override - public boolean hasGroupSupport() { - return true; - } - - private boolean pRemoveTransient(String worldName, String player, String permission) { - if (worldName == null) { - worldName = "*"; - } - - try { - perms.safeGetUser(worldName, player).removeTransientPermission(permission); - return true; - } catch (Exception e) { - return false; - } - } - + + private String name = "Permissions3"; + private ModularControl perms; + private Permissions permission; + + public Permission_Permissions3(final Plugin plugin) { + this.plugin = plugin; + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); + + // Load Plugin in case it was loaded before + if (this.permission == null) { + final Plugin perms = plugin.getServer().getPluginManager().getPlugin("Permissions"); + if (perms == null) { + plugin.getServer().getPluginManager().getPlugin("vPerms"); + this.name = "vPerms"; + } + if (perms != null) { + if (perms.isEnabled() && perms.getDescription().getVersion().startsWith("3")) { + this.permission = (Permissions) perms; + this.perms = (ModularControl) this.permission.getHandler(); + Permission.log.severe("Your permission system is outdated and no longer fully supported! It is highly advised to update!"); + Permission.log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), this.name)); + } + } + } + } + + @Override + public boolean isEnabled() { + if (this.permission == null) { + return false; + } else { + return this.permission.isEnabled(); + } + } + + @Override + public boolean playerInGroup(final String worldName, final String playerName, final String groupName) { + return permission.getHandler().inGroup(worldName, playerName, groupName); + } + + public class PermissionServerListener implements Listener { + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (Permission_Permissions3.this.permission == null) { + final Plugin permi = event.getPlugin(); + if ((permi.getDescription().getName().equals("Permissions") || permi.getDescription().getName().equals("vPerms")) && permi.getDescription().getVersion().startsWith("3")) { + if (permi.isEnabled()) { + Permission_Permissions3.this.permission = (Permissions) permi; + Permission_Permissions3.this.perms = (ModularControl) Permission_Permissions3.this.permission.getHandler(); + Permission.log.info(String.format("[%s][Permission] %s hooked.", Permission_Permissions3.this.plugin.getDescription().getName(), Permission_Permissions3.this.name)); + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (Permission_Permissions3.this.permission != null) { + if (event.getPlugin().getDescription().getName().equals("Permissions") || event.getPlugin().getDescription().getName().equals("vPerms")) { + Permission_Permissions3.this.permission = null; + Permission_Permissions3.this.perms = null; + Permission.log.info(String.format("[%s][Permission] %s un-hooked.", Permission_Permissions3.this.plugin.getDescription().getName(), Permission_Permissions3.this.name)); + } + } + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean has(final CommandSender sender, final String permission) { + if (sender.isOp() || !(sender instanceof Player)) { + return true; + } else { + return this.has(((Player) sender).getWorld().getName(), sender.getName(), permission); + } + } + + @Override + public boolean has(final Player player, final String permission) { + return this.has(player.getWorld().getName(), player.getName(), permission); + } + + public boolean playerAddGroup(String worldName, final String playerName, final String groupName) { + if (worldName == null) { + worldName = "*"; + } + + final Group g = this.perms.getGroupObject(worldName, groupName); + if (g == null) { + return false; + } + try { + this.perms.safeGetUser(worldName, playerName).addParent(g); + } catch (final Exception e) { + e.printStackTrace(); + return false; + } + return true; + } + + @Override + public boolean playerRemoveGroup(String worldName, final String playerName, final String groupName) { + if (worldName == null) { + worldName = "*"; + } + + final Group g = this.perms.getGroupObject(worldName, groupName); + if (g == null) { + return false; + } + try { + this.perms.safeGetUser(worldName, playerName).removeParent(g); + } catch (final Exception e) { + e.printStackTrace(); + return false; + } + return true; + } + + @Override + public boolean playerAdd(final String worldName, final String playerName, final String permission) { + perms.addUserPermission(worldName, playerName, permission); + return true; + } + + @Override + public boolean playerRemove(final String worldName, final String playerName, final String permission) { + perms.removeUserPermission(worldName, playerName, permission); + return true; + } + + @Override + public boolean groupAdd(String worldName, final String groupName, final String permission) { + if (worldName == null) { + worldName = "*"; + } + + this.perms.addGroupPermission(worldName, groupName, permission); + return true; + } + + @Override + public boolean groupRemove(String worldName, final String groupName, final String permission) { + if (worldName == null) { + worldName = "*"; + } + this.perms.removeGroupPermission(worldName, groupName, permission); + return true; + } + + @Override + public boolean groupHas(String worldName, final String groupName, final String permission) { + if (worldName == null) { + worldName = "*"; + } + try { + return this.perms.safeGetGroup(worldName, groupName).hasPermission(permission); + } catch (final Exception e) { + e.printStackTrace(); + return false; + } + } + + @Override + public String[] getPlayerGroups(final String world, final String playerName) { + return perms.getGroups(world, playerName); + } + + public String getPrimaryGroup(final String world, final String playerName) { + return this.getPlayerGroups(world, playerName)[0]; + } + + @Override + public boolean playerHas(final String worldName, final String playerName, final String permission) { + final Player p = this.plugin.getServer().getPlayer(playerName); + if (p != null) { + if (p.hasPermission(permission)) + return true; + } + return perms.has(worldName, playerName, permission); + } + + @Override + public boolean playerAddTransient(final Player player, final String permission) { + return this.playerAddTransient(null, player.getName(), permission); + } + + @Override + public boolean playerAddTransient(final String worldName, final Player player, final String permission) { + return this.playerAddTransient(worldName, player.getName(), permission); + } + + private boolean playerAddTransient(String worldName, final String player, final String permission) { + if (worldName == null) { + worldName = "*"; + } + try { + this.perms.safeGetUser(worldName, player).addTransientPermission(permission); + return true; + } catch (final Exception e) { + return false; + } + } + + + @Override + public boolean playerRemoveTransient(final Player player, final String permission) { + return this.pRemoveTransient(null, player.getName(), permission); + } + + @Override + public boolean playerRemoveTransient(final String worldName, final Player player, final String permission) { + return this.pRemoveTransient(worldName, player.getName(), permission); + } + + @Override + public String[] getGroups() { + + final Set groupNames = new HashSet<>(); + for (final World world : Bukkit.getServer().getWorlds()) { + for (final Group group : this.perms.getGroups(world.getName())) { + groupNames.add(group.getName()); + } + } + return groupNames.toArray(new String[0]); + } + + @Override + public boolean hasSuperPermsCompat() { + return false; + } + + @Override + public boolean hasGroupSupport() { + return true; + } + + private boolean pRemoveTransient(String worldName, final String player, final String permission) { + if (worldName == null) { + worldName = "*"; + } + + try { + this.perms.safeGetUser(worldName, player).removeTransientPermission(permission); + return true; + } catch (final Exception e) { + return false; + } + } + } diff --git a/src/net/milkbowl/vault/permission/plugins/Permission_PermissionsBukkit.java b/src/net/milkbowl/vault/permission/plugins/Permission_PermissionsBukkit.java index 7208246a..df5f5771 100644 --- a/src/net/milkbowl/vault/permission/plugins/Permission_PermissionsBukkit.java +++ b/src/net/milkbowl/vault/permission/plugins/Permission_PermissionsBukkit.java @@ -15,11 +15,10 @@ */ package net.milkbowl.vault.permission.plugins; -import java.util.ArrayList; -import java.util.List; - +import com.platymuus.bukkit.permissions.Group; +import com.platymuus.bukkit.permissions.PermissionInfo; +import com.platymuus.bukkit.permissions.PermissionsPlugin; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -28,210 +27,209 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import com.platymuus.bukkit.permissions.Group; -import com.platymuus.bukkit.permissions.PermissionInfo; -import com.platymuus.bukkit.permissions.PermissionsPlugin; +import java.util.ArrayList; +import java.util.List; public class Permission_PermissionsBukkit extends Permission { - - private final String name = "PermissionsBukkit"; - private PermissionsPlugin perms = null; - - public Permission_PermissionsBukkit(Plugin plugin) { - this.plugin = plugin; - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); - - // Load Plugin in case it was loaded before - if (perms == null) { - Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsBukkit"); - if (perms != null) { - this.perms = (PermissionsPlugin) perms; - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - - public class PermissionServerListener implements Listener { - Permission_PermissionsBukkit permission = null; - - public PermissionServerListener(Permission_PermissionsBukkit permission) { - this.permission = permission; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (permission.perms == null) { - Plugin perms = event.getPlugin(); - if (perms.getDescription().getName().equals("PermissionsBukkit")) { - permission.perms = (PermissionsPlugin) perms; - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (permission.perms != null) { - if (event.getPlugin().getDescription().getName().equals("PermissionsBukkit")) { - permission.perms = null; - log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name)); - } - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean isEnabled() { - if (perms == null) { - return false; - } else { - return perms.isEnabled(); - } - } - - @Override - public boolean playerHas(String world, String player, String permission) { - if (Bukkit.getPlayer(player) != null) { - return Bukkit.getPlayer(player).hasPermission(permission); - } else { - return false; - } - } - - @Override - public boolean playerAdd(String world, String player, String permission) { - if (world != null) { - permission = world + ":" + permission; - } - return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player setperm " + player + " " + permission + " true"); - } - - @Override - public boolean playerRemove(String world, String player, String permission) { - if (world != null) { - permission = world + ":" + permission; - } - return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player unsetperm " + player + " " + permission); - } - - // use superclass implementation of playerAddTransient() and playerRemoveTransient() - - @Override - public boolean groupHas(String world, String group, String permission) { - if (world != null && !world.isEmpty()) { - return perms.getGroup(group).getInfo().getWorldPermissions(world).get(permission) == null ? false : perms.getGroup(group).getInfo().getWorldPermissions(world).get(permission); - } - if (perms.getGroup(group) == null) { - return false; - } else if (perms.getGroup(group).getInfo() == null) { - return false; - } else if (perms.getGroup(group).getInfo().getPermissions() == null) { - return false; - } - return perms.getGroup(group).getInfo().getPermissions().get(permission); - } - - @Override - public boolean groupAdd(String world, String group, String permission) { - if (world != null) { - permission = world + ":" + permission; - } - return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions group setperm " + group + " " + permission + " true"); - } - - @Override - public boolean groupRemove(String world, String group, String permission) { - if (world != null) { - permission = world + ":" + permission; - } - return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions group unsetperm " + group + " " + permission); - } - - @Override - public boolean playerInGroup(String world, String player, String group) { - if (world != null) { - for (Group g : perms.getPlayerInfo(player).getGroups()) { - if (g.getName().equals(group)) { - return g.getInfo().getWorlds().contains(world); - } - } - return false; - } - Group g = perms.getGroup(group); - if (g == null) { - return false; - } - return g.getPlayers().contains(player); - } - - @Override - public boolean playerAddGroup(String world, String player, String group) { - if (world != null) { - return false; - } - return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player addgroup " + player + " " + group); - } - - @Override - public boolean playerRemoveGroup(String world, String player, String group) { - if (world != null) { - return false; - } - return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player removegroup " + player + " " + group); - } - - @Override - public String[] getPlayerGroups(String world, String player) { - List groupList = new ArrayList(); - PermissionInfo info = perms.getPlayerInfo(player); - if (world != null && info != null) { - for (Group group : perms.getPlayerInfo(player).getGroups()) { - if (group.getInfo().getWorlds().contains(world)) { - groupList.add(group.getName()); - } - } - return groupList.toArray(new String[0]); - } - if (info != null) { - for (Group group : info.getGroups()) { - groupList.add(group.getName()); - } - } - return groupList.toArray(new String[0]); - } - - @Override - public String getPrimaryGroup(String world, String player) { - if (perms.getPlayerInfo(player) == null) { - return null; - } else if (perms.getPlayerInfo(player).getGroups() != null && !perms.getPlayerInfo(player).getGroups().isEmpty() ) { - return perms.getPlayerInfo(player).getGroups().get(0).getName(); - } - return null; - } - - @Override - public String[] getGroups() { - List groupNames = new ArrayList(); - for (Group group : perms.getAllGroups()) { - groupNames.add(group.getName()); - } - - return groupNames.toArray(new String[0]); - } - - @Override - public boolean hasSuperPermsCompat() { - return true; - } - - @Override - public boolean hasGroupSupport() { - return true; - } + + private final String name = "PermissionsBukkit"; + private PermissionsPlugin perms; + + public Permission_PermissionsBukkit(final Plugin plugin) { + this.plugin = plugin; + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); + + // Load Plugin in case it was loaded before + if (this.perms == null) { + final Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsBukkit"); + if (perms != null) { + this.perms = (PermissionsPlugin) perms; + Permission.log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), this.name)); + } + } + } + + public class PermissionServerListener implements Listener { + final Permission_PermissionsBukkit permission; + + public PermissionServerListener(final Permission_PermissionsBukkit permission) { + this.permission = permission; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.permission.perms == null) { + final Plugin perms = event.getPlugin(); + if (perms.getDescription().getName().equals("PermissionsBukkit")) { + this.permission.perms = (PermissionsPlugin) perms; + Permission.log.info(String.format("[%s][Permission] %s hooked.", Permission_PermissionsBukkit.this.plugin.getDescription().getName(), this.permission.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.permission.perms != null) { + if (event.getPlugin().getDescription().getName().equals("PermissionsBukkit")) { + this.permission.perms = null; + Permission.log.info(String.format("[%s][Permission] %s un-hooked.", Permission_PermissionsBukkit.this.plugin.getDescription().getName(), this.permission.name)); + } + } + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean isEnabled() { + if (this.perms == null) { + return false; + } else { + return this.perms.isEnabled(); + } + } + + @Override + public boolean playerHas(final String world, final String player, final String permission) { + if (Bukkit.getPlayer(player) != null) { + return Bukkit.getPlayer(player).hasPermission(permission); + } else { + return false; + } + } + + @Override + public boolean playerAdd(final String world, final String player, String permission) { + if (world != null) { + permission = world + ":" + permission; + } + return this.plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player setperm " + player + " " + permission + " true"); + } + + @Override + public boolean playerRemove(final String world, final String player, String permission) { + if (world != null) { + permission = world + ":" + permission; + } + return this.plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player unsetperm " + player + " " + permission); + } + + // use superclass implementation of playerAddTransient() and playerRemoveTransient() + + @Override + public boolean groupHas(final String world, final String group, final String permission) { + if (world != null && !world.isEmpty()) { + return this.perms.getGroup(group).getInfo().getWorldPermissions(world).get(permission) != null && this.perms.getGroup(group).getInfo().getWorldPermissions(world).get(permission); + } + if (this.perms.getGroup(group) == null) { + return false; + } else if (this.perms.getGroup(group).getInfo() == null) { + return false; + } else if (this.perms.getGroup(group).getInfo().getPermissions() == null) { + return false; + } + return this.perms.getGroup(group).getInfo().getPermissions().get(permission); + } + + @Override + public boolean groupAdd(final String world, final String group, String permission) { + if (world != null) { + permission = world + ":" + permission; + } + return this.plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions group setperm " + group + " " + permission + " true"); + } + + @Override + public boolean groupRemove(final String world, final String group, String permission) { + if (world != null) { + permission = world + ":" + permission; + } + return this.plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions group unsetperm " + group + " " + permission); + } + + @Override + public boolean playerInGroup(final String world, final String player, final String group) { + if (world != null) { + for (final Group g : this.perms.getPlayerInfo(player).getGroups()) { + if (g.getName().equals(group)) { + return g.getInfo().getWorlds().contains(world); + } + } + return false; + } + final Group g = this.perms.getGroup(group); + if (g == null) { + return false; + } + return g.getPlayers().contains(player); + } + + @Override + public boolean playerAddGroup(final String world, final String player, final String group) { + if (world != null) { + return false; + } + return this.plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player addgroup " + player + " " + group); + } + + @Override + public boolean playerRemoveGroup(final String world, final String player, final String group) { + if (world != null) { + return false; + } + return this.plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player removegroup " + player + " " + group); + } + + @Override + public String[] getPlayerGroups(final String world, final String player) { + final List groupList = new ArrayList<>(); + final PermissionInfo info = this.perms.getPlayerInfo(player); + if (world != null && info != null) { + for (final Group group : this.perms.getPlayerInfo(player).getGroups()) { + if (group.getInfo().getWorlds().contains(world)) { + groupList.add(group.getName()); + } + } + return groupList.toArray(new String[0]); + } + if (info != null) { + for (final Group group : info.getGroups()) { + groupList.add(group.getName()); + } + } + return groupList.toArray(new String[0]); + } + + @Override + public String getPrimaryGroup(final String world, final String player) { + if (this.perms.getPlayerInfo(player) == null) { + return null; + } else if (this.perms.getPlayerInfo(player).getGroups() != null && !this.perms.getPlayerInfo(player).getGroups().isEmpty()) { + return this.perms.getPlayerInfo(player).getGroups().get(0).getName(); + } + return null; + } + + @Override + public String[] getGroups() { + final List groupNames = new ArrayList<>(); + for (final Group group : this.perms.getAllGroups()) { + groupNames.add(group.getName()); + } + + return groupNames.toArray(new String[0]); + } + + @Override + public boolean hasSuperPermsCompat() { + return true; + } + + @Override + public boolean hasGroupSupport() { + return true; + } } diff --git a/src/net/milkbowl/vault/permission/plugins/Permission_PermissionsEx.java b/src/net/milkbowl/vault/permission/plugins/Permission_PermissionsEx.java index 78128481..279ca504 100644 --- a/src/net/milkbowl/vault/permission/plugins/Permission_PermissionsEx.java +++ b/src/net/milkbowl/vault/permission/plugins/Permission_PermissionsEx.java @@ -15,10 +15,7 @@ */ package net.milkbowl.vault.permission.plugins; -import java.util.List; - import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -28,335 +25,336 @@ import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; - import ru.tehkode.permissions.PermissionGroup; import ru.tehkode.permissions.PermissionUser; import ru.tehkode.permissions.bukkit.PermissionsEx; -public class Permission_PermissionsEx extends Permission { - - private final String name = "PermissionsEx"; - private PermissionsEx permission = null; - - public Permission_PermissionsEx(Plugin plugin) { - this.plugin = plugin; - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); - - // Load Plugin in case it was loaded before - if (permission == null) { - Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsEx"); - if (perms != null) { - if (perms.isEnabled()) { - try { - if (Double.valueOf(perms.getDescription().getVersion()) < 1.16) { - log.info(String.format("[%s][Permission] %s below 1.16 is not compatible with Vault! Falling back to SuperPerms only mode. PLEASE UPDATE!", plugin.getDescription().getName(), name)); - } - } catch (NumberFormatException e) { - // Do nothing - } - permission = (PermissionsEx) perms; - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - } - - @Override - public boolean isEnabled() { - if (permission == null) { - return false; - } else { - return permission.isEnabled(); - } - } - - public class PermissionServerListener implements Listener { - Permission_PermissionsEx permission = null; - - public PermissionServerListener(Permission_PermissionsEx permission) { - this.permission = permission; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (permission.permission == null) { - Plugin perms = event.getPlugin(); - if (perms.getDescription().getName().equals("PermissionsEx")) { - try { - if (Double.valueOf(perms.getDescription().getVersion()) < 1.16) { - log.info(String.format("[%s][Permission] %s below 1.16 is not compatible with Vault! Falling back to SuperPerms only mode. PLEASE UPDATE!", plugin.getDescription().getName(), name)); - return; - } - } catch (NumberFormatException e) { - // Do nothing - } - permission.permission = (PermissionsEx) perms; - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (permission.permission != null) { - if (event.getPlugin().getDescription().getName().equals("PermissionsEx")) { - permission.permission = null; - log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name)); - } - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean playerInGroup(String worldName, OfflinePlayer op, String groupName) { - PermissionUser user = getUser(op); - if (user == null) { - return false; - } - return user.inGroup(groupName, worldName); - } - - @Override - public boolean playerInGroup(String worldName, String playerName, String groupName) { - return PermissionsEx.getPermissionManager().getUser(playerName).inGroup(groupName, worldName); - } - - @Override - public boolean playerAddGroup(String worldName, OfflinePlayer op, String groupName) { - PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); - PermissionUser user = getUser(op); - if (group == null || user == null) { - return false; - } else { - user.addGroup(groupName, worldName); - return true; - } - } - - @Override - public boolean playerAddGroup(String worldName, String playerName, String groupName) { - PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); - PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName); - if (group == null || user == null) { - return false; - } else { - user.addGroup(groupName, worldName); - return true; - } - } - - @Override - public boolean playerRemoveGroup(String worldName, OfflinePlayer op, String groupName) { - PermissionUser user = getUser(op); - user.removeGroup(groupName, worldName); - return true; - } - - @Override - public boolean playerRemoveGroup(String worldName, String playerName, String groupName) { - PermissionsEx.getPermissionManager().getUser(playerName).removeGroup(groupName, worldName); - return true; - } - - @Override - public boolean playerAdd(String worldName, OfflinePlayer op, String permission) { - PermissionUser user = getUser(op); - if (user == null) { - return false; - } else { - user.addPermission(permission, worldName); - return true; - } - } - - @Override - public boolean playerAdd(String worldName, String playerName, String permission) { - PermissionUser user = getUser(playerName); - if (user == null) { - return false; - } else { - user.addPermission(permission, worldName); - return true; - } - } - - @Override - public boolean playerRemove(String worldName, OfflinePlayer op, String permission) { - PermissionUser user = getUser(op); - if (user == null) { - return false; - } else { - user.removePermission(permission, worldName); - return true; - } - } - - @Override - public boolean playerRemove(String worldName, String playerName, String permission) { - PermissionUser user = getUser(playerName); - if (user == null) { - return false; - } else { - user.removePermission(permission, worldName); - return true; - } - } - - @Override - public boolean groupAdd(String worldName, String groupName, String permission) { - PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); - if (group == null) { - return false; - } else { - group.addPermission(permission, worldName); - return true; - } - } - - @Override - public boolean groupRemove(String worldName, String groupName, String permission) { - PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); - if (group == null) { - return false; - } else { - group.removePermission(permission, worldName); - return true; - } - } - - @Override - public boolean groupHas(String worldName, String groupName, String permission) { - PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); - if (group == null) { - return false; - } else { - return group.has(permission, worldName); - } - } - - private PermissionUser getUser(OfflinePlayer op) { - return PermissionsEx.getPermissionManager().getUser(op.getUniqueId()); - } - - private PermissionUser getUser(String playerName) { - return PermissionsEx.getPermissionManager().getUser(playerName); - } - - @Override - public String[] getPlayerGroups(String world, OfflinePlayer op) { - PermissionUser user = getUser(op); - return user == null ? null : user.getParentIdentifiers(world).toArray(new String[0]); - } - - @Override - public String[] getPlayerGroups(String world, String playerName) { - PermissionUser user = getUser(playerName); - return user == null ? null : user.getParentIdentifiers(world).toArray(new String[0]); - } - - @Override - public String getPrimaryGroup(String world, OfflinePlayer op) { - PermissionUser user = getUser(op); - if (user == null) { - return null; - } else if (user.getParentIdentifiers(world).size() > 0) { - return user.getParentIdentifiers(world).get(0); - } else { - return null; - } - } - - @Override - public String getPrimaryGroup(String world, String playerName) { - PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName); - if (user == null) { - return null; - } else if (user.getParentIdentifiers(world).size() > 0) { - return user.getParentIdentifiers(world).get(0); - } else { - return null; - } - } - - @Override - public boolean playerHas(String worldName, OfflinePlayer op, String permission) { - PermissionUser user = getUser(op); - if (user != null) { - return user.has(permission, worldName); - } else { - return false; - } - } - - @Override - public boolean playerHas(String worldName, String playerName, String permission) { - PermissionUser user = getUser(playerName); - if (user != null) { - return user.has(permission, worldName); - } else { - return false; - } - } - - - @Override - public boolean playerAddTransient(String worldName, Player player, String permission) { - PermissionUser pPlayer = getUser(player); - if (pPlayer != null) { - pPlayer.addTimedPermission(permission, worldName, 0); - return true; - } else { - return false; - } - } - - @Override - public boolean playerAddTransient(Player player, String permission) { - return playerAddTransient(null, player, permission); - } - - - @Override - public boolean playerRemoveTransient(Player player, String permission) { - return playerRemoveTransient(null, player, permission); - } - - @Override - public boolean playerRemoveTransient(String worldName, Player player, String permission) { - PermissionUser pPlayer = getUser(player); - if (pPlayer != null) { - pPlayer.removeTimedPermission(permission, worldName); - return true; - } else { - return false; - } - } - - @Override - public String[] getGroups() { - List groups = PermissionsEx.getPermissionManager().getGroupList(); - if (groups == null || groups.isEmpty()) { - return null; - } - String[] groupNames = new String[groups.size()]; - for (int i = 0; i < groups.size(); i++) { - groupNames[i] = groups.get(i).getName(); - } - return groupNames; - } - - @Override - public boolean hasSuperPermsCompat() { - return true; - } +import java.util.List; - @Override - public boolean hasGroupSupport() { - return true; - } +public class Permission_PermissionsEx extends Permission { + + private final String name = "PermissionsEx"; + private PermissionsEx permission; + + public Permission_PermissionsEx(final Plugin plugin) { + this.plugin = plugin; + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); + + // Load Plugin in case it was loaded before + if (this.permission == null) { + final Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsEx"); + if (perms != null) { + if (perms.isEnabled()) { + try { + if (Double.parseDouble(perms.getDescription().getVersion()) < 1.16) { + Permission.log.info(String.format("[%s][Permission] %s below 1.16 is not compatible with Vault! Falling back to SuperPerms only mode. PLEASE UPDATE!", plugin.getDescription().getName(), this.name)); + } + } catch (final NumberFormatException e) { + // Do nothing + } + this.permission = (PermissionsEx) perms; + Permission.log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), this.name)); + } + } + } + } + + @Override + public boolean isEnabled() { + if (this.permission == null) { + return false; + } else { + return this.permission.isEnabled(); + } + } + + public class PermissionServerListener implements Listener { + final Permission_PermissionsEx permission; + + public PermissionServerListener(final Permission_PermissionsEx permission) { + this.permission = permission; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.permission.permission == null) { + final Plugin perms = event.getPlugin(); + if (perms.getDescription().getName().equals("PermissionsEx")) { + try { + if (Double.parseDouble(perms.getDescription().getVersion()) < 1.16) { + Permission.log.info(String.format("[%s][Permission] %s below 1.16 is not compatible with Vault! Falling back to SuperPerms only mode. PLEASE UPDATE!", Permission_PermissionsEx.this.plugin.getDescription().getName(), Permission_PermissionsEx.this.name)); + return; + } + } catch (final NumberFormatException e) { + // Do nothing + } + this.permission.permission = (PermissionsEx) perms; + Permission.log.info(String.format("[%s][Permission] %s hooked.", Permission_PermissionsEx.this.plugin.getDescription().getName(), this.permission.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.permission.permission != null) { + if (event.getPlugin().getDescription().getName().equals("PermissionsEx")) { + this.permission.permission = null; + Permission.log.info(String.format("[%s][Permission] %s un-hooked.", Permission_PermissionsEx.this.plugin.getDescription().getName(), this.permission.name)); + } + } + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean playerInGroup(final String worldName, final OfflinePlayer op, final String groupName) { + final PermissionUser user = this.getUser(op); + if (user == null) { + return false; + } + return user.inGroup(groupName, worldName); + } + + @Override + public boolean playerInGroup(final String worldName, final String playerName, final String groupName) { + return PermissionsEx.getPermissionManager().getUser(playerName).inGroup(groupName, worldName); + } + + @Override + public boolean playerAddGroup(final String worldName, final OfflinePlayer op, final String groupName) { + final PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); + final PermissionUser user = this.getUser(op); + if (group == null || user == null) { + return false; + } else { + user.addGroup(groupName, worldName); + return true; + } + } + + @Override + public boolean playerAddGroup(final String worldName, final String playerName, final String groupName) { + final PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); + final PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName); + if (group == null || user == null) { + return false; + } else { + user.addGroup(groupName, worldName); + return true; + } + } + + @Override + public boolean playerRemoveGroup(final String worldName, final OfflinePlayer op, final String groupName) { + final PermissionUser user = this.getUser(op); + user.removeGroup(groupName, worldName); + return true; + } + + @Override + public boolean playerRemoveGroup(final String worldName, final String playerName, final String groupName) { + PermissionsEx.getPermissionManager().getUser(playerName).removeGroup(groupName, worldName); + return true; + } + + @Override + public boolean playerAdd(final String worldName, final OfflinePlayer op, final String permission) { + final PermissionUser user = this.getUser(op); + if (user == null) { + return false; + } else { + user.addPermission(permission, worldName); + return true; + } + } + + @Override + public boolean playerAdd(final String worldName, final String playerName, final String permission) { + final PermissionUser user = this.getUser(playerName); + if (user == null) { + return false; + } else { + user.addPermission(permission, worldName); + return true; + } + } + + @Override + public boolean playerRemove(final String worldName, final OfflinePlayer op, final String permission) { + final PermissionUser user = this.getUser(op); + if (user == null) { + return false; + } else { + user.removePermission(permission, worldName); + return true; + } + } + + @Override + public boolean playerRemove(final String worldName, final String playerName, final String permission) { + final PermissionUser user = this.getUser(playerName); + if (user == null) { + return false; + } else { + user.removePermission(permission, worldName); + return true; + } + } + + @Override + public boolean groupAdd(final String worldName, final String groupName, final String permission) { + final PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); + if (group == null) { + return false; + } else { + group.addPermission(permission, worldName); + return true; + } + } + + @Override + public boolean groupRemove(final String worldName, final String groupName, final String permission) { + final PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); + if (group == null) { + return false; + } else { + group.removePermission(permission, worldName); + return true; + } + } + + @Override + public boolean groupHas(final String worldName, final String groupName, final String permission) { + final PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); + if (group == null) { + return false; + } else { + return group.has(permission, worldName); + } + } + + private PermissionUser getUser(final OfflinePlayer op) { + return PermissionsEx.getPermissionManager().getUser(op.getUniqueId()); + } + + private PermissionUser getUser(final String playerName) { + return PermissionsEx.getPermissionManager().getUser(playerName); + } + + @Override + public String[] getPlayerGroups(final String world, final OfflinePlayer op) { + final PermissionUser user = this.getUser(op); + return user == null ? null : user.getParentIdentifiers(world).toArray(new String[0]); + } + + @Override + public String[] getPlayerGroups(final String world, final String playerName) { + final PermissionUser user = this.getUser(playerName); + return user == null ? null : user.getParentIdentifiers(world).toArray(new String[0]); + } + + @Override + public String getPrimaryGroup(final String world, final OfflinePlayer op) { + final PermissionUser user = this.getUser(op); + if (user == null) { + return null; + } else if (user.getParentIdentifiers(world).size() > 0) { + return user.getParentIdentifiers(world).get(0); + } else { + return null; + } + } + + @Override + public String getPrimaryGroup(final String world, final String playerName) { + final PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName); + if (user == null) { + return null; + } else if (user.getParentIdentifiers(world).size() > 0) { + return user.getParentIdentifiers(world).get(0); + } else { + return null; + } + } + + @Override + public boolean playerHas(final String worldName, final OfflinePlayer op, final String permission) { + final PermissionUser user = this.getUser(op); + if (user != null) { + return user.has(permission, worldName); + } else { + return false; + } + } + + @Override + public boolean playerHas(final String worldName, final String playerName, final String permission) { + final PermissionUser user = this.getUser(playerName); + if (user != null) { + return user.has(permission, worldName); + } else { + return false; + } + } + + + @Override + public boolean playerAddTransient(final String worldName, final Player player, final String permission) { + final PermissionUser pPlayer = this.getUser(player); + if (pPlayer != null) { + pPlayer.addTimedPermission(permission, worldName, 0); + return true; + } else { + return false; + } + } + + @Override + public boolean playerAddTransient(final Player player, final String permission) { + return this.playerAddTransient(null, player, permission); + } + + + @Override + public boolean playerRemoveTransient(final Player player, final String permission) { + return this.playerRemoveTransient(null, player, permission); + } + + @Override + public boolean playerRemoveTransient(final String worldName, final Player player, final String permission) { + final PermissionUser pPlayer = this.getUser(player); + if (pPlayer != null) { + pPlayer.removeTimedPermission(permission, worldName); + return true; + } else { + return false; + } + } + + @Override + public String[] getGroups() { + final List groups = PermissionsEx.getPermissionManager().getGroupList(); + if (groups == null || groups.isEmpty()) { + return null; + } + final String[] groupNames = new String[groups.size()]; + for (int i = 0; i < groups.size(); i++) { + groupNames[i] = groups.get(i).getName(); + } + return groupNames; + } + + @Override + public boolean hasSuperPermsCompat() { + return true; + } + + @Override + public boolean hasGroupSupport() { + return true; + } } diff --git a/src/net/milkbowl/vault/permission/plugins/Permission_Privileges.java b/src/net/milkbowl/vault/permission/plugins/Permission_Privileges.java index 64310b6a..e0eef6b2 100644 --- a/src/net/milkbowl/vault/permission/plugins/Permission_Privileges.java +++ b/src/net/milkbowl/vault/permission/plugins/Permission_Privileges.java @@ -17,150 +17,150 @@ import java.util.List; public class Permission_Privileges extends Permission { - - private final String name = "Privileges"; - private Privileges privs; - - public Permission_Privileges(Plugin plugin) { - this.plugin = plugin; - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); - // Load service in case it was loaded before - if (privs == null) { - Plugin perms = plugin.getServer().getPluginManager().getPlugin("Privileges"); - if (perms != null && perms.isEnabled()) { - this.privs = (Privileges) perms; - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - - public class PermissionServerListener implements Listener { - Permission_Privileges permission = null; - - public PermissionServerListener(Permission_Privileges permission) { - this.permission = permission; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (permission.privs == null) { - Plugin perms = event.getPlugin(); - if (perms.getDescription().getName().equals("Privileges")) { - permission.privs = (Privileges) perms; - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (permission.privs != null) { - if (event.getPlugin().getDescription().getName().equals("Privileges")) { - permission.privs = null; - log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name)); - } - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean isEnabled() { - return true; - } - - @Override - public boolean playerHas(String world, String player, String permission) { - Player p = plugin.getServer().getPlayer(player); - return p != null && p.hasPermission(permission); - } - - @Override - public boolean playerAdd(String world, String player, String permission) { - return false; - } - - // use superclass implementation of playerAddTransient() and playerRemoveTransient() - - @Override - public boolean playerRemove(String world, String player, String permission) { - return false; - } - - @Override - public boolean groupHas(String world, String group, String permission) { - Group g = privs.getGroupManager().getGroup(group); - return g != null && g.hasPermission(permission, world); - } - - @Override - public boolean groupAdd(String world, String group, String permission) { - Group g = privs.getGroupManager().getGroup(group); - return g != null && g.addPermission(world, permission); - } - - @Override - public boolean groupRemove(String world, String group, String permission) { - Group g = privs.getGroupManager().getGroup(group); - return g != null && g.removePermission(world, permission); - } - - @Override - public boolean playerInGroup(String world, String player, String group) { - OfflinePlayer p = Bukkit.getOfflinePlayer(player); - Group g = privs.getGroupManager().getGroup(p); - return g != null && g.isMemberOf(group); - } - - @Override - public boolean playerAddGroup(String world, String player, String group) { - Group g = privs.getGroupManager().setGroup(player, group); - return g != null; - } - - @Override - public boolean playerRemoveGroup(String world, String player, String group) { - Group g = privs.getGroupManager().getDefaultGroup(); - return g != null && playerAddGroup(world, player, g.getName()); - } - - @Override - public String[] getPlayerGroups(String world, String player) { - OfflinePlayer p = Bukkit.getOfflinePlayer(player); - if (p == null) { - throw new UnsupportedOperationException("Privileges does not support offline players."); - } - Group g = privs.getGroupManager().getGroup(p); - return g != null ? g.getGroupTree().toArray(new String[g.getGroupTree().size()]) : null; - } - - @Override - public String getPrimaryGroup(String world, String player) { - OfflinePlayer p = Bukkit.getOfflinePlayer(player); - Group g = privs.getGroupManager().getGroup(p); - return g != null ? g.getName() : null; - } - - @Override - public String[] getGroups() { - List groups = new ArrayList(); - for (Group g : privs.getGroupManager().getGroups()) { - groups.add(g.getName()); - } - return groups.toArray(new String[groups.size()]); - } - - @Override - public boolean hasSuperPermsCompat() { - return true; - } - - @Override - public boolean hasGroupSupport() { - return true; - } + + private final String name = "Privileges"; + private Privileges privs; + + public Permission_Privileges(final Plugin plugin) { + this.plugin = plugin; + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); + // Load service in case it was loaded before + if (this.privs == null) { + final Plugin perms = plugin.getServer().getPluginManager().getPlugin("Privileges"); + if (perms != null && perms.isEnabled()) { + privs = (Privileges) perms; + Permission.log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), this.name)); + } + } + } + + public class PermissionServerListener implements Listener { + final Permission_Privileges permission; + + public PermissionServerListener(final Permission_Privileges permission) { + this.permission = permission; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.permission.privs == null) { + final Plugin perms = event.getPlugin(); + if (perms.getDescription().getName().equals("Privileges")) { + this.permission.privs = (Privileges) perms; + Permission.log.info(String.format("[%s][Permission] %s hooked.", Permission_Privileges.this.plugin.getDescription().getName(), this.permission.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.permission.privs != null) { + if (event.getPlugin().getDescription().getName().equals("Privileges")) { + this.permission.privs = null; + Permission.log.info(String.format("[%s][Permission] %s un-hooked.", Permission_Privileges.this.plugin.getDescription().getName(), this.permission.name)); + } + } + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public boolean playerHas(final String world, final String player, final String permission) { + final Player p = this.plugin.getServer().getPlayer(player); + return p != null && p.hasPermission(permission); + } + + @Override + public boolean playerAdd(final String world, final String player, final String permission) { + return false; + } + + // use superclass implementation of playerAddTransient() and playerRemoveTransient() + + @Override + public boolean playerRemove(final String world, final String player, final String permission) { + return false; + } + + @Override + public boolean groupHas(final String world, final String group, final String permission) { + final Group g = this.privs.getGroupManager().getGroup(group); + return g != null && g.hasPermission(permission, world); + } + + @Override + public boolean groupAdd(final String world, final String group, final String permission) { + final Group g = this.privs.getGroupManager().getGroup(group); + return g != null && g.addPermission(world, permission); + } + + @Override + public boolean groupRemove(final String world, final String group, final String permission) { + final Group g = this.privs.getGroupManager().getGroup(group); + return g != null && g.removePermission(world, permission); + } + + @Override + public boolean playerInGroup(final String world, final String player, final String group) { + final OfflinePlayer p = Bukkit.getOfflinePlayer(player); + final Group g = this.privs.getGroupManager().getGroup(p); + return g != null && g.isMemberOf(group); + } + + @Override + public boolean playerAddGroup(final String world, final String player, final String group) { + final Group g = this.privs.getGroupManager().setGroup(player, group); + return g != null; + } + + @Override + public boolean playerRemoveGroup(final String world, final String player, final String group) { + final Group g = this.privs.getGroupManager().getDefaultGroup(); + return g != null && this.playerAddGroup(world, player, g.getName()); + } + + @Override + public String[] getPlayerGroups(final String world, final String player) { + final OfflinePlayer p = Bukkit.getOfflinePlayer(player); + if (p == null) { + throw new UnsupportedOperationException("Privileges does not support offline players."); + } + final Group g = this.privs.getGroupManager().getGroup(p); + return g != null ? g.getGroupTree().toArray(new String[0]) : null; + } + + @Override + public String getPrimaryGroup(final String world, final String player) { + final OfflinePlayer p = Bukkit.getOfflinePlayer(player); + final Group g = this.privs.getGroupManager().getGroup(p); + return g != null ? g.getName() : null; + } + + @Override + public String[] getGroups() { + final List groups = new ArrayList<>(); + for (final Group g : this.privs.getGroupManager().getGroups()) { + groups.add(g.getName()); + } + return groups.toArray(new String[0]); + } + + @Override + public boolean hasSuperPermsCompat() { + return true; + } + + @Override + public boolean hasGroupSupport() { + return true; + } } diff --git a/src/net/milkbowl/vault/permission/plugins/Permission_SimplyPerms.java b/src/net/milkbowl/vault/permission/plugins/Permission_SimplyPerms.java index 21b4a768..ccf69552 100644 --- a/src/net/milkbowl/vault/permission/plugins/Permission_SimplyPerms.java +++ b/src/net/milkbowl/vault/permission/plugins/Permission_SimplyPerms.java @@ -16,14 +16,9 @@ package net.milkbowl.vault.permission.plugins; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - import net.crystalyx.bukkit.simplyperms.SimplyAPI; import net.crystalyx.bukkit.simplyperms.SimplyPlugin; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -32,195 +27,197 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -public class Permission_SimplyPerms extends Permission{ - - private final String name = "SimplyPerms"; - private SimplyAPI perms; - - public Permission_SimplyPerms(Plugin plugin) { - this.plugin = plugin; - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); - // Load service in case it was loaded before - if (perms == null) { - Plugin perms = plugin.getServer().getPluginManager().getPlugin("SimplyPerms"); - if (perms != null && perms.isEnabled()) { - this.perms = ((SimplyPlugin) perms).getAPI(); - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - - public class PermissionServerListener implements Listener { - Permission_SimplyPerms permission = null; - - public PermissionServerListener(Permission_SimplyPerms permission) { - this.permission = permission; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (permission.perms == null) { - Plugin perms = event.getPlugin(); - if (perms.getDescription().getName().equals("SimplyPerms")) { - permission.perms = ((SimplyPlugin) perms).getAPI(); - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (permission.perms != null) { - if (event.getPlugin().getDescription().getName().equals("SimplyPerms")) { - permission.perms = null; - log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name)); - } - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean isEnabled() { - return perms != null; - } - - @Override - public boolean hasSuperPermsCompat() { - return true; - } - - @Override - public boolean playerHas(String world, String player, String permission) { - permission = permission.toLowerCase(); - Map playerPermissions = this.perms.getPlayerPermissions(player, world); - return playerPermissions.containsKey(permission) && playerPermissions.get(permission); - } - - @Override - public boolean playerAdd(String world, String player, String permission) { - permission = permission.toLowerCase(); - if (world != null) { - this.perms.addPlayerPermission(player, world, permission, true); - } else { - this.perms.addPlayerPermission(player, permission, true); - } - return true; - } - - @Override - public boolean playerRemove(String world, String player, String permission) { - permission = permission.toLowerCase(); - if (world != null) { - this.perms.removePlayerPermission(player, world, permission); - } else { - this.perms.removePlayerPermission(player, permission); - } - return true; - } - - @Override - public boolean groupHas(String world, String group, String permission) { - permission = permission.toLowerCase(); - Map groupPermissions = this.perms.getGroupPermissions(group, world); - return groupPermissions.containsKey(permission) && groupPermissions.get(permission); - } - - @Override - public boolean groupAdd(String world, String group, String permission) { - permission = permission.toLowerCase(); - if (world != null) { - this.perms.addGroupPermission(group, world, permission, true); - } else { - this.perms.addGroupPermission(group, permission, true); - } - return true; - } - - @Override - public boolean groupRemove(String world, String group, String permission) { - permission = permission.toLowerCase(); - if (world != null) { - permission = world + ":" + permission; - this.perms.removeGroupPermission(group, world, permission); - } else { - this.perms.removeGroupPermission(group, permission); - } - return true; - } - - @Override - public boolean playerInGroup(String world, String player, String group) { - if (world != null) { - for (String g : perms.getPlayerGroups(player)) { - if (g.equals(group)) { - return perms.getGroupWorlds(group).contains(world); - } - } - return false; - } - - if (!perms.getAllGroups().contains(group)) { - return false; - } - return perms.getPlayerGroups(player).contains(group); - } - - @Override - public boolean playerAddGroup(String world, String player, String group) { - group = group.toLowerCase(); - this.perms.addPlayerGroup(player, group); - return true; - } - - @Override - public boolean playerRemoveGroup(String world, String player, String group) { - group = group.toLowerCase(); - this.perms.removePlayerGroup(player, group); - return true; - } - - @Override - public String[] getPlayerGroups(String world, String player) { - List groupList = new ArrayList(); - if (world != null && perms.isPlayerInDB(player)) { - for (String group : perms.getPlayerGroups(player)) { - if (perms.getGroupWorlds(group).contains(world)) { - groupList.add(group); - } - } - return groupList.toArray(new String[0]); - } - if (perms.isPlayerInDB(player)) { - for (String group : perms.getPlayerGroups(player)) { - groupList.add(group); - } - } - return groupList.toArray(new String[0]); - } - - @Override - public String getPrimaryGroup(String world, String player) { - if (!perms.isPlayerInDB(player)) { - return null; - } else if (perms.getPlayerGroups(player) != null && !perms.getPlayerGroups(player).isEmpty() ) { - return perms.getPlayerGroups(player).get(0); - } - return null; - } - - @Override - public String[] getGroups() { - return perms.getAllGroups().toArray(new String[0]); - } - - @Override - public boolean hasGroupSupport() { - return true; - } +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +public class Permission_SimplyPerms extends Permission { + + private final String name = "SimplyPerms"; + private SimplyAPI perms; + + public Permission_SimplyPerms(final Plugin plugin) { + this.plugin = plugin; + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); + // Load service in case it was loaded before + if (this.perms == null) { + final Plugin perms = plugin.getServer().getPluginManager().getPlugin("SimplyPerms"); + if (perms != null && perms.isEnabled()) { + this.perms = ((SimplyPlugin) perms).getAPI(); + Permission.log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), this.name)); + } + } + } + + public class PermissionServerListener implements Listener { + final Permission_SimplyPerms permission; + + public PermissionServerListener(final Permission_SimplyPerms permission) { + this.permission = permission; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.permission.perms == null) { + final Plugin perms = event.getPlugin(); + if (perms.getDescription().getName().equals("SimplyPerms")) { + this.permission.perms = ((SimplyPlugin) perms).getAPI(); + Permission.log.info(String.format("[%s][Permission] %s hooked.", Permission_SimplyPerms.this.plugin.getDescription().getName(), this.permission.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.permission.perms != null) { + if (event.getPlugin().getDescription().getName().equals("SimplyPerms")) { + this.permission.perms = null; + Permission.log.info(String.format("[%s][Permission] %s un-hooked.", Permission_SimplyPerms.this.plugin.getDescription().getName(), this.permission.name)); + } + } + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean isEnabled() { + return this.perms != null; + } + + @Override + public boolean hasSuperPermsCompat() { + return true; + } + + @Override + public boolean playerHas(final String world, final String player, String permission) { + permission = permission.toLowerCase(); + final Map playerPermissions = perms.getPlayerPermissions(player, world); + return playerPermissions.containsKey(permission) && playerPermissions.get(permission); + } + + @Override + public boolean playerAdd(final String world, final String player, String permission) { + permission = permission.toLowerCase(); + if (world != null) { + perms.addPlayerPermission(player, world, permission, true); + } else { + perms.addPlayerPermission(player, permission, true); + } + return true; + } + + @Override + public boolean playerRemove(final String world, final String player, String permission) { + permission = permission.toLowerCase(); + if (world != null) { + perms.removePlayerPermission(player, world, permission); + } else { + perms.removePlayerPermission(player, permission); + } + return true; + } + + @Override + public boolean groupHas(final String world, final String group, String permission) { + permission = permission.toLowerCase(); + final Map groupPermissions = perms.getGroupPermissions(group, world); + return groupPermissions.containsKey(permission) && groupPermissions.get(permission); + } + + @Override + public boolean groupAdd(final String world, final String group, String permission) { + permission = permission.toLowerCase(); + if (world != null) { + perms.addGroupPermission(group, world, permission, true); + } else { + perms.addGroupPermission(group, permission, true); + } + return true; + } + + @Override + public boolean groupRemove(final String world, final String group, String permission) { + permission = permission.toLowerCase(); + if (world != null) { + permission = world + ":" + permission; + perms.removeGroupPermission(group, world, permission); + } else { + perms.removeGroupPermission(group, permission); + } + return true; + } + + @Override + public boolean playerInGroup(final String world, final String player, final String group) { + if (world != null) { + for (final String g : this.perms.getPlayerGroups(player)) { + if (g.equals(group)) { + return this.perms.getGroupWorlds(group).contains(world); + } + } + return false; + } + + if (!this.perms.getAllGroups().contains(group)) { + return false; + } + return this.perms.getPlayerGroups(player).contains(group); + } + + @Override + public boolean playerAddGroup(final String world, final String player, String group) { + group = group.toLowerCase(); + perms.addPlayerGroup(player, group); + return true; + } + + @Override + public boolean playerRemoveGroup(final String world, final String player, String group) { + group = group.toLowerCase(); + perms.removePlayerGroup(player, group); + return true; + } + + @Override + public String[] getPlayerGroups(final String world, final String player) { + final List groupList = new ArrayList<>(); + if (world != null && this.perms.isPlayerInDB(player)) { + for (final String group : this.perms.getPlayerGroups(player)) { + if (this.perms.getGroupWorlds(group).contains(world)) { + groupList.add(group); + } + } + return groupList.toArray(new String[0]); + } + if (this.perms.isPlayerInDB(player)) { + groupList.addAll(this.perms.getPlayerGroups(player)); + } + return groupList.toArray(new String[0]); + } + + @Override + public String getPrimaryGroup(final String world, final String player) { + if (!this.perms.isPlayerInDB(player)) { + return null; + } else if (this.perms.getPlayerGroups(player) != null && !this.perms.getPlayerGroups(player).isEmpty()) { + return this.perms.getPlayerGroups(player).get(0); + } + return null; + } + + @Override + public String[] getGroups() { + return this.perms.getAllGroups().toArray(new String[0]); + } + + @Override + public boolean hasGroupSupport() { + return true; + } + } \ No newline at end of file diff --git a/src/net/milkbowl/vault/permission/plugins/Permission_Starburst.java b/src/net/milkbowl/vault/permission/plugins/Permission_Starburst.java index ebc09405..b42818b7 100644 --- a/src/net/milkbowl/vault/permission/plugins/Permission_Starburst.java +++ b/src/net/milkbowl/vault/permission/plugins/Permission_Starburst.java @@ -15,12 +15,8 @@ */ package net.milkbowl.vault.permission.plugins; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - +import com.dthielke.starburst.*; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -31,277 +27,275 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import com.dthielke.starburst.Group; -import com.dthielke.starburst.GroupManager; -import com.dthielke.starburst.GroupSet; -import com.dthielke.starburst.StarburstPlugin; -import com.dthielke.starburst.User; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; public class Permission_Starburst extends Permission { - private StarburstPlugin perms; - private final String name = "Starburst"; - - public Permission_Starburst(Plugin plugin) { - this.plugin = plugin; - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); - - // Load Plugin in case it was loaded before - if (perms == null) { - Plugin p = plugin.getServer().getPluginManager().getPlugin("Starburst"); - if (p != null) { - perms = (StarburstPlugin) p; - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - - public class PermissionServerListener implements Listener { - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (perms == null) { - Plugin p = event.getPlugin(); - if (p.getDescription().getName().equals("Starburst")) { - perms = (StarburstPlugin) p; - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (perms != null) { - if (event.getPlugin().getDescription().getName().equals("Starburst")) { - perms = null; - log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), name)); - } - } - } - } - - @Override - public String[] getGroups() { - String[] s = new String[perms.getGroupManager().getDefaultGroupSet().getGroups().size()]; - int i = 0; - for (Group g : perms.getGroupManager().getDefaultGroupSet().getGroups()) { - s[i] = g.getName(); - i++; - } - return s; - } - - @Override - public String getName() { - return name; - } - - @Override - public String[] getPlayerGroups(String world, String player) { - OfflinePlayer op = Bukkit.getOfflinePlayer(player); - GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); - User user = set.getUser(op); - - Set children = user.getChildren(true); - List groups = new ArrayList(); - for (Group child : children) { - groups.add(child.getName()); - } - return groups.toArray(new String[groups.size()]); - } - - @Override - public String getPrimaryGroup(String world, String player) { - OfflinePlayer op = Bukkit.getOfflinePlayer(player); - GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); - User user = set.getUser(op); - - Set children = user.getChildren(false); - if (!children.isEmpty()) { - return children.iterator().next().getName(); - } else { - return null; - } - } - - @Override - public boolean groupAdd(String world, String group, String permission) { - GroupManager gm = perms.getGroupManager(); - GroupSet set = gm.getWorldSet(Bukkit.getWorld(world)); - if (set.hasGroup(group)) { - Group g = set.getGroup(group); - - boolean value = !permission.startsWith("^"); - permission = value ? permission : permission.substring(1); - g.addPermission(permission, value, true, true); - - for (User user : gm.getAffectedUsers(g)) { - user.applyPermissions(gm.getFactory()); - } - return true; - } else { - return false; - } - } - - @Override - public boolean groupHas(String world, String group, String permission) { - GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); - if (set.hasGroup(group)) { - Group g = set.getGroup(group); - return g.hasPermission(permission, true); - } else { - return false; - } - } - - @Override - public boolean groupRemove(String world, String group, String permission) { - GroupManager gm = perms.getGroupManager(); - GroupSet set = gm.getWorldSet(Bukkit.getWorld(world)); - if (set.hasGroup(group)) { - Group g = set.getGroup(group); - - boolean value = !permission.startsWith("^"); - permission = value ? permission : permission.substring(1); - - if (g.hasPermission(permission, false)) { - g.removePermission(permission, true); - - for (User user : gm.getAffectedUsers(g)) { - user.applyPermissions(gm.getFactory()); - } - return true; - } else { - return false; - } - } else { - return false; - } - } - - @Override - public boolean hasSuperPermsCompat() { - return true; - } - - @Override - public boolean isEnabled() { - return perms != null && perms.isEnabled(); - } - - @Override - public boolean playerAdd(String world, String player, String permission) { - OfflinePlayer op = Bukkit.getOfflinePlayer(player); - GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); - User user = set.getUser(op); - - boolean value = !permission.startsWith("^"); - permission = value ? permission : permission.substring(1); - user.addPermission(permission, value, true, true); - - if (user.isActive()) { - user.applyPermissions(perms.getGroupManager().getFactory()); - } - return true; - } - - @Override - public boolean playerAddGroup(String world, String player, String group) { - OfflinePlayer op = Bukkit.getOfflinePlayer(player); - GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); - User user = set.getUser(op); - - if (set.hasGroup(group)) { - Group g = set.getGroup(group); - if (!user.hasChild(g, false)) { - user.addChild(g, true); - - if (user.isActive()) { - user.applyPermissions(perms.getGroupManager().getFactory()); - } - return true; - } else { - return false; - } - } else { - return false; - } - } - - @Override - public boolean playerHas(String world, String player, String permission) { - OfflinePlayer op = Bukkit.getOfflinePlayer(player); - - if (op.isOnline()) { - Player p = (Player) op; - if (p.getWorld().getName().equalsIgnoreCase(world)) { - return p.hasPermission(permission); - } - } - - GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); - Group user = set.getUser(op); - return user.hasPermission(permission, true); - } - - @Override - public boolean playerInGroup(String world, String player, String group) { - OfflinePlayer op = Bukkit.getOfflinePlayer(player); - GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); - User user = set.getUser(op); - - if (set.hasGroup(group)) { - Group g = set.getGroup(group); - return user.hasChild(g, true); - } else { - return false; - } - } - - @Override - public boolean playerRemove(String world, String player, String permission) { - OfflinePlayer op = Bukkit.getOfflinePlayer(player); - GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); - User user = set.getUser(op); - - boolean value = !permission.startsWith("^"); - permission = value ? permission : permission.substring(1); - if (user.hasPermission(permission, false)) { - user.removePermission(permission, true); - if (user.isActive()) { - user.applyPermissions(perms.getGroupManager().getFactory()); - } - return true; - } else { - return false; - } - } - - @Override - public boolean playerRemoveGroup(String world, String player, String group) { - OfflinePlayer op = Bukkit.getOfflinePlayer(player); - GroupSet set = perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); - User user = set.getUser(op); - - if (set.hasGroup(group)) { - Group g = set.getGroup(group); - if (user.hasChild(g, false)) { - user.removeChild(g, true); - - if (user.isActive()) { - user.applyPermissions(perms.getGroupManager().getFactory()); - } - return true; - } else { - return false; - } - } else { - return false; - } - } - - @Override - public boolean hasGroupSupport() { - return true; - } + private StarburstPlugin perms; + private final String name = "Starburst"; + + public Permission_Starburst(final Plugin plugin) { + this.plugin = plugin; + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); + + // Load Plugin in case it was loaded before + if (this.perms == null) { + final Plugin p = plugin.getServer().getPluginManager().getPlugin("Starburst"); + if (p != null) { + this.perms = (StarburstPlugin) p; + Permission.log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), this.name)); + } + } + } + + public class PermissionServerListener implements Listener { + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (Permission_Starburst.this.perms == null) { + final Plugin p = event.getPlugin(); + if (p.getDescription().getName().equals("Starburst")) { + Permission_Starburst.this.perms = (StarburstPlugin) p; + Permission.log.info(String.format("[%s][Permission] %s hooked.", Permission_Starburst.this.plugin.getDescription().getName(), Permission_Starburst.this.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (Permission_Starburst.this.perms != null) { + if (event.getPlugin().getDescription().getName().equals("Starburst")) { + Permission_Starburst.this.perms = null; + Permission.log.info(String.format("[%s][Permission] %s un-hooked.", Permission_Starburst.this.plugin.getDescription().getName(), Permission_Starburst.this.name)); + } + } + } + } + + @Override + public String[] getGroups() { + final String[] s = new String[this.perms.getGroupManager().getDefaultGroupSet().getGroups().size()]; + int i = 0; + for (final Group g : this.perms.getGroupManager().getDefaultGroupSet().getGroups()) { + s[i] = g.getName(); + i++; + } + return s; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public String[] getPlayerGroups(final String world, final String player) { + final OfflinePlayer op = Bukkit.getOfflinePlayer(player); + final GroupSet set = this.perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); + final User user = set.getUser(op); + + final Set children = user.getChildren(true); + final List groups = new ArrayList<>(); + for (final Group child : children) { + groups.add(child.getName()); + } + return groups.toArray(new String[0]); + } + + @Override + public String getPrimaryGroup(final String world, final String player) { + final OfflinePlayer op = Bukkit.getOfflinePlayer(player); + final GroupSet set = this.perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); + final User user = set.getUser(op); + + final Set children = user.getChildren(false); + if (!children.isEmpty()) { + return children.iterator().next().getName(); + } else { + return null; + } + } + + @Override + public boolean groupAdd(final String world, final String group, String permission) { + final GroupManager gm = this.perms.getGroupManager(); + final GroupSet set = gm.getWorldSet(Bukkit.getWorld(world)); + if (set.hasGroup(group)) { + final Group g = set.getGroup(group); + + final boolean value = !permission.startsWith("^"); + permission = value ? permission : permission.substring(1); + g.addPermission(permission, value, true, true); + + for (final User user : gm.getAffectedUsers(g)) { + user.applyPermissions(gm.getFactory()); + } + return true; + } else { + return false; + } + } + + @Override + public boolean groupHas(final String world, final String group, final String permission) { + final GroupSet set = this.perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); + if (set.hasGroup(group)) { + final Group g = set.getGroup(group); + return g.hasPermission(permission, true); + } else { + return false; + } + } + + @Override + public boolean groupRemove(final String world, final String group, String permission) { + final GroupManager gm = this.perms.getGroupManager(); + final GroupSet set = gm.getWorldSet(Bukkit.getWorld(world)); + if (set.hasGroup(group)) { + final Group g = set.getGroup(group); + + final boolean value = !permission.startsWith("^"); + permission = value ? permission : permission.substring(1); + + if (g.hasPermission(permission, false)) { + g.removePermission(permission, true); + + for (final User user : gm.getAffectedUsers(g)) { + user.applyPermissions(gm.getFactory()); + } + return true; + } else { + return false; + } + } else { + return false; + } + } + + @Override + public boolean hasSuperPermsCompat() { + return true; + } + + @Override + public boolean isEnabled() { + return this.perms != null && this.perms.isEnabled(); + } + + @Override + public boolean playerAdd(final String world, final String player, String permission) { + final OfflinePlayer op = Bukkit.getOfflinePlayer(player); + final GroupSet set = this.perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); + final User user = set.getUser(op); + + final boolean value = !permission.startsWith("^"); + permission = value ? permission : permission.substring(1); + user.addPermission(permission, value, true, true); + + if (user.isActive()) { + user.applyPermissions(this.perms.getGroupManager().getFactory()); + } + return true; + } + + @Override + public boolean playerAddGroup(final String world, final String player, final String group) { + final OfflinePlayer op = Bukkit.getOfflinePlayer(player); + final GroupSet set = this.perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); + final User user = set.getUser(op); + + if (set.hasGroup(group)) { + final Group g = set.getGroup(group); + if (!user.hasChild(g, false)) { + user.addChild(g, true); + + if (user.isActive()) { + user.applyPermissions(this.perms.getGroupManager().getFactory()); + } + return true; + } else { + return false; + } + } else { + return false; + } + } + + @Override + public boolean playerHas(final String world, final String player, final String permission) { + final OfflinePlayer op = Bukkit.getOfflinePlayer(player); + + if (op.isOnline()) { + final Player p = (Player) op; + if (p.getWorld().getName().equalsIgnoreCase(world)) { + return p.hasPermission(permission); + } + } + + final GroupSet set = this.perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); + final Group user = set.getUser(op); + return user.hasPermission(permission, true); + } + + @Override + public boolean playerInGroup(final String world, final String player, final String group) { + final OfflinePlayer op = Bukkit.getOfflinePlayer(player); + final GroupSet set = this.perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); + final User user = set.getUser(op); + + if (set.hasGroup(group)) { + final Group g = set.getGroup(group); + return user.hasChild(g, true); + } else { + return false; + } + } + + @Override + public boolean playerRemove(final String world, final String player, String permission) { + final OfflinePlayer op = Bukkit.getOfflinePlayer(player); + final GroupSet set = this.perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); + final User user = set.getUser(op); + + final boolean value = !permission.startsWith("^"); + permission = value ? permission : permission.substring(1); + if (user.hasPermission(permission, false)) { + user.removePermission(permission, true); + if (user.isActive()) { + user.applyPermissions(this.perms.getGroupManager().getFactory()); + } + return true; + } else { + return false; + } + } + + @Override + public boolean playerRemoveGroup(final String world, final String player, final String group) { + final OfflinePlayer op = Bukkit.getOfflinePlayer(player); + final GroupSet set = this.perms.getGroupManager().getWorldSet(Bukkit.getWorld(world)); + final User user = set.getUser(op); + + if (set.hasGroup(group)) { + final Group g = set.getGroup(group); + if (user.hasChild(g, false)) { + user.removeChild(g, true); + + if (user.isActive()) { + user.applyPermissions(this.perms.getGroupManager().getFactory()); + } + return true; + } else { + return false; + } + } else { + return false; + } + } + + @Override + public boolean hasGroupSupport() { + return true; + } } diff --git a/src/net/milkbowl/vault/permission/plugins/Permission_SuperPerms.java b/src/net/milkbowl/vault/permission/plugins/Permission_SuperPerms.java index 93266427..dbab0f76 100644 --- a/src/net/milkbowl/vault/permission/plugins/Permission_SuperPerms.java +++ b/src/net/milkbowl/vault/permission/plugins/Permission_SuperPerms.java @@ -16,98 +16,95 @@ package net.milkbowl.vault.permission.plugins; import net.milkbowl.vault.permission.Permission; - import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; public class Permission_SuperPerms extends Permission { - - private final String name = "SuperPerms"; - public Permission_SuperPerms(Plugin plugin) { + public Permission_SuperPerms(final Plugin plugin) { this.plugin = plugin; } @Override public String getName() { - return name; + return "SuperPerms"; } - + @Override public boolean isEnabled() { return true; } - + @Override - public boolean playerHas(String world, String player, String permission) { - Player p = plugin.getServer().getPlayer(player); - return p != null ? p.hasPermission(permission) : false; + public boolean playerHas(final String world, final String player, final String permission) { + final Player p = this.plugin.getServer().getPlayer(player); + return p != null && p.hasPermission(permission); } - + @Override - public boolean playerAdd(String world, String player, String permission) { + public boolean playerAdd(final String world, final String player, final String permission) { return false; } - + // use superclass implementation of playerAddTransient() and playerRemoveTransient() - + @Override - public boolean playerRemove(String world, String player, String permission) { + public boolean playerRemove(final String world, final String player, final String permission) { return false; } - + @Override - public boolean groupHas(String world, String group, String permission) { - throw new UnsupportedOperationException(getName() + " no group permissions."); + public boolean groupHas(final String world, final String group, final String permission) { + throw new UnsupportedOperationException(this.getName() + " no group permissions."); } - + @Override - public boolean groupAdd(String world, String group, String permission) { - throw new UnsupportedOperationException(getName() + " no group permissions."); + public boolean groupAdd(final String world, final String group, final String permission) { + throw new UnsupportedOperationException(this.getName() + " no group permissions."); } - + @Override - public boolean groupRemove(String world, String group, String permission) { - throw new UnsupportedOperationException(getName() + " no group permissions."); + public boolean groupRemove(final String world, final String group, final String permission) { + throw new UnsupportedOperationException(this.getName() + " no group permissions."); } - + @Override - public boolean playerInGroup(String world, String player, String group) { - return playerHas(world, player, "groups." + group); + public boolean playerInGroup(final String world, final String player, final String group) { + return this.playerHas(world, player, "groups." + group); } - + @Override - public boolean playerAddGroup(String world, String player, String group) { - throw new UnsupportedOperationException(getName() + " no group permissions."); + public boolean playerAddGroup(final String world, final String player, final String group) { + throw new UnsupportedOperationException(this.getName() + " no group permissions."); } - + @Override - public boolean playerRemoveGroup(String world, String player, String group) { - throw new UnsupportedOperationException(getName() + " no group permissions."); + public boolean playerRemoveGroup(final String world, final String player, final String group) { + throw new UnsupportedOperationException(this.getName() + " no group permissions."); } - + @Override - public String[] getPlayerGroups(String world, String player) { - throw new UnsupportedOperationException(getName() + " no group permissions."); + public String[] getPlayerGroups(final String world, final String player) { + throw new UnsupportedOperationException(this.getName() + " no group permissions."); } - + @Override - public String getPrimaryGroup(String world, String player) { - throw new UnsupportedOperationException(getName() + " no group permissions."); + public String getPrimaryGroup(final String world, final String player) { + throw new UnsupportedOperationException(this.getName() + " no group permissions."); } - + @Override public String[] getGroups() { return new String[0]; } - + @Override public boolean hasSuperPermsCompat() { return true; } - - @Override - public boolean hasGroupSupport() { - return false; - } + + @Override + public boolean hasGroupSupport() { + return false; + } } diff --git a/src/net/milkbowl/vault/permission/plugins/Permission_TotalPermissions.java b/src/net/milkbowl/vault/permission/plugins/Permission_TotalPermissions.java index 653ef4e1..004c048d 100644 --- a/src/net/milkbowl/vault/permission/plugins/Permission_TotalPermissions.java +++ b/src/net/milkbowl/vault/permission/plugins/Permission_TotalPermissions.java @@ -15,10 +15,6 @@ */ package net.milkbowl.vault.permission.plugins; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; import net.ae97.totalpermissions.PermissionManager; import net.ae97.totalpermissions.TotalPermissions; import net.ae97.totalpermissions.permission.PermissionBase; @@ -31,181 +27,186 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -public class Permission_TotalPermissions extends Permission { - - private final String name = "TotalPermissions"; - private PermissionManager manager; - private TotalPermissions totalperms; - - public Permission_TotalPermissions(Plugin pl) { - this.plugin = pl; - } - - public class PermissionServerListener implements Listener { - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (manager == null || totalperms == null) { - Plugin permPlugin = event.getPlugin(); - if (permPlugin.getDescription().getName().equals(name)) { - totalperms = (TotalPermissions) permPlugin; - manager = totalperms.getManager(); - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (manager != null) { - if (event.getPlugin().getDescription().getName().equals(name)) { - totalperms = null; - manager = null; - log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), name)); - } - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean isEnabled() { - return plugin != null && plugin.isEnabled() && totalperms != null && totalperms.isEnabled(); - } - - @Override - public boolean hasSuperPermsCompat() { - return true; - } - - @Override - public boolean hasGroupSupport() { - return true; - } - - @Override - public boolean playerHas(String world, String player, String permission) { - PermissionBase user = manager.getUser(player); - return user.has(permission, world); - } - - @Override - public boolean playerAdd(String world, String player, String permission) { - try { - PermissionBase user = manager.getUser(player); - user.addPerm(permission, world); - return true; - } catch (IOException ex) { - plugin.getLogger().log(Level.SEVERE, - String.format("[%s] An error occured while saving perms", totalperms.getDescription().getName()), ex); - return false; - } - } - - @Override - public boolean playerRemove(String world, String player, String permission) { - try { - PermissionBase user = manager.getUser(player); - user.remPerm(permission, world); - return true; - } catch (IOException ex) { - plugin.getLogger().log(Level.SEVERE, - String.format("[%s] An error occured while saving perms", totalperms.getDescription().getName()), ex); - return false; - } - } - - @Override - public boolean groupHas(String world, String group, String permission) { - PermissionBase permGroup = manager.getGroup(group); - return permGroup.has(permission, world); - } - - @Override - public boolean groupAdd(String world, String group, String permission) { - try { - PermissionBase permGroup = manager.getGroup(group); - permGroup.addPerm(permission, world); - return true; - } catch (IOException ex) { - plugin.getLogger().log(Level.SEVERE, - String.format("[%s] An error occured while saving perms", totalperms.getDescription().getName()), ex); - return false; - } - } - - @Override - public boolean groupRemove(String world, String group, String permission) { - try { - PermissionBase permGroup = manager.getGroup(group); - permGroup.remPerm(permission, world); - return true; - } catch (IOException ex) { - plugin.getLogger().log(Level.SEVERE, - String.format("[%s] An error occured while saving perms", totalperms.getDescription().getName()), ex); - return false; - } - } - - @Override - public boolean playerInGroup(String world, String player, String group) { - PermissionUser user = manager.getUser(player); - List groups = user.getGroups(world); - return groups.contains(group); - } - - @Override - public boolean playerAddGroup(String world, String player, String group) { - try { - PermissionUser user = manager.getUser(player); - user.addGroup(group, world); - return true; - } catch (IOException ex) { - plugin.getLogger().log(Level.SEVERE, - String.format("[%s] An error occured while saving perms", totalperms.getDescription().getName()), ex); - return false; - } - } - - @Override - public boolean playerRemoveGroup(String world, String player, String group) { - try { - PermissionUser user = manager.getUser(player); - user.remGroup(group, world); - return true; - } catch (IOException ex) { - plugin.getLogger().log(Level.SEVERE, - String.format("[%s] An error occured while saving perms", totalperms.getDescription().getName()), ex); - return false; - } - } - - @Override - public String[] getPlayerGroups(String world, String player) { - PermissionUser user = manager.getUser(player); - List groups = user.getGroups(world); - if (groups == null) { - groups = new ArrayList(); - } - return groups.toArray(new String[groups.size()]); - } - - @Override - public String getPrimaryGroup(String world, String player) { - String[] groups = getPlayerGroups(world, player); - if (groups.length == 0) { - return ""; - } else { - return groups[0]; - } - } +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; - @Override - public String[] getGroups() { - return manager.getGroups(); - } +public class Permission_TotalPermissions extends Permission { + + private final String name = "TotalPermissions"; + private PermissionManager manager; + private TotalPermissions totalperms; + + public Permission_TotalPermissions(final Plugin pl) { + plugin = pl; + } + + public class PermissionServerListener implements Listener { + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (Permission_TotalPermissions.this.manager == null || Permission_TotalPermissions.this.totalperms == null) { + final Plugin permPlugin = event.getPlugin(); + if (permPlugin.getDescription().getName().equals(Permission_TotalPermissions.this.name)) { + Permission_TotalPermissions.this.totalperms = (TotalPermissions) permPlugin; + Permission_TotalPermissions.this.manager = Permission_TotalPermissions.this.totalperms.getManager(); + Permission.log.info(String.format("[%s][Permission] %s hooked.", Permission_TotalPermissions.this.plugin.getDescription().getName(), Permission_TotalPermissions.this.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (Permission_TotalPermissions.this.manager != null) { + if (event.getPlugin().getDescription().getName().equals(Permission_TotalPermissions.this.name)) { + Permission_TotalPermissions.this.totalperms = null; + Permission_TotalPermissions.this.manager = null; + Permission.log.info(String.format("[%s][Permission] %s un-hooked.", Permission_TotalPermissions.this.plugin.getDescription().getName(), Permission_TotalPermissions.this.name)); + } + } + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean isEnabled() { + return this.plugin != null && this.plugin.isEnabled() && this.totalperms != null && this.totalperms.isEnabled(); + } + + @Override + public boolean hasSuperPermsCompat() { + return true; + } + + @Override + public boolean hasGroupSupport() { + return true; + } + + @Override + public boolean playerHas(final String world, final String player, final String permission) { + final PermissionBase user = this.manager.getUser(player); + return user.has(permission, world); + } + + @Override + public boolean playerAdd(final String world, final String player, final String permission) { + try { + final PermissionBase user = this.manager.getUser(player); + user.addPerm(permission, world); + return true; + } catch (final IOException ex) { + this.plugin.getLogger().log(Level.SEVERE, + String.format("[%s] An error occured while saving perms", this.totalperms.getDescription().getName()), ex); + return false; + } + } + + @Override + public boolean playerRemove(final String world, final String player, final String permission) { + try { + final PermissionBase user = this.manager.getUser(player); + user.remPerm(permission, world); + return true; + } catch (final IOException ex) { + this.plugin.getLogger().log(Level.SEVERE, + String.format("[%s] An error occured while saving perms", this.totalperms.getDescription().getName()), ex); + return false; + } + } + + @Override + public boolean groupHas(final String world, final String group, final String permission) { + final PermissionBase permGroup = this.manager.getGroup(group); + return permGroup.has(permission, world); + } + + @Override + public boolean groupAdd(final String world, final String group, final String permission) { + try { + final PermissionBase permGroup = this.manager.getGroup(group); + permGroup.addPerm(permission, world); + return true; + } catch (final IOException ex) { + this.plugin.getLogger().log(Level.SEVERE, + String.format("[%s] An error occured while saving perms", this.totalperms.getDescription().getName()), ex); + return false; + } + } + + @Override + public boolean groupRemove(final String world, final String group, final String permission) { + try { + final PermissionBase permGroup = this.manager.getGroup(group); + permGroup.remPerm(permission, world); + return true; + } catch (final IOException ex) { + this.plugin.getLogger().log(Level.SEVERE, + String.format("[%s] An error occured while saving perms", this.totalperms.getDescription().getName()), ex); + return false; + } + } + + @Override + public boolean playerInGroup(final String world, final String player, final String group) { + final PermissionUser user = this.manager.getUser(player); + final List groups = user.getGroups(world); + return groups.contains(group); + } + + @Override + public boolean playerAddGroup(final String world, final String player, final String group) { + try { + final PermissionUser user = this.manager.getUser(player); + user.addGroup(group, world); + return true; + } catch (final IOException ex) { + this.plugin.getLogger().log(Level.SEVERE, + String.format("[%s] An error occured while saving perms", this.totalperms.getDescription().getName()), ex); + return false; + } + } + + @Override + public boolean playerRemoveGroup(final String world, final String player, final String group) { + try { + final PermissionUser user = this.manager.getUser(player); + user.remGroup(group, world); + return true; + } catch (final IOException ex) { + this.plugin.getLogger().log(Level.SEVERE, + String.format("[%s] An error occured while saving perms", this.totalperms.getDescription().getName()), ex); + return false; + } + } + + @Override + public String[] getPlayerGroups(final String world, final String player) { + final PermissionUser user = this.manager.getUser(player); + List groups = user.getGroups(world); + if (groups == null) { + groups = new ArrayList<>(); + } + return groups.toArray(new String[0]); + } + + @Override + public String getPrimaryGroup(final String world, final String player) { + final String[] groups = this.getPlayerGroups(world, player); + if (groups.length == 0) { + return ""; + } else { + return groups[0]; + } + } + + @Override + public String[] getGroups() { + return this.manager.getGroups(); + } } diff --git a/src/net/milkbowl/vault/permission/plugins/Permission_Xperms.java b/src/net/milkbowl/vault/permission/plugins/Permission_Xperms.java index e5454ebb..27b53503 100644 --- a/src/net/milkbowl/vault/permission/plugins/Permission_Xperms.java +++ b/src/net/milkbowl/vault/permission/plugins/Permission_Xperms.java @@ -15,10 +15,8 @@ */ package net.milkbowl.vault.permission.plugins; -import net.milkbowl.vault.permission.Permission; - import com.github.sebc722.xperms.core.Main; - +import net.milkbowl.vault.permission.Permission; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -28,152 +26,149 @@ import org.bukkit.plugin.Plugin; public class Permission_Xperms extends Permission { - - private final String name = "Xperms"; - private Main perms = null; - - public Permission_Xperms(Plugin plugin) { - this.plugin = plugin; - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); - - if(perms == null){ - Plugin perms = plugin.getServer().getPluginManager().getPlugin("Xperms"); - if(this.perms != null){ - if(perms.isEnabled()){ - try{ - if(Double.valueOf(perms.getDescription().getVersion()) < 1.1){ - log.info(String.format("[%s] [Permission] %s Current version is not compatible with vault! Please Update!", plugin.getDescription().getName(), name)); - } - } catch(NumberFormatException e){ - // version is first release, numbered 1.0.0 - log.info(String.format("[%s] [Permission] %s Current version is not compatibe with vault! Please Update!", plugin.getDescription().getName(), name)); - } - } - this.perms = (Main) perms; - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - - public class PermissionServerListener implements Listener { - Permission_Xperms permission = null; - - public PermissionServerListener(Permission_Xperms permission){ - this.permission = permission; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (permission.perms == null) { - Plugin perms = event.getPlugin(); - if(perms.getDescription().getName().equals("Xperms")){ - try{ - if(Double.valueOf(perms.getDescription().getVersion()) < 1.1){ - log.info(String.format("[%s] [Permission] %s Current version is not compatible with vault! Please Update!", plugin.getDescription().getName(), name)); - } - } catch(NumberFormatException e){ - // version is first release, numbered 1.0.0 - log.info(String.format("[%s] [Permission] %s Current version is not compatibe with vault! Please Update!", plugin.getDescription().getName(), name)); - } - permission.perms = (Main) perms; - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if(permission.perms != null){ - if(event.getPlugin().getName().equals("Xperms")){ - permission.perms = null; - log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name)); - } - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean isEnabled() { - return perms.isEnabled(); - } - - @Override - public boolean hasSuperPermsCompat() { - return true; - } - - @Override - public boolean playerHas(String world, String player, String permission) { - return perms.getXplayer().hasPerm(world, player, permission); - } - - @Override - public boolean playerAdd(String world, String player, String permission) { - return perms.getXplayer().addNode(world, player, permission); - } - - @Override - public boolean playerRemove(String world, String player, String permission) { - return perms.getXplayer().removeNode(world, player, permission); - } - - @Override - public boolean groupHas(String world, String group, String permission) { - return perms.getXgroup().hasPerm(group, permission); - } - - @Override - public boolean groupAdd(String world, String group, String permission) { - perms.getXgroup().addNode(group, permission); - return true; - } - - @Override - public boolean groupRemove(String world, String group, String permission) { - return perms.getXgroup().removeNode(group, permission); - } - - @Override - public boolean playerInGroup(String world, String player, String group) { - String groupForWorld = perms.getXplayer().getGroupForWorld(player, world); - if(groupForWorld.equals(group)){ - return true; - } - return false; - } - - @Override - public boolean playerAddGroup(String world, String player, String group) { - return perms.getXplayer().setPlayerGroup(world, player, group); - } - - @Override - public boolean playerRemoveGroup(String world, String player, String group) { - return perms.getXplayer().setPlayerDefault(world, player); - } - - @Override - public String[] getPlayerGroups(String world, String player) { - return perms.getXplayer().getPlayerGroups(player); - } - - @Override - public String getPrimaryGroup(String world, String player) { - return perms.getXplayer().getGroupForWorld(player, world); - } - - @Override - public String[] getGroups() { - return perms.getXgroup().getGroups(); - } - - @Override - public boolean hasGroupSupport() { - return true; - } + + private final String name = "Xperms"; + private Main perms; + + public Permission_Xperms(final Plugin plugin) { + this.plugin = plugin; + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); + + if (this.perms == null) { + final Plugin perms = plugin.getServer().getPluginManager().getPlugin("Xperms"); + if (this.perms != null) { + if (perms.isEnabled()) { + try { + if (Double.parseDouble(perms.getDescription().getVersion()) < 1.1) { + Permission.log.info(String.format("[%s] [Permission] %s Current version is not compatible with vault! Please Update!", plugin.getDescription().getName(), this.name)); + } + } catch (final NumberFormatException e) { + // version is first release, numbered 1.0.0 + Permission.log.info(String.format("[%s] [Permission] %s Current version is not compatibe with vault! Please Update!", plugin.getDescription().getName(), this.name)); + } + } + this.perms = (Main) perms; + Permission.log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), this.name)); + } + } + } + + public class PermissionServerListener implements Listener { + final Permission_Xperms permission; + + public PermissionServerListener(final Permission_Xperms permission) { + this.permission = permission; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.permission.perms == null) { + final Plugin perms = event.getPlugin(); + if (perms.getDescription().getName().equals("Xperms")) { + try { + if (Double.parseDouble(perms.getDescription().getVersion()) < 1.1) { + Permission.log.info(String.format("[%s] [Permission] %s Current version is not compatible with vault! Please Update!", Permission_Xperms.this.plugin.getDescription().getName(), Permission_Xperms.this.name)); + } + } catch (final NumberFormatException e) { + // version is first release, numbered 1.0.0 + Permission.log.info(String.format("[%s] [Permission] %s Current version is not compatibe with vault! Please Update!", Permission_Xperms.this.plugin.getDescription().getName(), Permission_Xperms.this.name)); + } + this.permission.perms = (Main) perms; + Permission.log.info(String.format("[%s][Permission] %s hooked.", Permission_Xperms.this.plugin.getDescription().getName(), Permission_Xperms.this.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.permission.perms != null) { + if (event.getPlugin().getName().equals("Xperms")) { + this.permission.perms = null; + Permission.log.info(String.format("[%s][Permission] %s un-hooked.", Permission_Xperms.this.plugin.getDescription().getName(), this.permission.name)); + } + } + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean isEnabled() { + return this.perms.isEnabled(); + } + + @Override + public boolean hasSuperPermsCompat() { + return true; + } + + @Override + public boolean playerHas(final String world, final String player, final String permission) { + return this.perms.getXplayer().hasPerm(world, player, permission); + } + + @Override + public boolean playerAdd(final String world, final String player, final String permission) { + return this.perms.getXplayer().addNode(world, player, permission); + } + + @Override + public boolean playerRemove(final String world, final String player, final String permission) { + return this.perms.getXplayer().removeNode(world, player, permission); + } + + @Override + public boolean groupHas(final String world, final String group, final String permission) { + return this.perms.getXgroup().hasPerm(group, permission); + } + + @Override + public boolean groupAdd(final String world, final String group, final String permission) { + this.perms.getXgroup().addNode(group, permission); + return true; + } + + @Override + public boolean groupRemove(final String world, final String group, final String permission) { + return this.perms.getXgroup().removeNode(group, permission); + } + + @Override + public boolean playerInGroup(final String world, final String player, final String group) { + final String groupForWorld = this.perms.getXplayer().getGroupForWorld(player, world); + return groupForWorld.equals(group); + } + + @Override + public boolean playerAddGroup(final String world, final String player, final String group) { + return this.perms.getXplayer().setPlayerGroup(world, player, group); + } + + @Override + public boolean playerRemoveGroup(final String world, final String player, final String group) { + return this.perms.getXplayer().setPlayerDefault(world, player); + } + + @Override + public String[] getPlayerGroups(final String world, final String player) { + return this.perms.getXplayer().getPlayerGroups(player); + } + + @Override + public String getPrimaryGroup(final String world, final String player) { + return this.perms.getXplayer().getGroupForWorld(player, world); + } + + @Override + public String[] getGroups() { + return this.perms.getXgroup().getGroups(); + } + + @Override + public boolean hasGroupSupport() { + return true; + } } \ No newline at end of file diff --git a/src/net/milkbowl/vault/permission/plugins/Permission_bPermissions.java b/src/net/milkbowl/vault/permission/plugins/Permission_bPermissions.java index caf2568b..1a70527b 100644 --- a/src/net/milkbowl/vault/permission/plugins/Permission_bPermissions.java +++ b/src/net/milkbowl/vault/permission/plugins/Permission_bPermissions.java @@ -15,10 +15,11 @@ */ package net.milkbowl.vault.permission.plugins; -import java.util.List; - +import de.bananaco.permissions.Permissions; +import de.bananaco.permissions.interfaces.PermissionSet; +import de.bananaco.permissions.worlds.HasPermission; +import de.bananaco.permissions.worlds.WorldPermissionsManager; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -27,255 +28,252 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import de.bananaco.permissions.Permissions; -import de.bananaco.permissions.interfaces.PermissionSet; -import de.bananaco.permissions.worlds.HasPermission; -import de.bananaco.permissions.worlds.WorldPermissionsManager; +import java.util.List; public class Permission_bPermissions extends Permission { - - private final String name = "bPermissions"; - private WorldPermissionsManager perms; - - public Permission_bPermissions(Plugin plugin) { - this.plugin = plugin; - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); - - // Load Plugin in case it was loaded before - if (perms == null) { - Plugin p = plugin.getServer().getPluginManager().getPlugin("bPermissions"); - if (p != null) { - perms = Permissions.getWorldPermissionsManager(); - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - - public class PermissionServerListener implements Listener { - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (perms == null) { - Plugin p = event.getPlugin(); - if(p.getDescription().getName().equals("bPermissions") && p.isEnabled()) { - perms = Permissions.getWorldPermissionsManager(); - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (perms != null) { - if (event.getPlugin().getDescription().getName().equals("bPermissions")) { - perms = null; - log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), name)); - } - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean isEnabled() { - return this.perms != null; - } - - @Override - public boolean playerHas(String world, String player, String permission) { - return HasPermission.has(player, world, permission); - } - - @Override - public boolean playerAdd(String world, String player, String permission) { - if (world == null) { - return false; - } - - PermissionSet set = perms.getPermissionSet(world); - if (set == null) { - return false; - } - - set.addPlayerNode(permission, player); - return true; - } - - @Override - public boolean playerRemove(String world, String player, String permission) { - if (world == null) { - return false; - } - - PermissionSet set = perms.getPermissionSet(world); - if (set == null) { - return false; - } - - set.removePlayerNode(permission, player); - return true; - } - - // use superclass implementation of playerAddTransient() and playerRemoveTransient() - - @Override - public boolean groupHas(String world, String group, String permission) { - if (world == null) { - return false; - } - - PermissionSet set = perms.getPermissionSet(world); - if (set == null) { - return false; - } - - if (set.getGroupNodes(group) == null) { - return false; - } - - return set.getGroupNodes(group).contains(permission); - } - - @Override - public boolean groupAdd(String world, String group, String permission) { - if (world == null) { - return false; - } - - PermissionSet set = perms.getPermissionSet(world); - if (set == null) { - return false; - } - - if (set.getGroupNodes(group) == null) { - return false; - } - - set.addNode(permission, group); - return true; - } - - @Override - public boolean groupRemove(String world, String group, String permission) { - if (world == null) { - return false; - } - - PermissionSet set = perms.getPermissionSet(world); - if (set == null) { - return false; - } - - if (set.getGroupNodes(group) == null) { - return false; - } - - set.removeNode(permission, group); - return true; - } - - @Override - public boolean playerInGroup(String world, String player, String group) { - if (world == null) { - return false; - } - - PermissionSet set = perms.getPermissionSet(world); - if (set == null) { - return false; - } - - if (set.getGroups(player) == null) { - return false; - } - - return set.getGroups(player).contains(group); - } - - @Override - public boolean playerAddGroup(String world, String player, String group) { - if (world == null) { - return false; - } - - PermissionSet set = perms.getPermissionSet(world); - if (set == null) { - return false; - } - - if (set.getGroupNodes(group) == null) { - return false; - } - - set.addGroup(player, group); - return true; - } - - @Override - public boolean playerRemoveGroup(String world, String player, String group) { - if (world == null) { - return false; - } - - PermissionSet set = perms.getPermissionSet(world); - if (set == null) { - return false; - } - - set.removeGroup(player, group); - return true; - } - - @Override - public String[] getPlayerGroups(String world, String player) { - if (world == null) { - return null; - } - - PermissionSet set = perms.getPermissionSet(world); - if (set == null) { - return null; - } - - List groups = set.getGroups(player); - return groups == null ? null : groups.toArray(new String[0]); - } - - @Override - public String getPrimaryGroup(String world, String player) { - if (world == null) { - return null; - } - - PermissionSet set = perms.getPermissionSet(world); - if (set == null) { - return null; - } - - List groups = set.getGroups(player); - if (groups == null || groups.isEmpty()) { - return null; - } else { - return groups.get(0); - } - } - - @Override - public String[] getGroups() { - throw new UnsupportedOperationException("bPermissions does not support server-wide groups"); - } - - @Override - public boolean hasSuperPermsCompat() { - return true; - } - - @Override - public boolean hasGroupSupport() { - return true; - } + + private final String name = "bPermissions"; + private WorldPermissionsManager perms; + + public Permission_bPermissions(final Plugin plugin) { + this.plugin = plugin; + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); + + // Load Plugin in case it was loaded before + if (this.perms == null) { + final Plugin p = plugin.getServer().getPluginManager().getPlugin("bPermissions"); + if (p != null) { + this.perms = Permissions.getWorldPermissionsManager(); + Permission.log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), this.name)); + } + } + } + + public class PermissionServerListener implements Listener { + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (Permission_bPermissions.this.perms == null) { + final Plugin p = event.getPlugin(); + if (p.getDescription().getName().equals("bPermissions") && p.isEnabled()) { + Permission_bPermissions.this.perms = Permissions.getWorldPermissionsManager(); + Permission.log.info(String.format("[%s][Permission] %s hooked.", Permission_bPermissions.this.plugin.getDescription().getName(), Permission_bPermissions.this.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (Permission_bPermissions.this.perms != null) { + if (event.getPlugin().getDescription().getName().equals("bPermissions")) { + Permission_bPermissions.this.perms = null; + Permission.log.info(String.format("[%s][Permission] %s un-hooked.", Permission_bPermissions.this.plugin.getDescription().getName(), Permission_bPermissions.this.name)); + } + } + } + } + + @Override + public String getName() { + return this.name; + } + + @Override + public boolean isEnabled() { + return perms != null; + } + + @Override + public boolean playerHas(final String world, final String player, final String permission) { + return HasPermission.has(player, world, permission); + } + + @Override + public boolean playerAdd(final String world, final String player, final String permission) { + if (world == null) { + return false; + } + + final PermissionSet set = this.perms.getPermissionSet(world); + if (set == null) { + return false; + } + + set.addPlayerNode(permission, player); + return true; + } + + @Override + public boolean playerRemove(final String world, final String player, final String permission) { + if (world == null) { + return false; + } + + final PermissionSet set = this.perms.getPermissionSet(world); + if (set == null) { + return false; + } + + set.removePlayerNode(permission, player); + return true; + } + + // use superclass implementation of playerAddTransient() and playerRemoveTransient() + + @Override + public boolean groupHas(final String world, final String group, final String permission) { + if (world == null) { + return false; + } + + final PermissionSet set = this.perms.getPermissionSet(world); + if (set == null) { + return false; + } + + if (set.getGroupNodes(group) == null) { + return false; + } + + return set.getGroupNodes(group).contains(permission); + } + + @Override + public boolean groupAdd(final String world, final String group, final String permission) { + if (world == null) { + return false; + } + + final PermissionSet set = this.perms.getPermissionSet(world); + if (set == null) { + return false; + } + + if (set.getGroupNodes(group) == null) { + return false; + } + + set.addNode(permission, group); + return true; + } + + @Override + public boolean groupRemove(final String world, final String group, final String permission) { + if (world == null) { + return false; + } + + final PermissionSet set = this.perms.getPermissionSet(world); + if (set == null) { + return false; + } + + if (set.getGroupNodes(group) == null) { + return false; + } + + set.removeNode(permission, group); + return true; + } + + @Override + public boolean playerInGroup(final String world, final String player, final String group) { + if (world == null) { + return false; + } + + final PermissionSet set = this.perms.getPermissionSet(world); + if (set == null) { + return false; + } + + if (set.getGroups(player) == null) { + return false; + } + + return set.getGroups(player).contains(group); + } + + @Override + public boolean playerAddGroup(final String world, final String player, final String group) { + if (world == null) { + return false; + } + + final PermissionSet set = this.perms.getPermissionSet(world); + if (set == null) { + return false; + } + + if (set.getGroupNodes(group) == null) { + return false; + } + + set.addGroup(player, group); + return true; + } + + @Override + public boolean playerRemoveGroup(final String world, final String player, final String group) { + if (world == null) { + return false; + } + + final PermissionSet set = this.perms.getPermissionSet(world); + if (set == null) { + return false; + } + + set.removeGroup(player, group); + return true; + } + + @Override + public String[] getPlayerGroups(final String world, final String player) { + if (world == null) { + return null; + } + + final PermissionSet set = this.perms.getPermissionSet(world); + if (set == null) { + return null; + } + + final List groups = set.getGroups(player); + return groups == null ? null : groups.toArray(new String[0]); + } + + @Override + public String getPrimaryGroup(final String world, final String player) { + if (world == null) { + return null; + } + + final PermissionSet set = this.perms.getPermissionSet(world); + if (set == null) { + return null; + } + + final List groups = set.getGroups(player); + if (groups == null || groups.isEmpty()) { + return null; + } else { + return groups.get(0); + } + } + + @Override + public String[] getGroups() { + throw new UnsupportedOperationException("bPermissions does not support server-wide groups"); + } + + @Override + public boolean hasSuperPermsCompat() { + return true; + } + + @Override + public boolean hasGroupSupport() { + return true; + } } diff --git a/src/net/milkbowl/vault/permission/plugins/Permission_bPermissions2.java b/src/net/milkbowl/vault/permission/plugins/Permission_bPermissions2.java index ecd2894e..ed71ff11 100644 --- a/src/net/milkbowl/vault/permission/plugins/Permission_bPermissions2.java +++ b/src/net/milkbowl/vault/permission/plugins/Permission_bPermissions2.java @@ -15,11 +15,8 @@ */ package net.milkbowl.vault.permission.plugins; -import java.util.HashSet; -import java.util.Set; - +import de.bananaco.bpermissions.api.*; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -30,176 +27,173 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; -import de.bananaco.bpermissions.api.ApiLayer; -import de.bananaco.bpermissions.api.World; -import de.bananaco.bpermissions.api.WorldManager; -import de.bananaco.bpermissions.api.Calculable; -import de.bananaco.bpermissions.api.CalculableType; +import java.util.HashSet; +import java.util.Set; public class Permission_bPermissions2 extends Permission { - - private final String name = "bPermissions2"; - private boolean hooked = false; - - public Permission_bPermissions2(Plugin plugin) { - this.plugin = plugin; - - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); - - // Load Plugin in case it was loaded before - if (!hooked) { - Plugin p = plugin.getServer().getPluginManager().getPlugin("bPermissions"); - if (p != null) { - hooked = true; - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - - public class PermissionServerListener implements Listener { - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if (!hooked) { - Plugin p = event.getPlugin(); - if(p.getDescription().getName().equals("bPermissions")) { - hooked = true; - log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if (hooked) { - if (event.getPlugin().getDescription().getName().equals("bPermissions")) { - hooked = false; - log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), name)); - } - } - } - } - - @Override - public String getName() { - return name; - } - - @Override - public boolean isEnabled() { - return hooked; - } - - @Override - public boolean has(Player player, String permission) { - return playerHas(player.getWorld().getName(), player.getName(), permission); - } - - @Override - public boolean has(String world, String player, String permission) { - return playerHas(world, player, permission); + + private final String name = "bPermissions2"; + private boolean hooked; + + public Permission_bPermissions2(final Plugin plugin) { + this.plugin = plugin; + + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin); + + // Load Plugin in case it was loaded before + if (!this.hooked) { + final Plugin p = plugin.getServer().getPluginManager().getPlugin("bPermissions"); + if (p != null) { + this.hooked = true; + Permission.log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), this.name)); + } + } } - + + public class PermissionServerListener implements Listener { + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (!Permission_bPermissions2.this.hooked) { + final Plugin p = event.getPlugin(); + if (p.getDescription().getName().equals("bPermissions")) { + Permission_bPermissions2.this.hooked = true; + Permission.log.info(String.format("[%s][Permission] %s hooked.", Permission_bPermissions2.this.plugin.getDescription().getName(), Permission_bPermissions2.this.name)); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (Permission_bPermissions2.this.hooked) { + if (event.getPlugin().getDescription().getName().equals("bPermissions")) { + Permission_bPermissions2.this.hooked = false; + Permission.log.info(String.format("[%s][Permission] %s un-hooked.", Permission_bPermissions2.this.plugin.getDescription().getName(), Permission_bPermissions2.this.name)); + } + } + } + } + @Override - public boolean has(CommandSender sender, String permission) { - if(sender instanceof Player) { - Player player = (Player) sender; - return has(player, permission); + public String getName() { + return this.name; + } + + @Override + public boolean isEnabled() { + return this.hooked; + } + + @Override + public boolean has(final Player player, final String permission) { + return this.playerHas(player.getWorld().getName(), player.getName(), permission); + } + + @Override + public boolean has(final String world, final String player, final String permission) { + return this.playerHas(world, player, permission); + } + + @Override + public boolean has(final CommandSender sender, final String permission) { + if (sender instanceof Player) { + final Player player = (Player) sender; + return this.has(player, permission); } return sender.hasPermission(permission); } - + @Override - public boolean has(org.bukkit.World world, String player, String permission) { - return playerHas(world.getName(), player, permission); + public boolean has(final org.bukkit.World world, final String player, final String permission) { + return this.playerHas(world.getName(), player, permission); } - + @Override - public boolean playerHas(String world, String player, String permission) { - return ApiLayer.hasPermission(world, CalculableType.USER, player, permission); - } - - @Override - public boolean playerAdd(String world, String player, String permission) { - ApiLayer.addPermission(world, CalculableType.USER, player, de.bananaco.bpermissions.api.Permission.loadFromString(permission)); - return true; - } - - @Override - public boolean playerRemove(String world, String player, String permission) { - ApiLayer.removePermission(world, CalculableType.USER, player, permission); - return true; - } - - // use superclass implementation of playerAddTransient() and playerRemoveTransient() - - @Override - public boolean groupHas(String world, String group, String permission) { - return ApiLayer.hasPermission(world, CalculableType.GROUP, group, permission); - } - - @Override - public boolean groupAdd(String world, String group, String permission) { - ApiLayer.addPermission(world, CalculableType.GROUP, group, de.bananaco.bpermissions.api.Permission.loadFromString(permission)); - return true; - } - - @Override - public boolean groupRemove(String world, String group, String permission) { - ApiLayer.removePermission(world, CalculableType.GROUP, group, permission); - return true; - } - - @Override - public boolean playerInGroup(String world, String player, String group) { - return ApiLayer.hasGroup(world, CalculableType.USER, player, group); - } - - @Override - public boolean playerAddGroup(String world, String player, String group) { - ApiLayer.addGroup(world, CalculableType.USER, player, group); - return true; - } - - @Override - public boolean playerRemoveGroup(String world, String player, String group) { - ApiLayer.removeGroup(world, CalculableType.USER, player, group); - return true; - } - - @Override - public String[] getPlayerGroups(String world, String player) { - return ApiLayer.getGroups(world, CalculableType.USER, player); - } - - @Override - public String getPrimaryGroup(String world, String player) { - String[] groups = getPlayerGroups(world, player); - return groups != null && groups.length > 0 ? groups[0] : null; - } - - @Override - public String[] getGroups() { - String[] groups = null; - Set gSet = new HashSet(); - for(World world : WorldManager.getInstance().getAllWorlds()) { - Set gr = world.getAll(CalculableType.GROUP); - for(Calculable c : gr) { - gSet.add(c.getNameLowerCase()); - } - } - // Convert to String - groups = gSet.toArray(new String[gSet.size()]); - return groups; - } - - @Override - public boolean hasSuperPermsCompat() { - return true; - } - - @Override - public boolean hasGroupSupport() { - return true; - } + public boolean playerHas(final String world, final String player, final String permission) { + return ApiLayer.hasPermission(world, CalculableType.USER, player, permission); + } + + @Override + public boolean playerAdd(final String world, final String player, final String permission) { + ApiLayer.addPermission(world, CalculableType.USER, player, de.bananaco.bpermissions.api.Permission.loadFromString(permission)); + return true; + } + + @Override + public boolean playerRemove(final String world, final String player, final String permission) { + ApiLayer.removePermission(world, CalculableType.USER, player, permission); + return true; + } + + // use superclass implementation of playerAddTransient() and playerRemoveTransient() + + @Override + public boolean groupHas(final String world, final String group, final String permission) { + return ApiLayer.hasPermission(world, CalculableType.GROUP, group, permission); + } + + @Override + public boolean groupAdd(final String world, final String group, final String permission) { + ApiLayer.addPermission(world, CalculableType.GROUP, group, de.bananaco.bpermissions.api.Permission.loadFromString(permission)); + return true; + } + + @Override + public boolean groupRemove(final String world, final String group, final String permission) { + ApiLayer.removePermission(world, CalculableType.GROUP, group, permission); + return true; + } + + @Override + public boolean playerInGroup(final String world, final String player, final String group) { + return ApiLayer.hasGroup(world, CalculableType.USER, player, group); + } + + @Override + public boolean playerAddGroup(final String world, final String player, final String group) { + ApiLayer.addGroup(world, CalculableType.USER, player, group); + return true; + } + + @Override + public boolean playerRemoveGroup(final String world, final String player, final String group) { + ApiLayer.removeGroup(world, CalculableType.USER, player, group); + return true; + } + + @Override + public String[] getPlayerGroups(final String world, final String player) { + return ApiLayer.getGroups(world, CalculableType.USER, player); + } + + @Override + public String getPrimaryGroup(final String world, final String player) { + final String[] groups = this.getPlayerGroups(world, player); + return groups != null && groups.length > 0 ? groups[0] : null; + } + + @Override + public String[] getGroups() { + String[] groups; + final Set gSet = new HashSet<>(); + for (final World world : WorldManager.getInstance().getAllWorlds()) { + final Set gr = world.getAll(CalculableType.GROUP); + for (final Calculable c : gr) { + gSet.add(c.getNameLowerCase()); + } + } + // Convert to String + groups = gSet.toArray(new String[0]); + return groups; + } + + @Override + public boolean hasSuperPermsCompat() { + return true; + } + + @Override + public boolean hasGroupSupport() { + return true; + } } diff --git a/src/net/milkbowl/vault/permission/plugins/Permission_rscPermissions.java b/src/net/milkbowl/vault/permission/plugins/Permission_rscPermissions.java index 2db8561b..8778cf3f 100644 --- a/src/net/milkbowl/vault/permission/plugins/Permission_rscPermissions.java +++ b/src/net/milkbowl/vault/permission/plugins/Permission_rscPermissions.java @@ -16,7 +16,6 @@ package net.milkbowl.vault.permission.plugins; import net.milkbowl.vault.permission.Permission; - import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -24,137 +23,135 @@ import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; - import ru.simsonic.rscPermissions.MainPluginClass; public class Permission_rscPermissions extends Permission { - - private final Plugin vault; - private ru.simsonic.rscPermissions.MainPluginClass rscp = null; - private ru.simsonic.rscPermissions.rscpAPI rscpAPI = null; - - public Permission_rscPermissions(Plugin plugin) { - super(); - this.vault = plugin; - Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), vault); - if (rscp == null) { - Plugin perms = plugin.getServer().getPluginManager().getPlugin("rscPermissions"); - if (perms != null && perms.isEnabled()) { - this.rscp = (MainPluginClass) perms; - rscpAPI = rscp.API; - plugin.getLogger().info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), "rscPermissions")); - } - } - } - - private class PermissionServerListener implements Listener { - private final Permission_rscPermissions bridge; - - public PermissionServerListener(Permission_rscPermissions bridge) { - this.bridge = bridge; - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginEnable(PluginEnableEvent event) { - if(bridge.rscp == null) { - Plugin plugin = event.getPlugin(); - if (plugin.getDescription().getName().equals("rscPermissions")) { - bridge.rscp = (MainPluginClass) plugin; - bridge.rscpAPI = bridge.rscp.API; - log.info(String.format("[%s][Permission] %s hooked.", vault.getDescription().getName(), "rscPermissions")); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPluginDisable(PluginDisableEvent event) { - if(bridge.rscpAPI != null){ - if(event.getPlugin().getDescription().getName().equals(bridge.rscpAPI.getName())) { - bridge.rscpAPI = null; - bridge.rscp = null; - log.info(String.format("[%s][Permission] %s un-hooked.", vault.getDescription().getName(), "rscPermissions")); - } - } - } - } - - @Override - public String getName() { - return "rscPermissions"; - } - - @Override - public boolean isEnabled() { - return rscpAPI != null && rscpAPI.isEnabled(); - } - - @Override - public boolean hasSuperPermsCompat() { - return rscpAPI.hasSuperPermsCompat(); - } - - @Override - public boolean hasGroupSupport() { - return rscpAPI.hasGroupSupport(); - } - - @Override - public boolean playerHas(String world, String player, String permission) { - return rscpAPI.playerHas(world, player, permission); - } - - @Override - public boolean playerAdd(String world, String player, String permission) { - return rscpAPI.playerAdd(world, player, permission); - } - - @Override - public boolean playerRemove(String world, String player, String permission) { - return rscpAPI.playerRemove(world, player, permission); - } - - @Override - public boolean groupHas(String world, String group, String permission) { - return rscpAPI.groupHas(world, group, permission); - } - - @Override - public boolean groupAdd(String world, String group, String permission) { - return rscpAPI.groupAdd(world, group, permission); - } - - @Override - public boolean groupRemove(String world, String group, String permission) { - return rscpAPI.groupRemove(world, group, permission); - } - - @Override - public boolean playerInGroup(String world, String player, String group) { - return rscpAPI.playerInGroup(world, player, group); - } - - @Override - public boolean playerAddGroup(String world, String player, String group) { - return rscpAPI.playerAddGroup(world, player, group); - } - - @Override - public boolean playerRemoveGroup(String world, String player, String group) { - return rscpAPI.playerRemoveGroup(world, player, group); - } - - @Override - public String[] getPlayerGroups(String world, String player) { - return rscpAPI.getPlayerGroups(world, player); - } - - @Override - public String getPrimaryGroup(String world, String player) { - return rscpAPI.getPrimaryGroup(world, player); - } - - @Override - public String[] getGroups() { - return rscpAPI.getGroups(); - } + + private final Plugin vault; + private ru.simsonic.rscPermissions.MainPluginClass rscp; + private ru.simsonic.rscPermissions.rscpAPI rscpAPI; + + public Permission_rscPermissions(final Plugin plugin) { + vault = plugin; + Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), this.vault); + if (this.rscp == null) { + final Plugin perms = plugin.getServer().getPluginManager().getPlugin("rscPermissions"); + if (perms != null && perms.isEnabled()) { + rscp = (MainPluginClass) perms; + this.rscpAPI = this.rscp.API; + plugin.getLogger().info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), "rscPermissions")); + } + } + } + + private class PermissionServerListener implements Listener { + private final Permission_rscPermissions bridge; + + public PermissionServerListener(final Permission_rscPermissions bridge) { + this.bridge = bridge; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginEnable(final PluginEnableEvent event) { + if (this.bridge.rscp == null) { + final Plugin plugin = event.getPlugin(); + if (plugin.getDescription().getName().equals("rscPermissions")) { + this.bridge.rscp = (MainPluginClass) plugin; + this.bridge.rscpAPI = this.bridge.rscp.API; + Permission.log.info(String.format("[%s][Permission] %s hooked.", Permission_rscPermissions.this.vault.getDescription().getName(), "rscPermissions")); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPluginDisable(final PluginDisableEvent event) { + if (this.bridge.rscpAPI != null) { + if (event.getPlugin().getDescription().getName().equals(this.bridge.rscpAPI.getName())) { + this.bridge.rscpAPI = null; + this.bridge.rscp = null; + Permission.log.info(String.format("[%s][Permission] %s un-hooked.", Permission_rscPermissions.this.vault.getDescription().getName(), "rscPermissions")); + } + } + } + } + + @Override + public String getName() { + return "rscPermissions"; + } + + @Override + public boolean isEnabled() { + return this.rscpAPI != null && this.rscpAPI.isEnabled(); + } + + @Override + public boolean hasSuperPermsCompat() { + return this.rscpAPI.hasSuperPermsCompat(); + } + + @Override + public boolean hasGroupSupport() { + return this.rscpAPI.hasGroupSupport(); + } + + @Override + public boolean playerHas(final String world, final String player, final String permission) { + return this.rscpAPI.playerHas(world, player, permission); + } + + @Override + public boolean playerAdd(final String world, final String player, final String permission) { + return this.rscpAPI.playerAdd(world, player, permission); + } + + @Override + public boolean playerRemove(final String world, final String player, final String permission) { + return this.rscpAPI.playerRemove(world, player, permission); + } + + @Override + public boolean groupHas(final String world, final String group, final String permission) { + return this.rscpAPI.groupHas(world, group, permission); + } + + @Override + public boolean groupAdd(final String world, final String group, final String permission) { + return this.rscpAPI.groupAdd(world, group, permission); + } + + @Override + public boolean groupRemove(final String world, final String group, final String permission) { + return this.rscpAPI.groupRemove(world, group, permission); + } + + @Override + public boolean playerInGroup(final String world, final String player, final String group) { + return this.rscpAPI.playerInGroup(world, player, group); + } + + @Override + public boolean playerAddGroup(final String world, final String player, final String group) { + return this.rscpAPI.playerAddGroup(world, player, group); + } + + @Override + public boolean playerRemoveGroup(final String world, final String player, final String group) { + return this.rscpAPI.playerRemoveGroup(world, player, group); + } + + @Override + public String[] getPlayerGroups(final String world, final String player) { + return this.rscpAPI.getPlayerGroups(world, player); + } + + @Override + public String getPrimaryGroup(final String world, final String player) { + return this.rscpAPI.getPrimaryGroup(world, player); + } + + @Override + public String[] getGroups() { + return this.rscpAPI.getGroups(); + } }