Skip to content

JossArchived/JNPC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JNPC

📙 Description

Library to manage npcs on your Nukkit server

📖 Features

  • Spawn any entity in minecraft
  • Entity scales
  • Fully manageable tag
  • 3D entities with animations
  • Click interaction
  • Simple API
  • Entity rotation
  • Emote support for Human Entities
  • Paths to walk

🌏 Add as dependency

Maven:

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

<dependency>
<groupId>com.github.Josscoder</groupId>
<artifactId>JNPC</artifactId>
<version>1.0.3-nukkit</version>
</dependency>

Setup

import cn.nukkit.plugin.PluginBase;
import josscoder.jnpc.JNPC;

public class JNPCTest extends PluginBase {

    @Override
    public void onEnable() {
        JNPC.init(this);
    }
}

Build a normal NPC

package josscoder.jnpc;

import cn.nukkit.entity.passive.EntitySheep;
import cn.nukkit.level.Location;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.utils.TextFormat;
import josscoder.jnpc.entity.npc.NPC;
import josscoder.jnpc.settings.AttributeSettings;

public class JNPCTest extends PluginBase {

    @Override
    public void onEnable() {
        JNPC.init(this);

        NPC.create(AttributeSettings.builder()
                .networkId(EntitySheep.NETWORK_ID)
                .location(new Location(0, 100, 0, 100, 0, getServer().getDefaultLevel()))
                .controller((clickedNPC, player) -> player.sendMessage(TextFormat.colorize("Hello i'm NPC " + npc.getEntityId())))
                .build());
    }
}

Build a human NPC

Well, there are 3 ways, getting the skin from the player, getting the skin with our NPCSkinUtils class / and/or obtaining a skin with geometry and texture with the same class, let's see:

Way #1

package josscoder.jnpc;

import cn.nukkit.entity.EntityHuman;
import cn.nukkit.event.EventHandler;
import cn.nukkit.event.Listener;
import cn.nukkit.event.player.PlayerJoinEvent;
import cn.nukkit.item.ItemEndCrystal;
import cn.nukkit.level.Location;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.utils.TextFormat;
import josscoder.jnpc.entity.npc.NPC;
import josscoder.jnpc.settings.AttributeSettings;
import josscoder.jnpc.settings.HumanAttributes;

public class JNPCTest extends PluginBase implements Listener {

    @Override
    public void onEnable() {
        JNPC.init(this);
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler
    private void onJoin(PlayerJoinEvent event) {
        HumanAttributes humanAttributes = HumanAttributes.builder()
                .skin(event.getPlayer().getSkin())
                .handItem(new ItemEndCrystal())
                .build();

        NPC.create(AttributeSettings.builder()
                        .networkId(EntityHuman.NETWORK_ID)
                        .location(new Location(0, 100, 0, 100, 0, getServer().getDefaultLevel()))
                        .controller((clickedNPC, player) -> player.sendMessage(TextFormat.colorize("Hello i'm NPC " + clickedNPC.getEntityId())))
                        .build(),
                humanAttributes
        );
    }
}

Way #2

package josscoder.jnpc;

import cn.nukkit.entity.EntityHuman;
import cn.nukkit.item.ItemEndCrystal;
import cn.nukkit.level.Location;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.utils.TextFormat;
import josscoder.jnpc.entity.npc.NPC;
import josscoder.jnpc.settings.AttributeSettings;
import josscoder.jnpc.settings.HumanAttributes;
import josscoder.jnpc.utils.NPCSkinUtils;

import java.io.File;

public class JNPCTest extends PluginBase {

    @Override
    public void onEnable() {
        JNPC.init(this);

        HumanAttributes humanAttributes = HumanAttributes.builder()
                .skin(NPCSkinUtils.from(new File(getDataFolder() + "/skins/").toPath().resolve("mySKin.png"))) //normal skin
                .handItem(new ItemEndCrystal())
                .build();

        NPC.create(AttributeSettings.builder()
                        .networkId(EntityHuman.NETWORK_ID)
                        .location(new Location(0, 100, 0, 100, 0, getServer().getDefaultLevel()))
                        .controller((clickedNPC, player) -> player.sendMessage(TextFormat.colorize("Hello i'm NPC " + clickedNPC.getEntityId())))
                        .build(),
                humanAttributes
        );
    }
}

Way #3

package josscoder.jnpc;

import cn.nukkit.entity.EntityHuman;
import cn.nukkit.entity.data.Skin;
import cn.nukkit.item.ItemEndCrystal;
import cn.nukkit.level.Location;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.utils.TextFormat;
import josscoder.jnpc.entity.npc.NPC;
import josscoder.jnpc.settings.AttributeSettings;
import josscoder.jnpc.settings.HumanAttributes;
import josscoder.jnpc.utils.NPCSkinUtils;

import java.io.File;
import java.nio.file.Path;

public class JNPCTest extends PluginBase {

    @Override
    public void onEnable() {
        JNPC.init(this);

        Path path = new File(getDataFolder() + "/skins/").toPath();
        Skin skinWithGeo = NPCSkinUtils.from(path.resolve("mySKin.png"), path.resolve("geo.json"), "custom.geo.skin");

        HumanAttributes humanAttributes = HumanAttributes.builder()
                .skin(skinWithGeo) // texture with geometry way #1
                .handItem(new ItemEndCrystal())
                .build();

        NPC.create(AttributeSettings.builder()
                        .networkId(EntityHuman.NETWORK_ID)
                        .location(new Location(0, 100, 0, 100, 0, getServer().getDefaultLevel()))
                        .controller((clickedNPC, player) -> player.sendMessage(TextFormat.colorize("Hello i'm NPC " + clickedNPC.getEntityId())))
                        .build(),
                humanAttributes
        );
    }
}

How to use controller (when click a NPC)

package josscoder.jnpc;

import cn.nukkit.entity.mob.EntityEnderman;
import cn.nukkit.level.Location;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.utils.TextFormat;
import josscoder.jnpc.entity.npc.NPC;
import josscoder.jnpc.settings.AttributeSettings;

public class JNPCTest extends PluginBase {

    @Override
    public void onEnable() {
        JNPC.init(this);

        NPC.create(AttributeSettings.builder()
                .networkId(EntityEnderman.NETWORK_ID)
                .location(new Location(0, 100, 0, 100, 0, getServer().getDefaultLevel()))
                .controller((clickedNPC, player) -> player.sendMessage(TextFormat.colorize("Hello i'm NPC " + clickedNPC.getEntityId()))) // here will send a message when the player clicking the NPC
                .build()
        );
    }
}

Build a 3d NPC from TexturePack

package josscoder.jnpc;

import cn.nukkit.level.Location;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.utils.TextFormat;
import josscoder.jnpc.entity.npc.NPC;
import josscoder.jnpc.settings.AttributeSettings;

public class JNPCTest extends PluginBase {

    @Override
    public void onEnable() {
        JNPC.init(this);

        NPC.create(AttributeSettings.builder()
                .customEntity(true)
                .minecraftId("clover:ffa_npc")
                .location(new Location(0, 100, 0, 100, 0, getServer().getDefaultLevel()))
                .controller((clickedNPC, player) -> player.sendMessage(TextFormat.colorize("Hello i'm NPC " + clickedNPC.getEntityId())))
                .build()
        );
    }
}

How to use the tag and lines

package josscoder.jnpc;

import cn.nukkit.level.Location;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.utils.TextFormat;
import josscoder.jnpc.entity.line.PlaceholderLine;
import josscoder.jnpc.entity.line.SimpleLine;
import josscoder.jnpc.entity.npc.NPC;
import josscoder.jnpc.settings.AttributeSettings;

public class JNPCTest extends PluginBase {

    @Override
    public void onEnable() {
        JNPC.init(this);

        NPC npc = NPC.create(AttributeSettings.builder()
                .customEntity(true)
                .minecraftId("clover:ffa_npc")
                .location(new Location(0, 100, 0, 100, 0, getServer().getDefaultLevel()))
                .controller((clickedNPC, player) -> player.sendMessage(TextFormat.colorize("Hello i'm NPC " + clickedNPC.getEntityId())))
                .build()
        );

        npc.getTagSettings()
                .height(2f)
                .addLine(new PlaceholderLine(player -> "Hello " + player.getName()))
                .addLine(new PlaceholderLine(player -> "You are " + player.getName()))
                .addLine(new SimpleLine("&d&lFirst Header", 2)) //line with spaces
                .addLine(new SimpleLine("&eSub header")) //normal line
                .addLine(new SimpleLine("&o&7Footer")) //normal line
                .adjust(); //ajust lines

        npc.getTagSettings().getLine(0).rename("&bNew First"); //rename, Maybe this is good for player counters in game npcs!
    }
}

Play with the sizes

package josscoder.jnpc;

import cn.nukkit.entity.mob.EntitySlime;
import cn.nukkit.level.Location;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.utils.TextFormat;
import josscoder.jnpc.entity.line.SimpleLine;
import josscoder.jnpc.entity.npc.NPC;
import josscoder.jnpc.settings.AttributeSettings;

public class JNPCTest extends PluginBase {

    @Override
    public void onEnable() {
        JNPC.init(this);

        NPC npc = NPC.create(AttributeSettings.builder()
                .networkId(EntitySlime.NETWORK_ID)
                .location(new Location(0, 100, 0, 100, 0, getServer().getDefaultLevel()))
                .controller((clickedNPC, player) -> player.sendMessage(TextFormat.colorize("Hello i'm NPC " + clickedNPC.getEntityId())))
                .build());

        npc.getTagSettings()
                .addLine(new SimpleLine("&d&lFirst Header", 2))
                .addLine(new SimpleLine("&eSub header"))
                .addLine(new SimpleLine("&o&7Footer"))
                .adjust();
    }
}

As we can see the slime is very small and the tag is very high, we have the solution for it:

package josscoder.jnpc;

import cn.nukkit.entity.mob.EntitySlime;
import cn.nukkit.level.Location;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.utils.TextFormat;
import josscoder.jnpc.entity.line.SimpleLine;
import josscoder.jnpc.entity.npc.NPC;
import josscoder.jnpc.settings.AttributeSettings;

public class JNPCTest extends PluginBase {

    @Override
    public void onEnable() {
        JNPC.init(this);

        NPC npc = NPC.create(AttributeSettings.builder()
                .networkId(EntitySlime.NETWORK_ID)
                .location(new Location(0, 100, 0, 100, 0, getServer().getDefaultLevel()))
                .controller((clickedNPC, player) -> player.sendMessage(TextFormat.colorize("Hello i'm NPC " + clickedNPC.getEntityId())))
                .build());

        npc.getTagSettings()
                .height(0.5f) //Here!
                .addLine(new SimpleLine("&d&lFirst Header", 2))
                .addLine(new SimpleLine("&eSub header"))
                .addLine(new SimpleLine("&o&7Footer"))
                .adjust();
    }
}

Wow, now it works great!

The legends were true... there are giant zombies!

But... how did you do it? Simple, this way:

package josscoder.jnpc;

import cn.nukkit.entity.mob.EntityZombie;
import cn.nukkit.level.Location;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.utils.TextFormat;
import josscoder.jnpc.entity.npc.NPC;
import josscoder.jnpc.settings.AttributeSettings;

public class JNPCTest extends PluginBase {

    @Override
    public void onEnable() {
        JNPC.init(this);

        NPC.create(AttributeSettings.builder()
                .networkId(EntityZombie.NETWORK_ID)
                .scale(10f) //Here!
                .location(new Location(0, 100, 0, 100, 0, getServer().getDefaultLevel()))
                .controller((clickedNPC, player) -> player.sendMessage(TextFormat.colorize("Hello i'm NPC " + clickedNPC.getEntityId())))
                .build());
    }
}

Follow player with the look (keepLooking)

package josscoder.jnpc;

import cn.nukkit.entity.mob.EntityCreeper;
import cn.nukkit.level.Location;
import cn.nukkit.plugin.PluginBase;
import josscoder.jnpc.entity.line.SimpleLine;
import josscoder.jnpc.entity.npc.NPC;
import josscoder.jnpc.settings.AttributeSettings;
import josscoder.jnpc.settings.TagSettings;

public class JNPCTest extends PluginBase {

    @Override
    public void onEnable() {
        JNPC.init(this);

        NPC npc = NPC.create(AttributeSettings.builder()
                .networkId(EntityCreeper.NETWORK_ID)
                .keepLooking(true) //Here!
                .scale(2)
                .location(new Location(0, 100, 0, 100, 0, getServer().getDefaultLevel()))
                .controller((clickedNPC, player) -> player.sendMessage("Mineplex is better than josscodercraft"))
                .build());

        TagSettings tagSettings = npc.getTagSettings();
        tagSettings
                .height(3f)
                .addLine(new SimpleLine("&a&lKarl the creeper"))
                .addLine(new SimpleLine("&o&7Click to receive love!"))
                .adjust();
    }
}

Special thanks to my friends Brayan and Jose Luis for helping me with 3d entity support

📜 LICENSE

This plugin is licensed under the Apache License 2.0 LICENSE, this plugin was completely created by Josscoder (José Luciano Mejia Arias)

About

Library to manage npcs on your Nukkit server

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages