Fixes #2274 hanging signs protection (#2278)

This commit is contained in:
tastybento 2024-01-20 08:17:50 -08:00 committed by GitHub
parent ffcda52912
commit 90a53e9fd8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View File

@ -210,7 +210,8 @@ public class BlockInteractionListener extends FlagListener
return true;
}
if (Tag.SIGNS.isTagged(type) && block.getState() instanceof Sign sign && !sign.isWaxed()) {
if ((Tag.ALL_HANGING_SIGNS.isTagged(type) || Tag.SIGNS.isTagged(type)) && block.getState() instanceof Sign sign
&& !sign.isWaxed()) {
// If waxed, then sign cannot be edited otherwise check
this.checkIsland(e, player, loc, Flags.SIGN_EDITING);
return true;

View File

@ -681,6 +681,7 @@ public final class Flags {
/**
* Sign edit protection
* Listener is {@link BlockInteractionListener}
* @since 1.24.0
*/
public static final Flag SIGN_EDITING = new Flag.Builder("SIGN_EDITING", Material.DARK_OAK_SIGN).mode(Flag.Mode.BASIC).type(Type.PROTECTION).build();

View File

@ -5,6 +5,7 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@ -19,6 +20,8 @@ import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.event.Event;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
@ -117,6 +120,12 @@ public class BlockInteractionListenerTest extends AbstractCommonSetup {
clickedBlocks.put(Material.CAKE, Flags.CAKE);
clickedBlocks.put(Material.BEEHIVE, Flags.HIVE);
clickedBlocks.put(Material.BEE_NEST, Flags.HIVE);
clickedBlocks.put(Material.ACACIA_WALL_HANGING_SIGN, Flags.SIGN_EDITING);
when(Tag.ALL_HANGING_SIGNS.isTagged(Material.ACACIA_HANGING_SIGN)).thenReturn(true);
clickedBlocks.put(Material.DARK_OAK_SIGN, Flags.SIGN_EDITING);
when(Tag.SIGNS.isTagged(Material.DARK_OAK_SIGN)).thenReturn(true);
clickedBlocks.put(Material.CHERRY_WALL_SIGN, Flags.SIGN_EDITING);
when(Tag.SIGNS.isTagged(Material.CHERRY_WALL_SIGN)).thenReturn(true);
}
@ -193,6 +202,10 @@ public class BlockInteractionListenerTest extends AbstractCommonSetup {
public void testOnPlayerInteractNothingInHandNotAllowed() {
int count = 0;
int worldSettingCount = 0;
// Make all block states a sign. Right now, only the sign check cares, so fix in the future if required
Sign sign = mock(Sign.class);
when(sign.isWaxed()).thenReturn(false);
when(clickedBlock.getState()).thenReturn(sign);
for (Material bm : clickedBlocks.keySet()) {
when(clickedBlock.getType()).thenReturn(bm);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);