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:
@@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
|
||||
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 @@ class HandlesSignClicks implements Listener {
|
||||
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) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.bukkit.block.Block;
|
||||
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 class HandlesSignClicksTest {
|
||||
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 class HandlesSignClicksTest {
|
||||
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 class HandlesSignClicksTest {
|
||||
}
|
||||
|
||||
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