Search in sources :

Example 26 with TownBlock

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

the class RepeatingTimerTask method run.

@Override
public void run() {
    // Perform a single block regen in each regen area, if any are left to do.
    if (TownyRegenAPI.hasPlotChunks()) {
        // only execute if the correct amount of time has passed.
        if (Math.max(1L, TownySettings.getPlotManagementSpeed()) >= ++timerCounter) {
            for (PlotBlockData plotChunk : new ArrayList<PlotBlockData>(TownyRegenAPI.getPlotChunks().values())) {
                if (!plotChunk.restoreNextBlock()) {
                    TownyRegenAPI.deletePlotChunk(plotChunk);
                    TownyRegenAPI.deletePlotChunkSnapshot(plotChunk);
                }
            }
            timerCounter = 0L;
        }
    }
    // Take a snapshot of the next townBlock and save.
    if (TownyRegenAPI.hasWorldCoords()) {
        try {
            TownBlock townBlock = TownyRegenAPI.getWorldCoord().getTownBlock();
            PlotBlockData plotChunk = new PlotBlockData(townBlock);
            // Create a new snapshot.
            plotChunk.initialize();
            if (!plotChunk.getBlockList().isEmpty() && !(plotChunk.getBlockList() == null))
                // Save the snapshot.
                TownyRegenAPI.addPlotChunkSnapshot(plotChunk);
            plotChunk = null;
            townBlock.setLocked(false);
            TownyUniverse.getDataSource().saveTownBlock(townBlock);
            plugin.updateCache(townBlock.getWorldCoord());
            if (!TownyRegenAPI.hasWorldCoords())
                TownyLogger.log.info("Plot snapshots completed.");
        } catch (NotRegisteredException e) {
        // Not a townblock so ignore.
        }
    }
    // Perform the next plot_management block_delete
    if (TownyRegenAPI.hasDeleteTownBlockIdQueue()) {
        TownyRegenAPI.doDeleteTownBlockIds(TownyRegenAPI.getDeleteTownBlockIdQueue());
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) ArrayList(java.util.ArrayList) PlotBlockData(com.palmergames.bukkit.towny.regen.PlotBlockData) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

Example 27 with TownBlock

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

the class TownClaim method townUnclaim.

private void townUnclaim(final Town town, final WorldCoord worldCoord, boolean force) throws TownyException {
    try {
        final TownBlock townBlock = worldCoord.getTownBlock();
        if (town != townBlock.getTown() && !force)
            throw new TownyException(TownySettings.getLangString("msg_area_not_own"));
        Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

            @Override
            public void run() {
                TownyUniverse.getDataSource().removeTownBlock(townBlock);
                // Raise an event to signal the unclaim
                BukkitTools.getPluginManager().callEvent(new TownUnclaimEvent(town, worldCoord));
            }
        }, 1);
    } catch (NotRegisteredException e) {
        throw new TownyException(TownySettings.getLangString("msg_not_claimed_1"));
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) TownUnclaimEvent(com.palmergames.bukkit.towny.event.TownUnclaimEvent) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 28 with TownBlock

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

the class TownyBlockListener method onBurn.

private boolean onBurn(Block block) {
    Location loc = block.getLocation();
    Coord coord = Coord.parseCoord(loc);
    TownyWorld townyWorld;
    try {
        townyWorld = TownyUniverse.getDataSource().getWorld(loc.getWorld().getName());
        if (!townyWorld.isUsingTowny())
            return false;
        try {
            if (townyWorld.isWarZone(coord)) {
                if (TownyWarConfig.isAllowingFireInWarZone()) {
                    return false;
                } else {
                    TownyMessaging.sendDebugMsg("onBlockIgnite: Canceled " + block.getType().name() + " 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) || (TownyUniverse.isWarTime() && TownySettings.isAllowWarBlockGriefing() && !townBlock.getTown().hasNation()))) {
                TownyMessaging.sendDebugMsg("onBlockIgnite: Canceled " + block.getType().name() + " from igniting within " + coord.toString() + ".");
                return true;
            }
        } catch (TownyException x) {
            // Not a town so check the world setting for fire
            if (!townyWorld.isFire()) {
                TownyMessaging.sendDebugMsg("onBlockIgnite: Canceled " + block.getType().name() + " from igniting within " + coord.toString() + ".");
                return true;
            }
        }
    } catch (NotRegisteredException e) {
    // Failed to fetch the world
    }
    return false;
}
Also used : WorldCoord(com.palmergames.bukkit.towny.object.WorldCoord) Coord(com.palmergames.bukkit.towny.object.Coord) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) Location(org.bukkit.Location) BlockLocation(com.palmergames.bukkit.towny.regen.block.BlockLocation) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 29 with TownBlock

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

the class TownyFlatFileSource method saveTownBlockList.

/*
	 * Save keys
	 */
@Override
public boolean saveTownBlockList() {
    List<String> list = new ArrayList<String>();
    for (TownBlock townBlock : getAllTownBlocks()) {
        list.add(townBlock.getWorld().getName() + "," + townBlock.getX() + "," + townBlock.getZ());
    }
    /*
		 *  Make sure we only save in async
		 */
    this.queryQueue.add(new FlatFile_Task(list, rootFolder + dataFolder + FileMgmt.fileSeparator() + "townblocks.txt"));
    return true;
}
Also used : ArrayList(java.util.ArrayList) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

Example 30 with TownBlock

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

the class TownyFlatFileSource method loadTownBlocks.

@Override
public boolean loadTownBlocks() {
    String line = "";
    String path;
    for (TownBlock townBlock : getAllTownBlocks()) {
        path = getTownBlockFilename(townBlock);
        //boolean set = false;
        File fileTownBlock = new File(path);
        if (fileTownBlock.exists() && fileTownBlock.isFile()) {
            try {
                KeyValueFile kvFile = new KeyValueFile(path);
                line = kvFile.get("name");
                if (line != null)
                    try {
                        townBlock.setName(line.trim());
                    } catch (Exception e) {
                    }
                line = kvFile.getString("price");
                if (line != null)
                    try {
                        townBlock.setPlotPrice(Double.parseDouble(line.trim()));
                    } catch (Exception e) {
                    }
                line = kvFile.getString("town");
                if (line != null)
                    try {
                        Town town = getTown(line.trim());
                        townBlock.setTown(town);
                    } catch (Exception e) {
                    }
                line = kvFile.getString("resident");
                if (line != null && !line.isEmpty())
                    try {
                        Resident res = getResident(line.trim());
                        townBlock.setResident(res);
                    } catch (Exception e) {
                    }
                line = kvFile.getString("type");
                if (line != null)
                    try {
                        townBlock.setType(Integer.parseInt(line));
                    } catch (Exception e) {
                    }
                line = kvFile.getString("outpost");
                if (line != null)
                    try {
                        townBlock.setOutpost(Boolean.parseBoolean(line));
                    } catch (Exception e) {
                    }
                line = kvFile.get("permissions");
                if ((line != null) && !line.isEmpty())
                    try {
                        townBlock.setPermissions(line.trim());
                    //set = true;
                    } catch (Exception e) {
                    }
                line = kvFile.get("changed");
                if (line != null)
                    try {
                        townBlock.setChanged(Boolean.parseBoolean(line.trim()));
                    } catch (Exception e) {
                    }
                line = kvFile.get("locked");
                if (line != null)
                    try {
                        townBlock.setLocked(Boolean.parseBoolean(line.trim()));
                    } catch (Exception e) {
                    }
            } catch (Exception e) {
                TownyMessaging.sendErrorMsg("Loading Error: Exception while reading TownBlock file " + path);
                return false;
            }
        //				if (!set) {
        //					// no permissions found so set in relation to it's owners perms.
        //					try {
        //						if (townBlock.hasResident()) {
        //							townBlock.setPermissions(townBlock.getResident().getPermissions().toString());
        //						} else {
        //							townBlock.setPermissions(townBlock.getTown().getPermissions().toString());
        //						}
        //					} catch (NotRegisteredException e) {
        //						// Will never reach here
        //					}
        //				}
        }
    }
    return true;
}
Also used : Town(com.palmergames.bukkit.towny.object.Town) Resident(com.palmergames.bukkit.towny.object.Resident) KeyValueFile(com.palmergames.util.KeyValueFile) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) File(java.io.File) KeyValueFile(com.palmergames.util.KeyValueFile) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) IOException(java.io.IOException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) AlreadyRegisteredException(com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException) InvalidNameException(javax.naming.InvalidNameException) 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