From 5ec3ed6092038ae8f172e91836abc4f29329aa37 Mon Sep 17 00:00:00 2001 From: JOO200 Date: Tue, 7 Jul 2020 08:56:52 +0200 Subject: [PATCH] Changed handling von PlayerTakeLecternBookEvent to match the chest-access flag --- .../listener/RegionProtectionListener.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 5ce744df..ab18533c 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 @@ -58,8 +58,10 @@ import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; +import org.bukkit.event.Event; import org.bukkit.event.Event.Result; import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerTakeLecternBookEvent; import org.bukkit.event.vehicle.VehicleExitEvent; import java.util.ArrayList; @@ -261,6 +263,11 @@ public void onUseBlock(final UseBlockEvent event) { canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.CHEST_ACCESS)); what = "open that"; + /* Inventory for blocks with the possibility to be only use, e.g. lectern */ + } else if (handleAsInventoryUsage(event.getOriginalEvent())) { + canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.CHEST_ACCESS)); + what = "take that"; + /* Beds */ } else if (Materials.isBed(type)) { canUse = query.testBuild(BukkitAdapter.adapt(target), associable, combine(event, Flags.INTERACT, Flags.SLEEP)); @@ -552,4 +559,14 @@ private static StateFlag[] combine(DelegateEvent event, StateFlag... flag) { return flags; } + /** + * Check if that event should be handled as inventory usage, e.g. if a player takes a book from a lectern + * + * @param event the event to handle + * @return whether it should be handled as inventory usage + */ + private static boolean handleAsInventoryUsage(Event event) { + return event instanceof PlayerTakeLecternBookEvent; + } + }