Question How to spawn a offline player?

xing

New member
Apr 19, 2023
1
0
1
I'm creating a NPC, I need it to act as a normal player.
I used Bukkit.createProfile("testname");profile.complete().Then I got a offlineplayer object but I don't know how to convert it to Player object.
"Bukkit.getOfflinePlayer("testname").player"(kotlin code) returns null except I login using MC client.
 
Version Output
This server is running Paper version git-Paper-513 (MC: 1.19.4) (Implementing API version 1.19.4-R0.1-SNAPSHOT) (Git: 6d2121e)

BlackPoison357

New member
Mar 5, 2023
4
0
1
What do you currently have? Simply creating the npc and have it represent a player is on the easier side, something like this should work (not tested). The acting like a player is tricker a player can do so much, it would depend on what exactly you want this npc to do as a player. Could use CitizensAPI, would would make this part easier.
Java:
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer("testname");
Player player = new CraftPlayer((CraftServer) Bukkit.getServer(), offlinePlayer.getProfile());