PlayerNPC is a simple NPC API for Spigot, that allows you to create your own NPC per player. This plugin was developed by SergiFerry
/npclib - Let you customize the NPCLib. Permission: playernpc.command
/npcglobal - Let you customize the Global NPCs.
Permission: playernpc.command
All changes made to Persistent NPC will be saved when the server restarts.
/npcpersonal - Let you customize the Personal NPCs.
Permission: playernpc.command
This is an experimental command, and it's only for developer testing purposes.
Changes will not be saved when the server restarts.
Spoiler: Plugins using PlayerNPC API
If you want to show your plugin here, contact me throught twitter
@SergiFerry
Code (Text):
<repository>
<id>ranull-repo-external</id>
<url>https://repo.ranull.com/maven/external/</url>
</repository>
<dependency>
<groupId>dev.sergiferry</groupId>
<artifactId>playernpc</artifactId>
<version>2023.4</version>
<scope>provided</scope>
</dependency>
First of all, register your Plugin to the NPCLib
Code (Java):
NPCLib.
getInstance
(
) .
registerPlugin
( plugin
)
;
Step 1, generate the NPC instance
Code (Java):
NPC.
Global npc
= NPCLib.
getInstance
(
) .
generateGlobalNPC
( plugin, id, location
)
;
//or
NPC.
Personal npc
= NPCLib.
getInstance
(
) .
generatePersonalNPC
( player, plugin, id, location
)
;
Step 2, modify the NPC attributes
Code (Java):
npc.
setSkin
( texture, signature
)
;
//Use https://mineskin.org/
npc.
setItem
( NPC.
Slot , ItemStack
)
;
npc.
setText
(
String ...
)
;
npc.
setGlowing
(
boolean , ChatColor
)
;
npc.
setCollidable
(
boolean
)
;
npc.
setGazeTrackingType
( NPC.
GazeTrackingType
)
;
npc.
setCustomTabListName
(
String ,
boolean
)
;
npc.
setHideDistance
(
double
)
;
npc.
setShowOnTabList
(
boolean
)
;
npc.
setInteractCooldown
(
long
)
;
npc.
setLineSpacing
(
double
)
;
npc.
setTextOpacity
( NPC.
Hologram .
Opacity
)
;
npc.
setTextAlignment
(
Vector
)
;
npc.
setPose
( NPC.
Pose
)
;
npc.
addCustomClickAction
( NPC.
Interact .
ClickType , CustomAction
)
;
Step 3, if you are using Personal NPCs, you need to create and show it to the player.
Code (Java):
npc.
create
(
)
;
npc.
show
(
)
;
You can listen for player interact with the NPC, but it's better to use ClickActions
Code (Java):
@EventHandler
public
void onNPCInteract
( NPC.
Events .
Interact event
)
{
Player player
= event.
getPlayer
(
)
;
NPC npc
= event.
getNPC
(
)
;
NPC.
Interact .
ClickType clickType
= event.
getClickType
(
)
;
}
You can hide it temporally or destroy it permanent.
Code (Java):
npc.
hide
(
)
;
npc.
destroy
(
)
;
You can change the NPC skin, even when if it's created and shown.
Code (Java):
npc.
setSkin
( NPC.
Skin
)
;
npc.
forceUpdate
(
)
;
You can change where the NPC looks at
Code (Java):
npc.
lookAt
( location
)
;
npc.
update
(
)
;
You can change the NPC location
Code (Java):
npc.
teleport
( location
)
;
You can change the Text above the NPC
Code (Java):
npc.
setText
(
String ...
)
;
npc.
setLineOpacity
(
Integer , NPC.
Hologram .
Opacity
)
;
npc.
updateText
(
)
;
//if the text have the same amount of lines
npc.
forceUpdateText
(
)
;
//if the text have different amount of lines
npc.
setHideText
(
boolean
)
;
//you can also hide the text and then show it later
Remember that some changes at the NPC instance will not have effect on the player client until you update the npc.
Code (Java):
npc.
update
(
)
;
npc.
forceUpdate
(
)
;