Search in sources :

Example 21 with TownBlock

use of com.palmergames.bukkit.towny.object.TownBlock in project Towny by ElgarL.

the class TownyRegenAPI method deleteTownBlockMaterial.

/**
	 * Deletes all of a specified block type from a TownBlock
	 * 
	 * @param townBlock
	 * @param material
	 */
public static void deleteTownBlockMaterial(TownBlock townBlock, Material material) {
    //Block block = null;
    int plotSize = TownySettings.getTownBlockSize();
    TownyMessaging.sendDebugMsg("Processing deleteTownBlockMaterial");
    World world = BukkitTools.getServer().getWorld(townBlock.getWorld().getName());
    if (world != null) {
        /*
			 * if
			 * (!world.isChunkLoaded(MinecraftTools.calcChunk(townBlock.getX()),
			 * MinecraftTools.calcChunk(townBlock.getZ())))
			 * return;
			 */
        int height = world.getMaxHeight() - 1;
        int worldx = townBlock.getX() * plotSize, worldz = townBlock.getZ() * plotSize;
        for (int z = 0; z < plotSize; z++) for (int x = 0; x < plotSize; x++) for (int y = height; y > 0; y--) {
            //Check from bottom up else minecraft won't remove doors
            Block block = world.getBlockAt(worldx + x, y, worldz + z);
            if (block.getType() == material) {
                block.setType(Material.AIR);
            }
            block = null;
        }
    }
}
Also used : Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) World(org.bukkit.World)

Example 22 with TownBlock

use of com.palmergames.bukkit.towny.object.TownBlock in project Towny by ElgarL.

the class TownyRegenAPI method doDeleteTownBlockIds.

/**
	 * Deletes all of a specified block type from a TownBlock
	 * 
	 * @param worldCoord
	 */
public static void doDeleteTownBlockIds(WorldCoord worldCoord) {
    //Block block = null;
    World world = null;
    int plotSize = TownySettings.getTownBlockSize();
    TownyMessaging.sendDebugMsg("Processing deleteTownBlockIds");
    world = worldCoord.getBukkitWorld();
    if (world != null) {
        /*
			 * if
			 * (!world.isChunkLoaded(MinecraftTools.calcChunk(townBlock.getX()),
			 * MinecraftTools.calcChunk(townBlock.getZ())))
			 * return;
			 */
        int height = world.getMaxHeight() - 1;
        int worldx = worldCoord.getX() * plotSize, worldz = worldCoord.getZ() * plotSize;
        for (int z = 0; z < plotSize; z++) for (int x = 0; x < plotSize; x++) for (int y = height; y > 0; y--) {
            //Check from bottom up else minecraft won't remove doors
            Block block = world.getBlockAt(worldx + x, y, worldz + z);
            try {
                if (worldCoord.getTownyWorld().isPlotManagementDeleteIds(block.getType().name())) {
                    block.setType(Material.AIR);
                }
            } catch (NotRegisteredException e) {
            // Not a registered world
            }
            block = null;
        }
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) World(org.bukkit.World)

Example 23 with TownBlock

use of com.palmergames.bukkit.towny.object.TownBlock in project Towny by ElgarL.

the class HealthRegenTimerTask method run.

@Override
public void run() {
    if (TownyUniverse.isWarTime())
        return;
    for (Player player : server.getOnlinePlayers()) {
        if (player.getHealth() <= 0)
            continue;
        Coord coord = Coord.parseCoord(player);
        try {
            TownyWorld world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
            TownBlock townBlock = world.getTownBlock(coord);
            if (CombatUtil.isAlly(townBlock.getTown(), TownyUniverse.getDataSource().getResident(player.getName()).getTown()))
                if (// only regen if not in an arena
                !townBlock.getType().equals(TownBlockType.ARENA))
                    incHealth(player);
        } catch (TownyException x) {
        }
    }
//if (TownySettings.getDebug())
//	System.out.println("[Towny] Debug: Health Regen");
}
Also used : Coord(com.palmergames.bukkit.towny.object.Coord) Player(org.bukkit.entity.Player) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 24 with TownBlock

use of com.palmergames.bukkit.towny.object.TownBlock in project Towny by ElgarL.

the class TownyHModFlatFileSource method loadWorlds.

@Override
public boolean loadWorlds() {
    System.out.println("[Towny] [hMod Conversion] Town Blocks");
    String line;
    String[] tokens;
    //Default world is the first one loaded
    TownyWorld world = getWorlds().toArray(new TownyWorld[0])[0];
    try {
        BufferedReader fin = new BufferedReader(new FileReader(rootFolder + dataFolder + "/townblocks.csv"));
        while ((line = fin.readLine()) != null) {
            tokens = line.split(",");
            if (tokens.length >= 4)
                try {
                    Town town = getTown(tokens[2]);
                    int x = Integer.parseInt(tokens[0]);
                    int z = Integer.parseInt(tokens[1]);
                    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) {
                    e.printStackTrace();
                }
        }
        fin.close();
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) IOException(java.io.IOException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)

Example 25 with TownBlock

use of com.palmergames.bukkit.towny.object.TownBlock in project Towny by ElgarL.

the class PlotClaim method residentClaim.

private boolean residentClaim(WorldCoord worldCoord) throws TownyException, EconomyException {
    //if (resident.hasTown())
    try {
        TownBlock townBlock = worldCoord.getTownBlock();
        Town town = townBlock.getTown();
        if ((resident.hasTown() && (resident.getTown() != town) && (!townBlock.getType().equals(TownBlockType.EMBASSY))) || ((!resident.hasTown()) && (!townBlock.getType().equals(TownBlockType.EMBASSY))))
            throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));
        try {
            Resident owner = townBlock.getResident();
            if (townBlock.getPlotPrice() != -1) {
                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);
                // Update any caches for this WorldCoord
                plugin.updateCache(worldCoord);
                return true;
            } else if (player.hasPermission(PermissionNodes.TOWNY_COMMAND_PLOT_ASMAYOR.getNode())) {
                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);
                // Update the townBlock data file so it's no longer using custom settings.
                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) {
            if (townBlock.getPlotPrice() == -1)
                throw new TownyException(TownySettings.getLangString("msg_err_plot_nfs"));
            double bankcap = TownySettings.getTownBankCap();
            if (bankcap > 0) {
                if (townBlock.getPlotPrice() + town.getHoldingBalance() > bankcap)
                    throw new TownyException(String.format(TownySettings.getLangString("msg_err_deposit_capped"), bankcap));
            }
            if (TownySettings.isUsingEconomy() && !resident.payTo(townBlock.getPlotPrice(), town, "Plot - Buy From Town"))
                throw new TownyException(TownySettings.getLangString("msg_no_money_purchase_plot"));
            townBlock.setPlotPrice(-1);
            townBlock.setResident(resident);
            // Set the plot permissions to mirror the new owners.
            townBlock.setType(townBlock.getType());
            TownyUniverse.getDataSource().saveTownBlock(townBlock);
            return true;
        }
    } catch (NotRegisteredException e) {
        throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));
    }
//else
//	throw new TownyException(TownySettings.getLangString("msg_err_not_in_town_claim"));
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Town(com.palmergames.bukkit.towny.object.Town) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) Resident(com.palmergames.bukkit.towny.object.Resident) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Aggregations

TownBlock (com.palmergames.bukkit.towny.object.TownBlock)34 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)28 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)16 TownyWorld (com.palmergames.bukkit.towny.object.TownyWorld)12 Resident (com.palmergames.bukkit.towny.object.Resident)11 Town (com.palmergames.bukkit.towny.object.Town)8 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)7 Coord (com.palmergames.bukkit.towny.object.Coord)7 WorldCoord (com.palmergames.bukkit.towny.object.WorldCoord)7 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)5 Location (org.bukkit.Location)5 BlockLocation (com.palmergames.bukkit.towny.regen.block.BlockLocation)4 World (org.bukkit.World)4 Block (org.bukkit.block.Block)4 Nation (com.palmergames.bukkit.towny.object.Nation)3 EventHandler (org.bukkit.event.EventHandler)3 EconomyException (com.palmergames.bukkit.towny.exceptions.EconomyException)2 KeyValueFile (com.palmergames.util.KeyValueFile)2 EOFException (java.io.EOFException)2