From 9a6b9d0c3800110b7f2858bc2c54fe26327f18e2 Mon Sep 17 00:00:00 2001 From: Acrobot Date: Thu, 29 Sep 2011 20:29:39 +0200 Subject: [PATCH] - Added option to tax all transactions - Updated Register and BukkitEx - Can't place shops in the wilderness - Fixed CraftBukkit's piston bug - no more try/catch --- com/Acrobot/ChestShop/Config/Config.java | 2 +- com/Acrobot/ChestShop/Config/Property.java | 3 +- com/Acrobot/ChestShop/Economy.java | 9 +- .../ChestShop/Listeners/blockBreak.java | 15 +- .../ChestShop/Listeners/playerInteract.java | 7 +- .../ChestShop/Listeners/pluginDisable.java | 2 +- .../ChestShop/Listeners/pluginEnable.java | 4 +- com/Acrobot/ChestShop/Utils/uTowny.java | 7 +- com/lennardf1989/bukkitex/Database.java | 151 +++++++++++------- .../payment}/Method.java | 49 +++--- .../payment}/Methods.java | 53 +++--- .../payment}/methods/BOSE6.java | 78 +++++---- .../payment}/methods/BOSE7.java | 44 +++-- .../payment}/methods/EE17.java | 103 ++++++------ .../payment}/methods/MCUR.java | 26 ++- .../payment}/methods/iCo4.java | 62 +++++-- .../payment}/methods/iCo5.java | 65 +++++--- .../payment}/methods/iCo6.java | 46 ++++-- plugin.yml | 2 +- 19 files changed, 456 insertions(+), 272 deletions(-) rename com/nijikokun/register/{payment/forChestShop => forChestShop/payment}/Method.java (90%) rename com/nijikokun/register/{payment/forChestShop => forChestShop/payment}/Methods.java (80%) rename com/nijikokun/register/{payment/forChestShop => forChestShop/payment}/methods/BOSE6.java (73%) rename com/nijikokun/register/{payment/forChestShop => forChestShop/payment}/methods/BOSE7.java (83%) rename com/nijikokun/register/{payment/forChestShop => forChestShop/payment}/methods/EE17.java (53%) rename com/nijikokun/register/{payment/forChestShop => forChestShop/payment}/methods/MCUR.java (80%) rename com/nijikokun/register/{payment/forChestShop => forChestShop/payment}/methods/iCo4.java (69%) rename com/nijikokun/register/{payment/forChestShop => forChestShop/payment}/methods/iCo5.java (76%) rename com/nijikokun/register/{payment/forChestShop => forChestShop/payment}/methods/iCo6.java (74%) diff --git a/com/Acrobot/ChestShop/Config/Config.java b/com/Acrobot/ChestShop/Config/Config.java index f8011ba..8a58946 100644 --- a/com/Acrobot/ChestShop/Config/Config.java +++ b/com/Acrobot/ChestShop/Config/Config.java @@ -1,6 +1,6 @@ package com.Acrobot.ChestShop.Config; -import com.nijikokun.register.payment.forChestShop.Methods; +import com.nijikokun.register.forChestShop.payment.Methods; /** * @author Acrobot diff --git a/com/Acrobot/ChestShop/Config/Property.java b/com/Acrobot/ChestShop/Config/Property.java index 45f8984..f9378d0 100644 --- a/com/Acrobot/ChestShop/Config/Property.java +++ b/com/Acrobot/ChestShop/Config/Property.java @@ -25,7 +25,8 @@ public enum Property { SHOW_MESSAGE_OUT_OF_STOCK(true, "Do you want to show \"Out of stock\" messages?"), SHOW_TRANSACTION_INFORMATION_CLIENT(true, "Do you want to show \"You bought/sold... \" messages?"), SHOW_TRANSACTION_INFORMATION_OWNER(true, "Do you want to show \"Somebody bought/sold... \" messages?"), - TOWNY_INTEGRATION(false, "Do you want to only let people build inside shop plots?"); + TOWNY_INTEGRATION(false, "Do you want to only let people build inside shop plots?"), + TAX_AMOUNT(0, "Percent of the price that should go to the server's account. (100 = 100 percent)"); private final Object value; diff --git a/com/Acrobot/ChestShop/Economy.java b/com/Acrobot/ChestShop/Economy.java index ca97a09..a5feb3f 100644 --- a/com/Acrobot/ChestShop/Economy.java +++ b/com/Acrobot/ChestShop/Economy.java @@ -1,7 +1,9 @@ package com.Acrobot.ChestShop; +import com.Acrobot.ChestShop.Config.Config; +import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.Utils.uLongName; -import com.nijikokun.register.payment.forChestShop.Method; +import com.nijikokun.register.forChestShop.payment.Method; /** * @author Acrobot @@ -15,6 +17,11 @@ public class Economy { } public static void add(String name, float amount) { + if (Config.getFloat(Property.TAX_AMOUNT) != 0F && !Config.getString(Property.SERVER_ECONOMY_ACCOUNT).isEmpty()) { + float tax = (Config.getFloat(Property.TAX_AMOUNT) / 100F) * amount; + economy.getAccount(Config.getString(Property.SERVER_ECONOMY_ACCOUNT)).add(tax); + amount = amount - tax; + } economy.getAccount(uLongName.getName(name)).add(amount); } diff --git a/com/Acrobot/ChestShop/Listeners/blockBreak.java b/com/Acrobot/ChestShop/Listeners/blockBreak.java index 6cf85cb..94295a6 100644 --- a/com/Acrobot/ChestShop/Listeners/blockBreak.java +++ b/com/Acrobot/ChestShop/Listeners/blockBreak.java @@ -5,12 +5,14 @@ import com.Acrobot.ChestShop.Utils.uBlock; import com.Acrobot.ChestShop.Utils.uLongName; import com.Acrobot.ChestShop.Utils.uSign; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.material.PistonBaseMaterial; /** * @author Acrobot @@ -57,6 +59,17 @@ public class blockBreak extends BlockListener { } private static Block getRetractBlock(BlockPistonRetractEvent event) { - return (!uSign.isSign(event.getRetractLocation().getBlock()) ? event.getRetractLocation().getBlock() : null); + Block block = getRetractLocationBlock(event); + return (block != null && !uSign.isSign(block) ? block : null); + } + + //Those are fixes for CraftBukkit's piston bug, where piston appears not to be a piston. + private static BlockFace getPistonDirection(Block block) { + return block.getState().getData() instanceof PistonBaseMaterial ? ((PistonBaseMaterial) block.getState().getData()).getFacing() : null; + } + + private static Block getRetractLocationBlock(BlockPistonRetractEvent event) { + BlockFace pistonDirection = getPistonDirection(event.getBlock()); + return pistonDirection != null ? event.getBlock().getRelative((pistonDirection), 2).getLocation().getBlock() : null; } } diff --git a/com/Acrobot/ChestShop/Listeners/playerInteract.java b/com/Acrobot/ChestShop/Listeners/playerInteract.java index 5e311b5..260d00c 100644 --- a/com/Acrobot/ChestShop/Listeners/playerInteract.java +++ b/com/Acrobot/ChestShop/Listeners/playerInteract.java @@ -71,11 +71,8 @@ public class playerInteract extends PlayerListener { Action buy = (Config.getBoolean(Property.REVERSE_BUTTONS) ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK); - if (action == buy) { - ShopManagement.buy(sign, player); - } else { - ShopManagement.sell(sign, player); - } + if (action == buy) ShopManagement.buy(sign, player); + else ShopManagement.sell(sign, player); } private static boolean enoughTimeHasPassed(Player player) { diff --git a/com/Acrobot/ChestShop/Listeners/pluginDisable.java b/com/Acrobot/ChestShop/Listeners/pluginDisable.java index b174093..a67ebdd 100644 --- a/com/Acrobot/ChestShop/Listeners/pluginDisable.java +++ b/com/Acrobot/ChestShop/Listeners/pluginDisable.java @@ -1,7 +1,7 @@ package com.Acrobot.ChestShop.Listeners; import com.Acrobot.ChestShop.Economy; -import com.nijikokun.register.payment.forChestShop.Methods; +import com.nijikokun.register.forChestShop.payment.Methods; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.ServerListener; diff --git a/com/Acrobot/ChestShop/Listeners/pluginEnable.java b/com/Acrobot/ChestShop/Listeners/pluginEnable.java index c8ac606..8f5e915 100644 --- a/com/Acrobot/ChestShop/Listeners/pluginEnable.java +++ b/com/Acrobot/ChestShop/Listeners/pluginEnable.java @@ -13,7 +13,7 @@ import com.Acrobot.ChestShop.Utils.uSign; import com.daemitus.deadbolt.Deadbolt; import com.griefcraft.lwc.LWCPlugin; import com.nijikokun.bukkit.Permissions.Permissions; -import com.nijikokun.register.payment.forChestShop.Methods; +import com.nijikokun.register.forChestShop.payment.Methods; import com.palmergames.bukkit.towny.Towny; import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.ServerListener; @@ -72,7 +72,7 @@ public class pluginEnable extends ServerListener { System.out.println(ChestShop.chatPrefix + description.getName() + " version " + description.getVersion() + " loaded."); } - private static String generateOutdatedVersion(String pluginName, String curVersion, String neededVersion){ + private static String generateOutdatedVersion(String pluginName, String curVersion, String neededVersion) { return (new StringBuilder(7).append(ChestShop.chatPrefix).append("Your ").append(pluginName).append(" is outdated! Need version AT LEAST ").append(neededVersion).append(" - Your version is ").append(curVersion).toString()); } } diff --git a/com/Acrobot/ChestShop/Utils/uTowny.java b/com/Acrobot/ChestShop/Utils/uTowny.java index edc9bc9..b954170 100644 --- a/com/Acrobot/ChestShop/Utils/uTowny.java +++ b/com/Acrobot/ChestShop/Utils/uTowny.java @@ -22,8 +22,13 @@ public class uTowny { return isBlockOwner(player, chestLocation) && isBlockOwner(player, signLocation); } + public static boolean isNotInTheWilderness(Location chestLocation, Location signLocation) { + return !uSign.towny.getTownyUniverse().isWilderness(chestLocation.getBlock()) && !uSign.towny.getTownyUniverse().isWilderness(signLocation.getBlock()); + } + public static boolean canBuild(Player player, Location chestLocation, Location signLocation) { - return !Config.getBoolean(Property.TOWNY_INTEGRATION) || (isInsideShopPlot(chestLocation, signLocation) && isPlotOwner(player, chestLocation, signLocation)); + System.out.println(isNotInTheWilderness(chestLocation, signLocation)); + return uSign.towny == null || !Config.getBoolean(Property.TOWNY_INTEGRATION) || (isNotInTheWilderness(chestLocation, signLocation) && isInsideShopPlot(chestLocation, signLocation) && isPlotOwner(player, chestLocation, signLocation)); } private static boolean isBlockOwner(Player player, Location location) { diff --git a/com/lennardf1989/bukkitex/Database.java b/com/lennardf1989/bukkitex/Database.java index 3898cf5..f199822 100644 --- a/com/lennardf1989/bukkitex/Database.java +++ b/com/lennardf1989/bukkitex/Database.java @@ -22,7 +22,7 @@ import java.util.logging.Level; import java.util.logging.Logger; public abstract class Database { - private final JavaPlugin javaPlugin; + private JavaPlugin javaPlugin; private ClassLoader classLoader; private Level loggerLevel; private boolean usingSQLite; @@ -31,7 +31,7 @@ public abstract class Database { /** * Create an instance of Database - * + * * @param javaPlugin Plugin instancing this database */ public Database(JavaPlugin javaPlugin) { @@ -45,8 +45,9 @@ public abstract class Database { method.setAccessible(true); //Store the ClassLoader - this.classLoader = (ClassLoader) method.invoke(javaPlugin); - } catch (Exception ex) { + this.classLoader = (ClassLoader)method.invoke(javaPlugin); + } + catch(Exception ex ) { throw new RuntimeException("Failed to retrieve the ClassLoader of the plugin using Reflection", ex); } } @@ -54,15 +55,15 @@ public abstract class Database { /** * Initialize the database using the passed arguments * - * @param driver Database-driver to use. For example: org.sqlite.JDBC - * @param url Location of the database. For example: jdbc:sqlite:{DIR}{NAME}.db - * @param username Username required to access the database - * @param password Password belonging to the username, may be empty - * @param isolation Isolation type. For example: SERIALIZABLE, also see TransactionIsolation + * @param driver Database-driver to use. For example: org.sqlite.JDBC + * @param url Location of the database. For example: jdbc:sqlite:{DIR}{NAME}.db + * @param username Username required to access the database + * @param password Password belonging to the username, may be empty + * @param isolation Isolation type. For example: SERIALIZABLE, also see TransactionIsolation */ public void initializeDatabase(String driver, String url, String username, String password, String isolation) { //Logging needs to be set back to the original level, no matter what happens - try { + try { //Disable all logging disableDatabaseLogging(false); @@ -73,16 +74,18 @@ public abstract class Database { loadDatabase(); //Create all tables - installDatabase(true); - } catch (Exception ex) { + installDatabase(false); + } + catch(Exception ex) { throw new RuntimeException("An exception has occured while initializing the database", ex); - } finally { + } + finally { //Enable all logging enableDatabaseLogging(false); } } - private void prepareDatabase(String driver, String url, String username, String password, String isolation) { + private void prepareDatabase(String driver, String url, String username, String password, String isolation) { //Setup the data source DataSourceConfig ds = new DataSourceConfig(); ds.setDriver(driver); @@ -101,7 +104,10 @@ public abstract class Database { List> classes = getDatabaseClasses(); //Do a sanity check first - if (classes.isEmpty()) throw new RuntimeException("Database has been enabled, but no classes are registered to it"); + if(classes.isEmpty()) { + //Exception: There is no use in continuing to load this database + throw new RuntimeException("Database has been enabled, but no classes are registered to it"); + } //Register them with the EbeanServer sc.setClasses(classes); @@ -116,6 +122,8 @@ public abstract class Database { sc.getDatabasePlatform().getDbDdlSyntax().setIdentity(""); } + prepareDatabaseAdditionalConfig(ds, sc); + //Finally the data source sc.setDataSourceConfig(ds); @@ -146,33 +154,34 @@ public abstract class Database { //Setup Ebean based on the configuration ebeanServer = EbeanServerFactory.create(serverConfig); - } catch (Exception ex) { + } + catch(Exception ex) { throw new RuntimeException("Failed to create a new instance of the EbeanServer", ex); - } finally { + } + finally { //Revert the ClassLoader back to its original value - if (currentClassLoader != null) Thread.currentThread().setContextClassLoader(currentClassLoader); + if(currentClassLoader != null) { + Thread.currentThread().setContextClassLoader(currentClassLoader); + } //Revert the "defaultUseCaches"-field in URLConnection back to its original value try { - if (cacheField != null) cacheField.setBoolean(null, cacheValue); - } catch (Exception e) { + if(cacheField != null) { + cacheField.setBoolean(null, cacheValue); + } + } + catch (Exception e) { System.out.println("Failed to revert the \"defaultUseCaches\"-field back to its original value, URLConnection-caching remains disabled."); } } } private void installDatabase(boolean rebuild) { - //Check if the database has to be rebuild - if (!rebuild) return; - - //Create a DDL generator - SpiEbeanServer serv = (SpiEbeanServer) ebeanServer; - DdlGenerator gen = serv.getDdlGenerator(); - - //Check if the database already (partially) exists + //Check if the database already (partially) exists boolean databaseExists = false; - for (Class aClass : getDatabaseClasses()) { + List> classes = getDatabaseClasses(); + for (Class aClass : classes) { try { //Do a simple query which only throws an exception if the table does not exist ebeanServer.find(aClass).findRowCount(); @@ -180,33 +189,53 @@ public abstract class Database { //Query passed without throwing an exception, a database therefore already exists databaseExists = true; break; - } catch (Exception ignored) {} + } catch (Exception ex) { + //Do nothing + } } - if(databaseExists) return; + //Check if the database has to be created or rebuilt + if(!rebuild && databaseExists) { + return; + } - //Fire "before drop" event + //Create a DDL generator + SpiEbeanServer serv = (SpiEbeanServer) ebeanServer; + DdlGenerator gen = serv.getDdlGenerator(); + + //Fire "before drop" event try { beforeDropDatabase(); - } catch (Exception ex) { + } + catch(Exception ex) { //If the database exists, dropping has to be canceled to prevent data-loss - if (databaseExists) throw new RuntimeException("An unexpected exception occured", ex); + if(databaseExists) { + throw new RuntimeException("An unexpected exception occured", ex); + } } //Generate a DropDDL-script gen.runScript(true, gen.generateDropDdl()); //If SQLite is being used, the database has to reloaded to release all resources - if (usingSQLite) loadDatabase(); + if(usingSQLite) { + loadDatabase(); + } //Generate a CreateDDL-script - //If SQLite is being used, the CreateDLL-script has to be validated and potentially fixed to be valid - gen.runScript(false, (usingSQLite ? validateCreateDDLSqlite(gen.generateCreateDdl()) : gen.generateCreateDdl())); + if(usingSQLite) { + //If SQLite is being used, the CreateDLL-script has to be validated and potentially fixed to be valid + gen.runScript(false, validateCreateDDLSqlite(gen.generateCreateDdl())); + } + else { + gen.runScript(false, gen.generateCreateDdl()); + } //Fire "after create" event try { afterCreateDatabase(); - } catch (Exception ex) { + } + catch(Exception ex) { throw new RuntimeException("An unexpected exception occured", ex); } } @@ -241,11 +270,12 @@ public abstract class Database { scriptLines.add(currentLine.trim()); //Check if the current line is of any use - if (currentLine.startsWith("create table")) { + if(currentLine.startsWith("create table")) { //Found a table, so get its name and remember the line it has been encountered on currentTable = currentLine.split(" ", 4)[2]; foundTables.put(currentLine.split(" ", 3)[2], scriptLines.size() - 1); - } else if (currentLine.length() > 0 && currentLine.charAt(0) == ';' && currentTable != null && !currentTable.isEmpty()) { + } + else if(currentLine.length() > 0 && currentLine.charAt(0) == ';' && currentTable != null && !currentTable.isEmpty()) { //Found the end of a table definition, so update the entry int index = scriptLines.size() - 1; foundTables.put(currentTable, index); @@ -260,16 +290,17 @@ public abstract class Database { //Reset the table-tracker currentTable = null; - } else if (currentLine.startsWith("alter table")) { + } + else if(currentLine.startsWith("alter table")) { //Found a potentially unsupported action String[] alterTableLine = currentLine.split(" ", 4); - if (alterTableLine[3].startsWith("add constraint")) { + if(alterTableLine[3].startsWith("add constraint")) { //Found an unsupported action: ALTER TABLE using ADD CONSTRAINT String[] addConstraintLine = alterTableLine[3].split(" ", 4); //Check if this line can be fixed somehow - if (addConstraintLine[3].startsWith("foreign key")) { + if(addConstraintLine[3].startsWith("foreign key")) { //Calculate the index of last line of the current table int tableLastLine = foundTables.get(alterTableLine[2]) + tableOffset; @@ -283,7 +314,8 @@ public abstract class Database { //Remove this line and raise the table offset because a line has been inserted scriptLines.remove(scriptLines.size() - 1); tableOffset++; - } else { + } + else { //Exception: This line cannot be fixed but is known the be unsupported by SQLite throw new RuntimeException("Unsupported action encountered: ALTER TABLE using ADD CONSTRAINT with " + addConstraintLine[3]); } @@ -293,14 +325,15 @@ public abstract class Database { //Turn all the lines back into a single string StringBuilder newScript = new StringBuilder(5); - for (String newLine : scriptLines) newScript.append(newLine).append('\n'); + for(String newLine : scriptLines) newScript.append(newLine).append('\n'); //Print the new script System.out.println(newScript); //Return the fixed script return newScript.toString(); - } catch (Exception ex) { + } + catch (Exception ex) { //Exception: Failed to fix the DDL or something just went plain wrong throw new RuntimeException("Failed to validate the CreateDDL-script for SQLite", ex); } @@ -308,7 +341,9 @@ public abstract class Database { private void disableDatabaseLogging(boolean logging) { //If logging is allowed, nothing has to be changed - if (logging) return; + if(logging) { + return; + } //Retrieve the level of the root logger loggerLevel = Logger.getLogger("").getLevel(); @@ -319,7 +354,9 @@ public abstract class Database { private void enableDatabaseLogging(boolean logging) { //If logging is allowed, nothing has to be changed - if (logging) return; + if(logging) { + return; + } //Set the level of the root logger back to the original value Logger.getLogger("").setLevel(loggerLevel); @@ -327,7 +364,7 @@ public abstract class Database { /** * Get a list of classes which should be registered with the EbeanServer - * + * * @return List List of classes which should be registered with the EbeanServer */ protected List> getDatabaseClasses() { @@ -337,18 +374,24 @@ public abstract class Database { /** * Method called before the loaded database is being dropped */ - protected void beforeDropDatabase() { - } + protected void beforeDropDatabase() {} /** * Method called after the loaded database has been created */ - protected void afterCreateDatabase() { - } + protected void afterCreateDatabase() {} + + /** + * Method called near the end of prepareDatabase, before the dataSourceConfig is attached to the serverConfig. + * + * @param dataSourceConfig + * @param serverConfig + */ + protected void prepareDatabaseAdditionalConfig(DataSourceConfig dataSourceConfig, ServerConfig serverConfig) {} /** * Get the instance of the EbeanServer - * + * * @return EbeanServer Instance of the EbeanServer */ public EbeanServer getDatabase() { diff --git a/com/nijikokun/register/payment/forChestShop/Method.java b/com/nijikokun/register/forChestShop/payment/Method.java similarity index 90% rename from com/nijikokun/register/payment/forChestShop/Method.java rename to com/nijikokun/register/forChestShop/payment/Method.java index 198f2f4..67b8bff 100644 --- a/com/nijikokun/register/payment/forChestShop/Method.java +++ b/com/nijikokun/register/forChestShop/payment/Method.java @@ -1,4 +1,4 @@ -package com.nijikokun.register.payment.forChestShop; +package com.nijikokun.register.forChestShop.payment; import org.bukkit.plugin.Plugin; @@ -14,11 +14,11 @@ 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. - *

+ * *

      *  if(method.getName().equalsIgnoreCase("iConomy"))
      *   iConomy plugin = ((iConomy)method.getPlugin());
- * + * * @return Object * @see #getName() * @see #getVersion() @@ -38,11 +38,11 @@ public interface Method { * @return String 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 int for each decimal place */ public int fractionalDigits(); @@ -88,6 +88,23 @@ public interface Method { */ public boolean hasBankAccount(String bank, String name); + /** + * Forces an account creation + * + * @param name Account name + * @return boolean + */ + public boolean createAccount(String name); + + /** + * Forces an account creation + * + * @param name Account name + * @param balance Initial account balance + * @return boolean + */ + public boolean createAccount(String name, Double balance); + /** * Returns a MethodAccount class for an account name. * @@ -127,25 +144,15 @@ public interface Method { */ 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 @@ -157,29 +164,17 @@ public interface Method { */ 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 diff --git a/com/nijikokun/register/payment/forChestShop/Methods.java b/com/nijikokun/register/forChestShop/payment/Methods.java similarity index 80% rename from com/nijikokun/register/payment/forChestShop/Methods.java rename to com/nijikokun/register/forChestShop/payment/Methods.java index 9cd9b93..5391a9d 100644 --- a/com/nijikokun/register/payment/forChestShop/Methods.java +++ b/com/nijikokun/register/forChestShop/payment/Methods.java @@ -1,20 +1,20 @@ -package com.nijikokun.register.payment.forChestShop; - -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; +package com.nijikokun.register.forChestShop.payment; import java.util.HashSet; import java.util.Set; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; + /** * The Methods 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 bukkit.yml: *

  *  economy:
@@ -29,7 +29,7 @@ public class Methods {
     private static String version = null;
     private static boolean self = false;
     private static Method Method = null;
-    public static String preferred = "";
+    private static String preferred = "";
     private static Set Methods = new HashSet();
     private static Set Dependencies = new HashSet();
     private static Set Attachables = new HashSet();
@@ -42,13 +42,13 @@ public class Methods {
      * Implement all methods along with their respective name & class.
      */
     private static void _init() {
-        addMethod("iConomy", new com.nijikokun.register.payment.forChestShop.methods.iCo6());
-        addMethod("iConomy", new com.nijikokun.register.payment.forChestShop.methods.iCo5());
-        addMethod("iConomy", new com.nijikokun.register.payment.forChestShop.methods.iCo4());
-        addMethod("BOSEconomy", new com.nijikokun.register.payment.forChestShop.methods.BOSE6());
-        addMethod("BOSEconomy", new com.nijikokun.register.payment.forChestShop.methods.BOSE7());
-        addMethod("Essentials", new com.nijikokun.register.payment.forChestShop.methods.EE17());
-        addMethod("Currency", new com.nijikokun.register.payment.forChestShop.methods.MCUR());
+        addMethod("iConomy", new com.nijikokun.register.forChestShop.payment.methods.iCo6());
+        addMethod("iConomy", new com.nijikokun.register.forChestShop.payment.methods.iCo5());
+        addMethod("iConomy", new com.nijikokun.register.forChestShop.payment.methods.iCo4());
+        addMethod("BOSEconomy", new com.nijikokun.register.forChestShop.payment.methods.BOSE6());
+        addMethod("BOSEconomy", new com.nijikokun.register.forChestShop.payment.methods.BOSE7());
+        addMethod("Essentials", new com.nijikokun.register.forChestShop.payment.methods.EE17());
+        addMethod("Currency", new com.nijikokun.register.forChestShop.payment.methods.MCUR());
         Dependencies.add("MultiCurrency");
     }
 
@@ -74,7 +74,6 @@ public class Methods {
 
     /**
      * Use to get version of Register plugin
-     *
      * @return version
      */
     public static String getVersion() {
@@ -86,6 +85,7 @@ public class Methods {
      * through the _init method.
      *
      * @return Set - Array of payment methods that are loaded.
+     * @see #setMethod(org.bukkit.plugin.Plugin)
      */
     public static Set getDependencies() {
         return Dependencies;
@@ -99,7 +99,7 @@ public class Methods {
      * @return Method or Null
      */
     public static Method createMethod(Plugin plugin) {
-        for (Method method : Methods)
+        for (Method method: Methods)
             if (method.isCompatible(plugin)) {
                 method.setPlugin(plugin);
                 return method;
@@ -117,6 +117,7 @@ public class Methods {
      * Verifies if Register has set a payment method for usage yet.
      *
      * @return boolean
+     * @see #setMethod(org.bukkit.plugin.Plugin)
      * @see #checkDisabled(org.bukkit.plugin.Plugin)
      */
     public static boolean hasMethod() {
@@ -127,6 +128,7 @@ public class Methods {
      * Checks Plugin Class against a multitude of checks to verify it's usability
      * as a payment method.
      *
+     * @param PluginManager the plugin manager for the server
      * @return boolean True on success, False on failure.
      */
     public static boolean setMethod(PluginManager manager) {
@@ -140,14 +142,14 @@ public class Methods {
 
         int count = 0;
         boolean match = false;
-        Plugin plugin;
+        Plugin plugin = null;
 
-        for (String name : Dependencies) {
+        for (String name : getDependencies()) {
             if (hasMethod())
                 break;
 
             plugin = manager.getPlugin(name);
-            if (plugin == null)
+            if (plugin == null || !plugin.isEnabled())
                 continue;
 
             Method current = createMethod(plugin);
@@ -170,8 +172,7 @@ public class Methods {
                             continue;
 
                         if (hasMethod()) {
-                            match = true;
-                            break;
+                            match = true; break;
                         }
 
                         if (preferred.isEmpty())
@@ -181,8 +182,8 @@ public class Methods {
                             if (preferred.equalsIgnoreCase(attached.getName()))
                                 Method = attached;
 
-                            else
-                                Method = attached;
+                        else
+                            Method = attached;
                     }
 
                     count++;
@@ -199,7 +200,7 @@ public class Methods {
      * @return boolean
      */
     public static boolean setPreferred(String check) {
-        if (Dependencies.contains(check)) {
+        if (getDependencies().contains(check)) {
             preferred = check;
             return true;
         }
@@ -224,7 +225,7 @@ public class Methods {
      * @return boolean
      */
     public static boolean checkDisabled(Plugin method) {
-        if (!hasMethod())
+        if(!hasMethod())
             return true;
 
         if (Method.isCompatible(method))
diff --git a/com/nijikokun/register/payment/forChestShop/methods/BOSE6.java b/com/nijikokun/register/forChestShop/payment/methods/BOSE6.java
similarity index 73%
rename from com/nijikokun/register/payment/forChestShop/methods/BOSE6.java
rename to com/nijikokun/register/forChestShop/payment/methods/BOSE6.java
index 9c69c3b..af7f74d 100644
--- a/com/nijikokun/register/payment/forChestShop/methods/BOSE6.java
+++ b/com/nijikokun/register/forChestShop/payment/methods/BOSE6.java
@@ -1,6 +1,7 @@
-package com.nijikokun.register.payment.forChestShop.methods;
+package com.nijikokun.register.forChestShop.payment.methods;
+
+import com.nijikokun.register.forChestShop.payment.Method;
 
-import com.nijikokun.register.payment.forChestShop.Method;
 import cosine.boseconomy.BOSEconomy;
 import org.bukkit.plugin.Plugin;
 
@@ -26,15 +27,15 @@ public class BOSE6 implements Method {
     public String getVersion() {
         return "0.6.2";
     }
-
+    
     public int fractionalDigits() {
-        return 0;
+    	return 0;
     }
 
     public String format(double amount) {
         String currency = this.BOSEconomy.getMoneyNamePlural();
 
-        if (amount == 1)
+        if(amount == 1) 
             currency = this.BOSEconomy.getMoneyName();
 
         return amount + " " + currency;
@@ -54,34 +55,51 @@ public class BOSE6 implements Method {
 
     public boolean hasBankAccount(String bank, String name) {
         return this.BOSEconomy.isBankOwner(bank, name)
-                || this.BOSEconomy.isBankMember(bank, name);
+            || this.BOSEconomy.isBankMember(bank, name);
+    }
+
+    public boolean createAccount(String name) {
+        if(hasAccount(name))
+            return false;
+
+        this.BOSEconomy.registerPlayer(name);
+        return true;
+    }
+
+    public boolean createAccount(String name, Double balance) {
+        if(hasAccount(name))
+            return false;
+
+        this.BOSEconomy.registerPlayer(name);
+        this.BOSEconomy.setPlayerMoney(name, balance, false);
+        return true;
     }
 
     public MethodAccount getAccount(String name) {
-        if (!hasAccount(name))
+        if(!hasAccount(name)) 
             return null;
 
         return new BOSEAccount(name, this.BOSEconomy);
     }
 
     public MethodBankAccount getBankAccount(String bank, String name) {
-        if (!hasBankAccount(bank, name))
+        if(!hasBankAccount(bank, name)) 
             return null;
 
         return new BOSEBankAccount(bank, BOSEconomy);
     }
 
     public boolean isCompatible(Plugin plugin) {
-        return plugin.getDescription().getName().equalsIgnoreCase("boseconomy")
-                && plugin instanceof BOSEconomy
-                && plugin.getDescription().getVersion().equals("0.6.2");
+        return plugin.getDescription().getName().equalsIgnoreCase("boseconomy") 
+            && plugin instanceof BOSEconomy
+            && plugin.getDescription().getVersion().equals("0.6.2");
     }
 
     public void setPlugin(Plugin plugin) {
         BOSEconomy = (BOSEconomy) plugin;
     }
 
-    public static class BOSEAccount implements MethodAccount {
+    public class BOSEAccount implements MethodAccount {
         private final String name;
         private final BOSEconomy BOSEconomy;
 
@@ -95,30 +113,30 @@ public class BOSE6 implements Method {
         }
 
         public boolean set(double amount) {
-            int IntAmount = (int) Math.ceil(amount);
+            int IntAmount = (int)Math.ceil(amount);
             return this.BOSEconomy.setPlayerMoney(this.name, IntAmount, false);
         }
 
         public boolean add(double amount) {
-            int IntAmount = (int) Math.ceil(amount);
+            int IntAmount = (int)Math.ceil(amount);
             return this.BOSEconomy.addPlayerMoney(this.name, IntAmount, false);
         }
 
         public boolean subtract(double amount) {
-            int IntAmount = (int) Math.ceil(amount);
-            int balance = (int) this.balance();
+            int IntAmount = (int)Math.ceil(amount);
+            int balance = (int)this.balance();
             return this.BOSEconomy.setPlayerMoney(this.name, (balance - IntAmount), false);
         }
 
         public boolean multiply(double amount) {
-            int IntAmount = (int) Math.ceil(amount);
-            int balance = (int) this.balance();
+            int IntAmount = (int)Math.ceil(amount);
+            int balance = (int)this.balance();
             return this.BOSEconomy.setPlayerMoney(this.name, (balance * IntAmount), false);
         }
 
         public boolean divide(double amount) {
-            int IntAmount = (int) Math.ceil(amount);
-            int balance = (int) this.balance();
+            int IntAmount = (int)Math.ceil(amount);
+            int balance = (int)this.balance();
             return this.BOSEconomy.setPlayerMoney(this.name, (balance / IntAmount), false);
         }
 
@@ -143,7 +161,7 @@ public class BOSE6 implements Method {
         }
     }
 
-    public static class BOSEBankAccount implements MethodBankAccount {
+    public class BOSEBankAccount implements MethodBankAccount {
         private final String bank;
         private final BOSEconomy BOSEconomy;
 
@@ -165,31 +183,31 @@ public class BOSE6 implements Method {
         }
 
         public boolean set(double amount) {
-            int IntAmount = (int) Math.ceil(amount);
+            int IntAmount = (int)Math.ceil(amount);
             return this.BOSEconomy.setBankMoney(bank, IntAmount, true);
         }
 
         public boolean add(double amount) {
-            int IntAmount = (int) Math.ceil(amount);
-            int balance = (int) this.balance();
+            int IntAmount = (int)Math.ceil(amount);
+            int balance = (int)this.balance();
             return this.BOSEconomy.setBankMoney(bank, (balance + IntAmount), false);
         }
 
         public boolean subtract(double amount) {
-            int IntAmount = (int) Math.ceil(amount);
-            int balance = (int) this.balance();
+            int IntAmount = (int)Math.ceil(amount);
+            int balance = (int)this.balance();
             return this.BOSEconomy.setBankMoney(bank, (balance - IntAmount), false);
         }
 
         public boolean multiply(double amount) {
-            int IntAmount = (int) Math.ceil(amount);
-            int balance = (int) this.balance();
+            int IntAmount = (int)Math.ceil(amount);
+            int balance = (int)this.balance();
             return this.BOSEconomy.setBankMoney(bank, (balance * IntAmount), false);
         }
 
         public boolean divide(double amount) {
-            int IntAmount = (int) Math.ceil(amount);
-            int balance = (int) this.balance();
+            int IntAmount = (int)Math.ceil(amount);
+            int balance = (int)this.balance();
             return this.BOSEconomy.setBankMoney(bank, (balance / IntAmount), false);
         }
 
diff --git a/com/nijikokun/register/payment/forChestShop/methods/BOSE7.java b/com/nijikokun/register/forChestShop/payment/methods/BOSE7.java
similarity index 83%
rename from com/nijikokun/register/payment/forChestShop/methods/BOSE7.java
rename to com/nijikokun/register/forChestShop/payment/methods/BOSE7.java
index 3a116b4..955c8b4 100644
--- a/com/nijikokun/register/payment/forChestShop/methods/BOSE7.java
+++ b/com/nijikokun/register/forChestShop/payment/methods/BOSE7.java
@@ -1,6 +1,7 @@
-package com.nijikokun.register.payment.forChestShop.methods;
+package com.nijikokun.register.forChestShop.payment.methods;
+
+import com.nijikokun.register.forChestShop.payment.Method;
 
-import com.nijikokun.register.payment.forChestShop.Method;
 import cosine.boseconomy.BOSEconomy;
 import org.bukkit.plugin.Plugin;
 
@@ -26,15 +27,15 @@ public class BOSE7 implements Method {
     public String getVersion() {
         return "0.7.0";
     }
-
+    
     public int fractionalDigits() {
-        return this.BOSEconomy.getFractionalDigits();
+    	return this.BOSEconomy.getFractionalDigits();
     }
 
     public String format(double amount) {
         String currency = this.BOSEconomy.getMoneyNamePlural();
 
-        if (amount == 1)
+        if(amount == 1) 
             currency = this.BOSEconomy.getMoneyName();
 
         return amount + " " + currency;
@@ -56,31 +57,48 @@ public class BOSE7 implements Method {
         return this.BOSEconomy.isBankOwner(bank, name) || this.BOSEconomy.isBankMember(bank, name);
     }
 
+    public boolean createAccount(String name) {
+        if(hasAccount(name))
+            return false;
+
+        this.BOSEconomy.registerPlayer(name);
+        return true;
+    }
+
+    public boolean createAccount(String name, Double balance) {
+        if(hasAccount(name))
+            return false;
+        
+        this.BOSEconomy.registerPlayer(name);
+        this.BOSEconomy.setPlayerMoney(name, balance, false);
+        return true;
+    }
+
     public MethodAccount getAccount(String name) {
-        if (!hasAccount(name))
+        if(!hasAccount(name)) 
             return null;
 
         return new BOSEAccount(name, this.BOSEconomy);
     }
 
     public MethodBankAccount getBankAccount(String bank, String name) {
-        if (!hasBankAccount(bank, name))
+        if(!hasBankAccount(bank, name)) 
             return null;
 
         return new BOSEBankAccount(bank, BOSEconomy);
     }
 
     public boolean isCompatible(Plugin plugin) {
-        return plugin.getDescription().getName().equalsIgnoreCase("boseconomy")
-                && plugin instanceof BOSEconomy
-                && !plugin.getDescription().getVersion().equals("0.6.2");
+        return plugin.getDescription().getName().equalsIgnoreCase("boseconomy") 
+            && plugin instanceof BOSEconomy
+           && !plugin.getDescription().getVersion().equals("0.6.2");
     }
 
     public void setPlugin(Plugin plugin) {
-        BOSEconomy = (BOSEconomy) plugin;
+        BOSEconomy = (BOSEconomy)plugin;
     }
 
-    public static class BOSEAccount implements MethodAccount {
+    public class BOSEAccount implements MethodAccount {
         private String name;
         private BOSEconomy BOSEconomy;
 
@@ -137,7 +155,7 @@ public class BOSE7 implements Method {
         }
     }
 
-    public static class BOSEBankAccount implements MethodBankAccount {
+    public class BOSEBankAccount implements MethodBankAccount {
         private String bank;
         private BOSEconomy BOSEconomy;
 
diff --git a/com/nijikokun/register/payment/forChestShop/methods/EE17.java b/com/nijikokun/register/forChestShop/payment/methods/EE17.java
similarity index 53%
rename from com/nijikokun/register/payment/forChestShop/methods/EE17.java
rename to com/nijikokun/register/forChestShop/payment/methods/EE17.java
index 4057a3d..34f03ba 100644
--- a/com/nijikokun/register/payment/forChestShop/methods/EE17.java
+++ b/com/nijikokun/register/forChestShop/payment/methods/EE17.java
@@ -1,10 +1,9 @@
-package com.nijikokun.register.payment.forChestShop.methods;
+package com.nijikokun.register.forChestShop.payment.methods;
 
+import com.nijikokun.register.forChestShop.payment.Method;
 import com.earth2me.essentials.Essentials;
 import com.earth2me.essentials.api.Economy;
-import com.earth2me.essentials.api.NoLoanPermittedException;
-import com.earth2me.essentials.api.UserDoesNotExistException;
-import com.nijikokun.register.payment.forChestShop.Method;
+
 import org.bukkit.plugin.Plugin;
 
 /**
@@ -31,9 +30,9 @@ public class EE17 implements Method {
     public String getVersion() {
         return "2.2";
     }
-
+    
     public int fractionalDigits() {
-        return -1;
+    	return -1;
     }
 
     public String format(double amount) {
@@ -56,8 +55,32 @@ public class EE17 implements Method {
         return false;
     }
 
+    public boolean createAccount(String name) {
+        if(hasAccount(name))
+            return false;
+        
+        Economy.createNPC(name);
+        return true;
+    }
+
+    public boolean createAccount(String name, Double balance) {
+        if(hasAccount(name))
+            return false;
+        
+        Economy.createNPC(name);
+
+        try {
+            Economy.setMoney(name, balance);
+        } catch (Exception ex) {
+            System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage());
+            return false;
+        }
+
+        return true;
+    }
+
     public MethodAccount getAccount(String name) {
-        if (!hasAccount(name))
+        if(!hasAccount(name)) 
             return null;
 
         return new EEcoAccount(name);
@@ -66,19 +89,20 @@ public class EE17 implements Method {
     public MethodBankAccount getBankAccount(String bank, String name) {
         return null;
     }
-
+	
     public boolean isCompatible(Plugin plugin) {
-        try { Class.forName("com.earth2me.essentials.api.Economy"); } catch (Exception e) { return false; }
+        try { Class.forName("com.earth2me.essentials.api.Economy"); }
+        catch(Exception e) { return false; }
 
         return plugin.getDescription().getName().equalsIgnoreCase("essentials")
-                && plugin instanceof Essentials;
+            && plugin instanceof Essentials;
     }
 
     public void setPlugin(Plugin plugin) {
-        Essentials = (Essentials) plugin;
+        Essentials = (Essentials)plugin;
     }
 
-    public static class EEcoAccount implements MethodAccount {
+    public class EEcoAccount implements MethodAccount {
         private String name;
 
         public EEcoAccount(String name) {
@@ -90,8 +114,8 @@ public class EE17 implements Method {
 
             try {
                 balance = Economy.getMoney(this.name);
-            } catch (UserDoesNotExistException ex) {
-                System.out.println("[REGISTER] Failed to grab balance in Essentials Economy: " + ex.getMessage());
+            } catch (Exception ex) {
+                System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage());
             }
 
             return balance;
@@ -100,11 +124,8 @@ public class EE17 implements Method {
         public boolean set(double amount) {
             try {
                 Economy.setMoney(name, amount);
-            } catch (UserDoesNotExistException ex) {
-                System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
-                return false;
-            } catch (NoLoanPermittedException ex) {
-                System.out.println("[REGISTER] No loan permitted in Essentials Economy: " + ex.getMessage());
+            } catch (Exception ex) {
+                System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage());
                 return false;
             }
 
@@ -114,11 +135,8 @@ public class EE17 implements Method {
         public boolean add(double amount) {
             try {
                 Economy.add(name, amount);
-            } catch (UserDoesNotExistException ex) {
-                System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
-                return false;
-            } catch (NoLoanPermittedException ex) {
-                System.out.println("[REGISTER] No loan permitted in Essentials Economy: " + ex.getMessage());
+            } catch (Exception ex) {
+                System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage());
                 return false;
             }
 
@@ -128,11 +146,8 @@ public class EE17 implements Method {
         public boolean subtract(double amount) {
             try {
                 Economy.subtract(name, amount);
-            } catch (UserDoesNotExistException ex) {
-                System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
-                return false;
-            } catch (NoLoanPermittedException ex) {
-                System.out.println("[REGISTER] No loan permitted in Essentials Economy: " + ex.getMessage());
+            } catch (Exception ex) {
+                System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage());
                 return false;
             }
 
@@ -142,11 +157,8 @@ public class EE17 implements Method {
         public boolean multiply(double amount) {
             try {
                 Economy.multiply(name, amount);
-            } catch (UserDoesNotExistException ex) {
-                System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
-                return false;
-            } catch (NoLoanPermittedException ex) {
-                System.out.println("[REGISTER] No loan permitted in Essentials Economy: " + ex.getMessage());
+            } catch (Exception ex) {
+                System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage());
                 return false;
             }
 
@@ -156,11 +168,8 @@ public class EE17 implements Method {
         public boolean divide(double amount) {
             try {
                 Economy.divide(name, amount);
-            } catch (UserDoesNotExistException ex) {
-                System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
-                return false;
-            } catch (NoLoanPermittedException ex) {
-                System.out.println("[REGISTER] No loan permitted in Essentials Economy: " + ex.getMessage());
+            } catch (Exception ex) {
+                System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage());
                 return false;
             }
 
@@ -170,8 +179,8 @@ public class EE17 implements Method {
         public boolean hasEnough(double amount) {
             try {
                 return Economy.hasEnough(name, amount);
-            } catch (UserDoesNotExistException ex) {
-                System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
+            } catch (Exception ex) {
+                System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage());
             }
 
             return false;
@@ -180,8 +189,8 @@ public class EE17 implements Method {
         public boolean hasOver(double amount) {
             try {
                 return Economy.hasMore(name, amount);
-            } catch (UserDoesNotExistException ex) {
-                System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
+            } catch (Exception ex) {
+                System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage());
             }
 
             return false;
@@ -190,8 +199,8 @@ public class EE17 implements Method {
         public boolean hasUnder(double amount) {
             try {
                 return Economy.hasLess(name, amount);
-            } catch (UserDoesNotExistException ex) {
-                System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
+            } catch (Exception ex) {
+                System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage());
             }
 
             return false;
@@ -200,8 +209,8 @@ public class EE17 implements Method {
         public boolean isNegative() {
             try {
                 return Economy.isNegative(name);
-            } catch (UserDoesNotExistException ex) {
-                System.out.println("[REGISTER] User does not exist in Essentials Economy: " + ex.getMessage());
+            } catch (Exception ex) {
+                System.out.println("[REGISTER] Error in Essentials Economy: " + ex.getMessage());
             }
 
             return false;
diff --git a/com/nijikokun/register/payment/forChestShop/methods/MCUR.java b/com/nijikokun/register/forChestShop/payment/methods/MCUR.java
similarity index 80%
rename from com/nijikokun/register/payment/forChestShop/methods/MCUR.java
rename to com/nijikokun/register/forChestShop/payment/methods/MCUR.java
index e5e189f..b901c32 100644
--- a/com/nijikokun/register/payment/forChestShop/methods/MCUR.java
+++ b/com/nijikokun/register/forChestShop/payment/methods/MCUR.java
@@ -1,8 +1,10 @@
-package com.nijikokun.register.payment.forChestShop.methods;
+package com.nijikokun.register.forChestShop.payment.methods;
+
+import com.nijikokun.register.forChestShop.payment.Method;
 
-import com.nijikokun.register.payment.forChestShop.Method;
 import me.ashtheking.currency.Currency;
 import me.ashtheking.currency.CurrencyList;
+
 import org.bukkit.plugin.Plugin;
 
 /**
@@ -26,9 +28,9 @@ public class MCUR implements Method {
     public String getVersion() {
         return "0.09";
     }
-
+    
     public int fractionalDigits() {
-        return -1;
+    	return -1;
     }
 
     public String format(double amount) {
@@ -51,6 +53,16 @@ public class MCUR implements Method {
         return false;
     }
 
+    public boolean createAccount(String name) {
+        CurrencyList.setValue((String) CurrencyList.maxCurrency(name)[0], name, 0);
+        return true;
+    }
+
+    public boolean createAccount(String name, Double balance) {
+        CurrencyList.setValue((String) CurrencyList.maxCurrency(name)[0], name, balance);
+        return true;
+    }
+
     public MethodAccount getAccount(String name) {
         return new MCurrencyAccount(name);
     }
@@ -61,15 +73,15 @@ public class MCUR implements Method {
 
     public boolean isCompatible(Plugin plugin) {
         return (plugin.getDescription().getName().equalsIgnoreCase("Currency")
-                || plugin.getDescription().getName().equalsIgnoreCase("MultiCurrency"))
-                && plugin instanceof Currency;
+             || plugin.getDescription().getName().equalsIgnoreCase("MultiCurrency"))
+             && plugin instanceof Currency;
     }
 
     public void setPlugin(Plugin plugin) {
         currencyList = (Currency) plugin;
     }
 
-    public static class MCurrencyAccount implements MethodAccount {
+    public class MCurrencyAccount implements MethodAccount{
         private String name;
 
         public MCurrencyAccount(String name) {
diff --git a/com/nijikokun/register/payment/forChestShop/methods/iCo4.java b/com/nijikokun/register/forChestShop/payment/methods/iCo4.java
similarity index 69%
rename from com/nijikokun/register/payment/forChestShop/methods/iCo4.java
rename to com/nijikokun/register/forChestShop/payment/methods/iCo4.java
index dfdfec7..bddbcdb 100644
--- a/com/nijikokun/register/payment/forChestShop/methods/iCo4.java
+++ b/com/nijikokun/register/forChestShop/payment/methods/iCo4.java
@@ -1,8 +1,10 @@
-package com.nijikokun.register.payment.forChestShop.methods;
+package com.nijikokun.register.forChestShop.payment.methods;
 
+import com.nijikokun.register.forChestShop.payment.Method;
 import com.nijiko.coelho.iConomy.iConomy;
 import com.nijiko.coelho.iConomy.system.Account;
-import com.nijikokun.register.payment.forChestShop.Method;
+
+
 import org.bukkit.plugin.Plugin;
 
 /**
@@ -26,9 +28,9 @@ public class iCo4 implements Method {
     public String getVersion() {
         return "4";
     }
-
+    
     public int fractionalDigits() {
-        return 2;
+    	return 2;
     }
 
     public String format(double amount) {
@@ -51,6 +53,32 @@ public class iCo4 implements Method {
         return false;
     }
 
+    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;
+    }
+
+    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;
+    }
+
     public MethodAccount getAccount(String name) {
         return new iCoAccount(com.nijiko.coelho.iConomy.iConomy.getBank().getAccount(name));
     }
@@ -58,18 +86,18 @@ public class iCo4 implements Method {
     public MethodBankAccount getBankAccount(String bank, String name) {
         return null;
     }
-
+	
     public boolean isCompatible(Plugin plugin) {
-        return plugin.getDescription().getName().equalsIgnoreCase("iconomy")
-                && plugin.getClass().getName().equals("com.nijiko.coelho.iConomy.iConomy")
-                && plugin instanceof iConomy;
+        return plugin.getDescription().getName().equalsIgnoreCase("iconomy") 
+            && plugin.getClass().getName().equals("com.nijiko.coelho.iConomy.iConomy")
+            && plugin instanceof iConomy;
     }
 
     public void setPlugin(Plugin plugin) {
-        iConomy = (iConomy) plugin;
+        iConomy = (iConomy)plugin;
     }
-
-    public static class iCoAccount implements MethodAccount {
+	
+    public class iCoAccount implements MethodAccount {
         private Account account;
 
         public iCoAccount(Account account) {
@@ -85,31 +113,31 @@ public class iCo4 implements Method {
         }
 
         public boolean set(double amount) {
-            if (this.account == null) return false;
+            if(this.account == null) return false;
             this.account.setBalance(amount);
             return true;
         }
 
         public boolean add(double amount) {
-            if (this.account == null) return false;
+            if(this.account == null) return false;
             this.account.add(amount);
             return true;
         }
 
         public boolean subtract(double amount) {
-            if (this.account == null) return false;
+            if(this.account == null) return false;
             this.account.subtract(amount);
             return true;
         }
 
         public boolean multiply(double amount) {
-            if (this.account == null) return false;
+            if(this.account == null) return false;
             this.account.multiply(amount);
             return true;
         }
 
         public boolean divide(double amount) {
-            if (this.account == null) return false;
+            if(this.account == null) return false;
             this.account.divide(amount);
             return true;
         }
@@ -131,7 +159,7 @@ public class iCo4 implements Method {
         }
 
         public boolean remove() {
-            if (this.account == null) return false;
+            if(this.account == null) return false;
             this.account.remove();
             return true;
         }
diff --git a/com/nijikokun/register/payment/forChestShop/methods/iCo5.java b/com/nijikokun/register/forChestShop/payment/methods/iCo5.java
similarity index 76%
rename from com/nijikokun/register/payment/forChestShop/methods/iCo5.java
rename to com/nijikokun/register/forChestShop/payment/methods/iCo5.java
index 7108966..d16fae9 100644
--- a/com/nijikokun/register/payment/forChestShop/methods/iCo5.java
+++ b/com/nijikokun/register/forChestShop/payment/methods/iCo5.java
@@ -1,11 +1,13 @@
-package com.nijikokun.register.payment.forChestShop.methods;
+package com.nijikokun.register.forChestShop.payment.methods;
 
+import com.nijikokun.register.forChestShop.payment.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 com.nijikokun.register.payment.forChestShop.Method;
+
+
 import org.bukkit.plugin.Plugin;
 
 /**
@@ -29,9 +31,9 @@ public class iCo5 implements Method {
     public String getVersion() {
         return "5";
     }
-
+    
     public int fractionalDigits() {
-        return 2;
+    	return 2;
     }
 
     public String format(double amount) {
@@ -54,6 +56,25 @@ public class iCo5 implements Method {
         return (hasBank(bank)) && com.iConomy.iConomy.getBank(bank).hasAccount(name);
     }
 
+    public boolean createAccount(String name) {
+        if(hasAccount(name))
+            return false;
+        
+        return com.iConomy.iConomy.Accounts.create(name);
+    }
+
+    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;
+    }
+
     public MethodAccount getAccount(String name) {
         return new iCoAccount(com.iConomy.iConomy.getAccount(name));
     }
@@ -63,16 +84,16 @@ public class iCo5 implements Method {
     }
 
     public boolean isCompatible(Plugin plugin) {
-        return plugin.getDescription().getName().equalsIgnoreCase("iconomy")
-                && plugin.getClass().getName().equals("com.iConomy.iConomy")
-                && plugin instanceof iConomy;
+        return plugin.getDescription().getName().equalsIgnoreCase("iconomy") 
+            && plugin.getClass().getName().equals("com.iConomy.iConomy")
+            && plugin instanceof iConomy;
     }
 
     public void setPlugin(Plugin plugin) {
-        iConomy = (iConomy) plugin;
+        iConomy = (iConomy)plugin;
     }
 
-    public static class iCoAccount implements MethodAccount {
+    public class iCoAccount implements MethodAccount {
         private Account account;
         private Holdings holdings;
 
@@ -90,31 +111,31 @@ public class iCo5 implements Method {
         }
 
         public boolean set(double amount) {
-            if (this.holdings == null) return false;
+            if(this.holdings == null) return false;
             this.holdings.set(amount);
             return true;
         }
 
         public boolean add(double amount) {
-            if (this.holdings == null) return false;
+            if(this.holdings == null) return false;
             this.holdings.add(amount);
             return true;
         }
 
         public boolean subtract(double amount) {
-            if (this.holdings == null) return false;
+            if(this.holdings == null) return false;
             this.holdings.subtract(amount);
             return true;
         }
 
         public boolean multiply(double amount) {
-            if (this.holdings == null) return false;
+            if(this.holdings == null) return false;
             this.holdings.multiply(amount);
             return true;
         }
 
         public boolean divide(double amount) {
-            if (this.holdings == null) return false;
+            if(this.holdings == null) return false;
             this.holdings.divide(amount);
             return true;
         }
@@ -136,13 +157,13 @@ public class iCo5 implements Method {
         }
 
         public boolean remove() {
-            if (this.account == null) return false;
+            if(this.account == null) return false;
             this.account.remove();
             return true;
         }
     }
 
-    public static class iCoBankAccount implements MethodBankAccount {
+    public class iCoBankAccount implements MethodBankAccount {
         private BankAccount account;
         private Holdings holdings;
 
@@ -168,31 +189,31 @@ public class iCo5 implements Method {
         }
 
         public boolean set(double amount) {
-            if (this.holdings == null) return false;
+            if(this.holdings == null) return false;
             this.holdings.set(amount);
             return true;
         }
 
         public boolean add(double amount) {
-            if (this.holdings == null) return false;
+            if(this.holdings == null) return false;
             this.holdings.add(amount);
             return true;
         }
 
         public boolean subtract(double amount) {
-            if (this.holdings == null) return false;
+            if(this.holdings == null) return false;
             this.holdings.subtract(amount);
             return true;
         }
 
         public boolean multiply(double amount) {
-            if (this.holdings == null) return false;
+            if(this.holdings == null) return false;
             this.holdings.multiply(amount);
             return true;
         }
 
         public boolean divide(double amount) {
-            if (this.holdings == null) return false;
+            if(this.holdings == null) return false;
             this.holdings.divide(amount);
             return true;
         }
@@ -214,7 +235,7 @@ public class iCo5 implements Method {
         }
 
         public boolean remove() {
-            if (this.account == null) return false;
+            if(this.account == null) return false;
             this.account.remove();
             return true;
         }
diff --git a/com/nijikokun/register/payment/forChestShop/methods/iCo6.java b/com/nijikokun/register/forChestShop/payment/methods/iCo6.java
similarity index 74%
rename from com/nijikokun/register/payment/forChestShop/methods/iCo6.java
rename to com/nijikokun/register/forChestShop/payment/methods/iCo6.java
index 89c2436..d0c4fd8 100644
--- a/com/nijikokun/register/payment/forChestShop/methods/iCo6.java
+++ b/com/nijikokun/register/forChestShop/payment/methods/iCo6.java
@@ -1,10 +1,12 @@
-package com.nijikokun.register.payment.forChestShop.methods;
+package com.nijikokun.register.forChestShop.payment.methods;
 
+import com.nijikokun.register.forChestShop.payment.Method;
 import com.iCo6.iConomy;
 import com.iCo6.system.Account;
 import com.iCo6.system.Accounts;
 import com.iCo6.system.Holdings;
-import com.nijikokun.register.payment.forChestShop.Method;
+
+
 import org.bukkit.plugin.Plugin;
 
 /**
@@ -28,9 +30,9 @@ public class iCo6 implements Method {
     public String getVersion() {
         return "6";
     }
-
+    
     public int fractionalDigits() {
-        return 2;
+    	return 2;
     }
 
     public String format(double amount) {
@@ -53,6 +55,20 @@ public class iCo6 implements Method {
         return false;
     }
 
+    public boolean createAccount(String name) {
+        if(hasAccount(name))
+            return false;
+        
+        return (new Accounts()).create(name);
+    }
+
+    public boolean createAccount(String name, Double balance) {
+        if(hasAccount(name))
+            return false;
+        
+        return (new Accounts()).create(name, balance);
+    }
+
     public MethodAccount getAccount(String name) {
         return new iCoAccount((new Accounts()).get(name));
     }
@@ -62,16 +78,16 @@ public class iCo6 implements Method {
     }
 
     public boolean isCompatible(Plugin plugin) {
-        return plugin.getDescription().getName().equalsIgnoreCase("iconomy")
-                && plugin.getClass().getName().equals("com.iCo6.iConomy")
-                && plugin instanceof iConomy;
+        return plugin.getDescription().getName().equalsIgnoreCase("iconomy") 
+            && plugin.getClass().getName().equals("com.iCo6.iConomy")
+            && plugin instanceof iConomy;
     }
 
     public void setPlugin(Plugin plugin) {
-        iConomy = (iConomy) plugin;
+        iConomy = (iConomy)plugin;
     }
 
-    public static class iCoAccount implements MethodAccount {
+    public class iCoAccount implements MethodAccount {
         private Account account;
         private Holdings holdings;
 
@@ -89,31 +105,31 @@ public class iCo6 implements Method {
         }
 
         public boolean set(double amount) {
-            if (this.holdings == null) return false;
+            if(this.holdings == null) return false;
             this.holdings.setBalance(amount);
             return true;
         }
 
         public boolean add(double amount) {
-            if (this.holdings == null) return false;
+            if(this.holdings == null) return false;
             this.holdings.add(amount);
             return true;
         }
 
         public boolean subtract(double amount) {
-            if (this.holdings == null) return false;
+            if(this.holdings == null) return false;
             this.holdings.subtract(amount);
             return true;
         }
 
         public boolean multiply(double amount) {
-            if (this.holdings == null) return false;
+            if(this.holdings == null) return false;
             this.holdings.multiply(amount);
             return true;
         }
 
         public boolean divide(double amount) {
-            if (this.holdings == null) return false;
+            if(this.holdings == null) return false;
             this.holdings.divide(amount);
             return true;
         }
@@ -135,7 +151,7 @@ public class iCo6 implements Method {
         }
 
         public boolean remove() {
-            if (this.account == null) return false;
+            if(this.account == null) return false;
             this.account.remove();
             return true;
         }
diff --git a/plugin.yml b/plugin.yml
index 64d697c..deccc9a 100644
--- a/plugin.yml
+++ b/plugin.yml
@@ -2,7 +2,7 @@ name: ChestShop
 
 main: com.Acrobot.ChestShop.ChestShop
 
-version: 3.21
+version: 3.22
 
 
 author: Acrobot