Skip to content

qrowned/NPC-Factory

Repository files navigation


Logo

NPC-Factory


This spigot plugin is a easy to use NPC API called NPC-Factory.
Creating non-player-characters was never so easy!

💻 Built With

  • java Java
  • mongodb Spigot

Installation

  1. Download the latest release.
  2. Put the .jar file in your plugins folder.
  3. Restart the server.

Developing

Add the dependency to your project:

Maven

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>

<dependency>
    <groupId>com.github.qrowned</groupId>
    <artifactId>NPC-Factory</artifactId>
    <version>1.0.0-RELEASE</version>
</dependency>

Gradle

maven {
    name 'jitpack.io'
    url 'https://jitpack.io'
}

implementation only: 'com.github.qrowned:NPC-Factory:1.0.0-RELEASE'

Code Example

public class NPCExample {

    private final NPCFactoryPlugin npcFactoryPlugin;

    public NPCExample(NPCFactoryPlugin npcFactoryPlugin) {
        this.npcFactoryPlugin = npcFactoryPlugin;
    }

    /**
     * Spawn sample npc
     *
     * @param location        location the npc should spawn
     * @param excludedPlayers list of players which should not see the npc
     */
    public void spawnNPC(Location location, List<Player> excludedPlayers) {
        final NPC npc = NPC.builder()
                .data(this.createNPCData())
                .location(location)
                .lookAtPlayers(false)
                .imitatePlayers(false)
                .build(this.npcFactoryPlugin.getNpcHandler());

        excludedPlayers.forEach(npc::exclude);
    }

    /**
     * Create a sample npc data
     *
     * @return created npc data
     */
    private NPCData createNPCData() {
        // Creating data and fetching data from mojang
        final NPCData npcData = NPCData.create(UUID.fromString("a7f2ffe9-cf32-46be-8453-9c73eb3be00b"));
        npcData.complete();

        // Change UUID & Name
        npcData.setUniqueId(UUID.randomUUID());
        npcData.setName("NPC-Factory");

        return npcData;
    }

}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages