summaryrefslogtreecommitdiffstats
path: root/Essentials/src/net/ess3/economy
diff options
context:
space:
mode:
Diffstat (limited to 'Essentials/src/net/ess3/economy')
-rw-r--r--Essentials/src/net/ess3/economy/Economy.java207
-rw-r--r--Essentials/src/net/ess3/economy/Money.java17
-rw-r--r--Essentials/src/net/ess3/economy/MoneyHolder.java36
-rw-r--r--Essentials/src/net/ess3/economy/Trade.java357
-rw-r--r--Essentials/src/net/ess3/economy/Worth.java33
-rw-r--r--Essentials/src/net/ess3/economy/WorthHolder.java100
-rw-r--r--Essentials/src/net/ess3/economy/register/Method.java217
-rw-r--r--Essentials/src/net/ess3/economy/register/Methods.java296
-rw-r--r--Essentials/src/net/ess3/economy/register/methods/BOSE6.java334
-rw-r--r--Essentials/src/net/ess3/economy/register/methods/BOSE7.java323
-rw-r--r--Essentials/src/net/ess3/economy/register/methods/MCUR.java195
-rw-r--r--Essentials/src/net/ess3/economy/register/methods/VaultEco.java347
-rw-r--r--Essentials/src/net/ess3/economy/register/methods/iCo4.java256
-rw-r--r--Essentials/src/net/ess3/economy/register/methods/iCo5.java376
-rw-r--r--Essentials/src/net/ess3/economy/register/methods/iCo6.java242
15 files changed, 3336 insertions, 0 deletions
diff --git a/Essentials/src/net/ess3/economy/Economy.java b/Essentials/src/net/ess3/economy/Economy.java
new file mode 100644
index 000000000..4ba48a3d9
--- /dev/null
+++ b/Essentials/src/net/ess3/economy/Economy.java
@@ -0,0 +1,207 @@
+package net.ess3.economy;
+
+import net.ess3.utils.Util;
+import net.ess3.api.*;
+import net.ess3.permissions.Permissions;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+
+public class Economy implements IEconomy
+{
+ private final IEssentials ess;
+ private final MoneyHolder npcs;
+
+ public Economy(IEssentials ess)
+ {
+ this.ess = ess;
+ this.npcs = new MoneyHolder(ess);
+ }
+
+ private double getNPCBalance(String name) throws UserDoesNotExistException
+ {
+ npcs.acquireReadLock();
+ try
+ {
+ Map<String, Double> balances = npcs.getData().getBalances();
+ if (balances == null)
+ {
+ throw new UserDoesNotExistException(name);
+ }
+ Double balance = npcs.getData().getBalances().get(name.toLowerCase(Locale.ENGLISH));
+ if (balance == null)
+ {
+ throw new UserDoesNotExistException(name);
+ }
+ return balance;
+ }
+ finally
+ {
+ npcs.unlock();
+ }
+ }
+
+ private void setNPCBalance(String name, double balance, boolean checkExistance) throws UserDoesNotExistException
+ {
+ npcs.acquireWriteLock();
+ try
+ {
+ Map<String, Double> balances = npcs.getData().getBalances();
+ if (balances == null)
+ {
+ balances = new HashMap<String, Double>();
+ npcs.getData().setBalances(balances);
+ }
+ if (checkExistance && !balances.containsKey(name.toLowerCase(Locale.ENGLISH)))
+ {
+ throw new UserDoesNotExistException(name);
+ }
+ balances.put(name.toLowerCase(Locale.ENGLISH), balance);
+ }
+ finally
+ {
+ npcs.unlock();
+ }
+ }
+
+ private double getStartingBalance()
+ {
+ double startingBalance = 0;
+ ISettings settings = ess.getSettings();
+ settings.acquireReadLock();
+ try
+ {
+ startingBalance = settings.getData().getEconomy().getStartingBalance();
+ }
+ finally
+ {
+ settings.unlock();
+ }
+ return startingBalance;
+ }
+
+ @Override
+ public void onReload()
+ {
+ this.npcs.onReload(false);
+ }
+
+ @Override
+ public double getMoney(String name) throws UserDoesNotExistException
+ {
+ IUser user = ess.getUser(name);
+ if (user == null)
+ {
+ return getNPCBalance(name);
+ }
+ return user.getMoney();
+ }
+
+ @Override
+ public void setMoney(String name, double balance) throws NoLoanPermittedException, UserDoesNotExistException
+ {
+ IUser user = ess.getUser(name);
+ if (user == null)
+ {
+ setNPCBalance(name, balance, true);
+ return;
+ }
+ if (balance < 0.0 && !Permissions.ECO_LOAN.isAuthorized(user))
+ {
+ throw new NoLoanPermittedException();
+ }
+ user.setMoney(balance);
+ }
+
+ @Override
+ public void resetBalance(String name) throws NoLoanPermittedException, UserDoesNotExistException
+ {
+ setMoney(name, getStartingBalance());
+ }
+
+ @Override
+ public String format(double amount)
+ {
+ return Util.displayCurrency(amount, ess);
+ }
+
+ @Override
+ public boolean playerExists(String name)
+ {
+ try
+ {
+ getMoney(name);
+ return true;
+ }
+ catch (UserDoesNotExistException ex)
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean isNPC(String name) throws UserDoesNotExistException
+ {
+ boolean result = ess.getUser(name) == null;
+ if (result)
+ {
+ getNPCBalance(name);
+ }
+ return result;
+ }
+
+ @Override
+ public boolean createNPC(String name)
+ {
+ try
+ {
+ if (isNPC(name))
+ {
+
+ setNPCBalance(name, getStartingBalance(), false);
+ return true;
+ }
+ }
+ catch (UserDoesNotExistException ex)
+ {
+ try
+ {
+ setNPCBalance(name, getStartingBalance(), false);
+ return true;
+ }
+ catch (UserDoesNotExistException ex1)
+ {
+ //This should never happen!
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void removeNPC(String name) throws UserDoesNotExistException
+ {
+ npcs.acquireWriteLock();
+ try
+ {
+ Map<String, Double> balances = npcs.getData().getBalances();
+ if (balances == null)
+ {
+ balances = new HashMap<String, Double>();
+ npcs.getData().setBalances(balances);
+ }
+ if (balances.containsKey(name.toLowerCase(Locale.ENGLISH)))
+ {
+ balances.remove(name.toLowerCase(Locale.ENGLISH));
+ }
+ else
+ {
+ throw new UserDoesNotExistException(name);
+ }
+ }
+ finally
+ {
+ npcs.unlock();
+ }
+ }
+}
diff --git a/Essentials/src/net/ess3/economy/Money.java b/Essentials/src/net/ess3/economy/Money.java
new file mode 100644
index 000000000..20eea3544
--- /dev/null
+++ b/Essentials/src/net/ess3/economy/Money.java
@@ -0,0 +1,17 @@
+package net.ess3.economy;
+
+import net.ess3.storage.MapValueType;
+import net.ess3.storage.StorageObject;
+import java.util.HashMap;
+import java.util.Map;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class Money implements StorageObject
+{
+ @MapValueType(Double.class)
+ private Map<String, Double> balances = new HashMap<String, Double>();
+}
diff --git a/Essentials/src/net/ess3/economy/MoneyHolder.java b/Essentials/src/net/ess3/economy/MoneyHolder.java
new file mode 100644
index 000000000..a17fdb01f
--- /dev/null
+++ b/Essentials/src/net/ess3/economy/MoneyHolder.java
@@ -0,0 +1,36 @@
+package net.ess3.economy;
+
+import net.ess3.api.IEssentials;
+import net.ess3.storage.AsyncStorageObjectHolder;
+import java.io.File;
+import java.io.IOException;
+
+
+public class MoneyHolder extends AsyncStorageObjectHolder<Money>
+{
+
+ @Override
+ public void finishRead()
+ {
+
+ }
+
+ @Override
+ public void finishWrite()
+ {
+
+ }
+
+
+ public MoneyHolder(IEssentials ess)
+ {
+ super(ess, Money.class);
+ onReload();
+ }
+
+ @Override
+ public File getStorageFile() throws IOException
+ {
+ return new File(ess.getDataFolder(), "economy_npcs.yml");
+ }
+}
diff --git a/Essentials/src/net/ess3/economy/Trade.java b/Essentials/src/net/ess3/economy/Trade.java
new file mode 100644
index 000000000..a5225a13a
--- /dev/null
+++ b/Essentials/src/net/ess3/economy/Trade.java
@@ -0,0 +1,357 @@
+package net.ess3.economy;
+
+import static net.ess3.I18n._;
+import net.ess3.api.ChargeException;
+import net.ess3.api.IEssentials;
+import net.ess3.api.ISettings;
+import net.ess3.api.IUser;
+import net.ess3.craftbukkit.InventoryWorkaround;
+import net.ess3.craftbukkit.SetExpFix;
+import net.ess3.permissions.NoCommandCostPermissions;
+import net.ess3.permissions.Permissions;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import lombok.Cleanup;
+import org.bukkit.Location;
+import org.bukkit.entity.Item;
+import org.bukkit.inventory.ItemStack;
+
+
+public class Trade
+{
+ private final transient String command;
+ private final transient String fallbackCommand;
+ private final transient Double money;
+ private final transient ItemStack itemStack;
+ private final transient Integer exp;
+ private final transient IEssentials ess;
+
+ public Trade(final String command, final IEssentials ess)
+ {
+ this(command, null, null, null, null, ess);
+ }
+
+ public Trade(final String command, final String fallback, final IEssentials ess)
+ {
+ this(command, fallback, null, null, null, ess);
+ }
+
+ public Trade(final double money, final IEssentials ess)
+ {
+ this(null, null, money, null, null, ess);
+ }
+
+ public Trade(final ItemStack items, final IEssentials ess)
+ {
+ this(null, null, null, items, null, ess);
+ }
+
+ public Trade(final int exp, final IEssentials ess)
+ {
+ this(null, null, null, null, exp, ess);
+ }
+
+ private Trade(final String command, final String fallback, final Double money, final ItemStack item, final Integer exp, final IEssentials ess)
+ {
+ this.command = command;
+ this.fallbackCommand = fallback;
+ this.money = money;
+ this.itemStack = item;
+ this.exp = exp;
+ this.ess = ess;
+ }
+
+ public void isAffordableFor(final IUser user) throws ChargeException
+ {
+ if (getMoney() != null
+ && getMoney() > 0
+ && !Permissions.ECO_LOAN.isAuthorized(user)
+ && !user.canAfford(getMoney()))
+ {
+ throw new ChargeException(_("notEnoughMoney"));
+ }
+
+ if (getItemStack() != null
+ && !InventoryWorkaround.containsItem(user.getInventory(), true, true, itemStack))
+ {
+ throw new ChargeException(_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")));
+ }
+
+ @Cleanup
+ final ISettings settings = ess.getSettings();
+ settings.acquireReadLock();
+
+ if (command != null && !command.isEmpty()
+ && !NoCommandCostPermissions.getPermission(command).isAuthorized(user)
+ && money < settings.getData().getEconomy().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command)
+ && 0 < settings.getData().getEconomy().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command)
+ && !Permissions.ECO_LOAN.isAuthorized(user))
+ {
+ throw new ChargeException(_("notEnoughMoney"));
+ }
+
+ if (exp != null && exp > 0
+ && SetExpFix.getTotalExperience(user) < exp)
+ {
+ throw new ChargeException(_("notEnoughExperience"));
+ }
+ }
+
+ public void pay(final IUser user)
+ {
+ pay(user, true);
+ }
+
+ public boolean pay(final IUser user, final boolean dropItems)
+ {
+ boolean success = true;
+ if (getMoney() != null && getMoney() > 0)
+ {
+ user.giveMoney(getMoney());
+ }
+ if (getItemStack() != null)
+ {
+ if (dropItems)
+ {
+ final Map<Integer, ItemStack> leftOver = InventoryWorkaround.addItem(user.getInventory(), true, getItemStack());
+ final Location loc = user.getLocation();
+ for (ItemStack dropStack : leftOver.values())
+ {
+ final int maxStackSize = dropStack.getType().getMaxStackSize();
+ final int stacks = dropStack.getAmount() / maxStackSize;
+ final int leftover = dropStack.getAmount() % maxStackSize;
+ final Item[] itemStacks = new Item[stacks + (leftover > 0 ? 1 : 0)];
+ for (int i = 0; i < stacks; i++)
+ {
+ final ItemStack stack = dropStack.clone();
+ stack.setAmount(maxStackSize);
+ itemStacks[i] = loc.getWorld().dropItem(loc, stack);
+ }
+ if (leftover > 0)
+ {
+ final ItemStack stack = dropStack.clone();
+ stack.setAmount(leftover);
+ itemStacks[stacks] = loc.getWorld().dropItem(loc, stack);
+ }
+ }
+ }
+ else
+ {
+ success = InventoryWorkaround.addAllItems(user.getInventory(), true, getItemStack());
+ }
+ user.updateInventory();
+ }
+ if (getExperience() != null)
+ {
+ SetExpFix.setTotalExperience(user, SetExpFix.getTotalExperience(user) + getExperience());
+ }
+ return success;
+ }
+
+ public void charge(final IUser user) throws ChargeException
+ {
+ if (getMoney() != null)
+ {
+ if (!user.canAfford(getMoney()) && getMoney() > 0)
+ {
+ throw new ChargeException(_("notEnoughMoney"));
+ }
+ user.takeMoney(getMoney());
+ }
+ if (getItemStack() != null)
+ {
+ if (!InventoryWorkaround.containsItem(user.getInventory(), true, true, itemStack))
+ {
+ throw new ChargeException(_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")));
+ }
+ InventoryWorkaround.removeItem(user.getInventory(), true, true, getItemStack());
+ user.updateInventory();
+ }
+ if (command != null && !command.isEmpty()
+ && !NoCommandCostPermissions.getPermission(command).isAuthorized(user))
+ {
+ @Cleanup
+ final ISettings settings = ess.getSettings();
+ settings.acquireReadLock();
+ final double cost = settings.getData().getEconomy().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command);
+ if (!user.canAfford(cost) && cost > 0)
+ {
+ throw new ChargeException(_("notEnoughMoney"));
+ }
+ user.takeMoney(cost);
+ }
+ if (getExperience() != null)
+ {
+ final int experience = SetExpFix.getTotalExperience(user);
+ if (experience < getExperience() && getExperience() > 0)
+ {
+ throw new ChargeException(_("notEnoughExperience"));
+ }
+ SetExpFix.setTotalExperience(user, experience - getExperience());
+ }
+ }
+
+ public Double getMoney()
+ {
+ return money;
+ }
+
+ public ItemStack getItemStack()
+ {
+ return itemStack;
+ }
+
+ public Integer getExperience()
+ {
+ return exp;
+ }
+
+ public Double getCommandCost(final IUser user)
+ {
+ double cost = 0d;
+ if (command != null && !command.isEmpty()
+ && !NoCommandCostPermissions.getPermission("all").isAuthorized(user)
+ && !NoCommandCostPermissions.getPermission(command).isAuthorized(user))
+ {
+ cost = ess.getSettings().getData().getEconomy().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command);
+ if (cost == 0.0 && fallbackCommand != null && !fallbackCommand.isEmpty())
+ {
+ cost = ess.getSettings().getData().getEconomy().getCommandCost(fallbackCommand.charAt(0) == '/' ? fallbackCommand.substring(1) : fallbackCommand);
+ }
+ }
+ return cost;
+ }
+ private static FileWriter fw = null;
+
+ public static void log(String type, String subtype, String event, String sender, Trade charge, String receiver, Trade pay, Location loc, IEssentials ess)
+ {
+ @Cleanup
+ final ISettings settings = ess.getSettings();
+ settings.acquireReadLock();
+ if (!settings.getData().getEconomy().isLogEnabled())
+ {
+ return;
+ }
+ if (fw == null)
+ {
+ try
+ {
+ fw = new FileWriter(new File(ess.getDataFolder(), "trade.log"), true);
+ }
+ catch (IOException ex)
+ {
+ Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
+ }
+ }
+ StringBuilder sb = new StringBuilder();
+ sb.append(type).append(",").append(subtype).append(",").append(event).append(",\"");
+ sb.append(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(new Date()));
+ sb.append("\",\"");
+ if (sender != null)
+ {
+ sb.append(sender);
+ }
+ sb.append("\",");
+ if (charge == null)
+ {
+ sb.append("\"\",\"\",\"\"");
+ }
+ else
+ {
+ if (charge.getItemStack() != null)
+ {
+ sb.append(charge.getItemStack().getAmount()).append(",");
+ sb.append(charge.getItemStack().getType().toString()).append(",");
+ sb.append(charge.getItemStack().getDurability());
+ }
+ if (charge.getMoney() != null)
+ {
+ sb.append(charge.getMoney()).append(",");
+ sb.append("money").append(",");
+ sb.append(settings.getData().getEconomy().getCurrencySymbol());
+ }
+ if (charge.getExperience() != null)
+ {
+ sb.append(charge.getExperience()).append(",");
+ sb.append("exp").append(",");
+ sb.append("\"\"");
+ }
+ }
+ sb.append(",\"");
+ if (receiver != null)
+ {
+ sb.append(receiver);
+ }
+ sb.append("\",");
+ if (pay == null)
+ {
+ sb.append("\"\",\"\",\"\"");
+ }
+ else
+ {
+ if (pay.getItemStack() != null)
+ {
+ sb.append(pay.getItemStack().getAmount()).append(",");
+ sb.append(pay.getItemStack().getType().toString()).append(",");
+ sb.append(pay.getItemStack().getDurability());
+ }
+ if (pay.getMoney() != null)
+ {
+ sb.append(pay.getMoney()).append(",");
+ sb.append("money").append(",");
+ sb.append(settings.getData().getEconomy().getCurrencySymbol());
+ }
+ if (pay.getExperience() != null)
+ {
+ sb.append(pay.getExperience()).append(",");
+ sb.append("exp").append(",");
+ sb.append("\"\"");
+ }
+ }
+ if (loc == null)
+ {
+ sb.append(",\"\",\"\",\"\",\"\"");
+ }
+ else
+ {
+ sb.append(",\"");
+ sb.append(loc.getWorld().getName()).append("\",");
+ sb.append(loc.getBlockX()).append(",");
+ sb.append(loc.getBlockY()).append(",");
+ sb.append(loc.getBlockZ()).append(",");
+ }
+ sb.append("\n");
+ try
+ {
+ fw.write(sb.toString());
+ fw.flush();
+ }
+ catch (IOException ex)
+ {
+ Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
+ }
+ }
+
+ public static void closeLog()
+ {
+ if (fw != null)
+ {
+ try
+ {
+ fw.close();
+ }
+ catch (IOException ex)
+ {
+ Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
+ }
+ fw = null;
+ }
+ }
+}
diff --git a/Essentials/src/net/ess3/economy/Worth.java b/Essentials/src/net/ess3/economy/Worth.java
new file mode 100644
index 000000000..91fa254b7
--- /dev/null
+++ b/Essentials/src/net/ess3/economy/Worth.java
@@ -0,0 +1,33 @@
+package net.ess3.economy;
+
+import net.ess3.storage.EnchantmentLevel;
+import net.ess3.storage.MapKeyType;
+import net.ess3.storage.MapValueType;
+import net.ess3.storage.StorageObject;
+import java.util.HashMap;
+import java.util.Map;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.bukkit.Material;
+import org.bukkit.material.MaterialData;
+
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class Worth implements StorageObject
+{
+ @MapKeyType(MaterialData.class)
+ @MapValueType(Double.class)
+ private Map<MaterialData, Double> sell = new HashMap<MaterialData, Double>();
+ @MapKeyType(MaterialData.class)
+ @MapValueType(Double.class)
+ private Map<MaterialData, Double> buy = new HashMap<MaterialData, Double>();
+ @MapKeyType(EnchantmentLevel.class)
+ @MapValueType(Double.class)
+ private Map<EnchantmentLevel, Double> enchantmentMultiplier = new HashMap<EnchantmentLevel, Double>();
+
+ public Worth()
+ {
+ sell.put(new MaterialData(Material.APPLE, (byte)0), 1.0);
+ }
+}
diff --git a/Essentials/src/net/ess3/economy/WorthHolder.java b/Essentials/src/net/ess3/economy/WorthHolder.java
new file mode 100644
index 000000000..59074c77f
--- /dev/null
+++ b/Essentials/src/net/ess3/economy/WorthHolder.java
@@ -0,0 +1,100 @@
+package net.ess3.economy;
+
+import net.ess3.api.IEssentials;
+import net.ess3.api.IWorth;
+import net.ess3.storage.AsyncStorageObjectHolder;
+import net.ess3.storage.EnchantmentLevel;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.material.MaterialData;
+
+
+public class WorthHolder extends AsyncStorageObjectHolder<net.ess3.economy.Worth> implements IWorth
+{
+
+ @Override
+ public void finishRead()
+ {
+
+ }
+
+ @Override
+ public void finishWrite()
+ {
+
+ }
+
+
+ public WorthHolder(final IEssentials ess)
+ {
+ super(ess, net.ess3.economy.Worth.class);
+ onReload(false);
+ }
+
+ @Override
+ public double getPrice(final ItemStack itemStack)
+ {
+ this.acquireReadLock();
+ try
+ {
+ final Map<MaterialData, Double> prices = this.getData().getSell();
+ if (prices == null || itemStack == null)
+ {
+ return Double.NaN;
+ }
+ final Double basePrice = prices.get(itemStack.getData());
+ if (basePrice == null || Double.isNaN(basePrice))
+ {
+ return Double.NaN;
+ }
+ double multiplier = 1.0;
+ if (itemStack.getType().getMaxDurability() > 0) {
+ multiplier *= (double)itemStack.getDurability() / (double)itemStack.getType().getMaxDurability();
+ }
+ if (itemStack.getEnchantments() != null && !itemStack.getEnchantments().isEmpty())
+ {
+ final Map<EnchantmentLevel, Double> enchantmentMultipliers = this.getData().getEnchantmentMultiplier();
+ if (enchantmentMultipliers != null)
+ {
+ for (Map.Entry<Enchantment, Integer> entry : itemStack.getEnchantments().entrySet())
+ {
+ final Double enchMult = enchantmentMultipliers.get(new EnchantmentLevel(entry.getKey(), entry.getValue()));
+ if (enchMult != null)
+ {
+ multiplier *= enchMult;
+ }
+ }
+ }
+ }
+ return basePrice * multiplier;
+ }
+ finally
+ {
+ this.unlock();
+ }
+ }
+
+ @Override
+ public void setPrice(final ItemStack itemStack, final double price)
+ {
+ acquireWriteLock();
+ try {
+ if (getData().getSell() == null) {
+ getData().setSell(new HashMap<MaterialData, Double>());
+ }
+ getData().getSell().put(itemStack.getData(), price);
+ } finally {
+ unlock();
+ }
+ }
+
+ @Override
+ public File getStorageFile() throws IOException
+ {
+ return new File(ess.getDataFolder(), "worth.yml");
+ }
+}
diff --git a/Essentials/src/net/ess3/economy/register/Method.java b/Essentials/src/net/ess3/economy/register/Method.java
new file mode 100644
index 000000000..c01e46476
--- /dev/null
+++ b/Essentials/src/net/ess3/economy/register/Method.java
@@ -0,0 +1,217 @@
+package net.ess3.economy.register;
+
+import org.bukkit.plugin.Plugin;
+
+
+/**
+ * Interface to be implemented by a payment method.
+ *
+ * @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
+ * @copyright Copyright (C) 2011
+ * @license AOL license <http://aol.nexua.org>
+ */
+public interface Method
+{
+ /**
+ * Encodes the Plugin into an Object disguised as the Plugin. If you want the original Plugin Class you must cast it
+ * to the correct Plugin, to do so you have to verify the name and or version then cast.
+ *
+ * <pre>
+ * if(method.getName().equalsIgnoreCase("iConomy"))
+ * iConomy plugin = ((iConomy)method.getPlugin());</pre>
+ *
+ * @return
+ * <code>Object</code>
+ * @see #getName()
+ * @see #getVersion()
+ */
+ public Object getPlugin();
+
+ /**
+ * Returns the actual name of this method.
+ *
+ * @return <code>String</code> Plugin name.
+ */
+ public String getName();
+
+ /**
+ * Returns the reported name of this method.
+ *
+ * @return <code>String</code> Plugin name.
+ */
+ public String getLongName();
+
+ /**
+ * Returns the actual version of this method.
+ *
+ * @return <code>String</code> Plugin version.
+ */
+ public String getVersion();
+
+ /**
+ * Returns the amount of decimal places that get stored
+ * NOTE: it will return -1 if there is no rounding
+ *
+ * @return <code>int</code> for each decimal place
+ */
+ public int fractionalDigits();
+
+ /**
+ * Formats amounts into this payment methods style of currency display.
+ *
+ * @param amount Double
+ * @return <code>String</code> - Formatted Currency Display.
+ */
+ public String format(double amount);
+
+ /**
+ * Allows the verification of bank API existence in this payment method.
+ *
+ * @return <code>boolean</code>
+ */
+ public boolean hasBanks();
+
+ /**
+ * Determines the existence of a bank via name.
+ *
+ * @param bank Bank name
+ * @return <code>boolean</code>
+ * @see #hasBanks
+ */
+ public boolean hasBank(String bank);
+
+ /**
+ * Determines the existence of an account via name.
+ *
+ * @param name Account name
+ * @return <code>boolean</code>
+ */
+ public boolean hasAccount(String name);
+
+ /**
+ * Check to see if an account <code>name</code> is tied to a <code>bank</code>.
+ *
+ * @param bank Bank name
+ * @param name Account name
+ * @return <code>boolean</code>
+ */
+ public boolean hasBankAccount(String bank, String name);
+
+ /**
+ * Forces an account creation
+ *
+ * @param name Account name
+ * @return <code>boolean</code>
+ */
+ public boolean createAccount(String name);
+
+ /**
+ * Forces an account creation
+ *
+ * @param name Account name
+ * @param balance Initial account balance
+ * @return <code>boolean</code>
+ */
+ public boolean createAccount(String name, Double balance);
+
+ /**
+ * Returns a <code>MethodAccount</code> class for an account <code>name</code>.
+ *
+ * @param name Account name
+ * @return <code>MethodAccount</code> <em>or</em> <code>Null</code>
+ */
+ public MethodAccount getAccount(String name);
+
+ /**
+ * Returns a <code>MethodBankAccount</code> class for an account <code>name</code>.
+ *
+ * @param bank Bank name
+ * @param name Account name
+ * @return <code>MethodBankAccount</code> <em>or</em> <code>Null</code>
+ */
+ public MethodBankAccount getBankAccount(String bank, String name);
+
+ /**
+ * Checks to verify the compatibility between this Method and a plugin.
+ * Internal usage only, for the most part.
+ *
+ * @param plugin Plugin
+ * @return <code>boolean</code>
+ */
+ public boolean isCompatible(Plugin plugin);
+
+ /**
+ * Set Plugin data.
+ *
+ * @param plugin Plugin
+ */
+ public void setPlugin(Plugin plugin);
+
+
+ /**
+ * Contains Calculator and Balance functions for Accounts.
+ */
+ public interface MethodAccount
+ {
+ public double balance();
+
+ public boolean set(double amount);
+
+ public boolean add(double amount);
+
+ public boolean subtract(double amount);
+
+ public boolean multiply(double amount);
+
+ public boolean divide(double amount);
+
+ public boolean hasEnough(double amount);
+
+ public boolean hasOver(double amount);
+
+ public boolean hasUnder(double amount);
+
+ public boolean isNegative();
+
+ public boolean remove();
+
+ @Override
+ public String toString();
+ }
+
+
+ /**
+ * Contains Calculator and Balance functions for Bank Accounts.
+ */
+ public interface MethodBankAccount
+ {
+ public double balance();
+
+ public String getBankName();
+
+ public int getBankId();
+
+ public boolean set(double amount);
+
+ public boolean add(double amount);
+
+ public boolean subtract(double amount);
+
+ public boolean multiply(double amount);
+
+ public boolean divide(double amount);
+
+ public boolean hasEnough(double amount);
+
+ public boolean hasOver(double amount);
+
+ public boolean hasUnder(double amount);
+
+ public boolean isNegative();
+
+ public boolean remove();
+
+ @Override
+ public String toString();
+ }
+}
diff --git a/Essentials/src/net/ess3/economy/register/Methods.java b/Essentials/src/net/ess3/economy/register/Methods.java
new file mode 100644
index 000000000..04208b4cb
--- /dev/null
+++ b/Essentials/src/net/ess3/economy/register/Methods.java
@@ -0,0 +1,296 @@
+package net.ess3.economy.register;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.PluginManager;
+
+
+/**
+ * The
+ * <code>Methods</code> initializes Methods that utilize the Method interface based on a "first come, first served"
+ * basis.
+ *
+ * Allowing you to check whether a payment method exists or not.
+ *
+ * Methods also allows you to set a preferred method of payment before it captures payment plugins in the initialization
+ * process.
+ *
+ * in
+ * <code>bukkit.yml</code>: <blockquote><pre>
+ * economy:
+ * preferred: "iConomy"
+ * </pre></blockquote>
+ *
+ * @author: Nijikokun <nijikokun@shortmail.com> (@nijikokun) @copyright: Copyright (C) 2011 @license: AOL license
+ * <http://aol.nexua.org>
+ */
+public class Methods
+{
+ private static String version = null;
+ private static boolean self = false;
+ private static Method Method = null;
+ private static String preferred = "";
+ private static Set<Method> Methods = new HashSet<Method>();
+ private static Set<String> Dependencies = new HashSet<String>();
+ private static Set<Method> Attachables = new HashSet<Method>();
+
+ static
+ {
+ _init();
+ }
+
+ /**
+ * Implement all methods along with their respective name & class.
+ */
+ private static void _init()
+ {
+ addMethod("iConomy", new net.ess3.economy.register.methods.iCo6());
+ addMethod("iConomy", new net.ess3.economy.register.methods.iCo5());
+ addMethod("iConomy", new net.ess3.economy.register.methods.iCo4());
+ addMethod("BOSEconomy", new net.ess3.economy.register.methods.BOSE6());
+ addMethod("BOSEconomy", new net.ess3.economy.register.methods.BOSE7());
+ addMethod("Currency", new net.ess3.economy.register.methods.MCUR());
+ Dependencies.add("MultiCurrency");
+ addMethod("Vault", new net.ess3.economy.register.methods.VaultEco());
+ }
+
+ /**
+ * Used by the plugin to setup version
+ *
+ * @param v version
+ */
+ public static void setVersion(String v)
+ {
+ version = v;
+ }
+
+ /**
+ * Use to reset methods during disable
+ */
+ public static void reset()
+ {
+ version = null;
+ self = false;
+ Method = null;
+ preferred = "";
+ Attachables.clear();
+ }
+
+ /**
+ * Use to get version of Register plugin
+ *
+ * @return version
+ */
+ public static String getVersion()
+ {
+ return version;
+ }
+
+ /**
+ * Returns an array of payment method names that have been loaded through the
+ * <code>_init</code> method.
+ *
+ * @return
+ * <code>Set<String></code> - Array of payment methods that are loaded.
+ * @see #setMethod(org.bukkit.plugin.Plugin)
+ */
+ public static Set<String> getDependencies()
+ {
+ return Dependencies;
+ }
+
+ /**
+ * Interprets Plugin class data to verify whether it is compatible with an existing payment method to use for
+ * payments and other various economic activity.
+ *
+ * @param plugin Plugin data from bukkit, Internal Class file.
+ * @return Method <em>or</em> Null
+ */
+ public static Method createMethod(Plugin plugin)
+ {
+ for (Method method : Methods)
+ {
+ if (method.isCompatible(plugin))
+ {
+ method.setPlugin(plugin);
+ return method;
+ }
+ }
+
+ return null;
+ }
+
+ private static void addMethod(String name, Method method)
+ {
+ Dependencies.add(name);
+ Methods.add(method);
+ }
+
+ /**
+ * Verifies if Register has set a payment method for usage yet.
+ *
+ * @return
+ * <code>boolean</code>
+ * @see #setMethod(org.bukkit.plugin.Plugin)
+ * @see #checkDisabled(org.bukkit.plugin.Plugin)
+ */
+ public static boolean hasMethod()
+ {
+ return (Method != null);
+ }
+
+ /**
+ * Checks Plugin Class against a multitude of checks to verify it's usability as a payment method.
+ *
+ * @param <code>PluginManager</code> the plugin manager for the server
+ * @return
+ * <code>boolean</code> True on success, False on failure.
+ */
+ public static boolean setMethod(PluginManager manager)
+ {
+ if (hasMethod())
+ {
+ return true;
+ }
+
+ if (self)
+ {
+ self = false;
+ return false;
+ }
+
+ int count = 0;
+ boolean match = false;
+ Plugin plugin = null;
+
+ for (String name : getDependencies())
+ {
+ if (hasMethod())
+ {
+ break;
+ }
+
+ plugin = manager.getPlugin(name);
+ if (plugin == null || !plugin.isEnabled())
+ {
+ continue;
+ }
+
+ Method current = createMethod(plugin);
+ if (current == null)
+ {
+ continue;
+ }
+
+ if (preferred.isEmpty())
+ {
+ Method = current;
+ }
+ else
+ {
+ Attachables.add(current);
+ }
+ }
+
+ if (!preferred.isEmpty())
+ {
+ do
+ {
+ if (hasMethod())
+ {
+ match = true;
+ }
+ else
+ {
+ for (Method attached : Attachables)
+ {
+ if (attached == null)
+ {
+ continue;
+ }
+
+ if (hasMethod())
+ {
+ match = true;
+ break;
+ }
+
+ if (preferred.isEmpty())
+ {
+ Method = attached;
+ }
+
+ if (count == 0)
+ {
+ if (preferred.equalsIgnoreCase(attached.getName()))
+ {
+ Method = attached;
+ }
+ else
+ {
+ Method = attached;
+ }
+ }
+ }
+
+ count++;
+ }
+ }
+ while (!match);
+ }
+
+ return hasMethod();
+ }
+
+ /**
+ * Sets the preferred economy
+ *
+ * @return
+ * <code>boolean</code>
+ */
+ public static boolean setPreferred(String check)
+ {
+ if (getDependencies().contains(check))
+ {
+ preferred = check;
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Grab the existing and initialized (hopefully) Method Class.
+ *
+ * @return
+ * <code>Method</code> <em>or</em>
+ * <code>Null</code>
+ */
+ public static Method getMethod()
+ {
+ return Method;
+ }
+
+ /**
+ * Verify is a plugin is disabled, only does this if we there is an existing payment method initialized in Register.
+ *
+ * @param method Plugin data from bukkit, Internal Class file.
+ * @return
+ * <code>boolean</code>
+ */
+ public static boolean checkDisabled(Plugin method)
+ {
+ if (!hasMethod())
+ {
+ return true;
+ }
+
+ if (Method.isCompatible(method))
+ {
+ Method = null;
+ }
+
+ return (Method == null);
+ }
+}
diff --git a/Essentials/src/net/ess3/economy/register/methods/BOSE6.java b/Essentials/src/net/ess3/economy/register/methods/BOSE6.java
new file mode 100644
index 000000000..200e8573c
--- /dev/null
+++ b/Essentials/src/net/ess3/economy/register/methods/BOSE6.java
@@ -0,0 +1,334 @@
+package net.ess3.economy.register.methods;
+
+import net.ess3.economy.register.Method;
+import cosine.boseconomy.BOSEconomy;
+import org.bukkit.plugin.Plugin;
+
+
+/**
+ * BOSEconomy 6 Implementation of Method
+ *
+ * @author Nijikokun <nijikokun@shortmail.com> (@nijikokun) @copyright (c) 2011 @license AOL license
+ * <http://aol.nexua.org>
+ */
+@SuppressWarnings("deprecation")
+public class BOSE6 implements Method
+{
+ private BOSEconomy BOSEconomy;
+
+ @Override
+ public BOSEconomy getPlugin()
+ {
+ return this.BOSEconomy;
+ }
+
+ @Override
+ public String getName()
+ {
+ return "BOSEconomy";
+ }
+
+ @Override
+ public String getLongName()
+ {
+ return getName();
+ }
+
+ @Override
+ public String getVersion()
+ {
+ return "0.6.2";
+ }
+
+ @Override
+ public int fractionalDigits()
+ {
+ return 0;
+ }
+
+ @Override
+ public String format(double amount)
+ {
+ String currency = this.BOSEconomy.getMoneyNamePlural();
+
+ if (amount == 1)
+ {
+ currency = this.BOSEconomy.getMoneyName();
+ }
+
+ return amount + " " + currency;
+ }
+
+ @Override
+ public boolean hasBanks()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean hasBank(String bank)
+ {
+ return this.BOSEconomy.bankExists(bank);
+ }
+
+ @Override
+ public boolean hasAccount(String name)
+ {
+ return this.BOSEconomy.playerRegistered(name, false);
+ }
+
+ @Override
+ public boolean hasBankAccount(String bank, String name)
+ {
+ return this.BOSEconomy.isBankOwner(bank, name)
+ || this.BOSEconomy.isBankMember(bank, name);
+ }
+
+ @Override
+ public boolean createAccount(String name)
+ {
+ if (hasAccount(name))
+ {
+ return false;
+ }
+
+ this.BOSEconomy.registerPlayer(name);
+ return true;
+ }
+
+ @Override
+ public boolean createAccount(String name, Double balance)
+ {
+ if (hasAccount(name))
+ {
+ return false;
+ }
+
+ this.BOSEconomy.registerPlayer(name);
+ this.BOSEconomy.setPlayerMoney(name, balance, false);
+ return true;
+ }
+
+ @Override
+ public MethodAccount getAccount(String name)
+ {
+ if (!hasAccount(name))
+ {
+ return null;
+ }
+
+ return new BOSEAccount(name, this.BOSEconomy);
+ }
+
+ @Override
+ public MethodBankAccount getBankAccount(String bank, String name)
+ {
+ if (!hasBankAccount(bank, name))
+ {
+ return null;
+ }
+
+ return new BOSEBankAccount(bank, BOSEconomy);
+ }
+
+ @Override
+ public boolean isCompatible(Plugin plugin)
+ {
+ return plugin.getDescription().getName().equalsIgnoreCase("boseconomy")
+ && plugin instanceof BOSEconomy
+ && plugin.getDescription().getVersion().equals("0.6.2");
+ }
+
+ @Override
+ public void setPlugin(Plugin plugin)
+ {
+ BOSEconomy = (BOSEconomy)plugin;
+ }
+
+
+ public class BOSEAccount implements MethodAccount
+ {
+ private final String name;
+ private final BOSEconomy BOSEconomy;
+
+ public BOSEAccount(String name, BOSEconomy bOSEconomy)
+ {
+ this.name = name;
+ this.BOSEconomy = bOSEconomy;
+ }
+
+ @Override
+ public double balance()
+ {
+ return (double)this.BOSEconomy.getPlayerMoney(this.name);
+ }
+
+ @Override
+ public boolean set(double amount)
+ {
+ int IntAmount = (int)Math.ceil(amount);
+ return this.BOSEconomy.setPlayerMoney(this.name, IntAmount, false);
+ }
+
+ @Override
+ public boolean add(double amount)
+ {
+ int IntAmount = (int)Math.ceil(amount);
+ return this.BOSEconomy.addPlayerMoney(this.name, IntAmount, false);
+ }
+
+ @Override
+ public boolean subtract(double amount)
+ {
+ int IntAmount = (int)Math.ceil(amount);
+ int balance = (int)this.balance();
+ return this.BOSEconomy.setPlayerMoney(this.name, (balance - IntAmount), false);
+ }
+
+ @Override
+ public boolean multiply(double amount)
+ {
+ int IntAmount = (int)Math.ceil(amount);
+ int balance = (int)this.balance();
+ return this.BOSEconomy.setPlayerMoney(this.name, (balance * IntAmount), false);
+ }
+
+ @Override
+ public boolean divide(double amount)
+ {
+ int IntAmount = (int)Math.ceil(amount);
+ int balance = (int)this.balance();
+ return this.BOSEconomy.setPlayerMoney(this.name, (balance / IntAmount), false);
+ }
+
+ @Override
+ public boolean hasEnough(double amount)
+ {
+ return (this.balance() >= amount);
+ }
+
+ @Override
+ public boolean hasOver(double amount)
+ {
+ return (this.balance() > amount);
+ }
+
+ @Override
+ public boolean hasUnder(double amount)
+ {
+ return (this.balance() < amount);
+ }
+
+ @Override
+ public boolean isNegative()
+ {
+ return (this.balance() < 0);
+ }
+
+ @Override
+ public boolean remove()
+ {
+ return false;
+ }
+ }
+
+
+ public class BOSEBankAccount implements MethodBankAccount
+ {
+ private final String bank;
+ private final BOSEconomy BOSEconomy;
+
+ public BOSEBankAccount(String bank, BOSEconomy bOSEconomy)
+ {
+ this.bank = bank;
+ this.BOSEconomy = bOSEconomy;
+ }
+
+ @Override
+ public String getBankName()
+ {
+ return this.bank;
+ }
+
+ @Override
+ public int getBankId()
+ {
+ return -1;
+ }
+
+ @Override
+ public double balance()
+ {
+ return (double)this.BOSEconomy.getBankMoney(bank);
+ }
+
+ @Override
+ public boolean set(double amount)
+ {
+ int IntAmount = (int)Math.ceil(amount);
+ return this.BOSEconomy.setBankMoney(bank, IntAmount, true);
+ }
+
+ @Override
+ public boolean add(double amount)
+ {
+ int IntAmount = (int)Math.ceil(amount);
+ int balance = (int)this.balance();
+ return this.BOSEconomy.setBankMoney(bank, (balance + IntAmount), false);
+ }
+
+ @Override
+ public boolean subtract(double amount)
+ {
+ int IntAmount = (int)Math.ceil(amount);
+ int balance = (int)this.balance();
+ return this.BOSEconomy.setBankMoney(bank, (balance - IntAmount), false);
+ }
+
+ @Override
+ public boolean multiply(double amount)
+ {
+ int IntAmount = (int)Math.ceil(amount);
+ int balance = (int)this.balance();
+ return this.BOSEconomy.setBankMoney(bank, (balance * IntAmount), false);
+ }
+
+ @Override
+ public boolean divide(double amount)
+ {
+ int IntAmount = (int)Math.ceil(amount);
+ int balance = (int)this.balance();
+ return this.BOSEconomy.setBankMoney(bank, (balance / IntAmount), false);
+ }
+
+ @Override
+ public boolean hasEnough(double amount)
+ {
+ return (this.balance() >= amount);
+ }
+
+ @Override
+ public boolean hasOver(double amount)
+ {
+ return (this.balance() > amount);
+ }
+
+ @Override
+ public boolean hasUnder(double amount)
+ {
+ return (this.balance() < amount);
+ }
+
+ @Override
+ public boolean isNegative()
+ {
+ return (this.balance() < 0);
+ }
+
+ @Override
+ public boolean remove()
+ {
+ return this.BOSEconomy.removeBank(bank);
+ }
+ }
+} \ No newline at end of file
diff --git a/Essentials/src/net/ess3/economy/register/methods/BOSE7.java b/Essentials/src/net/ess3/economy/register/methods/BOSE7.java
new file mode 100644
index 000000000..f9092c350
--- /dev/null
+++ b/Essentials/src/net/ess3/economy/register/methods/BOSE7.java
@@ -0,0 +1,323 @@
+package net.ess3.economy.register.methods;
+
+import net.ess3.economy.register.Method;
+import cosine.boseconomy.BOSEconomy;
+import org.bukkit.plugin.Plugin;
+
+
+/**
+ * BOSEconomy 7 Implementation of Method
+ *
+ * @author Acrobot
+ * @author Nijikokun <nijikokun@shortmail.com> (@nijikokun) @copyright (c) 2011 @license AOL license
+ * <http://aol.nexua.org>
+ */
+public class BOSE7 implements Method
+{
+ private BOSEconomy BOSEconomy;
+
+ @Override
+ public BOSEconomy getPlugin()
+ {
+ return this.BOSEconomy;
+ }
+
+ @Override
+ public String getName()
+ {
+ return "BOSEconomy";
+ }
+
+ @Override
+ public String getLongName()
+ {
+ return getName();
+ }
+
+ @Override
+ public String getVersion()
+ {
+ return "0.7.0";
+ }
+
+ @Override
+ public int fractionalDigits()
+ {
+ return this.BOSEconomy.getFractionalDigits();
+ }
+
+ @Override
+ public String format(double amount)
+ {
+ String currency = this.BOSEconomy.getMoneyNamePlural();
+
+ if (amount == 1)
+ {
+ currency = this.BOSEconomy.getMoneyName();
+ }
+
+ return amount + " " + currency;
+ }
+
+ @Override
+ public boolean hasBanks()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean hasBank(String bank)
+ {
+ return this.BOSEconomy.bankExists(bank);
+ }
+
+ @Override
+ public boolean hasAccount(String name)
+ {
+ return this.BOSEconomy.playerRegistered(name, false);
+ }
+
+ @Override
+ public boolean hasBankAccount(String bank, String name)
+ {
+ return this.BOSEconomy.isBankOwner(bank, name) || this.BOSEconomy.isBankMember(bank, name);
+ }
+
+ @Override
+ public boolean createAccount(String name)
+ {
+ if (hasAccount(name))
+ {
+ return false;
+ }
+
+ this.BOSEconomy.registerPlayer(name);
+ return true;
+ }
+
+ @Override
+ public boolean createAccount(String name, Double balance)
+ {
+ if (hasAccount(name))
+ {
+ return false;
+ }
+
+ this.BOSEconomy.registerPlayer(name);
+ this.BOSEconomy.setPlayerMoney(name, balance, false);
+ return true;
+ }
+
+ @Override
+ public MethodAccount getAccount(String name)
+ {
+ if (!hasAccount(name))
+ {
+ return null;
+ }
+
+ return new BOSEAccount(name, this.BOSEconomy);
+ }
+
+ @Override
+ public MethodBankAccount getBankAccount(String bank, String name)
+ {
+ if (!hasBankAccount(bank, name))
+ {
+ return null;
+ }
+
+ return new BOSEBankAccount(bank, BOSEconomy);
+ }
+
+ @Override
+ public boolean isCompatible(Plugin plugin)
+ {
+ return plugin.getDescription().getName().equalsIgnoreCase("boseconomy")
+ && plugin instanceof BOSEconomy
+ && !plugin.getDescription().getVersion().equals("0.6.2");
+ }
+
+ @Override
+ public void setPlugin(Plugin plugin)
+ {
+ BOSEconomy = (BOSEconomy)plugin;
+ }
+
+
+ public class BOSEAccount implements MethodAccount
+ {
+ private String name;
+ private BOSEconomy BOSEconomy;
+
+ public BOSEAccount(String name, BOSEconomy bOSEconomy)
+ {
+ this.name = name;
+ this.BOSEconomy = bOSEconomy;
+ }
+
+ @Override
+ public double balance()
+ {
+ return this.BOSEconomy.getPlayerMoneyDouble(this.name);
+ }
+
+ @Override
+ public boolean set(double amount)
+ {
+ return this.BOSEconomy.setPlayerMoney(this.name, amount, false);
+ }
+
+ @Override
+ public boolean add(double amount)
+ {
+ return this.BOSEconomy.addPlayerMoney(this.name, amount, false);
+ }
+
+ @Override
+ public boolean subtract(double amount)
+ {
+ double balance = this.balance();
+ return this.BOSEconomy.setPlayerMoney(this.name, (balance - amount), false);
+ }
+
+ @Override
+ public boolean multiply(double amount)
+ {
+ double balance = this.balance();
+ return this.BOSEconomy.setPlayerMoney(this.name, (balance * amount), false);
+ }
+
+ @Override
+ public boolean divide(double amount)
+ {
+ double balance = this.balance();
+ return this.BOSEconomy.setPlayerMoney(this.name, (balance / amount), false);
+ }
+
+ @Override
+ public boolean hasEnough(double amount)
+ {
+ return (this.balance() >= amount);
+ }
+
+ @Override
+ public boolean hasOver(double amount)
+ {
+ return (this.balance() > amount);
+ }
+
+ @Override
+ public boolean hasUnder(double amount)
+ {
+ return (this.balance() < amount);
+ }
+
+ @Override
+ public boolean isNegative()
+ {
+ return (this.balance() < 0);
+ }
+
+ @Override
+ public boolean remove()
+ {
+ return false;
+ }
+ }
+
+
+ public class BOSEBankAccount implements MethodBankAccount
+ {
+ private String bank;
+ private BOSEconomy BOSEconomy;
+
+ public BOSEBankAccount(String bank, BOSEconomy bOSEconomy)
+ {
+ this.bank = bank;
+ this.BOSEconomy = bOSEconomy;
+ }
+
+ @Override
+ public String getBankName()
+ {
+ return this.bank;
+ }
+
+ @Override
+ public int getBankId()
+ {
+ return -1;
+ }
+
+ @Override
+ public double balance()
+ {
+ return this.BOSEconomy.getBankMoneyDouble(bank);
+ }
+
+ @Override
+ public boolean set(double amount)
+ {
+ return this.BOSEconomy.setBankMoney(bank, amount, true);
+ }
+
+ @Override
+ public boolean add(double amount)
+ {
+ double balance = this.balance();
+ return this.BOSEconomy.setBankMoney(bank, (balance + amount), false);
+ }
+
+ @Override
+ public boolean subtract(double amount)
+ {
+ double balance = this.balance();
+ return this.BOSEconomy.setBankMoney(bank, (balance - amount), false);
+ }
+
+ @Override
+ public boolean multiply(double amount)
+ {
+ double balance = this.balance();
+ return this.BOSEconomy.setBankMoney(bank, (balance * amount), false);
+ }
+
+ @Override
+ public boolean divide(double amount)
+ {
+ double balance = this.balance();
+ return this.BOSEconomy.setBankMoney(bank, (balance / amount), false);
+ }
+
+ @Override
+ public boolean hasEnough(double amount)
+ {
+ return (this.balance() >= amount);
+ }
+
+ @Override
+ public boolean hasOver(double amount)
+ {
+ return (this.balance() > amount);
+ }
+
+ @Override
+ public boolean hasUnder(double amount)
+ {
+ return (this.balance() < amount);
+ }
+
+ @Override
+ public boolean isNegative()
+ {
+ return (this.balance() < 0);
+ }
+
+ @Override
+ public boolean remove()
+ {
+ return this.BOSEconomy.removeBank(bank);
+ }
+ }
+} \ No newline at end of file
diff --git a/Essentials/src/net/ess3/economy/register/methods/MCUR.java b/Essentials/src/net/ess3/economy/register/methods/MCUR.java
new file mode 100644
index 000000000..77fed351b
--- /dev/null
+++ b/Essentials/src/net/ess3/economy/register/methods/MCUR.java
@@ -0,0 +1,195 @@
+package net.ess3.economy.register.methods;
+
+import net.ess3.economy.register.Method;
+import me.ashtheking.currency.Currency;
+import me.ashtheking.currency.CurrencyList;
+import org.bukkit.plugin.Plugin;
+
+
+/**
+ * MultiCurrency Method implementation.
+ *
+ * @author Acrobot @copyright (c) 2011 @license AOL license <http://aol.nexua.org>
+ */
+public class MCUR implements Method
+{
+ private Currency currencyList;
+
+ @Override
+ public Object getPlugin()
+ {
+ return this.currencyList;
+ }
+
+ @Override
+ public String getName()
+ {
+ return "MultiCurrency";
+ }
+
+ @Override
+ public String getLongName()
+ {
+ return getName();
+ }
+
+ @Override
+ public String getVersion()
+ {
+ return "0.09";
+ }
+
+ @Override
+ public int fractionalDigits()
+ {
+ return -1;
+ }
+
+ @Override
+ public String format(double amount)
+ {
+ return amount + " Currency";
+ }
+
+ @Override
+ public boolean hasBanks()
+ {
+ return false;
+ }
+
+ @Override
+ public boolean hasBank(String bank)
+ {
+ return false;
+ }
+
+ @Override
+ public boolean hasAccount(String name)
+ {
+ return true;
+ }
+
+ @Override
+ public boolean hasBankAccount(String bank, String name)
+ {
+ return false;
+ }
+
+ @Override
+ public boolean createAccount(String name)
+ {
+ CurrencyList.setValue((String)CurrencyList.maxCurrency(name)[0], name, 0);
+ return true;
+ }
+
+ @Override
+ public boolean createAccount(String name, Double balance)
+ {
+ CurrencyList.setValue((String)CurrencyList.maxCurrency(name)[0], name, balance);
+ return true;
+ }
+
+ @Override
+ public MethodAccount getAccount(String name)
+ {
+ return new MCurrencyAccount(name);
+ }
+
+ @Override
+ public MethodBankAccount getBankAccount(String bank, String name)
+ {
+ return null;
+ }
+
+ @Override
+ public boolean isCompatible(Plugin plugin)
+ {
+ return (plugin.getDescription().getName().equalsIgnoreCase("Currency")
+ || plugin.getDescription().getName().equalsIgnoreCase("MultiCurrency"))
+ && plugin instanceof Currency;
+ }
+
+ @Override
+ public void setPlugin(Plugin plugin)
+ {
+ currencyList = (Currency)plugin;
+ }
+
+
+ public class MCurrencyAccount implements MethodAccount
+ {
+ private String name;
+
+ public MCurrencyAccount(String name)
+ {
+ this.name = name;
+ }
+
+ @Override
+ public double balance()
+ {
+ return CurrencyList.getValue((String)CurrencyList.maxCurrency(name)[0], name);
+ }
+
+ @Override
+ public boolean set(double amount)
+ {
+ CurrencyList.setValue((String)CurrencyList.maxCurrency(name)[0], name, amount);
+ return true;
+ }
+
+ @Override
+ public boolean add(double amount)
+ {
+ return CurrencyList.add(name, amount);
+ }
+
+ @Override
+ public boolean subtract(double amount)
+ {
+ return CurrencyList.subtract(name, amount);
+ }
+
+ @Override
+ public boolean multiply(double amount)
+ {
+ return CurrencyList.multiply(name, amount);
+ }
+
+ @Override
+ public boolean divide(double amount)
+ {
+ return CurrencyList.divide(name, amount);
+ }
+
+ @Override
+ public boolean hasEnough(double amount)
+ {
+ return CurrencyList.hasEnough(name, amount);
+ }
+
+ @Override
+ public boolean hasOver(double amount)
+ {
+ return CurrencyList.hasOver(name, amount);
+ }
+
+ @Override
+ public boolean hasUnder(double amount)
+ {
+ return CurrencyList.hasUnder(name, amount);
+ }
+
+ @Override
+ public boolean isNegative()
+ {
+ return CurrencyList.isNegative(name);
+ }
+
+ @Override
+ public boolean remove()
+ {
+ return CurrencyList.remove(name);
+ }
+ }
+}
diff --git a/Essentials/src/net/ess3/economy/register/methods/VaultEco.java b/Essentials/src/net/ess3/economy/register/methods/VaultEco.java
new file mode 100644
index 000000000..5281c5b2f
--- /dev/null
+++ b/Essentials/src/net/ess3/economy/register/methods/VaultEco.java
@@ -0,0 +1,347 @@
+package net.ess3.economy.register.methods;
+
+import net.ess3.economy.register.Method;
+import net.milkbowl.vault.Vault;
+import net.milkbowl.vault.economy.Economy;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.RegisteredServiceProvider;
+
+
+public class VaultEco implements Method
+{
+ private Vault vault;
+ private Economy economy;
+
+ @Override
+ public Vault getPlugin()
+ {
+ return this.vault;
+ }
+
+ @Override
+ public boolean createAccount(String name, Double amount)
+ {
+ if (hasAccount(name))
+ {
+ return false;
+ }
+
+ return false;
+ }
+
+ @Override
+ public String getName()
+ {
+ return this.vault.getDescription().getName();
+ }
+
+ public String getEconomy()
+ {
+ return economy == null ? "NoEco" : economy.getName();
+ }
+
+ @Override
+ public String getLongName()
+ {
+ return getName().concat(" - Economy: ").concat(getEconomy());
+ }
+
+ @Override
+ public String getVersion()
+ {
+ return this.vault.getDescription().getVersion();
+ }
+
+ @Override
+ public int fractionalDigits()
+ {
+ return 0;
+ }
+
+ @Override
+ public String format(double amount)
+ {
+ return this.economy.format(amount);
+ }
+
+ @Override
+ public boolean hasBanks()
+ {
+ return this.economy.hasBankSupport();
+ }
+
+ @Override
+ public boolean hasBank(String bank)
+ {
+ return this.economy.getBanks().contains(bank);
+ }
+
+ @Override
+ public boolean hasAccount(String name)
+ {
+ return this.economy.hasAccount(name);
+ }
+
+ @Override
+ public boolean hasBankAccount(String bank, String name)
+ {
+ return this.economy.isBankOwner(bank, name).transactionSuccess()
+ || this.economy.isBankMember(bank, name).transactionSuccess();
+ }
+
+ @Override
+ public boolean createAccount(String name)
+ {
+ return this.economy.createBank(name, "").transactionSuccess();
+ }
+
+ public boolean createAccount(String name, double balance)
+ {
+ if (!this.economy.createBank(name, "").transactionSuccess())
+ {
+ return false;
+ }
+ return this.economy.bankDeposit(name, balance).transactionSuccess();
+ }
+
+ @Override
+ public MethodAccount getAccount(String name)
+ {
+ if (!hasAccount(name))
+ {
+ return null;
+ }
+
+ return new VaultAccount(name, this.economy);
+ }
+
+ @Override
+ public MethodBankAccount getBankAccount(String bank, String name)
+ {
+ if (!hasBankAccount(bank, name))
+ {
+ return null;
+ }
+
+ return new VaultBankAccount(bank, economy);
+ }
+
+ @Override
+ public boolean isCompatible(Plugin plugin)
+ {
+ try
+ {
+ RegisteredServiceProvider<Economy> ecoPlugin = plugin.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
+ return plugin instanceof Vault && ecoPlugin != null && !ecoPlugin.getProvider().getName().equals("Essentials Economy");
+ }
+ catch (LinkageError e)
+ {
+ return false;
+ }
+ catch (Exception e)
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public void setPlugin(Plugin plugin)
+ {
+ this.vault = (Vault)plugin;
+ RegisteredServiceProvider<Economy> economyProvider = this.vault.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.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;
+ }
+
+ @Override
+ public double balance()
+ {
+ return this.economy.getBalance(this.name);
+ }
+
+ @Override
+ 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();
+ }
+
+ @Override
+ public boolean add(double amount)
+ {
+ return this.economy.depositPlayer(this.name, amount).transactionSuccess();
+ }
+
+ @Override
+ public boolean subtract(double amount)
+ {
+ return this.economy.withdrawPlayer(this.name, amount).transactionSuccess();
+ }
+
+ @Override
+ public boolean multiply(double amount)
+ {
+ double balance = this.balance();
+ return this.set(balance * amount);
+ }
+
+ @Override
+ public boolean divide(double amount)
+ {
+ double balance = this.balance();
+ return this.set(balance / amount);
+ }
+
+ @Override
+ public boolean hasEnough(double amount)
+ {
+ return (this.balance() >= amount);
+ }
+
+ @Override
+ public boolean hasOver(double amount)
+ {
+ return (this.balance() > amount);
+ }
+
+ @Override
+ public boolean hasUnder(double amount)
+ {
+ return (this.balance() < amount);
+ }
+
+ @Override
+ public boolean isNegative()
+ {
+ return (this.balance() < 0);
+ }
+
+ @Override
+ 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;
+ }
+
+ @Override
+ public String getBankName()
+ {
+ return this.bank;
+ }
+
+ @Override
+ public int getBankId()
+ {
+ return -1;
+ }
+
+ @Override
+ public double balance()
+ {
+ return this.economy.bankBalance(this.bank).balance;
+ }
+
+ @Override
+ 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();
+ }
+
+ @Override
+ public boolean add(double amount)
+ {
+ return this.economy.bankDeposit(this.bank, amount).transactionSuccess();
+ }
+
+ @Override
+ public boolean subtract(double amount)
+ {
+ return this.economy.bankWithdraw(this.bank, amount).transactionSuccess();
+ }
+
+ @Override
+ public boolean multiply(double amount)
+ {
+ double balance = this.balance();
+ return this.set(balance * amount);
+ }
+
+ @Override
+ public boolean divide(double amount)
+ {
+ double balance = this.balance();
+ return this.set(balance / amount);
+ }
+
+ @Override
+ public boolean hasEnough(double amount)
+ {
+ return (this.balance() >= amount);
+ }
+
+ @Override
+ public boolean hasOver(double amount)
+ {
+ return (this.balance() > amount);
+ }
+
+ @Override
+ public boolean hasUnder(double amount)
+ {
+ return (this.balance() < amount);
+ }
+
+ @Override
+ public boolean isNegative()
+ {
+ return (this.balance() < 0);
+ }
+
+ @Override
+ public boolean remove()
+ {
+ return this.set(0.0);
+ }
+ }
+} \ No newline at end of file
diff --git a/Essentials/src/net/ess3/economy/register/methods/iCo4.java b/Essentials/src/net/ess3/economy/register/methods/iCo4.java
new file mode 100644
index 000000000..3972b2432
--- /dev/null
+++ b/Essentials/src/net/ess3/economy/register/methods/iCo4.java
@@ -0,0 +1,256 @@
+package net.ess3.economy.register.methods;
+
+import net.ess3.economy.register.Method;
+import com.nijiko.coelho.iConomy.iConomy;
+import com.nijiko.coelho.iConomy.system.Account;
+import org.bukkit.plugin.Plugin;
+
+
+/**
+ * iConomy 4 Implementation of Method
+ *
+ * @author Nijikokun <nijikokun@shortmail.com> (@nijikokun) @copyright (c) 2011 @license AOL license
+ * <http://aol.nexua.org>
+ */
+public class iCo4 implements Method
+{
+ private iConomy iConomy;
+
+ @Override
+ public iConomy getPlugin()
+ {
+ return this.iConomy;
+ }
+
+ @Override
+ public String getName()
+ {
+ return "iConomy";
+ }
+
+ @Override
+ public String getLongName()
+ {
+ return getName();
+ }
+
+ @Override
+ public String getVersion()
+ {
+ return "4";
+ }
+
+ @Override
+ public int fractionalDigits()
+ {
+ return 2;
+ }
+
+ @Override
+ public String format(double amount)
+ {
+ return com.nijiko.coelho.iConomy.iConomy.getBank().format(amount);
+ }
+
+ @Override
+ public boolean hasBanks()
+ {
+ return false;
+ }
+
+ @Override
+ public boolean hasBank(String bank)
+ {
+ return false;
+ }
+
+ @Override
+ public boolean hasAccount(String name)
+ {
+ return com.nijiko.coelho.iConomy.iConomy.getBank().hasAccount(name);
+ }
+
+ @Override
+ public boolean hasBankAccount(String bank, String name)
+ {
+ return false;
+ }
+
+ @Override
+ public boolean createAccount(String name)
+ {
+ if (hasAccount(name))
+ {
+ return false;
+ }
+
+ try
+ {
+ com.nijiko.coelho.iConomy.iConomy.getBank().addAccount(name);
+ }
+ catch (Exception E)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean createAccount(String name, Double balance)
+ {
+ if (hasAccount(name))
+ {
+ return false;
+ }
+
+ try
+ {
+ com.nijiko.coelho.iConomy.iConomy.getBank().addAccount(name, balance);
+ }
+ catch (Exception E)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public MethodAccount getAccount(String name)
+ {
+ return new iCoAccount(com.nijiko.coelho.iConomy.iConomy.getBank().getAccount(name));
+ }
+
+ @Override
+ public MethodBankAccount getBankAccount(String bank, String name)
+ {
+ return null;
+ }
+
+ @Override
+ public boolean isCompatible(Plugin plugin)
+ {
+ return plugin.getDescription().getName().equalsIgnoreCase("iconomy")
+ && plugin.getClass().getName().equals("com.nijiko.coelho.iConomy.iConomy")
+ && plugin instanceof iConomy;
+ }
+
+ @Override
+ public void setPlugin(Plugin plugin)
+ {
+ iConomy = (iConomy)plugin;
+ }
+
+
+ public class iCoAccount implements MethodAccount
+ {
+ private Account account;
+
+ public iCoAccount(Account account)
+ {
+ this.account = account;
+ }
+
+ public Account getiCoAccount()
+ {
+ return account;
+ }
+
+ @Override
+ public double balance()
+ {
+ return this.account.getBalance();
+ }
+
+ @Override
+ public boolean set(double amount)
+ {
+ if (this.account == null)
+ {
+ return false;
+ }
+ this.account.setBalance(amount);
+ return true;
+ }
+
+ @Override
+ public boolean add(double amount)
+ {
+ if (this.account == null)
+ {
+ return false;
+ }
+ this.account.add(amount);
+ return true;
+ }
+
+ @Override
+ public boolean subtract(double amount)
+ {
+ if (this.account == null)
+ {
+ return false;
+ }
+ this.account.subtract(amount);
+ return true;
+ }
+
+ @Override
+ public boolean multiply(double amount)
+ {
+ if (this.account == null)
+ {
+ return false;
+ }
+ this.account.multiply(amount);
+ return true;
+ }
+
+ @Override
+ public boolean divide(double amount)
+ {
+ if (this.account == null)
+ {
+ return false;
+ }
+ this.account.divide(amount);
+ return true;
+ }
+
+ @Override
+ public boolean hasEnough(double amount)
+ {
+ return this.account.hasEnough(amount);
+ }
+
+ @Override
+ public boolean hasOver(double amount)
+ {
+ return this.account.hasOver(amount);
+ }
+
+ @Override
+ public boolean hasUnder(double amount)
+ {
+ return (this.balance() < amount);
+ }
+
+ @Override
+ public boolean isNegative()
+ {
+ return this.account.isNegative();
+ }
+
+ @Override
+ public boolean remove()
+ {
+ if (this.account == null)
+ {
+ return false;
+ }
+ this.account.remove();
+ return true;
+ }
+ }
+}
diff --git a/Essentials/src/net/ess3/economy/register/methods/iCo5.java b/Essentials/src/net/ess3/economy/register/methods/iCo5.java
new file mode 100644
index 000000000..171abfc7c
--- /dev/null
+++ b/Essentials/src/net/ess3/economy/register/methods/iCo5.java
@@ -0,0 +1,376 @@
+package net.ess3.economy.register.methods;
+
+import net.ess3.economy.register.Method;
+import com.iConomy.iConomy;
+import com.iConomy.system.Account;
+import com.iConomy.system.BankAccount;
+import com.iConomy.system.Holdings;
+import com.iConomy.util.Constants;
+import org.bukkit.plugin.Plugin;
+
+
+/**
+ * iConomy 5 Implementation of Method
+ *
+ * @author Nijikokun <nijikokun@shortmail.com> (@nijikokun) @copyright (c) 2011 @license AOL license
+ * <http://aol.nexua.org>
+ */
+public class iCo5 implements Method
+{
+ private iConomy iConomy;
+
+ @Override
+ public iConomy getPlugin()
+ {
+ return this.iConomy;
+ }
+
+ @Override
+ public String getName()
+ {
+ return "iConomy";
+ }
+
+ @Override
+ public String getLongName()
+ {
+ return getName();
+ }
+
+ @Override
+ public String getVersion()
+ {
+ return "5";
+ }
+
+ @Override
+ public int fractionalDigits()
+ {
+ return 2;
+ }
+
+ @Override
+ public String format(double amount)
+ {
+ return com.iConomy.iConomy.format(amount);
+ }
+
+ @Override
+ public boolean hasBanks()
+ {
+ return Constants.Banking;
+ }
+
+ @Override
+ public boolean hasBank(String bank)
+ {
+ return (hasBanks()) && com.iConomy.iConomy.Banks.exists(bank);
+ }
+
+ @Override
+ public boolean hasAccount(String name)
+ {
+ return com.iConomy.iConomy.hasAccount(name);
+ }
+
+ @Override
+ public boolean hasBankAccount(String bank, String name)
+ {
+ return (hasBank(bank)) && com.iConomy.iConomy.getBank(bank).hasAccount(name);
+ }
+
+ @Override
+ public boolean createAccount(String name)
+ {
+ if (hasAccount(name))
+ {
+ return false;
+ }
+
+ return com.iConomy.iConomy.Accounts.create(name);
+ }
+
+ @Override
+ public boolean createAccount(String name, Double balance)
+ {
+ if (hasAccount(name))
+ {
+ return false;
+ }
+
+ if (!com.iConomy.iConomy.Accounts.create(name))
+ {
+ return false;
+ }
+
+ getAccount(name).set(balance);
+
+ return true;
+ }
+
+ @Override
+ public MethodAccount getAccount(String name)
+ {
+ return new iCoAccount(com.iConomy.iConomy.getAccount(name));
+ }
+
+ @Override
+ public MethodBankAccount getBankAccount(String bank, String name)
+ {
+ return new iCoBankAccount(com.iConomy.iConomy.getBank(bank).getAccount(name));
+ }
+
+ @Override
+ public boolean isCompatible(Plugin plugin)
+ {
+ return plugin.getDescription().getName().equalsIgnoreCase("iconomy")
+ && plugin.getClass().getName().equals("com.iConomy.iConomy")
+ && plugin instanceof iConomy;
+ }
+
+ @Override
+ public void setPlugin(Plugin plugin)
+ {
+ iConomy = (iConomy)plugin;
+ }
+
+
+ public class iCoAccount implements MethodAccount
+ {
+ private Account account;
+ private Holdings holdings;
+
+ public iCoAccount(Account account)
+ {
+ this.account = account;
+ this.holdings = account.getHoldings();
+ }
+
+ public Account getiCoAccount()
+ {
+ return account;
+ }
+
+ @Override
+ public double balance()
+ {
+ return this.holdings.balance();
+ }
+
+ @Override
+ public boolean set(double amount)
+ {
+ if (this.holdings == null)
+ {
+ return false;
+ }
+ this.holdings.set(amount);
+ return true;
+ }
+
+ @Override
+ public boolean add(double amount)
+ {
+ if (this.holdings == null)
+ {
+ return false;
+ }
+ this.holdings.add(amount);
+ return true;
+ }
+
+ @Override
+ public boolean subtract(double amount)
+ {
+ if (this.holdings == null)
+ {
+ return false;
+ }
+ this.holdings.subtract(amount);
+ return true;
+ }
+
+ @Override
+ public boolean multiply(double amount)
+ {
+ if (this.holdings == null)
+ {
+ return false;
+ }
+ this.holdings.multiply(amount);
+ return true;
+ }
+
+ @Override
+ public boolean divide(double amount)
+ {
+ if (this.holdings == null)
+ {
+ return false;
+ }
+ this.holdings.divide(amount);
+ return true;
+ }
+
+ @Override
+ public boolean hasEnough(double amount)
+ {
+ return this.holdings.hasEnough(amount);
+ }
+
+ @Override
+ public boolean hasOver(double amount)
+ {
+ return this.holdings.hasOver(amount);
+ }
+
+ @Override
+ public boolean hasUnder(double amount)
+ {
+ return this.holdings.hasUnder(amount);
+ }
+
+ @Override
+ public boolean isNegative()
+ {
+ return this.holdings.isNegative();
+ }
+
+ @Override
+ public boolean remove()
+ {
+ if (this.account == null)
+ {
+ return false;
+ }
+ this.account.remove();
+ return true;
+ }
+ }
+
+
+ public class iCoBankAccount implements MethodBankAccount
+ {
+ private BankAccount account;
+ private Holdings holdings;
+
+ public iCoBankAccount(BankAccount account)
+ {
+ this.account = account;
+ this.holdings = account.getHoldings();
+ }
+
+ public BankAccount getiCoBankAccount()
+ {
+ return account;
+ }
+
+ @Override
+ public String getBankName()
+ {
+ return this.account.getBankName();
+ }
+
+ @Override
+ public int getBankId()
+ {
+ return this.account.getBankId();
+ }
+
+ @Override
+ public double balance()
+ {
+ return this.holdings.balance();
+ }
+
+ @Override
+ public boolean set(double amount)
+ {
+ if (this.holdings == null)
+ {
+ return false;
+ }
+ this.holdings.set(amount);
+ return true;
+ }
+
+ @Override
+ public boolean add(double amount)
+ {
+ if (this.holdings == null)
+ {
+ return false;
+ }
+ this.holdings.add(amount);
+ return true;
+ }
+
+ @Override
+ public boolean subtract(double amount)
+ {
+ if (this.holdings == null)
+ {
+ return false;
+ }
+ this.holdings.subtract(amount);
+ return true;
+ }
+
+ @Override
+ public boolean multiply(double amount)
+ {
+ if (this.holdings == null)
+ {
+ return false;
+ }
+ this.holdings.multiply(amount);
+ return true;
+ }
+
+ @Override
+ public boolean divide(double amount)
+ {
+ if (this.holdings == null)
+ {
+ return false;
+ }
+ this.holdings.divide(amount);
+ return true;
+ }
+
+ @Override
+ public boolean hasEnough(double amount)
+ {
+ return this.holdings.hasEnough(amount);
+ }
+
+ @Override
+ public boolean hasOver(double amount)
+ {
+ return this.holdings.hasOver(amount);
+ }
+
+ @Override
+ public boolean hasUnder(double amount)
+ {
+ return this.holdings.hasUnder(amount);
+ }
+
+ @Override
+ public boolean isNegative()
+ {
+ return this.holdings.isNegative();
+ }
+
+ @Override
+ public boolean remove()
+ {
+ if (this.account == null)
+ {
+ return false;
+ }
+ this.account.remove();
+ return true;
+ }
+ }
+} \ No newline at end of file
diff --git a/Essentials/src/net/ess3/economy/register/methods/iCo6.java b/Essentials/src/net/ess3/economy/register/methods/iCo6.java
new file mode 100644
index 000000000..4944a91a9
--- /dev/null
+++ b/Essentials/src/net/ess3/economy/register/methods/iCo6.java
@@ -0,0 +1,242 @@
+package net.ess3.economy.register.methods;
+
+import net.ess3.economy.register.Method;
+import com.iCo6.iConomy;
+import com.iCo6.system.Account;
+import com.iCo6.system.Accounts;
+import com.iCo6.system.Holdings;
+import org.bukkit.plugin.Plugin;
+
+
+/**
+ * iConomy 6 Implementation of Method
+ *
+ * @author Nijikokun <nijikokun@shortmail.com> (@nijikokun) @copyright (c) 2011 @license AOL license
+ * <http://aol.nexua.org>
+ */
+public class iCo6 implements Method
+{
+ private iConomy iConomy;
+
+ @Override
+ public iConomy getPlugin()
+ {
+ return this.iConomy;
+ }
+
+ @Override
+ public String getName()
+ {
+ return "iConomy";
+ }
+
+ @Override
+ public String getLongName()
+ {
+ return getName();
+ }
+
+ @Override
+ public String getVersion()
+ {
+ return "6";
+ }
+
+ @Override
+ public int fractionalDigits()
+ {
+ return 2;
+ }
+
+ @Override
+ public String format(double amount)
+ {
+ return com.iCo6.iConomy.format(amount);
+ }
+
+ @Override
+ public boolean hasBanks()
+ {
+ return false;
+ }
+
+ @Override
+ public boolean hasBank(String bank)
+ {
+ return false;
+ }
+
+ @Override
+ public boolean hasAccount(String name)
+ {
+ return (new Accounts()).exists(name);
+ }
+
+ @Override
+ public boolean hasBankAccount(String bank, String name)
+ {
+ return false;
+ }
+
+ @Override
+ public boolean createAccount(String name)
+ {
+ if (hasAccount(name))
+ {
+ return false;
+ }
+
+ return (new Accounts()).create(name);
+ }
+
+ @Override
+ public boolean createAccount(String name, Double balance)
+ {
+ if (hasAccount(name))
+ {
+ return false;
+ }
+
+ return (new Accounts()).create(name, balance);
+ }
+
+ @Override
+ public MethodAccount getAccount(String name)
+ {
+ return new iCoAccount((new Accounts()).get(name));
+ }
+
+ @Override
+ public MethodBankAccount getBankAccount(String bank, String name)
+ {
+ return null;
+ }
+
+ @Override
+ public boolean isCompatible(Plugin plugin)
+ {
+ return plugin.getDescription().getName().equalsIgnoreCase("iconomy")
+ && plugin.getClass().getName().equals("com.iCo6.iConomy")
+ && plugin instanceof iConomy;
+ }
+
+ @Override
+ public void setPlugin(Plugin plugin)
+ {
+ iConomy = (iConomy)plugin;
+ }
+
+
+ public class iCoAccount implements MethodAccount
+ {
+ private Account account;
+ private Holdings holdings;
+
+ public iCoAccount(Account account)
+ {
+ this.account = account;
+ this.holdings = account.getHoldings();
+ }
+
+ public Account getiCoAccount()
+ {
+ return account;
+ }
+
+ @Override
+ public double balance()
+ {
+ return this.holdings.getBalance();
+ }
+
+ @Override
+ public boolean set(double amount)
+ {
+ if (this.holdings == null)
+ {
+ return false;
+ }
+ this.holdings.setBalance(amount);
+ return true;
+ }
+
+ @Override
+ public boolean add(double amount)
+ {
+ if (this.holdings == null)
+ {
+ return false;
+ }
+ this.holdings.add(amount);
+ return true;
+ }
+
+ @Override
+ public boolean subtract(double amount)
+ {
+ if (this.holdings == null)
+ {
+ return false;
+ }
+ this.holdings.subtract(amount);
+ return true;
+ }
+
+ @Override
+ public boolean multiply(double amount)
+ {
+ if (this.holdings == null)
+ {
+ return false;
+ }
+ this.holdings.multiply(amount);
+ return true;
+ }
+
+ @Override
+ public boolean divide(double amount)
+ {
+ if (this.holdings == null)
+ {
+ return false;
+ }
+ this.holdings.divide(amount);
+ return true;
+ }
+
+ @Override
+ public boolean hasEnough(double amount)
+ {
+ return this.holdings.hasEnough(amount);
+ }
+
+ @Override
+ public boolean hasOver(double amount)
+ {
+ return this.holdings.hasOver(amount);
+ }
+
+ @Override
+ public boolean hasUnder(double amount)
+ {
+ return this.holdings.hasUnder(amount);
+ }
+
+ @Override
+ public boolean isNegative()
+ {
+ return this.holdings.isNegative();
+ }
+
+ @Override
+ public boolean remove()
+ {
+ if (this.account == null)
+ {
+ return false;
+ }
+ this.account.remove();
+ return true;
+ }
+ }
+}