Skip to content

Commit 697c8ac

Browse files
committed
Fix per-world time
1 parent ef4e85d commit 697c8ac

19 files changed

Lines changed: 375 additions & 158 deletions
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package org.bukkit.event.world;
2+
3+
import org.bukkit.event.Cancellable;
4+
import org.bukkit.event.Event;
5+
import org.bukkit.event.HandlerList;
6+
import org.jetbrains.annotations.ApiStatus;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
/**
10+
* Called when the time skips for a world clock.
11+
* <p>
12+
* If the event is cancelled the time will not change.
13+
*/
14+
// TODO - snapshot - 26.1 clock
15+
public class ClockTimeSkipEvent extends Event implements Cancellable {
16+
17+
private static final HandlerList HANDLER_LIST = new HandlerList();
18+
19+
private final SkipReason skipReason;
20+
private long skipAmount;
21+
22+
private boolean cancelled;
23+
24+
@ApiStatus.Internal
25+
public ClockTimeSkipEvent(@NotNull SkipReason skipReason, long skipAmount) {
26+
this.skipReason = skipReason;
27+
this.skipAmount = skipAmount;
28+
}
29+
30+
/**
31+
* Gets the reason why the time has skipped.
32+
*
33+
* @return a SkipReason value detailing why the time has skipped
34+
*/
35+
@NotNull
36+
public SkipReason getSkipReason() {
37+
return this.skipReason;
38+
}
39+
40+
/**
41+
* Gets the amount of time that was skipped.
42+
*
43+
* @return Amount of time skipped
44+
*/
45+
public long getSkipAmount() {
46+
return this.skipAmount;
47+
}
48+
49+
/**
50+
* Sets the amount of time to skip.
51+
*
52+
* @param skipAmount Amount of time to skip
53+
*/
54+
public void setSkipAmount(long skipAmount) {
55+
this.skipAmount = skipAmount;
56+
}
57+
58+
@Override
59+
public boolean isCancelled() {
60+
return this.cancelled;
61+
}
62+
63+
@Override
64+
public void setCancelled(boolean cancel) {
65+
this.cancelled = cancel;
66+
}
67+
68+
@NotNull
69+
@Override
70+
public HandlerList getHandlers() {
71+
return HANDLER_LIST;
72+
}
73+
74+
@NotNull
75+
public static HandlerList getHandlerList() {
76+
return HANDLER_LIST;
77+
}
78+
79+
/**
80+
* An enum specifying the reason the time skipped.
81+
*/
82+
public enum SkipReason {
83+
84+
/**
85+
* When time is changed using the vanilla /time command.
86+
*/
87+
COMMAND,
88+
/**
89+
* When time is changed by a plugin.
90+
*/
91+
CUSTOM,
92+
/**
93+
* When time is changed by all players sleeping in their beds and the
94+
* night skips.
95+
*/
96+
NIGHT_SKIP
97+
}
98+
}
Lines changed: 8 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.bukkit.event.world;
22

33
import org.bukkit.World;
4-
import org.bukkit.event.Cancellable;
54
import org.bukkit.event.HandlerList;
65
import org.jetbrains.annotations.ApiStatus;
76
import org.jetbrains.annotations.NotNull;
@@ -11,59 +10,26 @@
1110
* <p>
1211
* If the event is cancelled the time will not change.
1312
*/
14-
// TODO - snapshot - 26.1 API needed for clock!
15-
public class TimeSkipEvent extends WorldEvent implements Cancellable {
13+
public class TimeSkipEvent extends ClockTimeSkipEvent {
1614

1715
private static final HandlerList HANDLER_LIST = new HandlerList();
1816

19-
private final SkipReason skipReason;
20-
private long skipAmount;
21-
22-
private boolean cancelled;
17+
private final World world;
2318

2419
@ApiStatus.Internal
2520
public TimeSkipEvent(@NotNull World world, @NotNull SkipReason skipReason, long skipAmount) {
26-
super(world);
27-
this.skipReason = skipReason;
28-
this.skipAmount = skipAmount;
21+
super(skipReason, skipAmount);
22+
this.world = world;
2923
}
3024

3125
/**
32-
* Gets the reason why the time has skipped.
26+
* Returns the world that time is skipped in.
3327
*
34-
* @return a SkipReason value detailing why the time has skipped
28+
* @return world that time is skipped in
3529
*/
3630
@NotNull
37-
public SkipReason getSkipReason() {
38-
return this.skipReason;
39-
}
40-
41-
/**
42-
* Gets the amount of time that was skipped.
43-
*
44-
* @return Amount of time skipped
45-
*/
46-
public long getSkipAmount() {
47-
return this.skipAmount;
48-
}
49-
50-
/**
51-
* Sets the amount of time to skip.
52-
*
53-
* @param skipAmount Amount of time to skip
54-
*/
55-
public void setSkipAmount(long skipAmount) {
56-
this.skipAmount = skipAmount;
57-
}
58-
59-
@Override
60-
public boolean isCancelled() {
61-
return this.cancelled;
62-
}
63-
64-
@Override
65-
public void setCancelled(boolean cancel) {
66-
this.cancelled = cancel;
31+
public World getWorld() {
32+
return world;
6733
}
6834

6935
@NotNull
@@ -76,24 +42,4 @@ public HandlerList getHandlers() {
7642
public static HandlerList getHandlerList() {
7743
return HANDLER_LIST;
7844
}
79-
80-
/**
81-
* An enum specifying the reason the time skipped.
82-
*/
83-
public enum SkipReason {
84-
85-
/**
86-
* When time is changed using the vanilla /time command.
87-
*/
88-
COMMAND,
89-
/**
90-
* When time is changed by a plugin.
91-
*/
92-
CUSTOM,
93-
/**
94-
* When time is changed by all players sleeping in their beds and the
95-
* night skips.
96-
*/
97-
NIGHT_SKIP
98-
}
9945
}

paper-server/patches/features/0005-Entity-Activation-Range-2.0.patch

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,18 +354,18 @@ index 0000000000000000000000000000000000000000..ce6b57eeeeb1bd652f4bb53c19dcfbc0
354354
+ }
355355
+}
356356
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
357-
index 3cd2fcc38f3989bb5124ba5bc2f4597103e7a111..6d847ff3646b27fe9bc75e792d813a7f611ab3e5 100644
357+
index 16ed1b0057e74e2fd84060d5b00bf68c4a887816..3741607fa3ba755b3a9983ced08460053b75e17f 100644
358358
--- a/net/minecraft/server/level/ServerLevel.java
359359
+++ b/net/minecraft/server/level/ServerLevel.java
360-
@@ -857,6 +857,7 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
360+
@@ -864,6 +864,7 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
361361
profiler.pop();
362362
}
363363

364364
+ io.papermc.paper.entity.activation.ActivationRange.activateEntities(this); // Paper - EAR
365365
this.entityTickList
366366
.forEach(
367367
entity -> {
368-
@@ -1373,12 +1374,15 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
368+
@@ -1380,12 +1381,15 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
369369
entity.totalEntityAge++; // Paper - age-like counter for all entities
370370
profiler.push(entity.typeHolder()::getRegisteredName);
371371
profiler.incrementCounter("tickNonPassenger");
@@ -382,7 +382,7 @@ index 3cd2fcc38f3989bb5124ba5bc2f4597103e7a111..6d847ff3646b27fe9bc75e792d813a7f
382382
}
383383
// Paper start - log detailed entity tick information
384384
} finally {
385-
@@ -1389,7 +1393,7 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
385+
@@ -1396,7 +1400,7 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
386386
// Paper end - log detailed entity tick information
387387
}
388388

@@ -391,7 +391,7 @@ index 3cd2fcc38f3989bb5124ba5bc2f4597103e7a111..6d847ff3646b27fe9bc75e792d813a7f
391391
if (entity.isRemoved() || entity.getVehicle() != vehicle) {
392392
entity.stopRiding();
393393
} else if (entity instanceof Player || this.entityTickList.contains(entity)) {
394-
@@ -1399,12 +1403,21 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
394+
@@ -1406,12 +1410,21 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
395395
ProfilerFiller profiler = Profiler.get();
396396
profiler.push(entity.typeHolder()::getRegisteredName);
397397
profiler.incrementCounter("tickPassenger");

paper-server/patches/features/0016-Add-Alternate-Current-redstone-implementation.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,18 +2326,18 @@ index 0000000000000000000000000000000000000000..298076a0db4e6ee6e4775ac43bf749d9
23262326
+ }
23272327
+}
23282328
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
2329-
index 26c05173e7fb2bf055afda1717af0dd2e997118d..ffe3ae41dd3d8c4141f81edf0b92001db957ebac 100644
2329+
index 3741607fa3ba755b3a9983ced08460053b75e17f..5a911cc98faeb2db6eaf0d48cc5ff3c1f68f0a84 100644
23302330
--- a/net/minecraft/server/level/ServerLevel.java
23312331
+++ b/net/minecraft/server/level/ServerLevel.java
2332-
@@ -232,6 +232,7 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
2333-
public final WorldGenSettings worldGenSettings;
2332+
@@ -233,6 +233,7 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
2333+
private ServerClockManager clockManager;
23342334
public boolean hasPhysicsEvent = true; // Paper - BlockPhysicsEvent
23352335
public boolean hasEntityMoveEvent; // Paper - Add EntityMoveEvent
23362336
+ private final alternate.current.wire.WireHandler wireHandler = new alternate.current.wire.WireHandler(this); // Paper - optimize redstone (Alternate Current)
23372337

23382338
@Override
23392339
public @Nullable LevelChunk getChunkIfLoaded(int x, int z) {
2340-
@@ -2765,6 +2766,13 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
2340+
@@ -2773,6 +2774,13 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
23412341
return this.debugSynchronizers;
23422342
}
23432343

paper-server/patches/features/0020-Incremental-chunk-and-player-saving.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Subject: [PATCH] Incremental chunk and player saving
55

66

77
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
8-
index 40a500011e7fcb6f5b07ff289f737ed9d3550296..da8c04aa02032c4c582709727f8f7f0b66b697b1 100644
8+
index 3ee7ef093902997e259c900ba08596ff3823fb34..100b68f5ea119ae7055d92a8fc2743e68758d857 100644
99
--- a/net/minecraft/server/MinecraftServer.java
1010
+++ b/net/minecraft/server/MinecraftServer.java
1111
@@ -958,7 +958,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -94,10 +94,10 @@ index 40a500011e7fcb6f5b07ff289f737ed9d3550296..da8c04aa02032c4c582709727f8f7f0b
9494
ProfilerFiller profiler = Profiler.get();
9595
this.server.spark.executeMainThreadTasks(); // Paper - spark
9696
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
97-
index ffe3ae41dd3d8c4141f81edf0b92001db957ebac..98461e8468a7eeaef2544ee907ff64de1fd42a49 100644
97+
index 5a911cc98faeb2db6eaf0d48cc5ff3c1f68f0a84..4ac7ef5a1ed1fac04a9fd246212f59919deb498c 100644
9898
--- a/net/minecraft/server/level/ServerLevel.java
9999
+++ b/net/minecraft/server/level/ServerLevel.java
100-
@@ -1441,6 +1441,15 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
100+
@@ -1448,6 +1448,15 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
101101
public boolean mayInteract(final Entity entity, final BlockPos pos) {
102102
return !(entity instanceof Player player && (this.server.isUnderSpawnProtection(this, pos, player) || !this.getWorldBorder().isWithinBounds(pos)));
103103
}
@@ -126,7 +126,7 @@ index 41816ca8d4ef3d959d2b88cd4b2eedaaa541e612..82e87270d1ad89ad7aa56e028ced6b99
126126
private static final int NEUTRAL_MOB_DEATH_NOTIFICATION_RADII_Y = 10;
127127
private static final int FLY_STAT_RECORDING_SPEED = 25;
128128
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
129-
index 0613b053f4a75c0884280011ee092d9d108b3857..b69bcaa1e27a4fbe9a9568f3c9e1843167abe1f5 100644
129+
index 8c35af5f23ac46fa9d9647ead753d6c5ddf6af57..5e11abcfd681d86b1c0e282cf901108822766ce2 100644
130130
--- a/net/minecraft/server/players/PlayerList.java
131131
+++ b/net/minecraft/server/players/PlayerList.java
132132
@@ -418,6 +418,7 @@ public abstract class PlayerList {

paper-server/patches/features/0029-Optimize-Hoppers.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ index 0000000000000000000000000000000000000000..24a2090e068ad3c0d08705050944abdf
4848
+ }
4949
+}
5050
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
51-
index 3923f21c67165e2ecd2c9cecd5266758435a6806..92acd256fdf815dfb8dd743cf8ecd0eb377d996e 100644
51+
index 789374f3fe5f3730ec5edac248ed7927f8f04abd..f094726677ccef9029680b9de208b71133bbb87d 100644
5252
--- a/net/minecraft/server/MinecraftServer.java
5353
+++ b/net/minecraft/server/MinecraftServer.java
54-
@@ -1836,6 +1836,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
54+
@@ -1844,6 +1844,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
5555
level.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - BlockPhysicsEvent
5656
level.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent
5757
level.updateLagCompensationTick(); // Paper - lag compensation

paper-server/patches/features/0030-Anti-Xray.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ index a94e6ca1d396b6b0781de5d550c4a804274ee003..a1018e9ca9dfb978d6e6633577abd7d5
155155

156156
private ClientboundLevelChunkWithLightPacket(final RegistryFriendlyByteBuf input) {
157157
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
158-
index 78021db10860396fef4eb2e01926fbad123916fa..3f02da2014ed8e4169f4bb819b4d9e61154b7b06 100644
158+
index 4ac7ef5a1ed1fac04a9fd246212f59919deb498c..e562aec4366d7724f915e3dd5ae440a77e0947c5 100644
159159
--- a/net/minecraft/server/level/ServerLevel.java
160160
+++ b/net/minecraft/server/level/ServerLevel.java
161-
@@ -630,7 +630,7 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
161+
@@ -631,7 +631,7 @@ public class ServerLevel extends Level implements WorldGenLevel, ServerEntityGet
162162
savedDataStorage.set(io.papermc.paper.world.saveddata.PaperWorldPDC.TYPE, loadedWorldData.pdc() == null ? io.papermc.paper.world.saveddata.PaperWorldPDC.TYPE.constructor().get() : loadedWorldData.pdc());
163163
final GameRules gameRules = new GameRules(server.getWorldData().enabledFeatures(), savedDataStorage.computeIfAbsent(net.minecraft.world.level.gamerules.GameRuleMap.TYPE));
164164
this.gameRules = gameRules;
@@ -196,7 +196,7 @@ index ec40f02032f965f548b0c0a29aa9d9bbad6f439b..373da9d604cfb1614a0618d856aefd2b
196196
if (io.papermc.paper.event.packet.PlayerChunkLoadEvent.getHandlerList().getRegisteredListeners().length > 0) {
197197
new io.papermc.paper.event.packet.PlayerChunkLoadEvent(new org.bukkit.craftbukkit.CraftChunk(chunk), connection.getPlayer().getBukkitEntity()).callEvent();
198198
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
199-
index b69bcaa1e27a4fbe9a9568f3c9e1843167abe1f5..9218322801c41657c00928ef90b0de99df1670f6 100644
199+
index 5e11abcfd681d86b1c0e282cf901108822766ce2..3020a3208b14bb483b08cf59a796fb83c2403d1c 100644
200200
--- a/net/minecraft/server/players/PlayerList.java
201201
+++ b/net/minecraft/server/players/PlayerList.java
202202
@@ -331,7 +331,7 @@ public abstract class PlayerList {

0 commit comments

Comments
 (0)