From 1e0830542d04ef9ea89d39d14c1a2280403c622a Mon Sep 17 00:00:00 2001 From: ryanhamshire Date: Wed, 7 Jan 2015 20:08:04 -0800 Subject: [PATCH] Allowing environmental damage to minecarts. Still not TNT, creepers, or players (without permission). --- .../GriefPrevention/DataStore.java | 1 + .../GriefPrevention/EntityEventHandler.java | 45 ++++++++----------- .../GriefPrevention/WorldGuardWrapper.java | 3 +- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/me/ryanhamshire/GriefPrevention/DataStore.java b/src/me/ryanhamshire/GriefPrevention/DataStore.java index 10b8d86..f54b391 100644 --- a/src/me/ryanhamshire/GriefPrevention/DataStore.java +++ b/src/me/ryanhamshire/GriefPrevention/DataStore.java @@ -146,6 +146,7 @@ public abstract class DataStore } //if failed, world guard compat features will just be disabled. catch(ClassNotFoundException exception){ } + catch(NoClassDefFoundError exception){ } } private void loadSoftMutes() diff --git a/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java b/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java index b792919..fe20765 100644 --- a/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java @@ -764,36 +764,29 @@ class EntityEventHandler implements Listener //determine which player is attacking, if any Player attacker = null; Entity damageSource = event.getAttacker(); - - //if damage source is null, don't allow the damage when the vehicle is in a land claim - if(damageSource == null) + EntityType damageSourceType = null; + + //if damage source is null or a creeper, don't allow the damage when the vehicle is in a land claim + if(damageSource != null) { - Claim claim = this.dataStore.getClaimAt(event.getVehicle().getLocation(), false, null); - - //if it's claimed - if(claim != null) - { - event.setCancelled(true); - } - - return; - } - - if(damageSource.getType() == EntityType.PLAYER) - { - attacker = (Player)damageSource; - } - else if(damageSource instanceof Projectile) - { - Projectile arrow = (Projectile)damageSource; - if(arrow.getShooter() instanceof Player) - { - attacker = (Player)arrow.getShooter(); - } + damageSourceType = damageSource.getType(); + + if(damageSource.getType() == EntityType.PLAYER) + { + attacker = (Player)damageSource; + } + else if(damageSource instanceof Projectile) + { + Projectile arrow = (Projectile)damageSource; + if(arrow.getShooter() instanceof Player) + { + attacker = (Player)arrow.getShooter(); + } + } } //if not a player and not an explosion, always allow - if(attacker == null && !(damageSource instanceof Explosive)) + if(attacker == null && damageSourceType != EntityType.CREEPER && damageSourceType != EntityType.PRIMED_TNT) { return; } diff --git a/src/me/ryanhamshire/GriefPrevention/WorldGuardWrapper.java b/src/me/ryanhamshire/GriefPrevention/WorldGuardWrapper.java index 09b31b1..3f17c45 100644 --- a/src/me/ryanhamshire/GriefPrevention/WorldGuardWrapper.java +++ b/src/me/ryanhamshire/GriefPrevention/WorldGuardWrapper.java @@ -8,6 +8,7 @@ import com.sk89q.worldedit.BlockVector; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; @@ -32,7 +33,7 @@ class WorldGuardWrapper new BlockVector(greaterCorner.getX(), world.getMaxHeight(), greaterCorner.getZ())); ApplicableRegionSet overlaps = manager.getApplicableRegions(tempRegion); LocalPlayer localPlayer = worldGuard.wrapPlayer(creatingPlayer); - return overlaps.canBuild(localPlayer); + return overlaps.testState(localPlayer, DefaultFlag.BUILD); } return true;