Skip to content

Commit 596a701

Browse files
committed
Add TPARequestEvent#setSilent to suppress the default cancel message
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.
1 parent f8724e2 commit 596a701

4 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpa.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public void run(final Server server, final User user, final String commandLabel,
6161
final TPARequestEvent tpaEvent = new TPARequestEvent(user.getSource(), player, false);
6262
ess.getServer().getPluginManager().callEvent(tpaEvent);
6363
if (tpaEvent.isCancelled()) {
64+
if (tpaEvent.isSilent()) {
65+
throw new NoChargeException();
66+
}
6467
throw new TranslatableException("teleportRequestCancelled", player.getDisplayName());
6568
}
6669
player.requestTeleport(user, false);

‎Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaall.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ private void tpaAll(final CommandSource sender, final User target) {
4444
final TPARequestEvent tpaEvent = new TPARequestEvent(sender, player, true);
4545
ess.getServer().getPluginManager().callEvent(tpaEvent);
4646
if (tpaEvent.isCancelled()) {
47+
if (tpaEvent.isSilent()) {
48+
continue;
49+
}
4750
sender.sendTl("teleportRequestCancelled", player.getDisplayName());
4851
continue;
4952
}

‎Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpahere.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public void run(final Server server, final User user, final String commandLabel,
4242
final TPARequestEvent tpaEvent = new TPARequestEvent(user.getSource(), player, true);
4343
ess.getServer().getPluginManager().callEvent(tpaEvent);
4444
if (tpaEvent.isCancelled()) {
45+
if (tpaEvent.isSilent()) {
46+
throw new NoChargeException();
47+
}
4548
throw new TranslatableException("teleportRequestCancelled", player.getDisplayName());
4649
}
4750
player.requestTeleport(user, true);

‎Essentials/src/main/java/net/ess3/api/events/TPARequestEvent.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class TPARequestEvent extends Event implements Cancellable {
1414
private final CommandSource requester;
1515
private final IUser target;
1616
private boolean cancelled = false;
17+
private boolean silent = false;
1718
private boolean requestToTPAHere;
1819

1920
public TPARequestEvent(final CommandSource requester, final IUser target, final boolean tpaHere) {
@@ -39,6 +40,23 @@ public boolean isTeleportHere() {
3940
return requestToTPAHere;
4041
}
4142

43+
/**
44+
* @return true if a cancelled request should not show the default "request cancelled" message
45+
*/
46+
public boolean isSilent() {
47+
return silent;
48+
}
49+
50+
/**
51+
* Suppresses the default "request cancelled" message when this event is cancelled.
52+
* Use it when the cancelling plugin informs the requester itself.
53+
*
54+
* @param silent whether the cancel message should be suppressed
55+
*/
56+
public void setSilent(final boolean silent) {
57+
this.silent = silent;
58+
}
59+
4260
@Override
4361
public boolean isCancelled() {
4462
return cancelled;

0 commit comments

Comments
 (0)