aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0272-Add-worldborder-events.patch
blob: 09c3770e162894c4ec411ead27632f0cdf9ff7a6 (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
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..126fe50b519a8d7cd158f799058cb235f9c4cbdb
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/world/border/WorldBorderBoundsChangeEvent.java
@@ -0,0 +1,114 @@
+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.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;
+
+    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 type;
+    }
+
+    /**
+     * Gets the old size or the world border.
+     *
+     * @return the old size
+     */
+    public double getOldSize() {
+        return oldSize;
+    }
+
+    /**
+     * Gets the new size of the world border.
+     *
+     * @return the new size
+     */
+    public double getNewSize() {
+        return newSize;
+    }
+
+    /**
+     * Sets the new size of the world border.
+     *
+     * @param newSize the new size
+     */
+    public void setNewSize(double newSize) {
+        // PAIL: TODO: Magic Values
+        this.newSize = Math.min(6.0E7D, 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 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 && type == Type.INSTANT_MOVE) type = Type.STARTED_MOVE;
+    }
+
+    @Override
+    public boolean isCancelled() {
+        return 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..c3d578ae2c5615b0ebace99d9bacf100b086c971
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/world/border/WorldBorderBoundsChangeFinishEvent.java
@@ -0,0 +1,65 @@
+package io.papermc.paper.event.world.border;
+
+import org.bukkit.World;
+import org.bukkit.WorldBorder;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Called when a moving world border has finished it's 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;
+
+    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 oldSize;
+    }
+
+    /**
+     * Gets the new size of the worldborder.
+     *
+     * @return the new size
+     */
+    public double getNewSize() {
+        return newSize;
+    }
+
+    /**
+     * Gets the duration this worldborder took to make the change.
+     * <p>
+     * Can be 0 if handlers for {@link io.papermc.paper.event.world.border.WorldBorderCenterChangeEvent} set the duration to 0.
+     *
+     * @return the duration of the transition
+     */
+    public double getDuration() {
+        return 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..4a10c773a8d05a596066e63306dead74c1363fd7
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/world/border/WorldBorderCenterChangeEvent.java
@@ -0,0 +1,77 @@
+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.bukkit.event.world.WorldEvent;
+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;
+
+    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 oldCenter;
+    }
+
+    /**
+     * Gets the new center location for the world border.
+     *
+     * @return the new center
+     */
+    @NotNull
+    public Location getNewCenter() {
+        return 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 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..67bd469d3680c9554ce6c1d5493826a252682835
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/world/border/WorldBorderEvent.java
@@ -0,0 +1,22 @@
+package io.papermc.paper.event.world.border;
+
+import org.bukkit.World;
+import org.bukkit.WorldBorder;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.world.WorldEvent;
+import org.jetbrains.annotations.NotNull;
+
+public abstract class WorldBorderEvent extends WorldEvent {
+
+    private final WorldBorder worldBorder;
+
+    public WorldBorderEvent(@NotNull World world, @NotNull WorldBorder worldBorder) {
+        super(world);
+        this.worldBorder = worldBorder;
+    }
+
+    @NotNull
+    public WorldBorder getWorldBorder() {
+        return worldBorder;
+    }
+}