@Command( name = "add", permission = "mytown.cmd.assistant.ranks.add", parentName = "mytown.cmd.everyone.ranks", syntax = "/town ranks add <name> [templateRank]", completionKeys = {"-", "ranksCompletion"}) public static CommandResponse ranksAddCommand(ICommandSender sender, List<String> args) { if (args.size() < 1) return CommandResponse.SEND_SYNTAX; Resident res = MyTownUniverse.instance.getOrMakeResident(sender); Town town = getTownFromResident(res); if (town.ranksContainer.contains(args.get(0))) throw new MyTownCommandException("mytown.cmd.err.ranks.add.already", args.get(0)); Rank rank = new Rank(args.get(0), town, Rank.Type.REGULAR); if (args.size() == 2) { Rank template = getRankFromTown(town, args.get(1)); rank.permissionsContainer.addAll(template.permissionsContainer); } getDatasource().saveRank(rank); res.sendMessage( getLocal() .getLocalization("mytown.notification.town.ranks.add", args.get(0), town.getName())); return CommandResponse.DONE; }
@Command( name = "remove", permission = "mytown.cmd.assistant.ranks.remove", parentName = "mytown.cmd.everyone.ranks", syntax = "/town ranks remove <rank>", completionKeys = {"rankCompletion"}) public static CommandResponse ranksRemoveCommand(ICommandSender sender, List<String> args) { if (args.size() < 1) return CommandResponse.SEND_SYNTAX; Resident res = MyTownUniverse.instance.getOrMakeResident(sender); Town town = getTownFromResident(res); Rank rank = getRankFromTown(town, args.get(0)); if (rank.getType().unique) { throw new MyTownCommandException("mytown.cmd.err.ranks.cantDelete"); } for (Rank residentRank : town.residentsMap.values()) { if (residentRank == rank) { throw new MyTownCommandException("mytown.cmd.err.ranks.assigned"); } } getDatasource().deleteRank(rank); res.sendMessage( getLocal() .getLocalization("mytown.notification.town.ranks.rem", args.get(0), 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; }
@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 = "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 = "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; }
@Override public List<String> getTreeString(int depth) { List<String> out = new ArrayList<String>(); out.add(getTreeDepth(depth) + "Universe (" + getName() + ")"); if (plugin != null) { out.add(getTreeDepth(depth + 1) + "Server (" + plugin.getServer().getName() + ")"); out.add(getTreeDepth(depth + 2) + "Version: " + plugin.getServer().getVersion()); out.add( getTreeDepth(depth + 2) + "Players: " + plugin.getServer().getOnlinePlayers().length + "/" + plugin.getServer().getMaxPlayers()); out.add( getTreeDepth(depth + 2) + "Worlds (" + plugin.getServer().getWorlds().size() + "): " + Arrays.toString(plugin.getServer().getWorlds().toArray(new World[0]))); } out.add(getTreeDepth(depth + 1) + "Worlds (" + getDataSource().getWorlds().size() + "):"); for (TownyWorld world : getDataSource().getWorlds()) out.addAll(world.getTreeString(depth + 2)); out.add(getTreeDepth(depth + 1) + "Nations (" + getDataSource().getNations().size() + "):"); for (Nation nation : getDataSource().getNations()) out.addAll(nation.getTreeString(depth + 2)); Collection<Town> townsWithoutNation = getDataSource().getTownsWithoutNation(); out.add(getTreeDepth(depth + 1) + "Towns (" + townsWithoutNation.size() + "):"); for (Town town : townsWithoutNation) out.addAll(town.getTreeString(depth + 2)); Collection<Resident> residentsWithoutTown = getDataSource().getResidentsWithoutTown(); out.add(getTreeDepth(depth + 1) + "Residents (" + residentsWithoutTown.size() + "):"); for (Resident resident : residentsWithoutTown) out.addAll(resident.getTreeString(depth + 2)); return out; }
private void giveBonus(String[] split) throws TownyException { Town town; try { if (split.length != 2) throw new TownyException( String.format( TownySettings.getLangString("msg_err_invalid_input"), "Eg: givebonus [town/player] [n]")); try { town = TownyUniverse.getDataSource().getTown(split[0]); } catch (NotRegisteredException e) { town = TownyUniverse.getDataSource().getResident(split[0]).getTown(); } try { town.setBonusBlocks(town.getBonusBlocks() + Integer.parseInt(split[1].trim())); TownyMessaging.sendMsg( getSender(), String.format( TownySettings.getLangString("msg_give_total"), town.getName(), split[1], town.getBonusBlocks())); } catch (NumberFormatException nfe) { throw new TownyException(TownySettings.getLangString("msg_error_must_be_int")); } TownyUniverse.getDataSource().saveTown(town); } catch (TownyException e) { throw new TownyException(e.getMessage()); } }
@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; }
public static <T> T getFlagValueAtLocation(FlagType<T> flagType, int dim, int x, int y, int z) { if (MyTownUniverse.instance.blocks.contains(dim, x >> 4, z >> 4)) { Town town = MyTownUniverse.instance.blocks.get(dim, x >> 4, z >> 4).getTown(); return town.getValueAtCoords(dim, x, y, z, flagType); } else { return flagType.isWildPerm ? Wild.instance.flagsContainer.get(flagType).value : null; } }
public static boolean hasPermission( Resident res, FlagType<Boolean> flagType, int dim, int x, int y, int z) { if (MyTownUniverse.instance.blocks.contains(dim, x >> 4, z >> 4)) { Town town = MyTownUniverse.instance.blocks.get(dim, x >> 4, z >> 4).getTown(); return town.hasPermission(res, flagType, dim, x, y, z); } else { return !flagType.isWildPerm || Wild.instance.hasPermission(res, flagType); } }
public Location getTownSpawnLocation(Player player) throws TownyException { try { Resident resident = getDataSource().getResident(player.getName()); Town town = resident.getTown(); return town.getSpawn(); } catch (TownyException x) { throw new TownyException("Unable to get spawn location"); } }
public boolean isEnemy(Town a, Town b) { try { if (a == b) return false; if (a.getNation() == b.getNation()) return false; if (a.getNation().hasEnemy(b.getNation())) return true; } catch (NotRegisteredException e) { return false; } return false; }
public void onLogin(Player player) throws AlreadyRegisteredException, NotRegisteredException { if (!player.isOnline()) return; // Test and kick any players with invalid names. if ((player.getName().trim() == null) || (player.getName().contains(" "))) { player.kickPlayer("Invalid name!"); return; } Resident resident; if (!getDataSource().hasResident(player.getName())) { getDataSource().newResident(player.getName()); resident = getDataSource().getResident(player.getName()); TownyMessaging.sendMessage(player, TownySettings.getRegistrationMsg(player.getName())); resident.setRegistered(System.currentTimeMillis()); if (!TownySettings.getDefaultTownName().equals("")) try { Town town = getDataSource().getTown(TownySettings.getDefaultTownName()); town.addResident(resident); getDataSource().saveTown(town); } catch (NotRegisteredException e) { } catch (AlreadyRegisteredException e) { } getDataSource().saveResident(resident); getDataSource().saveResidentList(); } else { resident = getDataSource().getResident(player.getName()); resident.setLastOnline(System.currentTimeMillis()); getDataSource().saveResident(resident); } try { TownyMessaging.sendTownBoard(player, resident.getTown()); } catch (NotRegisteredException e) { } if (isWarTime()) getWarEvent().sendScores(player, 3); // Schedule to setup default modes when the player has finished loading if (getPlugin() .getServer() .getScheduler() .scheduleSyncDelayedTask(getPlugin(), new SetDefaultModes(this, player, false), 1) == -1) TownyMessaging.sendErrorMsg("Could not set default modes for " + player.getName() + "."); setChangedNotify(PLAYER_LOGIN); }
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 void addTown(Town town) throws AlreadyRegisteredException { if (hasTown(town)) throw new AlreadyRegisteredException(); else { towns.add(town); town.setWorld(this); } }
public static Rank getRankFromTown(Town town, String rankName) { Rank rank = town.ranksContainer.get(rankName); if (rank == null) { throw new MyTownCommandException("mytown.cmd.err.rank.notexist", rankName, town.getName()); } return rank; }
public static ArrayList<String> getMissionLogs(Town town) { Connection context = null; ResultSet rs = null; PreparedStatement ps = null; try { ArrayList<String> out = new ArrayList<String>(); try { context = SQL.getGameConnection(); ps = context.prepareStatement( "SELECT * FROM " + SQL.tb_prefix + TABLE_NAME + " WHERE `town_id` = ?"); ps.setInt(1, town.getId()); rs = ps.executeQuery(); SimpleDateFormat sdf = new SimpleDateFormat("M/dd h:mm:ss a z"); while (rs.next()) { Date date = new Date(rs.getLong("time")); Town target = CivGlobal.getTownFromId(rs.getInt("target_id")); if (target == null) { continue; } String playerName = rs.getString("playerName"); playerName = CivGlobal.getResidentViaUUID(UUID.fromString(playerName)).getName(); String str = sdf.format(date) + " - " + rs.getString("playerName") + ":" + target.getName() + ":" + rs.getString("missionName") + " -- " + rs.getString("result"); out.add(str); } } catch (SQLException e) { e.printStackTrace(); } return out; } finally { SQL.close(rs, ps, context); } }
public static void saveDocks(ArrayList<Town> towns, String directory) { PrintWriter writer = getPrintWriter(directory, "DocksSave.txt"); if (writer != null) { for (Town town : towns) { writer.print("townID:"); writer.print(town.getId()); writer.print(","); for (DocksUnit docksUnit : town.getDocks().getDocksUnits()) { writer.print(docksUnit.getUnitType().name()); writer.print(":"); writer.print(docksUnit.getBuildTo()); writer.print(","); } writer.println(); } writer.close(); } }
public static void logMission( Town town, Town target, Resident resident, String missionName, String result) { HashMap<String, Object> hashmap = new HashMap<String, Object>(); hashmap.put("town_id", town.getId()); hashmap.put("target_id", target.getId()); hashmap.put("time", new Date()); hashmap.put("playerName", resident.getUUIDString()); hashmap.put("missionName", missionName); hashmap.put("result", result); try { SQL.insertNow(hashmap, TABLE_NAME); } catch (SQLException e) { e.printStackTrace(); } }
public void removeTown(Town town) throws NotRegisteredException { if (!hasTown(town)) throw new NotRegisteredException(); else { towns.remove(town); try { town.setWorld(null); } catch (AlreadyRegisteredException e) { } } }
@Command( name = "rename", permission = "mytown.cmd.assistant.rename", parentName = "mytown.cmd", syntax = "/town rename <name>") public static CommandResponse renameCommand(ICommandSender sender, List<String> args) { if (args.size() < 1) return CommandResponse.SEND_SYNTAX; Resident res = MyTownUniverse.instance.getOrMakeResident(sender); Town town = getTownFromResident(res); if (getUniverse().towns.contains(args.get(0))) // Is the town name already in use? throw new MyTownCommandException("mytown.cmd.err.newtown.nameinuse", args.get(0)); town.rename(args.get(0)); getDatasource().saveTown(town); res.sendMessage(getLocal().getLocalization("mytown.notification.town.renamed")); 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); }
public void setTown(Town town) { try { if (hasTown()) this.town.removeTownBlock(this); } catch (NotRegisteredException e) { } this.town = town; try { town.addTownBlock(this); } catch (AlreadyRegisteredException e) { } catch (NullPointerException e) { } }
@Command( name = "invite", permission = "mytown.cmd.assistant.invite", parentName = "mytown.cmd", syntax = "/town invite <resident>", completionKeys = {"residentCompletion"}) public static CommandResponse inviteCommand(ICommandSender sender, List<String> args) { Resident res = MyTownUniverse.instance.getOrMakeResident(sender); Town town = getTownFromResident(res); if (args.size() < 1) return CommandResponse.SEND_SYNTAX; Resident target = getResidentFromName(args.get(0)); if (town.residentsMap.contains(args.get(0))) throw new MyTownCommandException( "mytown.cmd.err.invite.already", args.get(0), town.getName()); getDatasource().saveTownInvite(target, town); target.sendMessage( getLocal().getLocalization("mytown.notification.town.invited", town.getName())); res.sendMessage( getLocal().getLocalization("mytown.notification.town.invite.sent", args.get(0))); return CommandResponse.DONE; }
public static void saveFarmers(ArrayList<Town> towns, String directory) { PrintWriter writer = getPrintWriter(directory, "FarmersSave.txt"); if (writer != null) { if (towns.size() > 0) { writer.println("All Farmers enabled:" + Farming.isAllEnabled()); writer.println("All MoodToLoot:" + Farming.getAllMoodToLootTo()); writer.println("All Interval:" + Farming.getAllIntervalToFarm()); if (!Farming.isAllEnabled()) { for (Town town : towns) { writer.print("townID:" + town.getId()); writer.print(","); writer.print("enabled:" + town.getFarming().isEnabled()); writer.print(","); writer.print("MoodToLoot:" + town.getFarming().getMoodToLootTo()); writer.print(","); writer.print("Interval:" + town.getFarming().getIntervalToFarm()); writer.println(); } } } writer.close(); } }
@Command( name = "list", permission = "mytown.cmd.assistant.ranks.perm.list", parentName = "mytown.cmd.assistant.ranks.perm", syntax = "/town ranks perm list [rank]") public static CommandResponse ranksPermListCommand(ICommandSender sender, List<String> args) { Rank rank; Resident res = MyTownUniverse.instance.getOrMakeResident(sender); Town town = getTownFromResident(res); if (args.isEmpty()) { rank = getRankFromResident(res); } else { rank = getRankFromTown(town, args.get(0)); } res.sendMessage( getLocal() .getLocalization( "mytown.notification.town.ranks.perm.list", rank.getName(), town.getName(), rank.permissionsContainer.toString())); return CommandResponse.DONE; }
@Command( name = "setspawn", permission = "mytown.cmd.assistant.setspawn", parentName = "mytown.cmd", syntax = "/town setspawn") public static CommandResponse setSpawnCommand(ICommandSender sender, List<String> args) { EntityPlayer player = (EntityPlayer) sender; Resident res = MyTownUniverse.instance.getOrMakeResident(player); Town town = getTownFromResident(res); if (!town.isPointInTown(player.dimension, (int) player.posX, (int) player.posZ)) throw new MyTownCommandException( getLocal().getLocalization("mytown.cmd.err.setspawn.notintown", town.getName())); makePayment(player, Config.instance.costAmountSetSpawn.get()); town.getSpawn() .setDim(player.dimension) .setPosition((float) player.posX, (float) player.posY, (float) player.posZ) .setRotation(player.cameraYaw, player.cameraPitch); getDatasource().saveTown(town); res.sendMessage(getLocal().getLocalization("mytown.notification.town.setspawn")); return CommandResponse.DONE; }
public void adminSet(String[] split) throws TownyException { if (split.length == 0) { sender.sendMessage(ChatTools.formatTitle("/townyadmin set")); // TODO: player.sendMessage(ChatTools.formatCommand("", // "/townyadmin set", "king [nation] [king]", "")); sender.sendMessage( ChatTools.formatCommand( "", "/townyadmin set", "mayor [town] " + TownySettings.getLangString("town_help_2"), "")); sender.sendMessage(ChatTools.formatCommand("", "/townyadmin set", "mayor [town] npc", "")); // player.sendMessage(ChatTools.formatCommand("", "/townyadmin set", // "debugmode [on/off]", "")); // player.sendMessage(ChatTools.formatCommand("", "/townyadmin set", // "devmode [on/off]", "")); return; } if (!TownyUniverse.getPermissionSource() .testPermission( player, PermissionNodes.TOWNY_COMMAND_TOWNYADMIN_SET.getNode(split[0].toLowerCase()))) throw new TownyException(TownySettings.getLangString("msg_err_command_disable")); if (split[0].equalsIgnoreCase("mayor")) { if (split.length < 3) { sender.sendMessage(ChatTools.formatTitle("/townyadmin set mayor")); sender.sendMessage( ChatTools.formatCommand( "Eg", "/townyadmin set mayor", "[town] " + TownySettings.getLangString("town_help_2"), "")); sender.sendMessage( ChatTools.formatCommand("Eg", "/townyadmin set mayor", "[town] npc", "")); } else try { Resident newMayor = null; Town town = TownyUniverse.getDataSource().getTown(split[1]); if (split[2].equalsIgnoreCase("npc")) { String name = nextNpcName(); TownyUniverse.getDataSource().newResident(name); newMayor = TownyUniverse.getDataSource().getResident(name); newMayor.setRegistered(System.currentTimeMillis()); newMayor.setLastOnline(0); newMayor.setNPC(true); TownyUniverse.getDataSource().saveResident(newMayor); TownyUniverse.getDataSource().saveResidentList(); // set for no upkeep as an NPC mayor is assigned town.setHasUpkeep(false); } else { newMayor = TownyUniverse.getDataSource().getResident(split[2]); // set upkeep again town.setHasUpkeep(true); } if (!town.hasResident(newMayor)) TownCommand.townAddResident(town, newMayor); // Delete the resident if the old mayor was an NPC. Resident oldMayor = town.getMayor(); town.setMayor(newMayor); if (oldMayor.isNPC()) { try { town.removeResident(oldMayor); TownyUniverse.getDataSource().removeResident(oldMayor); TownyUniverse.getDataSource().removeResidentList(oldMayor); } catch (EmptyTownException e) { // Should never reach here as we are setting a new // mayor before removing the old one. e.printStackTrace(); } } TownyUniverse.getDataSource().saveTown(town); String[] msg = TownySettings.getNewMayorMsg(newMayor.getName()); TownyMessaging.sendTownMessage(town, msg); // TownyMessaging.sendMessage(player, msg); } catch (TownyException e) { TownyMessaging.sendErrorMsg(getSender(), e.getMessage()); } } else if (split[0].equalsIgnoreCase("capital")) { if (split.length < 2) { sender.sendMessage(ChatTools.formatTitle("/townyadmin set capital")); sender.sendMessage(ChatTools.formatCommand("Eg", "/ta set capital", "[town name]", "")); } else { try { Town newCapital = TownyUniverse.getDataSource().getTown(split[1]); Nation nation = newCapital.getNation(); nation.setCapital(newCapital); plugin.resetCache(); TownyMessaging.sendNationMessage( nation, TownySettings.getNewKingMsg(newCapital.getMayor().getName(), nation.getName())); TownyUniverse.getDataSource().saveNation(nation); TownyUniverse.getDataSource().saveNationList(); } catch (TownyException e) { TownyMessaging.sendErrorMsg(player, e.getMessage()); } } } else { TownyMessaging.sendErrorMsg( getSender(), String.format(TownySettings.getLangString("msg_err_invalid_property"), "administrative")); return; } }