I probably sound stupid, but I can't figure out how to use this library. I'm usually pretty good at figuring out how to use libraries, but with this one, there's no documentation, the Wiki is barren, and there's not one line of description text in the entire Javadoc.
Anyway, here's what I've got so far, but it hasn't worked once. No NPC shows up. I've tried with player's UUID, a random UUID, different names, calling spawn() or respawnTo(), etc. Nothing works.
private NPCPlayer npc = null;
private NPCPlayer addPlayer(String name, String uuid, World w, float x, float y, float z) {
//UUID.fromString(uuid)
return this.npcReg.spawnPlayerNPC(new Location(w, x, y, z), NPCPlayer.class, UUID.randomUUID(), name);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerLogin(PlayerLoginEvent event) { synchronized(API_SYNC) { //Player Login.
if(event.getResult() == PlayerLoginEvent.Result.ALLOWED) {
Player player = event.getPlayer();
String id = player.getUniqueId().toString();
World world = player.getWorld();
Location loc = player.getLocation();
//Not what I plan on doing in the actual plugin, but just a test:
if(npc == null) {
Main.dbg("LOGIN!");
npc = addPlayer(player.getName()+" test", id, world, (float)loc.getX()-5, (float)loc.getY(), (float)loc.getZ()-5);
//npc.setShowInList(true);
//npc.spawn();
//npc.respawnTo(player);
//npc.setSkin(id);
}
}
}}
npcReg
is defined in onEnable() as npcReg = NPCLib.createRegistry(this);
After the first few tries, it started giving an error when creating the entity:
[13:50:20 ERROR]: "Silently" catching entity tracking error.
net.minecraft.server.v1_10_R1.ReportedException: Adding entity to track
at net.minecraft.server.v1_10_R1.EntityTracker.addEntity(EntityTracker.java:141) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at net.minecraft.server.v1_10_R1.EntityTracker.addEntity(EntityTracker.java:100) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at net.minecraft.server.v1_10_R1.EntityTracker.track(EntityTracker.java:30) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at net.minecraft.server.v1_10_R1.WorldManager.a(WorldManager.java:19) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at net.minecraft.server.v1_10_R1.World.b(World.java:1028) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at net.minecraft.server.v1_10_R1.WorldServer.b(WorldServer.java:1126) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at net.minecraft.server.v1_10_R1.World.addEntity(World.java:1021) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at org.inventivetalent.npclib.generated.entity.NPCEntityPlayer.spawn(NPCEntityPlayer.java) [NPCLib_v2.2.6.jar:?]
at org.inventivetalent.npclib.npc.NPCAbstract.spawn(NPCAbstract.java:98) [NPCLib_v2.2.6.jar:?]
at com.pecacheu.test.Main.onPlayerLogin(Main.java:110) [Test.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25]
at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at net.minecraft.server.v1_10_R1.PlayerList.attemptLogin(PlayerList.java:507) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at net.minecraft.server.v1_10_R1.LoginListener.b(LoginListener.java:118) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at net.minecraft.server.v1_10_R1.LoginListener.E_(LoginListener.java:54) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at net.minecraft.server.v1_10_R1.NetworkManager.a(NetworkManager.java:233) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at net.minecraft.server.v1_10_R1.ServerConnection.c(ServerConnection.java:140) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:832) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:673) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:572) [spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_25]
Caused by: java.lang.IllegalStateException: Entity is already tracked!
at net.minecraft.server.v1_10_R1.EntityTracker.addEntity(EntityTracker.java:108) ~[spigot-1.10.2.jar:git-Spigot-a9631d2-67b2424]
... 27 more
So, I probably corrupted my world save. Perfect.
What steps will reproduce the problem?
What were you expecting to happen? What happened instead?
- Duplicate of player spawning.
- Nothing. Well, until the error started happening. Then the error happened.
- Also, the error stopped happening again. So that's a thing.
What version of the plugin are you using? Type /version <Plugin Name>
v2.2.6
What Spigot version are you using? Type /version
1.10.2
What plugins are you using? Type /plugins
Already tried it without other plugins.