Package com.palmergames.bukkit.towny.object

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


          } catch (NotRegisteredException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
            try {
              TownBlock townBlock = townyWorld.getTownBlock(coord);
              if ((!townBlock.getTown().hasMobs() && !townBlock.getPermissions().mobs && isRemovingTownEntity(livingEntity))) {
                //System.out.println("[Towny] Town MobRemovalTimerTask - added: " + livingEntity.toString());
                livingEntitiesToRemove.add(livingEntity);
              }
               
            } catch (TownyException x) {
View Full Code Here


    }
   
    // Take a snapshot of the next townBlock and save.
    if (TownyRegenAPI.hasWorldCoords()) {
      try {
        TownBlock townBlock = TownyRegenAPI.getWorldCoord().getTownBlock();
        PlotBlockData plotChunk = new PlotBlockData(townBlock);
          plotChunk.initialize(); // Create a new snapshot.

          if (!plotChunk.getBlockList().isEmpty() && !(plotChunk.getBlockList() == null))
            TownyRegenAPI.addPlotChunkSnapshot(plotChunk); // Save the snapshot.
       
          plotChunk = null;
         
          townBlock.setLocked(false);
          TownyUniverse.getDataSource().saveTownBlock(townBlock);
          plugin.updateCache();
         
          if (!TownyRegenAPI.hasWorldCoords())
            TownyLogger.log.info("Plot snapshots completed.");
View Full Code Here

    plugin.updateCache();
   
  }
 
  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());

            TownyUniverse.getDataSource().saveResident(owner);
            TownyUniverse.getDataSource().saveTownBlock(townBlock);

            return true;
          } else {
            //Should never reach here.
            throw new AlreadyRegisteredException(String.format(TownySettings.getLangString("msg_already_claimed"), owner.getName()));
          }
               
        } catch (NotRegisteredException e) {
          //Plot has no owner so it's the town selling it
          TownyMessaging.sendMsg(player, String.format("6) %s", worldCoord.toString()));
          if (townBlock.getPlotPrice() == -1)
              throw new TownyException(TownySettings.getLangString("msg_err_plot_nfs"));
          TownyMessaging.sendMsg(player, String.format("7) %s", worldCoord.toString()));
          if (TownySettings.isUsingEconomy() && !resident.payTo(townBlock.getPlotPrice(), town, "Plot - Buy From Town"))
              throw new TownyException(TownySettings.getLangString("msg_no_money_purchase_plot"));
          TownyMessaging.sendMsg(player, String.format("8) %s", worldCoord.toString()));
          townBlock.setPlotPrice(-1);
          townBlock.setResident(resident);
         
          // Set the plot permissions to mirror the new owners.
          townBlock.setType(townBlock.getType());
          TownyUniverse.getDataSource().saveTownBlock(townBlock);
          TownyMessaging.sendMsg(player, String.format("9) %s", worldCoord.toString()));
          return true;
        }
      } catch (NotRegisteredException e) {
View Full Code Here

 
  public static boolean isOnEdgeOfOwnership(TownBlockOwner owner, WorldCoord worldCoord) {
        int[][] offset = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };
        for (int i = 0; i < 4; i++)
            try {
                TownBlock edgeTownBlock = worldCoord.getWorld().getTownBlock(new Coord(worldCoord.getX() + offset[i][0], worldCoord.getZ() + offset[i][1]));
                if (!edgeTownBlock.isOwner(owner)) {
                    return true;
                }
            } catch (NotRegisteredException e) {
              return true;
            }
View Full Code Here

  }

  private boolean residentUnclaim(WorldCoord worldCoord) throws TownyException {
   
    try {
      TownBlock townBlock = worldCoord.getTownBlock();

      townBlock.setResident(null);
      townBlock.setPlotPrice(townBlock.getTown().getPlotPrice());
     
      // Set the plot permissions to mirror the towns.
      townBlock.setType(townBlock.getType());
      TownyUniverse.getDataSource().saveTownBlock(townBlock);
     
      plugin.updateCache();
           
View Full Code Here

        continue;
     
      Coord coord = Coord.parseCoord(player);
      try {
        TownyWorld world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
        TownBlock townBlock = world.getTownBlock(coord);
         
        if (universe.isAlly(townBlock.getTown(), TownyUniverse.getDataSource().getResident(player.getName()).getTown()))
          if (!townBlock.getType().equals(TownBlockType.ARENA)) // only regen if not in an arena
            incHealth(player);
      } catch (TownyException x) {
      }
    }
   
View Full Code Here

       
        TownyWorld world = TownyUniverse.getDataSource().getWorld(cell.getWorldName());
        WorldCoord worldCoord = new WorldCoord(world, cell.getX(), cell.getZ());
        universe.removeWarZone(worldCoord);
       
        TownBlock townBlock = worldCoord.getTownBlock();
        TownyUniverse.getDataSource().removeTownBlock(townBlock);
       
        try {
          List<WorldCoord> selection = new ArrayList<WorldCoord>();
          selection.add(worldCoord);
View Full Code Here

            try {
              world.newTownBlock(x, z);
            } catch (AlreadyRegisteredException e) {
            }
            TownBlock townblock = world.getTownBlock(x, z);

            if (town != null)
              townblock.setTown(town);

            try {
              townblock.setResident(getResident(tokens[3]));
            } catch (NotRegisteredException e) {
            }
          } catch (NumberFormatException e) {
            e.printStackTrace();
          } catch (NotRegisteredException e) {
View Full Code Here

    Location locTo = blockTo.getLocation();
    Coord coord = Coord.parseCoord(loc);
    Coord coordTo = Coord.parseCoord(locTo);
   
    TownyWorld townyWorld = null;
    TownBlock CurrentTownBlock = null, destinationTownBlock = null;
   
    try {
      townyWorld = TownyUniverse.getDataSource().getWorld(loc.getWorld().getName());
      CurrentTownBlock = townyWorld.getTownBlock(coord);
    } catch (NotRegisteredException e) {
      //System.out.print("Failed to fetch TownBlock");
    }
   
    try {
      destinationTownBlock = townyWorld.getTownBlock(coordTo);
    } catch (NotRegisteredException e1) {
      //System.out.print("Failed to fetch TownBlockTo");
    }
   
    if (CurrentTownBlock != destinationTownBlock) {

      // Cancel if either is not null, but other is (wild to town).
      if ((CurrentTownBlock == null && destinationTownBlock != null)
      || (CurrentTownBlock != null && destinationTownBlock == null)) {
        //event.setCancelled(true);
        return true;
      }
     
      // If both blocks are owned by the town.
      if (!CurrentTownBlock.hasResident() && !destinationTownBlock.hasResident())
        return false;
     
      try {
        if ((!CurrentTownBlock.hasResident() && destinationTownBlock.hasResident())
            || (CurrentTownBlock.hasResident() && !destinationTownBlock.hasResident())
            || (CurrentTownBlock.getResident() != destinationTownBlock.getResident())
   
            || (CurrentTownBlock.getPlotPrice() != -1)
            || (destinationTownBlock.getPlotPrice() != -1)) {
          return true;
        }
      } catch (NotRegisteredException e) {
        // Failed to fetch a resident
View Full Code Here

            TownyMessaging.sendDebugMsg("onBlockIgnite: Canceled " + block.getTypeId() + " from igniting within "+coord.toString()+".");
            return true;
          }
        }
       
        TownBlock townBlock = townyWorld.getTownBlock(coord);
        if ((block.getRelative(BlockFace.DOWN).getType() != Material.OBSIDIAN && !townBlock.getTown().isFire() && !townyWorld.isForceFire() && !townBlock.getPermissions().fire)
            || (block.getRelative(BlockFace.DOWN).getType() != Material.OBSIDIAN && plugin.getTownyUniverse().isWarTime() && TownySettings.isAllowWarBlockGriefing() && !townBlock.getTown().hasNation())) {
          TownyMessaging.sendDebugMsg("onBlockIgnite: Canceled " + block.getTypeId() + " from igniting within "+coord.toString()+".");
          return true;
        }
      } catch (TownyException x) {
        // Not a town so check the world setting for fire
View Full Code Here

TOP

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

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.