feat(wrapper): handle previous versions

This commit is contained in:
ineanto 2023-05-29 14:01:30 +02:00
parent 04fbcd99ba
commit 584b34fd51
3 changed files with 35 additions and 24 deletions

View file

@ -150,24 +150,32 @@ public class AppearanceManager {
respawn.setGameMode(player.getGameMode()); respawn.setGameMode(player.getGameMode());
respawn.setPreviousGameMode(player.getGameMode()); respawn.setPreviousGameMode(player.getGameMode());
respawn.setDifficulty(world.getDifficulty()); respawn.setDifficulty(world.getDifficulty());
respawn.setCopyMetadata(false); respawn.setCopyMetadata(true);
respawn.getHandle().getBooleans().write(0, false); // is debug
respawn.getHandle().getBooleans().write(0, false); // is flat
respawn.sendPacket(player); respawn.sendPacket(player);
} }
private void updateTabList(WrappedGameProfile gameProfile, String displayName) { private void updateTabList(WrappedGameProfile gameProfile, String displayName) {
final WrapperPlayerServerPlayerInfo add = new WrapperPlayerServerPlayerInfo();
if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
final WrapperPlayerServerPlayerInfoRemove remove = new WrapperPlayerServerPlayerInfoRemove(); final WrapperPlayerServerPlayerInfoRemove remove = new WrapperPlayerServerPlayerInfoRemove();
final WrapperPlayerServerPlayerInfo update = new WrapperPlayerServerPlayerInfo();
final EnumSet<EnumWrappers.PlayerInfoAction> actions = EnumSet.of( final EnumSet<EnumWrappers.PlayerInfoAction> actions = EnumSet.of(
EnumWrappers.PlayerInfoAction.REMOVE_PLAYER, // Necessary for 1.19.2 and below
EnumWrappers.PlayerInfoAction.ADD_PLAYER, EnumWrappers.PlayerInfoAction.ADD_PLAYER,
EnumWrappers.PlayerInfoAction.INITIALIZE_CHAT, EnumWrappers.PlayerInfoAction.INITIALIZE_CHAT,
EnumWrappers.PlayerInfoAction.UPDATE_LISTED, EnumWrappers.PlayerInfoAction.UPDATE_LISTED,
EnumWrappers.PlayerInfoAction.UPDATE_DISPLAY_NAME, EnumWrappers.PlayerInfoAction.UPDATE_DISPLAY_NAME,
EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE,
EnumWrappers.PlayerInfoAction.UPDATE_LATENCY); EnumWrappers.PlayerInfoAction.UPDATE_LATENCY);
update.setData(ImmutableList.of(new PlayerInfoData( remove.setUUIDs(ImmutableList.of(player.getUniqueId()));
remove.sendPacket(player);
add.setActions(actions);
} else {
final WrapperPlayerServerPlayerInfo remove = new WrapperPlayerServerPlayerInfo();
remove.setActions(EnumSet.of(EnumWrappers.PlayerInfoAction.REMOVE_PLAYER));
add.setActions(EnumSet.of(EnumWrappers.PlayerInfoAction.ADD_PLAYER));
remove.sendPacket(player);
}
add.setData(ImmutableList.of(new PlayerInfoData(
player.getUniqueId(), player.getUniqueId(),
player.getPing(), player.getPing(),
true, true,
@ -180,12 +188,6 @@ public class AppearanceManager {
// No, I'll not waste another day fixing their mess. Go cry about it to Mojang. // No, I'll not waste another day fixing their mess. Go cry about it to Mojang.
// (Long live NoEncryption!) // (Long live NoEncryption!)
))); )));
if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { add.sendPacket(player);
actions.remove(EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
remove.setUUIDs(ImmutableList.of(player.getUniqueId()));
remove.sendPacket(player);
}
update.setActions(actions);
update.sendPacket(player);
} }
} }

View file

@ -100,7 +100,11 @@ public class WrapperPlayServerRespawn extends AbstractPacket {
} }
public void setCopyMetadata(boolean value) { public void setCopyMetadata(boolean value) {
if(MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
handle.getBytes().write(0, ((byte) (value ? 0x01 : 0x00))); handle.getBytes().write(0, ((byte) (value ? 0x01 : 0x00)));
} else {
handle.getBooleans().write(0, value);
}
} }
//............. //.............

View file

@ -2,6 +2,7 @@ package xyz.atnrch.nicko.wrapper;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.utility.MinecraftVersion;
import com.comphenix.protocol.wrappers.EnumWrappers; import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.PlayerInfoData; import com.comphenix.protocol.wrappers.PlayerInfoData;
@ -32,7 +33,11 @@ public class WrapperPlayerServerPlayerInfo extends AbstractPacket {
} }
public void setActions(Set<EnumWrappers.PlayerInfoAction> value) { public void setActions(Set<EnumWrappers.PlayerInfoAction> value) {
if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
handle.getPlayerInfoActions().write(0, value); handle.getPlayerInfoActions().write(0, value);
} else {
handle.getPlayerInfoAction().write(0, value.stream().iterator().next()); // Get the first Value.
}
} }
public List<PlayerInfoData> getData() { public List<PlayerInfoData> getData() {
@ -40,6 +45,6 @@ public class WrapperPlayerServerPlayerInfo extends AbstractPacket {
} }
public void setData(List<PlayerInfoData> value) { public void setData(List<PlayerInfoData> value) {
handle.getPlayerInfoDataLists().write(1, value); handle.getPlayerInfoDataLists().write(0, value);
} }
} }