org.bukkit.event.EventException: null

Discussion in 'Plugin Development' started by anonymusdennis, Jul 13, 2020.

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

    anonymusdennis

    I Always get that error when I'm hiting an mob whilst being invisible, my Goal is, to improve the Attacking mechanics when an Player is invisible

    here is my full Code and the whole error:
    Code:java
    1. package com.anonymusdennis.trueinvis;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.EntityType;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.EventPriority;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.entity.EntityTargetEvent;
    10. import org.bukkit.inventory.PlayerInventory;
    11. import org.bukkit.potion.PotionEffectType;
    12.  
    13. public class EventsClass implements Listener {
    14. @EventHandler(priority = EventPriority.HIGHEST)
    15. public void ontarget(EntityTargetEvent event) {
    16.  
    17. if(event != null) {
    18.  
    19. if(event.getTarget().getType() == EntityType.PLAYER) {
    20.  
    21. Player player = (Player) event.getTarget();
    22.  
    23. PlayerInventory pi = player.getInventory();
    24. System.out.println(event.getEntity().getLastDamageCause().getEntity().getEntityId() == event.getTarget().getEntityId());
    25.  
    26. if(player.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
    27. if(pi.getBoots() == null && pi.getHelmet() == null && pi.getChestplate() == null && pi.getLeggings() == null && pi.getItemInMainHand().getType() == Material.AIR && pi.getItemInOffHand().getType() == Material.AIR || event.getEntity().getLastDamageCause().getEntity().getEntityId() != event.getTarget().getEntityId()) {
    28.  
    29. event.setCancelled(true);
    30.  
    31. }
    32. }
    33. }
    34. System.out.println("");
    35. return;
    36.  
    37. }}
    38. }
    39.  


    here is the error:

    Code:
    org.bukkit.event.EventException: null
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:311) ~[craftbukkit-1.16.1.jar:git-Bukkit-7560f5f]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[craftbukkit-1.16.1.jar:git-Bukkit-7560f5f]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:588) ~[craftbukkit-1.16.1.jar:git-Bukkit-7560f5f]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:575) ~[craftbukkit-1.16.1.jar:git-Bukkit-7560f5f]
            at org.bukkit.craftbukkit.v1_16_R1.event.CraftEventFactory.callEntityTargetLivingEvent(CraftEventFactory.java:1085) ~[craftbukkit-1.16.1.jar:git-Bukkit-7560f5f]
            at net.minecraft.server.v1_16_R1.EntityExperienceOrb.tick(EntityExperienceOrb.java:84) ~[craftbukkit-1.16.1.jar:git-Bukkit-7560f5f]
            at net.minecraft.server.v1_16_R1.WorldServer.entityJoinedWorld(WorldServer.java:641) ~[craftbukkit-1.16.1.jar:git-Bukkit-7560f5f]
            at net.minecraft.server.v1_16_R1.World.a(World.java:704) ~[craftbukkit-1.16.1.jar:git-Bukkit-7560f5f]
            at net.minecraft.server.v1_16_R1.WorldServer.doTick(WorldServer.java:386) ~[craftbukkit-1.16.1.jar:git-Bukkit-7560f5f]
            at net.minecraft.server.v1_16_R1.MinecraftServer.b(MinecraftServer.java:1047) ~[craftbukkit-1.16.1.jar:git-Bukkit-7560f5f]
            at net.minecraft.server.v1_16_R1.DedicatedServer.b(DedicatedServer.java:341) ~[craftbukkit-1.16.1.jar:git-Bukkit-7560f5f]
            at net.minecraft.server.v1_16_R1.MinecraftServer.a(MinecraftServer.java:965) ~[craftbukkit-1.16.1.jar:git-Bukkit-7560f5f]
            at net.minecraft.server.v1_16_R1.MinecraftServer.v(MinecraftServer.java:813) ~[craftbukkit-1.16.1.jar:git-Bukkit-7560f5f]
            at net.minecraft.server.v1_16_R1.MinecraftServer.lambda$0(MinecraftServer.java:155) ~[craftbukkit-1.16.1.jar:git-Bukkit-7560f5f]
            at java.lang.Thread.run(Thread.java:830) [?:?]
    Caused by: java.lang.NullPointerException
            at com.anonymusdennis.trueinvis.EventsClass.ontarget(EventsClass.java:24) ~[?:?]
            at jdk.internal.reflect.GeneratedMethodAccessor28.invoke(Unknown Source) ~[?:?]
            at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
            at java.lang.reflect.Method.invoke(Method.java:567) ~[?:?]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:309) ~[craftbukkit-1.16.1.jar:git-Bukkit-7560f5f]
            ... 14 more
     
  2. Online

    timtower Moderator Moderator

    @anonymusdennis
    event.getEntity().getLastDamageCause().getEntity().getEntityId()
    Something in that line is null.
     
  3. Offline

    Plootonix

    Not 100% sure what you're trying to do, but you might actually want to use an EventDamageByEntityEvent if you're looking to increase something such as the damage output by a player.
     
Thread Status:
Not open for further replies.

Share This Page