feat: player respawn support for 1.19
This commit is contained in:
parent
ac9af73fb6
commit
3ad3da9179
3 changed files with 39 additions and 44 deletions
20
pom.xml
20
pom.xml
|
@ -39,12 +39,12 @@
|
|||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!-- ProtocolLib -->
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- And so on -->
|
||||
<!-- PlaceHolder API -->
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
|
@ -52,13 +52,6 @@
|
|||
<version>2.11.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Spigot API -->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.19.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Inventory Lib -->
|
||||
<dependency>
|
||||
<groupId>xyz.xenondevs.invui</groupId>
|
||||
|
@ -97,15 +90,22 @@
|
|||
<artifactId>yamlconfig</artifactId>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
<!-- Jackson Core -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>2.13.3</version>
|
||||
<version>2.14.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.19.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
<version>2.13.3</version>
|
||||
<version>2.14.2</version>
|
||||
</dependency>
|
||||
<!-- Redis -->
|
||||
<dependency>
|
||||
|
|
|
@ -102,12 +102,14 @@ public class AppearanceManager {
|
|||
final WrappedGameProfile gameProfile = WrappedGameProfile.fromPlayer(player).withName(displayName);
|
||||
final ActionResult<Void> result = updateGameProfileSkin(gameProfile, skinChange);
|
||||
if (!result.isError()) {
|
||||
updateMetadata();
|
||||
updateTabList(gameProfile, displayName);
|
||||
respawnPlayer();
|
||||
}
|
||||
return new ActionResult<>();
|
||||
}
|
||||
|
||||
|
||||
private ActionResult<Void> updateGameProfileSkin(WrappedGameProfile gameProfile, boolean skinChange) {
|
||||
final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName());
|
||||
|
||||
|
@ -135,6 +137,11 @@ public class AppearanceManager {
|
|||
return new ActionResult<>();
|
||||
}
|
||||
|
||||
private void updateMetadata() {
|
||||
final WrappedDataWatcher entityWatcher = WrappedDataWatcher.getEntityWatcher(player);
|
||||
entityWatcher.setObject(17, (byte) 0x7f, true);
|
||||
}
|
||||
|
||||
private void respawnPlayer() {
|
||||
final World world = player.getWorld();
|
||||
final WrapperPlayServerRespawn respawn = new WrapperPlayServerRespawn();
|
||||
|
@ -145,7 +152,7 @@ public class AppearanceManager {
|
|||
respawn.setDifficulty(world.getDifficulty());
|
||||
respawn.setCopyMetadata(false);
|
||||
respawn.getHandle().getBooleans().write(0, false); // is debug
|
||||
respawn.getHandle().getBooleans().write(1, false); // is flat
|
||||
respawn.getHandle().getBooleans().write(0, false); // is flat
|
||||
respawn.sendPacket(player);
|
||||
}
|
||||
|
||||
|
@ -155,15 +162,20 @@ public class AppearanceManager {
|
|||
|
||||
final WrapperPlayerServerPlayerInfo update = new WrapperPlayerServerPlayerInfo();
|
||||
update.setActions(EnumSet.of(EnumWrappers.PlayerInfoAction.ADD_PLAYER,
|
||||
EnumWrappers.PlayerInfoAction.INITIALIZE_CHAT,
|
||||
EnumWrappers.PlayerInfoAction.UPDATE_LISTED,
|
||||
EnumWrappers.PlayerInfoAction.UPDATE_DISPLAY_NAME,
|
||||
EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE,
|
||||
EnumWrappers.PlayerInfoAction.UPDATE_LATENCY));
|
||||
update.setData(ImmutableList.of(new PlayerInfoData(
|
||||
gameProfile,
|
||||
player.getUniqueId(),
|
||||
player.getPing(),
|
||||
true,
|
||||
EnumWrappers.NativeGameMode.fromBukkit(player.getGameMode()),
|
||||
WrappedChatComponent.fromText(displayName)
|
||||
gameProfile,
|
||||
WrappedChatComponent.fromText(displayName),
|
||||
new WrappedRemoteChatSessionData(UUID.randomUUID(),
|
||||
WrappedProfilePublicKey.ofPlayer(player).getKeyData())
|
||||
)));
|
||||
remove.sendPacket(player);
|
||||
update.sendPacket(player);
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
package net.artelnatif.nicko.wrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.InternalStructure;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.BukkitConverters;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.MinecraftKey;
|
||||
import com.google.common.hash.Hashing;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Up-to-date version of the Wrapper class
|
||||
* for the PacketPlayServerRespawn.
|
||||
|
@ -50,7 +48,12 @@ public class WrapperPlayServerRespawn extends AbstractPacket {
|
|||
|
||||
public void setDimension(World value) {
|
||||
if (MinecraftVersion.WILD_UPDATE.atOrAbove()) {
|
||||
// 1.19 and above
|
||||
// 1.19 to 1.19.4
|
||||
// Thank you lukalt!
|
||||
final InternalStructure dimensionType = handle.getStructures().read(0);
|
||||
dimensionType.getMinecraftKeys().write(0, new MinecraftKey("minecraft", "dimension_type"));
|
||||
dimensionType.getMinecraftKeys().write(1, new MinecraftKey("minecraft", "overworld"));
|
||||
handle.getStructures().write(0, dimensionType);
|
||||
handle.getWorldKeys().write(0, value);
|
||||
} else if (MinecraftVersion.CAVES_CLIFFS_2.atOrAbove()) {
|
||||
// 1.18
|
||||
|
@ -100,26 +103,6 @@ public class WrapperPlayServerRespawn extends AbstractPacket {
|
|||
handle.getBytes().write(0, ((byte) (value ? 0x01 : 0x00)));
|
||||
}
|
||||
|
||||
//.............
|
||||
// Last death location Field
|
||||
// Added in 1.19.
|
||||
//.............
|
||||
|
||||
public Optional<BlockPosition> getLastDeathLocation() {
|
||||
if (MinecraftVersion.WILD_UPDATE.atOrAbove()) {
|
||||
return handle.getOptionals(BlockPosition.getConverter()).read(0);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public void setLastDeathLocation(Location value) {
|
||||
if (MinecraftVersion.WILD_UPDATE.atOrAbove()) {
|
||||
final BlockPosition locationToBlockPosition = BlockPosition.getConverter().getSpecific(value);
|
||||
final Optional<BlockPosition> blockPosition = Optional.ofNullable(locationToBlockPosition);
|
||||
handle.getOptionals(BlockPosition.getConverter()).write(0, blockPosition);
|
||||
}
|
||||
}
|
||||
|
||||
//.............
|
||||
// Seed Field
|
||||
// Added in 1.15.
|
||||
|
|
Loading…
Reference in a new issue