2011-09-22 15:56:06 +02:00
|
|
|
package com.Acrobot.ChestShop.Utils;
|
|
|
|
|
|
|
|
import com.Acrobot.ChestShop.Config.Config;
|
|
|
|
import com.Acrobot.ChestShop.Config.Property;
|
2011-09-23 14:07:20 +02:00
|
|
|
import com.palmergames.bukkit.towny.NotRegisteredException;
|
2011-09-22 15:56:06 +02:00
|
|
|
import com.palmergames.bukkit.towny.object.TownBlockType;
|
2012-03-17 15:00:25 +01:00
|
|
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
2011-09-22 15:56:06 +02:00
|
|
|
import org.bukkit.Location;
|
2012-02-16 19:09:37 +01:00
|
|
|
import org.bukkit.block.Block;
|
2011-09-22 15:56:06 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class uTowny {
|
|
|
|
public static boolean isInsideShopPlot(Location chestlocation, Location signLocation) {
|
2011-09-23 14:07:20 +02:00
|
|
|
return uSign.towny.getTownyUniverse().getTownBlock(chestlocation).getType() == TownBlockType.COMMERCIAL && uSign.towny.getTownyUniverse().getTownBlock(signLocation).getType() == TownBlockType.COMMERCIAL;
|
2011-09-22 15:56:06 +02:00
|
|
|
}
|
|
|
|
|
2011-09-25 16:17:44 +02:00
|
|
|
public static boolean isPlotOwner(Player player, Location chestLocation, Location signLocation) {
|
2012-01-09 22:39:38 +01:00
|
|
|
if (Config.getBoolean(Property.TOWNY_SHOPS_FOR_OWNERS_ONLY)) return isBlockOwner(player, chestLocation) && isBlockOwner(player, signLocation);
|
|
|
|
return isResident(player, chestLocation) && isResident(player, signLocation);
|
2011-09-22 15:56:06 +02:00
|
|
|
}
|
|
|
|
|
2012-02-16 19:09:37 +01:00
|
|
|
public static boolean isInWilderness(Location chestLocation, Location signLocation) {
|
|
|
|
return isInWilderness(chestLocation.getBlock()) || isInWilderness(signLocation.getBlock());
|
|
|
|
}
|
|
|
|
|
2012-03-17 15:00:25 +01:00
|
|
|
private static boolean isInWilderness(Block block) {
|
2012-02-16 19:09:37 +01:00
|
|
|
return uSign.towny.getTownyUniverse().isWilderness(block);
|
2011-09-29 20:29:39 +02:00
|
|
|
}
|
|
|
|
|
2011-09-25 16:17:44 +02:00
|
|
|
public static boolean canBuild(Player player, Location chestLocation, Location signLocation) {
|
2012-02-16 19:09:37 +01:00
|
|
|
return uSign.towny == null || !Config.getBoolean(Property.TOWNY_INTEGRATION) || (!isInWilderness(chestLocation, signLocation) && isInsideShopPlot(chestLocation, signLocation) && isPlotOwner(player, chestLocation, signLocation));
|
2011-09-22 15:56:06 +02:00
|
|
|
}
|
|
|
|
|
2011-09-25 16:17:44 +02:00
|
|
|
private static boolean isBlockOwner(Player player, Location location) {
|
2012-03-17 15:00:25 +01:00
|
|
|
try {
|
|
|
|
return uSign.towny.getTownyUniverse().getTownBlock(location).isOwner(TownyUniverse.getDataSource().getResident(player.getName()));
|
|
|
|
} catch (NotRegisteredException ex) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-09 22:39:38 +01:00
|
|
|
}
|
2012-03-17 15:00:25 +01:00
|
|
|
|
|
|
|
private static boolean isResident(Player p, Location l) {
|
|
|
|
try {
|
|
|
|
return uSign.towny.getTownyUniverse().getTownBlock(l).getTown().hasResident(p.getName());
|
|
|
|
} catch (NotRegisteredException ex) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-22 15:56:06 +02:00
|
|
|
}
|
|
|
|
}
|