Could not pass PlayerInteractEvent to Plugin

Discussion in 'Plugin Development' started by Ross Gosling, Sep 11, 2013.

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

    Ross Gosling

    My plugin manages to generate an error any time a player right clicks/left clicks a block/air/chest/anything...

    Does anyone have any idea how to fix this? I've looked at several threads but none have helped me and I've tried to fix it but can't.

    The Error Message (Multicraft goes bottom to top in chronological order)
    Code:
    11.09 16:09:04 [Server] INFO ... 16 more
    11.09 16:09:04 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    11.09 16:09:04 [Server] INFO at java.lang.reflect.Method.invoke(Method.java:601)
    11.09 16:09:04 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    11.09 16:09:04 [Server] INFO at sun.reflect.GeneratedMethodAccessor33.invoke(Unknown Source)
    11.09 16:09:04 [Server] INFO at me.x3DGosling.CustomGoslingPlugin.Main.PlayerInteractEvent(Main.java:1454)
    11.09 16:09:04 [Server] INFO Caused by: java.lang.NullPointerException
    11.09 16:09:04 [Server] INFO at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    11.09 16:09:04 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
    11.09 16:09:04 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
    11.09 16:09:04 [Server] INFO at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
    11.09 16:09:04 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
    11.09 16:09:04 [Server] INFO at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
    11.09 16:09:04 [Server] INFO at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
    11.09 16:09:04 [Server] INFO at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:116)
    11.09 16:09:04 [Server] INFO at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
    11.09 16:09:04 [Server] INFO at net.minecraft.server.v1_6_R2.Packet15Place.handle(SourceFile:58)
    11.09 16:09:04 [Server] INFO at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:628)
    11.09 16:09:04 [Server] INFO at net.minecraft.server.v1_6_R2.PlayerInteractManager.interact(PlayerInteractManager.java:373)
    11.09 16:09:04 [Server] INFO at org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:190)
    11.09 16:09:04 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    11.09 16:09:04 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    11.09 16:09:04 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    11.09 16:09:04 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    11.09 16:09:04 [Server] INFO org.bukkit.event.EventException
    11.09 16:09:04 [Server] SEVERE Could not pass event PlayerInteractEvent to CustomGoslingPlugin v1.0
    My Code
    Code:
        @EventHandler
        public void PlayerInteractEvent(PlayerInteractEvent Event) {
       
            Player Player = Event.getPlayer();
            Action Action = Event.getAction();
       
            int ItemID = Player.getItemInHand().getType().getId();
            String ItemName = Player.getItemInHand().getItemMeta().getDisplayName();
       
            if(ItemID == 329) {
           
                //RightClick with saddle
                if((Action.equals(org.bukkit.event.block.Action.RIGHT_CLICK_AIR)) || (Action.equals(org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK))) {
           
                    if(Player.hasPermission("GroupNode.RossFaction")) {
               
                        if(Player.hasPermission("CustomGoslingPlugin.InRossStable")) {
                       
                            if(this.getConfig().getBoolean("Emberstone.CastleRespawn") == false) {
                   
                                Player.performCommand("horses summon " + ItemName);
                       
                            }
                       
                            else {
                           
                                Player.sendMessage(ChatColor.RED + "You cannot summon horses here whilst your city is under seige");
                           
                            }
                       
                        }
                   
                        else {
                       
                            Player.sendMessage(ChatColor.RED + "You must be in faction controlled stables");
                       
                        }
               
                    }
               
                    else if(Player.hasPermission("GroupNode.LewisFaction")) {
                   
                        if(Player.hasPermission("CustomGoslingPlugin.InLewisStable")) {
                   
                            if(this.getConfig().getBoolean("Mykonos.CastleRespawn") == false) {
                           
                                Player.performCommand("horses summon " + ItemName);
                       
                            }
                       
                            else {
                           
                                Player.sendMessage(ChatColor.RED + "You cannot summon horses here whilst your city is under seige");
                           
                            }
                       
                        }
                   
                        else {
                       
                            Player.sendMessage(ChatColor.RED + "You must be in faction controlled stables");
                       
                        }
               
                    }
               
                    else if(Player.hasPermission("GroupNode.AlexFaction")) {
                   
                        if(Player.hasPermission("CustomGoslingPlugin.InAlexStable")) {
                   
                            if(this.getConfig().getBoolean("Summerhold.CastleRespawn") == false) {
                           
                                Player.performCommand("horses summon " + ItemName);
                       
                            }
                       
                            else {
                           
                                Player.sendMessage(ChatColor.RED + "You cannot summon horses here whilst your city is under seige");
                           
                            }
                       
                        }
                   
                        else {
                       
                            Player.sendMessage(ChatColor.RED + "You must be in faction controlled stables");
                       
                        }
               
                    }
               
                    else if(Player.hasPermission("GroupNode.CurtisFaction")) {
                   
                        if(Player.hasPermission("CustomGoslingPlugin.InCurtisStable")) {
                   
                            if(this.getConfig().getBoolean("Icarus.CastleRespawn") == false) {
                           
                                Player.performCommand("horses summon " + ItemName);
                       
                            }
                       
                            else {
                           
                                Player.sendMessage(ChatColor.RED + "You cannot summon horses here whilst your city is under seige");
                           
                            }
                       
                        }
                   
                        else {
                       
                            Player.sendMessage(ChatColor.RED + "You must be in faction controlled stables");
                       
                        }
               
                    }       
               
                }
           
                //LeftClick with saddle
                else if((Action.equals(org.bukkit.event.block.Action.LEFT_CLICK_AIR)) || (Action.equals(org.bukkit.event.block.Action.LEFT_CLICK_BLOCK))) {
               
                    if(Player.hasPermission("GroupNode.RossFaction")) {
               
                        if(Player.hasPermission("CustomGoslingPlugin.InRossStable")) {
                       
                            if(this.getConfig().getBoolean("Emberstone.CastleRespawn") == false) {
                   
                                Player.performCommand("horses dismiss");
                       
                            }
                       
                            else {
                           
                                Player.sendMessage(ChatColor.RED + "You cannot dismiss horses here whilst your city is under seige");
                           
                            }
                       
                        }
                   
                        else {
                       
                            Player.sendMessage(ChatColor.RED + "You must be in faction controlled stables");
                       
                        }
               
                    }
               
                    else if(Player.hasPermission("GroupNode.LewisFaction")) {
                   
                        if(Player.hasPermission("CustomGoslingPlugin.InLewisStable")) {
                   
                            if(this.getConfig().getBoolean("Mykonos.CastleRespawn") == false) {
                           
                                Player.performCommand("horses dismiss");
                       
                            }
                       
                            else {
                           
                                Player.sendMessage(ChatColor.RED + "You cannot dismiss horses here whilst your city is under seige");
                           
                            }
                       
                        }
                   
                        else {
                       
                            Player.sendMessage(ChatColor.RED + "You must be in faction controlled stables");
                       
                        }
               
                    }
               
                    else if(Player.hasPermission("GroupNode.AlexFaction")) {
                   
                        if(Player.hasPermission("CustomGoslingPlugin.InAlexStable")) {
                   
                            if(this.getConfig().getBoolean("Summerhold.CastleRespawn") == false) {
                           
                                Player.performCommand("horses dismiss");
                       
                            }
                       
                            else {
                           
                                Player.sendMessage(ChatColor.RED + "You cannot dismiss horses here whilst your city is under seige");
                           
                            }
                       
                        }
                   
                        else {
                       
                            Player.sendMessage(ChatColor.RED + "You must be in faction controlled stables");
                       
                        }
               
                    }
               
                    else if(Player.hasPermission("GroupNode.CurtisFaction")) {
                   
                        if(Player.hasPermission("CustomGoslingPlugin.InCurtisStable")) {
                   
                            if(this.getConfig().getBoolean("Icarus.CastleRespawn") == false) {
                           
                                Player.performCommand("horses dismiss");
                       
                            }
                       
                            else {
                           
                                Player.sendMessage(ChatColor.RED + "You cannot dismiss horses here whilst your city is under seige");
                           
                            }
                       
                        }
                   
                        else {
                       
                            Player.sendMessage(ChatColor.RED + "You must be in faction controlled stables");
                       
                        }
               
                    }
           
                }
           
            }
       
        }    
     
  2. Offline

    kreashenz

    Make sure you're checking if the item in the player's hand isn't null (if(player.getItemInHand() != null)) also, what's line 154?

    [Edit] Use camel case for your variables and methods. It's much easier to recognize your variables. (camel case is something like this, eg a method name, onPlayerInteractEvent. Notice the method starts with lower case)
     
  3. Offline

    Ross Gosling

    That check with the if statement hasn't done anything, still returns the error. The weird thing is that my code is still working properly and how it should but the error is unnerving and I believe it's causing issues with worldguard regions not working properly with interactions.
    And like 154 is an irrelevant integer being set in the onEnable() method...
     
  4. Offline

    kreashenz

  5. Offline

    Ross Gosling

    line 1454: if(Player.getItemInHand() != null) {

    I attempted to fix the problem but failed yet again:
    Original
    Code:
        @EventHandler
        public void PlayerInteractEvent(PlayerInteractEvent Event) {
         
            Player Player = Event.getPlayer();
            Action Action = Event.getAction();
         
            int ItemID = Player.getItemInHand().getType().getId();
            String ItemName = Player.getItemInHand().getItemMeta().getDisplayName();
         
            if(Player.getItemInHand() != null) {
         
                if(ItemID == 329) {
                 
                    //RightClick with saddle
                    if((Action.equals(org.bukkit.event.block.Action.RIGHT_CLICK_AIR)) || (Action.equals(org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK))) {
                 
                        if(Player.hasPerm...
    New
    Code:
        @EventHandler
        public void PlayerInteractEvent(PlayerInteractEvent Event) {
         
            Player Player = Event.getPlayer();
            Action Action = Event.getAction();
         
            if(Player.getItemInHand() != null) {
         
                int ItemID = Player.getItemInHand().getType().getId();
                String ItemName = Player.getItemInHand().getItemMeta().getDisplayName();
             
                if(ItemID == 329) {
                 
                    //RightClick with saddle
                    if((Action.equals(org.bukkit.event.block.Action.RIGHT_CLICK_AIR)) || (Action.equals(org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK))) {
                 
                        if(Player.hasPerm...
     
  6. Offline

    Ross Gosling

    Fixed it myself
    Code:
        @EventHandler
        public void PlayerInteractEvent(PlayerInteractEvent Event) {
           
            Player Player = Event.getPlayer();
           
            if((Player.getItemInHand() == null) || (Player.getItemInHand().getTypeId() == 0)) {
               
            }
           
            else if(Player.getItemInHand() != null) {
           
                int ItemID = Player.getItemInHand().getType().getId();
                String ItemName = Player.getItemInHand().getItemMeta().getDisplayName();
               
                Action Action = Event.getAction();
               
                if(ItemID == 329) {
                   
                    //RightClick with saddle
                    if((Action.equals(org.bukkit.event.block.Action.RIGHT_CLICK_AIR)) || (Action.equals(org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK))) {
                   
                        if(Player.hasPerm...
     
Thread Status:
Not open for further replies.

Share This Page