-
Notifications
You must be signed in to change notification settings - Fork 0
Fake Players
Note
This only works for 1.20.4+
Default inside the spigot api there is not a way to spawn in fake players thats why i have added it to UndefinedAPI.
For creating an fake player you will need to get the instance of the api. (See below)
val undefinedAPI = UndefinedAPI(JavaPlugin)
When you got a instance of the api you will be able to use the createFakePlayer(String, String)
method to create a fake player. The first parameter is the name of the player and the second parameter is for the skin. (See below)
val npc = undefinedAPI.createFakePlayer("TheRedMagic", "TheRedMagic")
This method will return null if the version the server is running is not supported.
For a player to be able to see a fake player you will need to add them to the viewers list. (See below)
npc.viewers.add(player)
If you remove the player from the viewer list the player won't be able to see the fake player anymore.
npc.viewers.remove(player)
When you have added the viewers to the list you can spawn the fake player with spawn(Location)
method. This will spawn the npc at that location. (See below)
val spawnLoc = Location(Bukkit.getWorld("world"), 10.0, 10.0, 10.0)
npc.spawn(spawnLoc)
When you have spawned the player you are able to move the player in 3 different ways. The most simple is using the teleport(Location)
method. This will teleport the player to that location. (See below)
npc.teleport(newLoc)
The second method is using a method called moveTo(Location)
this will move the npc to that location with a walking animation. This method will not work if the new location is more than 8 block away. (See below)
npc.moveTo(newLoc)
Lastly we have moveOrTeleport(Location)
method. Is method will put the last two in one. It will check if the player is more than 8 blocks away if it is it will use the teleport
method if not it will use the moveTo
method. (See below)
npc.moveOrTeleport(newLoc)
Changing the skin of the player simple. You will be able to use one of two method. The first one is setSkin(String)
this one will ask you to give the username of the players skin. (See below)
npc.setSkin("SpaceNiklas")
The second method is setSkin(String, String)
this one will ask for the texture and signature of the skin. (See below)
npc.setSkin("ewogICJ0aW1lc3RhbXAiIDogMTYwMjQzOTcxMjQ4MiwKICAicHJvZmlsZUlkIiA6ICI2OTBkMDM2OGM2NTE0OGM5ODZjMzEwN2FjMmRjNjFlYyIsCiAgInByb2ZpbGVOYW1lIiA6ICJ5emZyXzciLAogICJzaWduYXR1cmVSZXF1aXJlZCIgOiB0cnVlLAogICJ0ZXh0dXJlcyIgOiB7CiAgICAiU0tJTiIgOiB7CiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZGM4Y2UwNzRmYTY4MWJmOGRjYzMyY2FiMTc5NDk5NTRmYWI2OWRjODFmZTY3NmE5NzRiNzEyYWMwMmIyNTU2ZSIKICAgIH0KICB9Cn0=", "PgMBPhOx59zlc5BiUuR6xdRJLabQc1c/Z5NhtztviVHwfHA8+nGNcofSWnC0jPPgU9i31dA6TZiuxEQb6cOpA+EED9CXWDrU5CyTxWTTnTQq/JNxfHz6+PgZ7IxFWs/DlQbpHvSCEuNaKd9I6N4cmGpZaEky8xe3rnnMUrvMESBYOM1nEiMFLeTVKZf6+TvOkq/kEDT003UVaG/adZgYX+qDDWJZm3/Bqq1N9eGsj+z05HEWeDb2meKLq9c38e1FOPKF0GkpXsL+wFcLP1pGF6vWu6cWZkL1G7h0xzTnL6AIdE1YKWw0jVux4HJ8SGEwt0iVgcEWSkXBG/cWTYe/5Lqm1Ak8Es+ryiQiz2axkAd/16+wTs9bNW3SAz5hI7ypTsB43mFUrmKgDMRh1gfy68WhA5IitkgFvq1m3LmBFGtBJpPNuDEvLyh8GWVizBkmKvcANgysuhKYqOj7mzXGPSRi6nNWDVlKaU/pv1S9iiw175NGSKgoL9BhzoEdgGaIy4oyGzONT32kBQezpMDoEnHrSWzwT/4UqLJEz3N+wOqemmwbj7HWUIBQnMmZOICoZm+BkvXNKntjLcghDkB7k6MLvpDjC2PVywyIF0EUCXqCjfolobg436kvHDNquhOocncwbIrWuGxDXbVseYZ3qoizmllfqcjTuUS8NHPtUvQ=")
You are able to the values at this website here
Changing the name of the player is simple will automatically change it when setting the name value. (See below)
npc.name = "NewName"
The player has 3 different poses it can be. Crouching, swimming and gliding. Changing the players poses is very self explanatory just by setting them. (See below)
npc.isCrouching = true
npc.isSwimming = true
npc.isGliding = true
To reset the pose you can use the resetPose
method. (See below)
npc.resetPose()
Display items on the player you are able to use the setItem(ItemSlot, ItemStack)
method. (See below
npc.setItem(ItemSlot.MAINHAND, ItemStack(Material.SHIELD))
You are able to clear all items with clearItems
method. (See below)
npc.clearItems()
Setting the player on fire you need to set the onFire
boolean. (See below)
npc.onFire = true
npc.onFire = false
When you make a player use a item it will play a animation for example when a shield is used it will block. When a bow is used it will start charging. You are able to do this with useMainHand
or useOffHand
. (See below)
npc.useMainHand()
npc.useOffHand()
To stop using a hand you will use stopUsingMainHandItem
or stopUsingOffHandItem
. (See below)
npc.stopUsingMainHandItem()
npc.stopUsingMainHandItem()
There are two main animation the player can do. Moving there arm or having a damage effect. For moving the arm you can use moveMainHand
or moveOffHand
. (See below)
npc.moveMainHand()
npc.moveOffHand()
Now for an damage effect you can use damageAnimation
. (See below)
npc.damageAnimation()
To be listen to a interaction with a player you can use the interact
method. (See below)
npc.interact {
when(actionType){
ClickType.LEFT_CLICK -> sendLog("Left click")
ClickType.RIGHT_CLICK -> sendLog("Right click")
}
}
When you are done with the player you can remove it by using kill
method. (See below)
npc.kill()
If you want the animation with it you can use the deathAnimation
method. (See below)
npc.deathAnimation()