Package com.palmergames.bukkit.towny

Examples of com.palmergames.bukkit.towny.TownyException


      try {
        resident = TownyUniverse.getDataSource().getResident(player.getName());
        nation = resident.getTown().getNation();
        if (!resident.isKing())
          if (!nation.hasAssistant(resident))
            throw new TownyException(TownySettings.getLangString("msg_not_king_ass"));
      } catch (TownyException x) {
        TownyMessaging.sendErrorMsg(player, x.getMessage());
        return;
      }
View Full Code Here


      try {
        resident = TownyUniverse.getDataSource().getResident(player.getName());
        nation = resident.getTown().getNation();
        if (!resident.isKing())
          if (!nation.hasAssistant(resident))
            throw new TownyException(TownySettings.getLangString("msg_not_king_ass"));
      } catch (TownyException x) {
        TownyMessaging.sendErrorMsg(player, x.getMessage());
        return;
      }

      if (split[0].equalsIgnoreCase("neutral")) {
        try {
          if (!TownySettings.isDeclaringNeutral())
            throw new TownyException(TownySettings.getLangString("msg_neutral_disabled"));

          boolean choice = !nation.isNeutral();
          Double cost = TownySettings.getNationNeutralityCost();

          if (choice && TownySettings.isUsingEconomy() && !nation.pay(cost, "Nation Neutrality Cost"))
            throw new TownyException(TownySettings.getLangString("msg_nation_cant_neutral"));

          nation.setNeutral(choice);
          plugin.updateCache();

          // send message depending on if using IConomy and charging for neutral
View Full Code Here

    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");
    }
  } 
View Full Code Here

  public static Player getPlayer(Resident resident) throws TownyException {
    for (Player player : getOnlinePlayers())
      if (player.getName().equals(resident.getName()))
        return player;
    throw new TownyException(String.format("%s is not online", resident.getName()));
  }
View Full Code Here

                kvTable.sortByValue();
                kvTable.revese();
                if (kvTable.getKeyValues().size() > 0)
                        return kvTable.getKeyValues().get(0);
                else
                        throw new TownyException();
        }
View Full Code Here

  }

  public void parsePlotCommand(Player player, String[] split) throws TownyException {

    if ((!TownyUniverse.getPermissionSource().isTownyAdmin(player)) && ((plugin.isPermissions()) && (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOWN_PLOT.getNode()))))
      throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));

    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
                  throw new TownyException(String.format(TownySettings.getLangString("msg_err_invalid_property"), material));
            } else
              throw new TownyException(String.format(TownySettings.getLangString("msg_already_claimed"), townBlock.getResident().getName()));

          } else {
            // Shouldn't ever reach here as a null townBlock should be caught already in WorldCoord.
            player.sendMessage(TownySettings.getLangString("msg_err_empty_area_selection"));
          }
View Full Code Here

        plotTestOwner(resident, townBlock); //ignore the return as we are only checking for an exception
       
        townBlock.setType(type);
       
      } catch (NotRegisteredException e) {
        throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));
      }
    else
      throw new TownyException(TownySettings.getLangString("msg_err_must_belong_town"));
  }
View Full Code Here

        if (forSale != -1)
          TownyMessaging.sendTownMessage(townBlock.getTown(), TownySettings.getPlotForSaleMsg(resident.getName(), worldCoord));
        else
          TownyUniverse.getPlayer(resident).sendMessage(TownySettings.getLangString("msg_err_plot_nfs"));
      } catch (NotRegisteredException e) {
        throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));
      }
    else
      throw new TownyException(TownySettings.getLangString("msg_err_must_belong_town"));
  }
View Full Code Here

    //Make sure we are allowed to set these permissions.
    Town town = townBlock.getTown();

    if (split.contains("mobs")) {
      if (town.getWorld().isForceTownMobs())
        throw new TownyException(TownySettings.getLangString("msg_world_mobs"));
      if (plugin.isPermissions() && (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOGGLE_MOBS.getNode())))
        throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
    }

    if (split.contains("fire")) {
      if (town.getWorld().isForceFire())
        throw new TownyException(TownySettings.getLangString("msg_world_fire"));
      if (plugin.isPermissions() && (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOGGLE_FIRE.getNode())))
        throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
    }

    if (split.contains("explosion")) {
      if (town.getWorld().isForceExpl())
        throw new TownyException(TownySettings.getLangString("msg_world_expl"));
      if (plugin.isPermissions() && (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOGGLE_EXPLOSION.getNode())))
        throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
    }

    if (split.contains("pvp")) {
      if (town.getWorld().isForcePVP())
        throw new TownyException(TownySettings.getLangString("msg_world_pvp"));
      if (plugin.isPermissions() && (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOGGLE_PVP.getNode())))
        throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
    }
    if ((split.contains("pvp")) || (split.trim().equalsIgnoreCase("off"))) {
      if (townBlock.getType().equals(TownBlockType.ARENA))
        throw new TownyException(TownySettings.getLangString("msg_plot_pvp"));
    }
  }
View Full Code Here

    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"));

      return owner;
    }

  }
View Full Code Here

TOP

Related Classes of com.palmergames.bukkit.towny.TownyException

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.