fixed worldguard.notify and worldguard.bypass permissions, optimized getApplicableRegionSet() calls

This commit is contained in:
Redecouverte 2011-02-27 19:31:49 +01:00
parent 162cd20f80
commit dcef083e30
5 changed files with 234 additions and 196 deletions

View File

@ -41,6 +41,8 @@ worldguard.region.setparent.all
worldguard.region.priority.own
worldguard.region.priority.all
worldguard.region.bypass
worldguard.reloadwg
worldguard.region.delete.own
@ -56,3 +58,5 @@ worldguard.tpregion.override
worldguard.buyregion
worldguard.notify

View File

@ -32,7 +32,7 @@ public BukkitBlacklist(Boolean useAsWhitelist, WorldGuardPlugin plugin) {
public void broadcastNotification(String msg) {
for (Player player : plugin.getServer().getOnlinePlayers()) {
if (plugin.getWgConfiguration().hasPermission(player, "/worldguardnotify")) {
if (plugin.getWgConfiguration().hasPermission(player, "notify")) {
player.sendMessage(msg);
}
}

View File

@ -15,8 +15,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
package com.sk89q.worldguard.bukkit;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
@ -44,7 +43,7 @@ public class WorldGuardBlockListener extends BlockListener {
* Plugin.
*/
private WorldGuardPlugin plugin;
/**
* Construct the object;
*
@ -105,7 +104,7 @@ public void onBlockBreak(BlockBreakEvent event) {
player.setItemInHand(held);
}
}
if (wcfg.useRegions) {
Vector pt = BukkitUtil.toVector(event.getBlock());
@ -115,20 +114,20 @@ public void onBlockBreak(BlockBreakEvent event) {
return;
}
}
if (wcfg.getBlacklist() != null) {
if (!wcfg.getBlacklist().check(
new BlockBreakBlacklistEvent(BukkitPlayer.wrapPlayer(cfg, player),
toVector(event.getBlock()),
event.getBlock().getTypeId()), false, false)) {
toVector(event.getBlock()),
event.getBlock().getTypeId()), false, false)) {
event.setCancelled(true);
return;
}
if (wcfg.getBlacklist().check(
new DestroyWithBlacklistEvent(BukkitPlayer.wrapPlayer(cfg, player),
toVector(event.getBlock()),
player.getItemInHand().getTypeId()), false, false)) {
toVector(event.getBlock()),
player.getItemInHand().getTypeId()), false, false)) {
event.setCancelled(true);
return;
}
@ -143,15 +142,14 @@ public void onBlockBreak(BlockBreakEvent event) {
@Override
public void onBlockFlow(BlockFromToEvent event) {
if(event.isCancelled())
{
if (event.isCancelled()) {
return;
}
World world = event.getBlock().getWorld();
Block blockFrom = event.getBlock();
Block blockTo = event.getToBlock();
boolean isWater = blockFrom.getTypeId() == 8 || blockFrom.getTypeId() == 9;
boolean isLava = blockFrom.getTypeId() == 10 || blockFrom.getTypeId() == 11;
@ -178,18 +176,18 @@ public void onBlockFlow(BlockFromToEvent event) {
}
/*if (plugin.classicWater && isWater) {
int blockBelow = blockFrom.getRelative(0, -1, 0).getTypeId();
if (blockBelow != 0 && blockBelow != 8 && blockBelow != 9) {
blockFrom.setTypeId(9);
if (blockTo.getTypeId() == 0) {
blockTo.setTypeId(9);
}
return;
}
int blockBelow = blockFrom.getRelative(0, -1, 0).getTypeId();
if (blockBelow != 0 && blockBelow != 8 && blockBelow != 9) {
blockFrom.setTypeId(9);
if (blockTo.getTypeId() == 0) {
blockTo.setTypeId(9);
}
return;
}
}*/
// Check the fluid block (from) whether it is air. If so and the target block is protected, cancel the event
if(wcfg.preventWaterDamage.size() > 0 && blockFrom.getTypeId() == 0) {
if (wcfg.preventWaterDamage.size() > 0 && blockFrom.getTypeId() == 0) {
int targetId = world.getBlockTypeIdAt(
blockTo.getX(), blockTo.getY(), blockTo.getZ());
if (wcfg.preventWaterDamage.contains(targetId)) {
@ -197,7 +195,7 @@ public void onBlockFlow(BlockFromToEvent event) {
return;
}
}
if (wcfg.preventWaterDamage.size() > 0 && isWater) {
int targetId = world.getBlockTypeIdAt(
blockTo.getX(), blockTo.getY(), blockTo.getZ());
@ -220,8 +218,7 @@ public void onBlockFlow(BlockFromToEvent event) {
Vector pt = toVector(blockFrom.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(world.getName());
if (!mgr.getApplicableRegions(pt)
.allowsFlag("waterflow")) {
if (!mgr.getApplicableRegions(pt).allowsFlag("waterflow")) {
event.setCancelled(true);
return;
}
@ -236,11 +233,11 @@ public void onBlockFlow(BlockFromToEvent event) {
@Override
public void onBlockIgnite(BlockIgniteEvent event) {
if(event.isCancelled())
{
if (event.isCancelled()) {
return;
}
IgniteCause cause = event.getCause();
Block block = event.getBlock();
World world = block.getWorld();
@ -249,7 +246,41 @@ public void onBlockIgnite(BlockIgniteEvent event) {
WorldGuardWorldConfiguration wcfg = cfg.getWorldConfig(world.getName());
boolean isFireSpread = cause == IgniteCause.SPREAD;
if (wcfg.useRegions) {
Vector pt = toVector(block);
Player player = event.getPlayer();
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(world.getName());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
if (player != null && !cfg.hasPermission(player, "region.bypass")) {
LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(cfg, player);
if (cause == IgniteCause.FLINT_AND_STEEL
&& !set.canBuild(localPlayer)) {
event.setCancelled(true);
return;
}
if (cause == IgniteCause.FLINT_AND_STEEL
&& !set.allowsFlag(AreaFlags.FLAG_LIGHTER)) {
event.setCancelled(true);
return;
}
}
if (isFireSpread && set.allowsFlag(AreaFlags.FLAG_FIRE_SPREAD)) {
event.setCancelled(true);
return;
}
if (cause == IgniteCause.LAVA && !set.allowsFlag(AreaFlags.FLAG_LAVA_FIRE)) {
event.setCancelled(true);
return;
}
}
if (wcfg.preventLavaFire && cause == IgniteCause.LAVA) {
event.setCancelled(true);
return;
@ -259,7 +290,7 @@ public void onBlockIgnite(BlockIgniteEvent event) {
event.setCancelled(true);
return;
}
if (wcfg.blockLighter && cause == IgniteCause.FLINT_AND_STEEL) {
event.setCancelled(true);
return;
@ -274,7 +305,7 @@ public void onBlockIgnite(BlockIgniteEvent event) {
int x = block.getX();
int y = block.getY();
int z = block.getZ();
if (wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x, y - 1, z))
|| wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x + 1, y, z))
|| wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x - 1, y, z))
@ -284,39 +315,7 @@ public void onBlockIgnite(BlockIgniteEvent event) {
return;
}
}
/*if (plugin.useRegions) {
Vector pt = toVector(block);
if (player != null && !plugin.hasPermission(player, "/regionbypass")) {
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (cause == IgniteCause.FLINT_AND_STEEL
&& !plugin.globalRegionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
event.setCancelled(true);
return;
}
if (cause == IgniteCause.FLINT_AND_STEEL
&& !plugin.globalRegionManager.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_LIGHTER)) {
event.setCancelled(true);
return;
}
}
f (isFireSpread && !plugin.globalRegionManager.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_FIRE_SPREAD)) {
event.setCancelled(true);
return;
}
if (cause == IgniteCause.LAVA && !plugin.globalRegionManager.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_LAVA_FIRE)) {
event.setCancelled(true);
return;
}
}*/
}
/**
@ -327,8 +326,7 @@ public void onBlockIgnite(BlockIgniteEvent event) {
@Override
public void onBlockBurn(BlockBurnEvent event) {
if(event.isCancelled())
{
if (event.isCancelled()) {
return;
}
@ -363,8 +361,7 @@ public void onBlockBurn(BlockBurnEvent event) {
@Override
public void onBlockPhysics(BlockPhysicsEvent event) {
if(event.isCancelled())
{
if (event.isCancelled()) {
return;
}
@ -388,7 +385,7 @@ public void onBlockPhysics(BlockPhysicsEvent event) {
return;
}
}
/**
* Called when a block is interacted with
*
@ -397,8 +394,7 @@ public void onBlockPhysics(BlockPhysicsEvent event) {
@Override
public void onBlockInteract(BlockInteractEvent event) {
if(event.isCancelled())
{
if (event.isCancelled()) {
return;
}
@ -410,32 +406,33 @@ public void onBlockInteract(BlockInteractEvent event) {
if (entity instanceof Player
&& (block.getType() == Material.CHEST
|| block.getType() == Material.DISPENSER
|| block.getType() == Material.FURNACE
|| block.getType() == Material.BURNING_FURNACE
|| block.getType() == Material.NOTE_BLOCK)) {
Player player = (Player)entity;
|| block.getType() == Material.DISPENSER
|| block.getType() == Material.FURNACE
|| block.getType() == Material.BURNING_FURNACE
|| block.getType() == Material.NOTE_BLOCK)) {
Player player = (Player) entity;
if (wcfg.useRegions) {
Vector pt = toVector(block);
LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(cfg, player);
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
if (!cfg.hasPermission(player, "/regionbypass")
&& !mgr.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_CHEST_ACCESS)
&& !mgr.getApplicableRegions(pt).canBuild(localPlayer)) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
if (!cfg.hasPermission(player, "region.bypass")) {
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
if (!set.allowsFlag(AreaFlags.FLAG_CHEST_ACCESS) && !set.canBuild(localPlayer)) {
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
event.setCancelled(true);
return;
}
}
}
}
if (wcfg.getBlacklist() != null && entity instanceof Player) {
Player player = (Player)entity;
Player player = (Player) entity;
if (!wcfg.getBlacklist().check(
new BlockInteractBlacklistEvent(BukkitPlayer.wrapPlayer(cfg, player), toVector(block),
block.getTypeId()), false, false)) {
block.getTypeId()), false, false)) {
event.setCancelled(true);
return;
}
@ -450,8 +447,7 @@ public void onBlockInteract(BlockInteractEvent event) {
@Override
public void onBlockPlace(BlockPlaceEvent event) {
if(event.isCancelled())
{
if (event.isCancelled()) {
return;
}
@ -471,11 +467,11 @@ public void onBlockPlace(BlockPlaceEvent event) {
return;
}
}
if (wcfg.getBlacklist() != null) {
if (!wcfg.getBlacklist().check(
new BlockPlaceBlacklistEvent(BukkitPlayer.wrapPlayer(cfg, player), toVector(blockPlaced),
blockPlaced.getTypeId()), false, false)) {
blockPlaced.getTypeId()), false, false)) {
event.setCancelled(true);
return;
}
@ -485,7 +481,7 @@ public void onBlockPlace(BlockPlaceEvent event) {
if (wcfg.redstoneSponges && blockPlaced.isBlockIndirectlyPowered()) {
return;
}
int ox = blockPlaced.getX();
int oy = blockPlaced.getY();
int oz = blockPlaced.getZ();
@ -514,19 +510,19 @@ public void onBlockRightClick(BlockRightClickEvent event) {
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
ApplicableRegionSet app = mgr.getApplicableRegions(pt);
List<String> regions = mgr.getApplicableRegionsIDs(pt);
if (regions.size() > 0) {
player.sendMessage(ChatColor.YELLOW + "Can you build? "
+ (app.canBuild(BukkitPlayer.wrapPlayer(cfg, player)) ? "Yes" : "No"));
StringBuilder str = new StringBuilder();
for (Iterator<String> it = regions.iterator(); it.hasNext(); ) {
for (Iterator<String> it = regions.iterator(); it.hasNext();) {
str.append(it.next());
if (it.hasNext()) {
str.append(", ");
}
}
player.sendMessage(ChatColor.YELLOW + "Applicable regions: " + str.toString());
} else {
player.sendMessage(ChatColor.YELLOW + "WorldGuard: No defined regions here!");
@ -553,7 +549,6 @@ public void onBlockRightClick(BlockRightClickEvent event) {
}
}
/**
* Called when redstone changes
* From: the source of the redstone change
@ -574,7 +569,7 @@ public void onBlockRedstoneChange(BlockRedstoneEvent event) {
int ox = blockTo.getX();
int oy = blockTo.getY();
int oz = blockTo.getZ();
for (int cx = -1; cx <= 1; cx++) {
for (int cy = -1; cy <= 1; cy++) {
for (int cz = -1; cz <= 1; cz++) {
@ -583,17 +578,17 @@ public void onBlockRedstoneChange(BlockRedstoneEvent event) {
&& sponge.isBlockIndirectlyPowered()) {
clearSpongeWater(world, ox + cx, oy + cy, oz + cz);
} else if (sponge.getTypeId() == 19
&& ! sponge.isBlockIndirectlyPowered()) {
&& !sponge.isBlockIndirectlyPowered()) {
addSpongeWater(world, ox + cx, oy + cy, oz + cz);
}
}
}
}
return;
}
}
/**
* Remove water around a sponge.
*
@ -611,14 +606,13 @@ private void clearSpongeWater(World world, int ox, int oy, int oz) {
for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
if (isBlockWater(world, ox + cx, oy + cy, oz + cz)) {
world.getBlockAt(ox + cx, oy + cy, oz + cz)
.setTypeId(0);
world.getBlockAt(ox + cx, oy + cy, oz + cz).setTypeId(0);
}
}
}
}
}
/**
* Add water around a sponge.
*
@ -641,7 +635,7 @@ private void addSpongeWater(World world, int ox, int oy, int oz) {
}
}
}
// The positive x edge
cx = ox + wcfg.spongeRadius + 1;
for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
@ -661,7 +655,7 @@ private void addSpongeWater(World world, int ox, int oy, int oz) {
}
}
}
// The positive y edge
cy = oy + wcfg.spongeRadius + 1;
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
@ -671,7 +665,7 @@ private void addSpongeWater(World world, int ox, int oy, int oz) {
}
}
}
// The negative z edge
int cz = oz - wcfg.spongeRadius - 1;
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
@ -681,7 +675,7 @@ private void addSpongeWater(World world, int ox, int oy, int oz) {
}
}
}
// The positive z edge
cz = oz + wcfg.spongeRadius + 1;
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
@ -692,7 +686,7 @@ private void addSpongeWater(World world, int ox, int oy, int oz) {
}
}
}
/**
* Sets the given block to fluid water.
* Used by addSpongeWater()
@ -708,10 +702,10 @@ private void setBlockToWater(World world, int ox, int oy, int oz) {
Block block = world.getBlockAt(ox, oy, oz);
int id = block.getTypeId();
if (id == 0) {
block.setTypeId( 8 );
block.setTypeId(8);
}
}
/**
* Checks if the given block is water
*
@ -729,4 +723,4 @@ private boolean isBlockWater(World world, int ox, int oy, int oz) {
return false;
}
}
}
}

View File

@ -196,7 +196,7 @@ public boolean canBuild(Player player, int x, int y, int z) {
Vector pt = new Vector(x, y, z);
LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(this, player);
if (!hasPermission(player, "/regionbypass")) {
if (!hasPermission(player, "region.bypass")) {
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
if (!mgr.getApplicableRegions(pt).canBuild(localPlayer)) {
@ -215,7 +215,7 @@ public boolean canBuild(Player player, Vector pt) {
if (getWorldConfig(player.getWorld().getName()).useRegions) {
LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(this, player);
if (!hasPermission(player, "/regionbypass")) {
if (!hasPermission(player, "region.bypass")) {
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
if (!mgr.getApplicableRegions(pt).canBuild(localPlayer)) {
@ -256,17 +256,7 @@ public boolean hasPermission(Player player, String perm) {
return false;
}
}
/**
* Checks for the command or /region.
*
* @param player
* @param cmd
* @return
*/
public boolean canUseRegionCommand(Player player, String cmd) {
return hasPermission(player, "region")
|| hasPermission(player, cmd);
}
/**
* Checks to see if there are sufficient permissions, otherwise an exception

View File

@ -15,10 +15,10 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
package com.sk89q.worldguard.bukkit;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@ -38,11 +38,12 @@
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
public class WorldGuardEntityListener extends EntityListener {
/**
* Plugin.
*/
private WorldGuardPlugin plugin;
/**
* Construct the object;
*
@ -52,14 +53,13 @@ public WorldGuardEntityListener(WorldGuardPlugin plugin) {
this.plugin = plugin;
}
public void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
Entity defender = event.getEntity();
DamageCause type = event.getCause();
if (defender instanceof Player) {
Player player = (Player)defender;
if (defender instanceof Player) {
Player player = (Player) defender;
WorldGuardConfiguration cfg = plugin.getWgConfiguration();
WorldGuardWorldConfiguration wcfg = cfg.getWorldConfig(player.getWorld().getName());
@ -81,13 +81,12 @@ public void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
}
}
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity attacker = event.getDamager();
Entity defender = event.getEntity();
if (defender instanceof Player) {
Player player = (Player)defender;
Player player = (Player) defender;
WorldGuardConfiguration cfg = plugin.getWgConfiguration();
WorldGuardWorldConfiguration wcfg = cfg.getWorldConfig(player.getWorld().getName());
@ -102,50 +101,48 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Vector pt = toVector(defender.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
if (!mgr.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_PVP)) {
((Player)attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
if (!mgr.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_PVP)) {
((Player) attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
event.setCancelled(true);
return;
}
}
}
if (attacker != null && attacker instanceof Monster) {
if (attacker instanceof Creeper && wcfg.blockCreeperExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
ApplicableRegionSet set = mgr.getApplicableRegions(pt);
if (!mgr.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_MOB_DAMAGE)) {
if (!set.allowsFlag(AreaFlags.FLAG_MOB_DAMAGE)) {
event.setCancelled(true);
return;
}
if (attacker instanceof Creeper) {
if (!mgr.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_CREEPER_EXPLOSION)) {
if (!set.allowsFlag(AreaFlags.FLAG_CREEPER_EXPLOSION)) {
event.setCancelled(true);
return;
}
}
}
}
}
}
public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
Entity defender = event.getEntity();
Entity attacker = event.getDamager();
if (defender instanceof Player) {
Player player = (Player)defender;
if (defender instanceof Player) {
Player player = (Player) defender;
WorldGuardConfiguration cfg = plugin.getWgConfiguration();
WorldGuardWorldConfiguration wcfg = cfg.getWorldConfig(player.getWorld().getName());
@ -160,25 +157,23 @@ public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
Vector pt = toVector(defender.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
if (!mgr.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_PVP)) {
((Player)attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
if (!mgr.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_PVP)) {
((Player) attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
event.setCancelled(true);
return;
}
}
}
if (attacker != null && attacker instanceof Skeleton) {
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
if (wcfg.useRegions) {
Vector pt = toVector(defender.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
if (!mgr.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_MOB_DAMAGE)) {
event.setCancelled(true);
return;
}
}
if (!mgr.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_MOB_DAMAGE)) {
event.setCancelled(true);
return;
}
}
}
}
@ -187,11 +182,10 @@ public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
@Override
public void onEntityDamage(EntityDamageEvent event) {
if(event.isCancelled())
{
if (event.isCancelled()) {
return;
}
if (event instanceof EntityDamageByProjectileEvent) {
this.onEntityDamageByProjectile((EntityDamageByProjectileEvent) event);
return;
@ -205,9 +199,9 @@ public void onEntityDamage(EntityDamageEvent event) {
Entity defender = event.getEntity();
DamageCause type = event.getCause();
if (defender instanceof Player) {
Player player = (Player)defender;
if (defender instanceof Player) {
Player player = (Player) defender;
WorldGuardConfiguration cfg = plugin.getWgConfiguration();
WorldGuardWorldConfiguration wcfg = cfg.getWorldConfig(player.getWorld().getName());
@ -216,7 +210,7 @@ public void onEntityDamage(EntityDamageEvent event) {
event.setCancelled(true);
return;
}
if (wcfg.disableFallDamage && type == DamageCause.FALL) {
event.setCancelled(true);
return;
@ -232,7 +226,7 @@ public void onEntityDamage(EntityDamageEvent event) {
event.setCancelled(true);
return;
}
if (wcfg.teleportOnSuffocation && type == DamageCause.SUFFOCATION) {
findFreePosition(player);
event.setCancelled(true);
@ -255,8 +249,7 @@ public void onEntityDamage(EntityDamageEvent event) {
@Override
public void onEntityExplode(EntityExplodeEvent event) {
if(event.isCancelled())
{
if (event.isCancelled()) {
return;
}
@ -271,18 +264,17 @@ public void onEntityExplode(EntityExplodeEvent event) {
event.setCancelled(true);
return;
}
if (wcfg.blockCreeperExplosions) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
Vector pt = toVector(l);
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(wcfg.getWorldName());
if (!mgr.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_CREEPER_EXPLOSION)) {
if (!mgr.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_CREEPER_EXPLOSION)) {
event.setCancelled(true);
return;
}
@ -292,13 +284,12 @@ public void onEntityExplode(EntityExplodeEvent event) {
event.setCancelled(true);
return;
}
if (wcfg.useRegions) {
Vector pt = toVector(l);
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(wcfg.getWorldName());
if (!mgr.getApplicableRegions(pt)
.allowsFlag(AreaFlags.FLAG_TNT)) {
if (!mgr.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_TNT)) {
event.setCancelled(true);
return;
}
@ -315,31 +306,90 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
WorldGuardConfiguration cfg = plugin.getWgConfiguration();
WorldGuardWorldConfiguration wcfg = cfg.getWorldConfig(event.getEntity().getWorld().getName());
CreatureType creaType = (CreatureType)CreatureType.valueOf(event.getMobType().toString());
CreatureType creaType = (CreatureType) CreatureType.valueOf(event.getMobType().toString());
String creaName = "";
Boolean cancelEvent = false;
switch(creaType) {
case SPIDER: if (wcfg.blockCreatureSpawn.contains("spider")) { cancelEvent = true; } creaName = "spider"; break;
case ZOMBIE: if (wcfg.blockCreatureSpawn.contains("zombie")) { cancelEvent = true; } creaName = "zombie"; break;
case CREEPER: if (wcfg.blockCreatureSpawn.contains("creeper")) { cancelEvent = true; } creaName = "creeper"; break;
case SKELETON: if (wcfg.blockCreatureSpawn.contains("skeleton")) { cancelEvent = true; } creaName = "skeleton"; break;
case SQUID: if (wcfg.blockCreatureSpawn.contains("squid")) { cancelEvent = true; } creaName = "squid"; break;
case PIG_ZOMBIE: if (wcfg.blockCreatureSpawn.contains("pigzombie")) { cancelEvent = true; } creaName = "pigzombie"; break;
case GHAST: if (wcfg.blockCreatureSpawn.contains("ghast")) { cancelEvent = true; } creaName = "ghast"; break;
case SLIME: if (wcfg.blockCreatureSpawn.contains("slime")) { cancelEvent = true; } creaName = "slime"; break;
case PIG: if (wcfg.blockCreatureSpawn.contains("pig")) { cancelEvent = true; } creaName = "pig"; break;
case COW: if (wcfg.blockCreatureSpawn.contains("cow")) { cancelEvent = true; } creaName = "cow"; break;
case SHEEP: if (wcfg.blockCreatureSpawn.contains("sheep")) { cancelEvent = true; } creaName = "sheep"; break;
case CHICKEN: if (wcfg.blockCreatureSpawn.contains("chicken")) { cancelEvent = true; } creaName = "chicken"; break;
switch (creaType) {
case SPIDER:
if (wcfg.blockCreatureSpawn.contains("spider")) {
cancelEvent = true;
}
creaName = "spider";
break;
case ZOMBIE:
if (wcfg.blockCreatureSpawn.contains("zombie")) {
cancelEvent = true;
}
creaName = "zombie";
break;
case CREEPER:
if (wcfg.blockCreatureSpawn.contains("creeper")) {
cancelEvent = true;
}
creaName = "creeper";
break;
case SKELETON:
if (wcfg.blockCreatureSpawn.contains("skeleton")) {
cancelEvent = true;
}
creaName = "skeleton";
break;
case SQUID:
if (wcfg.blockCreatureSpawn.contains("squid")) {
cancelEvent = true;
}
creaName = "squid";
break;
case PIG_ZOMBIE:
if (wcfg.blockCreatureSpawn.contains("pigzombie")) {
cancelEvent = true;
}
creaName = "pigzombie";
break;
case GHAST:
if (wcfg.blockCreatureSpawn.contains("ghast")) {
cancelEvent = true;
}
creaName = "ghast";
break;
case SLIME:
if (wcfg.blockCreatureSpawn.contains("slime")) {
cancelEvent = true;
}
creaName = "slime";
break;
case PIG:
if (wcfg.blockCreatureSpawn.contains("pig")) {
cancelEvent = true;
}
creaName = "pig";
break;
case COW:
if (wcfg.blockCreatureSpawn.contains("cow")) {
cancelEvent = true;
}
creaName = "cow";
break;
case SHEEP:
if (wcfg.blockCreatureSpawn.contains("sheep")) {
cancelEvent = true;
}
creaName = "sheep";
break;
case CHICKEN:
if (wcfg.blockCreatureSpawn.contains("chicken")) {
cancelEvent = true;
}
creaName = "chicken";
break;
}
if (wcfg.useRegions && creaName != "") {
Vector pt = toVector(event.getEntity().getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(event.getEntity().getWorld().getName());
Boolean flagValue = mgr.getApplicableRegions(pt)
.getBooleanAreaFlag("creaturespawn", creaName, true, null);
Boolean flagValue = mgr.getApplicableRegions(pt).getBooleanAreaFlag("creaturespawn", creaName, true, null);
if (flagValue != null) {
if (!flagValue) {
cancelEvent = true;
@ -348,13 +398,13 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
}
}
}
if (cancelEvent) {
event.setCancelled(true);
return;
}
}
/**
* Find a position for the player to stand that is not inside a block.
* Blocks above the player will be iteratively tested until there is