@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; }
/** Checking item usage for right click on entity */ public boolean checkEntityRightClick(ItemStack item, Resident res, Entity entity) { for (Iterator<SegmentEntity> it = segmentsEntities.iterator(); it.hasNext(); ) { SegmentEntity segment = it.next(); if (segment.getType() == EntityType.PROTECT && segment.getCheckClass().isAssignableFrom(entity.getClass())) { int dim = entity.dimension; int x = (int) Math.floor(entity.posX); int y = (int) Math.floor(entity.posY); int z = (int) Math.floor(entity.posZ); if (!hasPermission(res, segment, dim, x, y, z)) { return true; } } } if (item == null) return false; for (Iterator<SegmentItem> it = segmentsItems.iterator(); it.hasNext(); ) { SegmentItem segment = it.next(); if (segment.getType() == ItemType.RIGHT_CLICK_ENTITY && segment.getCheckClass().isAssignableFrom(item.getItem().getClass())) { try { if (segment.checkCondition(item)) { int range = segment.getRange(item); int dim = entity.dimension; int x = (int) Math.floor(entity.posX); int y = (int) Math.floor(entity.posY); int z = (int) Math.floor(entity.posZ); if (range == 0) { if (!hasPermission(res, segment, dim, x, y, z)) { return true; } } else { Volume rangeBox = new Volume(x - range, y - range, z - range, x + range, y + range, z + range); if (!hasPermission(res, segment, dim, rangeBox)) { return true; } } } } catch (Exception ex) { MyTown.instance.LOG.error( "Failed to check item use on {} at the player {} ({}, {}, {} | Dim: {})", item.getDisplayName(), res.getPlayerName(), entity.posX, entity.posY, entity.posZ, entity.dimension); MyTown.instance.LOG.error(ExceptionUtils.getStackTrace(ex)); if (ex instanceof GetterException || ex instanceof ConditionException) { this.disableSegment(it, segment, ex.getMessage()); } } } } return false; }
@Command( name = "kick", permission = "mytown.cmd.assistant.kick", parentName = "mytown.cmd", syntax = "/town kick <resident>", completionKeys = {"residentCompletion"}) public static CommandResponse kickCommand(ICommandSender sender, List<String> args) { if (args.size() < 1) { return CommandResponse.SEND_SYNTAX; } Resident res = MyTownUniverse.instance.getOrMakeResident(sender); Resident target = getResidentFromName(args.get(0)); Town town = getTownFromResident(res); if (!target.townsContainer.contains(town)) { throw new MyTownCommandException( "mytown.cmd.err.resident.notsametown", args.get(0), town.getName()); } if (target == res) { throw new MyTownCommandException("mytown.cmd.err.kick.self"); } if (town.residentsMap.get(target) == town.ranksContainer.getMayorRank()) { throw new MyTownCommandException("mytown.cmd.err.kick.mayor"); } getDatasource().unlinkResidentFromTown(target, town); target.sendMessage( getLocal().getLocalization("mytown.notification.town.kicked", town.getName())); town.notifyEveryone( getLocal() .getLocalization( "mytown.notification.town.left", target.getPlayerName(), town.getName())); return CommandResponse.DONE; }
@Command( name = "pass", permission = "mytown.cmd.mayor.pass", parentName = "mytown.cmd", syntax = "/town pass <resident>", completionKeys = {"residentCompletion"}) public static CommandResponse passCommand(ICommandSender sender, List<String> args) { if (args.size() < 1) return CommandResponse.SEND_SYNTAX; Resident res = MyTownUniverse.instance.getOrMakeResident(sender); Resident target = getResidentFromName(args.get(0)); if (res == target) { throw new MyTownCommandException("mytown.cmd.err.resident.same"); } Town town = getTownFromResident(res); if (!town.residentsMap.containsKey(target)) { throw new MyTownCommandException( "mytown.cmd.err.resident.notsametown", target.getPlayerName(), town.getName()); } if (town.residentsMap.get(res).getType() == Rank.Type.MAYOR) { getDatasource().updateResidentToTownLink(target, town, town.ranksContainer.getMayorRank()); target.sendMessage(getLocal().getLocalization("mytown.notification.town.mayorShip.passed")); getDatasource().updateResidentToTownLink(res, town, town.ranksContainer.getDefaultRank()); res.sendMessage(getLocal().getLocalization("mytown.notification.town.mayorShip.taken")); } else { // ... } return CommandResponse.DONE; }
@Command( name = "promote", permission = "mytown.cmd.assistant.promote", parentName = "mytown.cmd", syntax = "/town promote <resident> <rank>", completionKeys = {"residentCompletion", "rankCompletion"}) public static CommandResponse promoteCommand(ICommandSender sender, List<String> args) { if (args.size() < 2) return CommandResponse.SEND_SYNTAX; Resident resSender = MyTownUniverse.instance.getOrMakeResident(sender); Resident resTarget = getResidentFromName(args.get(0)); Town town = getTownFromResident(resSender); if (!resTarget.townsContainer.contains(town)) throw new MyTownCommandException( "mytown.cmd.err.resident.notsametown", args.get(0), town.getName()); Rank mayorRank = town.ranksContainer.getMayorRank(); if (args.get(1).equalsIgnoreCase(mayorRank.getName())) throw new MyTownCommandException("mytown.cmd.err.promote.notMayor"); Rank rank = getRankFromTown(town, args.get(1)); if (getDatasource().updateResidentToTownLink(resTarget, town, rank)) { resSender.sendMessage( getLocal() .getLocalization( "mytown.cmd.promote.success.sender", resTarget.getPlayerName(), rank.getName())); resTarget.sendMessage( getLocal() .getLocalization( "mytown.cmd.promote.success.target", rank.getName(), town.getName())); } return CommandResponse.DONE; }
/** Populates the tab completion map. */ public static void populateCompletionMap() { List<String> populator = new ArrayList<String>(); for (Town town : getUniverse().towns) { populator.add(town.getName()); } CommandCompletion.addCompletions("townCompletionAndAll", populator); CommandCompletion.addCompletion("townCompletionAndAll", "@a"); CommandCompletion.addCompletions("townCompletion", populator); populator = new ArrayList<String>(); for (Resident res : getUniverse().residents) { populator.add(res.getPlayerName()); } CommandCompletion.addCompletions("residentCompletion", populator); populator = new ArrayList<String>(); for (FlagType flag : FlagType.values()) { populator.add(flag.name.toLowerCase()); } CommandCompletion.addCompletions("flagCompletion", populator); populator = new ArrayList<String>(); for (FlagType flag : FlagType.values()) { if (flag.isWhitelistable) populator.add(flag.name.toLowerCase()); } CommandCompletion.addCompletions("flagCompletionWhitelist", populator); populator = new ArrayList<String>(); for (Plot plot : MyTownUniverse.instance.plots) { populator.add(plot.toString()); } CommandCompletion.addCompletions("plotCompletion", populator); populator = new ArrayList<String>(); for (Rank rank : Rank.defaultRanks) { populator.add(rank.getName()); } CommandCompletion.addCompletions("rankCompletion", populator); }
/** Checking item usage for left or right click on block */ public boolean checkItem(ItemStack item, ItemType type, Resident res, BlockPos bp, int face) { for (Iterator<SegmentItem> it = segmentsItems.iterator(); it.hasNext(); ) { SegmentItem segment = it.next(); if (segment.getType() == type && segment.getCheckClass().isAssignableFrom(item.getItem().getClass())) { ForgeDirection direction = ForgeDirection.getOrientation(face); if (segment.isOnAdjacent()) { bp = new BlockPos( bp.getX() + direction.offsetX, bp.getY() + direction.offsetY, bp.getZ() + direction.offsetZ, bp.getDim()); } if (!segment.isDirectionalClientUpdate()) { direction = null; } try { if (segment.checkCondition(item)) { int range = segment.getRange(item); int dim = bp.getDim(); int x = bp.getX(); int y = bp.getY(); int z = bp.getZ(); boolean isProtected; if (range == 0) { isProtected = !hasPermission(res, segment, dim, x, y, z); } else { Volume rangeBox = new Volume(x - range, y - range, z - range, x + range, y + range, z + range); isProtected = !hasPermission(res, segment, dim, rangeBox); } if (isProtected) { if (segment.hasClientUpdate()) { sendClientUpdate( segment.getClientUpdateCoords(), bp, (EntityPlayerMP) res.getPlayer(), direction); } return true; } } } catch (Exception ex) { MyTown.instance.LOG.error( "Failed to check item use on {} at the player {} ({})", item.getDisplayName(), res.getPlayerName(), bp); MyTown.instance.LOG.error(ExceptionUtils.getStackTrace(ex)); if (ex instanceof GetterException || ex instanceof ConditionException) { this.disableSegment(it, segment, ex.getMessage()); } } } } return false; }