PlayerInfoDataLists containing null PlayerInfoData #92
ytnoos opened this issue ยท 4 comments
if(packetContainer.getType() == PacketType.Play.Server.PLAYER_INFO) {
int i = 0;
System.out.println("data list size : " + packetContainer.getPlayerInfoDataLists().getValues().size());
for (List<PlayerInfoData> value : packetContainer.getPlayerInfoDataLists().getValues()) {
List<PlayerInfoData> item = new ArrayList<>();
System.out.println("value size : " + value.size());
for (PlayerInfoData playerInfoData : value) {
System.out.println(playerInfoData);
}
}
}
I managed to fix by skipping null values in the for (are they supposed to be null? I think the List should just not contain them) but now I have another Exception
Error: https://pastebin.com/45epNvDj
Code; https://pastebin.com/6yGKgrcR
So, this is my new code
and this the error https://pastebin.com/apGhXgwn where ProtocolLibListener.java:104 corresponds to packetContainer.getPlayerInfoDataLists().write(0, newDatas);
Okay, apparently, you need to change the index from 0 to 1 as the newly introduced set of actions also inherits the Collection
interface @ytnoos . Like so:
List<PlayerInfoData> value = packetContainer.getPlayerInfoDataLists().read(1);
// your code to modify "value"
packetContainer.getPlayerInfoDataLists().write(1, value);
According to the stack trace you sent, PlayerInfoData.getProfile()
is null and not the PlayInfoData
itself. Starting with MC 1.19.3, the PlayerInfoData only contains values for fields that are specified in getPlayerInfoActions().read(0)
. For example, if only the action UPDATE_GAME_MODE
action is sent, you will be able to access PlayerInfoData.getProfileId()
and the PalyerInfoData.getGameMode()
but not PlayerInfoData.getProfile()
. So the solution for your case would be:
if(!packetContainer.getPlayerInfoActions().read(0).contains(PlayerInfoAction.UPDATE_GAME_MODE)) {
continue;
}
Also, the packet may contain only one PlayerInfoDataList structure so you do not need the outer loop and can just do something like this:
List<PlayerInfoData> value = packetContainer.getPlayerInfoDataLists().read(0);
// your code to modify "value"
packetContainer.getPlayerInfoDataLists().write(0, value);