diff --git a/src/main/java/codes/wasabi/xclaim/gui/ChunkEditor.java b/src/main/java/codes/wasabi/xclaim/gui/ChunkEditor.java index daf5150..079374f 100644 --- a/src/main/java/codes/wasabi/xclaim/gui/ChunkEditor.java +++ b/src/main/java/codes/wasabi/xclaim/gui/ChunkEditor.java @@ -50,20 +50,25 @@ private Events() { listener.register(); } - void tryRegisterPaperEvents() { - // PAPER ONLY: Item frame change event - Class itemFrameEventClass; - try { - itemFrameEventClass = Class.forName("io.papermc.paper.event.player.PlayerItemFrameChangeEvent") - .asSubclass(PlayerEvent.class); - } catch (ClassNotFoundException | ClassCastException ignored) { - return; + void tryRegisterConditionalEvents() { + // Register events that are not guaranteed to exist in Spigot 1.8+ + final String[] miscPlayerEvents = new String[] { + "io.papermc.paper.event.player.PlayerItemFrameChangeEvent", + "org.bukkit.event.player.PlayerArmorStandManipulateEvent" + }; + for (String className : miscPlayerEvents) { + try { + this.registerMiscPlayerEvent(Class.forName(className).asSubclass(PlayerEvent.class)); + } catch (ClassNotFoundException | ClassCastException ignored) { } } + } + + private void registerMiscPlayerEvent(@NotNull Class clazz) { Bukkit.getPluginManager().registerEvent( - itemFrameEventClass, + clazz, this, EventPriority.NORMAL, - (Listener ignored, Event event) -> this.onItemFrameChange((PlayerEvent) event), + (Listener ignored, Event event) -> this.onMiscPlayerEvent((PlayerEvent) event), XClaim.instance ); } @@ -309,6 +314,12 @@ public void onInteract(@NotNull PlayerInteractEvent event) { } } + @EventHandler + public void onInteractEntity(@NotNull PlayerInteractEntityEvent event) { + Player ply = event.getPlayer(); + if (getEditing(ply) != null) event.setCancelled(true); + } + @EventHandler public void onLeave(@NotNull PlayerQuitEvent event) { Player ply = event.getPlayer(); @@ -419,8 +430,7 @@ public void onMove(@NotNull PlayerMoveEvent event) { } } - // PAPER ONLY - public void onItemFrameChange(@NotNull PlayerEvent event) { + public void onMiscPlayerEvent(@NotNull PlayerEvent event) { Player ply = event.getPlayer(); if (getEditing(ply) != null && event instanceof Cancellable) { ((Cancellable) event).setCancelled(true); @@ -454,7 +464,7 @@ public static void initialize() { KEY_INVENTORY = Objects.requireNonNull(Platform.get().createNamespacedKey(XClaim.instance, "ce_inventory")); EVENTS = new Events(); Bukkit.getPluginManager().registerEvents(EVENTS, XClaim.instance); - EVENTS.tryRegisterPaperEvents(); + EVENTS.tryRegisterConditionalEvents(); } private static final Map editingMap = new HashMap<>();