From 8dc1da156f8e3f67f7e1cb28fce78d5efe44e50f Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 25 Jun 2020 17:58:10 +1000 Subject: [PATCH] Misc bugfixes to multiworld support --- nms-patches/IChunkLoader.patch | 4 +- nms-patches/Main.patch | 7 +- nms-patches/MinecraftServer.patch | 53 ++++++------ nms-patches/PersistentStructureLegacy.patch | 41 +++++++++ nms-patches/PlayerChunkMap.patch | 2 +- nms-patches/WorldUpgrader.patch | 83 +++++++++++++++++++ .../org/bukkit/craftbukkit/CraftServer.java | 6 +- 7 files changed, 164 insertions(+), 32 deletions(-) create mode 100644 nms-patches/PersistentStructureLegacy.patch diff --git a/nms-patches/IChunkLoader.patch b/nms-patches/IChunkLoader.patch index f90191bcc3..780643b090 100644 --- a/nms-patches/IChunkLoader.patch +++ b/nms-patches/IChunkLoader.patch @@ -30,9 +30,9 @@ + + return false; + } -+ // CraftBukkit end + -+ public NBTTagCompound getChunkData(ResourceKey resourcekey, Supplier supplier, NBTTagCompound nbttagcompound, ChunkCoordIntPair pos, @Nullable GeneratorAccess generatoraccess) throws IOException { ++ public NBTTagCompound getChunkData(ResourceKey resourcekey, Supplier supplier, NBTTagCompound nbttagcompound, ChunkCoordIntPair pos, @Nullable GeneratorAccess generatoraccess) throws IOException { ++ // CraftBukkit end int i = a(nbttagcompound); boolean flag = true; diff --git a/nms-patches/Main.patch b/nms-patches/Main.patch index 6b139fc142..69d94353d5 100644 --- a/nms-patches/Main.patch +++ b/nms-patches/Main.patch @@ -101,7 +101,7 @@ Thread thread = new Thread("Server Shutdown Thread") { public void run() { dedicatedserver.safeShutdown(true); -@@ -157,6 +173,7 @@ +@@ -157,14 +173,15 @@ thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(Main.LOGGER)); Runtime.getRuntime().addShutdownHook(thread); @@ -109,11 +109,12 @@ } catch (Exception exception1) { Main.LOGGER.fatal("Failed to start the minecraft server", exception1); } -@@ -164,7 +181,7 @@ + } - public static void convertWorld(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, boolean flag, BooleanSupplier booleansupplier, ImmutableSet> immutableset) { +- public static void convertWorld(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, boolean flag, BooleanSupplier booleansupplier, ImmutableSet> immutableset) { - Main.LOGGER.info("Forcing world upgrade!"); ++ public static void convertWorld(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, boolean flag, BooleanSupplier booleansupplier, ImmutableSet> immutableset) { // CraftBukkit + Main.LOGGER.info("Forcing world upgrade! {}", convertable_conversionsession.getLevelName()); // CraftBukkit WorldUpgrader worldupgrader = new WorldUpgrader(convertable_conversionsession, datafixer, immutableset, flag); IChatBaseComponent ichatbasecomponent = null; diff --git a/nms-patches/MinecraftServer.patch b/nms-patches/MinecraftServer.patch index eb7ee52289..a3277241df 100644 --- a/nms-patches/MinecraftServer.patch +++ b/nms-patches/MinecraftServer.patch @@ -9,11 +9,12 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufOutputStream; import io.netty.buffer.Unpooled; -@@ -54,6 +56,14 @@ +@@ -54,6 +56,15 @@ import org.apache.commons.lang3.Validate; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +// CraftBukkit start ++import com.google.common.collect.ImmutableSet; +import jline.console.ConsoleReader; +import joptsimple.OptionSet; +import org.bukkit.Bukkit; @@ -24,7 +25,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant implements IMojangStatistics, ICommandListener, AutoCloseable { -@@ -73,7 +83,7 @@ +@@ -73,7 +84,7 @@ public final DataFixer dataConverterManager; private String serverIp; private int serverPort; @@ -33,7 +34,7 @@ public final Map, WorldServer> worldServer; private PlayerList playerList; private volatile boolean isRunning; -@@ -124,6 +134,21 @@ +@@ -124,6 +135,21 @@ private final DefinedStructureManager ak; protected SaveData saveData; @@ -55,7 +56,7 @@ public static S a(Function function) { AtomicReference atomicreference = new AtomicReference(); Thread thread = new Thread(() -> { -@@ -133,21 +158,21 @@ +@@ -133,21 +159,21 @@ thread.setUncaughtExceptionHandler((thread1, throwable) -> { MinecraftServer.LOGGER.error(throwable); }); @@ -80,7 +81,7 @@ this.isRunning = true; this.h = new long[100]; this.K = ""; -@@ -173,7 +198,34 @@ +@@ -173,7 +199,34 @@ this.ak = new DefinedStructureManager(datapackresources.h(), convertable_conversionsession, datafixer); this.serverThread = thread; this.executorService = SystemUtils.f(); @@ -115,7 +116,7 @@ private void initializeScoreboards(WorldPersistentData worldpersistentdata) { PersistentScoreboard persistentscoreboard = (PersistentScoreboard) worldpersistentdata.a(PersistentScoreboard::new, "scoreboard"); -@@ -186,7 +238,7 @@ +@@ -186,7 +239,7 @@ public static void convertWorld(Convertable.ConversionSession convertable_conversionsession) { if (convertable_conversionsession.isConvertable()) { @@ -124,7 +125,7 @@ convertable_conversionsession.convert(new IProgressUpdate() { private long a = SystemUtils.getMonotonicMillis(); -@@ -209,48 +261,185 @@ +@@ -209,48 +262,187 @@ } @@ -199,7 +200,9 @@ + if (options.has("forceUpgrade")) { + net.minecraft.server.Main.convertWorld(worldSession, DataConverterRegistry.a(), options.has("eraseCache"), () -> { + return true; -+ }, worlddata.getGeneratorSettings().g()); ++ }, worlddata.getGeneratorSettings().e().c().stream().map((entry) -> { ++ return ResourceKey.a(IRegistry.ad, ((ResourceKey) entry.getKey()).a()); ++ }).collect(ImmutableSet.toImmutableSet())); + } + + IWorldDataServer iworlddataserver = worlddata; @@ -344,7 +347,7 @@ WorldBorder worldborder = worldserver.getWorldBorder(); worldborder.a(iworlddataserver.q()); -@@ -275,34 +464,8 @@ +@@ -275,34 +467,8 @@ iworlddataserver.c(true); } @@ -380,7 +383,7 @@ private static void a(WorldServer worldserver, IWorldDataServer iworlddataserver, boolean flag, boolean flag1, boolean flag2) { ChunkGenerator chunkgenerator = worldserver.getChunkProvider().getChunkGenerator(); -@@ -317,6 +480,21 @@ +@@ -317,6 +483,21 @@ Random random = new Random(worldserver.getSeed()); BlockPosition blockposition = worldchunkmanager.a(0, worldserver.getSeaLevel(), 0, 256, list, random); ChunkCoordIntPair chunkcoordintpair = blockposition == null ? new ChunkCoordIntPair(0, 0) : new ChunkCoordIntPair(blockposition); @@ -402,7 +405,7 @@ if (blockposition == null) { MinecraftServer.LOGGER.warn("Unable to find spawn biome"); -@@ -363,7 +541,7 @@ +@@ -363,7 +544,7 @@ } if (flag) { @@ -411,7 +414,7 @@ worldgenfeatureconfigured.a(worldserver, worldserver.getStructureManager(), chunkgenerator, worldserver.random, new BlockPosition(iworlddataserver.a(), iworlddataserver.b(), iworlddataserver.c())); } -@@ -383,8 +561,15 @@ +@@ -383,8 +564,15 @@ iworlddataserver.setGameType(EnumGamemode.SPECTATOR); } @@ -429,7 +432,7 @@ MinecraftServer.LOGGER.info("Preparing start region for dimension {}", worldserver.getDimensionKey().a()); BlockPosition blockposition = worldserver.getSpawn(); -@@ -397,17 +582,21 @@ +@@ -397,17 +585,21 @@ chunkproviderserver.addTicket(TicketType.START, new ChunkCoordIntPair(blockposition), 11, Unit.INSTANCE); while (chunkproviderserver.b() != 441) { @@ -460,7 +463,7 @@ if (forcedchunk != null) { LongIterator longiterator = forcedchunk.a().iterator(); -@@ -421,11 +610,17 @@ +@@ -421,11 +613,17 @@ } } @@ -480,7 +483,7 @@ } protected void loadResourcesZip() { -@@ -470,12 +665,16 @@ +@@ -470,12 +668,16 @@ worldserver.save((IProgressUpdate) null, flag1, worldserver.savingDisabled && !flag2); } @@ -497,7 +500,7 @@ return flag3; } -@@ -484,8 +683,29 @@ +@@ -484,8 +686,29 @@ this.stop(); } @@ -527,7 +530,7 @@ if (this.getServerConnection() != null) { this.getServerConnection().b(); } -@@ -494,6 +714,7 @@ +@@ -494,6 +717,7 @@ MinecraftServer.LOGGER.info("Saving players"); this.playerList.savePlayers(); this.playerList.shutdown(); @@ -535,7 +538,7 @@ } MinecraftServer.LOGGER.info("Saving worlds"); -@@ -571,14 +792,16 @@ +@@ -571,14 +795,16 @@ while (this.isRunning) { long i = SystemUtils.getMonotonicMillis() - this.nextTick; @@ -553,7 +556,7 @@ this.nextTick += 50L; GameProfilerTick gameprofilertick = GameProfilerTick.a("Server"); -@@ -624,6 +847,12 @@ +@@ -624,6 +850,12 @@ } catch (Throwable throwable1) { MinecraftServer.LOGGER.error("Exception stopping the server", throwable1); } finally { @@ -566,7 +569,7 @@ this.exit(); } -@@ -632,8 +861,15 @@ +@@ -632,8 +864,15 @@ } private boolean canSleepForTick() { @@ -583,7 +586,7 @@ protected void sleepForTick() { this.executeAll(); -@@ -739,7 +975,7 @@ +@@ -739,7 +978,7 @@ this.serverPing.b().a(agameprofile); } @@ -592,7 +595,7 @@ MinecraftServer.LOGGER.debug("Autosave started"); this.methodProfiler.enter("save"); this.playerList.savePlayers(); -@@ -769,22 +1005,39 @@ +@@ -769,22 +1008,39 @@ } protected void b(BooleanSupplier booleansupplier) { @@ -632,7 +635,7 @@ this.methodProfiler.enter("tick"); -@@ -868,7 +1121,7 @@ +@@ -868,7 +1124,7 @@ } public String getServerModName() { @@ -641,7 +644,7 @@ } public CrashReport b(CrashReport crashreport) { -@@ -1217,11 +1470,11 @@ +@@ -1217,11 +1473,11 @@ public CompletableFuture a(Collection collection) { CompletableFuture completablefuture = CompletableFuture.supplyAsync(() -> { @@ -655,7 +658,7 @@ }, this).thenCompose((immutablelist) -> { return DataPackResources.a(immutablelist, this.j() ? CommandDispatcher.ServerType.DEDICATED : CommandDispatcher.ServerType.INTEGRATED, this.h(), this.executorService, this); }).thenAcceptAsync((datapackresources) -> { -@@ -1592,6 +1845,22 @@ +@@ -1592,6 +1848,22 @@ } diff --git a/nms-patches/PersistentStructureLegacy.patch b/nms-patches/PersistentStructureLegacy.patch new file mode 100644 index 0000000000..2e5b6fc975 --- /dev/null +++ b/nms-patches/PersistentStructureLegacy.patch @@ -0,0 +1,41 @@ +--- a/net/minecraft/server/PersistentStructureLegacy.java ++++ b/net/minecraft/server/PersistentStructureLegacy.java +@@ -14,7 +14,7 @@ + + public class PersistentStructureLegacy { + +- private static final Map a = (Map) SystemUtils.a((Object) Maps.newHashMap(), (hashmap) -> { ++ private static final Map a = (Map) SystemUtils.a(Maps.newHashMap(), (hashmap) -> { // CraftBukkit - decompile error + hashmap.put("Village", "Village"); + hashmap.put("Mineshaft", "Mineshaft"); + hashmap.put("Mansion", "Mansion"); +@@ -27,7 +27,7 @@ + hashmap.put("Fortress", "Fortress"); + hashmap.put("EndCity", "EndCity"); + }); +- private static final Map b = (Map) SystemUtils.a((Object) Maps.newHashMap(), (hashmap) -> { ++ private static final Map b = (Map) SystemUtils.a(Maps.newHashMap(), (hashmap) -> { // CraftBukkit - decompile error + hashmap.put("Iglu", "Igloo"); + hashmap.put("TeDP", "Desert_Pyramid"); + hashmap.put("TeJP", "Jungle_Pyramid"); +@@ -228,16 +228,16 @@ + } + } + +- public static PersistentStructureLegacy a(ResourceKey resourcekey, @Nullable WorldPersistentData worldpersistentdata) { +- if (resourcekey == World.OVERWORLD) { ++ public static PersistentStructureLegacy a(ResourceKey resourcekey, @Nullable WorldPersistentData worldpersistentdata) { // CraftBukkit ++ if (resourcekey == DimensionManager.OVERWORLD) { // CraftBukkit + return new PersistentStructureLegacy(worldpersistentdata, ImmutableList.of("Monument", "Stronghold", "Village", "Mineshaft", "Temple", "Mansion"), ImmutableList.of("Village", "Mineshaft", "Mansion", "Igloo", "Desert_Pyramid", "Jungle_Pyramid", "Swamp_Hut", "Stronghold", "Monument")); + } else { + ImmutableList immutablelist; + +- if (resourcekey == World.THE_NETHER) { ++ if (resourcekey == DimensionManager.THE_NETHER) { // CraftBukkit + immutablelist = ImmutableList.of("Fortress"); + return new PersistentStructureLegacy(worldpersistentdata, immutablelist, immutablelist); +- } else if (resourcekey == World.THE_END) { ++ } else if (resourcekey == DimensionManager.THE_END) { // CraftBukkit + immutablelist = ImmutableList.of("EndCity"); + return new PersistentStructureLegacy(worldpersistentdata, immutablelist, immutablelist); + } else { diff --git a/nms-patches/PlayerChunkMap.patch b/nms-patches/PlayerChunkMap.patch index fa4d1733a3..232a6de1b7 100644 --- a/nms-patches/PlayerChunkMap.patch +++ b/nms-patches/PlayerChunkMap.patch @@ -122,7 +122,7 @@ NBTTagCompound nbttagcompound = this.read(chunkcoordintpair); - return nbttagcompound == null ? null : this.getChunkData(this.world.getDimensionKey(), this.l, nbttagcompound); -+ return nbttagcompound == null ? null : this.getChunkData(this.world.getDimensionKey(), this.l, nbttagcompound, chunkcoordintpair, world); // CraftBukkit ++ return nbttagcompound == null ? null : this.getChunkData(this.world.getTypeKey(), this.l, nbttagcompound, chunkcoordintpair, world); // CraftBukkit } boolean isOutsideOfRange(ChunkCoordIntPair chunkcoordintpair) { diff --git a/nms-patches/WorldUpgrader.patch b/nms-patches/WorldUpgrader.patch index 400ed1e8fc..6094c24872 100644 --- a/nms-patches/WorldUpgrader.patch +++ b/nms-patches/WorldUpgrader.patch @@ -1,5 +1,77 @@ --- a/net/minecraft/server/WorldUpgrader.java +++ b/net/minecraft/server/WorldUpgrader.java +@@ -25,7 +25,7 @@ + + private static final Logger LOGGER = LogManager.getLogger(); + private static final ThreadFactory b = (new ThreadFactoryBuilder()).setDaemon(true).build(); +- private final ImmutableSet> c; ++ private final ImmutableSet> c; // CraftBukkit + private final boolean d; + private final Convertable.ConversionSession e; + private final Thread f; +@@ -36,12 +36,12 @@ + private volatile int k; + private volatile int l; + private volatile int m; +- private final Object2FloatMap> n = Object2FloatMaps.synchronize(new Object2FloatOpenCustomHashMap(SystemUtils.k())); ++ private final Object2FloatMap> n = Object2FloatMaps.synchronize(new Object2FloatOpenCustomHashMap(SystemUtils.k())); // CraftBukkit + private volatile IChatBaseComponent o = new ChatMessage("optimizeWorld.stage.counting"); + private static final Pattern p = Pattern.compile("^r\\.(-?[0-9]+)\\.(-?[0-9]+)\\.mca$"); + private final WorldPersistentData q; + +- public WorldUpgrader(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, ImmutableSet> immutableset, boolean flag) { ++ public WorldUpgrader(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, ImmutableSet> immutableset, boolean flag) { // CraftBukkit + this.c = immutableset; + this.d = flag; + this.g = datafixer; +@@ -69,12 +69,12 @@ + + private void i() { + this.k = 0; +- Builder, ListIterator> builder = ImmutableMap.builder(); ++ Builder, ListIterator> builder = ImmutableMap.builder(); // CraftBukkit + + List list; + + for (UnmodifiableIterator unmodifiableiterator = this.c.iterator(); unmodifiableiterator.hasNext(); this.k += list.size()) { +- ResourceKey resourcekey = (ResourceKey) unmodifiableiterator.next(); ++ ResourceKey resourcekey = (ResourceKey) unmodifiableiterator.next(); // CraftBukkit + + list = this.b(resourcekey); + builder.put(resourcekey, list.listIterator()); +@@ -84,18 +84,18 @@ + this.i = true; + } else { + float f = (float) this.k; +- ImmutableMap, ListIterator> immutablemap = builder.build(); +- Builder, IChunkLoader> builder1 = ImmutableMap.builder(); ++ ImmutableMap, ListIterator> immutablemap = builder.build(); // CraftBukkit ++ Builder, IChunkLoader> builder1 = ImmutableMap.builder(); // CraftBukkit + UnmodifiableIterator unmodifiableiterator1 = this.c.iterator(); + + while (unmodifiableiterator1.hasNext()) { +- ResourceKey resourcekey1 = (ResourceKey) unmodifiableiterator1.next(); +- File file = this.e.a(resourcekey1); ++ ResourceKey resourcekey1 = (ResourceKey) unmodifiableiterator1.next(); // CraftBukkit ++ File file = this.e.a(null); // CraftBukkit + + builder1.put(resourcekey1, new IChunkLoader(new File(file, "region"), this.g, true)); + } + +- ImmutableMap, IChunkLoader> immutablemap1 = builder1.build(); ++ ImmutableMap, IChunkLoader> immutablemap1 = builder1.build(); // CraftBukkit + long i = SystemUtils.getMonotonicMillis(); + + this.o = new ChatMessage("optimizeWorld.stage.upgrading"); +@@ -107,7 +107,7 @@ + float f2; + + for (UnmodifiableIterator unmodifiableiterator2 = this.c.iterator(); unmodifiableiterator2.hasNext(); f1 += f2) { +- ResourceKey resourcekey2 = (ResourceKey) unmodifiableiterator2.next(); ++ ResourceKey resourcekey2 = (ResourceKey) unmodifiableiterator2.next(); // CraftBukkit + ListIterator listiterator = (ListIterator) immutablemap.get(resourcekey2); + IChunkLoader ichunkloader = (IChunkLoader) immutablemap1.get(resourcekey2); + @@ -122,7 +122,7 @@ int j = IChunkLoader.a(nbttagcompound); NBTTagCompound nbttagcompound1 = ichunkloader.getChunkData(resourcekey2, () -> { @@ -9,3 +81,14 @@ NBTTagCompound nbttagcompound2 = nbttagcompound1.getCompound("Level"); ChunkCoordIntPair chunkcoordintpair1 = new ChunkCoordIntPair(nbttagcompound2.getInt("xPos"), nbttagcompound2.getInt("zPos")); +@@ -195,8 +195,8 @@ + } + } + +- private List b(ResourceKey resourcekey) { +- File file = this.e.a(resourcekey); ++ private List b(ResourceKey resourcekey) { // CraftBukkit ++ File file = this.e.a(null); // CraftBukkit + File file1 = new File(file, "region"); + File[] afile = file1.listFiles((file2, s) -> { + return s.endsWith(".mca"); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 677f7e648d..38685302b9 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -4,6 +4,7 @@ import com.google.common.base.Charsets; import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterators; import com.google.common.collect.Lists; import com.google.common.collect.MapMaker; @@ -985,12 +986,15 @@ public final class CraftServer implements Server { worldSettings = new WorldSettings(name, EnumGamemode.getById(getDefaultGameMode().getValue()), hardcore, EnumDifficulty.EASY, false, new GameRules(), console.datapackconfiguration); worlddata = new WorldDataServer(worldSettings, generatorsettings, Lifecycle.stable()); } + worlddata.checkName(name); worlddata.a(console.getServerModName(), console.getModded().isPresent()); if (console.options.has("forceUpgrade")) { net.minecraft.server.Main.convertWorld(worldSession, DataConverterRegistry.a(), console.options.has("eraseCache"), () -> { return true; - }, worlddata.getGeneratorSettings().g()); + }, worlddata.getGeneratorSettings().e().c().stream().map((entry) -> { + return ResourceKey.a(IRegistry.ad, ((ResourceKey) entry.getKey()).a()); + }).collect(ImmutableSet.toImmutableSet())); } long j = BiomeManager.a(creator.seed());