Skip to content

Add TPARequestEvent#setSilent to suppress the default cancel message - #6653

Open
1wairesd wants to merge 1 commit into
EssentialsX:2.xfrom
1wairesd:feat/tparequest-silent
Open

1wairesd wants to merge 1 commit into
EssentialsX:2.xfrom
1wairesd:feat/tparequest-silent

Conversation

@1wairesd

Copy link
Copy Markdown
Contributor

Information

There is no separate feature request.

Details

Proposed feature:

When a plugin cancels TPARequestEvent, /tpa and /tpahere always throw teleportRequestCancelled ("Your teleport request to X was cancelled"), and /tpaall sends the same message. A plugin that cancels the request usually tells the player why, so the player gets two messages, the second one shown as an error.

This adds TPARequestEvent#setSilent(boolean) / isSilent(). If a cancelled event is silent:

  • /tpa and /tpahere stop without the error message (NoChargeException, like other early exits);
  • /tpaall skips that player without the message.

Default is false, so nothing changes for existing plugins.

Environments tested:

OS: Windows

Java version: OpenJDK 25.0.5 (build), ./gradlew :EssentialsX:build passes (checkstyle and unit tests)

  • Most recent Paper version (XX.YY.Z, git-Paper-BUILD)
  • CraftBukkit/Spigot/Paper 1.12.2
  • CraftBukkit 1.8.8

Demonstration:

@EventHandler(ignoreCancelled = true)
public void onTpaRequest(TPARequestEvent event) {
    if (!event.getRequester().isPlayer()) return;
    Player requester = event.getRequester().getPlayer();
    if (isProtected(event.getTarget().getBase().getWorld())) {
        event.setCancelled(true);
        event.setSilent(true);
        requester.sendMessage("Teleport denied: " + event.getTarget().getName() + " is in a protected world.");
    }
}

Before (one plugin message plus the Essentials error):

Teleport denied: B is in a protected world.
Error: Your teleport request to B was cancelled.

After, with setSilent(true):

Teleport denied: B is in a protected world.

Plugins that cancel a /tpa, /tpahere or /tpaall request and tell the requester why can now
skip the extra 'teleportRequestCancelled' error. Default behaviour is unchanged.
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