Package com.palmergames.bukkit.towny.object

Examples of com.palmergames.bukkit.towny.object.Town


      BufferedReader fin = new BufferedReader(new FileReader(rootFolder + dataFolder + "/townblocks.csv"));
      while ( (line = fin.readLine()) != null) {
        tokens = line.split(",");
        if (tokens.length >= 4)
          try {
            Town town = getTown(tokens[2]);
         
         
            int x = Integer.parseInt(tokens[0]);
            int z = Integer.parseInt(tokens[1]);
View Full Code Here


        line = kvFile.get("towns");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            Town town = getTown(token);
            if (town != null)
              nation.addTown(town);
          }
        }
View Full Code Here

    return new ArrayList<Town>(universe.getTownsMap().values());
  }
 
  @Override
  public Town getTown(String name) throws NotRegisteredException {
    Town town = universe.getTownsMap().get(name.toLowerCase());
    if (town == null)
      throw new NotRegisteredException(String.format("The town '%s' is not registered.", name));
    return town;
  }
View Full Code Here

  }
 
  @Override
  public void removeResident(Resident resident) {

    Town town = null;

    if (resident.hasTown())
      try {
        town = resident.getTown();
      } catch (NotRegisteredException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }

    try {
      if (town != null) {
        town.removeResident(resident);
        saveTown(town);
      }
      resident.clear();
    } catch (EmptyTownException e) {
      removeTown(town);
View Full Code Here

  }

  @Override
  public void removeTownBlock(TownBlock townBlock) {
    Resident resident = null;
    Town town = null;
    try {
      resident = townBlock.getResident();
    } catch (NotRegisteredException e) {
    }
    try {
View Full Code Here

    }

    if (universe.getTownsMap().containsKey(filteredName.toLowerCase()))
      throw new AlreadyRegisteredException("The town " + filteredName + " is already in use.");

    universe.getTownsMap().put(filteredName.toLowerCase(), new Town(filteredName));

    universe.setChangedNotify(NEW_TOWN);
  }
View Full Code Here

      Nation nation = town.getNation();
      nation.setCapital(town);
      saveNation(nation);
    }

    Town oldTown = new Town(oldName);

    try {
      town.pay(town.getHoldingBalance(), "Rename Town - Empty account of new town name.");
      oldTown.payTo(oldTown.getHoldingBalance(), town, "Rename Town - Transfer to new account");
    } catch (EconomyException e) {
    }

    for (Resident resident : toSave) {
      saveResident(resident);
View Full Code Here

    String nationCom = "/nation";

    if (split.length == 0)
      try {
        Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
        Town town = resident.getTown();
        Nation nation = town.getNation();
        TownyMessaging.sendMessage(player, TownyFormatter.getStatus(nation));
      } catch (NotRegisteredException x) {
        TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_dont_belong_nation"));
      }
    else if (split[0].equalsIgnoreCase("?"))
      for (String line : nation_help)
        player.sendMessage(line);
    else if (split[0].equalsIgnoreCase("list"))
      listNations(player);
    else if (split[0].equalsIgnoreCase("new")) {
      // TODO: Make an overloaded function
      // newNation(Player,String,Town)
      if (split.length == 1)
        TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_specify_nation_name"));
      else if (split.length == 2)
        try { // TODO: Make sure of the error catching
          Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
          if (!resident.isMayor() && !resident.getTown().hasAssistant(resident))
            throw new TownyException(TownySettings.getLangString("msg_peasant_right"));
          newNation(player, split[1], resident.getTown().getName());
        } catch (TownyException x) {
          TownyMessaging.sendErrorMsg(player, x.getMessage());
        }
      else
        // TODO: Check if player is an admin
        newNation(player, split[1], split[2]);
    } else if (split[0].equalsIgnoreCase("leave"))
      nationLeave(player);
    else if (split[0].equalsIgnoreCase("withdraw")) {
      if (split.length == 2)
        try {
          nationWithdraw(player, Integer.parseInt(split[1].trim()));
        } catch (NumberFormatException e) {
          TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_int"));
        }
      else
        TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_must_specify_amnt"), nationCom));
    } else if (split[0].equalsIgnoreCase("deposit")) {
      if (split.length == 2)
        try {
          nationDeposit(player, Integer.parseInt(split[1].trim()));
        } catch (NumberFormatException e) {
          TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_int"));
        }
      else
        TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_must_specify_amnt"), nationCom + " deposit"));
    } else {
      String[] newSplit = StringMgmt.remFirstArg(split);

      if (split[0].equalsIgnoreCase("king"))
        nationKing(player, newSplit);
      else if (split[0].equalsIgnoreCase("add"))
        nationAdd(player, newSplit);
      else if (split[0].equalsIgnoreCase("kick"))
        nationKick(player, newSplit);
      else if (split[0].equalsIgnoreCase("assistant"))
        nationAssistant(player, newSplit);
      else if (split[0].equalsIgnoreCase("set"))
        nationSet(player, newSplit);
      else if (split[0].equalsIgnoreCase("toggle"))
        nationToggle(player, newSplit);
      else if (split[0].equalsIgnoreCase("ally"))
        nationAlly(player, newSplit);
      else if (split[0].equalsIgnoreCase("enemy"))
        nationEnemy(player, newSplit);
      else if (split[0].equalsIgnoreCase("delete"))
        nationDelete(player, newSplit);
      else if (split[0].equalsIgnoreCase("online")) {
        try {
          Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
          Town town = resident.getTown();
          Nation nation = town.getNation();
          TownyMessaging.sendMessage(player, TownyFormatter.getFormattedOnlineResidents(plugin, TownySettings.getLangString("msg_nation_online"), nation));
        } catch (NotRegisteredException x) {
          TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_dont_belong_nation"));
        }
      } else
View Full Code Here

    try {
      if (!TownyUniverse.getPermissionSource().isTownyAdmin(player) && ((TownySettings.isNationCreationAdminOnly() && !plugin.isPermissions())
        || (plugin.isPermissions() && !TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_NATION_NEW.getNode()))))
        throw new TownyException(TownySettings.getNotPermToNewNationLine());

      Town town = TownyUniverse.getDataSource().getTown(capitalName);
      if (town.hasNation())
        throw new TownyException(TownySettings.getLangString("msg_err_already_nation"));

      if (!TownySettings.isValidRegionName(name))
        throw new TownyException(String.format(TownySettings.getLangString("msg_err_invalid_name"), name));

      if (TownySettings.isUsingEconomy() && !town.pay(TownySettings.getNewNationPrice(), "New Nation Cost"))
        throw new TownyException(TownySettings.getLangString("msg_no_funds_new_nation"));

      newNation(universe, name, town);
      /*universe.newNation(name);
      Nation nation = universe.getNation(name);
View Full Code Here

  }

  public void nationLeave(Player player) {
    try {
      Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
      Town town = resident.getTown();
      Nation nation = town.getNation();
      if (!resident.isMayor())
        if (!town.hasAssistant(resident))
          throw new TownyException(TownySettings.getLangString("msg_not_mayor_ass"));

      nation.removeTown(town);

      TownyUniverse.getDataSource().saveTown(town);
      TownyUniverse.getDataSource().saveNation(nation);
      TownyUniverse.getDataSource().saveNationList();

      TownyMessaging.sendNationMessage(nation, ChatTools.color(String.format(TownySettings.getLangString("msg_nation_town_left"), town.getName())));
      TownyMessaging.sendTownMessage(town, ChatTools.color(String.format(TownySettings.getLangString("msg_town_left_nation"), nation.getName())));
    } catch (TownyException x) {
      TownyMessaging.sendErrorMsg(player, x.getMessage());
      return;
    } catch (EmptyNationException en) {
View Full Code Here

TOP

Related Classes of com.palmergames.bukkit.towny.object.Town

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.