From 4440101a3a47c3dadf40e8e3fb0baeabea51fec1 Mon Sep 17 00:00:00 2001 From: Acrobot Date: Sun, 25 Sep 2011 16:17:44 +0200 Subject: [PATCH] - Added support for OddItem 0.8 - Fixed getRetractBlock --- com/Acrobot/ChestShop/DB/Queue.java | 4 +++- com/Acrobot/ChestShop/Items/Odd.java | 6 +++--- com/Acrobot/ChestShop/Listeners/blockBreak.java | 3 +-- .../ChestShop/Listeners/playerInteract.java | 1 - com/Acrobot/ChestShop/Listeners/pluginEnable.java | 15 +++++++++------ com/Acrobot/ChestShop/Listeners/signChange.java | 2 +- com/Acrobot/ChestShop/Utils/uTowny.java | 10 +++++----- plugin.yml | 2 +- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/com/Acrobot/ChestShop/DB/Queue.java b/com/Acrobot/ChestShop/DB/Queue.java index 180b2a3..d8c27c6 100644 --- a/com/Acrobot/ChestShop/DB/Queue.java +++ b/com/Acrobot/ChestShop/DB/Queue.java @@ -4,6 +4,7 @@ import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Property; +import javax.persistence.OptimisticLockException; import java.util.ArrayList; /** @@ -19,7 +20,8 @@ public class Queue implements Runnable { public void run() { ChestShop.getDB().delete(ChestShop.getDB().find(Transaction.class).where().lt("sec", System.currentTimeMillis() / 1000 - Config.getInteger(Property.RECORD_TIME_TO_LIVE)).findList()); - ChestShop.getDB().save(queue); + ArrayList queueCopy = queue; + try { ChestShop.getDB().save(queueCopy); } catch (OptimisticLockException ignored) {} queue.clear(); } } diff --git a/com/Acrobot/ChestShop/Items/Odd.java b/com/Acrobot/ChestShop/Items/Odd.java index 25faaf5..744194e 100644 --- a/com/Acrobot/ChestShop/Items/Odd.java +++ b/com/Acrobot/ChestShop/Items/Odd.java @@ -7,15 +7,15 @@ import org.bukkit.inventory.ItemStack; * @author Acrobot */ public class Odd { - public static OddItem oddItem; + public static boolean isInitialized; public static boolean isInitialized() { - return oddItem != null; + return isInitialized; } public static ItemStack returnItemStack(String name) { try { - return oddItem.getItemStack(name); + return OddItem.getItemStack(name); } catch (Exception ignored) { return null; } diff --git a/com/Acrobot/ChestShop/Listeners/blockBreak.java b/com/Acrobot/ChestShop/Listeners/blockBreak.java index d0b33b5..6cf85cb 100644 --- a/com/Acrobot/ChestShop/Listeners/blockBreak.java +++ b/com/Acrobot/ChestShop/Listeners/blockBreak.java @@ -11,7 +11,6 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.material.PistonBaseMaterial; /** * @author Acrobot @@ -58,6 +57,6 @@ public class blockBreak extends BlockListener { } private static Block getRetractBlock(BlockPistonRetractEvent event) { - return event.getBlock().getState().getData() instanceof PistonBaseMaterial ? event.getRetractLocation().getBlock() : null; + return (!uSign.isSign(event.getRetractLocation().getBlock()) ? event.getRetractLocation().getBlock() : null); } } diff --git a/com/Acrobot/ChestShop/Listeners/playerInteract.java b/com/Acrobot/ChestShop/Listeners/playerInteract.java index 273eda6..5e311b5 100644 --- a/com/Acrobot/ChestShop/Listeners/playerInteract.java +++ b/com/Acrobot/ChestShop/Listeners/playerInteract.java @@ -12,7 +12,6 @@ import com.Acrobot.ChestShop.Utils.uLongName; import com.Acrobot.ChestShop.Utils.uSign; import net.minecraft.server.IInventory; import net.minecraft.server.InventoryLargeChest; -import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Chest; diff --git a/com/Acrobot/ChestShop/Listeners/pluginEnable.java b/com/Acrobot/ChestShop/Listeners/pluginEnable.java index 5d25af6..c8ac606 100644 --- a/com/Acrobot/ChestShop/Listeners/pluginEnable.java +++ b/com/Acrobot/ChestShop/Listeners/pluginEnable.java @@ -10,13 +10,11 @@ import com.Acrobot.ChestShop.Protection.Plugins.LockettePlugin; import com.Acrobot.ChestShop.Protection.Security; import com.Acrobot.ChestShop.Utils.uNumber; import com.Acrobot.ChestShop.Utils.uSign; -import com.Acrobot.ChestShop.Utils.uTowny; import com.daemitus.deadbolt.Deadbolt; import com.griefcraft.lwc.LWCPlugin; import com.nijikokun.bukkit.Permissions.Permissions; import com.nijikokun.register.payment.forChestShop.Methods; import com.palmergames.bukkit.towny.Towny; -import info.somethingodd.bukkit.OddItem.OddItem; import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.ServerListener; import org.bukkit.plugin.Plugin; @@ -59,17 +57,22 @@ public class pluginEnable extends ServerListener { DeadboltPlugin.deadbolt = (Deadbolt) plugin; Security.protection = new DeadboltPlugin(); } else if (name.equals("OddItem")) { - if (Odd.oddItem != null) return; - Odd.oddItem = (OddItem) plugin; + if (Odd.isInitialized()) return; + if (plugin.getDescription().getVersion().startsWith("0.7")) { System.out.println(generateOutdatedVersion(name, plugin.getDescription().getVersion(), "0.8")); return; } + Odd.isInitialized = true; } else if (name.equals("Towny")) { if (uSign.towny != null) return; int versionNumber = 0; String[] split = plugin.getDescription().getVersion().split("\\."); - for (int i = 0; i < 4; i++) if (split.length >= i+1 && uNumber.isInteger(split[i])) versionNumber += (Math.pow(10, (3 - i) << 1) * Integer.parseInt(split[i])); //EPIC CODE RIGHT HERE - if(versionNumber < 760047){ System.out.println(ChestShop.chatPrefix + "Your Towny version is outdated! Need version AT LEAST 0.76.0.47! - Your version is " + plugin.getDescription().getVersion()); return; } + for (int i = 0; i < 4; i++) if (split.length >= i + 1 && uNumber.isInteger(split[i])) versionNumber += (Math.pow(10, (3 - i) << 1) * Integer.parseInt(split[i])); //EPIC CODE RIGHT HERE + if (versionNumber < 760047) { System.out.println(generateOutdatedVersion(name, plugin.getDescription().getVersion(), "0.76.0.47")); return; } uSign.towny = (Towny) plugin; } PluginDescriptionFile description = plugin.getDescription(); System.out.println(ChestShop.chatPrefix + description.getName() + " version " + description.getVersion() + " loaded."); } + + private static String generateOutdatedVersion(String pluginName, String curVersion, String neededVersion){ + return (new StringBuilder(7).append(ChestShop.chatPrefix).append("Your ").append(pluginName).append(" is outdated! Need version AT LEAST ").append(neededVersion).append(" - Your version is ").append(curVersion).toString()); + } } diff --git a/com/Acrobot/ChestShop/Listeners/signChange.java b/com/Acrobot/ChestShop/Listeners/signChange.java index e72c47e..2d2128c 100644 --- a/com/Acrobot/ChestShop/Listeners/signChange.java +++ b/com/Acrobot/ChestShop/Listeners/signChange.java @@ -90,7 +90,7 @@ public class signChange extends BlockListener { Block chestBlock = chest.getBlock(); - if(uSign.towny != null && !uTowny.canBuild(player, signBlock.getLocation(), chestBlock.getLocation())){ + if (uSign.towny != null && !uTowny.canBuild(player, signBlock.getLocation(), chestBlock.getLocation())) { player.sendMessage(Config.getLocal(Language.TOWNY_CANNOT_CREATE_SHOP_HERE)); dropSign(event); return; diff --git a/com/Acrobot/ChestShop/Utils/uTowny.java b/com/Acrobot/ChestShop/Utils/uTowny.java index 6d9ac27..edc9bc9 100644 --- a/com/Acrobot/ChestShop/Utils/uTowny.java +++ b/com/Acrobot/ChestShop/Utils/uTowny.java @@ -18,17 +18,17 @@ public class uTowny { return uSign.towny.getTownyUniverse().getTownBlock(chestlocation).getType() == TownBlockType.COMMERCIAL && uSign.towny.getTownyUniverse().getTownBlock(signLocation).getType() == TownBlockType.COMMERCIAL; } - public static boolean isPlotOwner(Player player, Location chestLocation, Location signLocation){ + public static boolean isPlotOwner(Player player, Location chestLocation, Location signLocation) { return isBlockOwner(player, chestLocation) && isBlockOwner(player, signLocation); } - public static boolean canBuild(Player player, Location chestLocation, Location signLocation){ + public static boolean canBuild(Player player, Location chestLocation, Location signLocation) { return !Config.getBoolean(Property.TOWNY_INTEGRATION) || (isInsideShopPlot(chestLocation, signLocation) && isPlotOwner(player, chestLocation, signLocation)); } - private static boolean isBlockOwner(Player player, Location location){ - try{ + private static boolean isBlockOwner(Player player, Location location) { + try { return uSign.towny.getTownyUniverse().getTownBlock(location).isOwner(uSign.towny.getTownyUniverse().getResident(player.getName())); - } catch (NotRegisteredException ex){ return false; } + } catch (NotRegisteredException ex) { return false; } } } diff --git a/plugin.yml b/plugin.yml index 6e3eb17..64d697c 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: ChestShop main: com.Acrobot.ChestShop.ChestShop -version: 3.2 +version: 3.21 author: Acrobot