Skip to content

Commit d9ff2a4

Browse files
committed
WorldBorder Warning Time works in ticks
PS: Mojang still set the default value in 15 what is a braking change.. but well... nothing use the warning time not?
1 parent a9bd90c commit d9ff2a4

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public interface WorldBorder {
4343
* @param seconds The time in seconds in which the border grows or shrinks from the previous size to that being set.
4444
*
4545
* @throws IllegalArgumentException if newSize is less than 1.0D or greater than {@link #getMaxSize()}
46+
* @see #setSize(double, TimeUnit, long)
4647
*/
4748
void setSize(double newSize, long seconds);
4849

@@ -117,15 +118,40 @@ public interface WorldBorder {
117118
* Gets the current border warning time in seconds.
118119
*
119120
* @return The current border warning time in seconds.
121+
* @deprecated Use {@link #getWarningTimeTicks()} instead
120122
*/
121-
int getWarningTime();
123+
@Deprecated(since = "1.21.11", forRemoval = true)
124+
default int getWarningTime() {
125+
return (int) Tick.of(this.getWarningTimeTicks()).toSeconds();
126+
}
127+
128+
/**
129+
* Gets the current border warning time in ticks.
130+
*
131+
* @return The current border warning time in ticks.
132+
*/
133+
long getWarningTimeTicks();
134+
135+
/**
136+
* Sets the warning time that causes the screen to be tinted red when a contracting border will reach the player within the specified time.
137+
*
138+
* @param seconds The amount of time in seconds.
139+
* @deprecated Use {@link #setWarningTime(TimeUnit, long)} instead
140+
*/
141+
@Deprecated(since = "1.21.11", forRemoval = true)
142+
default void setWarningTime(int seconds) {
143+
this.setWarningTime(TimeUnit.SECONDS, seconds);
144+
}
122145

123146
/**
124147
* Sets the warning time that causes the screen to be tinted red when a contracting border will reach the player within the specified time.
125148
*
126-
* @param seconds The amount of time in seconds. (The default is 15 seconds.)
149+
* @param unit The time unit.
150+
* @param time The time that causes the screen to be tinted red when a contracting border will reach.
151+
*
152+
* @see Tick
127153
*/
128-
void setWarningTime(int seconds);
154+
void setWarningTime(@NotNull TimeUnit unit, long time);
129155

130156
/**
131157
* Gets the current border warning distance.

paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorldBorder.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,16 @@ public void setDamageAmount(double damage) {
105105
}
106106

107107
@Override
108-
public int getWarningTime() {
108+
public long getWarningTimeTicks() {
109109
return this.handle.getWarningTime();
110110
}
111111

112112
@Override
113-
public void setWarningTime(int time) {
114-
this.handle.setWarningTime(time);
113+
public void setWarningTime(final TimeUnit unit, final long time) {
114+
Preconditions.checkArgument(unit != null, "TimeUnit cannot be null.");
115+
Preconditions.checkArgument(time >= 0, "time cannot be lower than 0");
116+
117+
this.handle.setWarningTime(Tick.tick().fromDuration(Duration.of(time, unit.toChronoUnit())));
115118
}
116119

117120
@Override

0 commit comments

Comments
 (0)