diff --git a/bundle/src/main/java/net/okocraft/box/platform/PatcherFactories.java b/bundle/src/main/java/net/okocraft/box/platform/PatcherFactories.java index f21d5ac4de..d230096523 100644 --- a/bundle/src/main/java/net/okocraft/box/platform/PatcherFactories.java +++ b/bundle/src/main/java/net/okocraft/box/platform/PatcherFactories.java @@ -6,27 +6,20 @@ import net.okocraft.box.version.common.item.LegacyVersionPatches; import org.jetbrains.annotations.NotNull; -import static net.okocraft.box.api.util.MCDataVersion.MC_1_19; -import static net.okocraft.box.api.util.MCDataVersion.MC_1_19_4; -import static net.okocraft.box.api.util.MCDataVersion.MC_1_20_3; -import static net.okocraft.box.api.util.MCDataVersion.MC_1_20_4; - final class PatcherFactories { static @NotNull ItemNamePatcher createItemNamePatcher(@NotNull ItemVersion startingVersion, @NotNull ItemVersion currentVersion) { var builder = new ItemNamePatcherBuilder(); - var dataVer = startingVersion.dataVersion(); - var itemVer = startingVersion.defaultItemVersion(); - if (dataVer.isBetween(MC_1_19, MC_1_19_4) && itemVer == 0) { + if (LegacyVersionPatches.shouldPatchGoatHorn(startingVersion)) { builder.append(LegacyVersionPatches::goatHornName); } - if (dataVer.isBefore(MC_1_20_3) && currentVersion.dataVersion().isAfterOrSame(MC_1_20_3)) { + if (LegacyVersionPatches.shouldPatchShortGrassName(startingVersion, currentVersion)) { builder.append(LegacyVersionPatches::shortGrassName); } - if (dataVer.isBefore(MC_1_20_4) && currentVersion.dataVersion().isAfterOrSame(MC_1_20_4)) { // TODO: back to MC_1_21 after Minecraft 1.21 released + if (true || LegacyVersionPatches.shouldPatchPotionName(startingVersion, currentVersion)) { // TODO: fix this after Minecraft 1.20.5 released builder.append(LegacyVersionPatches::potionName); } @@ -35,10 +28,8 @@ final class PatcherFactories { static @NotNull ItemDataPatcher createItemDataPatcher(@NotNull ItemVersion startingVersion, @NotNull ItemVersion ignoredCurrentVersion) { var builder = new ItemDataPatcherBuilder(); - var dataVer = startingVersion.dataVersion(); - var itemVer = startingVersion.defaultItemVersion(); - if (dataVer.isBetween(MC_1_19, MC_1_19_4) && itemVer == 0) { + if (LegacyVersionPatches.shouldPatchGoatHorn(startingVersion)) { builder.append(LegacyVersionPatches::goatHorn); } diff --git a/bundle/src/main/java/net/okocraft/box/platform/PlatformDependent.java b/bundle/src/main/java/net/okocraft/box/platform/PlatformDependent.java index 4789fad651..aadb8b7164 100644 --- a/bundle/src/main/java/net/okocraft/box/platform/PlatformDependent.java +++ b/bundle/src/main/java/net/okocraft/box/platform/PlatformDependent.java @@ -1,18 +1,18 @@ package net.okocraft.box.platform; +import net.okocraft.box.api.model.item.ItemVersion; import net.okocraft.box.api.scheduler.BoxScheduler; import net.okocraft.box.api.util.Folia; import net.okocraft.box.api.util.MCDataVersion; import net.okocraft.box.core.command.CommandRegisterer; import net.okocraft.box.storage.api.util.item.DefaultItem; import net.okocraft.box.storage.api.util.item.DefaultItemProvider; -import net.okocraft.box.api.model.item.ItemVersion; import net.okocraft.box.storage.api.util.item.patcher.ItemDataPatcher; import net.okocraft.box.storage.api.util.item.patcher.ItemNamePatcher; import net.okocraft.box.storage.api.util.item.patcher.PatcherFactory; import net.okocraft.box.version.common.command.BukkitCommandRegisterer; import net.okocraft.box.version.common.scheduler.FoliaSchedulerWrapper; -import net.okocraft.box.version.paper_1_21.Paper_1_21; +import net.okocraft.box.version.paper_1_20_5.Paper_1_20_5; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; @@ -22,6 +22,8 @@ public final class PlatformDependent { + private static final ItemVersion TESTING_VERSION = new ItemVersion(MCDataVersion.MC_1_20_4, 1); // TODO: remove this after Minecraft 1.20.5 released + public static @NotNull BoxScheduler createScheduler(@NotNull Plugin plugin) throws NotSupportedException { if (Folia.check() || MCDataVersion.current().isAfterOrSame(MCDataVersion.MC_1_20)) { return new FoliaSchedulerWrapper(plugin); @@ -31,9 +33,14 @@ public final class PlatformDependent { } public static @NotNull DefaultItemProvider createItemProvider() throws NotSupportedException { - if (MCDataVersion.current().isAfterOrSame(MCDataVersion.MC_1_20_4)) { // TODO: back to MC_1_21 after Minecraft 1.21 released - return new DefaultItemProviderImpl(new ItemVersion(MCDataVersion.MC_1_20_4, 0), Paper_1_21::defaultItems); + if (MCDataVersion.current().isSame(TESTING_VERSION.dataVersion())) { + return new DefaultItemProviderImpl(TESTING_VERSION, Paper_1_20_5::defaultItems); } + + if (MCDataVersion.current().isSame(MCDataVersion.MC_1_20_5)) { + return new DefaultItemProviderImpl(Paper_1_20_5.VERSION, Paper_1_20_5::defaultItems); + } + throw new NotSupportedException("Unsupported version: " + Bukkit.getVersion()); } diff --git a/settings.gradle.kts b/settings.gradle.kts index a288bdcf6f..65a20b1ef3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -53,7 +53,7 @@ val versionSuffix = "version" // versions sequenceOf( "common", - "paper-1_21" + "paper-1_20_5" ).forEach { include("$boxPrefix-$versionSuffix-$it") project(":$boxPrefix-$versionSuffix-$it").projectDir = file("./versions/$it") diff --git a/versions/common/src/main/java/net/okocraft/box/version/common/item/LegacyVersionPatches.java b/versions/common/src/main/java/net/okocraft/box/version/common/item/LegacyVersionPatches.java index 0c0f1c7280..7505d90251 100644 --- a/versions/common/src/main/java/net/okocraft/box/version/common/item/LegacyVersionPatches.java +++ b/versions/common/src/main/java/net/okocraft/box/version/common/item/LegacyVersionPatches.java @@ -1,5 +1,6 @@ package net.okocraft.box.version.common.item; +import net.okocraft.box.api.model.item.ItemVersion; import net.okocraft.box.storage.api.model.item.ItemData; import org.bukkit.Material; import org.bukkit.MusicInstrument; @@ -7,16 +8,33 @@ import org.bukkit.inventory.meta.MusicInstrumentMeta; import org.jetbrains.annotations.NotNull; +import static net.okocraft.box.api.util.MCDataVersion.MC_1_19; +import static net.okocraft.box.api.util.MCDataVersion.MC_1_19_4; +import static net.okocraft.box.api.util.MCDataVersion.MC_1_20_3; +import static net.okocraft.box.api.util.MCDataVersion.MC_1_20_5; + public final class LegacyVersionPatches { + public static boolean shouldPatchGoatHorn(@NotNull ItemVersion version) { + return version.dataVersion().isBetween(MC_1_19, MC_1_19_4) && version.defaultItemVersion() == 0; + } + public static @NotNull String goatHornName(@NotNull String original) { return original.equals("GOAT_HORN") ? "PONDER_GOAT_HORN" : original; } + public static boolean shouldPatchShortGrassName(@NotNull ItemVersion starting, @NotNull ItemVersion current) { + return starting.dataVersion().isBefore(MC_1_20_3) && current.dataVersion().isAfterOrSame(MC_1_20_3); + } + public static @NotNull String shortGrassName(@NotNull String original) { return original.equals("GRASS") ? "SHORT_GRASS" : original; } + public static boolean shouldPatchPotionName(@NotNull ItemVersion starting, @NotNull ItemVersion current) { + return starting.dataVersion().isBefore(MC_1_20_5) && current.dataVersion().isAfterOrSame(MC_1_20_5); + } + public static @NotNull String potionName(@NotNull String original) { String material; String potionType; diff --git a/versions/paper-1_21/build.gradle.kts b/versions/paper-1_20_5/build.gradle.kts similarity index 100% rename from versions/paper-1_21/build.gradle.kts rename to versions/paper-1_20_5/build.gradle.kts diff --git a/versions/paper-1_21/src/main/java/net/okocraft/box/version/paper_1_21/Paper_1_21.java b/versions/paper-1_20_5/src/main/java/net/okocraft/box/version/paper_1_20_5/Paper_1_20_5.java similarity index 75% rename from versions/paper-1_21/src/main/java/net/okocraft/box/version/paper_1_21/Paper_1_21.java rename to versions/paper-1_20_5/src/main/java/net/okocraft/box/version/paper_1_20_5/Paper_1_20_5.java index 6f1f434ef0..ea7af82875 100644 --- a/versions/paper-1_21/src/main/java/net/okocraft/box/version/paper_1_21/Paper_1_21.java +++ b/versions/paper-1_20_5/src/main/java/net/okocraft/box/version/paper_1_20_5/Paper_1_20_5.java @@ -1,5 +1,7 @@ -package net.okocraft.box.version.paper_1_21; +package net.okocraft.box.version.paper_1_20_5; +import net.okocraft.box.api.model.item.ItemVersion; +import net.okocraft.box.api.util.MCDataVersion; import net.okocraft.box.storage.api.util.item.DefaultItem; import net.okocraft.box.version.common.item.ItemSources; import org.bukkit.Bukkit; @@ -7,7 +9,9 @@ import java.util.stream.Stream; -public final class Paper_1_21 { +public final class Paper_1_20_5 { + + public static final ItemVersion VERSION = new ItemVersion(MCDataVersion.MC_1_20_5, 0); public static @NotNull Stream defaultItems() { return new ItemSources.Merger() @@ -24,7 +28,7 @@ public final class Paper_1_21 { .result(); } - private Paper_1_21() { + private Paper_1_20_5() { throw new UnsupportedOperationException(); } }