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!




    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(

    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
  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