From 70dae5976de608596b7d6e2a5a86ecb45d7f372d Mon Sep 17 00:00:00 2001 From: Helvetica Volubi Date: Sun, 28 Sep 2025 15:49:30 +0800 Subject: [PATCH] fix: try fixes #63 --- .../0010-Leaves-Base-Protocol-Core.patch | 4 +-- .../0022-Leaves-Leaves-Fakeplayer.patch | 16 ++++++---- .../java/org/leavesmc/leaves/bot/BotList.java | 30 ++++++++++++++++--- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/lophine-server/minecraft-patches/features/0010-Leaves-Base-Protocol-Core.patch b/lophine-server/minecraft-patches/features/0010-Leaves-Base-Protocol-Core.patch index 7542a8c..e7f6031 100644 --- a/lophine-server/minecraft-patches/features/0010-Leaves-Base-Protocol-Core.patch +++ b/lophine-server/minecraft-patches/features/0010-Leaves-Base-Protocol-Core.patch @@ -8,10 +8,10 @@ As a part of : Leaves (https://github.com/LeavesMC/Leaves/blob/ea91106ae57fc4cc1 Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) diff --git a/io/papermc/paper/threadedregions/RegionizedServer.java b/io/papermc/paper/threadedregions/RegionizedServer.java -index c39a114c2f5dfef15e18478281106e6abc4fef42..71a26b3a47a7c5798bf2d2902313b74fefa1cfb8 100644 +index 8405157ec35a443e238fa6866772c839621d73d7..a261f66c29412039bbbaed4758bcade2e076da56 100644 --- a/io/papermc/paper/threadedregions/RegionizedServer.java +++ b/io/papermc/paper/threadedregions/RegionizedServer.java -@@ -333,6 +333,8 @@ public final class RegionizedServer { +@@ -334,6 +334,8 @@ public final class RegionizedServer { } // Luminol end - Add a config to enable tick command diff --git a/lophine-server/minecraft-patches/features/0022-Leaves-Leaves-Fakeplayer.patch b/lophine-server/minecraft-patches/features/0022-Leaves-Leaves-Fakeplayer.patch index 9730315..6933d3f 100644 --- a/lophine-server/minecraft-patches/features/0022-Leaves-Leaves-Fakeplayer.patch +++ b/lophine-server/minecraft-patches/features/0022-Leaves-Leaves-Fakeplayer.patch @@ -33,7 +33,7 @@ index 66ec0424a46dcd49cf44467357d80b1a2d84d3b2..04ae8de63af0a8abe578f14c8ef85fd4 private DisconnectionDetails disconnectionDetails; private boolean encrypted; diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java -index ef0b401affa58077e8dd32b52063202a1c7e0bb6..ffbbbe5752a0aa0228c1f74f5ac147578805fafa 100644 +index ef0b401affa58077e8dd32b52063202a1c7e0bb6..c461ab6c6ab21008be893f84913f0e6f9cf6d336 100644 --- a/net/minecraft/server/MinecraftServer.java +++ b/net/minecraft/server/MinecraftServer.java @@ -349,6 +349,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop S spin(Function threadFunction) { ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.init(); // Paper - rewrite data converter system AtomicReference atomicReference = new AtomicReference<>(); -@@ -1040,6 +1042,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 0) { // Folia - region threading - this is complicated to implement, and even if done correctly is messy @@ -62,7 +66,7 @@ index ef0b401affa58077e8dd32b52063202a1c7e0bb6..ffbbbe5752a0aa0228c1f74f5ac14757 this.emptyTicks++; } else { this.emptyTicks = 0; -@@ -1914,6 +1917,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop botsByName = Maps.newHashMap(); private final Map> botsNameByWorldUuid = Maps.newHashMap(); + public boolean forceShutdown = false; + public BotList(MinecraftServer server) { this.server = server; this.dataStorage = new BotDataStorage(server.storageSource); @@ -129,7 +134,7 @@ public class BotList { ResourceKey resourcekey = null; if (nbt.getLong("WorldUUIDMost").isPresent() && nbt.getLong("WorldUUIDLeast").isPresent()) { - org.bukkit.World bWorld = Bukkit.getServer().getWorld(new UUID(nbt.getLong("WorldUUIDMost").orElseThrow(), nbt.getLong("WorldUUIDLeast").orElseThrow())); + World bWorld = Bukkit.getServer().getWorld(new UUID(nbt.getLong("WorldUUIDMost").orElseThrow(), nbt.getLong("WorldUUIDLeast").orElseThrow())); if (bWorld != null) { resourcekey = ((CraftWorld) bWorld).getHandle().dimension(); } @@ -225,7 +230,7 @@ public class BotList { if (entity.hasExactlyOnePlayerPassenger()) { bot.stopRiding(); entity.getPassengersAndSelf().forEach((entity1) -> { - if (!false && entity1 instanceof AbstractVillager villager) { + if (entity1 instanceof AbstractVillager villager) { final Player human = villager.getTradingPlayer(); if (human != null) { villager.setTradingPlayer(null); @@ -279,11 +284,28 @@ public class BotList { } } - public void removeAll() { + public boolean removeAll() { + boolean finished = true; + AtomicInteger check = new AtomicInteger(); + AtomicInteger received = new AtomicInteger(); for (ServerBot bot : this.bots) { bot.resume = FakeplayerConfig.canResident; - this.removeBot(bot, BotRemoveEvent.RemoveReason.INTERNAL, null, FakeplayerConfig.canResident); + if (TickThread.isTickThreadFor(bot)) { + this.removeBot(bot, BotRemoveEvent.RemoveReason.INTERNAL, null, FakeplayerConfig.canResident); + } else { + finished = false; + check.getAndIncrement(); + bot.getBukkitEntity().taskScheduler.schedule((Entity unused) -> { + BotList.this.removeBot(bot, BotRemoveEvent.RemoveReason.INTERNAL, null, FakeplayerConfig.canResident); + received.getAndIncrement(); + if (received.get() >= check.get()) { + this.forceShutdown = true; + MinecraftServer.getServer().stopServer(); + } + }, null, 1L); + } } + return finished; } public void loadBotInfo() {