diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java index c73ce2044..70e5a9715 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java @@ -47,6 +47,7 @@ import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.StateFlag.State; import com.sk89q.worldguard.protection.regions.RegionQuery; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -414,7 +415,15 @@ public void onUseEntity(UseEntityEvent event) { } /* Ridden on use */ } else if (Entities.isRiddenOnUse(entity)) { - canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.RIDE, Flags.INTERACT)); + StateFlag flagToCheck; + if (entity instanceof Tameable){ + flagToCheck = Flags.MOUNT_ANIMALS; + }else { + flagToCheck = Flags.MOUNT_VEHICLES; + } + // backward compatibility – if Flag.RIDE is allowed, just allow + canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.RIDE, Flags.INTERACT)) + || query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, flagToCheck)); what = "ride that"; /* Everything else */ @@ -511,13 +520,23 @@ public void onVehicleExit(VehicleExitEvent event) { if (!isRegionSupportEnabled(BukkitAdapter.adapt(vehicle.getWorld()))) return; // Region support disabled Entity exited = event.getExited(); - if (vehicle instanceof Tameable && exited instanceof Player) { + if(exited instanceof Player){ Player player = (Player) exited; LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); + StateFlag flagToCheck; + if (vehicle instanceof Tameable){ + flagToCheck = Flags.DISMOUNT_ANIMALS; + } else { + flagToCheck = Flags.DISMOUNT_VEHICLES; + } if (!isWhitelisted(Cause.create(player), vehicle.getWorld(), false)) { RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); Location location = vehicle.getLocation(); - if (!query.testBuild(BukkitAdapter.adapt(location), localPlayer, Flags.RIDE, Flags.INTERACT)) { + // don't let the INTERACT flag override dismounting + // the player might need to interact with world objects while staying mounted (buttons, doors etc) + // for backward compatibility, still allow the old Flags.RIDE | Flags.INTERACT + if (!query.testBuild(BukkitAdapter.adapt(location), localPlayer, flagToCheck) + && !query.testBuild(BukkitAdapter.adapt(location), localPlayer, Flags.RIDE, Flags.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/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java index 02d25357d..24c65c8d4 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java @@ -66,6 +66,10 @@ public final class Flags { public static final StateFlag DESTROY_VEHICLE = register(new StateFlag("vehicle-destroy", false)); public static final StateFlag LIGHTER = register(new StateFlag("lighter", false)); public static final StateFlag RIDE = register(new StateFlag("ride", false)); + public static final StateFlag MOUNT_ANIMALS = register(new StateFlag("mount-animals", false)); + public static final StateFlag MOUNT_VEHICLES = register(new StateFlag("mount-vehicles", false)); + public static final StateFlag DISMOUNT_ANIMALS = register(new StateFlag("dismount-animals", false)); + public static final StateFlag DISMOUNT_VEHICLES = register(new StateFlag("dismount-vehicles", false)); public static final StateFlag POTION_SPLASH = register(new StateFlag("potion-splash", false)); public static final StateFlag ITEM_FRAME_ROTATE = register(new StateFlag("item-frame-rotation", false)); public static final StateFlag TRAMPLE_BLOCKS = register(new StateFlag("block-trampling", false));