Problem with PlayerInteractEvent

Discussion in 'Plugin Development' started by Fep310, Mar 22, 2018.

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

    Fep310

    Whenever I click with an item pointing to the air, i get this error from the cmd:
    Code:
    [18:00:43 ERROR]: Could not pass event PlayerInteractEvent to HotbarKits v1.0
    org.bukkit.event.EventException: null
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:235) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:202) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:198) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:989) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at net.minecraft.server.v1_12_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:26) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at net.minecraft.server.v1_12_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:?]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:?]
            at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            at java.lang.Thread.run(Unknown Source) [?:?]
    Caused by: java.lang.NullPointerException
            at me.Fep310.HotbarKits.Events.KitClick.onChooseStdKit(KitClick.java:25) ~[?:?]
            at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
            at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
            at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
            ... 18 more
    This is the code that triggers this error:
    Code:
    package me.Fep310.HotbarKits.Events;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    import me.Fep310.HotbarKits.Main;
    import net.md_5.bungee.api.ChatColor;
    
    public class KitClick implements Listener {
     
        public KitClick(Main plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
     
        @EventHandler
        public void onChooseStdKit(PlayerInteractEvent e) {
         
            Player p = e.getPlayer();
            Action a = e.getAction();
         
            if ((a.equals(Action.RIGHT_CLICK_AIR))) {
                if (e.getItem().getItemMeta().getDisplayName().contains("Standard")) {
                    p.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "< ! > " + ChatColor.GRAY + "You chose the standard kit!");
                }
                else if (e.getItem().getItemMeta().getDisplayName().contains("GO PVP!")) {
                    p.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "< ! > " + ChatColor.RED + "You are now in the arena! " + ChatColor.BOLD + "Good Luck.");
                }
            }
        }
    }
    
    What should I do??
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Fep310 e.getItem() can return null.
    getDisplayName() can return null.
     
  3. Offline

    Fep310

    I love u
     
  4. Offline

    WattMann

    everyone loves him
     
Thread Status:
Not open for further replies.

Share This Page