Package com.palmergames.bukkit.towny.object

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


      player.sendMessage(ChatTools.formatCommand(TownySettings.getLangString("mayor_sing"), "/town claim", "outpost", TownySettings.getLangString("mayor_help_3")));
      player.sendMessage(ChatTools.formatCommand(TownySettings.getLangString("mayor_sing"), "/town claim", "[circle/rect] [radius]", TownySettings.getLangString("mayor_help_4")));
      player.sendMessage(ChatTools.formatCommand(TownySettings.getLangString("mayor_sing"), "/town claim", "[circle/rect] auto", TownySettings.getLangString("mayor_help_5")));
    } else {
      Resident resident;
      Town town;
      TownyWorld world;
      try {
        if (plugin.getTownyUniverse().isWarTime())
          throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));

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

        resident = TownyUniverse.getDataSource().getResident(player.getName());
        town = resident.getTown();
        if (!resident.isMayor() && !town.hasAssistant(resident))
          throw new TownyException(TownySettings.getLangString("msg_not_mayor_ass"));
        world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());

        if (!world.isUsingTowny())
          throw new TownyException(TownySettings.getLangString("msg_set_use_towny_off"));

        double blockCost = 0;
        List<WorldCoord> selection;
        boolean attachedToEdge = true;
        Coord key = Coord.parseCoord(plugin.getCache(player).getLastLocation());

        if (split.length == 1 && split[0].equalsIgnoreCase("outpost")) {
          if ((TownySettings.isAllowingOutposts())
            && (!plugin.isPermissions() || ((plugin.isPermissions()) && TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOWN_CLAIM_OUTPOST.getNode())))){

            if (world.hasTownBlock(key))
              throw new TownyException(String.format(TownySettings.getLangString("msg_already_claimed_1"), key));

            if (world.getMinDistanceFromOtherTowns(key) < TownySettings.getMinDistanceFromTownHomeblocks())
              throw new TownyException(TownySettings.getLangString("msg_too_close"));

            selection = new ArrayList<WorldCoord>();
            selection.add(new WorldCoord(world, key));
            blockCost = TownySettings.getOutpostCost();
            attachedToEdge = false;
          } else
            throw new TownyException(TownySettings.getLangString("msg_outpost_disable"));
        } else {
          selection = TownyUtil.selectWorldCoordArea(town, new WorldCoord(world, key), split);
          blockCost = TownySettings.getClaimPrice();
        }

        TownyMessaging.sendDebugMsg("townClaim: Pre-Filter Selection " + Arrays.toString(selection.toArray(new WorldCoord[0])));
        selection = TownyUtil.filterTownOwnedBlocks(selection);
        TownyMessaging.sendDebugMsg("townClaim: Post-Filter Selection " + Arrays.toString(selection.toArray(new WorldCoord[0])));
        checkIfSelectionIsValid(town, selection, attachedToEdge, blockCost, false);

        try {
          double cost = blockCost * selection.size();
          if (TownySettings.isUsingEconomy() && !town.pay(cost, String.format("Town Claim (%d)", selection.size())))
            throw new TownyException(String.format(TownySettings.getLangString("msg_no_funds_claim"), selection.size(), cost + TownyEconomyObject.getEconomyCurrency()));
        } catch (EconomyException e1) {
          throw new TownyException("Economy Error");
        }

View Full Code Here


                        player.sendMessage(ChatTools.formatCommand(TownySettings.getLangString("mayor_sing"), "/town unclaim", "", TownySettings.getLangString("mayor_help_6")));
                        player.sendMessage(ChatTools.formatCommand(TownySettings.getLangString("mayor_sing"), "/town unclaim", "[circle/rect] [radius]", TownySettings.getLangString("mayor_help_7")));
                        player.sendMessage(ChatTools.formatCommand(TownySettings.getLangString("mayor_sing"), "/town unclaim", "all", TownySettings.getLangString("mayor_help_8")));
                } else {
                        Resident resident;
                        Town town;
                        TownyWorld world;
                        try {
                                if (plugin.getTownyUniverse().isWarTime())
                                        throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));
                               
                                resident = TownyUniverse.getDataSource().getResident(player.getName());
                                town = resident.getTown();
                                if (!resident.isMayor())
                                        if (!town.hasAssistant(resident))
                                                throw new TownyException(TownySettings.getLangString("msg_not_mayor_ass"));
                world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
                               
                                List<WorldCoord> selection;
                                if (split.length == 1 && split[0].equalsIgnoreCase("all"))
View Full Code Here

        }
       
        public static void checkIfSelectionIsValid(TownBlockOwner owner, List<WorldCoord> selection, boolean attachedToEdge, double blockCost, boolean force) throws TownyException {
                if (force)
                        return;
                Town town = (Town)owner;
               
                //System.out.print("isEdgeBlock: "+ isEdgeBlock(owner, selection));
               
                if (attachedToEdge && !isEdgeBlock(owner, selection) && !town.getTownBlocks().isEmpty()) {
                        if (selection.size() == 0)
                                throw new TownyException(TownySettings.getLangString("msg_already_claimed_2"));
                        else
                                throw new TownyException(TownySettings.getLangString("msg_err_not_attached_edge"));
                }
               
                if (owner instanceof Town) {
                        //Town town = (Town)owner;
                        int available = TownySettings.getMaxTownBlocks(town) - town.getTownBlocks().size();
                        TownyMessaging.sendDebugMsg("Claim Check Available: " + available);
                        TownyMessaging.sendDebugMsg("Claim Selection Size: " + selection.size());
                        if (available - selection.size() < 0)
                                throw new TownyException(TownySettings.getLangString("msg_err_not_enough_blocks"));
                }
View Full Code Here

        }
        */
       
        private void townWithdraw(Player player, int amount) {
                Resident resident;
                Town town;
                try {
                        if(!TownySettings.getTownBankAllowWithdrawls())
                                throw new TownyException(TownySettings.getLangString("msg_err_withdraw_disabled"));
                       
                        if (amount < 0)
                                throw new TownyException(TownySettings.getLangString("msg_err_negative_money"));
                       
                        resident = TownyUniverse.getDataSource().getResident(player.getName());
                        town = resident.getTown();
                       
                        town.withdrawFromBank(resident, amount);
                        TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_xx_withdrew_xx"), resident.getName(), amount, "town"));
                } catch (TownyException x) {
                        TownyMessaging.sendErrorMsg(player, x.getMessage());
                } catch (EconomyException x) {
                        TownyMessaging.sendErrorMsg(player, x.getMessage());
View Full Code Here

                }
        }
       
        private void townDeposit(Player player, int amount) {
                Resident resident;
                Town town;
                try {
                        resident = TownyUniverse.getDataSource().getResident(player.getName());
                        town = resident.getTown();
                       
                        double bankcap = TownySettings.getTownBankCap();
                        if (bankcap > 0) {
                                if(amount + town.getHoldingBalance() > bankcap)
                                        throw new TownyException(String.format(TownySettings.getLangString("msg_err_deposit_capped"), bankcap));
                        }
                       
                        if (amount < 0)
                                throw new TownyException(TownySettings.getLangString("msg_err_negative_money"));
View Full Code Here

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

   * @throws TownyException if toggle is not permitted
   */
  private void toggleTest(Player player, TownBlock townBlock, String split) throws TownyException {

    //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"))) {
View Full Code Here

        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

      TownyMessaging.sendErrorMsg(getSender(), TownySettings.getLangString("msg_err_invalid_sub"));
  }

  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) {
View Full Code Here

      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]", ""));
    } else {
      try {
        Town town = TownyUniverse.getDataSource().getTown(split[0]);
        if (split.length == 1)
          TownyMessaging.sendMessage(getSender(), TownyFormatter.getStatus(town));
        else if (split[1].equalsIgnoreCase("add")) {
          /*
          if (isConsole) {
            sender.sendMessage("[Towny] InputError: This command was designed for use in game only.");
            return;
          }
          */
          TownCommand.townAdd(sender, town, StringMgmt.remArgs(split, 2));

        } else if (split[1].equalsIgnoreCase("kick")) {

          TownCommand.townKickResidents(getSender(), town.getMayor(), town, plugin.getTownyUniverse().getValidatedResidents(getSender(), StringMgmt.remArgs(split, 2)));

        } else if (split[1].equalsIgnoreCase("rename")) {

          if (TownySettings.isValidRegionName(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"));
        }

      } catch (NotRegisteredException e) {
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.