Destroy fire blocks when fire-spread is disallowed

This commit is contained in:
zml2008 2012-03-08 19:02:09 -08:00
parent 0bcf4b3597
commit 1463547af4

View File

@ -24,6 +24,7 @@
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -59,7 +60,7 @@
/** /**
* The listener for block events. * The listener for block events.
* *
* @author sk89q * @author sk89q
*/ */
public class WorldGuardBlockListener implements Listener { public class WorldGuardBlockListener implements Listener {
@ -68,7 +69,7 @@ public class WorldGuardBlockListener implements Listener {
/** /**
* Construct the object. * Construct the object.
* *
* @param plugin The plugin instance * @param plugin The plugin instance
*/ */
public WorldGuardBlockListener(WorldGuardPlugin plugin) { public WorldGuardBlockListener(WorldGuardPlugin plugin) {
@ -84,7 +85,7 @@ public void registerEvents() {
/** /**
* Get the world configuration given a world. * Get the world configuration given a world.
* *
* @param world The world to get the configuration for. * @param world The world to get the configuration for.
* @return The configuration for {@code world} * @return The configuration for {@code world}
*/ */
@ -94,7 +95,7 @@ protected WorldConfiguration getWorldConfig(World world) {
/** /**
* Get the world configuration given a player. * Get the world configuration given a player.
* *
* @param player The player to get the wold from * @param player The player to get the wold from
* @return The {@link WorldConfiguration} for the player's world * @return The {@link WorldConfiguration} for the player's world
*/ */
@ -124,7 +125,7 @@ public void onBlockDamage(BlockDamageEvent event) {
} }
} }
} }
/* /*
* Called when a block is broken. * Called when a block is broken.
*/ */
@ -171,7 +172,7 @@ public void onBlockBreak(BlockBreakEvent event) {
return; return;
} }
} }
if (wcfg.isChestProtected(event.getBlock(), player)) { if (wcfg.isChestProtected(event.getBlock(), player)) {
player.sendMessage(ChatColor.DARK_RED + "The chest is protected."); player.sendMessage(ChatColor.DARK_RED + "The chest is protected.");
event.setCancelled(true); event.setCancelled(true);
@ -238,7 +239,7 @@ public void onBlockFromTo(BlockFromToEvent event) {
// If so and the target block is protected, cancel the event // If so and the target block is protected, cancel the event
if (wcfg.preventWaterDamage.size() > 0) { if (wcfg.preventWaterDamage.size() > 0) {
int targetId = blockTo.getTypeId(); int targetId = blockTo.getTypeId();
if ((isAir || isWater) && if ((isAir || isWater) &&
wcfg.preventWaterDamage.contains(targetId)) { wcfg.preventWaterDamage.contains(targetId)) {
event.setCancelled(true); event.setCancelled(true);
@ -248,7 +249,7 @@ public void onBlockFromTo(BlockFromToEvent event) {
if (wcfg.allowedLavaSpreadOver.size() > 0 && isLava) { if (wcfg.allowedLavaSpreadOver.size() > 0 && isLava) {
int targetId = blockTo.getRelative(0, -1, 0).getTypeId(); int targetId = blockTo.getRelative(0, -1, 0).getTypeId();
if (!wcfg.allowedLavaSpreadOver.contains(targetId)) { if (!wcfg.allowedLavaSpreadOver.contains(targetId)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
@ -296,7 +297,6 @@ public void onBlockIgnite(BlockIgniteEvent event) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
boolean isFireSpread = cause == IgniteCause.SPREAD; boolean isFireSpread = cause == IgniteCause.SPREAD;
if (wcfg.preventLightningFire && cause == IgniteCause.LIGHTNING) { if (wcfg.preventLightningFire && cause == IgniteCause.LIGHTNING) {
@ -402,7 +402,9 @@ public void onBlockBurn(BlockBurnEvent event) {
} }
if (wcfg.fireSpreadDisableToggle) { if (wcfg.fireSpreadDisableToggle) {
Block block = event.getBlock();
event.setCancelled(true); event.setCancelled(true);
checkAndDestroyAround(block.getWorld(), block.getX(), block.getY(), block.getZ(), BlockID.FIRE);
return; return;
} }
@ -411,6 +413,7 @@ public void onBlockBurn(BlockBurnEvent event) {
if (wcfg.disableFireSpreadBlocks.contains(block.getTypeId())) { if (wcfg.disableFireSpreadBlocks.contains(block.getTypeId())) {
event.setCancelled(true); event.setCancelled(true);
checkAndDestroyAround(block.getWorld(), block.getX(), block.getY(), block.getZ(), BlockID.FIRE);
return; return;
} }
} }
@ -419,14 +422,18 @@ public void onBlockBurn(BlockBurnEvent event) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (wcfg.useRegions) { if (wcfg.useRegions) {
Block block = event.getBlock(); Block block = event.getBlock();
int x = block.getX();
int y = block.getY();
int z = block.getZ();
Vector pt = toVector(block); Vector pt = toVector(block);
RegionManager mgr = plugin.getGlobalRegionManager().get(block.getWorld()); RegionManager mgr = plugin.getGlobalRegionManager().get(block.getWorld());
ApplicableRegionSet set = mgr.getApplicableRegions(pt); ApplicableRegionSet set = mgr.getApplicableRegions(pt);
if (!set.allows(DefaultFlag.FIRE_SPREAD)) { if (!set.allows(DefaultFlag.FIRE_SPREAD)) {
checkAndDestroyAround(block.getWorld(), x, y, z, BlockID.FIRE);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -434,6 +441,21 @@ public void onBlockBurn(BlockBurnEvent event) {
} }
} }
private void checkAndDestroyAround(World world, int x, int y, int z, int required) {
checkAndDestroy(world, x, y, z + 1, required);
checkAndDestroy(world, x, y, z - 1, required);
checkAndDestroy(world, x, y + 1, z, required);
checkAndDestroy(world, x, y - 1, z, required);
checkAndDestroy(world, x + 1, y, z, required);
checkAndDestroy(world, x - 1, y, z, required);
}
private void checkAndDestroy(World world, int x, int y, int z, int required) {
if (world.getBlockTypeIdAt(x, y, z) == required) {
world.getBlockAt(x, y, z).setTypeId(BlockID.AIR);
}
}
/* /*
* Called when block physics occurs. * Called when block physics occurs.
*/ */
@ -505,7 +527,7 @@ public void onBlockPlace(BlockPlaceEvent event) {
return; return;
} }
} }
if (wcfg.signChestProtection && wcfg.getChestProtection().isChest(blockPlaced.getTypeId())) { if (wcfg.signChestProtection && wcfg.getChestProtection().isChest(blockPlaced.getTypeId())) {
if (wcfg.isAdjacentChestProtected(event.getBlock(), player)) { if (wcfg.isAdjacentChestProtected(event.getBlock(), player)) {
player.sendMessage(ChatColor.DARK_RED + "This spot is for a chest that you don't have permission for."); player.sendMessage(ChatColor.DARK_RED + "This spot is for a chest that you don't have permission for.");
@ -571,7 +593,7 @@ public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
WorldConfiguration wcfg = getWorldConfig(player); WorldConfiguration wcfg = getWorldConfig(player);
if (wcfg.signChestProtection) { if (wcfg.signChestProtection) {
if (event.getLine(0).equalsIgnoreCase("[Lock]")) { if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
if (wcfg.isChestProtectedPlacement(event.getBlock(), player)) { if (wcfg.isChestProtectedPlacement(event.getBlock(), player)) {
@ -580,7 +602,7 @@ public void onSignChange(SignChangeEvent event) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (event.getBlock().getTypeId() != BlockID.SIGN_POST) { if (event.getBlock().getTypeId() != BlockID.SIGN_POST) {
player.sendMessage(ChatColor.RED player.sendMessage(ChatColor.RED
+ "The [Lock] sign must be a sign post, not a wall sign."); + "The [Lock] sign must be a sign post, not a wall sign.");
@ -598,7 +620,7 @@ public void onSignChange(SignChangeEvent event) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
int below = event.getBlock().getRelative(0, -1, 0).getTypeId(); int below = event.getBlock().getRelative(0, -1, 0).getTypeId();
if (below == BlockID.TNT || below == BlockID.SAND if (below == BlockID.TNT || below == BlockID.SAND
@ -610,7 +632,7 @@ public void onSignChange(SignChangeEvent event) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
event.setLine(0, "[Lock]"); event.setLine(0, "[Lock]");
player.sendMessage(ChatColor.YELLOW player.sendMessage(ChatColor.YELLOW
+ "A chest or double chest above is now protected."); + "A chest or double chest above is now protected.");