Package com.palmergames.bukkit.towny.object

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


        private void parseTownCommand(Player player, String[] split) {
               
                if (split.length == 0)
                        try {
                                Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
                                Town town = resident.getTown();
                                TownyMessaging.sendMessage(player, TownyFormatter.getStatus(town));
                        } catch (NotRegisteredException x) {
                                TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_dont_belong_town"));
                        }
                else if (split[0].equalsIgnoreCase("?") || split[0].equalsIgnoreCase("help"))
                        for (String line : output)
                                player.sendMessage(line);
                else if (split[0].equalsIgnoreCase("here"))
                        showTownStatusHere(player);
                else if (split[0].equalsIgnoreCase("list"))
                        listTowns(player);
                else if (split[0].equalsIgnoreCase("new")) {
                        if (split.length == 1)
                                TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_specify_name"));
                        else if (split.length == 2)
                                newTown(player, split[1], player.getName());
                        else
                                // TODO: Check if player is an admin
                                newTown(player, split[1], split[2]);
                } else if (split[0].equalsIgnoreCase("leave")) {
                    townLeave(player);
            } else if (split[0].equalsIgnoreCase("withdraw")) {
                        if (split.length == 2)
                                try {
                                        townWithdraw(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"), "/town withdraw"));
                } else if (split[0].equalsIgnoreCase("deposit")) {
                        if (split.length == 2)
                                try {
                                        townDeposit(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"), "/town deposit"));
                } else {
                        String[] newSplit = StringMgmt.remFirstArg(split);
                       
                        if (split[0].equalsIgnoreCase("set"))
                                townSet(player, newSplit);
                        else if (split[0].equalsIgnoreCase("buy"))
                              townBuy(player, newSplit);
                        else if (split[0].equalsIgnoreCase("toggle"))
                              townToggle(player, newSplit);
                        else  if (split[0].equalsIgnoreCase("mayor"))
                                townMayor(player, newSplit);
                        else if (split[0].equalsIgnoreCase("assistant"))
                                townAssistant(player, newSplit);
                        else if (split[0].equalsIgnoreCase("spawn"))
                           townSpawn(player, newSplit);
                        else if (split[0].equalsIgnoreCase("delete"))
                                townDelete(player, newSplit);
                        else if (split[0].equalsIgnoreCase("join"))
                              parseTownJoin(player, newSplit);
                        else if (split[0].equalsIgnoreCase("add"))
                                townAdd(player, null, newSplit);
                        else if (split[0].equalsIgnoreCase("kick"))
                                townKick(player, newSplit);
                        else if (split[0].equalsIgnoreCase("claim"))
                                parseTownClaimCommand(player, newSplit);
                        else if (split[0].equalsIgnoreCase("unclaim"))
                                parseTownUnclaimCommand(player, newSplit);
                        else if (split[0].equalsIgnoreCase("online")) {
                  try {
                    Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
                    Town town = resident.getTown();
                    TownyMessaging.sendMessage(player, TownyFormatter.getFormattedOnlineResidents(plugin, TownySettings.getLangString("msg_town_online"), town));
                  } catch (NotRegisteredException x) {
                    TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_dont_belong_town"));
                  }
                        } else
                                try {
                                        Town town = TownyUniverse.getDataSource().getTown(split[0]);
                                        TownyMessaging.sendMessage(player, TownyFormatter.getStatus(town));
                                } catch (NotRegisteredException x) {
                                        TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_not_registered_1"), split[0]));
                                }
                }
View Full Code Here


         */
        public void showTownStatusAtCoord(Player player, TownyWorld world, Coord coord) throws TownyException {
                if (!world.hasTownBlock(coord))
                        throw new TownyException(String.format(TownySettings.getLangString("msg_not_claimed"), coord));

                Town town = world.getTownBlock(coord).getTown();
                TownyMessaging.sendMessage(player, TownyFormatter.getStatus(town));
        }
View Full Code Here

                player.sendMessage(ChatTools.formatCommand("", "/town toggle", "mobs", ""));
                player.sendMessage(ChatTools.formatCommand("", "/town toggle", "taxpercent", ""));
                player.sendMessage(ChatTools.formatCommand("", "/town toggle", "open", ""));
            } else {
              Resident resident;
                Town town;
                try {
                  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"));
                } catch (TownyException x) {
                  TownyMessaging.sendErrorMsg(player, x.getMessage());
                  return;
                }
               
                try {
                  // TODO: Let admin's call a subfunction of this.
                  if (split[0].equalsIgnoreCase("public")) {
                    if (plugin.isPermissions() && (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOGGLE_PUBLIC.getNode())))
                        throw new Exception(TownySettings.getLangString("msg_err_command_disable"));
                       
                       town.setPublic(!town.isPublic());
                         TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_changed_public"), town.isPublic() ? "Enabled" : "Disabled"));
                         
                     } else if (split[0].equalsIgnoreCase("pvp")) {
                      //Make sure we are allowed to set these permissions.
                      toggleTest(player,town,StringMgmt.join(split, " "));  
                        town.setPVP(!town.isPVP());
                        TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_changed_pvp"), "Town", town.isPVP() ? "Enabled" : "Disabled"));
                                       
                    } else if (split[0].equalsIgnoreCase("explosion")) {
                      //Make sure we are allowed to set these permissions.
                      toggleTest(player,town,StringMgmt.join(split, " "));
                      town.setBANG(!town.isBANG());
                      TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_changed_expl"), "Town", town.isBANG() ? "Enabled" : "Disabled"));

                    } else if (split[0].equalsIgnoreCase("fire")) {
                      //Make sure we are allowed to set these permissions.
                      toggleTest(player,town,StringMgmt.join(split, " "));
                      town.setFire(!town.isFire());
                      TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_changed_fire"), "Town", town.isFire() ? "Enabled" : "Disabled"));

                    } else if (split[0].equalsIgnoreCase("mobs")) {
                      //Make sure we are allowed to set these permissions.
                      toggleTest(player,town,StringMgmt.join(split, " "));
                      town.setHasMobs(!town.hasMobs());
                      TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_changed_mobs"), "Town", town.hasMobs() ? "Enabled" : "Disabled"));
           
                    } else if (split[0].equalsIgnoreCase("taxpercent")) {
                      town.setTaxPercentage(!town.isTaxPercentage());
                        TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_changed_taxpercent"), town.isTaxPercentage() ? "Enabled" : "Disabled"));
                    } else if (split[0].equalsIgnoreCase("open")) {
                      if (plugin.isPermissions() && (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOGGLE_OPEN.getNode())))
                        throw new Exception(TownySettings.getLangString("msg_err_command_disable"));
                     
                      town.setOpen(!town.isOpen());
                        TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_changed_open"), town.isOpen() ? "Enabled" : "Disabled"));
                       
                        // Send a warning when toggling on (a reminder about plot permissions).
                        if (town.isOpen())
                          TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_toggle_open_on_warning")));
                    } else {
                      TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_invalid_property"), "town"));
                      return;
                    }
                 
                  // Propagate perms to all unchanged, town owned, townblocks
              for (TownBlock townBlock : town.getTownBlocks()) {
                if (!townBlock.hasResident() && !townBlock.isChanged()) {
                  townBlock.setType(townBlock.getType());
                  TownyUniverse.getDataSource().saveTownBlock(townBlock);
                }
              }
View Full Code Here

  public static List<String> getStatus(TownBlock townBlock) {
    List<String> out = new ArrayList<String>();

    try {
      TownBlockOwner owner;
      Town town = townBlock.getTown();
      TownyWorld world = townBlock.getWorld();

      if (townBlock.hasResident()) {
        owner = townBlock.getResident();
      } else {
        owner = townBlock.getTown();
      }

      out.add(ChatTools.formatTitle(TownyFormatter.getFormattedName(owner) + ((MinecraftTools.isOnline(owner.getName())) ? Colors.LightGreen + " (Online)" : "")));
      out.add(Colors.Green + " Perm: " + ((owner instanceof Resident) ? townBlock.getPermissions().getColourString() : townBlock.getPermissions().getColourString().replace("f", "r")));
      out.add(Colors.Green + "PvP: " + ((town.isPVP() || world.isForcePVP() || townBlock.getPermissions().pvp) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + "  Explosions: " + ((world.isForceExpl() || townBlock.getPermissions().explosion) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + "  Firespread: " + ((town.isFire() || world.isForceFire() || townBlock.getPermissions().fire) ? Colors.Red + "ON" : Colors.LightGreen + "OFF") + Colors.Green + "  Mob Spawns: " + ((town.hasMobs() || world.isForceTownMobs() || townBlock.getPermissions().mobs) ? Colors.Red + "ON" : Colors.LightGreen + "OFF"));

    } catch (NotRegisteredException e) {
      out.add("Error: " + e.getMessage());
    }
View Full Code Here

   * @param resident
   * @return tax status message
   */
  public static List<String> getTaxStatus(Resident resident) {
    List<String> out = new ArrayList<String>();
    Town town = null;
    double plotTax = 0.0;
   
    out.add(ChatTools.formatTitle(getFormattedName(resident) + ((MinecraftTools.isOnline(resident.getName())) ? Colors.LightGreen + " (Online)" : "")));
   
    if (resident.hasTown()) {
      try {
        town = resident.getTown();
        out.add(Colors.Green + "Owner of: " + Colors.LightGreen + resident.getTownBlocks().size() + " plots");
       
        if (resident.isMayor() || town.hasAssistant(resident)) {
          out.add(Colors.Green + "Staff are exempt from paying town taxes.");
        } else {
          if(town.isTaxPercentage()) {
            out.add(Colors.Green + "Town Tax: " + Colors.LightGreen + (resident.getHoldingBalance() * town.getTaxes()/100));
          } else {
            out.add(Colors.Green + "Town Tax: " + Colors.LightGreen + town.getTaxes());
           
            if ((resident.getTownBlocks().size() > 0)) {
             
              for (TownBlock townBlock : new ArrayList<TownBlock>(resident.getTownBlocks())) {
                plotTax += townBlock.getType().getTax(townBlock.getTown());
              }
             
              out.add(Colors.Green + "Total Plot Taxes: " + Colors.LightGreen + plotTax);
            }
            out.add(Colors.Green + "Total Tax to pay: " + Colors.LightGreen + (town.getTaxes() + plotTax));
          }
        }
       
      } catch (NotRegisteredException e) {
        // Failed to fetch town
View Full Code Here

   
  }
 
  private boolean residentClaim(WorldCoord worldCoord) throws TownyException, EconomyException {
    TownBlock townBlock;
    Town town;
   
    TownyMessaging.sendMsg(player, String.format("1) %s", worldCoord.toString()));
   
    try {
      townBlock = worldCoord.getTownBlock();
      town = townBlock.getTown();
    } catch (NotRegisteredException e) {
      throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));
    }
   
    TownyMessaging.sendMsg(player, String.format("2) %s", worldCoord.toString()));
   
    if (!resident.hasTown() && town.isOpen()) {
      // Town is open, so have the player join the town first.
      TownCommand.townJoin(town, resident);
      TownyMessaging.sendMsg(player, String.format("3) %s", worldCoord.toString()));
    }
   
    TownyMessaging.sendMsg(player, String.format("4) %s", worldCoord.toString()));
   
    if (!resident.hasTown()) {
      // Town is not open, or resident failed to join.
      // You are thus needed to belong to a town in order to claim plots.
      TownyMessaging.sendMsg(player, String.format("5) %s", worldCoord.toString()));
      throw new TownyException(TownySettings.getLangString("msg_err_not_in_town_claim"));
    } else {
      // Resident is (now) in a town.
      try {
        // Check for embassy plot, or if the resident is is the town.
        if (!resident.getTown().equals(town) && !townBlock.getType().equals(TownBlockType.EMBASSY))
          throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));

        try {
          Resident owner = townBlock.getResident();
          if (townBlock.getPlotPrice() != -1) {
            // Plot is for sale
            if (TownySettings.isUsingEconomy() && !resident.payTo(townBlock.getPlotPrice(), owner, "Plot - Buy From Seller"))
              throw new TownyException(TownySettings.getLangString("msg_no_money_purchase_plot"));
           
            int maxPlots = TownySettings.getMaxResidentPlots(resident);
            if (maxPlots >= 0 && resident.getTownBlocks().size() + 1 > maxPlots)
              throw new TownyException(String.format(TownySettings.getLangString("msg_max_plot_own"), maxPlots));
           
            TownyMessaging.sendTownMessage(town, TownySettings.getBuyResidentPlotMsg(resident.getName(), owner.getName(), townBlock.getPlotPrice()));
            townBlock.setPlotPrice(-1);
            townBlock.setResident(resident);
           
            // Set the plot permissions to mirror the new owners.
            townBlock.setType(townBlock.getType());

            TownyUniverse.getDataSource().saveResident(owner);
            TownyUniverse.getDataSource().saveTownBlock(townBlock);
           
            plugin.updateCache();
            return true;
          } else if (town.isMayor(resident) || town.hasAssistant(resident)) {
            //Plot isn't for sale but re-possessing for town.
           
            if (TownySettings.isUsingEconomy() && !town.payTo(0.0, owner, "Plot - Buy Back"))
              throw new TownyException(TownySettings.getLangString("msg_town_no_money_purchase_plot"));
           
            TownyMessaging.sendTownMessage(town, TownySettings.getBuyResidentPlotMsg(town.getName(), owner.getName(), 0.0));
            townBlock.setResident(null);
            townBlock.setPlotPrice(-1);
           
            // Set the plot permissions to mirror the towns.
            townBlock.setType(townBlock.getType());
View Full Code Here

    if (pos.getWorld().isClaimable()) {
      if (args.length > 0) {
        int r = 0, available = 0;
       
        if (owner instanceof Town) {
          Town town = (Town)owner;
          available = TownySettings.getMaxTownBlocks(town) - town.getTownBlocks().size();
        } else if (owner instanceof Resident) {
          available = TownySettings.getMaxResidentPlots((Resident)owner);
        }
       
        if (args[0].equalsIgnoreCase("auto")) {
View Full Code Here

    List<WorldCoord> out = new ArrayList<WorldCoord>();
    if (pos.getWorld().isClaimable()) {
      if (args.length > 0) {
        int r = 0, available = 0;
        if (owner instanceof Town) {
            Town town = (Town)owner;
            available = TownySettings.getMaxTownBlocks(town) - town.getTownBlocks().size();
        } else if (owner instanceof Resident) {
          available = TownySettings.getMaxResidentPlots((Resident)owner);
        }
       
        if (args[0].equalsIgnoreCase("auto")) {
View Full Code Here

    if (block.getY() < topY)
      throw new TownyException(TownySettings.getLangString("msg_err_enemy_war_must_be_placed_above_ground"));
   
    TownyUniverse universe = plugin.getTownyUniverse();
    Resident attackingResident;
    Town landOwnerTown, attackingTown;
    Nation landOwnerNation, attackingNation;
   
    try {
      attackingResident = TownyUniverse.getDataSource().getResident(player.getName());
      attackingTown = attackingResident.getTown();
      attackingNation = attackingTown.getNation();
    } catch (NotRegisteredException e) {
      throw new TownyException(TownySettings.getLangString("msg_err_dont_belong_nation"));
    }
   
    try {
      landOwnerTown = worldCoord.getTownBlock().getTown();
      landOwnerNation = landOwnerTown.getNation();
    } catch (NotRegisteredException e) {
      throw new TownyException(TownySettings.getLangString("msg_err_enemy_war_not_part_of_nation"));
    }
   
    // Check Neutrality
    if (landOwnerNation.isNeutral())
      throw new TownyException(String.format(TownySettings.getLangString("msg_err_enemy_war_is_neutral"), landOwnerNation.getFormattedName()));
    if (!TownyUniverse.getPermissionSource().isTownyAdmin(player) && attackingNation.isNeutral())
      throw new TownyException(String.format(TownySettings.getLangString("msg_err_enemy_war_is_neutral"), attackingNation.getFormattedName()));
   
    // Check Minimum Players Online
    checkIfTownHasMinOnlineForWar(universe, landOwnerTown);
    checkIfNationHasMinOnlineForWar(universe, landOwnerNation);
    checkIfTownHasMinOnlineForWar(universe, attackingTown);
    checkIfNationHasMinOnlineForWar(universe, attackingNation);
   
    // Check that attack takes place on the edge of a town
    if (!TownyUtil.isOnEdgeOfOwnership(landOwnerTown, worldCoord))
      throw new TownyException(TownySettings.getLangString("msg_err_enemy_war_not_on_edge_of_town"));
   
    // Call Event (and make sure an attack isn't already under way)
    CellAttackEvent cellAttackEvent = new CellAttackEvent(player, block);
    plugin.getServer().getPluginManager().callEvent(cellAttackEvent);
   
    if (cellAttackEvent.isCancelled()) {
      if (cellAttackEvent.hasReason())
        throw new TownyException(cellAttackEvent.getReason());
      else
        return false;
    }
   
    // Successful Attack
    if (!landOwnerNation.hasEnemy(attackingNation)) {
      landOwnerNation.addEnemy(attackingNation);
      plugin.getTownyUniverse();
      TownyUniverse.getDataSource().saveNation(landOwnerNation);
    }
   
    // Update Cache
    universe.addWarZone(worldCoord);
    plugin.updateCache(worldCoord);
   
    TownyMessaging.sendGlobalMessage(String.format(TownySettings.getLangString("msg_enemy_war_area_under_attack"), landOwnerTown.getFormattedName(), worldCoord.toString(), attackingResident.getFormattedName()));
    return true;
  }
View Full Code Here

      CellUnderAttack cell = cellWonEvent.getCellAttackData();
     
      TownyUniverse universe = plugin.getTownyUniverse();
      try {
        Resident resident = TownyUniverse.getDataSource().getResident(cell.getNameOfFlagOwner());
        Town town = resident.getTown();
        Nation nation = town.getNation();
       
        TownyWorld world = TownyUniverse.getDataSource().getWorld(cell.getWorldName());
        WorldCoord worldCoord = new WorldCoord(world, cell.getX(), cell.getZ());
        universe.removeWarZone(worldCoord);
       
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.