use of com.palmergames.bukkit.towny.tasks.ProtectionRegenTask in project Towny by ElgarL.
the class TownyEntityListener method onEntityExplode.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent event) {
if (plugin.isError()) {
event.setCancelled(true);
return;
}
TownyWorld townyWorld;
/**
* Perform this test outside the block loop so we only get the world
* once per explosion.
*/
try {
townyWorld = TownyUniverse.getDataSource().getWorld(event.getLocation().getWorld().getName());
if (!townyWorld.isUsingTowny())
return;
} catch (NotRegisteredException e) {
// failed to get world so abort
return;
}
Coord coord;
List<Block> blocks = event.blockList();
Entity entity = event.getEntity();
int count = 0;
// Sort blocks by height (lowest to highest).
Collections.sort(blocks, ArraySort.getInstance());
for (Block block : blocks) {
coord = Coord.parseCoord(block.getLocation());
count++;
// Warzones
if (townyWorld.isWarZone(coord)) {
if (!TownyWarConfig.isAllowingExplosionsInWarZone()) {
if (event.getEntity() != null)
TownyMessaging.sendDebugMsg("onEntityExplode: Canceled " + event.getEntity().getEntityId() + " from exploding within " + coord.toString() + ".");
event.setCancelled(true);
return;
} else {
if (TownyWarConfig.explosionsBreakBlocksInWarZone()) {
if (TownyWarConfig.regenBlocksAfterExplosionInWarZone()) {
// ***********************************
// TODO
// On completion, remove TODO from config.yml
// comments.
/*
* if
* (!plugin.getTownyUniverse().hasProtectionRegenTask
* (new BlockLocation(block.getLocation()))) {
* ProtectionRegenTask task = new
* ProtectionRegenTask(plugin.getTownyUniverse(),
* block, false);
* task.setTaskId(plugin.getServer().getScheduler().
* scheduleSyncDelayedTask(plugin, task,
* ((TownySettings.getPlotManagementWildRegenDelay()
* + count)*20)));
* plugin.getTownyUniverse().addProtectionRegenTask
* (task ); }
*/
// TODO
// ***********************************
}
// Break the block
} else {
event.blockList().remove(block);
}
}
return;
}
// TODO: expand to protect neutrals during a war
try {
TownBlock townBlock = townyWorld.getTownBlock(coord);
// and the towns has no nation
if (townyWorld.isUsingTowny() && !townyWorld.isForceExpl()) {
if ((!townBlock.getPermissions().explosion) || (TownyUniverse.isWarTime() && TownySettings.isAllowWarBlockGriefing() && !townBlock.getTown().hasNation() && !townBlock.getTown().isBANG())) {
if (event.getEntity() != null)
TownyMessaging.sendDebugMsg("onEntityExplode: Canceled " + event.getEntity().getEntityId() + " from exploding within " + coord.toString() + ".");
event.setCancelled(true);
return;
}
}
} catch (TownyException x) {
// Wilderness explosion regeneration
if (townyWorld.isUsingTowny())
if (townyWorld.isExpl()) {
if (townyWorld.isUsingPlotManagementWildRevert() && (entity != null)) {
TownyMessaging.sendDebugMsg("onEntityExplode: Testing entity: " + entity.getType().getEntityClass().getSimpleName().toLowerCase() + " @ " + coord.toString() + ".");
if (townyWorld.isProtectingExplosionEntity(entity)) {
if ((!TownyRegenAPI.hasProtectionRegenTask(new BlockLocation(block.getLocation()))) && (block.getType() != Material.TNT)) {
ProtectionRegenTask task = new ProtectionRegenTask(plugin, block, false);
task.setTaskId(plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, task, ((TownySettings.getPlotManagementWildRegenDelay() + count) * 20)));
TownyRegenAPI.addProtectionRegenTask(task);
event.setYield((float) 0.0);
block.getDrops().clear();
}
}
}
} else {
event.setCancelled(true);
return;
}
}
}
}
use of com.palmergames.bukkit.towny.tasks.ProtectionRegenTask in project Towny by ElgarL.
the class TownyRegenAPI method cancelProtectionRegenTasks.
/**
* Cancel all regenerating tasks and clear all queues.
*/
public static void cancelProtectionRegenTasks() {
for (ProtectionRegenTask task : protectionRegenTasks.values()) {
BukkitTools.getServer().getScheduler().cancelTask(task.getTaskId());
task.replaceProtections();
}
protectionRegenTasks.clear();
protectionPlaceholders.clear();
}
use of com.palmergames.bukkit.towny.tasks.ProtectionRegenTask in project Towny by ElgarL.
the class TownyBlockListener method onBlockBreak.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
if (plugin.isError()) {
event.setCancelled(true);
return;
}
Player player = event.getPlayer();
Block block = event.getBlock();
//Get build permissions (updates cache if none exist)
boolean bDestroy = PlayerCacheUtil.getCachePermission(player, block.getLocation(), BukkitTools.getTypeId(block), BukkitTools.getData(block), TownyPermission.ActionType.DESTROY);
// Allow destroy if we are permitted
if (bDestroy)
return;
/*
* Fetch the players cache
*/
PlayerCache cache = plugin.getCache(player);
/*
* Allow destroy in a WarZone (FlagWar) if it's an editable material.
*/
if (cache.getStatus() == TownBlockStatus.WARZONE) {
if (!TownyWarConfig.isEditableMaterialInWarZone(block.getType())) {
event.setCancelled(true);
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_warzone_cannot_edit_material"), "destroy", block.getType().toString().toLowerCase()));
}
return;
}
/*
* Queue a protectionRegenTask if we have delayed regeneration set
*/
long delay = TownySettings.getRegenDelay();
if (delay > 0) {
if (!TownyRegenAPI.isPlaceholder(block)) {
if (!TownyRegenAPI.hasProtectionRegenTask(new BlockLocation(block.getLocation()))) {
ProtectionRegenTask task = new ProtectionRegenTask(plugin, block, true);
task.setTaskId(plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, task, 20 * delay));
TownyRegenAPI.addProtectionRegenTask(task);
}
} else {
TownyRegenAPI.removePlaceholder(block);
BukkitTools.setTypeId(block, 0, false);
}
} else {
event.setCancelled(true);
}
/*
* display any error recorded for this plot
*/
if ((cache.hasBlockErrMsg()) && (event.isCancelled()))
TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg());
}
Aggregations