From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Fri, 25 Feb 2022 07:14:48 -0800 Subject: [PATCH] CB fixes * Missing Level -> LevelStem generic in StructureCheck Need to use the right for injectDatafixingContext (Spottedleaf) * Removed incorrect parent perm for `minecraft.debugstick.always` (Machine_Maker) * Fixed method signature of Marker#addPassenger (Machine_Maker) * Removed unneeded UOE in CustomWorldChunkManager (extends BiomeSource) (Machine_Maker) * Honor Server#getLootTable method contract (Machine_Maker) Co-authored-by: Spottedleaf diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java index b84078f8105bccc40da0c14932ad3160c96d371c..c4bd9be9d1884be1f5040ff1417f44f8ac4b655f 100644 --- a/src/main/java/net/minecraft/server/level/ServerLevel.java +++ b/src/main/java/net/minecraft/server/level/ServerLevel.java @@ -302,7 +302,7 @@ public class ServerLevel extends Level implements WorldGenLevel { long l = minecraftserver.getWorldData().worldGenOptions().seed(); - this.structureCheck = new StructureCheck(this.chunkSource.chunkScanner(), this.registryAccess(), minecraftserver.getStructureManager(), resourcekey, chunkgenerator, this.chunkSource.randomState(), this, chunkgenerator.getBiomeSource(), l, datafixer); + this.structureCheck = new StructureCheck(this.chunkSource.chunkScanner(), this.registryAccess(), minecraftserver.getStructureManager(), this.getTypeKey(), chunkgenerator, this.chunkSource.randomState(), this, chunkgenerator.getBiomeSource(), l, datafixer); // Paper - Fix missing CB diff this.structureManager = new StructureManager(this, this.serverLevelData.worldGenOptions(), this.structureCheck); // CraftBukkit if ((this.dimension() == Level.END && this.dimensionTypeRegistration().is(BuiltinDimensionTypes.END)) || env == org.bukkit.World.Environment.THE_END) { // CraftBukkit - Allow to create EnderDragonBattle in default and custom END this.dragonFight = new EndDragonFight(this, this.serverLevelData.worldGenOptions().seed(), this.serverLevelData.endDragonFightData()); // CraftBukkit diff --git a/src/main/java/net/minecraft/world/level/levelgen/structure/StructureCheck.java b/src/main/java/net/minecraft/world/level/levelgen/structure/StructureCheck.java index 0dc7f88877020bddd5a84db51d349f52b673048e..aae73586265593ee7830fb8dd5c2e3d7560057f0 100644 --- a/src/main/java/net/minecraft/world/level/levelgen/structure/StructureCheck.java +++ b/src/main/java/net/minecraft/world/level/levelgen/structure/StructureCheck.java @@ -40,7 +40,7 @@ public class StructureCheck { private final ChunkScanAccess storageAccess; private final RegistryAccess registryAccess; private final StructureTemplateManager structureTemplateManager; - private final ResourceKey dimension; + private final ResourceKey dimension; // Paper - fix missing CB diff private final ChunkGenerator chunkGenerator; private final RandomState randomState; private final LevelHeightAccessor heightAccessor; @@ -54,7 +54,7 @@ public class StructureCheck { ChunkScanAccess chunkIoWorker, RegistryAccess registryManager, StructureTemplateManager structureTemplateManager, - ResourceKey worldKey, + ResourceKey worldKey, // Paper - fix missing CB diff ChunkGenerator chunkGenerator, RandomState noiseConfig, LevelHeightAccessor world, diff --git a/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java b/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java index 9b90649f71849b3830ca9b6a3c5a722c66b02f1f..209c6b64e79c29ea3bb84ddbe89a8bff66f81d0f 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java @@ -197,4 +197,11 @@ public class CraftLootTable implements org.bukkit.loot.LootTable { org.bukkit.loot.LootTable table = (org.bukkit.loot.LootTable) obj; return table.getKey().equals(this.getKey()); } + + // Paper start - satisfy equals/hashCode contract + @Override + public int hashCode() { + return java.util.Objects.hash(key); + } + // Paper end } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 4a4f7af9c7377e79a20398310ef7cf719d3cc0b5..10549f2f4d6ae01c080cdba16c71656b764314c3 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -2506,7 +2506,13 @@ public final class CraftServer implements Server { Preconditions.checkArgument(key != null, "NamespacedKey key cannot be null"); ReloadableServerRegistries.Holder registry = this.getServer().reloadableRegistries(); - return new CraftLootTable(key, registry.getLootTable(CraftLootTable.bukkitKeyToMinecraft(key))); + // Paper start - honor method contract + final ResourceKey lootTableKey = CraftLootTable.bukkitKeyToMinecraft(key); + final Optional table = registry.get().lookup(Registries.LOOT_TABLE) + .flatMap(registryEntryLookup -> registryEntryLookup.get(lootTableKey)) + .map(net.minecraft.core.Holder::value); + return table.map(lootTable -> new CraftLootTable(key, lootTable)).orElse(null); + // Paper end } @Override diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java index bbc880e136c8fba9634fd4fee9e3e6838ef3f377..e5f070de12b63487b71c54d8020a895e5eda862c 100644 --- a/src/main/java/org/bukkit/craftbukkit/Main.java +++ b/src/main/java/org/bukkit/craftbukkit/Main.java @@ -123,6 +123,7 @@ public class Main { this.acceptsAll(Main.asList("forceUpgrade"), "Whether to force a world upgrade"); this.acceptsAll(Main.asList("eraseCache"), "Whether to force cache erase during world upgrade"); this.acceptsAll(Main.asList("recreateRegionFiles"), "Whether to recreate region files during world upgrade"); + this.accepts("safeMode", "Loads level with vanilla datapack only"); // Paper this.acceptsAll(Main.asList("nogui"), "Disables the graphical console"); this.acceptsAll(Main.asList("nojline"), "Disables jline and emulates the vanilla console"); diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java index 905adf97c0d1f0d1c774a6835a5dffcfea884e58..c017ce2ca1bc535795c958a2e509af2adf88efa9 100644 --- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java +++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java @@ -26,6 +26,7 @@ import org.bukkit.scheduler.BukkitWorker; /** * The fundamental concepts for this implementation: + *
    *
  • Main thread owns {@link #head} and {@link #currentTick}, but it may be read from any thread
  • *
  • Main thread exclusively controls {@link #temp} and {@link #pending}. * They are never to be accessed outside of the main thread; alternatives exist to prevent locking.
  • @@ -41,6 +42,7 @@ import org.bukkit.scheduler.BukkitWorker; *
  • Sync tasks are only to be removed from runners on the main thread when coupled with a removal from pending and temp.
  • *
  • Most of the design in this scheduler relies on queuing special tasks to perform any data changes on the main thread. * When executed from inside a synchronous method, the scheduler will be updated before next execution by virtue of the frequent {@link #parsePending()} calls.
  • + *
*/ public class CraftScheduler implements BukkitScheduler { diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java index 8021fa01542a5dd203a834e88e286903093690cd..3879f1f69e13f4e90bd66c533bf76b257f041394 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -244,7 +244,7 @@ public final class CraftMagicNumbers implements UnsafeValues { try { nmsStack.applyComponents(new ItemParser(Commands.createValidationContext(MinecraftServer.getDefaultRegistryAccess())).parse(new StringReader(arguments)).components()); } catch (CommandSyntaxException ex) { - Logger.getLogger(CraftMagicNumbers.class.getName()).log(Level.SEVERE, null, ex); + com.mojang.logging.LogUtils.getClassLogger().error("Exception modifying ItemStack", new Throwable(ex)); // Paper - show stack trace } stack.setItemMeta(CraftItemStack.getItemMeta(nmsStack)); diff --git a/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java b/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java index 5ac25dab93fd4c9e9533c80d1ca3d93446d7a365..245ad120a36b6defca7e6889faae1ca5fc33d0c7 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java +++ b/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java @@ -15,7 +15,7 @@ public final class CraftDefaultPermissions { DefaultPermissions.registerPermission(CraftDefaultPermissions.ROOT + ".nbt.place", "Gives the user the ability to place restricted blocks with NBT in creative", org.bukkit.permissions.PermissionDefault.OP, parent); DefaultPermissions.registerPermission(CraftDefaultPermissions.ROOT + ".nbt.copy", "Gives the user the ability to copy NBT in creative", org.bukkit.permissions.PermissionDefault.TRUE, parent); DefaultPermissions.registerPermission(CraftDefaultPermissions.ROOT + ".debugstick", "Gives the user the ability to use the debug stick in creative", org.bukkit.permissions.PermissionDefault.OP, parent); - DefaultPermissions.registerPermission(CraftDefaultPermissions.ROOT + ".debugstick.always", "Gives the user the ability to use the debug stick in all game modes", org.bukkit.permissions.PermissionDefault.FALSE, parent); + DefaultPermissions.registerPermission(CraftDefaultPermissions.ROOT + ".debugstick.always", "Gives the user the ability to use the debug stick in all game modes", org.bukkit.permissions.PermissionDefault.FALSE/* , parent */); // Paper - should not have this parent, as it's not a "vanilla" utility // Spigot end parent.recalculatePermissibles(); }