Event Exceptions

Discussion in 'Plugin Development' started by BungeeTheCookie, Aug 4, 2014.

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

    BungeeTheCookie

    Hello Bukkit community! I am trying to make it so when an event for when an arena is enabled, it is cancelled. I am using a GameManager.getinstance().getArena(b.getWorld()) == null) return; check, but when an arena is null and even though the return statement is supposed to stop it, a stracktrace is being spammed. Here is my code for example,

    Code:
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onDecay(LeavesDecayEvent e){
            Block b = e.getBlock();
            if(GameManager.getInstance().getArena(b.getWorld()) == null) return; Arena a = GameManager.getInstance().getArena(b.getWorld());
            if(a != null){
                if(a.isEnabled() && !a.isUsed()){
                    e.setCancelled(true);
                }
            }
        }
     
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onSignChange(SignChangeEvent e){
            BlockState b = e.getBlock().getState();
            if(GameManager.getInstance().getArena(b.getWorld()) == null) return; Arena a = GameManager.getInstance().getArena(b.getWorld());
            if(a != null){
                if(a.isEnabled() && !a.isUsed()){
                    e.setCancelled(true);
                }
            }
        }
     
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onBlockSpread(BlockSpreadEvent e){
            Block b = e.getBlock();
            if(GameManager.getInstance().getArena(b.getWorld()) == null) return; Arena a = GameManager.getInstance().getArena(b.getWorld());
            if(a != null){
                if(a.isEnabled() && !a.isUsed()){
                    e.setCancelled(true);
                }
            }
        }
    And here is my getArena code:
    Code:
        public Arena getArena(World world) {
            for (Arena a : getArenas().values()) {
                if (a.getWorld().equals(world)) {
                    return a;
                }
            }
            return null;
        }
    If return null throws a NullPointerException, how do I catch it?
     
  2. Offline

    AoH_Ruthless

    BungeeTheCookie
    Check to make sure the blockstate is not null (I think it is null for some reason).
     
  3. Offline

    BungeeTheCookie

    No wonder. So I need to do it e.getBlock() instanceof BlockState and then cast the block to blockstate if it is?

    AoH_Ruthless
    Why would it be null in the first place?

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

    fireblast709

    AoH_Ruthless null Blocks from events... evenore, null BlockStates straight from the Block ಠ_ಠ
    BungeeTheCookie you will get a ClassCastException instead. Post your stack trace (and point us the lines, please :3)
     
  5. Offline

    BungeeTheCookie


    PHP:
    org.bukkit.event.EventException
        at org
    .bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:299) ~[Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [Spigot.jar:git-Spigot-1561]
        
    at bungeecookie.dtc.listeners.BlockTransformListener.callEvent(BlockTransformListener.java:29) [Destroy%20The%20Core.jar:?]
        
    at bungeecookie.dtc.listeners.BlockTransformListener.onBlockSpread(BlockTransformListener.java:62) [Destroy%20The%20Core.jar:?]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0]
        
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:296) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.handleBlockSpreadEvent(CraftEventFactory.java:365) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.BlockVine.a(BlockVine.java:250) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.WorldServer.g(WorldServer.java:433) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.WorldServer.doTick(WorldServer.java:215) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:687) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [Spigot.jar:git-Spigot-1561]
    Caused byjava.lang.NullPointerException
        at bungeecookie
    .dtc.game.GameManager.getArena(GameManager.java:92) ~[?:?]
        
    at bungeecookie.dtc.listeners.ArenaListener.onCoreBreakBypass(ArenaListener.java:52) ~[?:?]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0]
        
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:296) ~[Spigot.jar:git-Spigot-1561]
        ... 
    22 more
    [12:04:37] [Server thread/ERROR]: Could not pass event BlockSpreadEvent to DestroyTheCore v1.0
    org
    .bukkit.event.EventException
        at org
    .bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:299) ~[Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.handleBlockSpreadEvent(CraftEventFactory.java:365) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.BlockVine.a(BlockVine.java:250) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.WorldServer.g(WorldServer.java:433) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.WorldServer.doTick(WorldServer.java:215) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:687) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [Spigot.jar:git-Spigot-1561]
    Caused byjava.lang.NullPointerException
        at bungeecookie
    .dtc.game.GameManager.getArena(GameManager.java:92) ~[?:?]
        
    at bungeecookie.dtc.listeners.ArenaListener.onBlockSpread(ArenaListener.java:131) ~[?:?]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0]
        
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:296) ~[Spigot.jar:git-Spigot-1561]
        ... 
    12 more
    [12:04:38] [Server thread/ERROR]: Could not pass event ItemDespawnEvent to DestroyTheCore v1.0
    org
    .bukkit.event.EventException
        at org
    .bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:299) ~[Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callItemDespawnEvent(CraftEventFactory.java:332) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.EntityItem.h(EntityItem.java:130) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.World.entityJoinedWorld(World.java:1603) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.World.playerJoinedWorld(World.java:1578) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.World.tickEntities(World.java:1443) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.WorldServer.tickEntities(WorldServer.java:516) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:703) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [Spigot.jar:git-Spigot-1561]
    Caused byjava.lang.NullPointerException
        at bungeecookie
    .dtc.game.GameManager.getArena(GameManager.java:92) ~[?:?]
        
    at bungeecookie.dtc.listeners.ArenaListener.onItemDespawn(ArenaListener.java:177) ~[?:?]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0]
        
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:296) ~[Spigot.jar:git-Spigot-1561]
        ... 
    14 more
    [12:04:38] [Server thread/ERROR]: Could not pass event BlockTransformEvent to DestroyTheCore v1.0
    org
    .bukkit.event.EventException
        at org
    .bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:299) ~[Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [Spigot.jar:git-Spigot-1561]
        
    at bungeecookie.dtc.listeners.BlockTransformListener.callEvent(BlockTransformListener.java:29) [Destroy%20The%20Core.jar:?]
        
    at bungeecookie.dtc.listeners.BlockTransformListener.onBlockSpread(BlockTransformListener.java:62) [Destroy%20The%20Core.jar:?]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0]
        
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:296) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.handleBlockSpreadEvent(CraftEventFactory.java:365) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.BlockVine.a(BlockVine.java:250) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.WorldServer.g(WorldServer.java:433) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.WorldServer.doTick(WorldServer.java:215) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:687) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [Spigot.jar:git-Spigot-1561]
    Caused byjava.lang.NullPointerException
        at bungeecookie
    .dtc.game.GameManager.getArena(GameManager.java:92) ~[?:?]
        
    at bungeecookie.dtc.listeners.ArenaListener.onCoreBreakBypass(ArenaListener.java:52) ~[?:?]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0]
        
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:296) ~[Spigot.jar:git-Spigot-1561]
        ... 
    22 more
    [12:04:38] [Server thread/ERROR]: Could not pass event BlockSpreadEvent to DestroyTheCore v1.0
    org
    .bukkit.event.EventException
        at org
    .bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:299) ~[Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [Spigot.jar:git-Spigot-1561]
        
    at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.handleBlockSpreadEvent(CraftEventFactory.java:365) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.BlockVine.a(BlockVine.java:250) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.WorldServer.g(WorldServer.java:433) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.WorldServer.doTick(WorldServer.java:215) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:687) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [Spigot.jar:git-Spigot-1561]
        
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [Spigot.jar:git-Spigot-1561]
    Caused byjava.lang.NullPointerException
        at bungeecookie
    .dtc.game.GameManager.getArena(GameManager.java:92) ~[?:?]
        
    at bungeecookie.dtc.listeners.ArenaListener.onBlockSpread(ArenaListener.java:131) ~[?:?]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0]
        
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:296) ~[Spigot.jar:git-Spigot-1561]
        ... 
    12 more
     
  6. Offline

    fireblast709

  7. Offline

    BungeeTheCookie


    Code:
    if (a.getWorld().equals(world)) {
     
  8. Offline

    fireblast709

  9. Offline

    BungeeTheCookie


    Code:
     for (Arena a : getArenas().values()) {
                if (a.getWorld().equals(world)) {
                    return a;
                }
            }
    Neither can return null, because in order for an Arena to exist, the world has to exist as well.
     
  10. Offline

    Necrodoom

  11. Offline

    fireblast709

  12. Offline

    BungeeTheCookie

  13. Offline

    fireblast709

    BungeeTheCookie either has to be null in order for the error to be thrown
     
  14. Offline

    BungeeTheCookie

    It's not though. ;(

    fireblast709
    Lol Im stupid. In onEnable() I loaded the worlds after I loaded the Arenas, causing them to be null. Thanks

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

    Necrodoom

    Applies to both the supported and the supporter.
     
  16. Offline

    fireblast709

    Necrodoom well sorry that I helped someone with generic Java errors (and before I get burned for it, I know it's not counted as a valid argument)
     
  17. Offline

    Iroh

    Locked.
    Seek help where you acquired your server mod.
     
Thread Status:
Not open for further replies.

Share This Page