Could not pass event PlayerInteractEvent to [Main Class]

Discussion in 'Plugin Development' started by CoDGuardian, Jul 30, 2012.

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

    CoDGuardian

    I know this isn't a lot to go on, but i was just wondering what could cause this error. It seems that every time someone swings their arm, it throws up this error from my PlayerInteractEvent Listener. Any idea why?
     
  2. Offline

    rjVapes

    Can you post the code from your Listener?
     
  3. Offline

    CoDGuardian

    Eh the problem is it's really long and a lot of the variables that it uses are from other classes.

    Code:
    public class ClickWatcher implements org.bukkit.event.Listener{
        @EventHandler
        public void ClickListener(PlayerInteractEvent event){
            org.bukkit.event.block.Action action = event.getAction();
            if(DeathWatcher.deads.contains(event.getPlayer())&&(action.equals(Action.LEFT_CLICK_BLOCK)||action.equals(Action.LEFT_CLICK_AIR)||action.equals(Action.RIGHT_CLICK_BLOCK))){
                if(teleportTo<JoinHandler.people.size()){
                event.getPlayer().teleport(JoinHandler.people.get(teleportTo));
                teleportTo++;
                }
                else{
                    event.getPlayer().teleport(JoinHandler.people.get(0));
                    teleportTo=1;
                }
                event.setCancelled(true);
            }
            if(event.getClickedBlock().getType().equals(Material.ENDER_STONE)){
                event.setCancelled(true);
            }
                if(event.getClickedBlock().getType()==Material.WALL_SIGN||event.getClickedBlock().getType()==Material.SIGN_POST){
                    Inventory i=event.getPlayer().getInventory();
                    Sign s=(Sign)event.getClickedBlock().getState();
                    String command=s.getLine(0);
                    if(command.equalsIgnoreCase("elf")){
                        event.getPlayer().sendMessage("You are now an Elf!");
                        i.clear();
                        i.addItem(new ItemStack(Material.BOW));
                    }
                    if(command.equalsIgnoreCase("warrior")){
                        event.getPlayer().sendMessage("You are now a Warrior!");
                        i.clear();
                        i.addItem(new ItemStack(Material.IRON_SWORD));
                    }
                    if(command.equalsIgnoreCase("dwarf")){
                        event.getPlayer().sendMessage("You are now a Dwarf!");
                        i.clear();
                        i.addItem(new ItemStack(Material.IRON_PICKAXE));
                    }
                    if(command.equalsIgnoreCase("team 1")){
                        int x=team1.size();
                        if(x<=team2.size()||x<=team3.size()||x<=team4.size()){
                            event.getPlayer().teleport(t1List.get(x));
                            event.getPlayer().sendMessage(ChatColor.BLUE+("You have joined team 1 with "+team1.size()+" other players!"));
                            team1.put(event.getPlayer(), event.getPlayer().getLocation());
                            onTeam.add(event.getPlayer());
                        }
                        else
                            event.getPlayer().sendMessage("This team has more players than every other team. Join another team or wait for the other teams to get more players.");
                    }
                    if(command.equalsIgnoreCase("team 2")){
                        int x=team2.size();
                        if(x<=team1.size()||x<=team3.size()||x<=team4.size()){
                            event.getPlayer().teleport(t2List.get(x));
                            event.getPlayer().sendMessage(ChatColor.BLUE+("You have joined team 2 with "+team2.size()+" other players!"));
                            team2.put(event.getPlayer(), event.getPlayer().getLocation());
                            onTeam.add(event.getPlayer());
                        }
                        else
                            event.getPlayer().sendMessage("This team has more players than every other team. Join another team or wait for the other teams to get more players.");
                    }
                    if(command.equalsIgnoreCase("team 3")){
                        int x=team3.size();
                        if(x<=team2.size()||x<=team1.size()||x<=team4.size()){
                            event.getPlayer().teleport(t3List.get(x));
                            event.getPlayer().sendMessage(ChatColor.BLUE+("You have joined team 3 with "+team3.size()+" other players!"));
                            team3.put(event.getPlayer(), event.getPlayer().getLocation());
                            onTeam.add(event.getPlayer());
                        }
                        else
                            event.getPlayer().sendMessage("This team has more players than every other team. Join another team or wait for the other teams to get more players.");
                    }
                    if(command.equalsIgnoreCase("team 4")){
                        int x=team4.size();
                        if(x<=team2.size()||x<=team3.size()||x<=team1.size()){
                            event.getPlayer().teleport(t4List.get(x));
                            event.getPlayer().sendMessage(ChatColor.BLUE+("You have joined team 4 with "+team4.size()+" other players!"));
                            team4.put(event.getPlayer(), event.getPlayer().getLocation());
                            onTeam.add(event.getPlayer());
                        }
                        else
                            event.getPlayer().sendMessage("This team has more players than every other team. Join another team or wait for the other teams to get more players.");
                    }
     
                }
               
            }
     
            public static ArrayList <Location>t1List=new ArrayList<Location>();
            public static ArrayList <Location>t2List=new ArrayList<Location>();
            public static ArrayList <Location>t3List=new ArrayList<Location>();
            public static ArrayList <Location>t4List=new ArrayList<Location>();
            public static HashMap team1=new HashMap();
            public static HashMap team2=new HashMap();
            public static HashMap team3=new HashMap();
            public static HashMap team4=new HashMap();
            public static ArrayList <Player> onTeam= new ArrayList<Player>();
            public static int teleportTo=0;
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  4. Offline

    rjVapes

    If you look down in the stack trace when the error is thrown is there a null pointer exception further down in the stack? If so that's where your real problem is, it should reference a line number. Just dump the actual error (entire stack) log here too, the could not pass event is a symptom, not the actual problem.

    For instance
    Code:
     if(event.getClickedBlock().getType().equals(Material.ENDER_STONE))
    I think it's possible for getClickedBlock to be null there and throw an NPE, maybe elsewhere too, didn't go much further.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  5. Offline

    CoDGuardian

    Code:
    16:58:33 [SEVERE] Could not pass event PlayerInteractEvent to Classes
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:304)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
    at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEven
    t(CraftEventFactory.java:177)
    at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEven
    t(CraftEventFactory.java:147)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:879)
    at net.minecraft.server.Packet18ArmAnimation.handle(SourceFile:38)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:246)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:102)
    at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:8
    2)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:559)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:451)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
    at net.att.gha10.Classes.ClickListener.clickHandler(ClickListener.java:2
    3)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:302)
    ... 13 more
    16:58:33 [SEVERE] Could not pass event PlayerInteractEvent to CastleWars
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:304)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
    at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEven
    t(CraftEventFactory.java:177)
    at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEven
    t(CraftEventFactory.java:147)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:879)
    at net.minecraft.server.Packet18ArmAnimation.handle(SourceFile:38)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:246)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:102)
    at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:8
    2)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:559)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:451)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
    at net.att.gha10.CastleWars.ClickWatcher.ClickListener(ClickWatcher.java
    :40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:302)
    ... 13 more
    Yeah i see the null pointer exception now. I'll try throwing in an if statement that checks to see if its a block they are clicking.

    No that doesn't seem to be the problem. I put in if statements saying if(event.getClickedBlock!=null) and it still throws the error. Plus, i noticed even when i click on a block, it throws the error.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  6. Offline

    nisovin

    The stack trace shows what line the error is on, so look at that line. You're trying to do something with a null object.
     
  7. Offline

    CoDGuardian

    Yeah if i'm reading it correctly, it says Line 23. But Line 23 is
    Code:
    if(event.getClickedBlock()!=null&&(event.getClickedBlock().getType()==Material.WALL_SIGN||event.getClickedBlock().getType()==Material.SIGN_POST)){
    I figured since i put the !=null part first, if it were equal to null, it would just short circuit. Unless just simply calling event.getClickedBlock() is the problem. But i don't see how else i would check to see if they were clicking a block or not.
     
  8. Offline

    Firefly

    Are you sure the stack trace is not pointing to line 23 of an older version of your code? See if you can reproduce another stack trace and see if the line it points to changes.
     
  9. Offline

    CoDGuardian

    Ok i updated the plugin and swung my arm in the air and got the same stack trace.
    Here:
    Code:
    18:10:17 [SEVERE] Could not pass event PlayerInteractEvent to Classes
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:304)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
            at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEven
    t(CraftEventFactory.java:177)
            at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEven
    t(CraftEventFactory.java:147)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:879)
            at net.minecraft.server.Packet18ArmAnimation.handle(SourceFile:38)
            at net.minecraft.server.NetworkManager.b(NetworkManager.java:246)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:102)
            at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:8
    2)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:559)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:451)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
            at net.att.gha10.Classes.ClickListener.clickHandler(ClickListener.java:2
    3)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:302)
    Question: Does it start counting lines from 0? And does it count all the imports, although they may be condensed by eclipse? And does it count blank lines?

    Because along with the one pointed out earlier, it could be talking about either this line:
    Code:
    if(DeathWatcher.deads.contains(event.getPlayer())&&(action.equals(Action.LEFT_CLICK_BLOCK)||action.equals(Action.LEFT_CLICK_AIR)||action.equals(Action.RIGHT_CLICK_BLOCK))){
    Or this line too:
    Code:
    if(teleportTo<JoinHandler.people.size()){
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  10. Offline

    nisovin

    Did you rename your classes and methods? That error doesn't show the same class and method names as the code you've posted.

    Window -> Preferences -> General -> Editors -> Text Editors -> Show line numbers

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  11. Offline

    Firefly

    You have so many variables that could be null in that if statement that I would suggest nesting the conditions into multiple if-statements for debugging purposes.
     
  12. Offline

    CoDGuardian

    Like what?
    And ok i'll try that. Which statement are you referring to?

    P.S. I put up line numbers in Eclipse, line 23 is the blank line after all my imports. Odd.
     
  13. Offline

    Firefly

    Meaning you are either looking at the wrong class, or your stacktrace is out of sync with your code.
     
  14. Offline

    CoDGuardian

    I know it's not out of sync. And it says ClickWatcher.java in the stack trace, and that is the class i'm looking at. I think it probably doesn't count blank lines and might not even count imports.
     
  15. Offline

    rjVapes

    I believe it counts imports and blank lines, it's always pointed me to the correct place. So just to be super clear, when you say "i updated the plugin and swung my arm" you mean you also either did /reload, or stop/restarted the server? Preferably the later?

    What nisovin was referring to was that your first error log showed the error in ClickWatcher.ClickListener on line 23 of ClickWatcher.java (which is what you showed us), your second error log shows the error in ClickListener.clickHandler on line 23 of ClickListener.java.

    So either you changed the names of your functions around, like he assumed, or you fixed one problem and have stumbled onto another problem that happens to be on the same line number in a different file.

    Actually the other was on line 40 in the file you showed us. So you're looking at the wrong file :)

    Caused by: java.lang.NullPointerException
    at net.att.gha10.CastleWars.ClickWatcher.ClickListener(ClickWatcher.java
    :40)

    Caused by: java.lang.NullPointerException
    at net.att.gha10.Classes.ClickListener.clickHandler(ClickListener.java:2
    3)


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  16. Offline

    Firefly

    Which proves my point stated earlier.
     
    rjVapes likes this.
  17. Offline

    CoDGuardian

    Hmmm that's interesting. So apparently when i added the event.getClickedBlock()!=null, that fixed my ClickWatcher.java class which is the one i care about. The clickhandler class was from an old plugin, and now that i delete it, there is no error! Thanks a lot to all of you. :)
     
Thread Status:
Not open for further replies.

Share This Page