forked from PaperMC/Paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0069-Add-PlayerJumpEvent.patch
117 lines (115 loc) · 3.63 KB
/
0069-Add-PlayerJumpEvent.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Zach Brown <[email protected]>
Date: Thu, 28 Sep 2017 17:21:32 -0400
Subject: [PATCH] Add PlayerJumpEvent
diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerJumpEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerJumpEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..1d07c3d6bf3b9283371ca45698178979113085fa
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerJumpEvent.java
@@ -0,0 +1,105 @@
+package com.destroystokyo.paper.event.player;
+
+import com.google.common.base.Preconditions;
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.bukkit.event.player.PlayerMoveEvent;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Called when the server detects the player is jumping.
+ * <p>
+ * Added to avoid the overhead and special case logic that many plugins use
+ * when checking for jumps via {@link PlayerMoveEvent}, this event is fired whenever
+ * the server detects that the player is jumping.
+ */
+@NullMarked
+public class PlayerJumpEvent extends PlayerEvent implements Cancellable {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final Location to;
+ private Location from;
+
+ private boolean cancelled;
+
+ @ApiStatus.Internal
+ public PlayerJumpEvent(final Player player, final Location from, final Location to) {
+ super(player);
+ this.from = from;
+ this.to = to;
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * If a jump event is cancelled, the player will be moved or
+ * teleported back to the Location as defined by {@link #getFrom()}. This will not
+ * fire an event
+ *
+ * @return {@code true} if this event is cancelled
+ */
+ @Override
+ public boolean isCancelled() {
+ return this.cancelled;
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * If a jump event is cancelled, the player will be moved or
+ * teleported back to the Location as defined by {@link #getFrom()}. This will not
+ * fire an event
+ *
+ * @param cancel {@code true} if you wish to cancel this event
+ */
+ @Override
+ public void setCancelled(final boolean cancel) {
+ this.cancelled = cancel;
+ }
+
+ /**
+ * Gets the location this player jumped from
+ *
+ * @return Location the player jumped from
+ */
+ public Location getFrom() {
+ return this.from;
+ }
+
+ /**
+ * Sets the location to mark as where the player jumped from
+ *
+ * @param from New location to mark as the players previous location
+ */
+ public void setFrom(final Location from) {
+ Preconditions.checkArgument(from != null, "Cannot use null from location!");
+ Preconditions.checkArgument(from.getWorld() != null, "Cannot use from location with null world!");
+ this.from = from;
+ }
+
+ /**
+ * Gets the location this player jumped to
+ * <p>
+ * This information is based on what the client sends, it typically
+ * has little relation to the arc of the jump at any given point.
+ *
+ * @return Location the player jumped to
+ */
+ public Location getTo() {
+ return this.to.clone();
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+}