Remove QueryResponse class in favor of Writable

This commit is contained in:
Kieran Wallbanks 2021-05-05 16:24:30 +01:00
parent a43c0e1291
commit 0789bd619e
5 changed files with 8 additions and 23 deletions

View File

@ -8,10 +8,10 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minestom.server.MinecraftServer;
import net.minestom.server.extras.query.event.BasicQueryEvent;
import net.minestom.server.extras.query.event.FullQueryEvent;
import net.minestom.server.extras.query.response.QueryResponse;
import net.minestom.server.timer.Task;
import net.minestom.server.utils.NetworkUtils;
import net.minestom.server.utils.binary.BinaryWriter;
import net.minestom.server.utils.binary.Writeable;
import net.minestom.server.utils.time.TimeUnit;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
@ -202,7 +202,7 @@ public class Query {
}
}
private static void sendResponse(@NotNull QueryResponse queryResponse, int sessionID, @NotNull SocketAddress sender) {
private static void sendResponse(@NotNull Writeable queryResponse, int sessionID, @NotNull SocketAddress sender) {
// header
BinaryWriter response = new BinaryWriter();
response.writeByte((byte) 0);

View File

@ -2,7 +2,7 @@ package net.minestom.server.extras.query.event;
import net.minestom.server.event.CancellableEvent;
import net.minestom.server.event.Event;
import net.minestom.server.extras.query.response.QueryResponse;
import net.minestom.server.utils.binary.Writeable;
import org.jetbrains.annotations.NotNull;
import java.net.SocketAddress;
@ -13,7 +13,7 @@ import java.util.Objects;
*
* @param <T> the type of the response
*/
public abstract class QueryEvent<T extends QueryResponse> extends Event implements CancellableEvent {
public abstract class QueryEvent<T extends Writeable> extends Event implements CancellableEvent {
private final SocketAddress sender;
private final int sessionID;

View File

@ -3,6 +3,7 @@ package net.minestom.server.extras.query.response;
import net.minestom.server.MinecraftServer;
import net.minestom.server.extras.query.Query;
import net.minestom.server.utils.binary.BinaryWriter;
import net.minestom.server.utils.binary.Writeable;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
@ -10,7 +11,7 @@ import java.util.Objects;
/**
* A basic query response containing a fixed set of responses.
*/
public class BasicQueryResponse implements QueryResponse {
public class BasicQueryResponse implements Writeable {
private String motd, gametype, map, numPlayers, maxPlayers;
/**

View File

@ -5,6 +5,7 @@ import net.minestom.server.MinecraftServer;
import net.minestom.server.extensions.Extension;
import net.minestom.server.extras.query.Query;
import net.minestom.server.utils.binary.BinaryWriter;
import net.minestom.server.utils.binary.Writeable;
import org.jetbrains.annotations.NotNull;
import java.util.*;
@ -13,7 +14,7 @@ import java.util.stream.Collectors;
/**
* A full query response containing a dynamic set of responses.
*/
public class FullQueryResponse implements QueryResponse {
public class FullQueryResponse implements Writeable {
private static final PlainComponentSerializer PLAIN = PlainComponentSerializer.plain();
private static final byte[] PADDING_10 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
PADDING_11 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

View File

@ -1,17 +0,0 @@
package net.minestom.server.extras.query.response;
import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
/**
* A query response.
*/
public interface QueryResponse {
/**
* Writes the query response to a writer.
*
* @param writer the writer to write the response to
*/
void write(@NotNull BinaryWriter writer);
}