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());
}
}
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"));
}
}
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;
}
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;
}
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;
}
Aggregations