@Command( name = "delete", permission = "mytown.cmd.mayor.leave.delete", parentName = "mytown.cmd.everyone.leave", syntax = "/town leave delete") public static CommandResponse leaveDeleteCommand(ICommandSender sender, List<String> args) { Resident res = MyTownUniverse.instance.getOrMakeResident(sender); Town town = getTownFromResident(res); EntityPlayer player = (EntityPlayer) sender; if (town.residentsMap.get(res).getType() == Rank.Type.MAYOR) { town.notifyEveryone( getLocal() .getLocalization( "mytown.notification.town.deleted", town.getName(), res.getPlayerName())); int refund = 0; for (TownBlock block : town.townBlocksContainer) { refund += block.getPricePaid(); } refund += town.bank.getAmount(); makeRefund(player, refund); getDatasource().deleteTown(town); } return CommandResponse.DONE; }
// Temporary here, might integrate in the methods protected static boolean checkNearby(int dim, int x, int z, Town town) { int[] dx = {1, 0, -1, 0}; int[] dz = {0, 1, 0, -1}; for (int i = 0; i < 4; i++) { TownBlock block = getUniverse().blocks.get(dim, x + dx[i], z + dz[i]); if (block != null && block.getTown() == town) { return true; } } return false; }
public static boolean hasPermission( Resident res, FlagType<Boolean> flagType, int dim, Volume volume) { boolean inWild = false; for (int townBlockX = volume.getMinX() >> 4; townBlockX <= volume.getMaxX() >> 4; townBlockX++) { for (int townBlockZ = volume.getMinZ() >> 4; townBlockZ <= volume.getMaxZ() >> 4; townBlockZ++) { TownBlock townBlock = MyTownUniverse.instance.blocks.get(dim, townBlockX, townBlockZ); if (townBlock == null) { inWild = true; continue; } Town town = townBlock.getTown(); Volume rangeBox = volume.intersect(townBlock.toVolume()); // If the range volume intersects the TownBlock, check Town/Plot permissions if (rangeBox != null) { int totalIntersectArea = 0; // Check every plot in the current TownBlock and sum all plot areas for (Plot plot : townBlock.plotsContainer) { Volume plotIntersection = volume.intersect(plot.toVolume()); if (plotIntersection != null) { if (!plot.hasPermission(res, flagType)) { return false; } totalIntersectArea += plotIntersection.getVolumeAmount(); } } // If plot area sum is not equal to range area, check town permission if (totalIntersectArea != rangeBox.getVolumeAmount()) { if (!town.hasPermission(res, flagType)) { return false; } } } } } if (inWild) { return Wild.instance.hasPermission(res, flagType); } return true; }
@Command( name = "claim", permission = "mytown.cmd.assistant.claim", parentName = "mytown.cmd", syntax = "/town claim [range]") public static CommandResponse claimCommand(ICommandSender sender, List<String> args) { EntityPlayer player = (EntityPlayer) sender; Resident res = MyTownUniverse.instance.getOrMakeResident(player); Town town = getTownFromResident(res); boolean isFarClaim = false; if (args.size() < 1) { if (town.townBlocksContainer.size() >= town.getMaxBlocks()) throw new MyTownCommandException("mytown.cmd.err.town.maxBlocks", 1); if (getUniverse().blocks.contains(player.dimension, player.chunkCoordX, player.chunkCoordZ)) throw new MyTownCommandException("mytown.cmd.err.claim.already"); if (!checkNearby(player.dimension, player.chunkCoordX, player.chunkCoordZ, town)) { if (town.townBlocksContainer.getFarClaims() >= town.getMaxFarClaims()) throw new MyTownCommandException("mytown.cmd.err.claim.far.notAllowed"); isFarClaim = true; } for (int x = player.chunkCoordX - Config.instance.distanceBetweenTowns.get(); x <= player.chunkCoordX + Config.instance.distanceBetweenTowns.get(); x++) { for (int z = player.chunkCoordZ - Config.instance.distanceBetweenTowns.get(); z <= player.chunkCoordZ + Config.instance.distanceBetweenTowns.get(); z++) { Town nearbyTown = MyTownUtils.getTownAtPosition(player.dimension, x, z); if (nearbyTown != null && nearbyTown != town && !(Boolean) nearbyTown.flagsContainer.getValue(FlagType.NEARBY)) throw new MyTownCommandException( "mytown.cmd.err.claim.tooClose", nearbyTown.getName(), Config.instance.distanceBetweenTowns.get()); } } if (isFarClaim && town.townBlocksContainer.getFarClaims() + 1 > town.getMaxFarClaims()) throw new MyTownCommandException("mytown.cmd.err.claim.far.notAllowed"); int price = (isFarClaim ? Config.instance.costAmountClaimFar.get() : Config.instance.costAmountClaim.get()) + Config.instance.costAdditionClaim.get() * town.townBlocksContainer.size(); makeBankPayment(player, town, price); TownBlock block = getUniverse() .newBlock( player.dimension, player.chunkCoordX, player.chunkCoordZ, isFarClaim, price, town); if (block == null) throw new MyTownCommandException("mytown.cmd.err.claim.failed"); getDatasource().saveBlock(block); res.sendMessage( getLocal() .getLocalization( "mytown.notification.block.added", block.getX() * 16, block.getZ() * 16, block.getX() * 16 + 15, block.getZ() * 16 + 15, town.getName())); } else { if (!StringUtils.tryParseInt(args.get(0))) throw new MyTownCommandException("mytown.cmd.err.notPositiveInteger", args.get(0)); int radius = Integer.parseInt(args.get(0)); List<ChunkPos> chunks = WorldUtils.getChunksInBox( player.dimension, (int) (player.posX - radius * 16), (int) (player.posZ - radius * 16), (int) (player.posX + radius * 16), (int) (player.posZ + radius * 16)); isFarClaim = true; for (Iterator<ChunkPos> it = chunks.iterator(); it.hasNext(); ) { ChunkPos chunk = it.next(); if (checkNearby(player.dimension, chunk.getX(), chunk.getZ(), town)) { isFarClaim = false; } if (getUniverse().blocks.contains(player.dimension, chunk.getX(), chunk.getZ())) it.remove(); for (int x = chunk.getX() - Config.instance.distanceBetweenTowns.get(); x <= chunk.getX() + Config.instance.distanceBetweenTowns.get(); x++) { for (int z = chunk.getZ() - Config.instance.distanceBetweenTowns.get(); z <= chunk.getZ() + Config.instance.distanceBetweenTowns.get(); z++) { Town nearbyTown = MyTownUtils.getTownAtPosition(player.dimension, x, z); if (nearbyTown != null && nearbyTown != town && !(Boolean) nearbyTown.flagsContainer.getValue(FlagType.NEARBY)) throw new MyTownCommandException( "mytown.cmd.err.claim.tooClose", nearbyTown.getName(), Config.instance.distanceBetweenTowns.get()); } } } if (town.townBlocksContainer.size() + chunks.size() > town.getMaxBlocks()) throw new MyTownCommandException("mytown.cmd.err.town.maxBlocks", chunks.size()); if (isFarClaim && town.townBlocksContainer.getFarClaims() + 1 > town.getMaxFarClaims()) throw new MyTownCommandException("mytown.cmd.err.claim.far.notAllowed"); makeBankPayment( player, town, (isFarClaim ? Config.instance.costAmountClaimFar.get() + Config.instance.costAmountClaim.get() * (chunks.size() - 1) : Config.instance.costAmountClaim.get() * chunks.size()) + MathUtils.sumFromNtoM( town.townBlocksContainer.size(), town.townBlocksContainer.size() + chunks.size() - 1) * Config.instance.costAdditionClaim.get()); for (ChunkPos chunk : chunks) { int price = (isFarClaim ? Config.instance.costAmountClaimFar.get() : Config.instance.costAmountClaim.get()) + Config.instance.costAdditionClaim.get() * town.townBlocksContainer.size(); TownBlock block = getUniverse() .newBlock(player.dimension, chunk.getX(), chunk.getZ(), isFarClaim, price, town); // Only one of the block will be a farClaim, rest will be normal claim isFarClaim = false; getDatasource().saveBlock(block); res.sendMessage( getLocal() .getLocalization( "mytown.notification.block.added", block.getX() * 16, block.getZ() * 16, block.getX() * 16 + 15, block.getZ() * 16 + 15, town.getName())); } } return CommandResponse.DONE; }
@Command( name = "unclaim", permission = "mytown.cmd.assistant.unclaim", parentName = "mytown.cmd", syntax = "/town unclaim") public static CommandResponse unclaimCommand(ICommandSender sender, List<String> args) { EntityPlayer player = (EntityPlayer) sender; Resident res = MyTownUniverse.instance.getOrMakeResident(sender); TownBlock block = getBlockAtResident(res); Town town = getTownFromResident(res); if (town != block.getTown()) throw new MyTownCommandException("mytown.cmd.err.unclaim.notInTown"); if (block.isPointIn(town.getSpawn().getDim(), town.getSpawn().getX(), town.getSpawn().getZ())) throw new MyTownCommandException("mytown.cmd.err.unclaim.spawnPoint"); if (!checkNearby(block.getDim(), block.getX(), block.getZ(), town) && town.townBlocksContainer.size() <= 1) { throw new MyTownCommandException("mytown.cmd.err.unclaim.lastClaim"); } getDatasource().deleteBlock(block); res.sendMessage( getLocal() .getLocalization( "mytown.notification.block.removed", block.getX() << 4, block.getZ() << 4, block.getX() << 4 + 15, block.getZ() << 4 + 15, town.getName())); makeBankRefund(player, town, block.getPricePaid()); return CommandResponse.DONE; }
public boolean getPermission( Player player, TownBlockStatus status, WorldCoord pos, TownyPermission.ActionType actionType) { if (status == TownBlockStatus.OFF_WORLD || status == TownBlockStatus.WARZONE || status == TownBlockStatus.PLOT_OWNER || status == TownBlockStatus .TOWN_OWNER) // || plugin.isTownyAdmin(player)) // status == TownBlockStatus.ADMIN // || return true; if (status == TownBlockStatus.NOT_REGISTERED) { cacheBlockErrMsg(player, TownySettings.getLangString("msg_cache_block_error")); return false; } if (status == TownBlockStatus.LOCKED) { cacheBlockErrMsg(player, TownySettings.getLangString("msg_cache_block_error_locked")); return false; } TownBlock townBlock; // Town town; try { townBlock = pos.getTownBlock(); // town = townBlock.getTown(); } catch (NotRegisteredException e) { // Wilderness Permissions if (status == TownBlockStatus.UNCLAIMED_ZONE) if (TownyUniverse.getPermissionSource() .hasPermission(player, PermissionNodes.TOWNY_WILD_ALL.getNode(actionType.toString()))) { return true; } else if (!TownyPermission.getUnclaimedZonePerm(actionType, pos.getWorld())) { // Don't have permission to build/destroy/switch/item_use here cacheBlockErrMsg( player, String.format( TownySettings.getLangString("msg_cache_block_error_wild"), actionType.toString())); return false; } else return true; else { TownyMessaging.sendErrorMsg(player, "Error updating destroy permission."); return false; } } // Allow admins to have ALL permissions over towns. if (TownyUniverse.getPermissionSource().isTownyAdmin(player)) return true; // Plot Permissions // try { // Resident owner = townBlock.getResident(); if (townBlock.hasResident()) { if (status == TownBlockStatus.PLOT_FRIEND) { if (townBlock.getPermissions().getResidentPerm(actionType)) return true; else { cacheBlockErrMsg( player, String.format( TownySettings.getLangString("msg_cache_block_error_plot"), "friends", actionType.toString())); return false; } } else if (status == TownBlockStatus.PLOT_ALLY) if (townBlock.getPermissions().getAllyPerm(actionType)) return true; else { cacheBlockErrMsg( player, String.format( TownySettings.getLangString("msg_cache_block_error_plot"), "allies", actionType.toString())); return false; } else { // TODO: (Remove) if (status == TownBlockStatus.OUTSIDER) if (townBlock.getPermissions().getOutsiderPerm(actionType)) { // System.out.print("Outsider true"); return true; } else { cacheBlockErrMsg( player, String.format( TownySettings.getLangString("msg_cache_block_error_plot"), "outsiders", actionType.toString())); return false; } } } // } catch (NotRegisteredException x) { // } // Town Permissions if (status == TownBlockStatus.TOWN_RESIDENT) { if (townBlock.getPermissions().getResidentPerm(actionType)) return true; else { cacheBlockErrMsg( player, String.format( TownySettings.getLangString("msg_cache_block_error_town_resident"), actionType.toString())); return false; } } else if (status == TownBlockStatus.TOWN_ALLY) if (townBlock.getPermissions().getAllyPerm(actionType)) return true; else { cacheBlockErrMsg( player, String.format( TownySettings.getLangString("msg_cache_block_error_town_allies"), actionType.toString())); return false; } else if (status == TownBlockStatus.OUTSIDER || status == TownBlockStatus.ENEMY) if (townBlock.getPermissions().getOutsiderPerm(actionType)) return true; else { cacheBlockErrMsg( player, String.format( TownySettings.getLangString("msg_cache_block_error_town_outsider"), actionType.toString())); return false; } TownyMessaging.sendErrorMsg(player, "Error updating " + actionType.toString() + " permission."); return false; }
public TownBlockStatus getStatusCache(Player player, WorldCoord worldCoord) { // if (isTownyAdmin(player)) // return TownBlockStatus.ADMIN; if (!worldCoord.getWorld().isUsingTowny()) return TownBlockStatus.OFF_WORLD; // TownyUniverse universe = plugin.getTownyUniverse(); TownBlock townBlock; Town town; try { townBlock = worldCoord.getTownBlock(); town = townBlock.getTown(); if (townBlock.isLocked()) { // Push the TownBlock location to the queue for a snapshot (if it's not already in the // queue). if (town.getWorld().isUsingPlotManagementRevert() && (TownySettings.getPlotManagementSpeed() > 0)) { TownyRegenAPI.addWorldCoord(townBlock.getWorldCoord()); return TownBlockStatus.LOCKED; } townBlock.setLocked(false); } } catch (NotRegisteredException e) { // Unclaimed Zone switch rights return TownBlockStatus.UNCLAIMED_ZONE; } Resident resident; try { resident = TownyUniverse.getDataSource().getResident(player.getName()); } catch (TownyException e) { System.out.print("Failed to fetch resident: " + player.getName()); return TownBlockStatus.NOT_REGISTERED; } try { // War Time switch rights if (isWarTime()) { if (TownySettings.isAllowWarBlockGriefing()) { try { if (!resident.getTown().getNation().isNeutral() && !town.getNation().isNeutral()) return TownBlockStatus.WARZONE; } catch (NotRegisteredException e) { } } // If this town is not in a nation and we are set to non neutral status during war. if (!TownySettings.isWarTimeTownsNeutral() && !town.hasNation()) return TownBlockStatus.WARZONE; } // Town Owner Override try { if (townBlock.getTown().isMayor(resident) || townBlock.getTown().hasAssistant(resident)) return TownBlockStatus.TOWN_OWNER; } 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 if (resident.hasTown() && isAlly(owner.getTown(), resident.getTown())) return TownBlockStatus.PLOT_ALLY; 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 (isAlly(town, resident.getTown())) return TownBlockStatus.TOWN_ALLY; else if (isEnemy(resident.getTown(), town)) { if (townBlock.isWarZone()) return TownBlockStatus.WARZONE; else return TownBlockStatus.ENEMY; } 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; } }
/** * (Please use addDeleteTownBlockIdQueue in TownyRegenAPI) * * @param townBlock */ @Deprecated public void deleteTownBlockIds(TownBlock townBlock) { WorldCoord worldCoord = townBlock.getWorldCoord(); TownyRegenAPI.addDeleteTownBlockIdQueue(worldCoord); }