From 7694872ebca035c6d0b92c3828e6e92f2ddc1665 Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Tue, 23 Jul 2024 04:23:52 +0200 Subject: [PATCH] Allow arena signs to be broken while sneaking. This commit "fixes" the problem introduced in the "no sign edits" commit by not invoking the sign actions for interact events where the player is sneaking. This is not the ideal way to go about it, but since we need to bump the Spigot API version to access the sign change event that would fix the underlying issue, this will have to do for now. Fixes #791 --- changelog.md | 1 + .../MobArena/signs/HandlesSignClicks.java | 4 ++++ .../MobArena/signs/HandlesSignClicksTest.java | 24 ++++++++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 58588263..1f5961f3 100644 --- a/changelog.md +++ b/changelog.md @@ -20,6 +20,7 @@ These changes will (most likely) be included in the next version. - The `shuffle-positions` ability now correctly shuffles the position of the boss as well if `monster-teleport` is set to `false`. - The `obsidian-bomb` ability no longer breaks boss waves. - Text on Arena Signs is no longer explicitly truncated. This fixes an issue where color codes would count towards the character limit, causing the text that would otherwise fit on the sign to be cut off. +- Arena Signs can once again be destroyed, but it is necessary to break them while sneaking. ## [0.108] - 2024-01-01 ### Added diff --git a/src/main/java/com/garbagemule/MobArena/signs/HandlesSignClicks.java b/src/main/java/com/garbagemule/MobArena/signs/HandlesSignClicks.java index 64699504..5bfbbe1c 100644 --- a/src/main/java/com/garbagemule/MobArena/signs/HandlesSignClicks.java +++ b/src/main/java/com/garbagemule/MobArena/signs/HandlesSignClicks.java @@ -6,6 +6,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import java.util.HashMap; @@ -38,6 +39,9 @@ public void on(PlayerInteractEvent event) { if (!(block.getState() instanceof Sign)) { return; } + if (event.getPlayer().isSneaking() && event.getAction() == Action.LEFT_CLICK_BLOCK) { + return; + } ArenaSign sign = signStore.findByLocation(block.getLocation()); if (sign != null) { diff --git a/src/test/java/com/garbagemule/MobArena/signs/HandlesSignClicksTest.java b/src/test/java/com/garbagemule/MobArena/signs/HandlesSignClicksTest.java index 9d97a7c0..683b736c 100644 --- a/src/test/java/com/garbagemule/MobArena/signs/HandlesSignClicksTest.java +++ b/src/test/java/com/garbagemule/MobArena/signs/HandlesSignClicksTest.java @@ -5,6 +5,7 @@ import org.bukkit.block.Chest; import org.bukkit.block.Sign; import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.junit.Before; import org.junit.Test; @@ -50,12 +51,27 @@ public void noSignBlockNoFun() { verifyNoInteractions(signStore, invokesSignAction); } + @Test + public void sneakingPlayerNoFun() { + Block block = mock(Block.class); + when(block.getState()).thenReturn(mock(Sign.class)); + Player player = mock(Player.class); + when(player.isSneaking()).thenReturn(true); + PlayerInteractEvent event = event(player, block); + + subject.on(event); + + verifyNoInteractions(signStore, invokesSignAction); + } + @Test public void nonArenaSignNoFun() { Block block = mock(Block.class); when(block.getState()).thenReturn(mock(Sign.class)); + Player player = mock(Player.class); + when(player.isSneaking()).thenReturn(false); when(signStore.findByLocation(any())).thenReturn(null); - PlayerInteractEvent event = event(null, block); + PlayerInteractEvent event = event(player, block); subject.on(event); @@ -68,9 +84,10 @@ public void arenaSignInvokesAction() { Block block = mock(Block.class); when(block.getLocation()).thenReturn(location); when(block.getState()).thenReturn(mock(Sign.class)); + Player player = mock(Player.class); + when(player.isSneaking()).thenReturn(false); ArenaSign sign = new ArenaSign(location, "", "", ""); when(signStore.findByLocation(location)).thenReturn(sign); - Player player = mock(Player.class); PlayerInteractEvent event = event(player, block); subject.on(event); @@ -79,7 +96,8 @@ public void arenaSignInvokesAction() { } private PlayerInteractEvent event(Player player, Block block) { - return new PlayerInteractEvent(player, null, null, block, null); + Action action = Action.LEFT_CLICK_BLOCK; + return new PlayerInteractEvent(player, action, null, block, null); } }