Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-5041

Can't modify chunk in ChunkUnloadEvent


    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • None
    • git-Spigot-baafee9-17543ec (MC: 1.14.2) (Implementing API version 1.14.2-R0.1-SNAPSHOT)
    • Yes

      When trying to set a block in a chunk that is currently being unloaded (in the ChunkUnloadEvent) a ConcurrentModificatioException is thrown. I guess this is due to the chunk being unmarked as unloadable. The server did not crash when I tested on a local server. However I saw servers crashing due to this issue.

      Exception in the console:


      Example plugin code (binary included as an attachment):

      import org.bukkit.Bukkit;
      import org.bukkit.Material;
      import org.bukkit.World;
      import org.bukkit.event.EventHandler;
      import org.bukkit.event.Listener;
      import org.bukkit.event.world.ChunkUnloadEvent;
      import org.bukkit.plugin.java.JavaPlugin;
      public class TestPlugin extends JavaPlugin implements Listener {
         public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
         public void onChunkUnload(ChunkUnloadEvent e) {
            Bukkit.broadcastMessage("unload " + e.getChunk().getX() + "/" + e.getChunk().getZ());
            World world = e.getWorld();
            world.getBlockAt(e.getChunk().getX() >> 4, 100, e.getChunk().getZ() >> 4).setType(Material.GLASS);

            Unassigned Unassigned
            Gerrygames Gero Cammans
            2 Vote for this issue
            5 Start watching this issue