From 2c9f0c5e6759f9c2487e76e7784874d9095951e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9meth=20Noel?= Date: Wed, 30 Jun 2021 01:42:54 +0200 Subject: [PATCH] Updated ClientPingServerEvent.java --- .../event/server/ClientPingServerEvent.java | 56 ++++++++++++++++--- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/minestom/server/event/server/ClientPingServerEvent.java b/src/main/java/net/minestom/server/event/server/ClientPingServerEvent.java index f1cddd191..b6df76970 100644 --- a/src/main/java/net/minestom/server/event/server/ClientPingServerEvent.java +++ b/src/main/java/net/minestom/server/event/server/ClientPingServerEvent.java @@ -3,9 +3,10 @@ package net.minestom.server.event.server; import net.minestom.server.event.trait.CancellableEvent; import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.utils.time.TimeUnit; -import net.minestom.server.utils.time.UpdateOption; import org.jetbrains.annotations.NotNull; +import java.time.Duration; + /** * Called when a {@link PlayerConnection} sends a ping packet, @@ -14,13 +15,13 @@ import org.jetbrains.annotations.NotNull; * @see ServerListPingEvent */ public class ClientPingServerEvent implements CancellableEvent { - private static final UpdateOption DEFAULT_DELAY = new UpdateOption(0, TimeUnit.MILLISECOND); + private static final Duration DEFAULT_DELAY = Duration.of(0, TimeUnit.MILLISECOND); private final PlayerConnection connection; private long payload; private boolean cancelled = false; - private UpdateOption delay; + private Duration delay; /** * Creates a new client ping server event with 0 delay @@ -40,13 +41,24 @@ public class ClientPingServerEvent implements CancellableEvent { * @param connection the player connection * @param payload the payload the client sent */ - public ClientPingServerEvent(@NotNull PlayerConnection connection, long payload, UpdateOption delay) { + @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 + * + * @param connection the player connection + * @param payload the payload the client sent + */ + public ClientPingServerEvent(@NotNull PlayerConnection connection, long payload, Duration delay) { this.connection = connection; this.payload = payload; this.delay = delay; } - /** * PlayerConnection of received packet. Note that the player has not joined the server * at this time. @@ -82,7 +94,7 @@ public class ClientPingServerEvent implements CancellableEvent { * * @return the delay */ - public @NotNull UpdateOption getDelay() { + public @NotNull Duration getDelay() { return delay; } @@ -90,9 +102,35 @@ public class ClientPingServerEvent implements CancellableEvent { * Adds to the delay until minestom will send the ping response packet. * * @param delay the delay + * + * @deprecated Replaced by {@link #addDelay(Duration)} */ - public void addDelay(@NotNull UpdateOption delay) { - this.delay = new UpdateOption(this.delay.toMilliseconds() + delay.toMilliseconds(), TimeUnit.MILLISECOND); + @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. + * + * @param delay the delay + */ + public void addDelay(@NotNull Duration delay) { + 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()); } /** @@ -100,7 +138,7 @@ public class ClientPingServerEvent implements CancellableEvent { * * @param delay the delay */ - public void setDelay(@NotNull UpdateOption delay) { + public void setDelay(@NotNull Duration delay) { this.delay = delay; }