public boolean hasPermission(Resident res, Segment segment, int dim, int x, int y, int z) { TownBlock townBlock = getDatasource().getBlock(dim, x >> 4, z >> 4); if (townBlock == null) { if (res == null) { return !Wild.instance.getValue(segment.getFlag()).equals(segment.getDenialValue()); } else { if (!Wild.instance.hasPermission(res, segment.getFlag(), segment.getDenialValue())) { res.sendMessage(segment.getFlag().getLocalizedProtectionDenial()); return false; } } } else { Town town = townBlock.getTown(); if (res == null) { return !town.getValueAtCoords(dim, x, y, z, segment.getFlag()) .equals(segment.getDenialValue()); } else { if (!town.hasPermission(res, segment.getFlag(), segment.getDenialValue(), dim, x, y, z)) { res.protectionDenial( segment.getFlag().getLocalizedProtectionDenial(), Formatter.formatOwnersToString(town, dim, x, y, z)); return false; } } } return true; }
@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; }
// 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; }
public boolean hasPermission(Resident res, Segment segment, int dim, Volume area) { boolean inWild = false; for (int townBlockX = area.getMinX() >> 4; townBlockX <= area.getMaxX() >> 4; townBlockX++) { for (int townBlockZ = area.getMinZ() >> 4; townBlockZ <= area.getMaxZ() >> 4; townBlockZ++) { TownBlock townBlock = getDatasource().getBlock(dim, townBlockX, townBlockZ); if (townBlock == null) { inWild = true; } else { Town town = townBlock.getTown(); Volume rangeBox = townBlock.getAreaLimit(area); int totalIntersectArea = 0; // Check every plot in the current TownBlock and sum all plot areas for (Plot plot : townBlock.getPlots()) { int plotIntersectArea = plot.getIntersectingArea(rangeBox); if (plotIntersectArea > 0) { if (res == null) { if (plot.getValue(segment.getFlag()).equals(segment.getDenialValue())) { return false; } } else { if (!plot.hasPermission(res, segment.getFlag(), segment.getDenialValue())) { res.protectionDenial( segment.getFlag().getLocalizedProtectionDenial(), LocalizationProxy.getLocalization() .getLocalization( "mytown.notification.town.owners", town.getMayor() == null ? "SERVER ADMINS" : town.getMayor().getPlayerName())); return false; } } } totalIntersectArea += plotIntersectArea; } // If plot area sum is not equal to range area, check town permission if (totalIntersectArea != getArea(rangeBox)) { if (res == null) { if (town.getValue(segment.getFlag()).equals(segment.getDenialValue())) { return false; } } else { if (!town.hasPermission(res, segment.getFlag(), segment.getDenialValue())) { res.protectionDenial( segment.getFlag().getLocalizedProtectionDenial(), LocalizationProxy.getLocalization() .getLocalization( "mytown.notification.town.owners", town.getMayor() == null ? "SERVER ADMINS" : town.getMayor().getPlayerName())); return false; } } } } } } if (inWild) { if (res == null) { if (Wild.instance.getValue(segment.getFlag()).equals(segment.getDenialValue())) { return false; } } else { if (!Wild.instance.hasPermission(res, segment.getFlag(), segment.getDenialValue())) { res.sendMessage(segment.getFlag().getLocalizedProtectionDenial()); return false; } } } return true; }
/** Returns the town at the specified position or null if nothing found. */ public static Town getTownAtPosition(int dim, int x, int z) { TownBlock block = MyTownUniverse.instance.blocks.get(dim, x, z); if (block == null) return null; return block.getTown(); }