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
This commit is contained in:
@@ -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 `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.
|
- 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.
|
- 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
|
## [0.108] - 2024-01-01
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -38,6 +39,9 @@ class HandlesSignClicks implements Listener {
|
|||||||
if (!(block.getState() instanceof Sign)) {
|
if (!(block.getState() instanceof Sign)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (event.getPlayer().isSneaking() && event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ArenaSign sign = signStore.findByLocation(block.getLocation());
|
ArenaSign sign = signStore.findByLocation(block.getLocation());
|
||||||
if (sign != null) {
|
if (sign != null) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.block.Chest;
|
import org.bukkit.block.Chest;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -50,12 +51,27 @@ public class HandlesSignClicksTest {
|
|||||||
verifyNoInteractions(signStore, invokesSignAction);
|
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
|
@Test
|
||||||
public void nonArenaSignNoFun() {
|
public void nonArenaSignNoFun() {
|
||||||
Block block = mock(Block.class);
|
Block block = mock(Block.class);
|
||||||
when(block.getState()).thenReturn(mock(Sign.class));
|
when(block.getState()).thenReturn(mock(Sign.class));
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
when(player.isSneaking()).thenReturn(false);
|
||||||
when(signStore.findByLocation(any())).thenReturn(null);
|
when(signStore.findByLocation(any())).thenReturn(null);
|
||||||
PlayerInteractEvent event = event(null, block);
|
PlayerInteractEvent event = event(player, block);
|
||||||
|
|
||||||
subject.on(event);
|
subject.on(event);
|
||||||
|
|
||||||
@@ -68,9 +84,10 @@ public class HandlesSignClicksTest {
|
|||||||
Block block = mock(Block.class);
|
Block block = mock(Block.class);
|
||||||
when(block.getLocation()).thenReturn(location);
|
when(block.getLocation()).thenReturn(location);
|
||||||
when(block.getState()).thenReturn(mock(Sign.class));
|
when(block.getState()).thenReturn(mock(Sign.class));
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
when(player.isSneaking()).thenReturn(false);
|
||||||
ArenaSign sign = new ArenaSign(location, "", "", "");
|
ArenaSign sign = new ArenaSign(location, "", "", "");
|
||||||
when(signStore.findByLocation(location)).thenReturn(sign);
|
when(signStore.findByLocation(location)).thenReturn(sign);
|
||||||
Player player = mock(Player.class);
|
|
||||||
PlayerInteractEvent event = event(player, block);
|
PlayerInteractEvent event = event(player, block);
|
||||||
|
|
||||||
subject.on(event);
|
subject.on(event);
|
||||||
@@ -79,7 +96,8 @@ public class HandlesSignClicksTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private PlayerInteractEvent event(Player player, Block block) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user