From 06e02cbc3e1448ef1848aa4ed402abe967aac615 Mon Sep 17 00:00:00 2001 From: Acrobot Date: Fri, 23 Sep 2011 14:07:20 +0200 Subject: [PATCH] - Fixed towny integration (grr... java) - (Tried to) - it shouldn't cause too long message error. --- .../ChestShop/Listeners/playerInteract.java | 2 +- com/Acrobot/ChestShop/Listeners/pluginEnable.java | 5 +++-- com/Acrobot/ChestShop/Listeners/signChange.java | 5 ++--- com/Acrobot/ChestShop/Utils/uSign.java | 3 +++ com/Acrobot/ChestShop/Utils/uTowny.java | 14 ++++++-------- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/com/Acrobot/ChestShop/Listeners/playerInteract.java b/com/Acrobot/ChestShop/Listeners/playerInteract.java index bc9f8d3..273eda6 100644 --- a/com/Acrobot/ChestShop/Listeners/playerInteract.java +++ b/com/Acrobot/ChestShop/Listeners/playerInteract.java @@ -97,7 +97,7 @@ public class playerInteract extends PlayerListener { IInventory inventory = ((CraftInventory) chest.getInventory()).getInventory(); chest = uBlock.findNeighbor(chest); - if (chest != null) inventory = new InventoryLargeChest(player.getName() + "'s Shop", inventory, ((CraftInventory) chest.getInventory()).getInventory()); + if (chest != null) inventory = new InventoryLargeChest("Large chest", inventory, ((CraftInventory) chest.getInventory()).getInventory()); ((CraftPlayer) player).getHandle().a(inventory); //Show inventory on the screen } diff --git a/com/Acrobot/ChestShop/Listeners/pluginEnable.java b/com/Acrobot/ChestShop/Listeners/pluginEnable.java index 847d27d..5d25af6 100644 --- a/com/Acrobot/ChestShop/Listeners/pluginEnable.java +++ b/com/Acrobot/ChestShop/Listeners/pluginEnable.java @@ -9,6 +9,7 @@ import com.Acrobot.ChestShop.Protection.Plugins.LWCplugin; 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; @@ -61,12 +62,12 @@ public class pluginEnable extends ServerListener { if (Odd.oddItem != null) return; Odd.oddItem = (OddItem) plugin; } else if (name.equals("Towny")) { - if (uTowny.towny != null) return; + 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; } - uTowny.towny = (Towny) plugin; + uSign.towny = (Towny) plugin; } PluginDescriptionFile description = plugin.getDescription(); System.out.println(ChestShop.chatPrefix + description.getName() + " version " + description.getVersion() + " loaded."); diff --git a/com/Acrobot/ChestShop/Listeners/signChange.java b/com/Acrobot/ChestShop/Listeners/signChange.java index 3cf4dfe..e72c47e 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(!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; @@ -169,8 +169,7 @@ public class signChange extends BlockListener { } private static boolean formatFirstLine(String line1, Player player) { - return line1.isEmpty() || - (!line1.equals(uLongName.stripName(player.getName())) && !Permission.has(player, Permission.ADMIN)); + return line1.isEmpty() || (!line1.equals(uLongName.stripName(player.getName())) && !Permission.has(player, Permission.ADMIN)); } private static void dropSign(SignChangeEvent event) { diff --git a/com/Acrobot/ChestShop/Utils/uSign.java b/com/Acrobot/ChestShop/Utils/uSign.java index b24548c..6d3ec4d 100644 --- a/com/Acrobot/ChestShop/Utils/uSign.java +++ b/com/Acrobot/ChestShop/Utils/uSign.java @@ -2,6 +2,7 @@ package com.Acrobot.ChestShop.Utils; import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Property; +import com.palmergames.bukkit.towny.Towny; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -18,6 +19,8 @@ public class uSign { Pattern.compile("[\\w :]+") }; + public static Towny towny; //Moved this here - somehow, java fails at try/catch + public static boolean isSign(Block block) { return block.getState() instanceof Sign; } diff --git a/com/Acrobot/ChestShop/Utils/uTowny.java b/com/Acrobot/ChestShop/Utils/uTowny.java index 66681e8..6d9ac27 100644 --- a/com/Acrobot/ChestShop/Utils/uTowny.java +++ b/com/Acrobot/ChestShop/Utils/uTowny.java @@ -2,10 +2,8 @@ package com.Acrobot.ChestShop.Utils; import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Property; -import com.palmergames.bukkit.towny.Towny; -import com.palmergames.bukkit.towny.object.TownBlock; +import com.palmergames.bukkit.towny.NotRegisteredException; import com.palmergames.bukkit.towny.object.TownBlockType; -import com.palmergames.bukkit.towny.object.TownyPermission; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -14,10 +12,10 @@ import org.bukkit.entity.Player; * @author Acrobot */ public class uTowny { - public static Towny towny; + public static boolean isInsideShopPlot(Location chestlocation, Location signLocation) { - return towny.getTownyUniverse().getTownBlock(chestlocation).getType() == TownBlockType.COMMERCIAL && towny.getTownyUniverse().getTownBlock(signLocation).getType() == TownBlockType.COMMERCIAL; + 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){ @@ -25,12 +23,12 @@ public class uTowny { } public static boolean canBuild(Player player, Location chestLocation, Location signLocation){ - return towny == null || !Config.getBoolean(Property.TOWNY_INTEGRATION) || (isInsideShopPlot(chestLocation, signLocation) && isPlotOwner(player, chestLocation, signLocation)); + return !Config.getBoolean(Property.TOWNY_INTEGRATION) || (isInsideShopPlot(chestLocation, signLocation) && isPlotOwner(player, chestLocation, signLocation)); } private static boolean isBlockOwner(Player player, Location location){ try{ - return towny.getTownyUniverse().getTownBlock(location).isOwner(towny.getTownyUniverse().getResident(player.getName())); - } catch (Exception ex){ return false; } + return uSign.towny.getTownyUniverse().getTownBlock(location).isOwner(uSign.towny.getTownyUniverse().getResident(player.getName())); + } catch (NotRegisteredException ex){ return false; } } }