3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Change player info action enum to int

Read & write server id
Fix javadocs
Dieser Commit ist enthalten in:
kashike 2018-10-13 00:13:48 -07:00
Ursprung 33f333d8cc
Commit 78abba56af
7 geänderte Dateien mit 40 neuen und 38 gelöschten Zeilen

Datei anzeigen

@ -81,14 +81,18 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
ConnectionRequestBuilder createConnectionRequest(@NonNull RegisteredServer server); ConnectionRequestBuilder createConnectionRequest(@NonNull RegisteredServer server);
/** /**
* Gets a game profile properties of player * Gets the player's profile properties.
* @return a immutable list of properties *
* <p>The returned list may be unmodifiable.</p>
*
* @return the player's profile properties
*/ */
List<GameProfile.Property> getGameProfileProperties(); List<GameProfile.Property> getGameProfileProperties();
/** /**
* Sets a GameProfile properties({@link GameProfile.Property) * Sets the player's profile properties.
* @param properties a properties to set *
* @param properties the properties
*/ */
void setGameProfileProperties(List<GameProfile.Property> properties); void setGameProfileProperties(List<GameProfile.Property> properties);
@ -109,7 +113,7 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
void clearHeaderAndFooter(); void clearHeaderAndFooter();
/** /**
* Returns {@link this} {@link Player}'s tab list. * Returns the player's tab list.
* @return this player's tab list * @return this player's tab list
*/ */
TabList getTabList(); TabList getTabList();

Datei anzeigen

@ -59,7 +59,7 @@ public interface TabListEntry {
/** /**
* Sets the latency for {@code this} entry to the specified value * Sets the latency for {@code this} entry to the specified value
* @see this#getLatency() * @see #getLatency()
* @param latency to changed to * @param latency to changed to
* @return {@code this}, for chaining * @return {@code this}, for chaining
*/ */
@ -74,13 +74,13 @@ public interface TabListEntry {
* <li>Adventure</li> * <li>Adventure</li>
* <li>Spectator</li> * <li>Spectator</li>
* </ol> * </ol>
* @return * @return the game mode
*/ */
int getGameMode(); int getGameMode();
/** /**
* Sets the game mode for {@code this} entry to the specified value * Sets the game mode for {@code this} entry to the specified value
* @see this#getGameMode() * @see #getGameMode()
* @param gameMode to change to * @param gameMode to change to
* @return {@code this}, for chaining * @return {@code this}, for chaining
*/ */

Datei anzeigen

@ -64,10 +64,10 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
@Override @Override
public boolean handle(BossBar packet) { public boolean handle(BossBar packet) {
switch (packet.getAction()) { switch (packet.getAction()) {
case 0: // add case BossBar.ADD:
playerSessionHandler.getServerBossBars().add(packet.getUuid()); playerSessionHandler.getServerBossBars().add(packet.getUuid());
break; break;
case 1: // remove case BossBar.REMOVE:
playerSessionHandler.getServerBossBars().remove(packet.getUuid()); playerSessionHandler.getServerBossBars().remove(packet.getUuid());
break; break;
} }

Datei anzeigen

@ -9,6 +9,7 @@ import io.netty.buffer.ByteBuf;
import java.util.Arrays; import java.util.Arrays;
public class EncryptionRequest implements MinecraftPacket { public class EncryptionRequest implements MinecraftPacket {
private String serverId;
private byte[] publicKey; private byte[] publicKey;
private byte[] verifyToken; private byte[] verifyToken;
@ -38,14 +39,14 @@ public class EncryptionRequest implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { 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); publicKey = ProtocolUtils.readByteArray(buf, 256);
verifyToken = ProtocolUtils.readByteArray(buf, 16); verifyToken = ProtocolUtils.readByteArray(buf, 16);
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { 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, publicKey);
ProtocolUtils.writeByteArray(buf, verifyToken); ProtocolUtils.writeByteArray(buf, verifyToken);
} }

Datei anzeigen

@ -15,17 +15,22 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
public class PlayerListItem implements MinecraftPacket { 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<Item> items; private List<Item> items;
public PlayerListItem(Action action, List<Item> items) { public PlayerListItem(int action, List<Item> items) {
this.action = action; this.action = action;
this.items = items; this.items = items;
} }
public PlayerListItem() {} public PlayerListItem() {}
public Action getAction() { public int getAction() {
return action; return action;
} }
@ -35,7 +40,7 @@ public class PlayerListItem implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
action = Action.values()[ProtocolUtils.readVarInt(buf)]; action = ProtocolUtils.readVarInt(buf);
items = new ArrayList<>(); items = new ArrayList<>();
int length = ProtocolUtils.readVarInt(buf); int length = ProtocolUtils.readVarInt(buf);
@ -74,7 +79,7 @@ public class PlayerListItem implements MinecraftPacket {
@Override @Override
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
ProtocolUtils.writeVarInt(buf, action.ordinal()); ProtocolUtils.writeVarInt(buf, action);
ProtocolUtils.writeVarInt(buf, items.size()); ProtocolUtils.writeVarInt(buf, items.size());
for (Item item: items) { for (Item item: items) {
ProtocolUtils.writeUuid(buf, item.getUuid()); ProtocolUtils.writeUuid(buf, item.getUuid());
@ -185,12 +190,4 @@ public class PlayerListItem implements MinecraftPacket {
return this; return this;
} }
} }
public enum Action {
ADD_PLAYER,
UPDATE_GAMEMODE,
UPDATE_LATENCY,
UPDATE_DISPLAY_NAME,
REMOVE_PLAYER
}
} }

Datei anzeigen

@ -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"); Preconditions.checkArgument(!entries.containsKey(entry.getProfile().idAsUuid()), "this TabList already contains an entry with the same uuid");
PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry); 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); entries.put(entry.getProfile().idAsUuid(), entry);
} }
@ -49,7 +49,7 @@ public class VelocityTabList implements TabList {
TabListEntry entry = entries.remove(uuid); TabListEntry entry = entries.remove(uuid);
if (entry != null) { if (entry != null) {
PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry); 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); return Optional.ofNullable(entry);
@ -61,7 +61,7 @@ public class VelocityTabList implements TabList {
items.add(PlayerListItem.Item.from(value)); items.add(PlayerListItem.Item.from(value));
} }
entries.clear(); entries.clear();
connection.delayedWrite(new PlayerListItem(PlayerListItem.Action.REMOVE_PLAYER, items)); connection.delayedWrite(new PlayerListItem(PlayerListItem.REMOVE_PLAYER, items));
} }
@Override @Override
@ -78,13 +78,13 @@ public class VelocityTabList implements TabList {
//Packets are already forwarded on, so no need to do that here //Packets are already forwarded on, so no need to do that here
for (PlayerListItem.Item item : packet.getItems()) { for (PlayerListItem.Item item : packet.getItems()) {
UUID uuid = item.getUuid(); 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 //Sometimes UPDATE_GAMEMODE is sent before ADD_PLAYER so don't want to warn here
continue; continue;
} }
switch (packet.getAction()) { switch (packet.getAction()) {
case ADD_PLAYER: case PlayerListItem.ADD_PLAYER:
entries.put(item.getUuid(), TabListEntry.builder() entries.put(item.getUuid(), TabListEntry.builder()
.tabList(this) .tabList(this)
.profile(new GameProfile(UuidUtils.toUndashed(uuid), item.getName(), item.getProperties())) .profile(new GameProfile(UuidUtils.toUndashed(uuid), item.getName(), item.getProperties()))
@ -93,23 +93,23 @@ public class VelocityTabList implements TabList {
.gameMode(item.getGameMode()) .gameMode(item.getGameMode())
.build()); .build());
break; break;
case REMOVE_PLAYER: case PlayerListItem.REMOVE_PLAYER:
entries.remove(uuid); entries.remove(uuid);
break; break;
case UPDATE_DISPLAY_NAME: case PlayerListItem.UPDATE_DISPLAY_NAME:
entries.get(uuid).setDisplayName(item.getDisplayName()); entries.get(uuid).setDisplayName(item.getDisplayName());
break; break;
case UPDATE_LATENCY: case PlayerListItem.UPDATE_LATENCY:
entries.get(uuid).setLatency(item.getLatency()); entries.get(uuid).setLatency(item.getLatency());
break; break;
case UPDATE_GAMEMODE: case PlayerListItem.UPDATE_GAMEMODE:
entries.get(uuid).setGameMode(item.getGameMode()); entries.get(uuid).setGameMode(item.getGameMode());
break; break;
} }
} }
} }
void updateEntry(PlayerListItem.Action action, TabListEntry entry) { void updateEntry(int action, TabListEntry entry) {
if (entries.containsKey(entry.getProfile().idAsUuid())) { if (entries.containsKey(entry.getProfile().idAsUuid())) {
PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry); PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry);
connection.write(new PlayerListItem(action, Collections.singletonList(packetItem))); connection.write(new PlayerListItem(action, Collections.singletonList(packetItem)));

Datei anzeigen

@ -42,7 +42,7 @@ public class VelocityTabListEntry implements TabListEntry {
@Override @Override
public TabListEntry setDisplayName(@Nullable Component displayName) { public TabListEntry setDisplayName(@Nullable Component displayName) {
this.displayName = displayName; this.displayName = displayName;
tabList.updateEntry(PlayerListItem.Action.UPDATE_DISPLAY_NAME, this); tabList.updateEntry(PlayerListItem.UPDATE_DISPLAY_NAME, this);
return this; return this;
} }
@ -54,7 +54,7 @@ public class VelocityTabListEntry implements TabListEntry {
@Override @Override
public TabListEntry setLatency(int latency) { public TabListEntry setLatency(int latency) {
this.latency = latency; this.latency = latency;
tabList.updateEntry(PlayerListItem.Action.UPDATE_LATENCY, this); tabList.updateEntry(PlayerListItem.UPDATE_LATENCY, this);
return this; return this;
} }
@ -66,7 +66,7 @@ public class VelocityTabListEntry implements TabListEntry {
@Override @Override
public TabListEntry setGameMode(int gameMode) { public TabListEntry setGameMode(int gameMode) {
this.gameMode = gameMode; this.gameMode = gameMode;
tabList.updateEntry(PlayerListItem.Action.UPDATE_GAMEMODE, this); tabList.updateEntry(PlayerListItem.UPDATE_GAMEMODE, this);
return this; return this;
} }
} }