Solved Wand plugin bug

Discussion in 'Plugin Development' started by Tim203, Dec 24, 2016.

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

    Tim203

    Hello bukkit members,

    I have a question about my first plugin, i getting stuck by a little bug when i click left or right on a not-wand block.
    The console, left click (on a non-wand) block:
    Console error left click block (open)

    Could not pass event PlayerInteractEvent to TheWands v0.1
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot.jar:git-Spigot-870264a-0a645a2]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-870264a-0a645a2]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-870264a-0a645a2]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-870264a-0a645a2]
    at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:227) [spigot.jar:git-Spigot-870264a-0a645a2]
    at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:194) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.PlayerInteractManager.a(PlayerInteractManager.java:107) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:604) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.PacketPlayInBlockDig.a(SourceFile:40) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.PacketPlayInBlockDig.a(SourceFile:10) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-870264a-0a645a2]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_111]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_111]
    at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:712) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot.jar:git-Spigot-870264a-0a645a2]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.NullPointerException
    at io.github.tim203.KDWands.Wands.isWand(Wands.java:31) ~[?:?]
    at io.github.tim203.KDWands.Listeners.PlayerInteract(Listeners.java:38) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_111]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_111]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_111]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_111]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot.jar:git-Spigot-870264a-0a645a2]
    ... 18 more

    The console, right click (non-wand) block:
    Console error right click block (open)

    Could not pass event PlayerInteractEvent to TheWands v0.1
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot.jar:git-Spigot-870264a-0a645a2]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-870264a-0a645a2]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-870264a-0a645a2]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-870264a-0a645a2]
    at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:227) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.PlayerInteractManager.interact(PlayerInteractManager.java:463) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:740) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-870264a-0a645a2]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_111]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_111]
    at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:712) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot.jar:git-Spigot-870264a-0a645a2]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.NullPointerException
    at io.github.tim203.KDWands.Wands.isWand(Wands.java:31) ~[?:?]
    at io.github.tim203.KDWands.Listeners.PlayerInteract(Listeners.java:27) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_111]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_111]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_111]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_111]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot.jar:git-Spigot-870264a-0a645a2]
    ... 17 more

    And the code, Wands.java: (around the) 31
    Code:
    28:    public boolean isWand(ItemStack i) {
    29:        String name = i.getItemMeta().getDisplayName();
    30:        for (String s : wandtypes) {
    31:            if(name.equalsIgnoreCase(s)) {
    32:                return true;
    33:            }
    34:        }
    35:        return false;
    36:    }
    
    And the code, Listeners: Around the 27 and including 38
    Code:
    19:    @EventHandler
    20:    public void PlayerInteract(PlayerInteractEvent e) {
    21:        Action a = e.getAction();
    22:        Player p = e.getPlayer();
    23:        String name = p.getName();
    24:  
    25:        if(a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) {
    26:            ItemStack i = p.getItemInHand();
    27:            if(WP.wand.isWand(i)) {
    28:                if(WP.wand.hasSpell(name)) {
    29:                    WP.wand.nextSpell(name);
    30:                    p.sendMessage(WP.title + ChatColor.GOLD + "Spell set to: " + WP.spell.getSpell(p));
    31:                } else {
    32:                    WP.wand.setSpell(name, 0);
    33:                    p.sendMessage(WP.title + ChatColor.GOLD + "Spell set to: " + WP.spell.getSpell(p));
    34:                }
    35:            }
    36:        } else if(a == Action.LEFT_CLICK_AIR || a == Action.LEFT_CLICK_BLOCK) {
    37:            ItemStack i = p.getItemInHand();
    38:            if(WP.wand.isWand(i)) {
    39:                WP.spell.FireSpell(WP.spell.getSpell(p), name);
    40:            }
    41:        }
    42:    }
    
    I hope that you can help me and that i can learn something new.
     
    Last edited: Dec 24, 2016
  2. Offline

    Zombie_Striker

    @Tim203
    When you are not holding anything in your hand, the "ItemInHand" will return a null variable. Make sure the item is not null before using the item.
     
  3. Offline

    Tim203

    @Zombie_Striker Thanks for your answer, the right click error is now fixed :)

    But the left click still gives a error.

    The current source:
    Source PlayerInteract (open)

    Code:
    19       @EventHandler
    20        public void PlayerInteract(PlayerInteractEvent e) throws Throwable {
    21                if (e == null) {
    22                    return;
    23                }
    24                else {
    25                    Action a = e.getAction();
    26                    Player p = e.getPlayer();
    27                    String name = p.getName();
    28                    ItemStack i = p.getItemInHand();
    29                    if (i == null) {
    30                        return;
    31                    } else {
    32                        if(a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) {
    33                            if(WP.wand.isWand(i)) {
    34                                if(WP.wand.hasSpell(name)) {
    35                                    WP.wand.nextSpell(name);
    36                                    p.sendMessage(WP.title + ChatColor.GOLD + "Spell set to: " + WP.spell.getSpell(p));
    37                                } else {
    38                                    WP.wand.setSpell(name, 0);
    39                                    p.sendMessage(WP.title + ChatColor.GOLD + "Spell set to: " + WP.spell.getSpell(p));
    40                                }
    41                            }
    42                            else {
    43                                return;
    44                            }
    45                        }
    46               
    47                        if(a == Action.LEFT_CLICK_AIR || a == Action.LEFT_CLICK_BLOCK) {
    48                            if(WP.wand.isWand(i)) {
    49                                WP.spell.FireSpell(WP.spell.getSpell(p), name);
    50                            } else {
    51                                return;
    52                            }
    53                        }
    54                    }
    55                }
    56          
    57        }
    


    Source isWand (open)

    Code:
    33        public boolean isWand(ItemStack i) {
    34                if (i == null) {
    35                    return false;
    36                } else {
    37                    String name = i.getItemMeta().getDisplayName();
    38                    if (name != null) {
    39                        for (String s : wandtypes) {
    40                            if(name.equalsIgnoreCase(s)) {
    41                                return false;
    42                            }
    43                        }
    44                    } else {
    45                        return false;
    46                    }
    47                    return false;
    48                }
    49        }
    


    The console says:
    Console error left click block (open)

    Could not pass event PlayerInteractEvent to TheWands v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot.jar:git-Spigot-870264a-0a645a2]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-870264a-0a645a2]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-870264a-0a645a2]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-870264a-0a645a2]
    at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:227) [spigot.jar:git-Spigot-870264a-0a645a2]
    at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:194) [spigot.jar:git-Spigot-870264a-0a645a2]
    at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:190) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:1190) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.PacketPlayInArmAnimation.a(PacketPlayInArmAnimation.java:18) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.PacketPlayInArmAnimation.a(PacketPlayInArmAnimation.java:1) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-870264a-0a645a2]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_111]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_111]
    at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:712) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot.jar:git-Spigot-870264a-0a645a2]
    at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot.jar:git-Spigot-870264a-0a645a2]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.NullPointerException
    at io.github.tim203.TimWands.Wands.isWand(Wands.java:37) ~[?:?]
    at io.github.tim203.TimWands.Listeners.PlayerInteract(Listeners.java:48) ~[?:?]

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_111]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_111]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_111]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_111]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot.jar:git-Spigot-870264a-0a645a2]
    ... 18 more


    Thanks for your help!
     
    Last edited: Dec 24, 2016
  4. Offline

    Zombie_Striker

    @Tim203
    1. "i" can be null.
    2. Item meta can be null
    3. the displayname can be null.
    4. wandtypes can be null
    Go through each variable and figure out which one is null.
     
  5. Offline

    Tim203

    @Zombie_Striker Thanks man!
    The DisplayName was null.
    Thanks for help and if i have more questions, i can post it right?
    (Without saying it is solved?)
    Or it is more convenient to say that it is solved and if i have a new error that i make a new thread?
     
    Last edited: Dec 24, 2016
  6. Offline

    Zombie_Striker

    @Tim203
    If the error relates to this problem (with the wand), then yes, post it here. If not (it is for a different plugin/ different part of the plugin), then mark this as solved and make a new thread.
     
  7. Offline

    Tim203

    ok, thank you :)
     
Thread Status:
Not open for further replies.

Share This Page