diff --git a/com/Acrobot/ChestShop/ChestShop.java b/com/Acrobot/ChestShop/ChestShop.java index c8d3159..a7c74e1 100644 --- a/com/Acrobot/ChestShop/ChestShop.java +++ b/com/Acrobot/ChestShop/ChestShop.java @@ -20,7 +20,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.config.Configuration; import java.io.File; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; /** @@ -37,6 +37,7 @@ public class ChestShop extends JavaPlugin { private static Server server; public void onEnable() { + blockBreak blockBreak = new blockBreak(); PluginManager pm = getServer().getPluginManager(); //Yep, set up our folder! @@ -46,14 +47,18 @@ public class ChestShop extends JavaPlugin { Config.setUp(); //Register our events - pm.registerEvent(Event.Type.BLOCK_BREAK, new blockBreak(), Event.Priority.Normal, this); + 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); - pm.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, new blockBreak(), Event.Priority.Normal, this); - pm.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, new blockBreak(), Event.Priority.Normal, 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); + } description = this.getDescription(); //Description of the plugin server = getServer(); //Setting out server variable @@ -65,7 +70,6 @@ public class ChestShop extends JavaPlugin { if (Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) { getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Generator(), 300L, (long) Config.getDouble(Property.STATISTICS_PAGE_GENERATION_INTERVAL) * 20L); } - DB = database.getDatabase(); } //Now set up our logging to file! @@ -97,12 +101,12 @@ public class ChestShop extends JavaPlugin { return config; } - private Database database; + private static Database database; private void setupDB() { database = new Database(this) { protected java.util.List> getDatabaseClasses() { - List> list = new LinkedList>(); + List> list = new ArrayList>(); list.add(Transaction.class); return list; } @@ -117,8 +121,10 @@ public class ChestShop extends JavaPlugin { config.getString("database.password"), config.getString("database.isolation"), false, - false + true ); + + DB = database.getDatabase(); } @Override diff --git a/com/Acrobot/ChestShop/DB/Transaction.java b/com/Acrobot/ChestShop/DB/Transaction.java index 2f9d83f..9da5569 100644 --- a/com/Acrobot/ChestShop/DB/Transaction.java +++ b/com/Acrobot/ChestShop/DB/Transaction.java @@ -23,6 +23,8 @@ public class Transaction { private float price; private long sec; + public Transaction() {} + public float getAveragePricePerItem() { return price / amount; } diff --git a/com/Acrobot/ChestShop/Listeners/blockBreak.java b/com/Acrobot/ChestShop/Listeners/blockBreak.java index eaeb40b..1dc5a99 100644 --- a/com/Acrobot/ChestShop/Listeners/blockBreak.java +++ b/com/Acrobot/ChestShop/Listeners/blockBreak.java @@ -1,7 +1,5 @@ package com.Acrobot.ChestShop.Listeners; -import com.Acrobot.ChestShop.Config.Config; -import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Utils.uBlock; import com.Acrobot.ChestShop.Utils.uLongName; @@ -18,16 +16,16 @@ import org.bukkit.event.block.BlockPistonRetractEvent; * @author Acrobot */ public class blockBreak extends BlockListener { - private static boolean cancellingBlockBreak(Block block, Player player) { + public static boolean cancellingBlockBreak(Block block, Player player) { if (player != null && Permission.has(player, Permission.ADMIN)) return false; - if(uSign.isSign(block)) block.getState().update(); - + if (uSign.isSign(block)) block.getState().update(); + Sign sign = uBlock.findRestrictedSign(block); if (sign != null) return true; sign = uBlock.findSign(block); - return sign != null && (player == null || (!player.getName().equals(sign.getLine(0)) && !uLongName.stripName(player.getName()).equals(sign.getLine(0)))); + return sign != null && (player == null || (!uLongName.stripName(player.getName()).equals(sign.getLine(0)))); } public void onBlockBreak(BlockBreakEvent event) { @@ -35,15 +33,15 @@ public class blockBreak extends BlockListener { } public void onBlockPistonExtend(BlockPistonExtendEvent event) { - if (!Config.getBoolean(Property.USE_BUILT_IN_PROTECTION)) return; - - for (Block b : event.getBlocks()){ - if (cancellingBlockBreak(b, null)) event.setCancelled(true); return; + for (Block b : event.getBlocks()) { + if (cancellingBlockBreak(b, null)) { + event.setCancelled(true); + return; + } } } public void onBlockPistonRetract(BlockPistonRetractEvent event) { - if (!Config.getBoolean(Property.USE_BUILT_IN_PROTECTION)) return; if (cancellingBlockBreak(event.getRetractLocation().getBlock(), null)) event.setCancelled(true); } } diff --git a/com/Acrobot/ChestShop/Listeners/entityExplode.java b/com/Acrobot/ChestShop/Listeners/entityExplode.java new file mode 100644 index 0000000..f923ede --- /dev/null +++ b/com/Acrobot/ChestShop/Listeners/entityExplode.java @@ -0,0 +1,20 @@ +package com.Acrobot.ChestShop.Listeners; + +import org.bukkit.block.Block; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntityListener; + +/** + * @author Acrobot + */ +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)){ + event.setCancelled(true); + return; + } + } + } +} diff --git a/com/Acrobot/ChestShop/Listeners/playerInteract.java b/com/Acrobot/ChestShop/Listeners/playerInteract.java index 42009e6..9502fb2 100644 --- a/com/Acrobot/ChestShop/Listeners/playerInteract.java +++ b/com/Acrobot/ChestShop/Listeners/playerInteract.java @@ -5,8 +5,8 @@ import com.Acrobot.ChestShop.Config.Language; import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Protection.Default; -import com.Acrobot.ChestShop.Signs.restrictedSign; import com.Acrobot.ChestShop.Shop.ShopManagement; +import com.Acrobot.ChestShop.Signs.restrictedSign; import com.Acrobot.ChestShop.Utils.uBlock; import com.Acrobot.ChestShop.Utils.uLongName; import com.Acrobot.ChestShop.Utils.uSign; @@ -57,9 +57,9 @@ public class playerInteract extends PlayerListener { lastTransactionTime.put(player, System.currentTimeMillis()); - String playerName = player.getName(); + String playerName = uLongName.stripName(player.getName()); - if (playerName.equals(sign.getLine(0)) || uLongName.stripName(playerName).equals(sign.getLine(0))) { + if (playerName.equals(sign.getLine(0))) { Chest chest1 = uBlock.findChest(sign); if (chest1 == null) { player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED)); diff --git a/com/Acrobot/ChestShop/Listeners/signChange.java b/com/Acrobot/ChestShop/Listeners/signChange.java index 6dc33f8..6a6c746 100644 --- a/com/Acrobot/ChestShop/Listeners/signChange.java +++ b/com/Acrobot/ChestShop/Listeners/signChange.java @@ -73,7 +73,7 @@ public class signChange extends BlockListener { Boolean isReady = uSign.isValid(line); if (line[0].isEmpty() || (!line[0].startsWith(player.getName()) && !Permission.has(player, Permission.ADMIN))) { - event.setLine(0, player.getName()); + event.setLine(0, uLongName.stripName(player.getName())); } line = event.getLines(); diff --git a/com/Acrobot/ChestShop/Protection/Default.java b/com/Acrobot/ChestShop/Protection/Default.java index da6bfcb..8d1c80c 100644 --- a/com/Acrobot/ChestShop/Protection/Default.java +++ b/com/Acrobot/ChestShop/Protection/Default.java @@ -31,7 +31,7 @@ public class Default implements Protection { if (sign != null) signLine = sign.getLine(0); if (neighborSign != null) signLine = neighborSign.getLine(0); - return playerName.equals(signLine) || uLongName.stripName(playerName).equals(signLine); + return uLongName.stripName(playerName).equals(signLine); } public boolean protect(String name, Block block) { diff --git a/com/lennardf1989/bukkitex/Database.java b/com/lennardf1989/bukkitex/Database.java index 0bbb634..2dd422d 100644 --- a/com/lennardf1989/bukkitex/Database.java +++ b/com/lennardf1989/bukkitex/Database.java @@ -185,6 +185,8 @@ public abstract class Database { } catch (Exception ignored) {} } + if(databaseExists) return; + //Fire "before drop" event try { beforeDropDatabase(); diff --git a/plugin.yml b/plugin.yml index 5a2f249..612f6ac 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: ChestShop main: com.Acrobot.ChestShop.ChestShop -version: 3.00 BETA 10 +version: 3.00 BETA 11 author: Acrobot