Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public void run(final Server server, final User user, final String commandLabel,
final TPARequestEvent tpaEvent = new TPARequestEvent(user.getSource(), player, false);
ess.getServer().getPluginManager().callEvent(tpaEvent);
if (tpaEvent.isCancelled()) {
if (tpaEvent.isSilent()) {
throw new NoChargeException();
}
throw new TranslatableException("teleportRequestCancelled", player.getDisplayName());
}
player.requestTeleport(user, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ private void tpaAll(final CommandSource sender, final User target) {
final TPARequestEvent tpaEvent = new TPARequestEvent(sender, player, true);
ess.getServer().getPluginManager().callEvent(tpaEvent);
if (tpaEvent.isCancelled()) {
if (tpaEvent.isSilent()) {
continue;
}
sender.sendTl("teleportRequestCancelled", player.getDisplayName());
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public void run(final Server server, final User user, final String commandLabel,
final TPARequestEvent tpaEvent = new TPARequestEvent(user.getSource(), player, true);
ess.getServer().getPluginManager().callEvent(tpaEvent);
if (tpaEvent.isCancelled()) {
if (tpaEvent.isSilent()) {
throw new NoChargeException();
}
throw new TranslatableException("teleportRequestCancelled", player.getDisplayName());
}
player.requestTeleport(user, true);
Expand Down
18 changes: 18 additions & 0 deletions Essentials/src/main/java/net/ess3/api/events/TPARequestEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class TPARequestEvent extends Event implements Cancellable {
private final CommandSource requester;
private final IUser target;
private boolean cancelled = false;
private boolean silent = false;
private boolean requestToTPAHere;

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

/**
* @return true if a cancelled request should not show the default "request cancelled" message
*/
public boolean isSilent() {
return silent;
}

/**
* Suppresses the default "request cancelled" message when this event is cancelled.
* Use it when the cancelling plugin informs the requester itself.
*
* @param silent whether the cancel message should be suppressed
*/
public void setSilent(final boolean silent) {
this.silent = silent;
}

@Override
public boolean isCancelled() {
return cancelled;
Expand Down
Loading