Skip to content

Add combat sign editing blocker#395

Open
vLuckyyy wants to merge 1 commit into
masterfrom
sign-editing-combat-traps
Open

Add combat sign editing blocker#395
vLuckyyy wants to merge 1 commit into
masterfrom
sign-editing-combat-traps

Conversation

@vLuckyyy

Copy link
Copy Markdown
Member

No description provided.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +26 to +54
@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);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

To prevent potential bypasses of region protections (e.g., WorldGuard, Towny) and other internal plugin features (like Ender Pearl cooldowns/restrictions), we should:

  1. Add ignoreCancelled = true to the @EventHandler annotation. This ensures the blocker does not run if the interaction event has already been cancelled by a protection plugin.
  2. Check if event.useItemInHand() is already set to Result.DENY before setting it to Result.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);
        }
    }

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant