NPC

NPC is a fake player with which you can interact, change something, set skin to it, cape, detect clicks on npc, changing location, etc.

How to create?

So, how to create NPC?

Firstly, you need to build npc using HNpcBuilder, or creating HNpc field and set up it.

Example code:

import com.hakan.core.HCore;
import com.hakan.core.item.HItemBuilder;
import com.hakan.core.npc.HNPC;
import com.hakan.core.npc.skin.HNpcSkin;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;

import java.util.Arrays;

public class CustomNPC {

    public HNPC buildNPC() {
        return HCore.npcBuilder("npc id")
                .showEveryone(true) // you can show npc to everyone, or:
                .showEveryone(false)
                .viewers(/* List of specified players UUIDs and NPC will show to them*/)
                .location(new Location(Bukkit.getWorld("world"), 0, 0, 0, 0.0f, 0.0f)) // Npc will be spawned in x: 0 y: 0 z: 0 with yaw: 0 and pitch: 0 in world: world
                .lines(Arrays.asList(
                        "This is first line of hologram over the npc!",
                        "this is the second line."
                )) // Will create the holo over the npc
                .skin(HNpcSkin.from("Steve")) // Npc will have skin from player steve
                .equipment(HNPC.EquipmentType.HEAD, new HItemBuilder(Material.DIAMOND_HELMET).build()) // Npc will have diamond helmet on head
                .equipment(HNPC.EquipmentType.CHEST, new HItemBuilder(Material.DIAMOND_CHESTPLATE).build()) // Npc will have diamond chestplate
                .equipment(HNPC.EquipmentType.LEGS, new HItemBuilder(Material.DIAMOND_LEGGINGS).build()) // Npc will have diamond leggings
                .equipment(HNPC.EquipmentType.FEET, new HItemBuilder(Material.DIAMOND_BOOTS).build()) // Npc will have diamond boots
                .equipment(HNPC.EquipmentType.MAINHAND, new HItemBuilder(Material.DIAMOND_SWORD).build()) // Npc will have diamond sword in hand
                .whenClicked((player, action) -> {
                    
                }) // Will called when player will click. you can check if player is right clicked on npc or left clicked, and what player
                .whenDeleted(npc -> {
                    
                }) // Will called when npc is deleted
                .whenSpawned(npc -> {
                    
                }) // Will called when npc is spawned
                .forceBuild(); // Use forceBuild if you want to delete existing npc with provided id (if it exists)
    }
}

HNPC#showEveryone(boolean)

If in args will true, npc will shown to all, otherwise to provided players using HNPC#addViewers(List<UUID>)

HNPC#addViewer(List<Player>)

If npc is not shown for everyone, npc will shown to all added players in this method.

This method will add provided viewers, not set.

HNPC#removeViewer(List<Player>)

If npc is not shown for everyone, npc will shown to all players including in this method.

This method will remove provided viewers, not set.

HNPC#delete()

This method will delete npc.

HNPC#expire(int ticks)

Npc will delete after provided ticks.

HNPC#canEveryoneSee()

Returns boolean which means can everyone see the npc.

HNPC#getEntity()

Returns HNpcEntity by npc

HNPC#getID()

Returns NPC's id.

HNPC#getLocation()

Returns NPC's location.

HNPC#setLocation(Location loc)

Teleports NPC to provided location.

HNPC#getSkin()

Returns NPC's skin.

HNPC#setSkin(String skin)

Sets NPC's skin.

HNPC#whenClicked(BiConsumer<Player, Action>)

Calls when player clicked on npc. Action means LEFT CLICK or RIGHT CLICK

HNPC#whenDeleted(Consumer<HNPC>)

Calls when NPC is deleted.

HNPC#whenSpawned(Consumer<HNPC>)

Calls when NPC is spawned.

HNPC#walk(Location loc, double speed)

NPC will walk to provided location with provided speed.

HNPC#isDead()

Returns if npc is dead.

HNPC#isWalking()

Returns if npc is walking right now.

HNPC#setEquipment(EquipmentType type, ItemStack item)

Npc will wear provided item in provided equipment type.

Example when npc will wear diamond helmet on head :

npc.setEquipment(HNPC.EquipmentType.HEAD, new ItemStack(Material.DIAMOND_HELMET))

Ending

That's almost all method. But, anyway, all other methods will the same.

Last updated