Solved AsyncPlayerChatEvent is null

Discussion in 'Plugin Development' started by maxcreeper360, Mar 20, 2022.

Thread Status:
Not open for further replies.
  1. Offline

    maxcreeper360

    Hello, I am coding a plugin that will summon a wolf if a player sends a specific message. However, it returns null every time I enter the message in chat. Here is the event:

    Code:
    @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent e) {
        if (chat) {
            if (positiveMessages.contains(e.getMessage())) {
                summonTamedWolves(e.getPlayer());
            } else if (negativeMessages.contains(e.getMessage())) {
                summonAngryWolves(e.getPlayer());
            }
        }
    }
    I doubt anything is wrong with the event itself. It's likely something to do with the method that summons the wolf. Even more specific, I'm pretty sure it's the getWorld method. Here it is:

    Code:
    public static void summonTamedWolves(Player player) {
        for (int i = 10; i > 0; i--) {
            Entity wolfEntity = player.getWorld().spawnEntity(player.getLocation(), WOLF);
            Tameable wolf = (Tameable) wolfEntity;
            wolf.setOwner(player);
            player.sendMessage(ChatColor.GREEN + "Friendly dogs summoned!");
        }
    }
    Here are the logs:

    Code:
    [12:04:17] [Async Chat Thread - #0/ERROR]: Could not pass event AsyncPlayerChatEvent to Main v1.18.1
    org.bukkit.event.EventException: null
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:589) [spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:576) [spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
        at net.minecraft.server.network.PlayerConnection.chat(PlayerConnection.java:1863) [spigot-1.18.1-R0.1-SNAPSHOT.jar:3443-Spigot-699290c-2c1e499]
        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1797) [spigot-1.18.1-R0.1-SNAPSHOT.jar:3443-Spigot-699290c-2c1e499]
        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1763) [spigot-1.18.1-R0.1-SNAPSHOT.jar:3443-Spigot-699290c-2c1e499]
        at net.minecraft.network.protocol.game.PacketPlayInChat$1.run(PacketPlayInChat.java:40) [spigot-1.18.1-R0.1-SNAPSHOT.jar:3443-Spigot-699290c-2c1e499]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) [?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
        at java.lang.Thread.run(Thread.java:833) [?:?]
    Caused by: java.lang.IllegalStateException: Asynchronous entity add!
        at org.spigotmc.AsyncCatcher.catchOp(AsyncCatcher.java:14) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3443-Spigot-699290c-2c1e499]
        at net.minecraft.server.level.WorldServer.addEntity(WorldServer.java:988) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3443-Spigot-699290c-2c1e499]
        at net.minecraft.server.level.WorldServer.addFreshEntity(WorldServer.java:934) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3443-Spigot-699290c-2c1e499]
        at org.bukkit.craftbukkit.v1_18_R1.CraftWorld.addEntityToWorld(CraftWorld.java:804) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3443-Spigot-699290c-2c1e499]
        at org.bukkit.craftbukkit.v1_18_R1.CraftRegionAccessor.addEntity(CraftRegionAccessor.java:530) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3443-Spigot-699290c-2c1e499]
        at org.bukkit.craftbukkit.v1_18_R1.CraftRegionAccessor.spawn(CraftRegionAccessor.java:506) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3443-Spigot-699290c-2c1e499]
        at org.bukkit.craftbukkit.v1_18_R1.CraftRegionAccessor.spawn(CraftRegionAccessor.java:500) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3443-Spigot-699290c-2c1e499]
        at org.bukkit.craftbukkit.v1_18_R1.CraftRegionAccessor.spawn(CraftRegionAccessor.java:486) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3443-Spigot-699290c-2c1e499]
        at org.bukkit.craftbukkit.v1_18_R1.CraftRegionAccessor.spawnEntity(CraftRegionAccessor.java:394) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3443-Spigot-699290c-2c1e499]
        at com.max.firstplugin.Main.summonTamedWolves(Main.java:47) ~[?:?]
        at com.max.firstplugin.Main.onPlayerChat(Main.java:154) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
        ... 12 more
    Note: I am new to Bukkit. I'm still learning the spigot api.
     
  2. Online

    timtower Administrator Administrator Moderator

    @maxcreeper360
    Caused by: java.lang.IllegalStateException: Asynchronous entity add!
    What makes you think the event is null?
    Bukkit.runTask(<spawn here>)
     
  3. Offline

    maxcreeper360

    Thank you so much! I spent an hour debugging the top half when I didn't even see the bottom half! I fixed the problem.
     
Thread Status:
Not open for further replies.

Share This Page