NPCLib icon indicating copy to clipboard operation
NPCLib copied to clipboard

Cannot invoke "net.jitse.npclib.api.NPC.setLocation()" because "npc" is null

Open ayabusa opened this issue 4 years ago • 6 comments

Hello, I'm trying to use your api on my 1.18.1 spigot server but I have an issue : When i try to setLocation() before creating my npc I get the message below in the console. I have checked my code, but cannot find what I did wrong... Any idea on how to solve it ?

thanks a bunch :)

NPCLib Failed to create NPC. Please report the following stacktrace message
java.lang.NullPointerException: Cannot invoke "java.lang.Class.getConstructors()" because "this.npcClass" is null
        at net.jitse.npclib.NPCLib.createNPC(NPCLib.java:114) ~[?:?]
        at net.jitse.npclib.NPCLib.createNPC(NPCLib.java:128) ~[?:?]
        at fr.ayabusa.ignifusplugin.commands.CommandSpawnNpc.onCommand(CommandSpawnNpc.java:32) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_18_R1.CraftServer.dispatchCommand(CraftServer.java:821) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1939) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1778) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1759) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.network.protocol.game.PacketPlayInChat.a(PacketPlayInChat.java:46) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.network.protocol.game.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.network.protocol.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:30) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.TickTask.run(SourceFile:18) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.util.thread.IAsyncTaskHandler.c(SourceFile:151) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.util.thread.IAsyncTaskHandlerReentrant.c(SourceFile:23) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1158) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.MinecraftServer.c(MinecraftServer.java:1) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.util.thread.IAsyncTaskHandler.y(SourceFile:125) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.MinecraftServer.bf(MinecraftServer.java:1137) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.MinecraftServer.y(MinecraftServer.java:1130) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.util.thread.IAsyncTaskHandler.c(SourceFile:134) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1114) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1038) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:304) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at java.lang.Thread.run(Thread.java:833) [?:?]
[17:39:16] [Server thread/ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'spawnnpc' in plugin Ignifus_plugin v0.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_18_R1.CraftServer.dispatchCommand(CraftServer.java:821) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1939) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1778) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1759) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.network.protocol.game.PacketPlayInChat.a(PacketPlayInChat.java:46) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.network.protocol.game.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.network.protocol.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:30) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.TickTask.run(SourceFile:18) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.util.thread.IAsyncTaskHandler.c(SourceFile:151) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.util.thread.IAsyncTaskHandlerReentrant.c(SourceFile:23) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1158) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.MinecraftServer.c(MinecraftServer.java:1) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.util.thread.IAsyncTaskHandler.y(SourceFile:125) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.MinecraftServer.bf(MinecraftServer.java:1137) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.MinecraftServer.y(MinecraftServer.java:1130) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.util.thread.IAsyncTaskHandler.c(SourceFile:134) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1114) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1038) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:304) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3384-Spigot-78a14d9-b8a25cb]
        at java.lang.Thread.run(Thread.java:833) [?:?]
Caused by: java.lang.NullPointerException: Cannot invoke "net.jitse.npclib.api.NPC.setLocation(org.bukkit.Location)" because "npc" is null
        at fr.ayabusa.ignifusplugin.commands.CommandSpawnNpc.onCommand(CommandSpawnNpc.java:34) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
        ... 21 more

My code :

  public class CommandSpawnNpc implements CommandExecutor {
  
	  @Override
	  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
		  // TODO Auto-generated method 
		  
		  Player p = (Player)sender;
          
		  NPCLib librairie = main.library;
		  
		  List<String> name = new ArrayList<String>();
		  name.add("§bSmurf");
		  name.add("§2click to teleport");
		  
		  NPC npc = librairie.createNPC(name);
		  npc.setLocation(p.getLocation());
	          npc.create();
	          npc.show(p);
	      
		  return false;
	  }
  }

ayabusa avatar Jan 02 '22 17:01 ayabusa

Check if the NPC is null?

DxsSucuk avatar Jan 17 '22 20:01 DxsSucuk

Yes he is null but I don't know why

ayabusa avatar Jan 20 '22 17:01 ayabusa

Is your instance of the NPCLib null?

DxsSucuk avatar Jan 20 '22 18:01 DxsSucuk

sorry for the delay in response. so no my instance is not null, thank you for your reply but I think I will give up with the library and try the official way to spawn NPC.

ayabusa avatar Jan 28 '22 16:01 ayabusa

There is a official way to spawn NPCs? And I think I found the problem the plugin doesn't support the Server version you are using (maybe?).

DxsSucuk avatar Jan 31 '22 11:01 DxsSucuk

so this is the "official way" (without plugin or lib) to spawn NPC : https://www.spigotmc.org/threads/how-to-create-and-modify-npcs.400753/

ayabusa avatar Jan 31 '22 17:01 ayabusa