gpt4 book ai didi

java - Minecraft NPC 没有在服务器上生成并攻击我 : null pointer error

转载 作者:行者123 更新时间:2023-12-02 12:35:51 25 4
gpt4 key购买 nike

当我加入我的服务器时,“测试”会按预期打印,但 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);

}

}

最佳答案

您的字段 registry 为 NULL,因为您从未在 onEnable 中设置它。

将 onEnable 更改为

public void onEnable() {
this.registry = CitizensAPI.getNPCRegistry();
getServer().getPluginManager().registerEvents(this, this);
}

关于java - Minecraft NPC 没有在服务器上生成并攻击我 : null pointer error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45155375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com