Package com.palmergames.bukkit.towny.object

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


        line = kvFile.get("friends");
        if (line != null) {
          String[] tokens = line.split(",");
          for (String token : tokens) {
            if (!token.isEmpty()){
              Resident friend = getResident(token);
              if (friend != null)
                resident.addFriend(friend);
            }
          }
        }
View Full Code Here


        line = kvFile.get("residents");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            if (!token.isEmpty()){
              Resident resident = getResident(token);
              if (resident != null)
                town.addResident(resident);
            }
          }
        }

        line = kvFile.get("mayor");
        if (line != null)
          town.setMayor(getResident(line));

        line = kvFile.get("assistants");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            if (!token.isEmpty()){
              Resident assistant = getResident(token);
              if ((assistant != null) && (town.hasResident(assistant)))
                town.addAssistant(assistant);
            }
          }
        }
View Full Code Here

        line = kvFile.get("assistants");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            if (!token.isEmpty()){
              Resident assistant = getResident(token);
              if (assistant != null)
                nation.addAssistant(assistant);
            }
          }
        }
View Full Code Here

    int numPlayers = 0;
    for (Player player : TownyUniverse.getOnlinePlayers()) {
      numPlayers += 1;
      TownyMessaging.sendDebugMsg("[War] "+player.getName()+": ");
      try {
        Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
        if (resident.hasNation()) {
          Nation nation = resident.getTown().getNation();
          TownyMessaging.sendDebugMsg("[War]   hasNation");
          if (nation.isNeutral()) {
            if (warEvent.isWarringNation(nation))
              warEvent.nationLeave(nation);
            continue;
          }
          TownyMessaging.sendDebugMsg("[War]   notNeutral");
          if (!warEvent.isWarringNation(nation))
            continue;
          TownyMessaging.sendDebugMsg("[War]   warringNation");
          //TODO: Cache player coord & townblock
         
          WorldCoord worldCoord = new WorldCoord(TownyUniverse.getDataSource().getWorld(player.getWorld().getName()), Coord.parseCoord(player));
          if (!warEvent.isWarZone(worldCoord))
            continue;
          TownyMessaging.sendDebugMsg("[War]   warZone");
          if (player.getLocation().getBlockY() < TownySettings.getMinWarHeight())
            continue;
          TownyMessaging.sendDebugMsg("[War]   aboveMinHeight");
          TownBlock townBlock = worldCoord.getTownBlock(); //universe.getWorld(player.getWorld().getName()).getTownBlock(worldCoord);
          if (nation == townBlock.getTown().getNation() || townBlock.getTown().getNation().hasAlly(nation))
            continue;
          TownyMessaging.sendDebugMsg("[War]   notAlly");
          //Enemy nation
          warEvent.damage(resident.getTown(), townBlock);
          TownyMessaging.sendDebugMsg("[War]   damaged");
        }
      } catch(NotRegisteredException e) {
        continue;
      }
View Full Code Here

    if (split.length == 0 || split[0].equalsIgnoreCase("?")) {
      for (String line : output)
        player.sendMessage(line);
    } else {
      Resident resident;
      TownyWorld world;
      try {
        resident = TownyUniverse.getDataSource().getResident(player.getName());
        world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
      } catch (TownyException x) {
        TownyMessaging.sendErrorMsg(player, x.getMessage());
        return;
      }

      try {
        if (split[0].equalsIgnoreCase("claim")) {

          if (plugin.getTownyUniverse().isWarTime())
            throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));

          List<WorldCoord> selection = TownyUtil.selectWorldCoordArea(resident, new WorldCoord(world, Coord.parseCoord(player)), StringMgmt.remFirstArg(split));
          //selection = TownyUtil.filterUnownedPlots(selection);

          if (selection.size() > 0) {

            double cost = 0;

            // Remove any plots Not for sale (if not the mayor) and tally up costs.
            for (WorldCoord worldCoord : new ArrayList<WorldCoord>(selection)) {
              try {
                double price = worldCoord.getTownBlock().getPlotPrice();
                if (price > -1)
                  cost += worldCoord.getTownBlock().getPlotPrice();
                else {
                  if (!worldCoord.getTownBlock().getTown().isMayor(resident)) // || worldCoord.getTownBlock().getTown().hasAssistant(resident))
                    selection.remove(worldCoord);
                }
              } catch (NotRegisteredException e) {
                selection.remove(worldCoord);
              }
            }
           
            int maxPlots = TownySettings.getMaxResidentPlots(resident);
            if (maxPlots >= 0 && resident.getTownBlocks().size() + selection.size() > maxPlots)
              throw new TownyException(String.format(TownySettings.getLangString("msg_max_plot_own"), maxPlots));

            if (TownySettings.isUsingEconomy() && (!resident.canPayFromHoldings(cost)))
              throw new TownyException(String.format(TownySettings.getLangString("msg_no_funds_claim"), selection.size(), TownyEconomyObject.getFormattedBalance(cost)));

            // Start the claim task
            new PlotClaim(plugin, player, resident, selection, PlotClaim.Action.CLAIM).start();

          } else {
            player.sendMessage(TownySettings.getLangString("msg_err_empty_area_selection"));
          }
        } else if (split[0].equalsIgnoreCase("unclaim")) {

          if (plugin.getTownyUniverse().isWarTime())
            throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));

          if (split.length == 2 && split[1].equalsIgnoreCase("all")) {
            // Start the unclaim task
            new PlotClaim(plugin, player, resident, null, PlotClaim.Action.UNCLAIM).start();

          } else {
            List<WorldCoord> selection = TownyUtil.selectWorldCoordArea(resident, new WorldCoord(world, Coord.parseCoord(player)), StringMgmt.remFirstArg(split));
            selection = TownyUtil.filterOwnedBlocks(resident, selection);

            if (selection.size() > 0) {

              // Start the unclaim task
              new PlotClaim(plugin, player, resident, selection, PlotClaim.Action.UNCLAIM).start();

            } else {
              player.sendMessage(TownySettings.getLangString("msg_err_empty_area_selection"));
            }
          }
        } else if (split[0].equalsIgnoreCase("notforsale") || split[0].equalsIgnoreCase("nfs")) {
          List<WorldCoord> selection = TownyUtil.selectWorldCoordArea(resident, new WorldCoord(world, Coord.parseCoord(player)), StringMgmt.remFirstArg(split));
          selection = TownyUtil.filterOwnedBlocks(resident.getTown(), selection);

          for (WorldCoord worldCoord : selection) {
            setPlotForSale(resident, worldCoord, -1);
          }
        } else if (split[0].equalsIgnoreCase("forsale") || split[0].equalsIgnoreCase("fs")) {
          WorldCoord pos = new WorldCoord(world, Coord.parseCoord(player));
          double plotPrice = pos.getTownBlock().getTown().getPlotTypePrice(pos.getTownBlock().getType());

          if (split.length > 1) {

            int areaSelectPivot = TownyUtil.getAreaSelectPivot(split);
            List<WorldCoord> selection;
            if (areaSelectPivot >= 0) {
              selection = TownyUtil.selectWorldCoordArea(resident, new WorldCoord(world, Coord.parseCoord(player)), StringMgmt.subArray(split, areaSelectPivot + 1, split.length));
              selection = TownyUtil.filterOwnedBlocks(resident.getTown(), selection);
              if (selection.size() == 0) {
                player.sendMessage(TownySettings.getLangString("msg_err_empty_area_selection"));
                return;
              }
            } else {
              selection = new ArrayList<WorldCoord>();
              selection.add(pos);
            }

            // Check that it's not: /plot forsale within rect 3
            if (areaSelectPivot != 1) {
              try {
                // command was 'plot fs $'
                plotPrice = Double.parseDouble(split[1]);
                if (plotPrice < 0) {
                                TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_negative_money"));
                                return;
                            }
              } catch (NumberFormatException e) {
                throw new TownyException(String.format(TownySettings.getLangString("msg_error_must_be_num")));
              }
            }

            for (WorldCoord worldCoord : selection) {
              if (selection.size() > 1)
                plotPrice = worldCoord.getTownBlock().getTown().getPlotTypePrice(worldCoord.getTownBlock().getType());
               
              setPlotForSale(resident, worldCoord, plotPrice);
            }
          } else {
            // basic 'plot fs' command
            setPlotForSale(resident, pos, plotPrice);
          }
        } else if (split[0].equalsIgnoreCase("perm")) {

          TownBlock townBlock = new WorldCoord(world, Coord.parseCoord(player)).getTownBlock();
          TownyMessaging.sendMessage(player, TownyFormatter.getStatus(townBlock));

        } else if (split[0].equalsIgnoreCase("toggle")) {
          TownBlock townBlock = new WorldCoord(world, Coord.parseCoord(player)).getTownBlock();
          // Runs tests to make sure we are allowed to work on this plot.
          // Ignore the returns as we are only checking for an exception
          plotTestOwner(resident, townBlock);
          townBlock.getTown();

          plotToggle(player, new WorldCoord(world, Coord.parseCoord(player)).getTownBlock(), StringMgmt.remFirstArg(split));

        } else if (split[0].equalsIgnoreCase("set")) {

          split = StringMgmt.remFirstArg(split);
          Town town = resident.getTown();

          if (split.length > 0) {
            if (split[0].equalsIgnoreCase("perm")) {

              //Set plot level permissions (if the plot owner) or Mayor/Assistant of the town.

              TownBlock townBlock = new WorldCoord(world, Coord.parseCoord(player)).getTownBlock();
              // Test we are allowed to work on this plot
              TownBlockOwner owner = plotTestOwner(resident, townBlock);
              town = townBlock.getTown();

              // Check we are allowed to set these perms
              toggleTest(player, townBlock, StringMgmt.join(StringMgmt.remFirstArg(split), ""));

              TownCommand.setTownBlockPermissions(player, owner, townBlock.getPermissions(), StringMgmt.remFirstArg(split), true);
              townBlock.setChanged(true);
              TownyUniverse.getDataSource().saveTownBlock(townBlock);
              return;
            }

            if ((!TownyUniverse.getPermissionSource().isTownyAdmin(player)) && ((plugin.isPermissions())
              && (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOWN_PLOTTYPE.getNode())))
              && !town.isMayor(resident)
              && !town.hasAssistant(resident))
              throw new TownyException(String.format(TownySettings.getLangString("msg_cache_block_error_town_resident"), "change plot types"));
           
            WorldCoord worldCoord = new WorldCoord(world, Coord.parseCoord(player));
            TownBlock townBlock = worldCoord.getTownBlock();
            setPlotType(resident, worldCoord, split[0]);
            townBlock.setChanged(true);
            TownyUniverse.getDataSource().saveTownBlock(townBlock);
            player.sendMessage(String.format(TownySettings.getLangString("msg_plot_set_type"), split[0]));

          } else {
            player.sendMessage(ChatTools.formatCommand("", "/plot set", "reset", ""));
            player.sendMessage(ChatTools.formatCommand("", "/plot set", "shop|embassy|arena|wilds|spleef", ""));
            player.sendMessage(ChatTools.formatCommand("", "/plot set perm", "?", ""));
          }
        } else if (split[0].equalsIgnoreCase("clear")) {

          if (!resident.isMayor())
            throw new TownyException(TownySettings.getLangString("msg_not_mayor"));

          TownBlock townBlock = new WorldCoord(world, Coord.parseCoord(player)).getTownBlock();

          if (townBlock != null) {
            if (townBlock.isOwner(resident.getTown()) && (!townBlock.hasResident())) {
              for (String material : world.getPlotManagementMayorDelete())
                if (Material.matchMaterial(material) != null) {
                  plugin.getTownyUniverse().deleteTownBlockMaterial(townBlock, Material.getMaterial(material).getId());
                  player.sendMessage(String.format(TownySettings.getLangString("msg_clear_plot_material"), material));
                } else
View Full Code Here

   * @throws TownyException
   */
  public TownBlockOwner plotTestOwner(Resident resident, TownBlock townBlock) throws TownyException {

    if (townBlock.hasResident()) {
      Resident owner = townBlock.getResident();

      // If not the plot owner or the towns mayor
      if ((resident != owner) && (!townBlock.getTown().getMayor().equals(resident)) && (!townBlock.getTown().hasAssistant(resident)))
        throw new TownyException(TownySettings.getLangString("msg_area_not_own"));

      return owner;

    } else {
      Town owner = townBlock.getTown();

      if ((!owner.isMayor(resident)) && (!owner.hasAssistant(resident)))
        throw new TownyException(TownySettings.getLangString("msg_not_mayor_ass"));

      if ((resident.getTown() != owner))
        throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));

View Full Code Here

  }

  public void parseResidentCommand(Player player, String[] split) {
    if (split.length == 0)
      try {
        Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
        TownyMessaging.sendMessage(player, TownyFormatter.getStatus(resident));
      } catch (NotRegisteredException x) {
        TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_not_registered"));
      }
    else if (split[0].equalsIgnoreCase("?") || split[0].equalsIgnoreCase("help"))
      for (String line : output)
        player.sendMessage(line);
    else if (split[0].equalsIgnoreCase("list"))
      listResidents(player);
    else if (split[0].equalsIgnoreCase("tax")) {
      try {
        Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
        TownyMessaging.sendMessage(player, TownyFormatter.getTaxStatus(resident));
      } catch (NotRegisteredException x) {
        TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_not_registered"));
      }     
    } else if (split[0].equalsIgnoreCase("set")) {
      String[] newSplit = StringMgmt.remFirstArg(split);
      residentSet(player, newSplit);
    } else if (split[0].equalsIgnoreCase("friend")) {
      String[] newSplit = StringMgmt.remFirstArg(split);
      residentFriend(player, newSplit);
    } else if (split[0].equalsIgnoreCase("delete")) {
      String[] newSplit = StringMgmt.remFirstArg(split);
      residentDelete(player, newSplit);
    } else
      try {
        Resident resident = TownyUniverse.getDataSource().getResident(split[0]);
        TownyMessaging.sendMessage(player, TownyFormatter.getStatus(resident));
      } catch (NotRegisteredException x) {
        TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_registered_1"), split[0]));
      }
  }
View Full Code Here

    if (split.length == 0) {
      player.sendMessage(ChatTools.formatCommand("", "/resident set", "perm ...", "'/resident set perm' " + TownySettings.getLangString("res_5")));
      player.sendMessage(ChatTools.formatCommand("", "/resident set", "mode ...", "'/resident set mode' " + TownySettings.getLangString("res_5")));
    } else {
      Resident resident;
      try {
        resident = TownyUniverse.getDataSource().getResident(player.getName());
      } catch (TownyException x) {
        TownyMessaging.sendErrorMsg(player, x.getMessage());
        return;
      }

      // TODO: Let admin's call a subfunction of this.
      if (split[0].equalsIgnoreCase("perm")) {
        String[] newSplit = StringMgmt.remFirstArg(split);
        TownCommand.setTownBlockPermissions(player, resident, resident.getPermissions(), newSplit, true);
      } else if (split[0].equalsIgnoreCase("mode")) {
        String[] newSplit = StringMgmt.remFirstArg(split);
        setMode(player, newSplit);
      } else {
        TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_invalid_property"), "town"));
View Full Code Here

    if (split.length == 0) {
      player.sendMessage(ChatTools.formatCommand("", "/resident friend", "add " + TownySettings.getLangString("res_2"), ""));
      player.sendMessage(ChatTools.formatCommand("", "/resident friend", "remove " + TownySettings.getLangString("res_2"), ""));
      player.sendMessage(ChatTools.formatCommand("", "/resident friend", "clear", ""));
    } else {
      Resident resident;
      try {
        resident = TownyUniverse.getDataSource().getResident(player.getName());
      } catch (TownyException x) {
        TownyMessaging.sendErrorMsg(player, x.getMessage());
        return;
      }

      // TODO: Let admin's call a subfunction of this.
      if (split[0].equalsIgnoreCase("add")) {
        String[] names = StringMgmt.remFirstArg(split);
        residentFriendAdd(player, resident, plugin.getTownyUniverse().getOnlineResidents(player, names));
      } else if (split[0].equalsIgnoreCase("remove")) {
        String[] names = StringMgmt.remFirstArg(split);
        residentFriendRemove(player, resident, plugin.getTownyUniverse().getOnlineResidents(player, names));
      } else if (split[0].equalsIgnoreCase("add+")) {
        String[] names = StringMgmt.remFirstArg(split);
        residentFriendAdd(player, resident, getResidents(player, names));
      } else if (split[0].equalsIgnoreCase("remove+")) {
        String[] names = StringMgmt.remFirstArg(split);
        residentFriendRemove(player, resident, getResidents(player, names));
      } else if (split[0].equalsIgnoreCase("clearlist") || split[0].equalsIgnoreCase("clear")) {
        residentFriendRemove(player, resident, resident.getFriends());
      }

    }
  }
View Full Code Here

  private static List<Resident> getResidents(Player player, String[] names) {
    List<Resident> invited = new ArrayList<Resident>();
    for (String name : names)
      try {
        Resident target = TownyUniverse.getDataSource().getResident(name);
        invited.add(target);
      } catch (TownyException x) {
        TownyMessaging.sendErrorMsg(player, x.getMessage());
      }
    return invited;
View Full Code Here

TOP

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

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.