diff --git a/com/Acrobot/ChestShop/Config/Config.java b/com/Acrobot/ChestShop/Config/Config.java index 5297fa1..ae6003b 100644 --- a/com/Acrobot/ChestShop/Config/Config.java +++ b/com/Acrobot/ChestShop/Config/Config.java @@ -1,31 +1,27 @@ package com.Acrobot.ChestShop.Config; -import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Logging.Logging; import org.bukkit.util.config.Configuration; import java.io.File; import java.io.FileWriter; -import java.util.HashMap; /** * @author Acrobot */ public class Config { - private static File configFile = new File(ChestShop.folder, "config.yml"); - private static File langFile = new File(ChestShop.folder, "local.yml"); + private static File configFile = new File("plugins/ChestShop", "config.yml"); + private static File langFile = new File("plugins/ChestShop", "local.yml"); private static Configuration config = new Configuration(configFile); private static Configuration language = new Configuration(langFile); - public static HashMap defaultValues = new HashMap(); - public static void setUp() { config.load(); - for (Property def : com.Acrobot.ChestShop.Config.Property.values()) { + for (Property def : Property.values()) { if (config.getProperty(def.name()) == null) { - writeToFile(def.name() + ": " + def.getValue() + " #" + def.getComment(), configFile); + writeToFile(def.name() + ": " + def.getValue() + "\n#" + def.getComment(), configFile); } } config.load(); @@ -76,4 +72,9 @@ public class Config { private static Object getValue(String node) { return config.getProperty(node); } + + public static String getPreferred() { + config.load(); + return getString(Property.PREFERRED_ECONOMY_PLUGIN); + } } diff --git a/com/Acrobot/ChestShop/Config/Property.java b/com/Acrobot/ChestShop/Config/Property.java index 5944308..4126940 100644 --- a/com/Acrobot/ChestShop/Config/Property.java +++ b/com/Acrobot/ChestShop/Config/Property.java @@ -4,6 +4,7 @@ package com.Acrobot.ChestShop.Config; * @author Acrobot */ public enum Property { + PREFERRED_ECONOMY_PLUGIN("", "Preferred economy plugin (iConomy, BOSEconomy, Essentials). If you do not want to specify this, leave it blank."), REVERSE_BUTTONS(false, "If true, people will buy with left-click and sell with right-click."), SERVER_ECONOMY_ACCOUNT("", "Economy account's name you want Admin Shops to be assigned to"), ADMIN_SHOP_NAME("Admin Shop", "First line of your admin shop should look like this"), diff --git a/com/Acrobot/ChestShop/Items/DataValue.java b/com/Acrobot/ChestShop/Items/DataValue.java index c2f4602..03ef42d 100644 --- a/com/Acrobot/ChestShop/Items/DataValue.java +++ b/com/Acrobot/ChestShop/Items/DataValue.java @@ -20,22 +20,26 @@ public class DataValue { MaterialData materialData = null; - switch (material) { - case SAPLING: - case LOG: - materialData = new Tree(TreeSpecies.valueOf(arg)); - break; - case STEP: - case DOUBLE_STEP: - materialData = new Step(Items.getMat(arg)); - break; - case WOOL: - case INK_SACK: - materialData = new Wool(DyeColor.valueOf(arg)); - break; - case COAL: - materialData = new Coal(CoalType.valueOf(arg)); - break; + try { + switch (material) { + case SAPLING: + case LOG: + materialData = new Tree(TreeSpecies.valueOf(arg)); + break; + case STEP: + case DOUBLE_STEP: + materialData = new Step(Items.getMaterial(arg)); + break; + case WOOL: + case INK_SACK: + materialData = new Wool(DyeColor.valueOf(arg)); + break; + case COAL: + materialData = new Coal(CoalType.valueOf(arg)); + break; + } + } catch (Exception e) { + return 0; } return (materialData == null ? 0 : materialData.getData()); diff --git a/com/Acrobot/ChestShop/Items/Items.java b/com/Acrobot/ChestShop/Items/Items.java index 8c5d043..3d41430 100644 --- a/com/Acrobot/ChestShop/Items/Items.java +++ b/com/Acrobot/ChestShop/Items/Items.java @@ -10,10 +10,9 @@ import org.bukkit.inventory.ItemStack; */ public class Items { - public static Material getMat(String itemName) { - if (uNumber.isInteger(itemName)) { - return Material.getMaterial(Integer.parseInt(itemName)); - } + public static Material getMaterial(String itemName) { + if (uNumber.isInteger(itemName)) return Material.getMaterial(Integer.parseInt(itemName)); + int length = 256; Material finalMat = null; itemName = itemName.toLowerCase().replace("_", "").replace(" ", ""); @@ -28,30 +27,55 @@ public class Items { } public static ItemStack getItemStack(String itemName) { - if (Odd.isInitialized()) { - ItemStack odd = Odd.returnItemStack(itemName.replace(":", ";")); - if (odd != null) { - return odd; - } - } - String[] split = itemName.split(":"); - itemName = split[0]; - short dataValue = (short) (split.length > 1 && uNumber.isInteger(split[1]) ? Integer.parseInt(split[1]) : 0); - - Material mat; - - String[] data = itemName.split(" "); - if (data.length >= 2) { - mat = getMat(itemName.substring(itemName.indexOf(' '))); - byte argData = DataValue.get(data[0], mat); - - if (argData != 0) { - dataValue = argData; - } - } else { - mat = getMat(itemName); + ItemStack toReturn; + if ((toReturn = getFromOddItem(itemName)) != null) { + return toReturn; } - return (mat != null ? new ItemStack(mat, 1, dataValue) : null); + Material material = getMaterial(itemName); + if(material != null) return new ItemStack(material, 1); + + return getItemStackWithDataValue(itemName); } + + private static ItemStack getFromOddItem(String itemName) { + if (!Odd.isInitialized()) return null; + return Odd.returnItemStack(itemName.replace(":", ";")); + } + + private static ItemStack getItemStackWithDataValue(String itemName){ + if(!itemName.contains(":")) return getItemStackWithDataValueFromWord(itemName); + + String[] word = itemName.split(":"); + if(word.length < 2 || !uNumber.isInteger(word[1])) return null; + + Material item = getMaterial(word[0]); + if(item == null) return null; + + short dataValue = Short.parseShort(word[1]); + return new ItemStack(item, 1, dataValue); + } + + private static ItemStack getItemStackWithDataValueFromWord(String itemName) { + if (!itemName.contains(" ") || getMaterial(itemName) != null) return null; + String[] word = itemName.split(" "); + if(word.length < 2) return null; + + String dataValue = word[0]; + + String material[] = new String[word.length - 1]; + System.arraycopy(word, 1, material, 0, word.length - 1); + StringBuilder mat = new StringBuilder(); + + for(String s : material){ + mat.append(s); + } + + Material item = getMaterial(mat.toString()); + + return item == null ? null : new ItemStack(item, 1, DataValue.get(dataValue, item)); + + + } + } diff --git a/com/Acrobot/ChestShop/Listeners/pluginEnable.java b/com/Acrobot/ChestShop/Listeners/pluginEnable.java index ec95de3..ceae162 100644 --- a/com/Acrobot/ChestShop/Listeners/pluginEnable.java +++ b/com/Acrobot/ChestShop/Listeners/pluginEnable.java @@ -1,6 +1,7 @@ package com.Acrobot.ChestShop.Listeners; import com.Acrobot.ChestShop.ChestShop; +import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Economy; import com.Acrobot.ChestShop.Items.Odd; import com.Acrobot.ChestShop.Permission; @@ -22,7 +23,7 @@ import org.yi.acru.bukkit.Lockette.Lockette; */ public class pluginEnable extends ServerListener { - public static Methods methods = new Methods(); + public static Methods methods = new Methods(Config.getPreferred()); public void onPluginEnable(PluginEnableEvent event) { diff --git a/com/Acrobot/ChestShop/Utils/uSign.java b/com/Acrobot/ChestShop/Utils/uSign.java index 232c8a7..f6ba4ac 100644 --- a/com/Acrobot/ChestShop/Utils/uSign.java +++ b/com/Acrobot/ChestShop/Utils/uSign.java @@ -2,17 +2,27 @@ package com.Acrobot.ChestShop.Utils; import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Property; -import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Sign; +import java.util.regex.Pattern; + /** * @author Acrobot */ public class uSign { + //static Pattern firstLine = Pattern.compile("^[A-Za-z0-9].+$"); + + static Pattern[] patterns = { + Pattern.compile("^$|^\\w.+$"), + Pattern.compile("[0-9]+"), + Pattern.compile(".+"), + Pattern.compile("[\\w :]+") + }; + public static boolean isSign(Block block) { - return (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN); + return block.getState() instanceof Sign; } public static boolean isAdminShop(String owner) { @@ -31,10 +41,14 @@ public class uSign { } } - public static boolean isValidPreparedSign(String[] line) { - try { - return !line[0].startsWith("[") && !line[0].endsWith("]") && !line[0].startsWith(":") && !line[3].split(":")[0].isEmpty() && uNumber.isInteger(line[1]) && line[2].split(":").length <= 2; - } catch (Exception e) { + public static boolean isValidPreparedSign(String[] lines){ + try{ + boolean toReturn = true; + for(int i = 0; i < 4; i++){ + toReturn = toReturn && patterns[i].matcher(lines[i]).matches(); + } + return toReturn; + } catch (Exception e){ return false; } } diff --git a/com/nijikokun/register/payment/forChestShop/Methods.java b/com/nijikokun/register/payment/forChestShop/Methods.java index 0d73e99..5e15097 100644 --- a/com/nijikokun/register/payment/forChestShop/Methods.java +++ b/com/nijikokun/register/payment/forChestShop/Methods.java @@ -1,11 +1,13 @@ package com.nijikokun.register.payment.forChestShop; +import com.nijikokun.register.payment.forChestShop.methods.BOSE6; +import com.nijikokun.register.payment.forChestShop.methods.BOSE7; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; + import java.util.HashSet; import java.util.Set; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; - /** * Methods.java * Controls the getting / setting of methods & the method of payment used. @@ -29,7 +31,7 @@ public class Methods { /** * Allows you to set which economy plugin is most preferred. * - * @param preferred + * @param preferred - preferred economy plugin */ public Methods(String preferred) { this._init(); @@ -42,7 +44,8 @@ public class Methods { private void _init() { this.addMethod("iConomy", new com.nijikokun.register.payment.forChestShop.methods.iCo4()); this.addMethod("iConomy", new com.nijikokun.register.payment.forChestShop.methods.iCo5()); - this.addMethod("BOSEconomy", new com.nijikokun.register.payment.forChestShop.methods.BOSE()); + this.addMethod("BOSEconomy", new BOSE6()); + this.addMethod("BOSEconomy", new BOSE7()); this.addMethod("Essentials", new com.nijikokun.register.payment.forChestShop.methods.EE17()); } @@ -76,7 +79,7 @@ public class Methods { int count = 0; boolean match = false; - Plugin plugin = null; + Plugin plugin; PluginManager manager = method.getServer().getPluginManager(); for(String name: this.getDependencies()) { diff --git a/com/nijikokun/register/payment/forChestShop/methods/BOSE.java b/com/nijikokun/register/payment/forChestShop/methods/BOSE6.java similarity index 85% rename from com/nijikokun/register/payment/forChestShop/methods/BOSE.java rename to com/nijikokun/register/payment/forChestShop/methods/BOSE6.java index 4103b1e..75b85df 100644 --- a/com/nijikokun/register/payment/forChestShop/methods/BOSE.java +++ b/com/nijikokun/register/payment/forChestShop/methods/BOSE6.java @@ -4,7 +4,7 @@ import com.nijikokun.register.payment.forChestShop.Method; import cosine.boseconomy.BOSEconomy; import org.bukkit.plugin.Plugin; -public class BOSE implements Method { +public class BOSE6 implements Method { private BOSEconomy BOSEconomy; public BOSEconomy getPlugin() { @@ -38,7 +38,7 @@ public class BOSE implements Method { } public boolean hasBankAccount(String bank, String name) { - return this.BOSEconomy.isBankOwner(bank, name); + return this.BOSEconomy.isBankOwner(bank, name) || this.BOSEconomy.isBankMember(bank, name); } public MethodAccount getAccount(String name) { @@ -47,11 +47,12 @@ public class BOSE implements Method { } public MethodBankAccount getBankAccount(String bank, String name) { - return new BOSEBankAccount(bank, name, BOSEconomy); + 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; + return plugin.getDescription().getName().equalsIgnoreCase("boseconomy") && plugin instanceof BOSEconomy && plugin.getDescription().getVersion().equals("0.6.2"); } public void setPlugin(Plugin plugin) { @@ -122,11 +123,9 @@ public class BOSE implements Method { public class BOSEBankAccount implements MethodBankAccount { private String bank; - private String name; private BOSEconomy BOSEconomy; - public BOSEBankAccount(String bank, String name, BOSEconomy bOSEconomy) { - this.name = name; + public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) { this.bank = bank; this.BOSEconomy = bOSEconomy; } @@ -140,36 +139,36 @@ public class BOSE implements Method { } public double balance() { - return Double.valueOf(this.BOSEconomy.getBankMoney(name)); + return Double.valueOf(this.BOSEconomy.getBankMoney(bank)); } public boolean set(double amount) { int IntAmount = (int)Math.ceil(amount); - return this.BOSEconomy.setBankMoney(name, IntAmount, true); + return this.BOSEconomy.setBankMoney(bank, IntAmount, true); } public boolean add(double amount) { int IntAmount = (int)Math.ceil(amount); int balance = (int)this.balance(); - return this.BOSEconomy.setBankMoney(this.name, (balance + IntAmount), false); + return this.BOSEconomy.setBankMoney(bank, (balance + IntAmount), false); } public boolean subtract(double amount) { int IntAmount = (int)Math.ceil(amount); int balance = (int)this.balance(); - return this.BOSEconomy.setBankMoney(this.name, (balance - IntAmount), false); + return this.BOSEconomy.setBankMoney(bank, (balance - IntAmount), false); } public boolean multiply(double amount) { int IntAmount = (int)Math.ceil(amount); int balance = (int)this.balance(); - return this.BOSEconomy.setBankMoney(this.name, (balance * IntAmount), false); + return this.BOSEconomy.setBankMoney(bank, (balance * IntAmount), false); } public boolean divide(double amount) { int IntAmount = (int)Math.ceil(amount); int balance = (int)this.balance(); - return this.BOSEconomy.setBankMoney(this.name, (balance / IntAmount), false); + return this.BOSEconomy.setBankMoney(bank, (balance / IntAmount), false); } public boolean hasEnough(double amount) { diff --git a/com/nijikokun/register/payment/forChestShop/methods/BOSE7.java b/com/nijikokun/register/payment/forChestShop/methods/BOSE7.java new file mode 100644 index 0000000..d6a51a9 --- /dev/null +++ b/com/nijikokun/register/payment/forChestShop/methods/BOSE7.java @@ -0,0 +1,188 @@ +package com.nijikokun.register.payment.forChestShop.methods; + +import com.nijikokun.register.payment.forChestShop.Method; +import cosine.boseconomy.BOSEconomy; +import org.bukkit.plugin.Plugin; + +/** + * @author Acrobot + */ + +public class BOSE7 implements Method { + private BOSEconomy BOSEconomy; + + public BOSEconomy getPlugin() { + return this.BOSEconomy; + } + + public String getName() { + return "BOSEconomy"; + } + + public String getVersion() { + return "0.7.0"; + } + + public String format(double amount) { + String currency = this.BOSEconomy.getMoneyNamePlural(); + if(amount == 1) currency = this.BOSEconomy.getMoneyName(); + return amount + " " + currency; + } + + public boolean hasBanks() { + return true; + } + + public boolean hasBank(String bank) { + return this.BOSEconomy.bankExists(bank); + } + + public boolean hasAccount(String name) { + return this.BOSEconomy.playerRegistered(name, false); + } + + public boolean hasBankAccount(String bank, String name) { + return this.BOSEconomy.isBankOwner(bank, name) || this.BOSEconomy.isBankMember(bank, name); + } + + public MethodAccount getAccount(String name) { + if(!hasAccount(name)) return null; + return new BOSEAccount(name, this.BOSEconomy); + } + + public MethodBankAccount getBankAccount(String bank, String 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"); + } + + 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; + } + + public double balance() { + return this.BOSEconomy.getPlayerMoneyDouble(this.name); + } + + public boolean set(double amount) { + return this.BOSEconomy.setPlayerMoney(this.name, amount, false); + } + + public boolean add(double amount) { + return this.BOSEconomy.addPlayerMoney(this.name, amount, false); + } + + public boolean subtract(double amount) { + double balance = this.balance(); + return this.BOSEconomy.setPlayerMoney(this.name, (balance - amount), false); + } + + public boolean multiply(double amount) { + double balance = this.balance(); + return this.BOSEconomy.setPlayerMoney(this.name, (balance * amount), false); + } + + public boolean divide(double amount) { + double balance = this.balance(); + return this.BOSEconomy.setPlayerMoney(this.name, (balance / amount), false); + } + + public boolean hasEnough(double amount) { + return (this.balance() >= amount); + } + + public boolean hasOver(double amount) { + return (this.balance() > amount); + } + + public boolean hasUnder(double amount) { + return (this.balance() < amount); + } + + public boolean isNegative() { + return (this.balance() < 0); + } + + public boolean remove() { + return false; + } + } + + public class BOSEBankAccount implements MethodBankAccount { + private String bank; + private BOSEconomy BOSEconomy; + + public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) { + this.bank = bank; + this.BOSEconomy = bOSEconomy; + } + + public String getBankName() { + return this.bank; + } + + public int getBankId() { + return -1; + } + + public double balance() { + return this.BOSEconomy.getBankMoneyDouble(bank); + } + + public boolean set(double amount) { + return this.BOSEconomy.setBankMoney(bank, amount, true); + } + + public boolean add(double amount) { + double balance = this.balance(); + return this.BOSEconomy.setBankMoney(bank, (balance + amount), false); + } + + public boolean subtract(double amount) { + double balance = this.balance(); + return this.BOSEconomy.setBankMoney(bank, (balance - amount), false); + } + + public boolean multiply(double amount) { + double balance = this.balance(); + return this.BOSEconomy.setBankMoney(bank, (balance * amount), false); + } + + public boolean divide(double amount) { + double balance = this.balance(); + return this.BOSEconomy.setBankMoney(bank, (balance / amount), false); + } + + public boolean hasEnough(double amount) { + return (this.balance() >= amount); + } + + public boolean hasOver(double amount) { + return (this.balance() > amount); + } + + public boolean hasUnder(double amount) { + return (this.balance() < amount); + } + + public boolean isNegative() { + return (this.balance() < 0); + } + + public boolean remove() { + return this.BOSEconomy.removeBank(bank); + } + } +} \ No newline at end of file diff --git a/plugin.yml b/plugin.yml index 0cabb10..0214b71 100644 --- a/plugin.yml +++ b/plugin.yml @@ -3,7 +3,7 @@ name: ChestShop main: com.Acrobot.ChestShop.ChestShop database: true -version: 3.00 BETA 8 +version: 3.00 BETA 9 author: Acrobot