com.palmergames.bukkit.towny.object.TownyUniverse Java Examples

The following examples show how to use com.palmergames.bukkit.towny.object.TownyUniverse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClaimChecks.java    From WildernessTp with MIT License 5 votes vote down vote up
private boolean townyClaim(Location loc) {
    if (wild.getConfig().getBoolean("Towny")) {
        try {
            if (!TownyUniverse.isWilderness(loc.getBlock()) && !checkSurroundingTowns(loc))
                return true;
            else
                return false;
        } catch (NullPointerException e) {
            wild.getLogger().info(loc.toString());
        }
    } else
        return false;
    return false;
}
 
Example #2
Source File: ClaimChecks.java    From WildernessTp with MIT License 5 votes vote down vote up
private boolean checkSurroundingTowns(Location loc) {
    int distance = range / 2;
    Vector top = new Vector(loc.getX() + distance, loc.getY(), loc.getZ() + distance);
    Vector bottom = new Vector(loc.getX() - distance, loc.getY(), loc.getZ() - distance);
    for (int z = bottom.getBlockZ(); z <= top.getBlockZ(); z++) {
        for (int x = bottom.getBlockX(); x <= top.getBlockX(); x++) {
            Block block = new Location(loc.getWorld(), x, loc.getWorld().getHighestBlockYAt(x, z), z).getBlock();
            if (!TownyUniverse.isWilderness(block))
                return true;
        }
    }
    return false;
}
 
Example #3
Source File: TownyListener.java    From ShopChest with MIT License 5 votes vote down vote up
private boolean handleForLocation(Player player, Location loc, Cancellable e) {
    TownBlock townBlock = TownyUniverse.getTownBlock(loc);
    if (townBlock == null)
        return false;

    try {
        Town town = townBlock.getTown();
        Optional<Resident> playerResident = town.getResidents().stream()
                .filter(r -> r.getName().equals(player.getName()))
                .findFirst();
                
        if (!playerResident.isPresent()) {
            e.setCancelled(true);
            plugin.debug("Cancel Reason: Towny (no resident)");
            return true;
        }

        Resident resident = playerResident.get();
        String plotType = townBlock.getType().name();
        boolean cancel = (resident.isMayor() && !Config.townyShopPlotsMayor.contains(plotType))
                || (resident.isKing() && !Config.townyShopPlotsKing.contains(plotType))
                || (!resident.isKing() && !resident.isMayor() && !Config.townyShopPlotsResidents.contains(plotType));
        
        if (cancel) {
            e.setCancelled(true);
            plugin.debug("Cancel Reason: Towny (no permission)");
            return true;
        }
    } catch (NotRegisteredException ignored) {
    }
    return false;
}
 
Example #4
Source File: TownyHandler.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isCommercialArea(Location loc) {
	Plugin plugin = Bukkit.getPluginManager().getPlugin("Towny");
	if (plugin != null) {
		TownBlock townBlock = TownyUniverse.getTownBlock(loc);
		return townBlock.getType() == TownBlockType.COMMERCIAL;
	} else {
		return false;
	}
}