Solved Could not pass but passed

Discussion in 'Plugin Development' started by spy85, Feb 24, 2014.

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

    spy85

    Several of my plugins use PlayerInteractEvents and in console always say something like: Could not pass PlayerInteractEvent to iTutorial 1.0 but the weird thing is the plugin executes everything as needed with no problems. So it says its not passing it but it is? Why is this and how can I make sure its properly passing without error in console like that?

    Thanks!
     
  2. Offline

    MrInspector

    Probably something wrong with your code. ;)
     
  3. Offline

    spy85

    I must be doing it every time because it does this every time I make a plugin. Here I'll post the source code.

    What am I doing incorrectly or in properly?
    Code:java
    1. package Signs;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.block.Sign;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.player.PlayerInteractEvent;
    10. import org.bukkit.plugin.Plugin;
    11.  
    12. import Interfaces.Labels;
    13.  
    14. import com.garris0n.BaseSiege.Kit.Kit;
    15. import com.garris0n.BaseSiege.Kit.KitHandler;
    16.  
    17. public class ClassSign implements Listener, Labels {
    18.  
    19. private static Plugin plugin;
    20. public ClassSign(Plugin plugin){
    21. this.plugin = plugin;
    22. }
    23.  
    24. @EventHandler
    25. public void onSignClick(PlayerInteractEvent e){
    26. Player player = e.getPlayer();
    27.  
    28. if(e.getClickedBlock().getTypeId() != 63 && e.getClickedBlock().getTypeId() != 68){
    29. return;
    30. }
    31. Sign sign = (Sign)e.getClickedBlock().getState();
    32.  
    33. if(!sign.getLine(0).contains("[Class]") && !sign.getLine(0).contains("[CLASS]")){
    34. return;
    35. }
    36. Kit kit = KitHandler.loadKit(sign.getLine(2));
    37. String defaultKitName = plugin.getConfig().getString("classes.defaultKitName");
    38.  
    39. try{
    40. kit.getName();
    41. }catch(Exception e1){
    42. player.sendMessage(chatPrefix+ChatColor.RED+"Class not found.");
    43. }
    44.  
    45. if(!player.hasPermission("wwz.class."+kit.getName().toLowerCase())){
    46. player.sendMessage(chatPrefix+ChatColor.RED+
    47. "You do not own this class. Purchase this class at "+
    48. ChatColor.AQUA+"[URL]http://www.strikecraft.net/wwzshop/[/URL]");
    49. return;
    50. }
    51.  
    52. try{
    53. KitHandler.getKit(player).getName();
    54. }catch(Exception e2){
    55. KitHandler.setKit(player, KitHandler.getKit(defaultKitName));
    56. }
    57.  
    58. if(kit.getName().equals( KitHandler.getKit(player).getName() )){
    59. player.sendMessage(chatPrefix+ChatColor.RED+"You already have this class selected.");
    60. return;
    61. }
    62.  
    63. KitHandler.setKit(player, kit);
    64. player.sendMessage(chatPrefix+ChatColor.AQUA+"You will now spawn with the class "+kit.getName()+".");
    65. }
    66.  
    67. }
    68.  


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

    Sagacious_Zed Bukkit Docs

    When exceptions happen, part of the code may have executed, which may have some consequence.

    You should also paste the error into a code block
     
  5. Offline

    spy85

    Ok could you look at the code I just posted and check out what the problem may be. Thanks!
    (maybe it has something to do with when I register the listener?)
     
  6. Offline

    Sagacious_Zed Bukkit Docs

    It takes much longer to work out exactly why Bukkit could not pass PlayerInteractEvent without the stacktrace
     
  7. Offline

    spy85

    To make it quicker I'll just put a try catch around the entire contents of the method listener and see if it throws anything and then it will tell me specifically what line although I can't see how anything could be being thrown as it successfully makes it through the end.

    By the way if it helps here is the registrations for the listeners in case anything is up:

    Code:java
    1. getServer().getPluginManager().registerEvents(new JoinLeaveListener(this), this);
    2. getServer().getPluginManager().registerEvents(co.deathListener, this);
    3. getServer().getPluginManager().registerEvents(new ZombiesSunBurn(this), this);
    4. getServer().getPluginManager().registerEvents(new JoinGameSign(this), this);
    5. getServer().getPluginManager().registerEvents(new HurtListener(this), this);
    6. getServer().getPluginManager().registerEvents(new ChatListener(this), this);
    7. getServer().getPluginManager().registerEvents(new ClassSign(this), this);


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

    Luke_Lax

    Just post the stacks trace that says it did not pass, that'll give us a reason and a line number
     
  9. Offline

    Garris0n

    First of all, you should be using getKit instead of loadKit. The loadKit method loads it from the file, the getKit gets it from the already loaded list.
    Second, what are those try/catch blocks for? The getName() method would throw a NullPointerException if the kit was null, but you could just check it if was null. Also, right after doing the check, you use getName() again anyway, so that would throw a NullPointerException regardless.
     
  10. Offline

    spy85

    Ya I used a try catch with the getName() to test if it was valid or not basically idk why I did that tbh just not thinking.

    Here it is:
    Code:
    [16:59:55] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to WorldWarZ v2.5
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:481) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:466) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:191) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:161) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:978) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInArmAnimation.a(SourceFile:43) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInArmAnimation.handle(SourceFile:9) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    Caused by: java.lang.NullPointerException
    at Signs.ClassSign.onSignClick(ClassSign.java:28) ~[?:?]
    at sun.reflect.GeneratedMethodAccessor46.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_17]
    at java.lang.reflect.Method.invoke(Method.java:601) ~[?:1.7.0_17]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:318) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    ... 15 more
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  11. Offline

    Sagacious_Zed Bukkit Docs

    As stated in the stack trace the cause of bukkit not being able to pass the event was because of a null pointer exception. Also on the cause by line of the stack trace it points to line 28 of ClassSign.java.

    Upon inspecting that line, you never check the return value of getClickedBlock

    You should always read the entirety of the stack trace.
     
    Konkz likes this.
  12. Offline

    Garris0n

    Add a null check and don't proceed to use .getName() after it says the value is null. Also, don't use loadKit.
     
    Konkz likes this.
  13. Offline

    Konkz

    *Tesco Motto*
    Stack Trace, every little help.Also

    @spy85 you will find this post VERY helpful http://forums.bukkit.org/threads/ho...ubleshoot-your-own-plugins-by-yourself.32457/
     
  14. Offline

    spy85

    I am confused why is getClickedBlock() throwing null pointer exception? How can it be?
     
  15. Offline

    Konkz


    I shall repeat something posted above.

    Just add a null check.
     
  16. Offline

    spy85

    Oh that makes sense sorry I am falling asleep right now I can't focus. My bad.

    Konkz thanks so much I appreciate the help!

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

    Konkz


    Don't thank me, thank Garris0n
     
  18. Offline

    spy85

    Oh I already did through skype haha! But thanks so much Garris0n I really appreciate it!!!
     
    Garris0n and Konkz like this.
Thread Status:
Not open for further replies.

Share This Page