Big Stack Trace for someone to decipher.

Discussion in 'Spigot Plugin Development' started by Surprisejedi, Jun 5, 2017.

  1. Code (Text):
    [14:41:59 ERROR]: Could not pass event EntityDamageByEntityEvent to Cyclone_AntiCheat v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory.callEvent(CraftEventFactory.java:92) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:577) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:482) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory.handleLivingEntityDamageEvent(CraftEventFactory.java:609) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at net.minecraft.server.v1_11_R1.EntityLiving.damageEntity0(EntityLiving.java:1309) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at net.minecraft.server.v1_11_R1.EntityHuman.damageEntity0(EntityHuman.java:864) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at net.minecraft.server.v1_11_R1.EntityLiving.damageEntity(EntityLiving.java:855) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at net.minecraft.server.v1_11_R1.EntityHuman.damageEntity(EntityHuman.java:782) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at net.minecraft.server.v1_11_R1.EntityPlayer.damageEntity(EntityPlayer.java:505) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at net.minecraft.server.v1_11_R1.EntityHuman.attack(EntityHuman.java:1023) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at net.minecraft.server.v1_11_R1.EntityPlayer.attack(EntityPlayer.java:1158) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1578) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at net.minecraft.server.v1_11_R1.PacketPlayInUseEntity.a(SourceFile:69) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at net.minecraft.server.v1_11_R1.PacketPlayInUseEntity.a(SourceFile:13) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_121]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_121]
        at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:747) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]
    Caused by: java.lang.NullPointerException
        at me.surprisejedi.cac.Listeners.Reach(Listeners.java:15) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_121]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_121]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_121]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
        ... 26 more
    Main Class:
    Code (Java):
    package me.surprisejedi.cac;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener{
        @Override
        public void onEnable(){
            getServer().getPluginManager().registerEvents(new Listeners(), this);
           
        }
        @Override
        public void onDisable(){
           
        }
        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            return false;
        }
    }
     
    Listener Class:
    Code (Java):
    package me.surprisejedi.cac;
    package me.surprisejedi.cac;

    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;

    public class Listeners implements Listener {
        private CAChat staffchat;
        @EventHandler
        public void Reach(EntityDamageByEntityEvent e) {
            Player attacker = (Player) e.getDamager();
            Player victim = (Player) e.getEntity();
            if(attacker.getLocation().distance(victim.getLocation()) >= 2) {
                    staffchat.sendStaffAlert("Player" + attacker.getDisplayName() + "Hit Player " + victim.getDisplayName() + "From " + attacker.getLocation().distance(victim.getLocation()) + "blocks away.");
            }
        }
    }

     
    CAChat Class:
    Code (Java):
    package me.surprisejedi.cac;

    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;

    public class CAChat {
        ArrayList<Player> staffGroup = new ArrayList<Player>();
        public void StaffChat() {
            staffGroup.add(Bukkit.getPlayer("Surprisejedi"));  
        }
        public void sendStaffAlert(String msg) {
            for(Player players : staffGroup) {
                players.sendMessage(msg);
            }
        }
       
    }
     
    I could find the error myself, but there are people that can do it faster than me.
     
  2. NPE in your Listeners class on line 15

    If I counted correctly it's this line
    Code (Java):
    if(attacker.getLocation().distance(victim.getLocation()) >= 2) {
    attacker or victim could be null.


    Code (Java):
        public void Reach(EntityDamageByEntityEvent e) {
            Player attacker = (Player) e.getDamager();
            Player victim = (Player) e.getEntity();
    Here you are missing instance checks! Do not cast blindly!


    Edit: The double package in your class put me in the wrong line. The blind cast comment still holds though. @DevLeeo is corect you should add a constructor and ask for a CAChat instance to set your field to.
     
    #2 Nikl, Jun 5, 2017
    Last edited: Jun 5, 2017
  3. Code (Text):

    public class Listeners implements Listener {
       private CAChat staffchat; // THIS IS ALWAYS NULL... You must initialize this.
        @EventHandler
       public void Reach(EntityDamageByEntityEvent e) {
            Player attacker = (Player) e.getDamager();
            Player victim = (Player) e.getEntity();
           if(attacker.getLocation().distance(victim.getLocation()) >= 2) {
                    staffchat.sendStaffAlert("Player" + attacker.getDisplayName() + "Hit Player " + victim.getDisplayName() + "From " + attacker.getLocation().distance(victim.getLocation()) + "blocks away.");
           }
       }
    }
     
    You can initialize by changing to
    Code (Text):
     private CAChat staffchat = new CAChat();
     
    • Agree Agree x 1