Handle the TNT flag better in the new system.

Now the build flag works in tandem with the TNT flag.
This commit is contained in:
sk89q 2014-08-22 11:27:23 -07:00
parent e47c563ced
commit d8da89703b
3 changed files with 32 additions and 10 deletions

View File

@ -23,6 +23,7 @@
import com.sk89q.worldguard.bukkit.util.WGMetadata;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
@ -114,6 +115,27 @@ public Block getFirstBlock() {
return null;
}
/**
* Find the first type matching one in the given array.
*
* @param types an array of types
* @return a found type or null
*/
@Nullable
public EntityType find(EntityType... types) {
for (Object object : causes) {
if (object instanceof Entity) {
for (EntityType type : types) {
if (((Entity) object).getType() == type) {
return type;
}
}
}
}
return null;
}
@Override
public String toString() {
return Joiner.on(" | ").join(causes);

View File

@ -26,7 +26,6 @@
import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent;
import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent;
import com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent;
import com.sk89q.worldguard.bukkit.util.Entities;
import com.sk89q.worldguard.bukkit.util.Materials;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
@ -106,14 +105,6 @@ public void onBreakBlock(final BreakBlockEvent event) {
event.filter(testState(query, DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE), config.explosionFlagCancellation);
}
// ================================================================
// TNT flag
// ================================================================
if (Entities.isTNTBased(entity)) { // TNT + explosive TNT carts
event.filter(testState(query, DefaultFlag.TNT), config.explosionFlagCancellation);
}
}
}

View File

@ -146,7 +146,16 @@ public void onBreakBlock(final BreakBlockEvent event) {
event.filter(new Predicate<Location>() {
@Override
public boolean apply(Location target) {
boolean canBreak = query.testBuild(target, associable);
boolean canBreak;
/* TNT */
if (event.getCause().find(EntityType.PRIMED_TNT, EntityType.PRIMED_TNT) != null) {
canBreak = query.testBuild(target, associable, DefaultFlag.TNT);
/* Everything else */
} else {
canBreak = query.testBuild(target, associable);
}
if (!canBreak) {
tellErrorMessage(event.getCause(), target);