Player interact event error

Discussion in 'Plugin Development' started by gamer1097, Jul 30, 2013.

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

    gamer1097

    Error
    Code:
    14:50:11 [SEVERE] Could not pass event PlayerInteractEvent to MobAPA v<1.0>
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:427)
            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.v1_5_R3.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:190)
            at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:160)
            at net.minecraft.server.v1_5_R3.PlayerConnection.a(PlayerConnection.java
    :1010)
            at net.minecraft.server.v1_5_R3.Packet18ArmAnimation.handle(SourceFile:4
    1)
            at net.minecraft.server.v1_5_R3.NetworkManager.b(NetworkManager.java:292
    )
            at net.minecraft.server.v1_5_R3.PlayerConnection.d(PlayerConnection.java
    :115)
            at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35)
            at net.minecraft.server.v1_5_R3.DedicatedServerConnection.b(SourceFile:3
    0)
            at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:5
    81)
            at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:2
    26)
            at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:4
    77)
            at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java
    :410)
            at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:5
    73)
    Caused by: java.lang.NullPointerException
            at net.gamersmods.MobAPA.Listener.EventListener.playerInteract(EventList
    ener.java:110)
            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:425)



    Player interact event
    Code:
        @EventHandler
        public void playerInteract(PlayerInteractEvent event)
        {
            Player player = event.getPlayer();
            Action action = event.getAction();
            Material block = event.getClickedBlock().getType();
           
            if(action == Action.RIGHT_CLICK_BLOCK)
            {
                if(block == Material.SIGN_POST || block == Material.WALL_SIGN)
                {
                    Sign sign = (Sign)event.getClickedBlock().getState();
                    String line1 = sign.getLine(1);
                   
                    if(line1.contains("[JoinGame]") && Main.plugin.Players.size() < Main.maxPlayers && Main.isWorldGenerated == true)
                    {
                        if(Main.plugin.InGameQueue.containsKey(player))
                        {
                            player.sendMessage(ReferenceStrings.errorJoin1);
                        }
                        else if(Main.GameStarted == false)
                        {
                            if(Main.plugin.Players.size() > 10)
                            {
                                Teleport.VotingAndToolSelection(player);
                                Main.plugin.InGameQueue.put(player, null);
                                Main.plugin.Players.put(player, null);
                                Bukkit.broadcastMessage(ChatColor.LIGHT_PURPLE + "[MobAPA] " + ChatColor.GREEN + player.getName() + " has joined the Game. " + Main.plugin.Players.size() + "/" + Main.maxPlayers + " Joined");
                            }
                            else
                            {
                                Teleport.VotingAndToolSelection(player);
                                Main.plugin.InGameQueue.put(player, null);
                                Main.plugin.Players.put(player, null);
                                Bukkit.broadcastMessage(ChatColor.LIGHT_PURPLE + "[MobAPA] " + ChatColor.GREEN + player.getName() + " has joined the Game. We need 10 players to start! There are currently: " + Main.plugin.Players.size() + "/" + Main.maxPlayers + " Joined");
                                System.out.println(Main.plugin.Players.size());
                                if(Main.plugin.Players.size() == 10)
                                {
                                    CountDown.StartCountDownTimer(player);
                                }   
                            }
                        }
                        else if(Main.GameStarted == true)
                        {
                            player.sendMessage(ReferenceStrings.errorJoin2);
                        }
                    }
                    else
                    {
                        if(Main.isWorldGenerated == false)
                        {
                            player.sendMessage(ReferenceStrings.worldIsNotGenerated);
                        }
                        else
                        {
                            player.sendMessage(ReferenceStrings.errorJoin3);   
                        }
                    }
                   
                }
            }
           
        }
     
  2. Offline

    foodyling

    Are you even going to bother and check if there is a block in the event at all? Material block = event.getClickedBlock().getType(); wont work if there is no block you know.
     
  3. Offline

    gamer1097

    It works but when I click in the air or anything thats not a sign it does that error
     
  4. Offline

    foodyling

    gamer1097 Did you even bother to read what I said, or just post more information on the error?
     
  5. Offline

    Seadragon91

    How he said, if you click into the air the block is null and that will threw the NPE. Check if the block
    1) is null
    or check if you click on a block with
    2) Action.LEFT_CLICK_BLOCK. Action.RIGHT_CLICK_BLOCK

    Do that before you get the type of the block.
     
  6. Offline

    gamer1097



    I tried many things and I can' get it to work.
    http://pastebin.com/TnL4iD1E

    Anyone want to help?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  7. Offline

    Seadragon91

  8. Offline

    xTrollxDudex

    gamer1097
    Most likely you didn't instatiate Main. What is line 110?
     
  9. Offline

    IcyRelic

    add this to the start of the event

    Code:java
    1. if (!event.hasBlock()){
    2. return;
    3. }
     
  10. Offline

    gamer1097




    Error
    Code:
    31.07 11:38:24 [Server] INFO at net.gamersmods.MobAPA.Listener.EventListener.playerInteract(EventListener.java:176)
    31.07 11:38:24 [Server] INFO Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_6_R2.block.CraftBlockState cannot be cast to org.bukkit.block.Sign

    Code
    http://pastebin.com/1AwwT3uW


    I get this error
    Code:
    31.07 11:38:24 [Server] INFO at net.gamersmods.MobAPA.Listener.EventListener.playerInteract(EventListener.java:176)
    31.07 11:38:24 [Server] INFO Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_6_R2.block.CraftBlockState cannot be cast to org.bukkit.block.Sign
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  11. Offline

    Seadragon91


    Ops, sorry. Please change this:
    Code:
     if (action == Action.RIGHT_CLICK_BLOCK)
    to
    Code:
    if (action == Action.RIGHT_CLICK_BLOCK && (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)) {
    The error will be thrown if you right-click on a block that is not a sign, forget to add a check for that.
     
  12. Offline

    gamer1097




    Thank You
     
Thread Status:
Not open for further replies.

Share This Page