当我加入我的服务器时,“测试”按预期打印但是npc没有生成,也没有攻击我。这是plugin.yml:
main: com.megacrafting.MegaParty
version: 1.0
name: Megaparty
depend: [Citizens]
这是错误:
[20:58:24 ERROR]: Could not pass event PlayerJoinEvent to Megaparty v1.0
org.bukkit.event.EventException: null
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-b78586d-f3356f1]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-b78586d-f3356f1]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:499) [spigot.jar:git-Spigot-b78586d-f3356f1]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.PlayerList.onPlayerJoin(PlayerList.java:342) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.PlayerList.a(PlayerList.java:162) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.LoginListener.b(LoginListener.java:159) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.LoginListener.e(LoginListener.java:57) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.NetworkManager.a(NetworkManager.java:233) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:140) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:842) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:405) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot.jar:git-Spigot-b78586d-f3356f1]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
Caused by: java.lang.NullPointerException
at com.megacrafting.MegaParty.onJoin(MegaParty.java:35) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-b78586d-f3356f1]
... 14 more
以下是代码:
package com.megacrafting;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
public class MegaParty extends JavaPlugin implements Listener {
private NPCRegistry registry;
public void onEnable() {
NPCRegistry registry = CitizensAPI.getNPCRegistry();
getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player p = event.getPlayer();
p.sendMessage("testing");
Location loc = p.getLocation();
NPC npc = registry.createNPC(EntityType.PLAYER, "keys9");
npc.spawn(loc);
npc.getNavigator().setTarget(p, true);
}
}
答案 0 :(得分:1)
您的字段registry
为NULL,因为您从未在onEnable
中设置它。
将onEnable更改为
public void onEnable() {
this.registry = CitizensAPI.getNPCRegistry();
getServer().getPluginManager().registerEvents(this, this);
}