Skip to content

Commit

Permalink
[Bukkit & Fabric] Update to 24w44a (predicted on Bukkit)
Browse files Browse the repository at this point in the history
  • Loading branch information
NEZNAMY committed Oct 31, 2024
1 parent d285544 commit 918620a
Show file tree
Hide file tree
Showing 30 changed files with 353 additions and 111 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ val platforms = setOf(
projects.fabric,
projects.fabric.v1144,
projects.fabric.v1182,
projects.fabric.v1203
projects.fabric.v1203,
projects.fabric.v1213
).map { it.dependencyProject }

val special = setOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
@SuppressWarnings("unused") // Used via reflection
public class PaperPacketTabList extends TabListBase<Component> {

private final EnumSet<ClientboundPlayerInfoUpdatePacket.Action> updateDisplayName = EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME);
private final EnumSet<ClientboundPlayerInfoUpdatePacket.Action> updateLatency = EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY);
private final EnumSet<ClientboundPlayerInfoUpdatePacket.Action> updateGameMode = EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE);
private final EnumSet<ClientboundPlayerInfoUpdatePacket.Action> updateListed = EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED);
private final EnumSet<ClientboundPlayerInfoUpdatePacket.Action> addPlayer = EnumSet.allOf(ClientboundPlayerInfoUpdatePacket.Action.class);
private static final EnumSet<ClientboundPlayerInfoUpdatePacket.Action> updateDisplayName = EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME);
private static final EnumSet<ClientboundPlayerInfoUpdatePacket.Action> updateLatency = EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY);
private static final EnumSet<ClientboundPlayerInfoUpdatePacket.Action> updateGameMode = EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE);
private static final EnumSet<ClientboundPlayerInfoUpdatePacket.Action> updateListed = EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED);
private static final EnumSet<ClientboundPlayerInfoUpdatePacket.Action> addPlayer = EnumSet.allOf(ClientboundPlayerInfoUpdatePacket.Action.class);

private static final Field entries;

Expand Down Expand Up @@ -93,13 +93,18 @@ public void updateListOrder(@NonNull UUID entry, int listOrder) {
// TODO update module to 1.21.2 when it comes out
}

@Override
public void updateHat(@NonNull UUID entry, boolean showHat) {
// TODO update module to 1.21.4 when it comes out
}

@Override
public void addEntry(@NonNull UUID id, @NonNull String name, @Nullable Skin skin, boolean listed, int latency,
int gameMode, @Nullable Component displayName, int listOrder) {
int gameMode, @Nullable Component displayName, int listOrder, boolean showHat) {
sendPacket(new ClientboundPlayerInfoUpdatePacket(addPlayer, new ClientboundPlayerInfoUpdatePacket.Entry(
id, createProfile(id, name, skin), listed, latency, GameType.byId(gameMode), displayName, null
)));
// TODO update module to 1.21.2 when it comes out
// TODO update module to 1.21.4 when it comes out
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ public void updateListOrder(@NonNull UUID entry, int listOrder) {
// Shrug
}

@Override
public void updateHat(@NonNull UUID entry, boolean showHat) {
// Shrug
}

@Override
public void addEntry(@NonNull UUID id, @NonNull String name, @Nullable Skin skin, boolean listed, int latency,
int gameMode, @Nullable String displayName, int listOrder) {
int gameMode, @Nullable String displayName, int listOrder, boolean showHat) {
// Shrug
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class PacketTabList1193 extends PacketTabList18 {
private static final Map<Action, EnumSet<?>> actionToEnumSet = new EnumMap<>(Action.class);

private static boolean v1_21_2Plus;
private static boolean v1_21_4Plus;

private static Enum actionAddPlayer;
private static Enum actionUpdateDisplayName;
Expand All @@ -35,6 +36,7 @@ public class PacketTabList1193 extends PacketTabList18 {
private static Field PlayerInfoData_UUID;
private static Field PlayerInfoData_GameMode;
private static Field PlayerInfoData_Listed;
private static Field PlayerInfoData_ShowHat;
private static Field PlayerInfoData_ListOrder;
private static Field PlayerInfoData_RemoteChatSession;

Expand Down Expand Up @@ -74,7 +76,7 @@ public static void loadNew() throws ReflectiveOperationException {

loadSharedContent(playerInfoDataClass, EnumGamemodeClass);

PlayerInfoData_Listed = ReflectionUtils.getOnlyField(playerInfoDataClass, boolean.class);
PlayerInfoData_Listed = ReflectionUtils.getFields(playerInfoDataClass, boolean.class).get(0);
PlayerInfoData_GameMode = ReflectionUtils.getOnlyField(playerInfoDataClass, EnumGamemodeClass);
PlayerInfoData_RemoteChatSession = ReflectionUtils.getOnlyField(playerInfoDataClass, RemoteChatSession$Data);
PlayerInfoData_UUID = ReflectionUtils.getOnlyField(playerInfoDataClass, UUID.class);
Expand All @@ -91,10 +93,20 @@ public static void loadNew() throws ReflectiveOperationException {
actionToEnumSet.put(Action.UPDATE_LISTED, EnumSet.of(Enum.valueOf(ActionClass, Action.UPDATE_LISTED.name())));
try {
actionToEnumSet.put(Action.UPDATE_LIST_ORDER, EnumSet.of(Enum.valueOf(ActionClass, Action.UPDATE_LIST_ORDER.name())));
newPlayerInfoData = playerInfoDataClass.getConstructor(UUID.class, GameProfile.class, boolean.class, int.class,
EnumGamemodeClass, IChatBaseComponent, int.class, RemoteChatSession$Data);
PlayerInfoData_ListOrder = ReflectionUtils.getFields(playerInfoDataClass, int.class).get(1);
v1_21_2Plus = true;
try {
// 1.21.4+
actionToEnumSet.put(Action.UPDATE_HAT, EnumSet.of(Enum.valueOf(ActionClass, Action.UPDATE_HAT.name())));
PlayerInfoData_ShowHat = ReflectionUtils.getFields(playerInfoDataClass, boolean.class).get(1);
newPlayerInfoData = playerInfoDataClass.getConstructor(UUID.class, GameProfile.class, boolean.class, int.class,
EnumGamemodeClass, IChatBaseComponent, boolean.class, int.class, RemoteChatSession$Data);
v1_21_4Plus = true;
} catch (Exception ignored) {
// 1.21.2 - 1.21.3
newPlayerInfoData = playerInfoDataClass.getConstructor(UUID.class, GameProfile.class, boolean.class, int.class,
EnumGamemodeClass, IChatBaseComponent, int.class, RemoteChatSession$Data);
}
} catch (Exception ignored) {
// 1.21.1-, should have a better check
newPlayerInfoData = playerInfoDataClass.getConstructor(UUID.class, GameProfile.class, boolean.class, int.class,
Expand All @@ -111,22 +123,30 @@ public void removeEntry(@NonNull UUID entry) {
@Override
public void updateListed(@NonNull UUID entry, boolean listed) {
packetSender.sendPacket(player,
createPacket(Action.UPDATE_LISTED, entry, "", null, listed, 0, 0, null, 0));
createPacket(Action.UPDATE_LISTED, entry, "", null, listed, 0, 0, null, 0, false));
}

@Override
public void updateListOrder(@NonNull UUID entry, int listOrder) {
if (player.getPlatform().getServerVersion().getNetworkId() >= ProtocolVersion.V1_21_2.getNetworkId()) {
packetSender.sendPacket(player,
createPacket(Action.UPDATE_LIST_ORDER, entry, "", null, false, 0, 0, null, listOrder));
createPacket(Action.UPDATE_LIST_ORDER, entry, "", null, false, 0, 0, null, listOrder, false));
}
}

@Override
public void updateHat(@NonNull UUID entry, boolean showHat) {
if (player.getPlatform().getServerVersion().getNetworkId() >= ProtocolVersion.V1_21_4.getNetworkId()) {
packetSender.sendPacket(player,
createPacket(Action.UPDATE_HAT, entry, "", null, false, 0, 0, null, 0, showHat));
}
}

@SneakyThrows
@NotNull
@Override
public Object createPacket(@NonNull Action action, @NonNull UUID id, @NonNull String name, @Nullable Skin skin,
boolean listed, int latency, int gameMode, @Nullable Object displayName, int listOrder) {
boolean listed, int latency, int gameMode, @Nullable Object displayName, int listOrder, boolean showHat) {
Object packet = newPlayerInfo.newInstance(actionToEnumSet.get(action), Collections.emptyList());
PLAYERS.set(packet, Collections.singletonList(newPlayerInfoData(
id,
Expand All @@ -135,6 +155,7 @@ public Object createPacket(@NonNull Action action, @NonNull UUID id, @NonNull St
latency,
gameModes[gameMode],
displayName,
showHat,
listOrder,
null
)));
Expand All @@ -155,6 +176,7 @@ public void onPacketSend(@NonNull Object packet) {
Object displayName = PlayerInfoData_DisplayName.get(nmsData);
int latency = PlayerInfoData_Latency.getInt(nmsData);
int listOrder = v1_21_2Plus ? PlayerInfoData_ListOrder.getInt(nmsData) : 0;
boolean showHat = v1_21_4Plus && PlayerInfoData_ShowHat.getBoolean(nmsData);
if (actions.contains(actionUpdateDisplayName)) {
Object expectedName = getExpectedDisplayNames().get(id);
if (expectedName != null && expectedName != displayName) {
Expand All @@ -180,6 +202,7 @@ public void onPacketSend(@NonNull Object packet) {
latency,
PlayerInfoData_GameMode.get(nmsData),
displayName,
showHat,
listOrder,
PlayerInfoData_RemoteChatSession.get(nmsData)) : nmsData);
}
Expand All @@ -189,11 +212,13 @@ public void onPacketSend(@NonNull Object packet) {
@NotNull
@SneakyThrows
private static Object newPlayerInfoData(@NotNull UUID id, @Nullable GameProfile profile, boolean listed, int latency,
@Nullable Object gameMode, @Nullable Object displayName, int listOrder, @Nullable Object chatSession) {
if (v1_21_2Plus) {
return newPlayerInfoData.newInstance(id, profile, listed, latency, gameMode, displayName, listOrder, chatSession);
@Nullable Object gameMode, @Nullable Object displayName, boolean showHat, int listOrder, @Nullable Object chatSession) {
if (v1_21_4Plus) {
return newPlayerInfoData.newInstance(id, profile, listed, latency, gameMode, displayName, showHat, listOrder, chatSession);
} else if (v1_21_2Plus) {
return newPlayerInfoData.newInstance(id, profile, listed, latency, gameMode, displayName, listOrder, chatSession);
} else {
return newPlayerInfoData.newInstance(id, profile, listed, latency, gameMode, displayName, chatSession);
return newPlayerInfoData.newInstance(id, profile, listed, latency, gameMode, displayName, chatSession);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void removeEntry(@NonNull UUID entry) {
public void updateDisplayName(@NonNull UUID entry, @Nullable String displayName) {
if (!displayNames.containsKey(entry)) return; // Entry not tracked by TAB
packetSender.sendPacket(player, newPacket.apply(displayNames.get(entry), false, 0));
addEntry(entry, userNames.get(entry), null, false, 0, 0, displayName, 0);
addEntry(entry, userNames.get(entry), null, false, 0, 0, displayName, 0, false);
}

@Override
Expand All @@ -111,10 +111,15 @@ public void updateListOrder(@NonNull UUID entry, int listOrder) {
// Added in 1.21.2
}

@Override
public void updateHat(@NonNull UUID entry, boolean showHat) {
// Added in 1.21.4
}

@Override
@SneakyThrows
public void addEntry(@NonNull UUID id, @NonNull String name, @Nullable Skin skin, boolean listed, int latency,
int gameMode, @Nullable String displayName, int listOrder) {
int gameMode, @Nullable String displayName, int listOrder, boolean showHat) {
String display = displayName == null ? name : displayName;
packetSender.sendPacket(player, newPacket.apply(display, true, latency));
userNames.put(id, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,25 @@ protected static void loadSharedContent(Class<?> infoData, Class<Enum> gameMode)
@Override
public void removeEntry(@NonNull UUID entry) {
packetSender.sendPacket(player,
createPacket(Action.REMOVE_PLAYER, entry, "", null, false, 0, 0, null, 0));
createPacket(Action.REMOVE_PLAYER, entry, "", null, false, 0, 0, null, 0, false));
}

@Override
public void updateDisplayName(@NonNull UUID entry, @Nullable Object displayName) {
packetSender.sendPacket(player,
createPacket(Action.UPDATE_DISPLAY_NAME, entry, "", null, false, 0, 0, displayName, 0));
createPacket(Action.UPDATE_DISPLAY_NAME, entry, "", null, false, 0, 0, displayName, 0, false));
}

@Override
public void updateLatency(@NonNull UUID entry, int latency) {
packetSender.sendPacket(player,
createPacket(Action.UPDATE_LATENCY, entry, "", null, false, latency, 0, null, 0));
createPacket(Action.UPDATE_LATENCY, entry, "", null, false, latency, 0, null, 0, false));
}

@Override
public void updateGameMode(@NonNull UUID entry, int gameMode) {
packetSender.sendPacket(player,
createPacket(Action.UPDATE_GAME_MODE, entry, "", null, false, 0, gameMode, null, 0));
createPacket(Action.UPDATE_GAME_MODE, entry, "", null, false, 0, gameMode, null, 0, false));
}

@Override
Expand All @@ -143,11 +143,16 @@ public void updateListOrder(@NonNull UUID entry, int listOrder) {
// Added in 1.21.2
}

@Override
public void updateHat(@NonNull UUID entry, boolean showHat) {
// Added in 1.21.4
}

@Override
public void addEntry(@NonNull UUID id, @NonNull String name, @Nullable Skin skin, boolean listed, int latency,
int gameMode, @Nullable Object displayName, int listOrder) {
int gameMode, @Nullable Object displayName, int listOrder, boolean showHat) {
packetSender.sendPacket(player,
createPacket(Action.ADD_PLAYER, id, name, skin, listed, latency, gameMode, displayName, listOrder));
createPacket(Action.ADD_PLAYER, id, name, skin, listed, latency, gameMode, displayName, listOrder, showHat));
}

/**
Expand All @@ -171,12 +176,14 @@ public void addEntry(@NonNull UUID id, @NonNull String name, @Nullable Skin skin
* Entry display name
* @param listOrder
* Entry list order
* @param showHat
* Show hat flag
* @return Packet from given parameters
*/
@SneakyThrows
@NotNull
public Object createPacket(@NonNull Action action, @NonNull UUID id, @NonNull String name, @Nullable Skin skin,
boolean listed, int latency, int gameMode, @Nullable Object displayName, int listOrder) {
boolean listed, int latency, int gameMode, @Nullable Object displayName, int listOrder, boolean showHat) {
Object packet = newPlayerInfo.newInstance(Enum.valueOf(ActionClass, action.name()), Collections.emptyList());
List<Object> parameters = new ArrayList<>();
if (newPlayerInfoData.getParameterTypes()[0] == PlayerInfoClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ public Item item(@NonNull UUID id) {
* Entry display name
* @param listOrder
* Entry list order
* @param showHat
* Show hat flag
* @return Converted item from parameters
*/
@NotNull
public Item entryToItem(@NonNull UUID id, @NonNull String name, @Nullable Skin skin, boolean listed, int latency,
int gameMode, @Nullable BaseComponent displayName, int listOrder) {
int gameMode, @Nullable BaseComponent displayName, int listOrder, boolean showHat) {
Item item = item(id);
item.setUsername(name);
item.setDisplayName(displayName);
Expand All @@ -98,6 +100,7 @@ public Item entryToItem(@NonNull UUID id, @NonNull String name, @Nullable Skin s
item.setProperties(new Property[0]);
}
item.setListOrder(listOrder);
// TODO showHat once BungeeCord adds it
return item;
}

Expand Down
Loading

0 comments on commit 918620a

Please sign in to comment.