Solved org.bukkit.World#createExplosion throws java.util.NoSuchElementException

Discussion in 'Spigot Plugin Development' started by TheSniper99, Jan 8, 2020.

  1. Hello to everyone, as you can read from the title my plugin thrown a java.util.NoSuchElementException while running the function below:
    Code (Java):
        private void fakeExplosion(final Location location) {
            location.getWorld().createExplosion(location.getX(), location.getY(), location.getZ(), 4, false, false);
        }
    Parameters of World#createExplosion:
    x X coordinate
    y Y coordinate
    z Z coordinate
    power The power of explosion, where 4F is TNT
    setFire Whether or not to set blocks on fire
    breakBlocks Whether or not to have blocks be destroyed

    Here's the stacktrace:
    Code (Text):
    In date 08 January 2020 17:32:06 an exception caused by java.util.NoSuchElementException has been generated!

    *** BEGIN EXCEPTION STACKTRACE ***

    org.bukkit.craftbukkit.v1_12_R1.util.UnsafeList$Itr.next(UnsafeList.java:248)
    net.minecraft.server.v1_12_R1.Chunk.a(Chunk.java:1033)
    net.minecraft.server.v1_12_R1.World.getEntities(World.java:2627)
    net.minecraft.server.v1_12_R1.Explosion.a(Explosion.java:108)
    net.minecraft.server.v1_12_R1.World.createExplosion(World.java:2064)
    net.minecraft.server.v1_12_R1.WorldServer.createExplosion(WorldServer.java:1287)
    org.bukkit.craftbukkit.v1_12_R1.CraftWorld.createExplosion(CraftWorld.java:580)
    arena.Arena.fakeExplosion(Arena.java:1311)
    arena.Arena.onPlayerDeath(Arena.java:1481)
    arena.Arena.runPlayersTick(Arena.java:949)
    arena.Arena.runTick(Arena.java:832)
    main.SpaceWars$Clock.run(SpaceWars.java:1165)

    *** END EXCEPTION STACKTRACE ***

     
    What I'm asking is: why did it happen? This error occurred only once in over a year that I'm running this plugin, why? Did I make a mistake? From the Java documentation it says that this exception is "Thrown by various accessor methods to indicate that the element being requested does not exist" such as enumerations or iterators. Does anyone have any idea about this?
     
    #1 TheSniper99, Jan 8, 2020
    Last edited: Apr 30, 2020
  2. This was created by CraftWorld#createExplosion()... did this occur only once?
    All you can do to prevent this: Update to the newest version and (obvsly) dont use reloads
     
  3. arena.Arena.fakeExplosion(Arena.java:1311)

    Line 1311 please? Also, for the love of God, please split your code up into separate classes.
     
    • Agree Agree x 1
  4. Yeah, only once in over a year
    Updating it to newest verstions will be a challenge, it uses some NMS to improve performance and resolve some problems, but it can be done. The plugin itself supports reloads, so I don't use the /reload command
    Code (Text):
    location.getWorld().createExplosion(location.getX(), location.getY(), location.getZ(), 4, false, false);
    I have 86 classes in 14 packages
    [​IMG]
     
  5. electronicboy

    IRC Staff

    Using the bukkit API async is not safe, stick to calling that stuff from the main thread...
     
  6. What does exactly World#createExplosion do? I supposed it just sends packets saying that an explosion occurred if the map isn't changed... should I run that using Scheduler#callSyncMethod and waiting for the Future#get method?
     
  7. You still want to split it up further probably. Having classes >1k LOC is just a huge mess
     
  8. Alright my problem got resolved, this is the answer. Thank you guys
     
  9. electronicboy

    IRC Staff

    it creates an explosion, as the method implies; The specific behavior of the explosion that caused your issue is the fact that it looks for entities being damaged, worth noting that you should actually consider if the work you're doing overall is actually safe to do async or not, and if there is really any gains from async (often times, the process of having to ensure thread safety and doing stuff over multiple threads completely kills all of the gains from async work)
     
    • Useful Useful x 1