From a84c68d49d80fde32ae39b32c587529e00cfe03a Mon Sep 17 00:00:00 2001 From: Acrobot Date: Tue, 6 Sep 2011 19:01:57 +0200 Subject: [PATCH] - Changed how configuration works, so it works with plugin folder in different place - Added support for Deadbolt - By default, left clicking your own sign doesn't do anything - Restricted signs now check if you've got permission ChestShop.group.groupName - Added support for stacking unstackable things - Updated Register - Changed how plugins are loaded. --- com/Acrobot/ChestShop/ChestShop.java | 81 ++++--- com/Acrobot/ChestShop/Commands/ItemInfo.java | 2 +- com/Acrobot/ChestShop/Config/Config.java | 65 +----- .../ChestShop/Config/ConfigObject.java | 67 ++++++ com/Acrobot/ChestShop/Config/Language.java | 2 +- com/Acrobot/ChestShop/Config/Property.java | 3 +- com/Acrobot/ChestShop/Economy.java | 4 +- com/Acrobot/ChestShop/Items/Items.java | 4 +- .../ChestShop/Listeners/blockBreak.java | 6 +- .../ChestShop/Listeners/entityExplode.java | 8 +- .../ChestShop/Listeners/playerInteract.java | 8 +- .../ChestShop/Listeners/pluginDisable.java | 11 +- .../ChestShop/Listeners/pluginEnable.java | 59 ++--- com/Acrobot/ChestShop/Logging/Logging.java | 4 +- ...ockettePlugin.java => DeadboltPlugin.java} | 12 +- .../ChestShop/Protection/Plugins/Default.java | 8 +- .../Protection/Plugins/LWCplugin.java | 1 - .../Protection/Plugins/LockettePlugin.java | 6 +- .../ChestShop/Signs/restrictedSign.java | 5 +- com/Acrobot/ChestShop/Utils/uInventory.java | 34 ++- com/Acrobot/ChestShop/Utils/uLongName.java | 2 +- com/Acrobot/ChestShop/Utils/uSign.java | 14 +- .../register/payment/forChestShop/Method.java | 11 +- .../payment/forChestShop/Methods.java | 205 ++++++++++++++++++ .../payment/forChestShop/methods/BOSE6.java | 13 +- .../payment/forChestShop/methods/BOSE7.java | 17 +- .../payment/forChestShop/methods/EE17.java | 10 +- .../payment/forChestShop/methods/MCUR.java | 16 +- .../payment/forChestShop/methods/iCo4.java | 20 +- .../payment/forChestShop/methods/iCo5.java | 26 ++- .../payment/forChestShop/methods/iCo6.java | 23 +- .../payment/forChestShop/Methods.java | 203 ----------------- plugin.yml | 5 +- 33 files changed, 513 insertions(+), 442 deletions(-) create mode 100644 com/Acrobot/ChestShop/Config/ConfigObject.java rename com/Acrobot/ChestShop/Protection/Plugins/{OldLockettePlugin.java => DeadboltPlugin.java} (52%) rename com/{nijikokun => LRFLEW}/register/payment/forChestShop/Method.java (94%) create mode 100644 com/LRFLEW/register/payment/forChestShop/Methods.java rename com/{nijikokun => LRFLEW}/register/payment/forChestShop/methods/BOSE6.java (96%) rename com/{nijikokun => LRFLEW}/register/payment/forChestShop/methods/BOSE7.java (93%) rename com/{nijikokun => LRFLEW}/register/payment/forChestShop/methods/EE17.java (96%) rename com/{nijikokun => LRFLEW}/register/payment/forChestShop/methods/MCUR.java (85%) rename com/{nijikokun => LRFLEW}/register/payment/forChestShop/methods/iCo4.java (83%) rename com/{nijikokun => LRFLEW}/register/payment/forChestShop/methods/iCo5.java (87%) rename com/{nijikokun => LRFLEW}/register/payment/forChestShop/methods/iCo6.java (86%) delete mode 100644 com/nijikokun/register/payment/forChestShop/Methods.java diff --git a/com/Acrobot/ChestShop/ChestShop.java b/com/Acrobot/ChestShop/ChestShop.java index 7a10d91..d9a6758 100644 --- a/com/Acrobot/ChestShop/ChestShop.java +++ b/com/Acrobot/ChestShop/ChestShop.java @@ -3,6 +3,7 @@ package com.Acrobot.ChestShop; import com.Acrobot.ChestShop.Commands.ItemInfo; import com.Acrobot.ChestShop.Commands.Version; import com.Acrobot.ChestShop.Config.Config; +import com.Acrobot.ChestShop.Config.ConfigObject; import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.DB.Generator; import com.Acrobot.ChestShop.DB.Queue; @@ -14,6 +15,7 @@ import com.avaje.ebean.EbeanServer; import com.lennardf1989.bukkitex.Database; import org.bukkit.Server; import org.bukkit.event.Event; +import org.bukkit.event.Listener; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -30,57 +32,34 @@ import java.util.List; */ public class ChestShop extends JavaPlugin { - public static final File folder = new File("plugins/ChestShop"); + public static File folder = new File("plugins/ChestShop"); public static final String chatPrefix = "[ChestShop] "; private static EbeanServer DB; private static PluginDescriptionFile description; private static Server server; + public static PluginManager pm; + public void onEnable() { - PluginManager pm = getServer().getPluginManager(); + pm = getServer().getPluginManager(); + folder = getDataFolder(); //Set up our config file! - Config.setUp(); + Config.setup(new ConfigObject()); //Register our events - blockBreak blockBreak = new blockBreak(); + registerEvents(); description = this.getDescription(); //Description of the plugin server = getServer(); //Setting out server variable - pm.registerEvent(Event.Type.BLOCK_BREAK, blockBreak, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.BLOCK_PLACE, new blockPlace(), Event.Priority.Normal, this); - pm.registerEvent(Event.Type.SIGN_CHANGE, new signChange(), Event.Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_INTERACT, new playerInteract(), Event.Priority.Highest, this); - pm.registerEvent(Event.Type.PLUGIN_ENABLE, new pluginEnable(), Event.Priority.Monitor, this); - pm.registerEvent(Event.Type.PLUGIN_DISABLE, new pluginDisable(), Event.Priority.Monitor, this); - - if(Config.getBoolean(Property.USE_BUILT_IN_PROTECTION)){ - pm.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, blockBreak, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, blockBreak, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.ENTITY_EXPLODE, new entityExplode(), Event.Priority.Normal, this); - } - - if (Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) { //Now set up our database for storing transactions! - setupDB(); - getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Queue(), 200L, 200L); - - if (Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) { - getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Generator(), 300L, (long) Config.getDouble(Property.STATISTICS_PAGE_GENERATION_INTERVAL) * 20L); - } - } - - //Now set up our logging to file! - if (Config.getBoolean(Property.LOG_TO_FILE)) { - getServer().getScheduler().scheduleAsyncRepeatingTask(this, new FileWriterQueue(), 201L, 201L); - } - - //And now for the chest masking - if (Config.getBoolean(Property.MASK_CHESTS_AS_OTHER_BLOCKS)) { - getServer().getScheduler().scheduleAsyncRepeatingTask(this, new MaskChest(), 40L, 40L); - } + pluginEnable.initializePlugins(); + if (Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) setupDB(); + if (Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) scheduleTask(new Generator(), 300L, (long) Config.getDouble(Property.STATISTICS_PAGE_GENERATION_INTERVAL) * 20L); + if (Config.getBoolean(Property.LOG_TO_FILE)) scheduleTask(new FileWriterQueue(), 201L, 201L); + if (Config.getBoolean(Property.MASK_CHESTS_AS_OTHER_BLOCKS)) scheduleTask(new MaskChest(), 40L, 40L); //Register our commands! getCommand("iteminfo").setExecutor(new ItemInfo()); @@ -93,6 +72,33 @@ public class ChestShop extends JavaPlugin { System.out.println('[' + getPluginName() + "] version " + getVersion() + " shutting down!"); } + ////////////////// REGISTER EVENTS & SCHEDULER /////////////////////////// + private void registerEvents() { + blockBreak blockBreak = new blockBreak(); + registerEvent(Event.Type.BLOCK_BREAK, blockBreak); + registerEvent(Event.Type.BLOCK_PLACE, new blockPlace()); + registerEvent(Event.Type.SIGN_CHANGE, new signChange()); + registerEvent(Event.Type.PLAYER_INTERACT, new playerInteract(), Event.Priority.Highest); + registerEvent(Event.Type.PLUGIN_ENABLE, new pluginEnable()); + registerEvent(Event.Type.PLUGIN_DISABLE, new pluginDisable()); + if (!Config.getBoolean(Property.USE_BUILT_IN_PROTECTION)) return; + registerEvent(Event.Type.BLOCK_PISTON_EXTEND, blockBreak); + registerEvent(Event.Type.BLOCK_PISTON_RETRACT, blockBreak); + registerEvent(Event.Type.ENTITY_EXPLODE, new entityExplode()); + } + + private void registerEvent(Event.Type type, Listener listener) { + registerEvent(type, listener, Event.Priority.Normal); + } + + private void registerEvent(Event.Type type, Listener listener, Event.Priority priority) { + pm.registerEvent(type, listener, priority, this); + } + + private void scheduleTask(Runnable runnable, long startTime, long repetetionTime) { + server.getScheduler().scheduleAsyncRepeatingTask(this, runnable, startTime, repetetionTime); + } + ///////////////////// DATABASE STUFF //////////////////////////////// private static Configuration getBukkitConfig() { Configuration config = new Configuration(new File("bukkit.yml")); @@ -124,6 +130,7 @@ public class ChestShop extends JavaPlugin { ); DB = database.getDatabase(); + getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Queue(), 200L, 200L); } @Override @@ -147,4 +154,8 @@ public class ChestShop extends JavaPlugin { public static EbeanServer getDB() { return DB; } + + public static ArrayList getDependencies() { + return (ArrayList) description.getSoftDepend(); + } } diff --git a/com/Acrobot/ChestShop/Commands/ItemInfo.java b/com/Acrobot/ChestShop/Commands/ItemInfo.java index eeb6fbd..6a86e0b 100644 --- a/com/Acrobot/ChestShop/Commands/ItemInfo.java +++ b/com/Acrobot/ChestShop/Commands/ItemInfo.java @@ -24,7 +24,7 @@ public class ItemInfo implements CommandExecutor { item = Items.getItemStack(args[0]); } - if(item == null || item.getType() == Material.AIR) return false; + if (item == null || item.getType() == Material.AIR) return false; sender.sendMessage(Config.getLocal(Language.iteminfo)); sender.sendMessage(item.getTypeId() + (item.getDurability() != 0 ? " : " + item.getDurability() : "") + " - " + ChatColor.GRAY + item.getType().name()); diff --git a/com/Acrobot/ChestShop/Config/Config.java b/com/Acrobot/ChestShop/Config/Config.java index fb23109..a870e0d 100644 --- a/com/Acrobot/ChestShop/Config/Config.java +++ b/com/Acrobot/ChestShop/Config/Config.java @@ -1,66 +1,23 @@ package com.Acrobot.ChestShop.Config; -import com.Acrobot.ChestShop.ChestShop; -import com.Acrobot.ChestShop.Utils.uLongName; -import org.bukkit.util.config.Configuration; - -import java.io.File; -import java.io.FileWriter; +import com.LRFLEW.register.payment.forChestShop.Methods; /** * @author Acrobot */ public class Config { - private static final File configFile = new File(ChestShop.folder, "config.yml"); - private static final File langFile = new File(ChestShop.folder, "local.yml"); - private static final Configuration config = new Configuration(configFile); - private static final Configuration language = new Configuration(langFile); + private static ConfigObject config; - public static void setUp() { - if(!ChestShop.folder.exists()) ChestShop.folder.mkdir(); - - reloadConfig(); - config.load(); - - reloadLanguage(); - language.load(); - - uLongName.config.load(); - } - - private static void reloadConfig(){ - config.load(); - for (Property def : Property.values()) { - if (config.getProperty(def.name()) == null) { - writeToFile('\n' + def.name() + ": " + def.getValue() + "\n#" + def.getComment(), configFile); - } - } - } - - private static void reloadLanguage(){ - language.load(); - for (Language def : Language.values()) { - if (language.getProperty(def.name()) == null) { - writeToFile('\n' + def.name() + ": \"" + def.toString() + '\"', langFile); - } - } - } - - private static void writeToFile(String string, File file) { - try { - FileWriter fw = new FileWriter(file, true); - fw.write(string + '\n'); - fw.close(); - } catch (Exception e) { - System.out.println("Couldn't write to file - " + file.getName()); - } + public static void setup(ConfigObject cfg) { + config = cfg; + Methods.preferred = Config.getString(Property.PREFERRED_ECONOMY_PLUGIN); } public static boolean getBoolean(Property value) { return (Boolean) getValue(value.name()); } - public static float getFloat(Property value){ + public static float getFloat(Property value) { return new Float(getValue(value.name()).toString()); } @@ -73,7 +30,7 @@ public class Config { } public static double getDouble(Property value) { - return config.getDouble(value.name(), -1); + return Double.parseDouble(getValue(value.name()).toString()); } private static String getColored(String msg) { @@ -81,16 +38,10 @@ public class Config { } public static String getLocal(Language lang) { - return getColored(language.getString(Language.prefix.name()) + language.getString(lang.name())); + return getColored(config.getLanguageConfig().getString(Language.prefix.name()) + config.getLanguageConfig().getString(lang.name())); } 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/ConfigObject.java b/com/Acrobot/ChestShop/Config/ConfigObject.java new file mode 100644 index 0000000..ba7c548 --- /dev/null +++ b/com/Acrobot/ChestShop/Config/ConfigObject.java @@ -0,0 +1,67 @@ +package com.Acrobot.ChestShop.Config; + +import com.Acrobot.ChestShop.ChestShop; +import com.Acrobot.ChestShop.Utils.uLongName; +import org.bukkit.util.config.Configuration; + +import java.io.File; +import java.io.FileWriter; + +/** + * @author Acrobot + */ +public class ConfigObject { + private final File configFile = new File(ChestShop.folder, "config.yml"); + private final File langFile = new File(ChestShop.folder, "local.yml"); + private final Configuration config = new Configuration(configFile); + private final Configuration language = new Configuration(langFile); + + public ConfigObject() { + if (!ChestShop.folder.exists()) ChestShop.folder.mkdir(); + + reloadConfig(); + config.load(); + + reloadLanguage(); + language.load(); + + uLongName.config = new Configuration(new File(ChestShop.folder, "longName.storage")); + uLongName.config.load(); + } + + private void reloadConfig() { + config.load(); + for (Property def : Property.values()) { + if (config.getProperty(def.name()) == null) { + writeToFile('\n' + def.name() + ": " + def.getValue() + "\n#" + def.getComment(), configFile); + } + } + } + + private void reloadLanguage() { + language.load(); + for (Language def : Language.values()) { + if (language.getProperty(def.name()) == null) { + writeToFile('\n' + def.name() + ": \"" + def.toString() + '\"', langFile); + } + } + } + + private static void writeToFile(String string, File file) { + try { + FileWriter fw = new FileWriter(file, true); + fw.write(string); + fw.close(); + } catch (Exception e) { + System.out.println("Couldn't write to file - " + file.getName()); + } + } + + public Configuration getLanguageConfig() { + return language; + } + + public Object getProperty(String property) { + return config.getProperty(property); + } +} diff --git a/com/Acrobot/ChestShop/Config/Language.java b/com/Acrobot/ChestShop/Config/Language.java index 1dbb4f2..f32e53d 100644 --- a/com/Acrobot/ChestShop/Config/Language.java +++ b/com/Acrobot/ChestShop/Config/Language.java @@ -3,7 +3,7 @@ package com.Acrobot.ChestShop.Config; /** * @author Acrobot */ -public enum Language{ +public enum Language { prefix("&a[Shop] &f"), iteminfo("&aItem Information:&f"), diff --git a/com/Acrobot/ChestShop/Config/Property.java b/com/Acrobot/ChestShop/Config/Property.java index 1ec3e72..6c3910b 100644 --- a/com/Acrobot/ChestShop/Config/Property.java +++ b/com/Acrobot/ChestShop/Config/Property.java @@ -6,7 +6,8 @@ package com.Acrobot.ChestShop.Config; 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."), - //ALLOW_LEFT_CLICK_DESTROYING(false, "If true, if you left-click your own shop sign you won't open chest's inventory, but instead you will start destroying the sign."), + ALLOW_LEFT_CLICK_DESTROYING(true, "If true, if you left-click your own shop sign you won't open chest's inventory, but instead you will start destroying the sign."), + STACK_UNSTACKABLES(false, "If true, ALL things (including food, etc.) will stack up to 64"), 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"), SHOP_CREATION_PRICE(0, "Amount of money player must pay to create a shop"), diff --git a/com/Acrobot/ChestShop/Economy.java b/com/Acrobot/ChestShop/Economy.java index dc26753..6274c74 100644 --- a/com/Acrobot/ChestShop/Economy.java +++ b/com/Acrobot/ChestShop/Economy.java @@ -1,11 +1,11 @@ package com.Acrobot.ChestShop; import com.Acrobot.ChestShop.Utils.uLongName; -import com.nijikokun.register.payment.forChestShop.Method; +import com.LRFLEW.register.payment.forChestShop.Method; /** * @author Acrobot - * Economy management + * Economy management */ public class Economy { public static Method economy; diff --git a/com/Acrobot/ChestShop/Items/Items.java b/com/Acrobot/ChestShop/Items/Items.java index 80cb8ff..e5676ca 100644 --- a/com/Acrobot/ChestShop/Items/Items.java +++ b/com/Acrobot/ChestShop/Items/Items.java @@ -52,10 +52,10 @@ public class Items { return item == null ? null : new ItemStack(item, 1, Short.parseShort(word[1])); } - private static ItemStack getItemStackWithDataValueFromWord(String itemName){ + private static ItemStack getItemStackWithDataValueFromWord(String itemName) { int indexOfChar = itemName.indexOf(' '); - if(indexOfChar == -1) return null; + if (indexOfChar == -1) return null; Material item = getMaterial(itemName.substring(indexOfChar)); return item == null ? null : new ItemStack(item, 1, DataValue.get(itemName.substring(0, indexOfChar), item)); } diff --git a/com/Acrobot/ChestShop/Listeners/blockBreak.java b/com/Acrobot/ChestShop/Listeners/blockBreak.java index a78eaa1..12554b4 100644 --- a/com/Acrobot/ChestShop/Listeners/blockBreak.java +++ b/com/Acrobot/ChestShop/Listeners/blockBreak.java @@ -32,15 +32,15 @@ public class blockBreak extends BlockListener { if (cancellingBlockBreak(event.getBlock(), event.getPlayer())) event.setCancelled(true); } - private static boolean isCorrectSign(Sign sign, Block block){ + private static boolean isCorrectSign(Sign sign, Block block) { return sign.getBlock() == block || getAttachedFace(sign) == block; } - private static Block getAttachedFace(Sign sign){ + private static Block getAttachedFace(Sign sign) { return sign.getBlock().getRelative(((org.bukkit.material.Sign) sign.getData()).getAttachedFace()); } - private static boolean playerIsNotOwner(Player player, Sign sign){ + private static boolean playerIsNotOwner(Player player, Sign sign) { return player == null || !uLongName.stripName(player.getName()).equals(sign.getLine(0)); } diff --git a/com/Acrobot/ChestShop/Listeners/entityExplode.java b/com/Acrobot/ChestShop/Listeners/entityExplode.java index f923ede..a71fe52 100644 --- a/com/Acrobot/ChestShop/Listeners/entityExplode.java +++ b/com/Acrobot/ChestShop/Listeners/entityExplode.java @@ -7,11 +7,11 @@ import org.bukkit.event.entity.EntityListener; /** * @author Acrobot */ -public class entityExplode extends EntityListener{ - public void onEntityExplode(EntityExplodeEvent event){ +public class entityExplode extends EntityListener { + public void onEntityExplode(EntityExplodeEvent event) { if (event.isCancelled() || event.blockList() == null) return; - for(Block block : event.blockList()){ - if(blockBreak.cancellingBlockBreak(block, null)){ + for (Block block : event.blockList()) { + if (blockBreak.cancellingBlockBreak(block, null)) { event.setCancelled(true); return; } diff --git a/com/Acrobot/ChestShop/Listeners/playerInteract.java b/com/Acrobot/ChestShop/Listeners/playerInteract.java index 1a8acb9..17bb4ce 100644 --- a/com/Acrobot/ChestShop/Listeners/playerInteract.java +++ b/com/Acrobot/ChestShop/Listeners/playerInteract.java @@ -57,9 +57,9 @@ public class playerInteract extends PlayerListener { lastTransactionTime.put(player, System.currentTimeMillis()); - event.setCancelled(true); + if (action == Action.RIGHT_CLICK_BLOCK) event.setCancelled(true); - if (uLongName.stripName(player.getName()).equals(sign.getLine(0))) { + if (uLongName.stripName(player.getName()).equals(sign.getLine(0)) && (action != Action.LEFT_CLICK_BLOCK || !Config.getBoolean(Property.ALLOW_LEFT_CLICK_DESTROYING))) { showChestGUI(player, block); return; } @@ -68,7 +68,7 @@ public class playerInteract extends PlayerListener { player.sendMessage(Config.getLocal(Language.ACCESS_DENIED)); return; } - + Action buy = (Config.getBoolean(Property.REVERSE_BUTTONS) ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK); if (action == buy) { @@ -77,7 +77,7 @@ public class playerInteract extends PlayerListener { ShopManagement.sell(sign, player); } } - + private static boolean enoughTimeHasPassed(Player player) { return !lastTransactionTime.containsKey(player) || (System.currentTimeMillis() - lastTransactionTime.get(player)) >= interval; } diff --git a/com/Acrobot/ChestShop/Listeners/pluginDisable.java b/com/Acrobot/ChestShop/Listeners/pluginDisable.java index 026a50c..88b1545 100644 --- a/com/Acrobot/ChestShop/Listeners/pluginDisable.java +++ b/com/Acrobot/ChestShop/Listeners/pluginDisable.java @@ -1,6 +1,7 @@ package com.Acrobot.ChestShop.Listeners; import com.Acrobot.ChestShop.Economy; +import com.LRFLEW.register.payment.forChestShop.Methods; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.ServerListener; @@ -9,13 +10,9 @@ import org.bukkit.event.server.ServerListener; */ public class pluginDisable extends ServerListener { public void onPluginDisable(PluginDisableEvent event) { - if (Economy.economy != null && pluginEnable.methods.hasMethod()) { - boolean check = pluginEnable.methods.checkDisabled(event.getPlugin()); - - if (check) { - Economy.economy = null; - System.out.println("[ChestShop] Economy plugin disabled!"); - } + if (Economy.economy != null && Methods.hasMethod() && Methods.checkDisabled(event.getPlugin())) { + Economy.economy = null; + System.out.println("[ChestShop] Economy plugin disabled!"); } } } diff --git a/com/Acrobot/ChestShop/Listeners/pluginEnable.java b/com/Acrobot/ChestShop/Listeners/pluginEnable.java index d74b644..b375d6c 100644 --- a/com/Acrobot/ChestShop/Listeners/pluginEnable.java +++ b/com/Acrobot/ChestShop/Listeners/pluginEnable.java @@ -1,17 +1,17 @@ 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; +import com.Acrobot.ChestShop.Protection.Plugins.DeadboltPlugin; import com.Acrobot.ChestShop.Protection.Plugins.LWCplugin; import com.Acrobot.ChestShop.Protection.Plugins.LockettePlugin; -import com.Acrobot.ChestShop.Protection.Plugins.OldLockettePlugin; import com.Acrobot.ChestShop.Protection.Security; +import com.LRFLEW.register.payment.forChestShop.Methods; +import com.daemitus.deadbolt.Deadbolt; import com.griefcraft.lwc.LWCPlugin; import com.nijikokun.bukkit.Permissions.Permissions; -import com.nijikokun.register.payment.forChestShop.Methods; import info.somethingodd.bukkit.OddItem.OddItem; import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.ServerListener; @@ -19,47 +19,26 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.yi.acru.bukkit.Lockette.Lockette; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - /** * @author Acrobot */ public class pluginEnable extends ServerListener { - public static final Methods methods = new Methods(Config.getPreferred()); - - private static final List pluginsToLoad = new LinkedList(Arrays.asList( - "Permissions", - "LWC", - "Lockette", - "OddItem" - )); - public void onPluginEnable(PluginEnableEvent event) { - LinkedList toRemove = new LinkedList(); - - //Economy plugins - if (!methods.hasMethod()) { - if (methods.setMethod(event.getPlugin())) { - Economy.economy = methods.getMethod(); - System.out.println(ChestShop.chatPrefix + Economy.economy.getName() + ' ' + Economy.economy.getVersion() + " loaded."); - } + if (!Methods.hasMethod() && Methods.setMethod(ChestShop.pm)) { + Economy.economy = Methods.getMethod(); + System.out.println(ChestShop.chatPrefix + Economy.economy.getName() + ' ' + Economy.economy.getVersion() + " loaded."); } + } - for (String pluginName : pluginsToLoad) { - Plugin plugin = ChestShop.getBukkitServer().getPluginManager().getPlugin(pluginName); - if (plugin == null) continue; - initializePlugin(pluginName, plugin); - toRemove.add(pluginName); + public static void initializePlugins() { + for (Object plugin : ChestShop.getDependencies()) { + Plugin pl = ChestShop.pm.getPlugin((String) plugin); + if (pl != null) initializePlugin((String) plugin, pl); } - - for (String pluginName : toRemove) pluginsToLoad.remove(pluginName); } private static void initializePlugin(String name, Plugin plugin) { //Really messy, right? But it's short and fast :) - PluginDescriptionFile description = plugin.getDescription(); if (name.equals("Permissions")) { if (Permission.permissions != null) return; Permission.permissions = ((Permissions) plugin).getHandler(); @@ -68,18 +47,18 @@ public class pluginEnable extends ServerListener { LWCplugin.setLWC(((LWCPlugin) plugin).getLWC()); Security.protection = new LWCplugin(); } else if (name.equals("Lockette")) { - if (OldLockettePlugin.lockette != null || LockettePlugin.lockette != null) return; - if (plugin.getClass().getName().equals("com.daemitus.lockette.Lockette")) { - LockettePlugin.lockette = (com.daemitus.lockette.Lockette) plugin; - Security.protection = new LockettePlugin(); - } else { - OldLockettePlugin.lockette = (Lockette) plugin; - Security.protection = new OldLockettePlugin(); - } + if (LockettePlugin.lockette != null) return; + LockettePlugin.lockette = (Lockette) plugin; + Security.protection = new LockettePlugin(); + } else if (name.equals("Deadbolt")) { + if (DeadboltPlugin.deadbolt != null) return; + DeadboltPlugin.deadbolt = (Deadbolt) plugin; + Security.protection = new DeadboltPlugin(); } else if (name.equals("OddItem")) { if (Odd.oddItem != null) return; Odd.oddItem = (OddItem) plugin; } + PluginDescriptionFile description = plugin.getDescription(); System.out.println(ChestShop.chatPrefix + description.getName() + " version " + description.getVersion() + " loaded."); } } diff --git a/com/Acrobot/ChestShop/Logging/Logging.java b/com/Acrobot/ChestShop/Logging/Logging.java index 46e7f12..54c8f2e 100644 --- a/com/Acrobot/ChestShop/Logging/Logging.java +++ b/com/Acrobot/ChestShop/Logging/Logging.java @@ -27,7 +27,7 @@ public class Logging { } public static void log(String string) { - if (Config.getBoolean(Property.LOG_TO_CONSOLE)) logger.log(Level.INFO,"[ChestShop] " + string); + if (Config.getBoolean(Property.LOG_TO_CONSOLE)) logger.log(Level.INFO, "[ChestShop] " + string); if (Config.getBoolean(Property.LOG_TO_FILE)) FileWriterQueue.addToQueue(getDateAndTime() + ' ' + string); } @@ -36,7 +36,7 @@ public class Logging { if (Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) logToDatabase(isBuying, shop, player); } - private static void logToDatabase(boolean isBuying, Shop shop, Player player){ + private static void logToDatabase(boolean isBuying, Shop shop, Player player) { Transaction transaction = new Transaction(); transaction.setAmount(shop.stockAmount); diff --git a/com/Acrobot/ChestShop/Protection/Plugins/OldLockettePlugin.java b/com/Acrobot/ChestShop/Protection/Plugins/DeadboltPlugin.java similarity index 52% rename from com/Acrobot/ChestShop/Protection/Plugins/OldLockettePlugin.java rename to com/Acrobot/ChestShop/Protection/Plugins/DeadboltPlugin.java index be4540e..13929a4 100644 --- a/com/Acrobot/ChestShop/Protection/Plugins/OldLockettePlugin.java +++ b/com/Acrobot/ChestShop/Protection/Plugins/DeadboltPlugin.java @@ -1,23 +1,23 @@ package com.Acrobot.ChestShop.Protection.Plugins; import com.Acrobot.ChestShop.Protection.Protection; +import com.daemitus.deadbolt.Deadbolt; import org.bukkit.block.Block; import org.bukkit.entity.Player; -import org.yi.acru.bukkit.Lockette.Lockette; /** * @author Acrobot */ -public class OldLockettePlugin implements Protection { - public static Lockette lockette; +public class DeadboltPlugin implements Protection { + public static Deadbolt deadbolt; public boolean isProtected(Block block) { - return Lockette.isProtected(block); + return Deadbolt.isProtected(block); } public boolean canAccess(Player player, Block block) { - int length = (player.getName().length() > 15? 15 : player.getName().length()); - return player.getName().substring(0, length).equals(Lockette.getProtectedOwner(block)); + int length = (player.getName().length() > 15 ? 15 : player.getName().length()); + return Deadbolt.getAllNames(block).contains(player.getName().substring(0, length)); } public boolean protect(String name, Block block) { diff --git a/com/Acrobot/ChestShop/Protection/Plugins/Default.java b/com/Acrobot/ChestShop/Protection/Plugins/Default.java index 9bcefa0..fad3103 100644 --- a/com/Acrobot/ChestShop/Protection/Plugins/Default.java +++ b/com/Acrobot/ChestShop/Protection/Plugins/Default.java @@ -15,20 +15,20 @@ public class Default implements Protection { public boolean isProtected(Block block) { if (!(block.getState() instanceof Chest)) return false; if (uBlock.findSign(block) != null) return true; - + Chest neighbor = uBlock.findNeighbor(block); return neighbor != null && uBlock.findSign(neighbor.getBlock()) != null; } public boolean canAccess(Player player, Block block) { String playerName = player.getName(); - + Sign sign = uBlock.findSign(block); - if(sign != null) return uLongName.stripName(playerName).equals(sign.getLine(0)); + if (sign != null) return uLongName.stripName(playerName).equals(sign.getLine(0)); Chest neighborChest = uBlock.findNeighbor(block); Sign neighborSign = (neighborChest != null ? uBlock.findSign(neighborChest.getBlock()) : null); - + return neighborSign != null && uLongName.stripName(playerName).equals(neighborSign.getLine(0)); } diff --git a/com/Acrobot/ChestShop/Protection/Plugins/LWCplugin.java b/com/Acrobot/ChestShop/Protection/Plugins/LWCplugin.java index c92514d..09a92dd 100644 --- a/com/Acrobot/ChestShop/Protection/Plugins/LWCplugin.java +++ b/com/Acrobot/ChestShop/Protection/Plugins/LWCplugin.java @@ -5,7 +5,6 @@ import com.Acrobot.ChestShop.Protection.Protection; import com.griefcraft.lwc.LWC; import com.griefcraft.model.ProtectionTypes; import com.griefcraft.modules.limits.LimitsModule; -import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; diff --git a/com/Acrobot/ChestShop/Protection/Plugins/LockettePlugin.java b/com/Acrobot/ChestShop/Protection/Plugins/LockettePlugin.java index 962093a..271ec5d 100644 --- a/com/Acrobot/ChestShop/Protection/Plugins/LockettePlugin.java +++ b/com/Acrobot/ChestShop/Protection/Plugins/LockettePlugin.java @@ -1,9 +1,9 @@ package com.Acrobot.ChestShop.Protection.Plugins; import com.Acrobot.ChestShop.Protection.Protection; -import com.daemitus.lockette.Lockette; import org.bukkit.block.Block; import org.bukkit.entity.Player; +import org.yi.acru.bukkit.Lockette.Lockette; /** * @author Acrobot @@ -16,8 +16,8 @@ public class LockettePlugin implements Protection { } public boolean canAccess(Player player, Block block) { - int length = (player.getName().length() > 15? 15 : player.getName().length()); - return player.getName().substring(0, length).equals(Lockette.getOwnerName(block)); + int length = (player.getName().length() > 15 ? 15 : player.getName().length()); + return player.getName().substring(0, length).equals(Lockette.getProtectedOwner(block)); } public boolean protect(String name, Block block) { diff --git a/com/Acrobot/ChestShop/Signs/restrictedSign.java b/com/Acrobot/ChestShop/Signs/restrictedSign.java index cbe4d3c..170f3fc 100644 --- a/com/Acrobot/ChestShop/Signs/restrictedSign.java +++ b/com/Acrobot/ChestShop/Signs/restrictedSign.java @@ -27,14 +27,15 @@ public class restrictedSign { public static boolean canAccess(Sign sign, Player player) { Block blockUp = sign.getBlock().getRelative(BlockFace.UP); if (Permission.permissions == null || !uSign.isSign(blockUp) || Permission.has(player, Permission.ADMIN)) return true; - + String world = blockUp.getWorld().getName(); String playerName = player.getName(); sign = (Sign) blockUp.getState(); for (int i = 1; i <= 3; i++) { - if(Permission.permissions.inGroup(world, playerName, sign.getLine(i))) return true; + if (Permission.permissions != null && Permission.permissions.inGroup(world, playerName, sign.getLine(i))) return true; + if (player.hasPermission("ChestShop.group." + sign.getLine(i))) return true; } return false; } diff --git a/com/Acrobot/ChestShop/Utils/uInventory.java b/com/Acrobot/ChestShop/Utils/uInventory.java index 823f3f9..ad72a3b 100644 --- a/com/Acrobot/ChestShop/Utils/uInventory.java +++ b/com/Acrobot/ChestShop/Utils/uInventory.java @@ -1,5 +1,7 @@ package com.Acrobot.ChestShop.Utils; +import com.Acrobot.ChestShop.Config.Config; +import com.Acrobot.ChestShop.Config.Property; import org.bukkit.Material; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -10,7 +12,7 @@ import java.util.HashMap; * @author Acrobot */ public class uInventory { - + public static int remove(Inventory inv, ItemStack item, int amount, short durability) { amount = (amount > 0 ? amount : 1); Material itemMaterial = item.getType(); @@ -45,13 +47,29 @@ public class uInventory { public static int add(Inventory inv, ItemStack item, int amount) { amount = (amount > 0 ? amount : 1); - - ItemStack itemToAdd = new ItemStack(item.getType(), amount, item.getDurability()); - HashMap items = inv.addItem(itemToAdd); - + if (Config.getBoolean(Property.STACK_UNSTACKABLES)) return addAndStackTo64(inv, item, amount); + HashMap items = inv.addItem(new ItemStack(item.getType(), amount, item.getDurability())); amount = 0; - for(ItemStack toAdd : items.values()){ - amount += toAdd.getAmount(); + for (ItemStack toAdd : items.values()) amount += toAdd.getAmount(); + + return amount; + } + + public static int addAndStackTo64(Inventory inv, ItemStack item, int amount) { + Material type = item.getType(); + for (int slot = 0; slot < inv.getSize(); slot++) { + if (amount <= 0) return 0; + ItemStack curItem = inv.getItem(slot); + if (curItem == null || curItem.getType() == Material.AIR) { + item.setAmount((amount > 64 ? 64 : amount)); + amount -= item.getAmount(); + inv.setItem(slot, item); + } else if (curItem.getType() == type && curItem.getDurability() == item.getDurability() && curItem.getAmount() != 64) { + int toFill = (64 - curItem.getAmount()); + item.setAmount((amount > toFill ? 64 : curItem.getAmount() + amount)); + amount -= item.getAmount(); + inv.setItem(slot, item); + } } return amount; } @@ -68,7 +86,7 @@ public class uInventory { public static int fits(Inventory inv, ItemStack item, int amount, short durability) { Material itemMaterial = item.getType(); - int maxStackSize = itemMaterial.getMaxStackSize(); + int maxStackSize = (Config.getBoolean(Property.STACK_UNSTACKABLES) ? 64 : itemMaterial.getMaxStackSize()); int amountLeft = amount; for (ItemStack currentItem : inv.getContents()) { diff --git a/com/Acrobot/ChestShop/Utils/uLongName.java b/com/Acrobot/ChestShop/Utils/uLongName.java index b6840c8..350a050 100644 --- a/com/Acrobot/ChestShop/Utils/uLongName.java +++ b/com/Acrobot/ChestShop/Utils/uLongName.java @@ -9,7 +9,7 @@ import java.io.File; * @author Acrobot */ public class uLongName { - public static final Configuration config = new Configuration(new File(ChestShop.folder, "longName.storage")); + public static Configuration config = new Configuration(new File(ChestShop.folder, "longName.storage")); public static String getName(final String shortName) { return config.getString(shortName, shortName); diff --git a/com/Acrobot/ChestShop/Utils/uSign.java b/com/Acrobot/ChestShop/Utils/uSign.java index 179697d..b24548c 100644 --- a/com/Acrobot/ChestShop/Utils/uSign.java +++ b/com/Acrobot/ChestShop/Utils/uSign.java @@ -17,7 +17,7 @@ public class uSign { Pattern.compile(".+"), Pattern.compile("[\\w :]+") }; - + public static boolean isSign(Block block) { return block.getState() instanceof Sign; } @@ -38,12 +38,12 @@ public class uSign { } } - public static boolean isValidPreparedSign(String[] lines){ - try{ + public static boolean isValidPreparedSign(String[] lines) { + try { boolean toReturn = true; - for(int i = 0; i < 4 && toReturn; i++) toReturn = patterns[i].matcher(lines[i]).matches(); + for (int i = 0; i < 4 && toReturn; i++) toReturn = patterns[i].matcher(lines[i]).matches(); return toReturn && lines[2].split(":").length <= 2; - } catch (Exception e){ + } catch (Exception e) { return false; } } @@ -56,13 +56,13 @@ public class uSign { return price(text, false); } - private static float price(String text, boolean buy){ + private static float price(String text, boolean buy) { String toContain = buy ? "b" : "s"; text = text.replace(" ", "").toLowerCase(); String[] split = text.split(":"); int part = (text.contains(toContain) ? (split[0].contains(toContain) ? 0 : 1) : -1); - if(part == -1 || (part == 1 && split.length != 2)) return -1; + if (part == -1 || (part == 1 && split.length != 2)) return -1; split[part] = split[part].replace(toContain, ""); diff --git a/com/nijikokun/register/payment/forChestShop/Method.java b/com/LRFLEW/register/payment/forChestShop/Method.java similarity index 94% rename from com/nijikokun/register/payment/forChestShop/Method.java rename to com/LRFLEW/register/payment/forChestShop/Method.java index 91ff226..f23caed 100644 --- a/com/nijikokun/register/payment/forChestShop/Method.java +++ b/com/LRFLEW/register/payment/forChestShop/Method.java @@ -1,4 +1,4 @@ -package com.nijikokun.register.payment.forChestShop; +package com.LRFLEW.register.payment.forChestShop; import org.bukkit.plugin.Plugin; @@ -38,7 +38,14 @@ 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(); /** * Formats amounts into this payment methods style of currency display. diff --git a/com/LRFLEW/register/payment/forChestShop/Methods.java b/com/LRFLEW/register/payment/forChestShop/Methods.java new file mode 100644 index 0000000..f7cb558 --- /dev/null +++ b/com/LRFLEW/register/payment/forChestShop/Methods.java @@ -0,0 +1,205 @@ +package com.LRFLEW.register.payment.forChestShop; + +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; + +import java.util.HashSet; +import java.util.Set; + +/** + * 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 server.properties: + *

+ *  economy=iConomy
+ * 
+ * + * @author: Nijikokun (@nijikokun) + * @copyright: Copyright (C) 2011 + * @license: AOL license + */ +public class Methods { + private static String version = null; + private static boolean self = false; + private static Method Method = null; + public static String preferred = ""; + private static Set Methods = new HashSet(); + private static Set Dependencies = new HashSet(); + private static Set Attachables = new HashSet(); + + static { _init(); } + + /** + * Implement all methods along with their respective name & class. + */ + private static void _init() { + addMethod("iConomy", new com.LRFLEW.register.payment.forChestShop.methods.iCo6()); + addMethod("iConomy", new com.LRFLEW.register.payment.forChestShop.methods.iCo5()); + addMethod("iConomy", new com.LRFLEW.register.payment.forChestShop.methods.iCo4()); + addMethod("BOSEconomy", new com.LRFLEW.register.payment.forChestShop.methods.BOSE6()); + addMethod("BOSEconomy", new com.LRFLEW.register.payment.forChestShop.methods.BOSE7()); + addMethod("Essentials", new com.LRFLEW.register.payment.forChestShop.methods.EE17()); + addMethod("Currency", new com.LRFLEW.register.payment.forChestShop.methods.MCUR()); + Dependencies.add("MultiCurrency"); + } + + /** + * 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 _init method. + * + * @return Set - Array of payment methods that are loaded. + */ + public static Set 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 or 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 boolean + * @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. + * + * @return boolean 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; + + for (String name : Dependencies) { + if (hasMethod()) break; + plugin = manager.getPlugin(name); + if (plugin == null) 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(); + } + + /** + * Grab the existing and initialized (hopefully) Method Class. + * + * @return Method or Null + */ + 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 boolean + */ + public static boolean checkDisabled(Plugin method) { + if (!hasMethod()) return true; + if (Method.isCompatible(method)) Method = null; + return (Method == null); + } +} diff --git a/com/nijikokun/register/payment/forChestShop/methods/BOSE6.java b/com/LRFLEW/register/payment/forChestShop/methods/BOSE6.java similarity index 96% rename from com/nijikokun/register/payment/forChestShop/methods/BOSE6.java rename to com/LRFLEW/register/payment/forChestShop/methods/BOSE6.java index 3be44e4..fe68890 100644 --- a/com/nijikokun/register/payment/forChestShop/methods/BOSE6.java +++ b/com/LRFLEW/register/payment/forChestShop/methods/BOSE6.java @@ -1,6 +1,7 @@ -package com.nijikokun.register.payment.forChestShop.methods; +package com.LRFLEW.register.payment.forChestShop.methods; + +import com.LRFLEW.register.payment.forChestShop.Method; -import com.nijikokun.register.payment.forChestShop.Method; import cosine.boseconomy.BOSEconomy; import org.bukkit.plugin.Plugin; @@ -11,7 +12,7 @@ import org.bukkit.plugin.Plugin; * @copyright (c) 2011 * @license AOL license */ -@SuppressWarnings({"deprecation"}) +@SuppressWarnings("deprecation") public class BOSE6 implements Method { private BOSEconomy BOSEconomy; @@ -26,6 +27,10 @@ public class BOSE6 implements Method { public String getVersion() { return "0.6.2"; } + + public int fractionalDigits() { + return 0; + } public String format(double amount) { String currency = this.BOSEconomy.getMoneyNamePlural(); @@ -76,7 +81,7 @@ public class BOSE6 implements Method { this.BOSEconomy = bOSEconomy; } - public double balance() { + public double balance() { return (double) this.BOSEconomy.getPlayerMoney(this.name); } diff --git a/com/nijikokun/register/payment/forChestShop/methods/BOSE7.java b/com/LRFLEW/register/payment/forChestShop/methods/BOSE7.java similarity index 93% rename from com/nijikokun/register/payment/forChestShop/methods/BOSE7.java rename to com/LRFLEW/register/payment/forChestShop/methods/BOSE7.java index 1e31447..b0bee2a 100644 --- a/com/nijikokun/register/payment/forChestShop/methods/BOSE7.java +++ b/com/LRFLEW/register/payment/forChestShop/methods/BOSE7.java @@ -1,6 +1,7 @@ -package com.nijikokun.register.payment.forChestShop.methods; +package com.LRFLEW.register.payment.forChestShop.methods; + +import com.LRFLEW.register.payment.forChestShop.Method; -import com.nijikokun.register.payment.forChestShop.Method; import cosine.boseconomy.BOSEconomy; import org.bukkit.plugin.Plugin; @@ -26,6 +27,10 @@ public class BOSE7 implements Method { public String getVersion() { return "0.7.0"; } + + public int fractionalDigits() { + return this.BOSEconomy.getFractionalDigits(); + } public String format(double amount) { String currency = this.BOSEconomy.getMoneyNamePlural(); @@ -68,8 +73,8 @@ public class BOSE7 implements Method { } public static class BOSEAccount implements MethodAccount { - private final String name; - private final BOSEconomy BOSEconomy; + private String name; + private BOSEconomy BOSEconomy; public BOSEAccount(String name, BOSEconomy bOSEconomy) { this.name = name; @@ -125,8 +130,8 @@ public class BOSE7 implements Method { } public static class BOSEBankAccount implements MethodBankAccount { - private final String bank; - private final BOSEconomy BOSEconomy; + private String bank; + private BOSEconomy BOSEconomy; public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) { this.bank = bank; diff --git a/com/nijikokun/register/payment/forChestShop/methods/EE17.java b/com/LRFLEW/register/payment/forChestShop/methods/EE17.java similarity index 96% rename from com/nijikokun/register/payment/forChestShop/methods/EE17.java rename to com/LRFLEW/register/payment/forChestShop/methods/EE17.java index 1c0d89d..c4fed2e 100644 --- a/com/nijikokun/register/payment/forChestShop/methods/EE17.java +++ b/com/LRFLEW/register/payment/forChestShop/methods/EE17.java @@ -1,11 +1,11 @@ -package com.nijikokun.register.payment.forChestShop.methods; +package com.LRFLEW.register.payment.forChestShop.methods; +import com.LRFLEW.register.payment.forChestShop.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; @@ -33,6 +33,10 @@ public class EE17 implements Method { public String getVersion() { return "2.2"; } + + public int fractionalDigits() { + return -1; + } public String format(double amount) { return Economy.format(amount); @@ -75,7 +79,7 @@ public class EE17 implements Method { } public static class EEcoAccount implements MethodAccount { - private final String name; + private String name; public EEcoAccount(String name) { this.name = name; diff --git a/com/nijikokun/register/payment/forChestShop/methods/MCUR.java b/com/LRFLEW/register/payment/forChestShop/methods/MCUR.java similarity index 85% rename from com/nijikokun/register/payment/forChestShop/methods/MCUR.java rename to com/LRFLEW/register/payment/forChestShop/methods/MCUR.java index b053a84..cd64a4d 100644 --- a/com/nijikokun/register/payment/forChestShop/methods/MCUR.java +++ b/com/LRFLEW/register/payment/forChestShop/methods/MCUR.java @@ -1,6 +1,6 @@ -package com.nijikokun.register.payment.forChestShop.methods; +package com.LRFLEW.register.payment.forChestShop.methods; -import com.nijikokun.register.payment.forChestShop.Method; +import com.LRFLEW.register.payment.forChestShop.Method; import me.ashtheking.currency.Currency; import me.ashtheking.currency.CurrencyList; @@ -22,12 +22,16 @@ public class MCUR implements Method { } public String getName() { - return "Currency"; + return "MultiCurrency"; } public String getVersion() { return "0.09"; } + + public int fractionalDigits() { + return -1; + } public String format(double amount) { return amount + " Currency"; @@ -58,7 +62,9 @@ public class MCUR implements Method { } public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase(getName()) && plugin instanceof Currency; + return (plugin.getDescription().getName().equalsIgnoreCase("Currency") + || plugin.getDescription().getName().equalsIgnoreCase("MultiCurrency")) + && plugin instanceof Currency; } public void setPlugin(Plugin plugin) { @@ -66,7 +72,7 @@ public class MCUR implements Method { } public static class MCurrencyAccount implements MethodAccount{ - private final String name; + private String name; public MCurrencyAccount(String name) { this.name = name; diff --git a/com/nijikokun/register/payment/forChestShop/methods/iCo4.java b/com/LRFLEW/register/payment/forChestShop/methods/iCo4.java similarity index 83% rename from com/nijikokun/register/payment/forChestShop/methods/iCo4.java rename to com/LRFLEW/register/payment/forChestShop/methods/iCo4.java index 11a5f2c..101e857 100644 --- a/com/nijikokun/register/payment/forChestShop/methods/iCo4.java +++ b/com/LRFLEW/register/payment/forChestShop/methods/iCo4.java @@ -1,9 +1,9 @@ -package com.nijikokun.register.payment.forChestShop.methods; +package com.LRFLEW.register.payment.forChestShop.methods; +import com.LRFLEW.register.payment.forChestShop.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; @@ -28,9 +28,13 @@ public class iCo4 implements Method { public String getVersion() { return "4"; } + + public int fractionalDigits() { + return 2; + } - public String format(double amount) { - return iConomy.getBank().format(amount); + public String format(double amount) { + return com.nijiko.coelho.iConomy.iConomy.getBank().format(amount); } public boolean hasBanks() { @@ -42,7 +46,7 @@ public class iCo4 implements Method { } public boolean hasAccount(String name) { - return iConomy.getBank().hasAccount(name); + return com.nijiko.coelho.iConomy.iConomy.getBank().hasAccount(name); } public boolean hasBankAccount(String bank, String name) { @@ -50,7 +54,7 @@ public class iCo4 implements Method { } public MethodAccount getAccount(String name) { - return new iCoAccount(iConomy.getBank().getAccount(name)); + return new iCoAccount(com.nijiko.coelho.iConomy.iConomy.getBank().getAccount(name)); } public MethodBankAccount getBankAccount(String bank, String name) { @@ -58,7 +62,9 @@ public class iCo4 implements Method { } public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && !plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin.getDescription().getVersion().length() > 0 && plugin.getDescription().getVersion().charAt(0) == '4' && 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) { diff --git a/com/nijikokun/register/payment/forChestShop/methods/iCo5.java b/com/LRFLEW/register/payment/forChestShop/methods/iCo5.java similarity index 87% rename from com/nijikokun/register/payment/forChestShop/methods/iCo5.java rename to com/LRFLEW/register/payment/forChestShop/methods/iCo5.java index 52b3806..4e95385 100644 --- a/com/nijikokun/register/payment/forChestShop/methods/iCo5.java +++ b/com/LRFLEW/register/payment/forChestShop/methods/iCo5.java @@ -1,12 +1,12 @@ -package com.nijikokun.register.payment.forChestShop.methods; +package com.LRFLEW.register.payment.forChestShop.methods; +import com.LRFLEW.register.payment.forChestShop.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; @@ -31,9 +31,13 @@ public class iCo5 implements Method { public String getVersion() { return "5"; } + + public int fractionalDigits() { + return 2; + } - public String format(double amount) { - return iConomy.format(amount); + public String format(double amount) { + return com.iConomy.iConomy.format(amount); } public boolean hasBanks() { @@ -41,27 +45,29 @@ public class iCo5 implements Method { } public boolean hasBank(String bank) { - return (hasBanks()) && this.iConomy.Banks.exists(bank); + return (hasBanks()) && com.iConomy.iConomy.Banks.exists(bank); } public boolean hasAccount(String name) { - return this.iConomy.hasAccount(name); + return com.iConomy.iConomy.hasAccount(name); } public boolean hasBankAccount(String bank, String name) { - return (hasBank(bank)) && this.iConomy.getBank(bank).hasAccount(name); + return (hasBank(bank)) && com.iConomy.iConomy.getBank(bank).hasAccount(name); } public MethodAccount getAccount(String name) { - return new iCoAccount(this.iConomy.getAccount(name)); + return new iCoAccount(com.iConomy.iConomy.getAccount(name)); } public MethodBankAccount getBankAccount(String bank, String name) { - return new iCoBankAccount(this.iConomy.getBank(bank).getAccount(name)); + return new iCoBankAccount(com.iConomy.iConomy.getBank(bank).getAccount(name)); } 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) { diff --git a/com/nijikokun/register/payment/forChestShop/methods/iCo6.java b/com/LRFLEW/register/payment/forChestShop/methods/iCo6.java similarity index 86% rename from com/nijikokun/register/payment/forChestShop/methods/iCo6.java rename to com/LRFLEW/register/payment/forChestShop/methods/iCo6.java index b523201..10603ad 100644 --- a/com/nijikokun/register/payment/forChestShop/methods/iCo6.java +++ b/com/LRFLEW/register/payment/forChestShop/methods/iCo6.java @@ -1,11 +1,11 @@ -package com.nijikokun.register.payment.forChestShop.methods; +package com.LRFLEW.register.payment.forChestShop.methods; +import com.LRFLEW.register.payment.forChestShop.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; @@ -30,9 +30,13 @@ public class iCo6 implements Method { public String getVersion() { return "6"; } + + public int fractionalDigits() { + return 2; + } - public String format(double amount) { - return iConomy.format(amount); + public String format(double amount) { + return com.iCo6.iConomy.format(amount); } public boolean hasBanks() { @@ -60,10 +64,9 @@ public class iCo6 implements Method { } public boolean isCompatible(Plugin plugin) { - try { Class.forName("com.iCo6.IO.InventoryDB"); } - catch(Exception e) {return false;} - - 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) { @@ -71,8 +74,8 @@ public class iCo6 implements Method { } public static class iCoAccount implements MethodAccount { - private final Account account; - private final Holdings holdings; + private Account account; + private Holdings holdings; public iCoAccount(Account account) { this.account = account; diff --git a/com/nijikokun/register/payment/forChestShop/Methods.java b/com/nijikokun/register/payment/forChestShop/Methods.java deleted file mode 100644 index 5fa1580..0000000 --- a/com/nijikokun/register/payment/forChestShop/Methods.java +++ /dev/null @@ -1,203 +0,0 @@ -package com.nijikokun.register.payment.forChestShop; - -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; - -import java.util.HashSet; -import java.util.Set; - -/** - * 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 methods = new Methods();
- * 
- * - * Methods also allows you to set a preferred method of payment before it captures - * payment plugins in the initialization process. - * - *
- *  Methods methods = new Methods("iConomy");
- * 
- * - * @author: Nijikokun (@nijikokun) - * @copyright: Copyright (C) 2011 - * @license: AOL license - */ -public class Methods { - private boolean self = false; - private Method Method = null; - private String preferred = ""; - private final Set Methods = new HashSet(); - private final Set Dependencies = new HashSet(); - private final Set Attachables = new HashSet(); - - /** - * Initialize Method class - */ - public Methods() { - this._init(); - } - - /** - * Initializes Methods class utilizing a "preferred" payment method check before - * returning the first method that was initialized. - * - * @param preferred Payment method that is most preferred for this setup. - */ - public Methods(String preferred) { - this._init(); - - if(this.Dependencies.contains(preferred)) { - this.preferred = preferred; - } - } - - /** - * Implement all methods along with their respective name & class. - * - * @see #Methods() - * @see #Methods(java.lang.String) - */ - private void _init() { - this.addMethod("iConomy", new com.nijikokun.register.payment.forChestShop.methods.iCo6()); - this.addMethod("iConomy", new com.nijikokun.register.payment.forChestShop.methods.iCo5()); - this.addMethod("iConomy", new com.nijikokun.register.payment.forChestShop.methods.iCo4()); - this.addMethod("BOSEconomy", new com.nijikokun.register.payment.forChestShop.methods.BOSE6()); - this.addMethod("BOSEconomy", new com.nijikokun.register.payment.forChestShop.methods.BOSE7()); - this.addMethod("Essentials", new com.nijikokun.register.payment.forChestShop.methods.EE17()); - this.addMethod("MultiCurrency", new com.nijikokun.register.payment.forChestShop.methods.MCUR()); - } - - /** - * Returns an array of payment method names that have been loaded - * through the _init method. - * - * @return Set - Array of payment methods that are loaded. - * @see #setMethod(org.bukkit.plugin.Plugin) - */ - public Set 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 or Null - */ - public Method createMethod(Plugin plugin) { - for (Method method: Methods) { - if (method.isCompatible(plugin)) { - method.setPlugin(plugin); - return method; - } - } - - return null; - } - - private void addMethod(String name, Method method) { - Dependencies.add(name); - Methods.add(method); - } - - /** - * 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 boolean hasMethod() { - return (Method != null); - } - - /** - * Checks Plugin Class against a multitude of checks to verify it's usability - * as a payment method. - * - * @param method Plugin data from bukkit, Internal Class file. - * @return boolean True on success, False on failure. - */ - public boolean setMethod(Plugin method) { - if(hasMethod()) return true; - if(self) { self = false; return false; } - - int count = 0; - boolean match = false; - Plugin plugin; - PluginManager manager = method.getServer().getPluginManager(); - - for(String name: this.Dependencies) { - if(hasMethod()) break; - if(method.getDescription().getName().equals(name)) plugin = method; else plugin = manager.getPlugin(name); - if(plugin == null) continue; - - Method current = this.createMethod(plugin); - if(current == null) continue; - - if(this.preferred.isEmpty()) - this.Method = current; - else { - this.Attachables.add(current); - } - } - - if(!this.preferred.isEmpty()) { - do { - if(hasMethod()) { - match = true; - } else { - for(Method attached: this.Attachables) { - if(attached == null) continue; - - if(hasMethod()) { - match = true; - break; - } - - if(this.preferred.isEmpty()) this.Method = attached; - - if(count == 0) { - if(this.preferred.equalsIgnoreCase(attached.getName())) - this.Method = attached; - } else { - this.Method = attached; - } - } - - count++; - } - } while(!match); - } - - return hasMethod(); - } - - /** - * Grab the existing and initialized (hopefully) Method Class. - * - * @return Method or Null - */ - public 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 boolean - */ - public boolean checkDisabled(Plugin method) { - if(!hasMethod()) return true; - if (Method.isCompatible(method)) Method = null; - return (Method == null); - } -} diff --git a/plugin.yml b/plugin.yml index 421eae8..5292a4e 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,12 +2,15 @@ name: ChestShop main: com.Acrobot.ChestShop.ChestShop -version: 3.04 +version: 3.1 author: Acrobot description: > A chest shop for economy plugins. + + +softdepend: [Permissions, LWC, Lockette, Deadbolt, OddItem] commands: iteminfo: aliases: [iinfo]