aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0261-Add-worldborder-events.patch
blob: 1c889b6cdd5d642748cf78c26cca603101557657 (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Mon, 4 Jan 2021 22:40:26 -0800
Subject: [PATCH] Add worldborder events


diff --git a/src/main/java/io/papermc/paper/event/world/border/WorldBorderBoundsChangeEvent.java b/src/main/java/io/papermc/paper/event/world/border/WorldBorderBoundsChangeEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..02ac479840c137ca5afcec149ef884e5a5d62928
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/world/border/WorldBorderBoundsChangeEvent.java
@@ -0,0 +1,117 @@
+package io.papermc.paper.event.world.border;
+
+import org.bukkit.World;
+import org.bukkit.WorldBorder;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Called when a world border changes its bounds, either over time, or instantly.
+ */
+public class WorldBorderBoundsChangeEvent extends WorldBorderEvent implements Cancellable {
+
+    private static final HandlerList HANDLER_LIST = new HandlerList();
+
+    private Type type;
+    private final double oldSize;
+    private double newSize;
+    private long duration;
+    private boolean cancelled;
+
+    @ApiStatus.Internal
+    public WorldBorderBoundsChangeEvent(@NotNull World world, @NotNull WorldBorder worldBorder, @NotNull Type type, double oldSize, double newSize, long duration) {
+        super(world, worldBorder);
+        this.type = type;
+        this.oldSize = oldSize;
+        this.newSize = newSize;
+        this.duration = duration;
+    }
+
+    /**
+     * Gets if this change is an instant change or over-time change.
+     *
+     * @return the change type
+     */
+    @NotNull
+    public Type getType() {
+        return this.type;
+    }
+
+    /**
+     * Gets the old size or the world border.
+     *
+     * @return the old size
+     */
+    public double getOldSize() {
+        return this.oldSize;
+    }
+
+    /**
+     * Gets the new size of the world border.
+     *
+     * @return the new size
+     */
+    public double getNewSize() {
+        return this.newSize;
+    }
+
+    /**
+     * Sets the new size of the world border.
+     *
+     * @param newSize the new size
+     */
+    public void setNewSize(double newSize) {
+        this.newSize = Math.min(this.worldBorder.getMaxSize(), Math.max(1.0D, newSize));
+    }
+
+    /**
+     * Gets the time in milliseconds for the change. Will be 0 if instant.
+     *
+     * @return the time in milliseconds for the change
+     */
+    public long getDuration() {
+        return this.duration;
+    }
+
+    /**
+     * Sets the time in milliseconds for the change. Will change {@link #getType()} to return
+     * {@link Type#STARTED_MOVE}.
+     *
+     * @param duration the time in milliseconds for the change
+     */
+    public void setDuration(long duration) {
+        // PAIL: TODO: Magic Values
+        this.duration = Math.min(9223372036854775L, Math.max(0L, duration));
+        if (duration >= 0 && this.type == Type.INSTANT_MOVE) {
+            this.type = Type.STARTED_MOVE;
+        }
+    }
+
+    @Override
+    public boolean isCancelled() {
+        return this.cancelled;
+    }
+
+    @Override
+    public void setCancelled(boolean cancel) {
+        this.cancelled = cancel;
+    }
+
+    @NotNull
+    @Override
+    public HandlerList getHandlers() {
+        return HANDLER_LIST;
+    }
+
+    @NotNull
+    public static HandlerList getHandlerList() {
+        return HANDLER_LIST;
+    }
+
+    public enum Type {
+        STARTED_MOVE,
+        INSTANT_MOVE
+    }
+}
diff --git a/src/main/java/io/papermc/paper/event/world/border/WorldBorderBoundsChangeFinishEvent.java b/src/main/java/io/papermc/paper/event/world/border/WorldBorderBoundsChangeFinishEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..a44964593b7f78c5086dc4928e75ad892e624671
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/world/border/WorldBorderBoundsChangeFinishEvent.java
@@ -0,0 +1,67 @@
+package io.papermc.paper.event.world.border;
+
+import org.bukkit.World;
+import org.bukkit.WorldBorder;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Called when a moving world border has finished its move.
+ */
+public class WorldBorderBoundsChangeFinishEvent extends WorldBorderEvent {
+
+    private static final HandlerList HANDLER_LIST = new HandlerList();
+
+    private final double oldSize;
+    private final double newSize;
+    private final double duration;
+
+    @ApiStatus.Internal
+    public WorldBorderBoundsChangeFinishEvent(@NotNull World world, @NotNull WorldBorder worldBorder, double oldSize, double newSize, double duration) {
+        super(world, worldBorder);
+        this.oldSize = oldSize;
+        this.newSize = newSize;
+        this.duration = duration;
+    }
+
+    /**
+     * Gets the old size of the worldborder.
+     *
+     * @return the old size
+     */
+    public double getOldSize() {
+        return this.oldSize;
+    }
+
+    /**
+     * Gets the new size of the worldborder.
+     *
+     * @return the new size
+     */
+    public double getNewSize() {
+        return this.newSize;
+    }
+
+    /**
+     * Gets the duration this worldborder took to make the change.
+     * <p>
+     * Can be 0 if handlers for {@link WorldBorderCenterChangeEvent} set the duration to 0.
+     *
+     * @return the duration of the transition
+     */
+    public double getDuration() {
+        return this.duration;
+    }
+
+    @NotNull
+    @Override
+    public HandlerList getHandlers() {
+        return HANDLER_LIST;
+    }
+
+    @NotNull
+    public static HandlerList getHandlerList() {
+        return HANDLER_LIST;
+    }
+}
diff --git a/src/main/java/io/papermc/paper/event/world/border/WorldBorderCenterChangeEvent.java b/src/main/java/io/papermc/paper/event/world/border/WorldBorderCenterChangeEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..a90f67e902c6ae35b2399e6f72a3ff8a5c15d05a
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/world/border/WorldBorderCenterChangeEvent.java
@@ -0,0 +1,79 @@
+package io.papermc.paper.event.world.border;
+
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.WorldBorder;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Called when a world border's center is changed.
+ */
+public class WorldBorderCenterChangeEvent extends WorldBorderEvent implements Cancellable {
+
+    private static final HandlerList HANDLER_LIST = new HandlerList();
+
+    private final Location oldCenter;
+    private Location newCenter;
+
+    private boolean cancelled;
+
+    @ApiStatus.Internal
+    public WorldBorderCenterChangeEvent(@NotNull World world, @NotNull WorldBorder worldBorder, @NotNull Location oldCenter, @NotNull Location newCenter) {
+        super(world, worldBorder);
+        this.oldCenter = oldCenter;
+        this.newCenter = newCenter;
+    }
+
+    /**
+     * Gets the original center location of the world border.
+     *
+     * @return the old center
+     */
+    @NotNull
+    public Location getOldCenter() {
+        return this.oldCenter;
+    }
+
+    /**
+     * Gets the new center location for the world border.
+     *
+     * @return the new center
+     */
+    @NotNull
+    public Location getNewCenter() {
+        return this.newCenter;
+    }
+
+    /**
+     * Sets the new center location for the world border. Y coordinate is ignored.
+     *
+     * @param newCenter the new center
+     */
+    public void setNewCenter(@NotNull Location newCenter) {
+        this.newCenter = newCenter;
+    }
+
+    @Override
+    public boolean isCancelled() {
+        return this.cancelled;
+    }
+
+    @Override
+    public void setCancelled(boolean cancel) {
+        this.cancelled = cancel;
+    }
+
+    @NotNull
+    @Override
+    public HandlerList getHandlers() {
+        return HANDLER_LIST;
+    }
+
+    @NotNull
+    public static HandlerList getHandlerList() {
+        return HANDLER_LIST;
+    }
+}
diff --git a/src/main/java/io/papermc/paper/event/world/border/WorldBorderEvent.java b/src/main/java/io/papermc/paper/event/world/border/WorldBorderEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..adb244f9be35c43ff99dbc3a771e1fdfb21da68c
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/world/border/WorldBorderEvent.java
@@ -0,0 +1,23 @@
+package io.papermc.paper.event.world.border;
+
+import org.bukkit.World;
+import org.bukkit.WorldBorder;
+import org.bukkit.event.world.WorldEvent;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+
+public abstract class WorldBorderEvent extends WorldEvent {
+
+    protected final WorldBorder worldBorder;
+
+    @ApiStatus.Internal
+    protected WorldBorderEvent(@NotNull World world, @NotNull WorldBorder worldBorder) {
+        super(world);
+        this.worldBorder = worldBorder;
+    }
+
+    @NotNull
+    public WorldBorder getWorldBorder() {
+        return this.worldBorder;
+    }
+}