Skip to content

Commit

Permalink
Allow arena signs to be broken while sneaking.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
garbagemule committed Aug 20, 2024
1 parent a33f016 commit 7694872
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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);
}

}

0 comments on commit 7694872

Please sign in to comment.