Skip to content

Commit 9479d05

Browse files
committed
fix: sign editing plugins overriding realty sign management
1 parent cb9de2c commit 9479d05

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

realty-paper/src/main/java/io/github/md5sha256/realty/listener/SignInteractionListener.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import org.bukkit.event.block.Action;
2020
import org.bukkit.event.block.BlockBreakEvent;
2121
import org.bukkit.event.player.PlayerInteractEvent;
22-
import org.bukkit.event.player.PlayerSignOpenEvent;
2322
import org.bukkit.event.world.ChunkLoadEvent;
23+
import org.bukkit.inventory.EquipmentSlot;
2424
import org.bukkit.event.world.ChunkUnloadEvent;
2525
import org.jetbrains.annotations.NotNull;
2626

@@ -29,6 +29,12 @@
2929

3030
/**
3131
* Handles sign click interactions, sign break cleanup, and chunk-based sign caching.
32+
*
33+
* <p>Interact uses {@link org.bukkit.event.EventPriority#LOWEST} so Realty-linked signs are handled
34+
* before other plugins; the event is cancelled for those signs so handlers that respect
35+
* cancellation defer. {@link io.papermc.paper.event.player.PlayerOpenSignEvent} uses
36+
* {@link org.bukkit.event.EventPriority#HIGHEST} so Realty can suppress the sign editor for linked
37+
* signs after other listeners.</p>
3238
*/
3339
public class SignInteractionListener implements Listener {
3440

@@ -56,7 +62,7 @@ public SignInteractionListener(@NotNull Database database,
5662
this.messages = messages;
5763
}
5864

59-
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
65+
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
6066
public void onPlayerInteract(@NotNull PlayerInteractEvent event) {
6167
Block block = event.getClickedBlock();
6268
if (block == null || !(block.getState(false) instanceof Sign)) {
@@ -66,11 +72,15 @@ public void onPlayerInteract(@NotNull PlayerInteractEvent event) {
6672
if (action != Action.RIGHT_CLICK_BLOCK && action != Action.LEFT_CLICK_BLOCK) {
6773
return;
6874
}
75+
if (event.getHand() == EquipmentSlot.OFF_HAND) {
76+
return;
77+
}
6978
SignCache.SignCacheEntry entry = signCache.get(
7079
block.getWorld().getUID(), block.getX(), block.getY(), block.getZ());
7180
if (entry == null) {
7281
return;
7382
}
83+
event.setCancelled(true);
7484
Player player = event.getPlayer();
7585
executorState.dbExec().execute(() -> {
7686
RealtyApi.RegionWithState rws = logic.getRegionWithState(
@@ -100,7 +110,7 @@ public void onPlayerInteract(@NotNull PlayerInteractEvent event) {
100110
});
101111
}
102112

103-
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
113+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
104114
public void onSignOpen(@NotNull PlayerOpenSignEvent event) {
105115
Sign sign = event.getSign();
106116
Block block = sign.getBlock();

0 commit comments

Comments
 (0)