Add combat sign editing blocker#395
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a feature to prevent players from editing signs during combat, addressing issues with sign traps that block ender pearl throws. It adds a new SignEditingBlocker listener, configuration settings, and corresponding unit tests. The review feedback highlights a potential issue where the blocker could bypass region protections or override other item restrictions (like ender pearl cooldowns). It suggests adding ignoreCancelled = true to the event handler and checking the current item use result before allowing it.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| @EventHandler | ||
| void onInteract(PlayerInteractEvent event) { | ||
| if (!this.config.signEditing.disableSignEditingDuringCombat) { | ||
| return; | ||
| } | ||
|
|
||
| if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { | ||
| return; | ||
| } | ||
|
|
||
| Block clickedBlock = event.getClickedBlock(); | ||
| if (clickedBlock == null || !isSign(clickedBlock.getType())) { | ||
| return; | ||
| } | ||
|
|
||
| Player player = event.getPlayer(); | ||
| UUID uniqueId = player.getUniqueId(); | ||
|
|
||
| if (!this.fightManager.isInCombat(uniqueId)) { | ||
| return; | ||
| } | ||
|
|
||
| event.setUseInteractedBlock(Result.DENY); | ||
|
|
||
| ItemStack item = event.getItem(); | ||
| if (item != null && isEnderPearl(item.getType())) { | ||
| event.setUseItemInHand(Result.ALLOW); | ||
| } | ||
| } |
There was a problem hiding this comment.
To prevent potential bypasses of region protections (e.g., WorldGuard, Towny) and other internal plugin features (like Ender Pearl cooldowns/restrictions), we should:
- Add
ignoreCancelled = trueto the@EventHandlerannotation. This ensures the blocker does not run if the interaction event has already been cancelled by a protection plugin. - Check if
event.useItemInHand()is already set toResult.DENYbefore setting it toResult.ALLOW. This prevents overriding other controllers (like a pearl cooldown controller) that have explicitly blocked the item use.
@EventHandler(ignoreCancelled = true)
void onInteract(PlayerInteractEvent event) {
if (!this.config.signEditing.disableSignEditingDuringCombat) {
return;
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Block clickedBlock = event.getClickedBlock();
if (clickedBlock == null || !isSign(clickedBlock.getType())) {
return;
}
Player player = event.getPlayer();
UUID uniqueId = player.getUniqueId();
if (!this.fightManager.isInCombat(uniqueId)) {
return;
}
event.setUseInteractedBlock(Result.DENY);
ItemStack item = event.getItem();
if (item != null && isEnderPearl(item.getType()) && event.useItemInHand() != Result.DENY) {
event.setUseItemInHand(Result.ALLOW);
}
}There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 57f8c9e452
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| ItemStack item = event.getItem(); | ||
| if (item != null && isEnderPearl(item.getType())) { | ||
| event.setUseItemInHand(Result.ALLOW); |
There was a problem hiding this comment.
Preserve prior item-use denials when allowing pearls
When this blocker runs for a combat player holding an ender pearl, it unconditionally changes the item result to ALLOW. PlayerInteractEvent can already have an item-use DENY from an earlier listener (for example a protected region or item blacklist), and this line overrides that denial on sign clicks, letting the pearl launch where another plugin intentionally blocked it. Only force ALLOW if the current item result is not DENY, or otherwise preserve existing cancellation state.
Useful? React with 👍 / 👎.
No description provided.