Skip to content
Hakan Kargın edited this page Jun 6, 2022 · 6 revisions

How To Use

NPC System

With this system you can create and manage client-side NPCs easily.

Let's create an NPC with hCore

HNPC npc = HCore.npcBuilder(id)
        .showEveryone(false)
        .location(location)
        .lines(lines)
        .skin(player.getName())
        .build();

and then let's set equipments of this npc

npc.setEquipment(HNPC.EquipmentType.CHEST, new ItemStack(Material.DIAMOND_CHESTPLATE));
npc.setEquipment(HNPC.EquipmentType.LEGS, new ItemStack(Material.LEATHER_LEGGINGS));

Our NPC is ready but nobody can see it for now. We can add viewer to NPC.

npc.addViewers(player.getUniqueId());

Example

public void create(Player player) {
    String id = player.getName() + System.currentTimeMillis();
    Location location = player.getLocation();
    List<String> lines = Arrays.asList("this is a", "client-side npc", "with client-side hologram");

    HNPC npc = HCore.buildNpc(id)
            .showEveryone(false)
            .addViewers(player.getUniqueId())
            .location(location)
            .lines(lines)
            .skin(player.getName())
            .build();

    npc.setEquipment(HNPC.EquipmentType.CHEST, new ItemStack(Material.DIAMOND_CHESTPLATE)); //sets chestplate of npc as diamond
    npc.setEquipment(HNPC.EquipmentType.LEGS, new ItemStack(Material.LEATHER_LEGGINGS)); //sets leggings of npc as leather
    npc.expire(15, TimeUnit.SECONDS); //our npc will remove in 15 seconds

    HCore.syncScheduler().after(20 * 5)
            .run(() -> npc.walk(player.getLocation(), 0.25)); //our npc will walk to player 5 seconds later with speed 0.25
}
Clone this wiki locally