feat: preliminary 1.20.2 support

This commit is contained in:
ineanto 2023-10-24 07:37:34 +02:00
parent 36589747af
commit 2a326232ca
4 changed files with 50 additions and 45 deletions

10
pom.xml
View file

@ -16,6 +16,10 @@
</properties> </properties>
<repositories> <repositories>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
<repository> <repository>
<id>xenondevs</id> <id>xenondevs</id>
<url>https://repo.xenondevs.xyz/releases</url> <url>https://repo.xenondevs.xyz/releases</url>
@ -32,10 +36,6 @@
<id>placeholderapi</id> <id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url> <url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository> </repository>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -57,7 +57,7 @@
<dependency> <dependency>
<groupId>com.comphenix.protocol</groupId> <groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId> <artifactId>ProtocolLib</artifactId>
<version>5.0.1-SNAPSHOT</version> <version>5.1.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View file

@ -70,7 +70,7 @@ public class AppearanceManager {
public void updateOthers() { public void updateOthers() {
final WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy(); final WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy();
final WrapperPlayServerNamedEntitySpawn spawn = new WrapperPlayServerNamedEntitySpawn(); final WrapperPlayServerSpawnEntity spawn = new WrapperPlayServerSpawnEntity();
destroy.setEntityIds(IntList.of(player.getEntityId())); destroy.setEntityIds(IntList.of(player.getEntityId()));
spawn.setEntityId(player.getEntityId()); spawn.setEntityId(player.getEntityId());
spawn.setLocation(player.getLocation()); spawn.setLocation(player.getLocation());

View file

@ -18,28 +18,45 @@ import org.bukkit.World;
* for the PacketPlayServerRespawn. * for the PacketPlayServerRespawn.
* *
* @author ineanto, based on work from dmulloy2 and Kristian S. Strangeland * @author ineanto, based on work from dmulloy2 and Kristian S. Strangeland
* <p>
* <p>
* Packet changes history (not accurate)
* <p>
* In 1.20.2, all the fields were replaced with a
* single "CommonPlayerSpawnInfo" record object.
* <p>
* The dimension field was changed numerous times:
* - 1.8 through 1.17 (?) required an integer,
* - 1.18 need an instance of a Holder of a ResourceKey,
* - 1.19 and after dropped this requirement.
* N.b.: this field is a nightmare please mojang stop refactoring
* your code to change things that were working perfectly fine before
* <p>
* The Seed field was added in 1.15.
* The Difficulty field was removed in 1.14.
*/ */
public class WrapperPlayServerRespawn extends AbstractPacket { public class WrapperPlayServerRespawn extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.RESPAWN; public static final PacketType TYPE = PacketType.Play.Server.RESPAWN;
private InternalStructure commonPlayerSpawnInfoStructure;
public WrapperPlayServerRespawn() { public WrapperPlayServerRespawn() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
commonPlayerSpawnInfoStructure = handle.getStructures().read(0);
}
} }
//.............
// Dimension/World Field
// The dimension field has changed numerous times:
// - 1.8 through 1.17 (?) need an integer,
// - 1.18 need a Holder of a World ResourceKey,
// - 1.19 and beyond don't require a Holder.
//
// n.b.: this field is a nightmare please mojang stop refactoring
// your code to change things that were working perfectly fine before
//.............
public void setDimension(World value) { public void setDimension(World value) {
if (MinecraftVersion.WILD_UPDATE.atOrAbove()) { if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
// 1.20.2
final InternalStructure dimensionType = commonPlayerSpawnInfoStructure.getStructures().read(0);
dimensionType.getMinecraftKeys().write(0, new MinecraftKey("minecraft", "dimension_type"));
dimensionType.getMinecraftKeys().write(1, new MinecraftKey("minecraft", "overworld"));
commonPlayerSpawnInfoStructure.getStructures().write(0, dimensionType);
commonPlayerSpawnInfoStructure.getWorldKeys().write(0, value);
} else if (MinecraftVersion.WILD_UPDATE.atOrAbove()) {
// 1.19 to 1.20.1 // 1.19 to 1.20.1
// Thank you lukalt! // Thank you lukalt!
final InternalStructure dimensionType = handle.getStructures().read(0); final InternalStructure dimensionType = handle.getStructures().read(0);
@ -59,50 +76,38 @@ public class WrapperPlayServerRespawn extends AbstractPacket {
} }
} }
//.............
// GameMode Field
//.............
public void setGameMode(GameMode value) { public void setGameMode(GameMode value) {
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
commonPlayerSpawnInfoStructure.getGameModes().write(0, EnumWrappers.NativeGameMode.fromBukkit(value));
return;
}
handle.getGameModes().write(0, EnumWrappers.NativeGameMode.fromBukkit(value)); handle.getGameModes().write(0, EnumWrappers.NativeGameMode.fromBukkit(value));
} }
//.............
// Previous GameMode Field
//.............
public void setPreviousGameMode(GameMode value) { public void setPreviousGameMode(GameMode value) {
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
commonPlayerSpawnInfoStructure.getGameModes().write(1, EnumWrappers.NativeGameMode.fromBukkit(value));
return;
}
handle.getGameModes().write(1, EnumWrappers.NativeGameMode.fromBukkit(value)); handle.getGameModes().write(1, EnumWrappers.NativeGameMode.fromBukkit(value));
} }
//.............
// Copy Metadata Field
//.............
public void setCopyMetadata(boolean value) { public void setCopyMetadata(boolean value) {
if(MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) return;
if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
handle.getBytes().write(0, ((byte) (value ? 0x01 : 0x00))); handle.getBytes().write(0, ((byte) (value ? 0x01 : 0x00)));
} else { } else {
handle.getBooleans().write(0, value); handle.getBooleans().write(0, value);
} }
} }
//.............
// Seed Field
// Added in 1.15.
//.............
public void setSeed(long value) { public void setSeed(long value) {
if (MinecraftVersion.BEE_UPDATE.atOrAbove()) { if (MinecraftVersion.BEE_UPDATE.atOrAbove() && !MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
handle.getLongs().write(0, Hashing.sha256().hashLong(value).asLong()); handle.getLongs().write(0, Hashing.sha256().hashLong(value).asLong());
} }
} }
//.............
// Difficulty Field
// Removed in 1.14.
//.............
public void setDifficulty(Difficulty difficulty) { public void setDifficulty(Difficulty difficulty) {
if (difficulty != null && !MinecraftVersion.VILLAGE_UPDATE.atOrAbove()) { if (difficulty != null && !MinecraftVersion.VILLAGE_UPDATE.atOrAbove()) {
handle.getDifficulties().write(0, EnumWrappers.Difficulty.valueOf(difficulty.name())); handle.getDifficulties().write(0, EnumWrappers.Difficulty.valueOf(difficulty.name()));

View file

@ -12,16 +12,16 @@ import java.util.UUID;
/** /**
* This packet is sent by the server when a player comes into visible range, not when a player joins. * This packet is sent by the server when a player comes into visible range, not when a player joins.
*/ */
public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket { public class WrapperPlayServerSpawnEntity extends AbstractPacket {
/** /**
* The packet type that is wrapped by this wrapper. * The packet type that is wrapped by this wrapper.
*/ */
public static final PacketType TYPE = PacketType.Play.Server.NAMED_ENTITY_SPAWN; public static final PacketType TYPE = PacketType.Play.Server.SPAWN_ENTITY;
/** /**
* Constructors a new wrapper for the specified packet * Constructors a new wrapper for the specified packet
*/ */
public WrapperPlayServerNamedEntitySpawn() { public WrapperPlayServerSpawnEntity() {
super(new PacketContainer(TYPE), TYPE); super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }