ERROR which is not critical, I can't get the origin of it...

Discussion in 'Spigot Plugin Development' started by plapi, Sep 4, 2019.

  1. Hello, it has been now 3 full hours in which I tried to solve this error.. I can't get it..
    First of all: If it is possible to disable error outputs, let me know because everything is working fine (yes even with this errors).

    I can't post the full code because it's like 4k lines but I will post seperat parts which are named in the error.

    When I remove the 3 following parts in my code, the error is gone with it.

    CONSOLE ERROR:

    Code (Text):
    [20:14:43] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to sushibuild v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:228) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:195) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:191) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1200) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInArmAnimation.a(PacketPlayInArmAnimation.java:18) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInArmAnimation.a(PacketPlayInArmAnimation.java:1) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_222]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_222]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222]
    Caused by: java.lang.NullPointerException
        at de.oskarsus.listener.LISTENER.handyInteract(LISTENER.java:2346) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_222]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_222]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_222]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_222]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        ... 18 more

    PART 1:
    Code (Java):
        ///////////////////////////////////// CUASING NON-CRITICTAL ERROR ////////////////////////////////////////////////////////////
        @EventHandler
        public void onRightClickEvent(PlayerInteractEvent e) {
         
            Player p = (Player) e.getPlayer();
            if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
                    if(p.getItemInHand().getItemMeta().getDisplayName().equals("§8» §c50mg Kokainpulver")) {
                    addkoks(p, p.getUniqueId());
                    p.playSound(p.getLocation(), Sound.ENDERMAN_DEATH, 5F, 10F);
                 
                 
                 
                    for (PotionEffect effects : p.getActivePotionEffects()) {
                        p.removePotionEffect(effects.getType());
                    }
                 
                    p.addPotionEffect(potion(PotionEffectType.BLINDNESS, 200, 1));
                    p.addPotionEffect(potion(PotionEffectType.SLOW, 200, 1));
                    p.addPotionEffect(potion(PotionEffectType.CONFUSION, 320, 1));
                    p.addPotionEffect(potion(PotionEffectType.WITHER, 40, 1));
                 
                    p.addPotionEffect(potion(PotionEffectType.NIGHT_VISION, 6000, 1));            
                    p.addPotionEffect(potion(PotionEffectType.SATURATION, 6000, 1));    
                    p.addPotionEffect(potion(PotionEffectType.SPEED, 6000, 1));
                 
                    if(p.getItemInHand().getAmount() == 1) {
                        p.getInventory().removeItem(p.getItemInHand());
                    } else {
                        p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
                    }
                 
                    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                    scheduler.scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
                        @Override
                        public void run() {
                     
                            p.addPotionEffect(potion(PotionEffectType.WITHER, 40, 1));
                            p.addPotionEffect(potion(PotionEffectType.CONFUSION, 140, 2));
                         
                       
                        }
                    }, 6000);

                }
             
                else if(p.getItemInHand().getItemMeta().getDisplayName().equals("§8» §c10mg Methkristalle")) {
                    addkoks(p, p.getUniqueId());
                    p.playSound(p.getLocation(), Sound.DRINK, 5F, 10F);
                    p.playSound(p.getLocation(), Sound.ENDERMAN_DEATH, 5F, 10F);
                 
                 
                 
                    for (PotionEffect effects : p.getActivePotionEffects()) {
                        p.removePotionEffect(effects.getType());
                    }
                 
                    p.addPotionEffect(potion(PotionEffectType.BLINDNESS, 200, 2));
                    p.addPotionEffect(potion(PotionEffectType.SLOW, 200, 2));
                    p.addPotionEffect(potion(PotionEffectType.CONFUSION, 320, 2));
                    p.addPotionEffect(potion(PotionEffectType.WITHER, 80, 2));
                 
                 
                    p.addPotionEffect(potion(PotionEffectType.INCREASE_DAMAGE, 12000, 1));
                    p.addPotionEffect(potion(PotionEffectType.SPEED, 12000, 1));
                    p.addPotionEffect(potion(PotionEffectType.SATURATION, 12000, 1));
                    p.addPotionEffect(potion(PotionEffectType.DAMAGE_RESISTANCE, 12000, 0));
                 
                    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                    scheduler.scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
                        @Override
                        public void run() {
                   
                            p.addPotionEffect(potion(PotionEffectType.WITHER, 80, 2));
                            p.addPotionEffect(potion(PotionEffectType.CONFUSION, 140, 2));
                         
                       
                        }
                    }, 12000);
                 
                    if(p.getItemInHand().getAmount() == 1) {
                        p.getInventory().removeItem(p.getItemInHand());
                    } else {
                        p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
                    }

                }
             
             
                else if(p.getItemInHand().getItemMeta().getDisplayName().equals("§8» §c250mg Marihuana")) {
                    addmarihuana(p, p.getUniqueId());
                    p.playSound(p.getLocation(), Sound.LAVA_POP, 5F, 10F);
                    p.playSound(p.getLocation(), Sound.LAVA_POP, 5F, 10F);
                    p.playSound(p.getLocation(), Sound.FIZZ, 5F, 10F);
                 
                 
                 
                    for (PotionEffect effects : p.getActivePotionEffects()) {
                        p.removePotionEffect(effects.getType());
                    }
                 
                    p.addPotionEffect(potion(PotionEffectType.BLINDNESS, 40, 0));
                    p.addPotionEffect(potion(PotionEffectType.SLOW, 2400, 1));
                    p.addPotionEffect(potion(PotionEffectType.SATURATION, 2400, 1));
                 
                    BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                    scheduler.scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
                        @Override
                        public void run() {
                   
                         
                       
                        }
                    }, 2400);
                 
                    if(p.getItemInHand().getAmount() == 1) {
                        p.getInventory().removeItem(p.getItemInHand());
                    } else {
                        p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
                     
                    }

                }
             
         
             
             
                 
                else if(p.getInventory().getHeldItemSlot() == 8) {
                 
                    e.setCancelled(true);
                }

            }      
            else {
             
                //e.setCancelled(true);
            }
        }
    PART 2:
    Code (Java):
    ///////////////////////////////////// CUASING NON-CRITICTAL ERROR ////////////////////////////////////////////////////////////
            @EventHandler
            public void handyInteract(PlayerInteractEvent e) {
            Player p = e.getPlayer();
                if(e.getAction().equals(Action.RIGHT_CLICK_AIR)
                || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)
                || e.getAction().equals(Action.LEFT_CLICK_AIR)
                || e.getAction().equals(Action.LEFT_CLICK_BLOCK)){
         
                    if(p.getItemInHand().getItemMeta().getDisplayName().equals("§8» §cHandy")) {
         
         
                        e.setCancelled(true);
                        setHandyInv();
                        p.openInventory(handyinv);
                        p.playSound(p.getLocation(), Sound.PISTON_EXTEND, 1, 1);
                    }
         
                }
         
            }
    PART 3:
    Code (Java):
    ///////////////////////////////////// CUASING NON-CRITICTAL ERROR ////////////////////////////////////////////////////////////
        @EventHandler
        public void onLeftClickEvent(PlayerInteractEvent e) {
            Player p = e.getPlayer();
         
            if(e.getAction().equals(Action.LEFT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
             
                if(p.getItemInHand().getItemMeta().getDisplayName().equals("§8» §c10mg Methkristalle")) {
                 
                    e.setCancelled(true);
                 


                    setInvCrystalInfo();
                 
                 
                    p.openInventory(crystalinfo);

                }
             
             
                else if(p.getItemInHand().getItemMeta().getDisplayName().equals("§8» §c250mg Marihuana")) {
                 
                    e.setCancelled(true);
                 

                    setInvMarihuanaInfo();
                 
                    p.openInventory(marihuanainfo);

                }
             
             
                else if(p.getItemInHand().getItemMeta().getDisplayName().equals("§8» §c50mg Kokainpulver")) {
                 
                    e.setCancelled(true);
                 

                    setInvKokainInfo();
                 
                 
                    p.openInventory(kokaininfo);

                 
                }
             
             
             
            } else {
                //e.setCancelled(false);
            }
         
        }
    This is much code and I hope for some good answers. Like I said before: If possible I would Supress console errors caused by those 3 because they don't give me any disadvantage..

    Best Regards,
    plapi

    Edit: When I see my code.. I realize I should'nt use that much spaces lol
     
  2. SteelPhoenix

    Moderator

    I didn't go through all your code, but for one you're assuming the player is holding an item and that that item has a display name. Otherwise they'd be null so you can't use them.
     
  3.  
  4. Thats right, but I still don't know why the error comes up..
     
  5. Maybe I said it wrong: I dont unterstand why the error appears. I knew that before
     
  6. The error appears, because the object is null, and Java can't do anything with a null object. Check to make sure the object is not null before trying to invoke anything from it.
     
  7. Added a if (p.getItemInHand() != null) to every function, it still gives me those errors..
     
  8. So send us the line 2346 of your code in de.oskarsus.listener.LISTENER.handyInteract.
     
  9. Look back in your stacktrace, and let us know which line the NPE is coming from.