Merge pull request #502 from boozaa/patch-1

Update Economy_InTime2.java
This commit is contained in:
Nick Minkler 2014-01-18 05:33:19 -08:00
commit 97d512348d
1 changed files with 199 additions and 199 deletions

View File

@ -13,202 +13,202 @@
+ + You should have received a copy of the GNU Lesser General Public License + + You should have received a copy of the GNU Lesser General Public License
+ + along with Vault. If not, see <http://www.gnu.org/licenses/>. + + along with Vault. If not, see <http://www.gnu.org/licenses/>.
+ + */ + + */
+ +package net.milkbowl.vault.economy.plugins; package net.milkbowl.vault.economy.plugins;
+ +
+ +import java.util.List; import java.util.List;
+ +import java.util.logging.Logger; import java.util.logging.Logger;
+ +
+ +import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
+ +import net.milkbowl.vault.economy.EconomyResponse; import net.milkbowl.vault.economy.EconomyResponse;
+ +import net.milkbowl.vault.economy.EconomyResponse.ResponseType; import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
+ +
+ +import org.bukkit.Bukkit; import org.bukkit.Bukkit;
+ +import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
+ +import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
+ +import org.bukkit.event.Listener; import org.bukkit.event.Listener;
+ +import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginDisableEvent;
+ +import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.PluginEnableEvent;
+ +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
+ +
+ +Import com.BlackMage.Intime.Intime import com.BlackMage.Intime.Intime
+ +
+ +public class Economy_InTime2 implements Economy { public class Economy_InTime2 implements Economy {
+ + private static final Logger log = Logger.getLogger("Minecraft"); private static final Logger log = Logger.getLogger("Minecraft");
+ +
+ + private String name = "InTime2"; private String name = "InTime2";
+ + private Plugin plugin = null; private Plugin plugin = null;
+ + protected Main economy = null; protected Main economy = null;
+ +
+ + public Economy_InTime2(Plugin plugin) { public Economy_InTime2(Plugin plugin) {
+ + this.plugin = plugin; this.plugin = plugin;
+ + Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin); Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin);
+ + // Load Plugin in case it was loaded before // Load Plugin in case it was loaded before
+ + if (economy == null) { if (economy == null) {
+ + Plugin ec = plugin.getServer().getPluginManager().getPlugin("InTime2"); Plugin ec = plugin.getServer().getPluginManager().getPlugin("InTime2");
+ + if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.BlackMage.InTime2.InTime2")) { if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.BlackMage.InTime2.InTime2")) {
+ + log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name)); log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
+ + } }
+ + } }
+ + } }
+ +
+ + @Override @Override
+ + public boolean isEnabled() { public boolean isEnabled() {
+ + if (economy == null) { if (economy == null) {
+ + return false; return false;
+ + } else { } else {
+ + return true; return true;
+ + } }
+ + } }
+ +
+ + @Override @Override
+ + public String getName() { public String getName() {
+ + return name; return name;
+ + } }
+ +
+ + @Override @Override
+ + public String format(double amount) { public String format(double amount) {
+ + return Functions.format(amount); return Functions.format(amount);
+ + } }
+ +
+ + @Override @Override
+ + public String currencyNameSingular() { public String currencyNameSingular() {
+ + return Functions.currencyName(); return Functions.currencyName();
+ + } }
+ +
+ + @Override @Override
+ + public String currencyNamePlural() { public String currencyNamePlural() {
+ + return Functions.currencyName(); return Functions.currencyName();
+ + } }
+ +
+ + @Override @Override
+ + public double getBalance(String playerName) { public double getBalance(String playerName) {
+ + return (double) Backend.getMoney(playerName); return (double) Backend.getMoney(playerName);
+ + } }
+ +
+ + @Override @Override
+ + public EconomyResponse withdrawPlayer(String playerName, double amount) { public EconomyResponse withdrawPlayer(String playerName, double amount) {
+ + if (amount < 0) { if (amount < 0) {
+ + return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds"); return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot withdraw negative funds");
+ + } }
+ +
+ + if (Backend.hasEnoughMoney(playerName, amount)) { if (Backend.hasEnoughMoney(playerName, amount)) {
+ + int newAmount = Backend.getMoney(playerName) - amount; int newAmount = Backend.getMoney(playerName) - amount;
+ + Backend.setMoney(playerName, newAmount); Backend.setMoney(playerName, newAmount);
+ + return new EconomyResponse(amount, newAmount, ResponseType.SUCCESS, null); return new EconomyResponse(amount, newAmount, ResponseType.SUCCESS, null);
+ + } else { } else {
+ + return new EconomyResponse(0, Backend.getMoney(playerName), ResponseType.FAILURE, "Insufficient funds"); return new EconomyResponse(0, Backend.getMoney(playerName), ResponseType.FAILURE, "Insufficient funds");
+ + } }
+ + } }
+ +
+ + @Override @Override
+ + public EconomyResponse depositPlayer(String playerName, double amount) { public EconomyResponse depositPlayer(String playerName, double amount) {
+ + if (amount < 0) { if (amount < 0) {
+ + return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds"); return new EconomyResponse(0, 0, ResponseType.FAILURE, "Cannot desposit negative funds");
+ + } }
+ +
+ + int newAmount = Backend.getMoney(playerName) + amount; int newAmount = Backend.getMoney(playerName) + amount;
+ + Backend.setMoney(playerName, newAmount); Backend.setMoney(playerName, newAmount);
+ + return new EconomyResponse(amount, newAmount, ResponseType.SUCCESS, null); return new EconomyResponse(amount, newAmount, ResponseType.SUCCESS, null);
+ + } }
+ +
+ + @Override @Override
+ + public boolean has(String playerName, double amount) { public boolean has(String playerName, double amount) {
+ + return getBalance(playerName) >= amount; return getBalance(playerName) >= amount;
+ + } }
+ +
+ + @Override @Override
+ + public EconomyResponse createBank(String name, String player) { public EconomyResponse createBank(String name, String player) {
+ +
+ + return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!"); return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!");
+ + } }
+ +
+ + @Override @Override
+ + public EconomyResponse deleteBank(String name) { public EconomyResponse deleteBank(String name) {
+ + return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!"); return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!");
+ + } }
+ +
+ + @Override @Override
+ + public EconomyResponse bankHas(String name, double amount) { public EconomyResponse bankHas(String name, double amount) {
+ + return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!"); return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!");
+ + } }
+ +
+ + @Override @Override
+ + public EconomyResponse bankWithdraw(String name, double amount) { public EconomyResponse bankWithdraw(String name, double amount) {
+ + return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!"); return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!");
+ + } }
+ +
+ + @Override @Override
+ + public EconomyResponse bankDeposit(String name, double amount) { public EconomyResponse bankDeposit(String name, double amount) {
+ + return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!"); return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!");
+ + } }
+ +
+ + @Override @Override
+ + public EconomyResponse isBankOwner(String name, String playerName) { public EconomyResponse isBankOwner(String name, String playerName) {
+ + return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!"); return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!");
+ + } }
+ +
+ + @Override @Override
+ + public EconomyResponse isBankMember(String name, String playerName) { public EconomyResponse isBankMember(String name, String playerName) {
+ + return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!"); return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!");
+ + } }
+ +
+ + @Override @Override
+ + public EconomyResponse bankBalance(String name) { public EconomyResponse bankBalance(String name) {
+ + return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!"); return new EconomyResponse(0, 0, ResponseType.FAILURE, "Banks not supported by InTime2!");
+ + } }
+ +
+ + @Override @Override
+ + public List<String> getBanks() { public List<String> getBanks() {
+ + throw new UnsupportedOperationException("Banks not supported by InTime2!"); throw new UnsupportedOperationException("Banks not supported by InTime2!");
+ + } }
+ +
+ + @Override @Override
+ + public boolean hasBankSupport() { public boolean hasBankSupport() {
+ + return false; return false;
+ + } }
+ +
+ + @Override @Override
+ + public boolean hasAccount(String playerName) { public boolean hasAccount(String playerName) {
+ + return true; // All players have an account return true; // All players have an account
+ + } }
+ +
+ + @Override @Override
+ + public boolean createPlayerAccount(String playerName) { public boolean createPlayerAccount(String playerName) {
+ + return true; // All players have an account return true; // All players have an account
+ + } }
+ +
+ + @Override @Override
+ + public int fractionalDigits() { public int fractionalDigits() {
+ + return -1; return -1;
+ + } }
+ +
+ + @Override @Override
+ + public boolean hasAccount(String playerName, String worldName) { public boolean hasAccount(String playerName, String worldName) {
+ + return hasAccount(playerName); return hasAccount(playerName);
+ + } }
+ +
+ + @Override @Override
+ + public double getBalance(String playerName, String world) { public double getBalance(String playerName, String world) {
+ + return getBalance(playerName); return getBalance(playerName);
+ + } }
+ +
+ + @Override @Override
+ + public boolean has(String playerName, String worldName, double amount) { public boolean has(String playerName, String worldName, double amount) {
+ + return has(playerName, amount); return has(playerName, amount);
+ + } }
+ +
+ + @Override @Override
+ + public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) { public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) {
+ + return withdrawPlayer(playerName, amount); return withdrawPlayer(playerName, amount);
+ + } }
+ +
+ + @Override @Override
+ + public EconomyResponse depositPlayer(String playerName, String worldName, double amount) { public EconomyResponse depositPlayer(String playerName, String worldName, double amount) {
+ + return depositPlayer(playerName, amount); return depositPlayer(playerName, amount);
+ + } }
+ +
+ + @Override @Override
+ + public boolean createPlayerAccount(String playerName, String worldName) { public boolean createPlayerAccount(String playerName, String worldName) {
+ + return createPlayerAccount(playerName); return createPlayerAccount(playerName);
+ + } }
+ +} }