13
0
geforkt von Mirrors/Velocity

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);
/**
* Gets a game profile properties of player
* @return a immutable list of properties
* Gets the player's profile properties.
*
* <p>The returned list may be unmodifiable.</p>
*
* @return the player's profile properties
*/
List<GameProfile.Property> 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<GameProfile.Property> 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();

Datei anzeigen

@ -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 {
* <li>Adventure</li>
* <li>Spectator</li>
* </ol>
* @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
*/

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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<Item> items;
public PlayerListItem(Action action, List<Item> items) {
public PlayerListItem(int action, List<Item> 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
}
}

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");
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)));

Datei anzeigen

@ -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;
}
}