Hi, firstly thank you for reading this even if you don't help
So juste like said in the title i'm trying to create a fake sleeping plyaer using NMS and packets but since there is not much tutorial on how to use Packets and NMS i only managed to found one but on spigot
Tutorial in Spigot
And I managed to translate some of the functions in Paper but when it comes to using DataWatcher and Packets I didnt find what where the Paper function, i sincerely hope someone will be able to help me with that and thank you in advance
Here is a whole code
import com.mojang.authlib.GameProfile;
import fr.lvegroup.lveplugin.Data.PlayerData;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ClientInformation;
import net.minecraft.server.level.ServerPlayer;
import com.mojang.authlib.properties.Property;
import net.minecraft.server.network.ServerPlayerConnection;
import net.minecraft.world.entity.Pose;
import org.apache.logging.log4j.core.util.WrappedFileWatcher;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_20_R3.CraftServer;
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import java.util.UUID;
import static fr.lvegroup.lveplugin.LVE.getPlayerData;
public class KnockedManager {
public static void SetKO(Player player) {
PlayerData Pdata = getPlayerData(player);
Pdata.setData("KO", true);
Location playerLocation = player.getLocation();
player.setPose(org.bukkit.entity.Pose.SITTING);
}
public static void CorpseEntity(Player player){
//Creation NPC et récupération skin
ServerPlayer craftPlayer = ((CraftPlayer) player).getHandle();
Property textures = (Property) craftPlayer.getGameProfile().getProperties().get("textures").toArray()[0];
GameProfile gameProfile = new GameProfile(UUID.randomUUID(),player.getName());
gameProfile.getProperties().put("textures", new Property("textures", textures.value(), textures.signature()));
//Creation du corp par terre
ServerPlayer sleeping = new ServerPlayer(
((CraftServer) Bukkit.getServer()).getServer(),
((CraftWorld) player.getWorld()).getHandle(),
gameProfile,
ClientInformation.createDefault());
sleeping.teleportTo(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ());
//Fake Bed
Location bed = player.getLocation().add(1,0,0);
BlockPos position = new BlockPos((int) Math.floor(bed.getX()), (int) Math.floor(bed.getY()), (int) Math.floor(bed.getZ()));
sleeping.startSleeping(position);
//Hide Nametag
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
Team team = scoreboard.registerNewTeam(String.valueOf(sleeping.getDisplayName()));
team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
//Make so the Fake Player position is sleeping
sleeping.setPose(Pose.SLEEPING);
DataWatcher watcher = sleeping.getDataWatcher();
byte b = 0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40;
watcher.set(new WrappedFileWatcher.WrappedFileWatcherObject(17, DataWatcherRegistry.Byte), b);
//Make so Fake player is positioned in a diagonal way from the blocks rather than parrallel
PacketPlayOutEntity.PacketPlayOutRelEntityMove move = new PacketPlayerOutEntity.PacketPlayOutRelEntityMove(
sleeping.getId(), (byte) 0, (byte) ((player.getLocation().getY() - 1.7 - player.getLocation().getY()) *32),
(byte) 0, false);
//packet sending
for (Player on : Bukkit.getOnlinePlayers()){
ServerPlayerConnection connection = ((CraftPlayer)on).getHandle().connection;
connection.send(new PlayerPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, sleeping));
connection.send(new PlayerPlayOutNamedEntitySpawn(sleeping));
connection.sendPacket(new PacketPlayOutEntityMetadata(sleeping.getId(), watcher, true));
connection.sendPacket(move);
new BukkitRunnable(){
public void run() {
connection.sendpacket(new PlayerPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, sleeping))
}
}.runTaskAsynchronously(LVEPlugin.getPlugin(KnockedManager.class));
}
}
}
And Here is the problematic part which are the function DataWatcher, PacketPlayerOutEntity, PlayerPlayOutNamedEntitySpawn, PlayerPlayOutPlayerInfo, PacketPlayOutEntityMetadata and .sendPacket :
//Make so the Fake Player position is sleeping
sleeping.setPose(Pose.SLEEPING);
DataWatcher watcher = sleeping.getDataWatcher();
byte b = 0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40;
watcher.set(new WrappedFileWatcher.WrappedFileWatcherObject(17, DataWatcherRegistry.Byte), b);
//Make so Fake player is positioned in a diagonal way from the blocks rather than parrallel
PacketPlayOutEntity.PacketPlayOutRelEntityMove move = new PacketPlayerOutEntity.PacketPlayOutRelEntityMove(
sleeping.getId(), (byte) 0, (byte) ((player.getLocation().getY() - 1.7 - player.getLocation().getY()) *32),
(byte) 0, false);
//packet sending
for (Player on : Bukkit.getOnlinePlayers()){
ServerPlayerConnection connection = ((CraftPlayer)on).getHandle().connection;
connection.send(new PlayerPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, sleeping));
connection.send(new PlayerPlayOutNamedEntitySpawn(sleeping));
connection.sendPacket(new PacketPlayOutEntityMetadata(sleeping.getId(), watcher, true));
connection.sendPacket(move);
new BukkitRunnable(){
public void run() {
connection.sendpacket(new PlayerPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, sleeping))
}
}.runTaskAsynchronously(LVEPlugin.getPlugin(KnockedManager.class));
}
}
}
So juste like said in the title i'm trying to create a fake sleeping plyaer using NMS and packets but since there is not much tutorial on how to use Packets and NMS i only managed to found one but on spigot
Tutorial in Spigot
And I managed to translate some of the functions in Paper but when it comes to using DataWatcher and Packets I didnt find what where the Paper function, i sincerely hope someone will be able to help me with that and thank you in advance
Here is a whole code
import com.mojang.authlib.GameProfile;
import fr.lvegroup.lveplugin.Data.PlayerData;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ClientInformation;
import net.minecraft.server.level.ServerPlayer;
import com.mojang.authlib.properties.Property;
import net.minecraft.server.network.ServerPlayerConnection;
import net.minecraft.world.entity.Pose;
import org.apache.logging.log4j.core.util.WrappedFileWatcher;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_20_R3.CraftServer;
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import java.util.UUID;
import static fr.lvegroup.lveplugin.LVE.getPlayerData;
public class KnockedManager {
public static void SetKO(Player player) {
PlayerData Pdata = getPlayerData(player);
Pdata.setData("KO", true);
Location playerLocation = player.getLocation();
player.setPose(org.bukkit.entity.Pose.SITTING);
}
public static void CorpseEntity(Player player){
//Creation NPC et récupération skin
ServerPlayer craftPlayer = ((CraftPlayer) player).getHandle();
Property textures = (Property) craftPlayer.getGameProfile().getProperties().get("textures").toArray()[0];
GameProfile gameProfile = new GameProfile(UUID.randomUUID(),player.getName());
gameProfile.getProperties().put("textures", new Property("textures", textures.value(), textures.signature()));
//Creation du corp par terre
ServerPlayer sleeping = new ServerPlayer(
((CraftServer) Bukkit.getServer()).getServer(),
((CraftWorld) player.getWorld()).getHandle(),
gameProfile,
ClientInformation.createDefault());
sleeping.teleportTo(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ());
//Fake Bed
Location bed = player.getLocation().add(1,0,0);
BlockPos position = new BlockPos((int) Math.floor(bed.getX()), (int) Math.floor(bed.getY()), (int) Math.floor(bed.getZ()));
sleeping.startSleeping(position);
//Hide Nametag
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
Team team = scoreboard.registerNewTeam(String.valueOf(sleeping.getDisplayName()));
team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
//Make so the Fake Player position is sleeping
sleeping.setPose(Pose.SLEEPING);
DataWatcher watcher = sleeping.getDataWatcher();
byte b = 0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40;
watcher.set(new WrappedFileWatcher.WrappedFileWatcherObject(17, DataWatcherRegistry.Byte), b);
//Make so Fake player is positioned in a diagonal way from the blocks rather than parrallel
PacketPlayOutEntity.PacketPlayOutRelEntityMove move = new PacketPlayerOutEntity.PacketPlayOutRelEntityMove(
sleeping.getId(), (byte) 0, (byte) ((player.getLocation().getY() - 1.7 - player.getLocation().getY()) *32),
(byte) 0, false);
//packet sending
for (Player on : Bukkit.getOnlinePlayers()){
ServerPlayerConnection connection = ((CraftPlayer)on).getHandle().connection;
connection.send(new PlayerPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, sleeping));
connection.send(new PlayerPlayOutNamedEntitySpawn(sleeping));
connection.sendPacket(new PacketPlayOutEntityMetadata(sleeping.getId(), watcher, true));
connection.sendPacket(move);
new BukkitRunnable(){
public void run() {
connection.sendpacket(new PlayerPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, sleeping))
}
}.runTaskAsynchronously(LVEPlugin.getPlugin(KnockedManager.class));
}
}
}
And Here is the problematic part which are the function DataWatcher, PacketPlayerOutEntity, PlayerPlayOutNamedEntitySpawn, PlayerPlayOutPlayerInfo, PacketPlayOutEntityMetadata and .sendPacket :
//Make so the Fake Player position is sleeping
sleeping.setPose(Pose.SLEEPING);
DataWatcher watcher = sleeping.getDataWatcher();
byte b = 0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40;
watcher.set(new WrappedFileWatcher.WrappedFileWatcherObject(17, DataWatcherRegistry.Byte), b);
//Make so Fake player is positioned in a diagonal way from the blocks rather than parrallel
PacketPlayOutEntity.PacketPlayOutRelEntityMove move = new PacketPlayerOutEntity.PacketPlayOutRelEntityMove(
sleeping.getId(), (byte) 0, (byte) ((player.getLocation().getY() - 1.7 - player.getLocation().getY()) *32),
(byte) 0, false);
//packet sending
for (Player on : Bukkit.getOnlinePlayers()){
ServerPlayerConnection connection = ((CraftPlayer)on).getHandle().connection;
connection.send(new PlayerPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, sleeping));
connection.send(new PlayerPlayOutNamedEntitySpawn(sleeping));
connection.sendPacket(new PacketPlayOutEntityMetadata(sleeping.getId(), watcher, true));
connection.sendPacket(move);
new BukkitRunnable(){
public void run() {
connection.sendpacket(new PlayerPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, sleeping))
}
}.runTaskAsynchronously(LVEPlugin.getPlugin(KnockedManager.class));
}
}
}