From 93ced5ca7a2e26e4b630549010175e6f3007f925 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sun, 4 Jan 2015 13:50:48 -0800 Subject: [PATCH] Revert USE flag's functionality to 5.x, add new INTERACT flag. --- .../listener/RegionProtectionListener.java | 19 ++++++---- .../worldguard/bukkit/util/Materials.java | 35 +++++++++++++++++++ .../protection/flags/DefaultFlag.java | 3 +- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java b/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java index f106141b..80e2c7e5 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java @@ -254,22 +254,27 @@ public boolean apply(Location target) { /* Inventory */ } else if (Materials.isInventoryBlock(type)) { - canUse = query.testBuild(target, associable, DefaultFlag.USE, DefaultFlag.CHEST_ACCESS); + canUse = query.testBuild(target, associable, DefaultFlag.INTERACT, DefaultFlag.CHEST_ACCESS); what = "open that"; /* Beds */ } else if (type == Material.BED_BLOCK) { - canUse = query.testBuild(target, associable, DefaultFlag.USE, DefaultFlag.SLEEP); + canUse = query.testBuild(target, associable, DefaultFlag.INTERACT, DefaultFlag.SLEEP); what = "sleep"; /* TNT */ } else if (type == Material.TNT) { - canUse = query.testBuild(target, associable, DefaultFlag.TNT); + canUse = query.testBuild(target, associable, DefaultFlag.INTERACT, DefaultFlag.TNT); what = "use explosives"; + /* Legacy USE flag */ + } else if (Materials.isUseFlagApplicable(type)) { + canUse = query.testBuild(target, associable, DefaultFlag.INTERACT, DefaultFlag.USE); + what = "use that"; + /* Everything else */ } else { - canUse = query.testBuild(target, associable, DefaultFlag.USE); + canUse = query.testBuild(target, associable, DefaultFlag.INTERACT); what = "use that"; } @@ -383,7 +388,7 @@ public void onUseEntity(UseEntityEvent event) { /* Everything else */ } else { - canUse = query.testBuild(target, associable, DefaultFlag.USE); + canUse = query.testBuild(target, associable, DefaultFlag.INTERACT); what = "use that"; } @@ -438,7 +443,7 @@ public void onDamageEntity(DamageEntityEvent event) { /* Everything else */ } else { - canDamage = query.testBuild(target, associable, DefaultFlag.USE); + canDamage = query.testBuild(target, associable, DefaultFlag.INTERACT); what = "hit that"; } @@ -458,7 +463,7 @@ public void onVehicleExit(VehicleExitEvent event) { if (!isWhitelisted(Cause.create(player), vehicle.getWorld())) { RegionQuery query = getPlugin().getRegionContainer().createQuery(); Location location = vehicle.getLocation(); - if (!query.testBuild(location, player, DefaultFlag.USE)) { + if (!query.testBuild(location, player, DefaultFlag.INTERACT)) { long now = System.currentTimeMillis(); Long lastTime = WGMetadata.getIfPresent(player, DISEMBARK_MESSAGE_KEY, Long.class); if (lastTime == null || now - lastTime >= LAST_MESSAGE_DELAY) { diff --git a/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index baf82292..7e971080 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -21,6 +21,7 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; +import com.sk89q.worldguard.protection.flags.DefaultFlag; import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.entity.EntityType; @@ -576,6 +577,40 @@ public static boolean isInventoryBlock(Material material) { || material == Material.DROPPER; } + /** + * Test whether the given material is affected by + * {@link DefaultFlag#USE}. + * + *

Generally, materials that are considered by this method are those + * that are not inventories but can be used.

+ * + * @param material the material + * @return true if covered by the use flag + */ + public static boolean isUseFlagApplicable(Material material) { + return material == Material.LEVER + || material == Material.STONE_BUTTON + || material == Material.WOOD_BUTTON + || material == Material.NOTE_BLOCK + || material == Material.DIODE_BLOCK_OFF + || material == Material.DIODE_BLOCK_ON + || material == Material.WOODEN_DOOR + || material == Material.TRAP_DOOR + || material == Material.FENCE_GATE + || material == Material.JUKEBOX + || material == Material.DISPENSER + || material == Material.FURNACE + || material == Material.BURNING_FURNACE + || material == Material.WORKBENCH + || material == Material.BREWING_STAND + || material == Material.ENCHANTMENT_TABLE + || material == Material.CAULDRON + || material == Material.BEACON + || material == Material.ANVIL + || material == Material.HOPPER + || material == Material.DROPPER; + } + /** * Test whether the given type is Redstone ore. * diff --git a/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java b/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java index 1ffc0ba3..681418fc 100644 --- a/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java +++ b/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java @@ -47,6 +47,7 @@ public final class DefaultFlag { public static final StateFlag BLOCK_BREAK = new StateFlag("block-break", false); public static final StateFlag BLOCK_PLACE = new StateFlag("block-place", false); public static final StateFlag USE = new StateFlag("use", false); + public static final StateFlag INTERACT = new StateFlag("interact", false); public static final StateFlag PVP = new StateFlag("pvp", false); public static final StateFlag SLEEP = new StateFlag("sleep", false); public static final StateFlag TNT = new StateFlag("tnt", false); @@ -128,7 +129,7 @@ public final class DefaultFlag { public static final Flag[] flagsList = new Flag[] { PASSTHROUGH, BUILD, CONSTRUCT, BLOCK_BREAK, BLOCK_PLACE, PVP, CHEST_ACCESS, PISTONS, - TNT, LIGHTER, USE, PLACE_VEHICLE, DESTROY_VEHICLE, SLEEP, + TNT, LIGHTER, USE, INTERACT, PLACE_VEHICLE, DESTROY_VEHICLE, SLEEP, MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, INVINCIBILITY, EXP_DROPS, CREEPER_EXPLOSION, OTHER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD, DENY_MESSAGE, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE,