mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-07-01 08:54:51 +02:00
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:
parent
e47c563ced
commit
d8da89703b
|
@ -23,6 +23,7 @@
|
||||||
import com.sk89q.worldguard.bukkit.util.WGMetadata;
|
import com.sk89q.worldguard.bukkit.util.WGMetadata;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
|
@ -114,6 +115,27 @@ public Block getFirstBlock() {
|
||||||
return null;
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return Joiner.on(" | ").join(causes);
|
return Joiner.on(" | ").join(causes);
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent;
|
import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent;
|
||||||
import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent;
|
import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent;
|
||||||
import com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent;
|
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.bukkit.util.Materials;
|
||||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
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);
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,16 @@ public void onBreakBlock(final BreakBlockEvent event) {
|
||||||
event.filter(new Predicate<Location>() {
|
event.filter(new Predicate<Location>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Location target) {
|
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) {
|
if (!canBreak) {
|
||||||
tellErrorMessage(event.getCause(), target);
|
tellErrorMessage(event.getCause(), target);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user