public TownBlockStatus getStatusCache(Player player, WorldCoord worldCoord) { if (isTownyAdmin(player)) return TownBlockStatus.ADMIN; if (!worldCoord.getWorld().isUsingTowny()) return TownBlockStatus.OFF_WORLD; TownyUniverse universe = getTownyUniverse(); TownBlock townBlock; Town town; try { townBlock = worldCoord.getTownBlock(); town = townBlock.getTown(); } catch (NotRegisteredException e) { // Unclaimed Zone switch rights return TownBlockStatus.UNCLAIMED_ZONE; } try { Resident resident = universe.getResident(player.getName()); // War Time switch rights if (universe.isWarTime()) try { if (!resident.getTown().getNation().isNeutral() && !town.getNation().isNeutral()) return TownBlockStatus.WARZONE; } catch (NotRegisteredException e) { } // Resident Plot switch rights try { Resident owner = townBlock.getResident(); if (resident == owner) return TownBlockStatus.PLOT_OWNER; else if (owner.hasFriend(resident)) return TownBlockStatus.PLOT_FRIEND; else // Exit out and use town permissions throw new TownyException(); } catch (NotRegisteredException x) { } catch (TownyException x) { } // Town resident destroy rights if (!resident.hasTown()) throw new TownyException(); if (resident.getTown() != town) { // Allied destroy rights if (universe.isAlly(resident.getTown(), town)) return TownBlockStatus.TOWN_ALLY; else return TownBlockStatus.OUTSIDER; } else if (resident.isMayor() || resident.getTown().hasAssistant(resident)) return TownBlockStatus.TOWN_OWNER; else return TownBlockStatus.TOWN_RESIDENT; } catch (TownyException e) { // Outsider destroy rights return TownBlockStatus.OUTSIDER; } }
public void removeTownBlock(TownBlock townBlock) { try { if (townBlock.hasResident()) townBlock.getResident().removeTownBlock(townBlock); } catch (NotRegisteredException e) { } try { if (townBlock.hasTown()) townBlock.getTown().removeTownBlock(townBlock); } catch (NotRegisteredException e) { } removeTownBlock(townBlock.getCoord()); }
public boolean getPermission( Player player, TownBlockStatus status, WorldCoord pos, TownyPermission.ActionType actionType) { if (status == TownBlockStatus.OFF_WORLD || status == TownBlockStatus.ADMIN || status == TownBlockStatus.WARZONE || status == TownBlockStatus.PLOT_OWNER || status == TownBlockStatus.TOWN_OWNER) return true; TownBlock townBlock; Town town; try { townBlock = pos.getTownBlock(); town = townBlock.getTown(); } catch (NotRegisteredException e) { // Wilderness Permissions if (status == TownBlockStatus.UNCLAIMED_ZONE) if (hasPermission(player, "towny.wild." + actionType.toString())) return true; else if (!TownyPermission.getUnclaimedZone(actionType, pos.getWorld())) { // TODO: Have permission to destroy here cacheBlockErrMsg(player, "Not allowed to " + actionType.toString() + " in the wild."); return false; } else return true; else { sendErrorMsg(player, "Error updating destroy permission."); return false; } } // Plot Permissions try { Resident owner = townBlock.getResident(); if (status == TownBlockStatus.PLOT_FRIEND) { if (owner.getPermissions().getResident(actionType)) return true; else { cacheBlockErrMsg( player, "Owner doesn't allow friends to " + actionType.toString() + " here."); return false; } } else if (status == TownBlockStatus.PLOT_ALLY) if (owner.getPermissions().getAlly(actionType)) return true; else { cacheBlockErrMsg( player, "Owner doesn't allow allies to " + actionType.toString() + " here."); return false; } else if (status == TownBlockStatus.OUTSIDER) if (owner.getPermissions().getOutsider(actionType)) return true; else { cacheBlockErrMsg( player, "Owner doesn't allow outsiders to " + actionType.toString() + " here."); return false; } } catch (NotRegisteredException x) { } // Town Permissions if (status == TownBlockStatus.TOWN_RESIDENT) { if (town.getPermissions().getResident(actionType)) return true; else { cacheBlockErrMsg(player, "Residents aren't allowed to " + actionType.toString() + "."); return false; } } else if (status == TownBlockStatus.TOWN_ALLY) if (town.getPermissions().getAlly(actionType)) return true; else { cacheBlockErrMsg(player, "Allies aren't allowed to " + actionType.toString() + " here."); return false; } else if (status == TownBlockStatus.OUTSIDER) if (town.getPermissions().getOutsider(actionType)) return true; else { cacheBlockErrMsg(player, "Outsiders aren't allowed to " + actionType.toString() + " here."); return false; } sendErrorMsg(player, "Error updating " + actionType.toString() + " permission."); return false; }