- Fixed towny integration (grr... java)

- (Tried to) - it shouldn't cause too long message error.
This commit is contained in:
Acrobot 2011-09-23 14:07:20 +02:00
parent ad51a87175
commit 06e02cbc3e
5 changed files with 15 additions and 14 deletions

View File

@ -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
}

View File

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

View File

@ -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) {

View File

@ -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;
}

View File

@ -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; }
}
}