diff --git a/com/Acrobot/ChestShop/ChestShop.java b/com/Acrobot/ChestShop/ChestShop.java index 5ab560b..04e7835 100644 --- a/com/Acrobot/ChestShop/ChestShop.java +++ b/com/Acrobot/ChestShop/ChestShop.java @@ -4,6 +4,7 @@ import com.Acrobot.ChestShop.Commands.ItemInfo; import com.Acrobot.ChestShop.Commands.Options; import com.Acrobot.ChestShop.Commands.Version; import com.Acrobot.ChestShop.Config.Config; +import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.DB.Generator; import com.Acrobot.ChestShop.DB.Queue; import com.Acrobot.ChestShop.DB.Transaction; @@ -33,8 +34,9 @@ public class ChestShop extends JavaPlugin { private final blockBreak blockBreak = new blockBreak(); private final blockPlace blockPlace = new blockPlace(); private final signChange signChange = new signChange(); - + private final pluginDisable pluginDisable = new pluginDisable(); private final playerInteract playerInteract = new playerInteract(); + public static File folder; public static EbeanServer db; @@ -50,6 +52,7 @@ public class ChestShop extends JavaPlugin { pm.registerEvent(Event.Type.SIGN_CHANGE, signChange, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_INTERACT, playerInteract, Event.Priority.Highest, this); pm.registerEvent(Event.Type.PLUGIN_ENABLE, pluginEnable, Event.Priority.Monitor, this); + pm.registerEvent(Event.Type.PLUGIN_DISABLE, pluginDisable, Event.Priority.Monitor, this); desc = this.getDescription(); server = getServer(); @@ -62,18 +65,18 @@ public class ChestShop extends JavaPlugin { //Now set up our database for storing transactions! setupDBfile(); - if (Config.getBoolean("useDB")) { + if (Config.getBoolean(Property.USE_DATABASE)) { setupDB(); getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Queue(), 200L, 200L); - if (Config.getBoolean("generateStatisticsPage")) { + if (Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) { getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Generator(), 300L, 300L); } db = getDatabase(); } //Now set up our logging to file! - if (Config.getBoolean("logToFile")) { + if (Config.getBoolean(Property.LOG_TO_FILE)) { getServer().getScheduler().scheduleAsyncRepeatingTask(this, new FileWriterQueue(), 201L, 201L); } diff --git a/com/Acrobot/ChestShop/Commands/ItemInfo.java b/com/Acrobot/ChestShop/Commands/ItemInfo.java index cab9489..749c403 100644 --- a/com/Acrobot/ChestShop/Commands/ItemInfo.java +++ b/com/Acrobot/ChestShop/Commands/ItemInfo.java @@ -1,6 +1,7 @@ package com.Acrobot.ChestShop.Commands; import com.Acrobot.ChestShop.Config.Config; +import com.Acrobot.ChestShop.Config.Language; import com.Acrobot.ChestShop.Items.Items; import org.bukkit.Material; import org.bukkit.command.Command; @@ -28,7 +29,7 @@ public class ItemInfo implements CommandExecutor { return false; } - player.sendMessage(Config.getLocal("iteminfo")); + player.sendMessage(Config.getLocal(Language.iteminfo)); player.sendMessage(itemInHand.getTypeId() + ":" + itemInHand.getDurability() + " - " + itemInHand.getType().name()); return true; @@ -39,7 +40,7 @@ public class ItemInfo implements CommandExecutor { return false; } - sender.sendMessage(Config.getLocal("iteminfo")); + sender.sendMessage(Config.getLocal(Language.iteminfo)); sender.sendMessage(item.getTypeId() + ":" + item.getDurability() + " - " + item.getType().name()); return true; diff --git a/com/Acrobot/ChestShop/Config/Config.java b/com/Acrobot/ChestShop/Config/Config.java index 55b4ca6..9321b49 100644 --- a/com/Acrobot/ChestShop/Config/Config.java +++ b/com/Acrobot/ChestShop/Config/Config.java @@ -18,12 +18,11 @@ public class Config { private static Configuration language = new Configuration(langFile); public static HashMap defaultValues = new HashMap(); - private static String langChar = Character.toString((char) 167); public static void setUp() { config.load(); - for (DefaultValue def : DefaultValue.values()){ + for (Property def : com.Acrobot.ChestShop.Config.Property.values()){ if(config.getProperty(def.name()) == null){ writeToFile(def.name() + ": " + def.getValue() + " #" + def.getComment(), configFile); } @@ -31,14 +30,12 @@ public class Config { config.load(); language.load(); - for (DefaultLanguage def : DefaultLanguage.values()) { + for (Language def : Language.values()) { if (language.getProperty(def.name()) == null) { - writeToFile(def.name() + ": \"" + def.toString() + "\"", langFile); + writeToFile(def.name() + ": \"" + def.toString() + '\"', langFile); } } language.load(); - - } public static void writeToFile(String string, File file) { @@ -51,47 +48,31 @@ public class Config { } } - public static boolean getBoolean(String node) { - return (Boolean) getValue(node); + public static boolean getBoolean(Property value){ + return (Boolean) getValue(value.name()); } - public static String getString(String node) { - return getColored((String) getValue(node)); + public static String getString(Property value){ + return getColored((String) getValue(value.name())); } - public static int getInteger(String node) { - return Integer.parseInt(getValue(node).toString()); + public static int getInteger(Property value){ + return Integer.parseInt(getValue(value.name()).toString()); } - public static double getDouble(String node) { - return config.getDouble(node, -1); - } - - private static Object getValue(String node, Configuration configuration, File file) { - if (configuration.getProperty(node) == null) { - writeToFile(DefaultLanguage.lookup(node).toString(), file); - configuration.load(); - } - return configuration.getProperty(node); + public static double getDouble(Property value){ + return config.getDouble(value.name(), -1); } public static String getColored(String msg) { - return msg.replaceAll("&", langChar); + return msg.replaceAll("&([0-9a-f])", "\u00A7$1"); } - public static String getLocal(String node) { - return getColored(getDefaultLocal("prefix") + (String) getDefaultLocal(node)); + public static String getLocal(Language lang) { + return getColored(language.getString(Language.prefix.name()) + language.getString(lang.name())); } private static Object getValue(String node) { - return getValue(node, config, configFile); - } - - private static Object getDefaultLocal(String node) { - if (language.getProperty(node) == null) { - writeToFile(DefaultLanguage.lookup(node).toString(), langFile); - language.load(); - } - return language.getString(node); + return config.getProperty(node); } } diff --git a/com/Acrobot/ChestShop/Config/DefaultValue.java b/com/Acrobot/ChestShop/Config/DefaultValue.java deleted file mode 100644 index 281cb6e..0000000 --- a/com/Acrobot/ChestShop/Config/DefaultValue.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.Acrobot.ChestShop.Config; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author Acrobot - */ -public enum DefaultValue { - reverse_buttons(false, "If true, people will buy with left-click and sell with right-click."), - serverEconomyAccount("", "Economy account's name you want Admin Shops to be assigned to"), - logToFile(false, "If true, plugin will log transactions in its own file"), - useDB(false, "If true, plugin will log transactions in EBean database"), - adminShopName("Admin Shop", "First line of your admin shop should look like this"), - generateStatisticsPage(false, "If true, plugin will generate shop statistics webpage."), - DBtimeToLive(600, "How long should transaction information be stored?"), - logToConsole(true, "Do you want ChestShop's messages to show up in console?"); - - private Object value; - private String comment; - - private static final Map names = new HashMap(); - - private DefaultValue(Object value, String comment) { - this.value = value; - this.comment = comment; - } - - public Object getValue() { - return (value instanceof String ? "\"" + value + "\"" : value); - } - - public String getComment() { - return comment; - } - - public String toString() { - return name(); - } - - public static DefaultValue lookup(String name) { - return names.get(name); - } - - static { - for (DefaultValue def : values()) { - names.put(def.name(), def); - } - } -} diff --git a/com/Acrobot/ChestShop/Config/DefaultLanguage.java b/com/Acrobot/ChestShop/Config/Language.java similarity index 81% rename from com/Acrobot/ChestShop/Config/DefaultLanguage.java rename to com/Acrobot/ChestShop/Config/Language.java index 2e49c2e..65ef33c 100644 --- a/com/Acrobot/ChestShop/Config/DefaultLanguage.java +++ b/com/Acrobot/ChestShop/Config/Language.java @@ -6,7 +6,7 @@ import java.util.Map; /** * @author Acrobot */ -public enum DefaultLanguage { +public enum Language { prefix("&a[Shop] &f"), iteminfo("&aItem Information:&f"), options("&aCustomizable options: "), @@ -35,17 +35,18 @@ public enum DefaultLanguage { YOU_CANNOT_CREATE_SHOP("You can't create this type of shop!"), NO_CHEST_DETECTED("Couldn't find a chest!"), ANOTHER_SHOP_DETECTED("Another player's shop detected!"), + CANNOT_ACCESS_THE_CHEST("You don't have permissions to access this chest!"), - PROTECTED_SHOP("Successfully protected the shop!"), + PROTECTED_SHOP("Successfully protected the shop with LWC!"), SHOP_CREATED("Shop successfully created!"), INCORRECT_ITEM_ID("You have specified invalid item id!"); private String text; - private static final Map names = new HashMap(); + private static final Map names = new HashMap(); - private DefaultLanguage(String def) { + private Language(String def) { text = def; } @@ -53,12 +54,12 @@ public enum DefaultLanguage { return text; } - public static DefaultLanguage lookup(String name) { + public static Language lookup(String name) { return names.get(name); } static { - for (DefaultLanguage def : values()) { + for (Language def : values()) { names.put(def.name(), def); } } diff --git a/com/Acrobot/ChestShop/Config/Property.java b/com/Acrobot/ChestShop/Config/Property.java new file mode 100644 index 0000000..39c6ea2 --- /dev/null +++ b/com/Acrobot/ChestShop/Config/Property.java @@ -0,0 +1,57 @@ +package com.Acrobot.ChestShop.Config; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Acrobot + */ +public enum Property { + 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"), + LOG_TO_FILE(false, "If true, plugin will log transactions in its own file"), + LOG_TO_CONSOLE(true, "Do you want ChestShop's messages to show up in console?"), + USE_DATABASE(false, "If true, plugin will log transactions in EBean database"), + ADMIN_SHOP_NAME("Admin Shop", "First line of your admin shop should look like this"), + GENERATE_STATISTICS_PAGE(false, "If true, plugin will generate shop statistics webpage."), + STATISTICS_PAGE_PATH("plugins/ChestShop/website.html", "Where should your generated website be saved?"), + RECORD_TIME_TO_LIVE(600, "How long should transaction information be stored?"), + USE_BUILT_IN_PROTECTION(true, "Do you want to use built-in protection?"), + PROTECT_CHEST_WITH_LWC(false, "Do you want to protect shop chests with LWC?"), + PROTECT_SIGN_WITH_LWC(false, "Do you want to protect shop signs with LWC?"); + + + + + private Object value; + private String comment; + + private static final Map names = new HashMap(); + + private Property(Object value, String comment) { + this.value = value; + this.comment = comment; + } + + public Object getValue() { + return (value instanceof String ? "\"" + value + '\"' : value); + } + + public String getComment() { + return comment; + } + + public String toString() { + return name(); + } + + public static Property lookup(String name) { + return names.get(name); + } + + static { + for (Property def : values()) { + names.put(def.name(), def); + } + } +} diff --git a/com/Acrobot/ChestShop/DB/Generator.java b/com/Acrobot/ChestShop/DB/Generator.java index a65242e..1beee2b 100644 --- a/com/Acrobot/ChestShop/DB/Generator.java +++ b/com/Acrobot/ChestShop/DB/Generator.java @@ -1,6 +1,8 @@ package com.Acrobot.ChestShop.DB; import com.Acrobot.ChestShop.ChestShop; +import com.Acrobot.ChestShop.Config.Config; +import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.Logging.Logging; import org.bukkit.Material; @@ -11,7 +13,7 @@ import java.util.List; * @author Acrobot */ public class Generator implements Runnable { - private static String filePath = ChestShop.folder + "/website.html"; + private static String filePath = Config.getString(Property.STATISTICS_PAGE_PATH); private static double generationTime; diff --git a/com/Acrobot/ChestShop/DB/Queue.java b/com/Acrobot/ChestShop/DB/Queue.java index 1395ac7..94d4ffb 100644 --- a/com/Acrobot/ChestShop/DB/Queue.java +++ b/com/Acrobot/ChestShop/DB/Queue.java @@ -2,6 +2,7 @@ package com.Acrobot.ChestShop.DB; import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Config.Config; +import com.Acrobot.ChestShop.Config.Property; import java.util.LinkedList; import java.util.List; @@ -17,7 +18,7 @@ public class Queue implements Runnable { } public void run() { - List toDelete = ChestShop.getDB().find(Transaction.class).where().lt("sec", System.currentTimeMillis() / 1000 - Config.getInteger("DBtimeToLive")).findList(); + List toDelete = ChestShop.getDB().find(Transaction.class).where().lt("sec", System.currentTimeMillis() / 1000 - Config.getInteger(Property.RECORD_TIME_TO_LIVE)).findList(); ChestShop.getDB().delete(toDelete); ChestShop.getDB().save(queue); queue.clear(); diff --git a/com/Acrobot/ChestShop/Listeners/playerInteract.java b/com/Acrobot/ChestShop/Listeners/playerInteract.java index 2476d08..f0d0b68 100644 --- a/com/Acrobot/ChestShop/Listeners/playerInteract.java +++ b/com/Acrobot/ChestShop/Listeners/playerInteract.java @@ -1,6 +1,8 @@ package com.Acrobot.ChestShop.Listeners; import com.Acrobot.ChestShop.Config.Config; +import com.Acrobot.ChestShop.Config.Language; +import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Protection.Security; import com.Acrobot.ChestShop.Shop.ShopManagement; @@ -40,9 +42,9 @@ public class playerInteract extends PlayerListener { Block block = event.getClickedBlock(); - if (block.getType() == Material.CHEST) { + if (Config.getBoolean(Property.USE_BUILT_IN_PROTECTION) && block.getType() == Material.CHEST) { if (!Permission.has(player, Permission.ADMIN) && Security.isProtected(block) && !Security.canAccess(player, block)) { - player.sendMessage(Config.getLocal("ACCESS_DENIED")); + player.sendMessage(Config.getLocal(Language.ACCESS_DENIED)); event.setCancelled(true); return; } @@ -70,7 +72,7 @@ public class playerInteract extends PlayerListener { Chest chest1 = SearchForBlock.findChest(sign); if (chest1 == null) { - player.sendMessage(Config.getLocal("NO_CHEST_DETECTED")); + player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED)); return; } @@ -91,7 +93,7 @@ public class playerInteract extends PlayerListener { } - Action buy = (Config.getBoolean("reverse_buttons") ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK); + Action buy = (Config.getBoolean(Property.REVERSE_BUTTONS) ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK); if (action == buy) { ShopManagement.buy(sign, player); diff --git a/com/Acrobot/ChestShop/Listeners/pluginDisable.java b/com/Acrobot/ChestShop/Listeners/pluginDisable.java new file mode 100644 index 0000000..be63710 --- /dev/null +++ b/com/Acrobot/ChestShop/Listeners/pluginDisable.java @@ -0,0 +1,21 @@ +package com.Acrobot.ChestShop.Listeners; + +import com.Acrobot.ChestShop.Economy; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.event.server.ServerListener; + +/** + * @author Acrobot + */ +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!"); + } + } + } +} diff --git a/com/Acrobot/ChestShop/Listeners/pluginEnable.java b/com/Acrobot/ChestShop/Listeners/pluginEnable.java index 9316ba9..d706308 100644 --- a/com/Acrobot/ChestShop/Listeners/pluginEnable.java +++ b/com/Acrobot/ChestShop/Listeners/pluginEnable.java @@ -22,13 +22,13 @@ import org.yi.acru.bukkit.Lockette.Lockette; */ public class pluginEnable extends ServerListener { - private Methods methods = new Methods(); + public static Methods methods = new Methods(); public void onPluginEnable(PluginEnableEvent event) { //Economy plugins - if (!this.methods.hasMethod()) { + if (!methods.hasMethod()) { if (methods.setMethod(event.getPlugin())) { Economy.economy = methods.getMethod(); System.out.println("[ChestShop] " + Economy.economy.getName() + ' ' + Economy.economy.getVersion() + " loaded."); @@ -54,6 +54,7 @@ public class pluginEnable extends ServerListener { PluginDescriptionFile pDesc = lwcPlugin.getDescription(); LWCplugin.lwc = ((LWCPlugin) lwcPlugin).getLWC(); Security.protection = new LWCplugin(); + System.out.println("[ChestShop] " + pDesc.getName() + " version " + pDesc.getVersion() + " loaded."); } } diff --git a/com/Acrobot/ChestShop/Listeners/signChange.java b/com/Acrobot/ChestShop/Listeners/signChange.java index 80f723f..99ac7bd 100644 --- a/com/Acrobot/ChestShop/Listeners/signChange.java +++ b/com/Acrobot/ChestShop/Listeners/signChange.java @@ -1,8 +1,11 @@ package com.Acrobot.ChestShop.Listeners; import com.Acrobot.ChestShop.Config.Config; +import com.Acrobot.ChestShop.Config.Language; +import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.Items.Items; import com.Acrobot.ChestShop.Permission; +import com.Acrobot.ChestShop.Protection.Default; import com.Acrobot.ChestShop.Protection.Security; import com.Acrobot.ChestShop.Utils.Numerical; import com.Acrobot.ChestShop.Utils.SearchForBlock; @@ -30,22 +33,23 @@ public class signChange extends BlockListener { ItemStack stock = Items.getItemStack(line[3]); + Material mat = stock == null ? null : stock.getType(); boolean playerIsAdmin = Permission.has(player, Permission.ADMIN); if (isAlmostReady) { + if (mat == null) { + player.sendMessage(Config.getLocal(Language.INCORRECT_ITEM_ID)); + dropSign(event); + return; + } if (!playerIsAdmin && !(Permission.has(player, Permission.SHOP_CREATION) || ((Permission.has(player, Permission.SHOP_CREATION + "." + mat.getId()) || !Permission.has(player, Permission.EXCLUDE_ITEM + "." + mat.getId()))))) { - player.sendMessage(Config.getLocal("YOU_CAN'T_CREATE_SHOP")); - dropSign(event); - return; - } - if (mat == null) { - player.sendMessage(Config.getLocal("INCORRECT_ITEM_ID")); + player.sendMessage(Config.getLocal(Language.YOU_CANNOT_CREATE_SHOP)); dropSign(event); return; } @@ -92,25 +96,39 @@ public class signChange extends BlockListener { if (!isAdminShop) { if (chest == null) { - player.sendMessage(Config.getLocal("NO_CHEST_DETECTED")); + player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED)); dropSign(event); return; } else if (!playerIsAdmin) { boolean canPlaceSign = Security.canPlaceSign(player, signBlock); if (!canPlaceSign) { - player.sendMessage(Config.getLocal("ANOTHER_SHOP_DETECTED")); + player.sendMessage(Config.getLocal(Language.ANOTHER_SHOP_DETECTED)); dropSign(event); return; } + + Default protection = new Default(); + Block chestBlock = chest.getBlock(); + + if(Security.isProtected(chestBlock) || protection.isProtected(chestBlock)){ + if(!Security.canAccess(player, chestBlock) || !protection.canAccess(player, chestBlock)){ + player.sendMessage(Config.getLocal(Language.CANNOT_ACCESS_THE_CHEST)); + dropSign(event); + return; + } + } } } - if (Security.protect(player.getName(), chest.getBlock())) { - player.sendMessage(Config.getLocal("PROTECTED_SHOP")); + if (Config.getBoolean(Property.PROTECT_CHEST_WITH_LWC) && Security.protect(player.getName(), chest.getBlock())) { + if(Config.getBoolean(Property.PROTECT_SIGN_WITH_LWC)){ + Security.protect(player.getName(), signBlock); + } + player.sendMessage(Config.getLocal(Language.PROTECTED_SHOP)); } - player.sendMessage(Config.getLocal("SHOP_CREATED")); + player.sendMessage(Config.getLocal(Language.SHOP_CREATED)); } public static void dropSign(SignChangeEvent event) { diff --git a/com/Acrobot/ChestShop/Logging/Logging.java b/com/Acrobot/ChestShop/Logging/Logging.java index 3e5f1c4..daa1d9e 100644 --- a/com/Acrobot/ChestShop/Logging/Logging.java +++ b/com/Acrobot/ChestShop/Logging/Logging.java @@ -1,6 +1,7 @@ package com.Acrobot.ChestShop.Logging; import com.Acrobot.ChestShop.Config.Config; +import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.DB.Queue; import com.Acrobot.ChestShop.DB.Transaction; import com.Acrobot.ChestShop.Shop.Shop; @@ -23,7 +24,7 @@ public class Logging { } public static void log(String string) { - if (Config.getBoolean("logToConsole")) { + if (Config.getBoolean(Property.LOG_TO_CONSOLE)) { System.out.println("[ChestShop] " + string); } FileWriterQueue.addToQueue(getDateAndTime() + ' ' + string); @@ -31,7 +32,7 @@ public class Logging { public static void logTransaction(boolean isBuying, Shop shop, Player player) { log(player.getName() + (isBuying ? " bought " : " sold ") + shop.stockAmount + ' ' + shop.stock.getType() + " for " + (isBuying ? shop.buyPrice + " from " : shop.sellPrice + " to ") + shop.owner); - if (!Config.getBoolean("useDB")) { + if (!Config.getBoolean(Property.USE_DATABASE)) { return; } Transaction transaction = new Transaction(); diff --git a/com/Acrobot/ChestShop/Protection/LockettePlugin.java b/com/Acrobot/ChestShop/Protection/LockettePlugin.java index 6c6109e..e0bc847 100644 --- a/com/Acrobot/ChestShop/Protection/LockettePlugin.java +++ b/com/Acrobot/ChestShop/Protection/LockettePlugin.java @@ -15,7 +15,7 @@ public class LockettePlugin implements Protection { } public boolean canAccess(Player player, Block block) { - return (player.getName().equals(Lockette.getProtectedOwner(block))); + return player.getName().equals(Lockette.getProtectedOwner(block)); } public boolean protect(String name, Block block) { diff --git a/com/Acrobot/ChestShop/Shop/Shop.java b/com/Acrobot/ChestShop/Shop/Shop.java index 602673b..f1c561d 100644 --- a/com/Acrobot/ChestShop/Shop/Shop.java +++ b/com/Acrobot/ChestShop/Shop/Shop.java @@ -3,6 +3,8 @@ package com.Acrobot.ChestShop.Shop; import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Chests.ChestObject; import com.Acrobot.ChestShop.Config.Config; +import com.Acrobot.ChestShop.Config.Language; +import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.Economy; import com.Acrobot.ChestShop.Logging.Logging; import com.Acrobot.ChestShop.Utils.InventoryUtil; @@ -33,28 +35,28 @@ public class Shop { public boolean buy(Player player) { if (chest == null && !isAdminShop()) { - player.sendMessage(Config.getLocal("NO_CHEST_DETECTED")); + player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED)); return false; } if (buyPrice == -1) { - player.sendMessage(Config.getLocal("NO_BUYING_HERE")); + player.sendMessage(Config.getLocal(Language.NO_BUYING_HERE)); return false; } String playerName = player.getName(); if (!Economy.hasEnough(playerName, buyPrice)) { - player.sendMessage(Config.getLocal("NOT_ENOUGH_MONEY")); + player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_MONEY)); return false; } if (!stockFitsPlayer(player)) { - player.sendMessage(Config.getLocal("NOT_ENOUGH_SPACE_IN_INVENTORY")); + player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_SPACE_IN_INVENTORY)); return false; } String materialName = stock.getType().name(); if (!isAdminShop() && !hasEnoughStock()) { - player.sendMessage(Config.getLocal("NOT_ENOUGH_STOCK")); - sendMessageToOwner(Config.getLocal("NOT_ENOUGH_STOCK_IN_YOUR_SHOP").replace("%material", materialName)); + player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_STOCK)); + sendMessageToOwner(Config.getLocal(Language.NOT_ENOUGH_STOCK_IN_YOUR_SHOP).replace("%material", materialName)); return false; } @@ -68,7 +70,7 @@ public class Shop { chest.removeItem(stock, stock.getDurability(), stockAmount); } String formatedPrice = Economy.formatBalance(buyPrice); - player.sendMessage(Config.getLocal("YOU_BOUGHT_FROM_SHOP") + player.sendMessage(Config.getLocal(Language.YOU_BOUGHT_FROM_SHOP) .replace("%amount", String.valueOf(stockAmount)) .replace("%item", materialName) .replace("%owner", owner) @@ -78,7 +80,7 @@ public class Shop { Logging.logTransaction(true, this, player); player.updateInventory(); - sendMessageToOwner(Config.getLocal("SOMEBODY_BOUGHT_FROM_YOUR_SHOP") + sendMessageToOwner(Config.getLocal(Language.SOMEBODY_BOUGHT_FROM_YOUR_SHOP) .replace("%amount", String.valueOf(stockAmount)) .replace("%item", materialName) .replace("%buyer", playerName) @@ -88,11 +90,11 @@ public class Shop { public boolean sell(Player player) { if (chest == null && !isAdminShop()) { - player.sendMessage(Config.getLocal("NO_CHEST_DETECTED")); + player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED)); return false; } if (sellPrice == -1) { - player.sendMessage(Config.getLocal("NO_SELLING_HERE")); + player.sendMessage(Config.getLocal(Language.NO_SELLING_HERE)); return false; } String account = getOwnerAccount(); @@ -100,17 +102,17 @@ public class Shop { if (accountExists) { if (!Economy.hasEnough(account, sellPrice)) { - player.sendMessage(Config.getLocal("NOT_ENOUGH_MONEY_SHOP")); + player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_MONEY_SHOP)); return false; } } if (!isAdminShop() && !stockFitsChest(chest)) { - player.sendMessage(Config.getLocal("NOT_ENOUGH_SPACE_IN_CHEST")); + player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_SPACE_IN_CHEST)); return false; } if (InventoryUtil.amount(player.getInventory(), stock, stock.getDurability()) < stockAmount) { - player.sendMessage(Config.getLocal("NOT_ENOUGH_ITEMS_TO_SELL")); + player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_ITEMS_TO_SELL)); return false; } @@ -128,7 +130,7 @@ public class Shop { String materialName = stock.getType().name(); String formatedBalance = Economy.formatBalance(sellPrice); - player.sendMessage(Config.getLocal("YOU_SOLD_TO_SHOP") + player.sendMessage(Config.getLocal(Language.YOU_SOLD_TO_SHOP) .replace("%amount", String.valueOf(stockAmount)) .replace("%item", materialName) .replace("%buyer", owner) @@ -138,7 +140,7 @@ public class Shop { Logging.logTransaction(false, this, player); player.updateInventory(); - sendMessageToOwner(Config.getLocal("SOMEBODY_SOLD_TO_YOUR_SHOP") + sendMessageToOwner(Config.getLocal(Language.SOMEBODY_SOLD_TO_YOUR_SHOP) .replace("%amount", String.valueOf(stockAmount)) .replace("%item", materialName) .replace("%seller", player.getName()) @@ -150,7 +152,7 @@ public class Shop { private String getOwnerAccount() { if (SignUtil.isAdminShop(owner)) { - return Config.getString("serverEconomyAccount"); + return Config.getString(Property.SERVER_ECONOMY_ACCOUNT); } else { return owner; } diff --git a/com/Acrobot/ChestShop/Utils/SignUtil.java b/com/Acrobot/ChestShop/Utils/SignUtil.java index a69a1cd..251de89 100644 --- a/com/Acrobot/ChestShop/Utils/SignUtil.java +++ b/com/Acrobot/ChestShop/Utils/SignUtil.java @@ -1,6 +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.block.Block; import org.bukkit.block.Sign; @@ -15,7 +16,7 @@ public class SignUtil { } public static boolean isAdminShop(String owner) { - return owner.toLowerCase().replace(" ", "").equals(Config.getString("adminShopName").toLowerCase().replace(" ", "")); + return owner.toLowerCase().replace(" ", "").equals(Config.getString(Property.ADMIN_SHOP_NAME).toLowerCase().replace(" ", "")); } public static boolean isValid(Sign sign) { diff --git a/plugin.yml b/plugin.yml index f5e57e5..cb628bd 100644 --- a/plugin.yml +++ b/plugin.yml @@ -8,16 +8,16 @@ version: 3.00 author: Acrobot description: > - A chest shop for economy mods. + A chest shop for economy plugins. commands: iteminfo: - aliases: [ii,iinfo] + aliases: [iinfo] description: Lists item id and names usage: | / (item name/item ID/alias) () - optional csVersion: - aliases: cv + aliases: [cv] description: Shows the ChestShop's version usage: | /