Updated ClientPingServerEvent.java

This commit is contained in:
Németh Noel 2021-06-30 01:42:54 +02:00
parent 6a4de332a6
commit 2c9f0c5e67

View File

@ -3,9 +3,10 @@ package net.minestom.server.event.server;
import net.minestom.server.event.trait.CancellableEvent; import net.minestom.server.event.trait.CancellableEvent;
import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.utils.time.TimeUnit; import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.utils.time.UpdateOption;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.time.Duration;
/** /**
* Called when a {@link PlayerConnection} sends a ping packet, * Called when a {@link PlayerConnection} sends a ping packet,
@ -14,13 +15,13 @@ import org.jetbrains.annotations.NotNull;
* @see ServerListPingEvent * @see ServerListPingEvent
*/ */
public class ClientPingServerEvent implements CancellableEvent { 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 final PlayerConnection connection;
private long payload; private long payload;
private boolean cancelled = false; private boolean cancelled = false;
private UpdateOption delay; private Duration delay;
/** /**
* Creates a new client ping server event with 0 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 connection the player connection
* @param payload the payload the client sent * @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.connection = connection;
this.payload = payload; this.payload = payload;
this.delay = delay; this.delay = delay;
} }
/** /**
* PlayerConnection of received packet. Note that the player has not joined the server * PlayerConnection of received packet. Note that the player has not joined the server
* at this time. * at this time.
@ -82,7 +94,7 @@ public class ClientPingServerEvent implements CancellableEvent {
* *
* @return the delay * @return the delay
*/ */
public @NotNull UpdateOption getDelay() { public @NotNull Duration getDelay() {
return delay; return delay;
} }
@ -90,9 +102,35 @@ public class ClientPingServerEvent implements CancellableEvent {
* Adds to the delay until minestom will send the ping response packet. * Adds to the delay until minestom will send the ping response packet.
* *
* @param delay the delay * @param delay the delay
*
* @deprecated Replaced by {@link #addDelay(Duration)}
*/ */
public void addDelay(@NotNull UpdateOption delay) { @SuppressWarnings("removal")
this.delay = new UpdateOption(this.delay.toMilliseconds() + delay.toMilliseconds(), TimeUnit.MILLISECOND); @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 * @param delay the delay
*/ */
public void setDelay(@NotNull UpdateOption delay) { public void setDelay(@NotNull Duration delay) {
this.delay = delay; this.delay = delay;
} }