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()); } }
public void remove(Town town) { for (TownBlock townBlock : town.getTownBlocks()) remove(townBlock.getWorldCoord()); warringTowns.remove(town); try { if (!townsLeft(town.getNation())) eliminate(town.getNation()); } catch (NotRegisteredException e) { } }
public void add(Town town) { TownyMessaging.sendTownMessage(town, TownySettings.getJoinWarMsg(town)); townScores.put(town, 0); warringTowns.add(town); for (TownBlock townBlock : town.getTownBlocks()) if (town.isHomeBlock(townBlock)) warZone.put(townBlock.getWorldCoord(), TownySettings.getWarzoneHomeBlockHealth()); else warZone.put(townBlock.getWorldCoord(), TownySettings.getWarzoneTownBlockHealth()); }
public boolean loadTowns() { sendDebugMsg("Loading Towns"); for (Town town : universe.getTowns()) if (!loadTown(town)) { System.out.println( "[Towny] Loading Error: Could not read town data " + town.getName() + "'."); return false; } return true; }
public void remove(Town attacker, Town town) throws NotRegisteredException { townScored(attacker, TownySettings.getWarPointsForTown()); for (TownBlock townBlock : town.getTownBlocks()) remove(townBlock.getWorldCoord()); warringTowns.remove(town); try { if (!townsLeft(town.getNation())) eliminate(town.getNation()); } catch (NotRegisteredException e) { } }
public void eliminate(Town town) { remove(town); try { checkNation(town.getNation()); } catch (NotRegisteredException e) { TownyMessaging.sendErrorMsg("[War] Error checking " + town.getName() + "'s nation."); } TownyMessaging.sendGlobalMessage(TownySettings.getWarTimeEliminatedMsg(town.getName())); checkEnd(); }
/** * Is town b an enemy of town a? * * @param a * @param b * @return true if b is an enemy. */ public static 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 remove(WorldCoord worldCoord) { try { Town town = worldCoord.getTownBlock().getTown(); TownyMessaging.sendGlobalMessage( TownySettings.getWarTimeLoseTownBlockMsg(worldCoord, town.getName())); warZone.remove(worldCoord); } catch (NotRegisteredException e) { TownyMessaging.sendGlobalMessage(TownySettings.getWarTimeLoseTownBlockMsg(worldCoord)); warZone.remove(worldCoord); } }
/** * Get a TownyAccountHolder for the nation of which player is a resident, if any. * * @param player * @return TownyAccountHolder for the nation of which player is a resident, if any. null * otherwise. */ public TownyAccountHolder getNationAccountHolder(Player player) { try { Resident resident = TownyUniverse.getDataSource().getResident(player.getName()); Town town = resident.getTown(); Nation nation = town.getNation(); return new TownyAccountHolder(nation); } catch (NotRegisteredException e) { } return null; }
public void remove(Town attacker, TownBlock townBlock) throws NotRegisteredException { townScored(attacker, TownySettings.getWarPointsForTownBlock()); townBlock.getTown().addBonusBlocks(-1); attacker.addBonusBlocks(1); try { if (!townBlock .getTown() .payTo(TownySettings.getWartimeTownBlockLossPrice(), attacker, "War - TownBlock Loss")) { remove(townBlock.getTown()); TownyMessaging.sendTownMessage( townBlock.getTown(), "Your town ran out of funds to support yourself in war."); } else TownyMessaging.sendTownMessage( townBlock.getTown(), "Your town lost " + TownySettings.getWartimeTownBlockLossPrice() + " " + TownyEconomyObject.getEconomyCurrency() + "."); } catch (EconomyException e) { } if (townBlock.getTown().isHomeBlock(townBlock)) remove(townBlock.getTown()); else remove(townBlock.getWorldCoord()); TownyUniverse.getDataSource().saveTown(townBlock.getTown()); TownyUniverse.getDataSource().saveTown(attacker); }
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; } }
public void parseAdminTownCommand(String[] split) throws TownyException { // TODO Make this use the actual town command procedually. if (split.length == 0 || split[0].equalsIgnoreCase("?")) { sender.sendMessage(ChatTools.formatTitle("/townyadmin town")); sender.sendMessage( ChatTools.formatCommand( TownySettings.getLangString("admin_sing"), "/townyadmin town", "[town]", "")); sender.sendMessage( ChatTools.formatCommand( TownySettings.getLangString("admin_sing"), "/townyadmin town", "[town] add/kick [] .. []", "")); sender.sendMessage( ChatTools.formatCommand( TownySettings.getLangString("admin_sing"), "/townyadmin town", "[town] rename [newname]", "")); sender.sendMessage( ChatTools.formatCommand( TownySettings.getLangString("admin_sing"), "/townyadmin town", "[town] delete", "")); sender.sendMessage( ChatTools.formatCommand( TownySettings.getLangString("admin_sing"), "/townyadmin town", "[town] spawn", "")); sender.sendMessage( ChatTools.formatCommand( TownySettings.getLangString("admin_sing"), "/townyadmin town", "[town] outpost #", "")); return; } try { Town town = TownyUniverse.getDataSource().getTown(split[0]); if (split.length == 1) { TownyMessaging.sendMessage(getSender(), TownyFormatter.getStatus(town)); return; } if (!TownyUniverse.getPermissionSource() .testPermission( player, PermissionNodes.TOWNY_COMMAND_TOWNYADMIN_TOWN.getNode(split[1].toLowerCase()))) throw new TownyException(TownySettings.getLangString("msg_err_command_disable")); if (split[1].equalsIgnoreCase("add")) { /* * if (isConsole) { sender.sendMessage( * "[Towny] InputError: This command was designed for use in game only." * ); return; } */ TownCommand.townAdd(getSender(), town, StringMgmt.remArgs(split, 2)); } else if (split[1].equalsIgnoreCase("kick")) { TownCommand.townKickResidents( getSender(), town.getMayor(), town, TownyUniverse.getValidatedResidents(getSender(), StringMgmt.remArgs(split, 2))); } else if (split[1].equalsIgnoreCase("delete")) { TownyUniverse.getDataSource().removeTown(town); } else if (split[1].equalsIgnoreCase("rename")) { if (!NameValidation.isBlacklistName(split[2])) { TownyUniverse.getDataSource().renameTown(town, split[2]); TownyMessaging.sendTownMessage( town, String.format( TownySettings.getLangString("msg_town_set_name"), ((getSender() instanceof Player) ? player.getName() : "CONSOLE"), town.getName())); } else TownyMessaging.sendErrorMsg(getSender(), TownySettings.getLangString("msg_invalid_name")); } else if (split[1].equalsIgnoreCase("spawn")) { TownCommand.townSpawn(player, StringMgmt.remArgs(split, 2), town, "", false); } else if (split[1].equalsIgnoreCase("outpost")) { TownCommand.townSpawn(player, StringMgmt.remArgs(split, 2), town, "", true); } } catch (NotRegisteredException e) { TownyMessaging.sendErrorMsg(getSender(), e.getMessage()); } catch (TownyException e) { TownyMessaging.sendErrorMsg(getSender(), e.getMessage()); } }
public int countActiveWarBlocks(Town town) { int n = 0; for (TownBlock townBlock : town.getTownBlocks()) if (warZone.containsKey(townBlock.getWorldCoord())) n++; return n; }
public void townLeave(Town town) { remove(town); TownyMessaging.sendGlobalMessage(TownySettings.getWarTimeForfeitMsg(town.getName())); checkEnd(); }