diff --git a/build.gradle b/build.gradle index 826c1288d..bb56e4a1c 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ repositories { configure(apiDependencies) { serverApiVersion = '1.21.11-R0.1-SNAPSHOT' mockBukkitServerApiVersion = '1.21' - mockBukkitVersion = '4.109.0' + mockBukkitVersion = '4.110.0' } dependencies { diff --git a/src/main/java/org/mvplugins/multiverse/core/utils/compatibility/WorldCompatibility.java b/src/main/java/org/mvplugins/multiverse/core/utils/compatibility/WorldCompatibility.java index badfef902..5ec4cf496 100644 --- a/src/main/java/org/mvplugins/multiverse/core/utils/compatibility/WorldCompatibility.java +++ b/src/main/java/org/mvplugins/multiverse/core/utils/compatibility/WorldCompatibility.java @@ -18,10 +18,12 @@ public final class WorldCompatibility { private static final Try SAVE_WITH_FLUSH_METHOD; private static final boolean HAS_GET_COORDINATE_SCALE_METHOD; + private static final boolean HAS_HAS_BONUS_CHEST_METHOD; static { SAVE_WITH_FLUSH_METHOD = ReflectHelper.tryGetMethod(World.class, "save", boolean.class); HAS_GET_COORDINATE_SCALE_METHOD = ReflectHelper.hasMethod(World.class, "getCoordinateScale"); + HAS_HAS_BONUS_CHEST_METHOD = ReflectHelper.hasMethod(World.class, "hasBonusChest"); } /** @@ -65,6 +67,25 @@ public static double getCoordinateScale(World world) { }; } + /** + * Checks if the world has a bonus chest. + *
+ * On PaperMC 1.21.5+, this can be obtained directly from the API. On older versions, it always returns false as + * bonus chest is not supported. + * + * @param world The world to check + * @return True if the world has a bonus chest, false otherwise + * + * @since 5.7 + */ + @ApiStatus.AvailableSince("5.7") + public static boolean hasBonusChest(World world) { + if (HAS_HAS_BONUS_CHEST_METHOD) { + return world.hasBonusChest(); + } + return false; + } + private WorldCompatibility() { throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); } diff --git a/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java b/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java index 90ca017b9..de71677f8 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java @@ -880,6 +880,7 @@ public Attempt regenWorld(@NotNull Re CreateWorldOptions createWorldOptions = CreateWorldOptions.worldName(world.getName()) .biome(world.getBiome()) + .bonusChest(world.getBukkitWorld().map(WorldCompatibility::hasBonusChest).getOrElse(false)) .environment(world.getEnvironment()) .generateStructures(world.canGenerateStructures().getOrElse(true)) .generator(world.getGenerator())