Library to manage npcs on your Nukkit server
- 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
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>
import cn.nukkit.plugin.PluginBase;
import josscoder.jnpc.JNPC;
public class JNPCTest extends PluginBase {
@Override
public void onEnable() {
JNPC.init(this);
}
}
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());
}
}
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:
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
);
}
}
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
);
}
}
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
);
}
}
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()
);
}
}
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()
);
}
}
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!
}
}
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();
}
}
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());
}
}
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();
}
}
This plugin is licensed under the Apache License 2.0 LICENSE, this plugin was completely created by Josscoder (José Luciano Mejia Arias)