From 78abba56afa76ed0310c979986581bf2d3f9d988 Mon Sep 17 00:00:00 2001 From: kashike Date: Sat, 13 Oct 2018 00:13:48 -0700 Subject: [PATCH] Change player info action enum to int Read & write server id Fix javadocs --- .../com/velocitypowered/api/proxy/Player.java | 14 +++++++---- .../api/proxy/player/TabListEntry.java | 6 ++--- .../backend/BackendPlaySessionHandler.java | 4 ++-- .../protocol/packet/EncryptionRequest.java | 5 ++-- .../proxy/protocol/packet/PlayerListItem.java | 23 ++++++++----------- .../proxy/tablist/VelocityTabList.java | 20 ++++++++-------- .../proxy/tablist/VelocityTabListEntry.java | 6 ++--- 7 files changed, 40 insertions(+), 38 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/proxy/Player.java b/api/src/main/java/com/velocitypowered/api/proxy/Player.java index 57300de66..844200ea5 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/Player.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/Player.java @@ -81,14 +81,18 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage ConnectionRequestBuilder createConnectionRequest(@NonNull RegisteredServer server); /** - * Gets a game profile properties of player - * @return a immutable list of properties + * Gets the player's profile properties. + * + *

The returned list may be unmodifiable.

+ * + * @return the player's profile properties */ List getGameProfileProperties(); /** - * Sets a GameProfile properties({@link GameProfile.Property) - * @param properties a properties to set + * Sets the player's profile properties. + * + * @param properties the properties */ void setGameProfileProperties(List properties); @@ -109,7 +113,7 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage void clearHeaderAndFooter(); /** - * Returns {@link this} {@link Player}'s tab list. + * Returns the player's tab list. * @return this player's tab list */ TabList getTabList(); diff --git a/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java b/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java index 4e25b1ec5..c0da1a5c2 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java @@ -59,7 +59,7 @@ public interface TabListEntry { /** * Sets the latency for {@code this} entry to the specified value - * @see this#getLatency() + * @see #getLatency() * @param latency to changed to * @return {@code this}, for chaining */ @@ -74,13 +74,13 @@ public interface TabListEntry { *
  • Adventure
  • *
  • Spectator
  • * - * @return + * @return the game mode */ int getGameMode(); /** * Sets the game mode for {@code this} entry to the specified value - * @see this#getGameMode() + * @see #getGameMode() * @param gameMode to change to * @return {@code this}, for chaining */ diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java index 4e48f7e6c..dc2b6a6cd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java @@ -64,10 +64,10 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { @Override public boolean handle(BossBar packet) { switch (packet.getAction()) { - case 0: // add + case BossBar.ADD: playerSessionHandler.getServerBossBars().add(packet.getUuid()); break; - case 1: // remove + case BossBar.REMOVE: playerSessionHandler.getServerBossBars().remove(packet.getUuid()); break; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequest.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequest.java index 4f80cc3a4..76ce0ba7a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequest.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/EncryptionRequest.java @@ -9,6 +9,7 @@ import io.netty.buffer.ByteBuf; import java.util.Arrays; public class EncryptionRequest implements MinecraftPacket { + private String serverId; private byte[] publicKey; private byte[] verifyToken; @@ -38,14 +39,14 @@ public class EncryptionRequest implements MinecraftPacket { @Override public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { - ProtocolUtils.readString(buf); // Server ID, can be ignored since it is an empty string + this.serverId = ProtocolUtils.readString(buf, 20); publicKey = ProtocolUtils.readByteArray(buf, 256); verifyToken = ProtocolUtils.readByteArray(buf, 16); } @Override public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { - ProtocolUtils.writeString(buf, ""); // Server ID + ProtocolUtils.writeString(buf, this.serverId); ProtocolUtils.writeByteArray(buf, publicKey); ProtocolUtils.writeByteArray(buf, verifyToken); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItem.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItem.java index 6a8ba0944..cad08ae37 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItem.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItem.java @@ -15,17 +15,22 @@ import java.util.List; import java.util.UUID; public class PlayerListItem implements MinecraftPacket { - private Action action; + public static final int ADD_PLAYER = 0; + public static final int UPDATE_GAMEMODE = 1; + public static final int UPDATE_LATENCY = 2; + public static final int UPDATE_DISPLAY_NAME = 3; + public static final int REMOVE_PLAYER = 4; + private int action; private List items; - public PlayerListItem(Action action, List items) { + public PlayerListItem(int action, List items) { this.action = action; this.items = items; } public PlayerListItem() {} - public Action getAction() { + public int getAction() { return action; } @@ -35,7 +40,7 @@ public class PlayerListItem implements MinecraftPacket { @Override public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { - action = Action.values()[ProtocolUtils.readVarInt(buf)]; + action = ProtocolUtils.readVarInt(buf); items = new ArrayList<>(); int length = ProtocolUtils.readVarInt(buf); @@ -74,7 +79,7 @@ public class PlayerListItem implements MinecraftPacket { @Override public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { - ProtocolUtils.writeVarInt(buf, action.ordinal()); + ProtocolUtils.writeVarInt(buf, action); ProtocolUtils.writeVarInt(buf, items.size()); for (Item item: items) { ProtocolUtils.writeUuid(buf, item.getUuid()); @@ -185,12 +190,4 @@ public class PlayerListItem implements MinecraftPacket { return this; } } - - public enum Action { - ADD_PLAYER, - UPDATE_GAMEMODE, - UPDATE_LATENCY, - UPDATE_DISPLAY_NAME, - REMOVE_PLAYER - } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java index 2edc3f2a3..153c1b339 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java @@ -40,7 +40,7 @@ public class VelocityTabList implements TabList { Preconditions.checkArgument(!entries.containsKey(entry.getProfile().idAsUuid()), "this TabList already contains an entry with the same uuid"); PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry); - connection.write(new PlayerListItem(PlayerListItem.Action.ADD_PLAYER, Collections.singletonList(packetItem))); + connection.write(new PlayerListItem(PlayerListItem.ADD_PLAYER, Collections.singletonList(packetItem))); entries.put(entry.getProfile().idAsUuid(), entry); } @@ -49,7 +49,7 @@ public class VelocityTabList implements TabList { TabListEntry entry = entries.remove(uuid); if (entry != null) { PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry); - connection.write(new PlayerListItem(PlayerListItem.Action.REMOVE_PLAYER, Collections.singletonList(packetItem))); + connection.write(new PlayerListItem(PlayerListItem.REMOVE_PLAYER, Collections.singletonList(packetItem))); } return Optional.ofNullable(entry); @@ -61,7 +61,7 @@ public class VelocityTabList implements TabList { items.add(PlayerListItem.Item.from(value)); } entries.clear(); - connection.delayedWrite(new PlayerListItem(PlayerListItem.Action.REMOVE_PLAYER, items)); + connection.delayedWrite(new PlayerListItem(PlayerListItem.REMOVE_PLAYER, items)); } @Override @@ -78,13 +78,13 @@ public class VelocityTabList implements TabList { //Packets are already forwarded on, so no need to do that here for (PlayerListItem.Item item : packet.getItems()) { UUID uuid = item.getUuid(); - if (packet.getAction() != PlayerListItem.Action.ADD_PLAYER && !entries.containsKey(uuid)) { + if (packet.getAction() != PlayerListItem.ADD_PLAYER && !entries.containsKey(uuid)) { //Sometimes UPDATE_GAMEMODE is sent before ADD_PLAYER so don't want to warn here continue; } switch (packet.getAction()) { - case ADD_PLAYER: + case PlayerListItem.ADD_PLAYER: entries.put(item.getUuid(), TabListEntry.builder() .tabList(this) .profile(new GameProfile(UuidUtils.toUndashed(uuid), item.getName(), item.getProperties())) @@ -93,23 +93,23 @@ public class VelocityTabList implements TabList { .gameMode(item.getGameMode()) .build()); break; - case REMOVE_PLAYER: + case PlayerListItem.REMOVE_PLAYER: entries.remove(uuid); break; - case UPDATE_DISPLAY_NAME: + case PlayerListItem.UPDATE_DISPLAY_NAME: entries.get(uuid).setDisplayName(item.getDisplayName()); break; - case UPDATE_LATENCY: + case PlayerListItem.UPDATE_LATENCY: entries.get(uuid).setLatency(item.getLatency()); break; - case UPDATE_GAMEMODE: + case PlayerListItem.UPDATE_GAMEMODE: entries.get(uuid).setGameMode(item.getGameMode()); break; } } } - void updateEntry(PlayerListItem.Action action, TabListEntry entry) { + void updateEntry(int action, TabListEntry entry) { if (entries.containsKey(entry.getProfile().idAsUuid())) { PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry); connection.write(new PlayerListItem(action, Collections.singletonList(packetItem))); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java index 43862c874..bc60d73ca 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java @@ -42,7 +42,7 @@ public class VelocityTabListEntry implements TabListEntry { @Override public TabListEntry setDisplayName(@Nullable Component displayName) { this.displayName = displayName; - tabList.updateEntry(PlayerListItem.Action.UPDATE_DISPLAY_NAME, this); + tabList.updateEntry(PlayerListItem.UPDATE_DISPLAY_NAME, this); return this; } @@ -54,7 +54,7 @@ public class VelocityTabListEntry implements TabListEntry { @Override public TabListEntry setLatency(int latency) { this.latency = latency; - tabList.updateEntry(PlayerListItem.Action.UPDATE_LATENCY, this); + tabList.updateEntry(PlayerListItem.UPDATE_LATENCY, this); return this; } @@ -66,7 +66,7 @@ public class VelocityTabListEntry implements TabListEntry { @Override public TabListEntry setGameMode(int gameMode) { this.gameMode = gameMode; - tabList.updateEntry(PlayerListItem.Action.UPDATE_GAMEMODE, this); + tabList.updateEntry(PlayerListItem.UPDATE_GAMEMODE, this); return this; } }