Remove deprecated UpdateOption.java

This commit is contained in:
TheMode 2021-07-25 06:25:32 +02:00
parent adacf6b8aa
commit ad964a0a39
9 changed files with 41 additions and 251 deletions

View File

@ -1394,18 +1394,6 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
this.lastAbsoluteSynchronizationTime = 0;
}
/**
* Set custom cooldown for position synchronization.
*
* @param cooldown custom cooldown for position synchronization.
* @deprecated Replaced by {@link #setCustomSynchronizationCooldown(Duration)}
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true)
public void setCustomSynchronizationCooldown(@Nullable net.minestom.server.utils.time.UpdateOption cooldown) {
setCustomSynchronizationCooldown(cooldown != null ? Duration.ofMillis(cooldown.toMilliseconds()) : null);
}
/**
* Set custom cooldown for position synchronization.
*

View File

@ -55,19 +55,6 @@ public class ItemEntity extends Entity {
return mergeDelay;
}
/**
* Changes the merge update option.
* Can be set to null to entirely remove the delay.
*
* @param mergeUpdateOption the new merge update option
* @deprecated Replaced by {@link #setMergeDelay(Duration)}
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true)
public static void setMergeUpdateOption(@Nullable net.minestom.server.utils.time.UpdateOption mergeUpdateOption) {
setMergeDelay(mergeUpdateOption != null ? mergeUpdateOption.toDuration() : null);
}
/**
* Changes the merge delay.
* Can be set to null to entirely remove the delay.

View File

@ -1,34 +1,20 @@
package net.minestom.server.entity.ai.goal;
import net.minestom.server.coordinate.Point;
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.EntityCreature;
import net.minestom.server.entity.ai.GoalSelector;
import net.minestom.server.entity.pathfinding.Navigator;
import net.minestom.server.coordinate.Point;
import org.jetbrains.annotations.NotNull;
import java.time.Duration;
public class FollowTargetGoal extends GoalSelector {
private final Duration pathDuration;
private long lastUpdateTime = 0;
private boolean forceEnd = false;
private Point lastTargetPos;
/**
* Creates a follow target goal object.
*
* @param entityCreature the entity
* @param pathUpdateOption the time between each path update (to check if the target moved)
* @deprecated Replaced by {@link #FollowTargetGoal(EntityCreature, Duration)}
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true)
public FollowTargetGoal(@NotNull EntityCreature entityCreature, @NotNull net.minestom.server.utils.time.UpdateOption pathUpdateOption) {
this(entityCreature, pathUpdateOption.toDuration());
}
/**
* Creates a follow target goal object.
*

View File

@ -35,18 +35,6 @@ public class ClientPingServerEvent implements CancellableEvent {
this.delay = DEFAULT_DELAY;
}
/**
* Creates a new client ping server event with 0 delay
*
* @param connection the player connection
* @param payload the payload the client sent
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true)
public ClientPingServerEvent(@NotNull PlayerConnection connection, long payload, net.minestom.server.utils.time.UpdateOption delay) {
this(connection, payload, delay.toDuration());
}
/**
* Creates a new client ping server event with 0 delay
*
@ -98,19 +86,6 @@ public class ClientPingServerEvent implements CancellableEvent {
return delay;
}
/**
* Adds to the delay until minestom will send the ping response packet.
*
* @param delay the delay
*
* @deprecated Replaced by {@link #addDelay(Duration)}
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true)
public void addDelay(@NotNull net.minestom.server.utils.time.UpdateOption delay) {
addDelay(delay.toDuration());
}
/**
* Adds to the delay until minestom will send the ping response packet.
*
@ -120,19 +95,6 @@ public class ClientPingServerEvent implements CancellableEvent {
this.delay = this.delay.plus(delay);
}
/**
* Sets the delay until minestom will send the ping response packet.
*
* @param delay the delay
*
* @deprecated Replaced by {@link #setDelay(Duration)}
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true)
public void setDelay(@NotNull net.minestom.server.utils.time.UpdateOption delay) {
setDelay(delay.toDuration());
}
/**
* Sets the delay until minestom will send the ping response packet.
*

View File

@ -383,25 +383,10 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
*
* @return the client update rate for time related packet
*/
@Nullable
public Duration getTimeUpdate() {
public @Nullable Duration getTimeUpdate() {
return timeUpdate;
}
/**
* Changes the rate at which the client is updated about the time
* <p>
* Setting it to null means that the client will never know about time change
* (but will still change server-side)
*
* @param timeUpdate the new update rate concerning time
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true)
public void setTimeUpdate(@Nullable net.minestom.server.utils.time.UpdateOption timeUpdate) {
setTimeUpdate(timeUpdate != null ? timeUpdate.toDuration() : null);
}
/**
* Changes the rate at which the client is updated about the time
* <p>
@ -419,12 +404,8 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
*
* @return the {@link TimeUpdatePacket} with this instance data
*/
@NotNull
private TimeUpdatePacket createTimePacket() {
TimeUpdatePacket timeUpdatePacket = new TimeUpdatePacket();
timeUpdatePacket.worldAge = worldAge;
timeUpdatePacket.timeOfDay = time;
return timeUpdatePacket;
private @NotNull TimeUpdatePacket createTimePacket() {
return new TimeUpdatePacket(worldAge, time);
}
/**
@ -432,8 +413,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
*
* @return the {@link WorldBorder} linked to the instance
*/
@NotNull
public WorldBorder getWorldBorder() {
public @NotNull WorldBorder getWorldBorder() {
return worldBorder;
}
@ -442,8 +422,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
*
* @return an unmodifiable {@link Set} containing all the entities in the instance
*/
@NotNull
public Set<Entity> getEntities() {
public @NotNull Set<@NotNull Entity> getEntities() {
return Collections.unmodifiableSet(entities);
}

View File

@ -11,10 +11,14 @@ public class TimeUpdatePacket implements ServerPacket {
public long worldAge;
public long timeOfDay;
/**
* Default constructor, required for reflection operations.
*/
public TimeUpdatePacket() {}
public TimeUpdatePacket(long worldAge, long timeOfDay) {
this.worldAge = worldAge;
this.timeOfDay = timeOfDay;
}
public TimeUpdatePacket() {
this(0, 0);
}
@Override
public void write(@NotNull BinaryWriter writer) {

View File

@ -2,7 +2,6 @@ package net.minestom.server.timer;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.minestom.server.extras.selfmodification.MinestomRootClassLoader;
import net.minestom.server.utils.time.TimeUnit;
import org.jetbrains.annotations.NotNull;
import java.time.Duration;
@ -22,7 +21,9 @@ public class TaskBuilder {
private final Runnable runnable;
// True if the task planned for the application shutdown
private final boolean shutdown;
/** Extension which owns this task, or null if none */
/**
* Extension which owns this task, or null if none
*/
private final String owningExtension;
// Delay value for the task execution
private long delay;
@ -30,8 +31,8 @@ public class TaskBuilder {
private long repeat;
/**
* If this task is owned by an extension, should it survive the unloading of said extension?
* May be useful for delay tasks, but it can prevent the extension classes from being unloaded, and preventing a full
* reload of that extension.
* May be useful for delay tasks, but it can prevent the extension classes from being unloaded, and preventing a full
* reload of that extension.
*/
private boolean isTransient;
@ -69,34 +70,17 @@ public class TaskBuilder {
* @param unit The unit of time for {@code time}
* @return this builder, for chaining
*/
@NotNull
public TaskBuilder delay(long time, @NotNull TemporalUnit unit) {
public @NotNull TaskBuilder delay(long time, @NotNull TemporalUnit unit) {
return delay(Duration.of(time, unit));
}
/**
* Specifies that the {@link Task} should delay its execution by the specified amount of time.
*
* @param updateOption the UpdateOption for this builder.
* @return this builder, for chaining
*
* @deprecated Replaced by {@link #delay(Duration)}
*/
@SuppressWarnings("removal")
@NotNull
@Deprecated(forRemoval = true)
public TaskBuilder delay(net.minestom.server.utils.time.UpdateOption updateOption) {
return delay(updateOption.toDuration());
}
/**
* Specifies that the {@link Task} should delay its execution by the specified amount of time.
*
* @param duration the Duration for this builder.
* @return this builder, for chaining
*/
@NotNull
public TaskBuilder delay(Duration duration) {
public @NotNull TaskBuilder delay(@NotNull Duration duration) {
this.delay = duration.toMillis();
return this;
}
@ -108,34 +92,17 @@ public class TaskBuilder {
* @param unit The {@link TemporalUnit} for {@code time}
* @return this builder, for chaining
*/
@NotNull
public TaskBuilder repeat(long time, @NotNull TemporalUnit unit) {
public @NotNull TaskBuilder repeat(long time, @NotNull TemporalUnit unit) {
return repeat(Duration.of(time, unit));
}
/**
* Specifies that the {@link Task} should continue to run after waiting for the specified value until it is terminated.
*
* @param updateOption the UpdateOption for this builder.
* @return this builder, for chaining
*
* @deprecated Replaced by {@link #repeat(Duration)}
*/
@SuppressWarnings("removal")
@NotNull
@Deprecated(forRemoval = true)
public TaskBuilder repeat(net.minestom.server.utils.time.UpdateOption updateOption) {
return repeat(updateOption.toDuration());
}
/**
* Specifies that the {@link Task} should continue to run after waiting for the specified value until it is terminated.
*
* @param duration the Duration for this builder.
* @return this builder, for chaining
*/
@NotNull
public TaskBuilder repeat(Duration duration) {
public @NotNull TaskBuilder repeat(@NotNull Duration duration) {
this.repeat = duration.toMillis();
return this;
}
@ -145,8 +112,7 @@ public class TaskBuilder {
*
* @return this builder, for chaining
*/
@NotNull
public TaskBuilder clearDelay() {
public @NotNull TaskBuilder clearDelay() {
this.delay = 0L;
return this;
}
@ -156,15 +122,16 @@ public class TaskBuilder {
*
* @return this builder, for chaining
*/
@NotNull
public TaskBuilder clearRepeat() {
public @NotNull TaskBuilder clearRepeat() {
this.repeat = 0L;
return this;
}
/** If this task is owned by an extension, should it survive the unloading of said extension?
* May be useful for delay tasks, but it can prevent the extension classes from being unloaded, and preventing a full
* reload of that extension. */
/**
* If this task is owned by an extension, should it survive the unloading of said extension?
* May be useful for delay tasks, but it can prevent the extension classes from being unloaded, and preventing a full
* reload of that extension.
*/
public TaskBuilder makeTransient() {
isTransient = true;
return this;
@ -190,7 +157,7 @@ public class TaskBuilder {
synchronized (shutdownTasks) {
shutdownTasks.put(task.getId(), task);
}
if(owningExtension != null) {
if (owningExtension != null) {
this.schedulerManager.onScheduleShutdownFromExtension(owningExtension, task);
}
} else {

View File

@ -6,19 +6,9 @@ import java.time.Duration;
import java.time.temporal.TemporalUnit;
public final class Cooldown {
private final Duration duration;
private long lastUpdate;
/**
* @deprecated Replaced by {@link #Cooldown(Duration)}
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true)
public Cooldown(@NotNull UpdateOption updateOption) {
this(updateOption.toDuration());
}
public Cooldown(Duration duration) {
this.duration = duration;
this.lastUpdate = System.currentTimeMillis();
@ -39,10 +29,10 @@ public final class Cooldown {
/**
* Gets if something is in cooldown based on the current time.
*
* @param currentTime the current time in milliseconds
* @param lastUpdate the last update in milliseconds
* @param temporalUnit the time unit of the cooldown
* @param cooldown the value of the cooldown
* @param currentTime the current time in milliseconds
* @param lastUpdate the last update in milliseconds
* @param temporalUnit the time unit of the cooldown
* @param cooldown the value of the cooldown
* @return true if the cooldown is in progress, false otherwise
*/
public static boolean hasCooldown(long currentTime, long lastUpdate, @NotNull TemporalUnit temporalUnit, long cooldown) {
@ -52,25 +42,9 @@ public final class Cooldown {
/**
* Gets if something is in cooldown based on the current time.
*
* @param currentTime the current time in milliseconds
* @param lastUpdate the last update in milliseconds
* @param updateOption the cooldown
* @return true if the cooldown is in progress, false otherwise
*
* @deprecated Replaced by {@link #hasCooldown(long, long, Duration)}
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true)
public static boolean hasCooldown(long currentTime, long lastUpdate, @NotNull UpdateOption updateOption) {
return hasCooldown(currentTime, lastUpdate, updateOption.toDuration());
}
/**
* Gets if something is in cooldown based on the current time.
*
* @param currentTime the current time in milliseconds
* @param lastUpdate the last update in milliseconds
* @param duration the cooldown
* @param currentTime the current time in milliseconds
* @param lastUpdate the last update in milliseconds
* @param duration the cooldown
* @return true if the cooldown is in progress, false otherwise
*/
public static boolean hasCooldown(long currentTime, long lastUpdate, @NotNull Duration duration) {
@ -81,9 +55,9 @@ public final class Cooldown {
/**
* Gets if something is in cooldown based on the current time ({@link System#currentTimeMillis()}).
*
* @param lastUpdate the last update in milliseconds
* @param temporalUnit the time unit of the cooldown
* @param cooldown the value of the cooldown
* @param lastUpdate the last update in milliseconds
* @param temporalUnit the time unit of the cooldown
* @param cooldown the value of the cooldown
* @return true if the cooldown is in progress, false otherwise
*/
public static boolean hasCooldown(long lastUpdate, @NotNull TemporalUnit temporalUnit, int cooldown) {

View File

@ -1,57 +0,0 @@
package net.minestom.server.utils.time;
import org.jetbrains.annotations.NotNull;
import java.time.Duration;
import java.time.temporal.TemporalUnit;
import java.util.Objects;
/**
* @deprecated Replaced by {@link java.time.Duration}
*/
@Deprecated(forRemoval = true)
public class UpdateOption {
private final long value;
private final TemporalUnit temporalUnit;
public UpdateOption(long value, @NotNull TemporalUnit temporalUnit) {
this.value = value;
this.temporalUnit = temporalUnit;
}
public long getValue() {
return value;
}
@NotNull
public TemporalUnit getTemporalUnit() {
return temporalUnit;
}
@Override
public int hashCode() {
return Objects.hash(value, temporalUnit);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UpdateOption updateOption = (UpdateOption) o;
return Objects.equals(value, updateOption.value) && Objects.equals(temporalUnit, updateOption.temporalUnit);
}
/**
* Converts this update option to milliseconds
*
* @return the converted milliseconds based on the time value and the unit
*/
public long toMilliseconds() {
return toDuration().toMillis();
}
public Duration toDuration() {
return Duration.of(value, temporalUnit);
}
}