@Command( name = "withdraw", permission = "mytown.cmd.assistant.bank.withdraw", parentName = "mytown.cmd.everyone.bank", syntax = "/town bank withdraw <amount>") public static CommandResponse bankWithdrawCommand(ICommandSender sender, List<String> args) { if (args.size() < 1) return CommandResponse.SEND_SYNTAX; if (!StringUtils.tryParseInt(args.get(0))) throw new MyTownCommandException("mytown.cmd.err.notPositiveInteger", args.get(0)); Resident res = MyTownUniverse.instance.getOrMakeResident(sender); Town town = getTownFromResident(res); if (town instanceof AdminTown) throw new MyTownCommandException("mytown.cmd.err.adminTown", town.getName()); int amount = Integer.parseInt(args.get(0)); if (town.bank.getAmount() < amount) throw new MyTownCommandException( "mytown.cmd.err.bank.withdraw", EconomyProxy.getCurrency(town.bank.getAmount())); makeRefund(res.getPlayer(), amount); town.bank.addAmount(-amount); getDatasource().saveTownBank(town.bank); return CommandResponse.DONE; }
@Command( name = "set", permission = "mytown.cmd.assistant.plot.limit.set", parentName = "mytown.cmd.assistant.plot.limit", syntax = "/town plot limit set <limit>") public static CommandResponse plotLimitSetCommand(ICommandSender sender, List<String> args) { if (args.size() < 1) return CommandResponse.SEND_SYNTAX; if (!StringUtils.tryParseInt(args.get(0)) || Integer.parseInt(args.get(0)) < 1) { throw new MyTownCommandException("mytown.cmd.err.notPositiveInteger", args.get(0)); } int limit = Integer.parseInt(args.get(0)); Resident res = MyTownUniverse.instance.getOrMakeResident(sender); Town town = getTownFromResident(res); town.plotsContainer.setMaxPlots(limit); getDatasource().saveTown(town); res.sendMessage( getLocal() .getLocalization( "mytown.notification.plot.limit.set", town.plotsContainer.getMaxPlots())); return CommandResponse.DONE; }
@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; }