Skip to content

Commit af44749

Browse files
Koora7334JRoy
andauthored
Add WarmUpCancelled Event & Expose TPType (#6351)
<!-- EssentialsX feature submission guide ==================================== NOTE: Failure to fill out this template properly may result in your PR being delayed or ignored without warning. NOTE: Don't type between any arrows in the template, as this text will be hidden. This includes this header block and any other explanation text blocks. Want to discuss your PR before submitting it? Join the EssentialsX Development server: https://discord.gg/CUN7qVb EssentialsX is GPL ------------------ By contributing to EssentialsX, you agree to license your code under the GNU General Public License version 3, which can be found at the link below: https://github.com/EssentialsX/Essentials/blob/2.x/LICENSE Instructions ------------ If you are submitting a new feature, please follow the following steps: 1. Fill out the template in full. This includes providing screenshots and a link to the original feature request. If there isn't an existing feature request, we strongly recommend opening a new feature request BEFORE opening your PR to implement it, as this allows us to review whether we're likely to accept your feature in advance, and also allows us to discuss possible implementations for the feature. If there is no associated feature request, your PR may be delayed or rejected without warning. You can open a new feature request by following this link: https://github.com/EssentialsX/Essentials/issues/new/choose 2. If you are fixing a performance issue, please use the "Bug fix" PR template instead. The "bug fix" template is better suited to performance issues. 3. Include a demonstration. If you are adding commands, please provide screenshots and/or a video demonstration of the feature. Similarly, if you are adding a new API, please include a link to example code that takes advantage of your proposed API. This will aid us in reviewing PRs and speed up the process significantly. --> ### Information <!-- Replace #nnnn with the number of the original issue. If this PR implements features from multiple issues, you should repeat the phrase "closes #nnnn" for each issue. --> ### Details **Proposed feature:** This PR add a new event when a warmpup teleport is cancelled, and it also expose the tpType **Environments tested:** <!-- Type the OS you have used below. --> OS: Debian 12 <!-- Type the JDK version (from java -version) you have used below. --> Java version: OpenJDK Runtime Environment Corretto-8.422.05.1 (build 1.8.0_422-b05) <!-- Put an "x" inside the boxes for the server software you have tested this bug fix on. If this feature does not apply to a server, strike through the server software using ~~strikethrough~~. If you have tested on other environments, add a new line with relevant details. --> - [x] Most recent Paper version (1.21.8, git-Paper-60-main@29c8822) - [ ] CraftBukkit/Spigot/Paper 1.12.2 - [x] Paper 1.8.8 --------- Co-authored-by: Josh Roy <[email protected]>
1 parent 87dfe37 commit af44749

File tree

3 files changed

+96
-4
lines changed

3 files changed

+96
-4
lines changed

Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@ public void back(final CompletableFuture<Boolean> future) {
457457
nowAsync(teleportOwner, new LocationTarget(teleportOwner.getLastLocation()), TeleportCause.COMMAND, future);
458458
}
459459

460+
public TeleportType getTpType() {
461+
return this.tpType;
462+
}
463+
460464
public void setTpType(final TeleportType tpType) {
461465
this.tpType = tpType;
462466
}

Essentials/src/main/java/com/earth2me/essentials/AsyncTimedTeleport.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.earth2me.essentials;
22

3-
import net.ess3.api.IEssentials;
4-
import net.ess3.api.IUser;
3+
import java.util.UUID;
4+
import java.util.concurrent.CompletableFuture;
5+
56
import org.bukkit.Location;
67
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
78

8-
import java.util.UUID;
9-
import java.util.concurrent.CompletableFuture;
9+
import net.ess3.api.IEssentials;
10+
import net.ess3.api.IUser;
11+
import net.essentialsx.api.v2.events.TeleportWarmupCancelledEvent;
12+
import net.essentialsx.api.v2.events.TeleportWarmupCancelledEvent.CancelReason;
1013

1114
public class AsyncTimedTeleport implements Runnable {
1215
private static final double MOVE_CONSTANT = 0.3;
@@ -149,6 +152,14 @@ void cancelTimer(final boolean notifyUser) {
149152
}
150153
try {
151154
ess.getServer().getScheduler().cancelTask(timer_task);
155+
156+
final IUser teleportUser = ess.getUser(this.timer_teleportee);
157+
if (teleportUser != null && teleportUser.getBase() != null) {
158+
final TeleportWarmupCancelledEvent.CancelReason cancelReason = teleportUser.getBase().isOnline() ? CancelReason.MOVE : CancelReason.LEAVE;
159+
final TeleportWarmupCancelledEvent event = new TeleportWarmupCancelledEvent(teleportUser.getBase(), this.teleport.getTpType(), cancelReason, notifyUser);
160+
ess.getServer().getPluginManager().callEvent(event);
161+
}
162+
152163
if (notifyUser) {
153164
teleportOwner.sendTl("pendingTeleportCancelled");
154165
if (timer_teleportee != null && !timer_teleportee.equals(teleportOwner.getBase().getUniqueId())) {
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package net.essentialsx.api.v2.events;
2+
3+
import org.bukkit.entity.Player;
4+
import org.bukkit.event.Event;
5+
import org.bukkit.event.HandlerList;
6+
import com.earth2me.essentials.AsyncTeleport.TeleportType;
7+
8+
/**
9+
* Called when a player's teleport warmup is cancelled.
10+
*/
11+
public class TeleportWarmupCancelledEvent extends Event {
12+
13+
private static final HandlerList handlers = new HandlerList();
14+
15+
private final Player player;
16+
private final TeleportType teleportType;
17+
private final CancelReason cancelReason;
18+
private final boolean notifyUser;
19+
20+
public TeleportWarmupCancelledEvent(final Player player, final TeleportType teleportType, CancelReason cancelReason, final boolean notifyUser) {
21+
this.player = player;
22+
this.teleportType = teleportType;
23+
this.cancelReason = cancelReason;
24+
this.notifyUser = notifyUser;
25+
}
26+
27+
public static HandlerList getHandlerList() {
28+
return handlers;
29+
}
30+
31+
@Override
32+
public HandlerList getHandlers() {
33+
return handlers;
34+
}
35+
36+
/**
37+
* @return the player whose teleport was canceled.
38+
*/
39+
public Player getPlayer() {
40+
return this.player;
41+
}
42+
43+
/**
44+
* @return the type of teleport that was canceled.
45+
*/
46+
public TeleportType getTeleportType() {
47+
return this.teleportType;
48+
}
49+
50+
/**
51+
* @return the reason the teleport was cancelled.
52+
*/
53+
public CancelReason getCancelReason() {
54+
return this.cancelReason;
55+
}
56+
57+
/**
58+
* @return true if the player was notified that the teleport was canceled, otherwise false.
59+
*/
60+
public boolean isPlayerNotified() {
61+
return this.notifyUser;
62+
}
63+
64+
/**
65+
* Indicates the reason why the teleportation was cancelled.
66+
*/
67+
public enum CancelReason {
68+
/**
69+
* Indicates that the cancellation occurred because the player disconnected
70+
*/
71+
LEAVE,
72+
/**
73+
* Indicates that the cancellation occurred because the player moved
74+
*/
75+
MOVE,
76+
}
77+
}

0 commit comments

Comments
 (0)