Even more changes, almost ready for relase!

This commit is contained in:
Acrobot 2011-06-11 17:36:55 +02:00
parent 3f6fb7ed03
commit fbc87e8977
17 changed files with 180 additions and 138 deletions

View File

@ -4,6 +4,7 @@ import com.Acrobot.ChestShop.Commands.ItemInfo;
import com.Acrobot.ChestShop.Commands.Options; import com.Acrobot.ChestShop.Commands.Options;
import com.Acrobot.ChestShop.Commands.Version; import com.Acrobot.ChestShop.Commands.Version;
import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Property;
import com.Acrobot.ChestShop.DB.Generator; import com.Acrobot.ChestShop.DB.Generator;
import com.Acrobot.ChestShop.DB.Queue; import com.Acrobot.ChestShop.DB.Queue;
import com.Acrobot.ChestShop.DB.Transaction; import com.Acrobot.ChestShop.DB.Transaction;
@ -33,8 +34,9 @@ public class ChestShop extends JavaPlugin {
private final blockBreak blockBreak = new blockBreak(); private final blockBreak blockBreak = new blockBreak();
private final blockPlace blockPlace = new blockPlace(); private final blockPlace blockPlace = new blockPlace();
private final signChange signChange = new signChange(); private final signChange signChange = new signChange();
private final pluginDisable pluginDisable = new pluginDisable();
private final playerInteract playerInteract = new playerInteract(); private final playerInteract playerInteract = new playerInteract();
public static File folder; public static File folder;
public static EbeanServer db; 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.SIGN_CHANGE, signChange, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_INTERACT, playerInteract, Event.Priority.Highest, 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_ENABLE, pluginEnable, Event.Priority.Monitor, this);
pm.registerEvent(Event.Type.PLUGIN_DISABLE, pluginDisable, Event.Priority.Monitor, this);
desc = this.getDescription(); desc = this.getDescription();
server = getServer(); server = getServer();
@ -62,18 +65,18 @@ public class ChestShop extends JavaPlugin {
//Now set up our database for storing transactions! //Now set up our database for storing transactions!
setupDBfile(); setupDBfile();
if (Config.getBoolean("useDB")) { if (Config.getBoolean(Property.USE_DATABASE)) {
setupDB(); setupDB();
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Queue(), 200L, 200L); 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); getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Generator(), 300L, 300L);
} }
db = getDatabase(); db = getDatabase();
} }
//Now set up our logging to file! //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); getServer().getScheduler().scheduleAsyncRepeatingTask(this, new FileWriterQueue(), 201L, 201L);
} }

View File

@ -1,6 +1,7 @@
package com.Acrobot.ChestShop.Commands; package com.Acrobot.ChestShop.Commands;
import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Language;
import com.Acrobot.ChestShop.Items.Items; import com.Acrobot.ChestShop.Items.Items;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -28,7 +29,7 @@ public class ItemInfo implements CommandExecutor {
return false; return false;
} }
player.sendMessage(Config.getLocal("iteminfo")); player.sendMessage(Config.getLocal(Language.iteminfo));
player.sendMessage(itemInHand.getTypeId() + ":" + itemInHand.getDurability() + " - " + itemInHand.getType().name()); player.sendMessage(itemInHand.getTypeId() + ":" + itemInHand.getDurability() + " - " + itemInHand.getType().name());
return true; return true;
@ -39,7 +40,7 @@ public class ItemInfo implements CommandExecutor {
return false; return false;
} }
sender.sendMessage(Config.getLocal("iteminfo")); sender.sendMessage(Config.getLocal(Language.iteminfo));
sender.sendMessage(item.getTypeId() + ":" + item.getDurability() + " - " + item.getType().name()); sender.sendMessage(item.getTypeId() + ":" + item.getDurability() + " - " + item.getType().name());
return true; return true;

View File

@ -18,12 +18,11 @@ public class Config {
private static Configuration language = new Configuration(langFile); private static Configuration language = new Configuration(langFile);
public static HashMap<String, Object> defaultValues = new HashMap<String, Object>(); public static HashMap<String, Object> defaultValues = new HashMap<String, Object>();
private static String langChar = Character.toString((char) 167);
public static void setUp() { public static void setUp() {
config.load(); config.load();
for (DefaultValue def : DefaultValue.values()){ for (Property def : com.Acrobot.ChestShop.Config.Property.values()){
if(config.getProperty(def.name()) == null){ if(config.getProperty(def.name()) == null){
writeToFile(def.name() + ": " + def.getValue() + " #" + def.getComment(), configFile); writeToFile(def.name() + ": " + def.getValue() + " #" + def.getComment(), configFile);
} }
@ -31,14 +30,12 @@ public class Config {
config.load(); config.load();
language.load(); language.load();
for (DefaultLanguage def : DefaultLanguage.values()) { for (Language def : Language.values()) {
if (language.getProperty(def.name()) == null) { if (language.getProperty(def.name()) == null) {
writeToFile(def.name() + ": \"" + def.toString() + "\"", langFile); writeToFile(def.name() + ": \"" + def.toString() + '\"', langFile);
} }
} }
language.load(); language.load();
} }
public static void writeToFile(String string, File file) { public static void writeToFile(String string, File file) {
@ -51,47 +48,31 @@ public class Config {
} }
} }
public static boolean getBoolean(String node) { public static boolean getBoolean(Property value){
return (Boolean) getValue(node); return (Boolean) getValue(value.name());
} }
public static String getString(String node) { public static String getString(Property value){
return getColored((String) getValue(node)); return getColored((String) getValue(value.name()));
} }
public static int getInteger(String node) { public static int getInteger(Property value){
return Integer.parseInt(getValue(node).toString()); return Integer.parseInt(getValue(value.name()).toString());
} }
public static double getDouble(String node) { public static double getDouble(Property value){
return config.getDouble(node, -1); return config.getDouble(value.name(), -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 String getColored(String msg) { public static String getColored(String msg) {
return msg.replaceAll("&", langChar); return msg.replaceAll("&([0-9a-f])", "\u00A7$1");
} }
public static String getLocal(String node) { public static String getLocal(Language lang) {
return getColored(getDefaultLocal("prefix") + (String) getDefaultLocal(node)); return getColored(language.getString(Language.prefix.name()) + language.getString(lang.name()));
} }
private static Object getValue(String node) { private static Object getValue(String node) {
return getValue(node, config, configFile); return config.getProperty(node);
}
private static Object getDefaultLocal(String node) {
if (language.getProperty(node) == null) {
writeToFile(DefaultLanguage.lookup(node).toString(), langFile);
language.load();
}
return language.getString(node);
} }
} }

View File

@ -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<String, DefaultValue> names = new HashMap<String, DefaultValue>();
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);
}
}
}

View File

@ -6,7 +6,7 @@ import java.util.Map;
/** /**
* @author Acrobot * @author Acrobot
*/ */
public enum DefaultLanguage { public enum Language {
prefix("&a[Shop] &f"), prefix("&a[Shop] &f"),
iteminfo("&aItem Information:&f"), iteminfo("&aItem Information:&f"),
options("&aCustomizable options: "), options("&aCustomizable options: "),
@ -35,17 +35,18 @@ public enum DefaultLanguage {
YOU_CANNOT_CREATE_SHOP("You can't create this type of shop!"), YOU_CANNOT_CREATE_SHOP("You can't create this type of shop!"),
NO_CHEST_DETECTED("Couldn't find a chest!"), NO_CHEST_DETECTED("Couldn't find a chest!"),
ANOTHER_SHOP_DETECTED("Another player's shop detected!"), 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!"), SHOP_CREATED("Shop successfully created!"),
INCORRECT_ITEM_ID("You have specified invalid item id!"); INCORRECT_ITEM_ID("You have specified invalid item id!");
private String text; private String text;
private static final Map<String, DefaultLanguage> names = new HashMap<String, DefaultLanguage>(); private static final Map<String, Language> names = new HashMap<String, Language>();
private DefaultLanguage(String def) { private Language(String def) {
text = def; text = def;
} }
@ -53,12 +54,12 @@ public enum DefaultLanguage {
return text; return text;
} }
public static DefaultLanguage lookup(String name) { public static Language lookup(String name) {
return names.get(name); return names.get(name);
} }
static { static {
for (DefaultLanguage def : values()) { for (Language def : values()) {
names.put(def.name(), def); names.put(def.name(), def);
} }
} }

View File

@ -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<String, Property> names = new HashMap<String, Property>();
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);
}
}
}

View File

@ -1,6 +1,8 @@
package com.Acrobot.ChestShop.DB; package com.Acrobot.ChestShop.DB;
import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Property;
import com.Acrobot.ChestShop.Logging.Logging; import com.Acrobot.ChestShop.Logging.Logging;
import org.bukkit.Material; import org.bukkit.Material;
@ -11,7 +13,7 @@ import java.util.List;
* @author Acrobot * @author Acrobot
*/ */
public class Generator implements Runnable { 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; private static double generationTime;

View File

@ -2,6 +2,7 @@ package com.Acrobot.ChestShop.DB;
import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Property;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -17,7 +18,7 @@ public class Queue implements Runnable {
} }
public void run() { public void run() {
List<Transaction> toDelete = ChestShop.getDB().find(Transaction.class).where().lt("sec", System.currentTimeMillis() / 1000 - Config.getInteger("DBtimeToLive")).findList(); List<Transaction> 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().delete(toDelete);
ChestShop.getDB().save(queue); ChestShop.getDB().save(queue);
queue.clear(); queue.clear();

View File

@ -1,6 +1,8 @@
package com.Acrobot.ChestShop.Listeners; package com.Acrobot.ChestShop.Listeners;
import com.Acrobot.ChestShop.Config.Config; 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.Permission;
import com.Acrobot.ChestShop.Protection.Security; import com.Acrobot.ChestShop.Protection.Security;
import com.Acrobot.ChestShop.Shop.ShopManagement; import com.Acrobot.ChestShop.Shop.ShopManagement;
@ -40,9 +42,9 @@ public class playerInteract extends PlayerListener {
Block block = event.getClickedBlock(); 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)) { 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); event.setCancelled(true);
return; return;
} }
@ -70,7 +72,7 @@ public class playerInteract extends PlayerListener {
Chest chest1 = SearchForBlock.findChest(sign); Chest chest1 = SearchForBlock.findChest(sign);
if (chest1 == null) { if (chest1 == null) {
player.sendMessage(Config.getLocal("NO_CHEST_DETECTED")); player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
return; 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) { if (action == buy) {
ShopManagement.buy(sign, player); ShopManagement.buy(sign, player);

View File

@ -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!");
}
}
}
}

View File

@ -22,13 +22,13 @@ import org.yi.acru.bukkit.Lockette.Lockette;
*/ */
public class pluginEnable extends ServerListener { public class pluginEnable extends ServerListener {
private Methods methods = new Methods(); public static Methods methods = new Methods();
public void onPluginEnable(PluginEnableEvent event) { public void onPluginEnable(PluginEnableEvent event) {
//Economy plugins //Economy plugins
if (!this.methods.hasMethod()) { if (!methods.hasMethod()) {
if (methods.setMethod(event.getPlugin())) { if (methods.setMethod(event.getPlugin())) {
Economy.economy = methods.getMethod(); Economy.economy = methods.getMethod();
System.out.println("[ChestShop] " + Economy.economy.getName() + ' ' + Economy.economy.getVersion() + " loaded."); System.out.println("[ChestShop] " + Economy.economy.getName() + ' ' + Economy.economy.getVersion() + " loaded.");
@ -54,6 +54,7 @@ public class pluginEnable extends ServerListener {
PluginDescriptionFile pDesc = lwcPlugin.getDescription(); PluginDescriptionFile pDesc = lwcPlugin.getDescription();
LWCplugin.lwc = ((LWCPlugin) lwcPlugin).getLWC(); LWCplugin.lwc = ((LWCPlugin) lwcPlugin).getLWC();
Security.protection = new LWCplugin(); Security.protection = new LWCplugin();
System.out.println("[ChestShop] " + pDesc.getName() + " version " + pDesc.getVersion() + " loaded."); System.out.println("[ChestShop] " + pDesc.getName() + " version " + pDesc.getVersion() + " loaded.");
} }
} }

View File

@ -1,8 +1,11 @@
package com.Acrobot.ChestShop.Listeners; package com.Acrobot.ChestShop.Listeners;
import com.Acrobot.ChestShop.Config.Config; 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.Items.Items;
import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Protection.Default;
import com.Acrobot.ChestShop.Protection.Security; import com.Acrobot.ChestShop.Protection.Security;
import com.Acrobot.ChestShop.Utils.Numerical; import com.Acrobot.ChestShop.Utils.Numerical;
import com.Acrobot.ChestShop.Utils.SearchForBlock; import com.Acrobot.ChestShop.Utils.SearchForBlock;
@ -30,22 +33,23 @@ public class signChange extends BlockListener {
ItemStack stock = Items.getItemStack(line[3]); ItemStack stock = Items.getItemStack(line[3]);
Material mat = stock == null ? null : stock.getType(); Material mat = stock == null ? null : stock.getType();
boolean playerIsAdmin = Permission.has(player, Permission.ADMIN); boolean playerIsAdmin = Permission.has(player, Permission.ADMIN);
if (isAlmostReady) { if (isAlmostReady) {
if (mat == null) {
player.sendMessage(Config.getLocal(Language.INCORRECT_ITEM_ID));
dropSign(event);
return;
}
if (!playerIsAdmin && !(Permission.has(player, Permission.SHOP_CREATION) if (!playerIsAdmin && !(Permission.has(player, Permission.SHOP_CREATION)
|| ((Permission.has(player, Permission.SHOP_CREATION + "." + mat.getId()) || ((Permission.has(player, Permission.SHOP_CREATION + "." + mat.getId())
|| !Permission.has(player, Permission.EXCLUDE_ITEM + "." + mat.getId()))))) { || !Permission.has(player, Permission.EXCLUDE_ITEM + "." + mat.getId()))))) {
player.sendMessage(Config.getLocal("YOU_CAN'T_CREATE_SHOP")); player.sendMessage(Config.getLocal(Language.YOU_CANNOT_CREATE_SHOP));
dropSign(event);
return;
}
if (mat == null) {
player.sendMessage(Config.getLocal("INCORRECT_ITEM_ID"));
dropSign(event); dropSign(event);
return; return;
} }
@ -92,25 +96,39 @@ public class signChange extends BlockListener {
if (!isAdminShop) { if (!isAdminShop) {
if (chest == null) { if (chest == null) {
player.sendMessage(Config.getLocal("NO_CHEST_DETECTED")); player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
dropSign(event); dropSign(event);
return; return;
} else if (!playerIsAdmin) { } else if (!playerIsAdmin) {
boolean canPlaceSign = Security.canPlaceSign(player, signBlock); boolean canPlaceSign = Security.canPlaceSign(player, signBlock);
if (!canPlaceSign) { 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); dropSign(event);
return; return;
} }
} }
} }
if (Security.protect(player.getName(), chest.getBlock())) {
player.sendMessage(Config.getLocal("PROTECTED_SHOP"));
} }
player.sendMessage(Config.getLocal("SHOP_CREATED")); 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(Language.SHOP_CREATED));
} }
public static void dropSign(SignChangeEvent event) { public static void dropSign(SignChangeEvent event) {

View File

@ -1,6 +1,7 @@
package com.Acrobot.ChestShop.Logging; package com.Acrobot.ChestShop.Logging;
import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Property;
import com.Acrobot.ChestShop.DB.Queue; import com.Acrobot.ChestShop.DB.Queue;
import com.Acrobot.ChestShop.DB.Transaction; import com.Acrobot.ChestShop.DB.Transaction;
import com.Acrobot.ChestShop.Shop.Shop; import com.Acrobot.ChestShop.Shop.Shop;
@ -23,7 +24,7 @@ public class Logging {
} }
public static void log(String string) { public static void log(String string) {
if (Config.getBoolean("logToConsole")) { if (Config.getBoolean(Property.LOG_TO_CONSOLE)) {
System.out.println("[ChestShop] " + string); System.out.println("[ChestShop] " + string);
} }
FileWriterQueue.addToQueue(getDateAndTime() + ' ' + string); FileWriterQueue.addToQueue(getDateAndTime() + ' ' + string);
@ -31,7 +32,7 @@ public class Logging {
public static void logTransaction(boolean isBuying, Shop shop, Player player) { 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); 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; return;
} }
Transaction transaction = new Transaction(); Transaction transaction = new Transaction();

View File

@ -15,7 +15,7 @@ public class LockettePlugin implements Protection {
} }
public boolean canAccess(Player player, Block block) { 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) { public boolean protect(String name, Block block) {

View File

@ -3,6 +3,8 @@ package com.Acrobot.ChestShop.Shop;
import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Chests.ChestObject; import com.Acrobot.ChestShop.Chests.ChestObject;
import com.Acrobot.ChestShop.Config.Config; 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.Economy;
import com.Acrobot.ChestShop.Logging.Logging; import com.Acrobot.ChestShop.Logging.Logging;
import com.Acrobot.ChestShop.Utils.InventoryUtil; import com.Acrobot.ChestShop.Utils.InventoryUtil;
@ -33,28 +35,28 @@ public class Shop {
public boolean buy(Player player) { public boolean buy(Player player) {
if (chest == null && !isAdminShop()) { if (chest == null && !isAdminShop()) {
player.sendMessage(Config.getLocal("NO_CHEST_DETECTED")); player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
return false; return false;
} }
if (buyPrice == -1) { if (buyPrice == -1) {
player.sendMessage(Config.getLocal("NO_BUYING_HERE")); player.sendMessage(Config.getLocal(Language.NO_BUYING_HERE));
return false; return false;
} }
String playerName = player.getName(); String playerName = player.getName();
if (!Economy.hasEnough(playerName, buyPrice)) { if (!Economy.hasEnough(playerName, buyPrice)) {
player.sendMessage(Config.getLocal("NOT_ENOUGH_MONEY")); player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_MONEY));
return false; return false;
} }
if (!stockFitsPlayer(player)) { if (!stockFitsPlayer(player)) {
player.sendMessage(Config.getLocal("NOT_ENOUGH_SPACE_IN_INVENTORY")); player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_SPACE_IN_INVENTORY));
return false; return false;
} }
String materialName = stock.getType().name(); String materialName = stock.getType().name();
if (!isAdminShop() && !hasEnoughStock()) { if (!isAdminShop() && !hasEnoughStock()) {
player.sendMessage(Config.getLocal("NOT_ENOUGH_STOCK")); player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_STOCK));
sendMessageToOwner(Config.getLocal("NOT_ENOUGH_STOCK_IN_YOUR_SHOP").replace("%material", materialName)); sendMessageToOwner(Config.getLocal(Language.NOT_ENOUGH_STOCK_IN_YOUR_SHOP).replace("%material", materialName));
return false; return false;
} }
@ -68,7 +70,7 @@ public class Shop {
chest.removeItem(stock, stock.getDurability(), stockAmount); chest.removeItem(stock, stock.getDurability(), stockAmount);
} }
String formatedPrice = Economy.formatBalance(buyPrice); 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("%amount", String.valueOf(stockAmount))
.replace("%item", materialName) .replace("%item", materialName)
.replace("%owner", owner) .replace("%owner", owner)
@ -78,7 +80,7 @@ public class Shop {
Logging.logTransaction(true, this, player); Logging.logTransaction(true, this, player);
player.updateInventory(); 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("%amount", String.valueOf(stockAmount))
.replace("%item", materialName) .replace("%item", materialName)
.replace("%buyer", playerName) .replace("%buyer", playerName)
@ -88,11 +90,11 @@ public class Shop {
public boolean sell(Player player) { public boolean sell(Player player) {
if (chest == null && !isAdminShop()) { if (chest == null && !isAdminShop()) {
player.sendMessage(Config.getLocal("NO_CHEST_DETECTED")); player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
return false; return false;
} }
if (sellPrice == -1) { if (sellPrice == -1) {
player.sendMessage(Config.getLocal("NO_SELLING_HERE")); player.sendMessage(Config.getLocal(Language.NO_SELLING_HERE));
return false; return false;
} }
String account = getOwnerAccount(); String account = getOwnerAccount();
@ -100,17 +102,17 @@ public class Shop {
if (accountExists) { if (accountExists) {
if (!Economy.hasEnough(account, sellPrice)) { if (!Economy.hasEnough(account, sellPrice)) {
player.sendMessage(Config.getLocal("NOT_ENOUGH_MONEY_SHOP")); player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_MONEY_SHOP));
return false; return false;
} }
} }
if (!isAdminShop() && !stockFitsChest(chest)) { 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; return false;
} }
if (InventoryUtil.amount(player.getInventory(), stock, stock.getDurability()) < stockAmount) { 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; return false;
} }
@ -128,7 +130,7 @@ public class Shop {
String materialName = stock.getType().name(); String materialName = stock.getType().name();
String formatedBalance = Economy.formatBalance(sellPrice); 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("%amount", String.valueOf(stockAmount))
.replace("%item", materialName) .replace("%item", materialName)
.replace("%buyer", owner) .replace("%buyer", owner)
@ -138,7 +140,7 @@ public class Shop {
Logging.logTransaction(false, this, player); Logging.logTransaction(false, this, player);
player.updateInventory(); 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("%amount", String.valueOf(stockAmount))
.replace("%item", materialName) .replace("%item", materialName)
.replace("%seller", player.getName()) .replace("%seller", player.getName())
@ -150,7 +152,7 @@ public class Shop {
private String getOwnerAccount() { private String getOwnerAccount() {
if (SignUtil.isAdminShop(owner)) { if (SignUtil.isAdminShop(owner)) {
return Config.getString("serverEconomyAccount"); return Config.getString(Property.SERVER_ECONOMY_ACCOUNT);
} else { } else {
return owner; return owner;
} }

View File

@ -1,6 +1,7 @@
package com.Acrobot.ChestShop.Utils; package com.Acrobot.ChestShop.Utils;
import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Property;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
@ -15,7 +16,7 @@ public class SignUtil {
} }
public static boolean isAdminShop(String owner) { 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) { public static boolean isValid(Sign sign) {

View File

@ -8,16 +8,16 @@ version: 3.00
author: Acrobot author: Acrobot
description: > description: >
A chest shop for economy mods. A chest shop for economy plugins.
commands: commands:
iteminfo: iteminfo:
aliases: [ii,iinfo] aliases: [iinfo]
description: Lists item id and names description: Lists item id and names
usage: | usage: |
/<command> (item name/item ID/alias) /<command> (item name/item ID/alias)
() - optional () - optional
csVersion: csVersion:
aliases: cv aliases: [cv]
description: Shows the ChestShop's version description: Shows the ChestShop's version
usage: | usage: |
/<command> /<command>