Skip to content

Commit a64ea13

Browse files
authored
Re-implement per-world and per-player time (#13814)
1 parent 1f81973 commit a64ea13

22 files changed

Lines changed: 435 additions & 224 deletions

paper-api/src/main/java/org/bukkit/World.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,10 +2094,8 @@ default boolean setSpawnLocation(int x, int y, int z) {
20942094
*
20952095
* @param time The new absolute time to set this world to
20962096
* @see #setTime(long) Sets the relative time of this world
2097-
* @deprecated all overworlds share the same world clock by default now
20982097
* @throws IllegalArgumentException if this world does not have a world clock (e.g. the nether)
20992098
*/
2100-
@Deprecated // TODO world clock API with links to it
21012099
public void setFullTime(long time);
21022100

21032101
// Paper start
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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.jspecify.annotations.NullMarked;
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+
@ApiStatus.Experimental
16+
@NullMarked
17+
public class ClockTimeSkipEvent extends Event implements Cancellable {
18+
19+
private static final HandlerList HANDLER_LIST = new HandlerList();
20+
21+
private final SkipReason skipReason;
22+
private long skipAmount;
23+
24+
private boolean cancelled;
25+
26+
@ApiStatus.Internal
27+
public ClockTimeSkipEvent(final SkipReason skipReason, final long skipAmount) {
28+
this.skipReason = skipReason;
29+
this.skipAmount = skipAmount;
30+
}
31+
32+
/**
33+
* Gets the reason why the time has skipped.
34+
*
35+
* @return a SkipReason value detailing why the time has skipped
36+
*/
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;
67+
}
68+
69+
@Override
70+
public HandlerList getHandlers() {
71+
return HANDLER_LIST;
72+
}
73+
74+
public static HandlerList getHandlerList() {
75+
return HANDLER_LIST;
76+
}
77+
78+
/**
79+
* An enum specifying the reason the time skipped.
80+
*/
81+
public enum SkipReason {
82+
83+
/**
84+
* When time is changed using the vanilla /time command.
85+
*/
86+
COMMAND,
87+
/**
88+
* When time is changed by a plugin.
89+
*/
90+
CUSTOM,
91+
/**
92+
* When time is changed by all players sleeping in their beds and the
93+
* night skips.
94+
*/
95+
NIGHT_SKIP
96+
}
97+
}
Lines changed: 10 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;
@@ -10,60 +9,29 @@
109
* Called when the time skips in a world.
1110
* <p>
1211
* If the event is cancelled the time will not change.
12+
*
13+
* @see ClockTimeSkipEvent for changing of clocks that affect all worlds
1314
*/
14-
// TODO - snapshot - 26.1 API needed for clock!
15-
public class TimeSkipEvent extends WorldEvent implements Cancellable {
15+
public class TimeSkipEvent extends ClockTimeSkipEvent {
1616

1717
private static final HandlerList HANDLER_LIST = new HandlerList();
1818

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

2421
@ApiStatus.Internal
2522
public TimeSkipEvent(@NotNull World world, @NotNull SkipReason skipReason, long skipAmount) {
26-
super(world);
27-
this.skipReason = skipReason;
28-
this.skipAmount = skipAmount;
23+
super(skipReason, skipAmount);
24+
this.world = world;
2925
}
3026

3127
/**
32-
* Gets the reason why the time has skipped.
28+
* Returns the world that time is skipped in.
3329
*
34-
* @return a SkipReason value detailing why the time has skipped
30+
* @return world that time is skipped in
3531
*/
3632
@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;
33+
public World getWorld() {
34+
return world;
6735
}
6836

6937
@NotNull
@@ -76,24 +44,4 @@ public HandlerList getHandlers() {
7644
public static HandlerList getHandlerList() {
7745
return HANDLER_LIST;
7846
}
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-
}
9947
}

0 commit comments

Comments
 (0)