From 693a05f2cb378565fcf00f2a94e8c1726adae965 Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Mon, 25 Aug 2025 19:44:03 +0200 Subject: [PATCH] move the updater command out of dev --- .../iris/core/commands/CommandDeveloper.java | 1 - .../iris/core/commands/CommandIris.java | 21 +------ .../iris/core/commands/CommandStudio.java | 56 ++++++++++++------- .../iris/core/commands/CommandUpdater.java | 26 +++++---- 4 files changed, 54 insertions(+), 50 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/core/commands/CommandDeveloper.java b/core/src/main/java/com/volmit/iris/core/commands/CommandDeveloper.java index 3fc3df546..6080530bb 100644 --- a/core/src/main/java/com/volmit/iris/core/commands/CommandDeveloper.java +++ b/core/src/main/java/com/volmit/iris/core/commands/CommandDeveloper.java @@ -64,7 +64,6 @@ import java.util.zip.GZIPOutputStream; public class CommandDeveloper implements DecreeExecutor { private CommandTurboPregen turboPregen; private CommandLazyPregen lazyPregen; - private CommandUpdater updater; @Decree(description = "Get Loaded TectonicPlates Count", origin = DecreeOrigin.BOTH, sync = true) public void EngineStatus() { diff --git a/core/src/main/java/com/volmit/iris/core/commands/CommandIris.java b/core/src/main/java/com/volmit/iris/core/commands/CommandIris.java index 3f1c0b588..75448c8dc 100644 --- a/core/src/main/java/com/volmit/iris/core/commands/CommandIris.java +++ b/core/src/main/java/com/volmit/iris/core/commands/CommandIris.java @@ -21,7 +21,6 @@ package com.volmit.iris.core.commands; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.nms.INMS; -import com.volmit.iris.core.pregenerator.ChunkUpdater; import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.framework.Engine; @@ -33,7 +32,6 @@ import com.volmit.iris.util.decree.annotations.Decree; import com.volmit.iris.util.decree.annotations.Param; import com.volmit.iris.util.decree.specialhandlers.NullablePlayerHandler; import com.volmit.iris.util.format.C; -import com.volmit.iris.util.format.Form; import com.volmit.iris.util.io.IO; import com.volmit.iris.util.misc.ServerProperties; import com.volmit.iris.util.plugin.VolmitSender; @@ -56,6 +54,7 @@ import static org.bukkit.Bukkit.getServer; @Decree(name = "iris", aliases = {"ir", "irs"}, description = "Basic Command") public class CommandIris implements DecreeExecutor { + private CommandUpdater updater; private CommandStudio studio; private CommandPregen pregen; private CommandSettings settings; @@ -318,24 +317,6 @@ public class CommandIris implements DecreeExecutor { return dir.delete(); } - @Decree(description = "Updates all chunk in the specified world") - public void updater( - @Param(description = "World to update chunks at") - World world - ) { - if (!IrisToolbelt.isIrisWorld(world)) { - sender().sendMessage(C.GOLD + "This is not an Iris world"); - return; - } - ChunkUpdater updater = new ChunkUpdater(world); - if (sender().isPlayer()) { - sender().sendMessage(C.GREEN + "Updating " + world.getName() + " Total chunks: " + Form.f(updater.getChunks())); - } else { - Iris.info(C.GREEN + "Updating " + world.getName() + " Total chunks: " + Form.f(updater.getChunks())); - } - updater.start(); - } - @Decree(description = "Set aura spins") public void aura( @Param(description = "The h color value", defaultValue = "-20") diff --git a/core/src/main/java/com/volmit/iris/core/commands/CommandStudio.java b/core/src/main/java/com/volmit/iris/core/commands/CommandStudio.java index d6261ee23..2adb48780 100644 --- a/core/src/main/java/com/volmit/iris/core/commands/CommandStudio.java +++ b/core/src/main/java/com/volmit/iris/core/commands/CommandStudio.java @@ -182,17 +182,32 @@ public class CommandStudio implements DecreeExecutor { int rad = engine.getMantle().getRadius(); var mantle = engine.getMantle().getMantle(); var chunkMap = new KMap(); - for (int i = -(radius + rad); i <= radius + rad; i++) { - for (int j = -(radius + rad); j <= radius + rad; j++) { - int xx = i + x, zz = j + z; - if (Math.abs(i) <= radius && Math.abs(j) <= radius) { - mantle.deleteChunk(xx, zz); - continue; + ParallelQueueJob prep = new ParallelQueueJob<>() { + @Override + public void execute(Position2 pos) { + var cpos = pos.add(x, z); + if (Math.abs(pos.getX()) <= radius && Math.abs(pos.getZ()) <= radius) { + mantle.deleteChunk(cpos.getX(), cpos.getZ()); + return; } - chunkMap.put(new Position2(xx, zz), mantle.getChunk(xx, zz)); - mantle.deleteChunk(xx, zz); + chunkMap.put(cpos, mantle.getChunk(cpos.getX(), cpos.getZ())); + mantle.deleteChunk(cpos.getX(), cpos.getZ()); + } + + @Override + public String getName() { + return "Preparing Mantle"; + } + }; + for (int xx = -(radius + rad); xx <= radius + rad; xx++) { + for (int zz = -(radius + rad); zz <= radius + rad; zz++) { + prep.queue(new Position2(xx, zz)); } } + CountDownLatch pLatch = new CountDownLatch(1); + prep.execute(sender(), pLatch::countDown); + pLatch.await(); + ParallelQueueJob job = new ParallelQueueJob<>() { @Override @@ -210,23 +225,26 @@ public class CommandStudio implements DecreeExecutor { job.queue(new Position2(i + x, j + z)); } } - CountDownLatch latch = new CountDownLatch(1); job.execute(sender(), latch::countDown); latch.await(); int sections = mantle.getWorldHeight() >> 4; chunkMap.forEach((pos, chunk) -> { - var c = mantle.getChunk(pos.getX(), pos.getZ()); - for (MantleFlag flag : MantleFlag.values()) { - c.flag(flag, chunk.isFlagged(flag)); - } - c.clear(); - for (int y = 0; y < sections; y++) { - var slice = chunk.get(y); - if (slice == null) continue; - var s = c.getOrCreate(y); - slice.getSliceMap().forEach(s::putSlice); + var c = mantle.getChunk(pos.getX(), pos.getZ()).use(); + try { + for (MantleFlag flag : MantleFlag.values()) { + c.flag(flag, chunk.isFlagged(flag)); + } + c.clear(); + for (int y = 0; y < sections; y++) { + var slice = chunk.get(y); + if (slice == null) continue; + var s = c.getOrCreate(y); + slice.getSliceMap().forEach(s::putSlice); + } + } finally { + c.release(); } }); } catch (Throwable e) { diff --git a/core/src/main/java/com/volmit/iris/core/commands/CommandUpdater.java b/core/src/main/java/com/volmit/iris/core/commands/CommandUpdater.java index 38aba40a5..e19fc61ba 100644 --- a/core/src/main/java/com/volmit/iris/core/commands/CommandUpdater.java +++ b/core/src/main/java/com/volmit/iris/core/commands/CommandUpdater.java @@ -18,6 +18,7 @@ package com.volmit.iris.core.commands; +import lombok.Synchronized; import org.bukkit.World; import com.volmit.iris.Iris; @@ -32,7 +33,8 @@ import com.volmit.iris.util.format.Form; @Decree(name = "updater", origin = DecreeOrigin.BOTH, description = "Iris World Updater") public class CommandUpdater implements DecreeExecutor { - private ChunkUpdater chunkUpdater; + private final Object lock = new Object(); + private transient ChunkUpdater chunkUpdater; @Decree(description = "Updates all chunk in the specified world") public void start( @@ -43,19 +45,22 @@ public class CommandUpdater implements DecreeExecutor { sender().sendMessage(C.GOLD + "This is not an Iris world"); return; } - if (chunkUpdater != null) { - chunkUpdater.stop(); - } + synchronized (lock) { + if (chunkUpdater != null) { + chunkUpdater.stop(); + } - chunkUpdater = new ChunkUpdater(world); - if (sender().isPlayer()) { - sender().sendMessage(C.GREEN + "Updating " + world.getName() + C.GRAY + " Total chunks: " + Form.f(chunkUpdater.getChunks())); - } else { - Iris.info(C.GREEN + "Updating " + world.getName() + C.GRAY + " Total chunks: " + Form.f(chunkUpdater.getChunks())); + chunkUpdater = new ChunkUpdater(world); + if (sender().isPlayer()) { + sender().sendMessage(C.GREEN + "Updating " + world.getName() + C.GRAY + " Total chunks: " + Form.f(chunkUpdater.getChunks())); + } else { + Iris.info(C.GREEN + "Updating " + world.getName() + C.GRAY + " Total chunks: " + Form.f(chunkUpdater.getChunks())); + } + chunkUpdater.start(); } - chunkUpdater.start(); } + @Synchronized("lock") @Decree(description = "Pause the updater") public void pause( ) { if (chunkUpdater == null) { @@ -78,6 +83,7 @@ public class CommandUpdater implements DecreeExecutor { } } + @Synchronized("lock") @Decree(description = "Stops the updater") public void stop() { if (chunkUpdater == null) {