diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5cd6004..4849bec 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,21 +11,21 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v7 with: fetch-depth: 0 - name: Set BUILD_VERSION run: echo "BUILD_VERSION=$(git describe --tags $(git rev-list --tags --max-count=1))-b$GITHUB_RUN_NUMBER" >> $GITHUB_ENV - name: Restore Maven cache id: cache-restore - uses: actions/cache/restore@v4 + uses: actions/cache/restore@v6 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ secrets.CACHE_VERSION }}-${{ hashFiles('./.github/workflows/buildtools.sh') }} restore-keys: | ${{ runner.os }}-maven-${{ secrets.CACHE_VERSION }}- - - name: Set up JDK 17/25 - uses: actions/setup-java@v4 + - name: Set up JDK 17/21/25 + uses: actions/setup-java@v6 with: distribution: 'temurin' java-version: | @@ -37,16 +37,16 @@ jobs: bash ./.github/workflows/buildtools.sh - name: Build run: | - mvn clean package -pl zip-plugin --batch-mode --also-make -Drevision=$BUILD_VERSION + mvn package -pl zip-plugin --batch-mode --also-make -Drevision=$BUILD_VERSION mv zip-plugin/target/zip-*.jar ./ - name: Save Maven cache if: always() && steps.cache-restore.outputs.cache-hit != 'true' - uses: actions/cache/save@v4 + uses: actions/cache/save@v6 with: path: ~/.m2/repository key: ${{ steps.cache-restore.outputs.cache-primary-key }} - name: Upload artifacts - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: name: zero-inventory-problems-plugin path: ./zip-*.jar diff --git a/.github/workflows/buildtools.sh b/.github/workflows/buildtools.sh index 41ae5eb..a6ad648 100644 --- a/.github/workflows/buildtools.sh +++ b/.github/workflows/buildtools.sh @@ -32,7 +32,7 @@ checkVersion "1.20.1" "R0.1" "17" checkVersion "1.20.2" "R0.1" "17" checkVersion "1.20.4" "R0.1" "17" checkVersion "1.20.6" "R0.1" "21" -checkVersion "1.21" "R0.1" "21" +checkVersion "1.21.1" "R0.1" "21" checkVersion "1.21.3" "R0.1" "21" checkVersion "1.21.4" "R0.1" "21" checkVersion "1.21.5" "R0.1" "21" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b08671f..35a778b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,23 +8,25 @@ on: jobs: release: runs-on: ubuntu-latest + permissions: + contents: write steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v7 with: fetch-depth: 0 - name: Set RELEASE_VERSION run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - name: Maven cache - uses: actions/cache@v4 + uses: actions/cache@v6 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ secrets.CACHE_VERSION }}-${{ hashFiles('./.github/workflows/buildtools.sh') }} restore-keys: | ${{ runner.os }}-maven-${{ secrets.CACHE_VERSION }}- - - name: Set up JDK 17/25 - uses: actions/setup-java@v4 + - name: Set up JDK 17/21/25 + uses: actions/setup-java@v6 with: distribution: 'temurin' java-version: | @@ -42,4 +44,3 @@ jobs: with: artifacts: "zip-*.jar" name: Release ${{ env.RELEASE_VERSION }} - token: ${{ secrets.GITHUB_TOKEN }} diff --git a/zip-nms/zip-nms-api/src/main/java/dev/imprex/zip/nms/api/NmsManager.java b/zip-nms/zip-nms-api/src/main/java/dev/imprex/zip/nms/api/NmsManager.java index 48ffabd..17780a6 100644 --- a/zip-nms/zip-nms-api/src/main/java/dev/imprex/zip/nms/api/NmsManager.java +++ b/zip-nms/zip-nms-api/src/main/java/dev/imprex/zip/nms/api/NmsManager.java @@ -51,11 +51,19 @@ protected static ItemStack asCraftMirror(T minecraftItem) { CRAFT_ITEM_STACK_CLASS, CRAFT_ITEM_STACK_CLASS, minecraftItem.getClass()); + + // Paper 26.3+ support + if (method == null) { + method = CRAFT_ITEM_STACK_CLASS.getMethod("asBukkitMirror", minecraftItem.getClass()); + } + method.setAccessible(true); craftItemStackAsCraftMirror = method; } return (ItemStack) craftItemStackAsCraftMirror.invoke(null, minecraftItem); + } catch (NoSuchMethodException e) { + throw new IllegalStateException("Unable to find a CraftItemStack mirror method for " + minecraftItem.getClass().getName(), e); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new IllegalStateException(e); } diff --git a/zip-plugin/src/main/java/dev/imprex/zip/config/BackpackConfig.java b/zip-plugin/src/main/java/dev/imprex/zip/config/BackpackConfig.java index c7b245f..aa56709 100644 --- a/zip-plugin/src/main/java/dev/imprex/zip/config/BackpackConfig.java +++ b/zip-plugin/src/main/java/dev/imprex/zip/config/BackpackConfig.java @@ -1,17 +1,31 @@ package dev.imprex.zip.config; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; - +import java.util.Collections; +import java.util.Map; +import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Stream; + import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; - + import dev.imprex.zip.BackpackPlugin; import dev.imprex.zip.common.MinecraftVersion; +import dev.imprex.zip.common.Version; +import dev.imprex.zip.common.ZIPLogger; public class BackpackConfig { + private static final Pattern CONFIG_FILE_PATTERN = Pattern.compile("config-(\\d+(?:\\.\\d+){0,2})\\.yml"); + private final BackpackPlugin plugin; private GeneralConfig generalConfig; @@ -28,15 +42,10 @@ public void deserialize() { Path configPath = dataFolder.resolve("config.yml"); if (Files.notExists(configPath)) { - String configVersion = MinecraftVersion.majorVersion() + "." + MinecraftVersion.minorVersion(); - - if (Files.notExists(dataFolder)) { - Files.createDirectories(dataFolder); - } - - Files.copy(BackpackPlugin.class.getResourceAsStream("/config/config-" + configVersion + ".yml"), configPath); + Files.createDirectories(dataFolder); + this.copyDefaultConfig(configPath); } - } catch (IOException e) { + } catch (IOException | URISyntaxException e) { throw new RuntimeException("unable to create config", e); } @@ -51,6 +60,39 @@ public void deserialize() { this.messageConfig = new MessageConfig(this.plugin); } + private void copyDefaultConfig(Path target) throws IOException, URISyntaxException { + URI resource = BackpackPlugin.class.getResource("").toURI(); + Version current = MinecraftVersion.current(); + + try (FileSystem fileSystem = FileSystems.newFileSystem(resource, Collections.emptyMap()); + Stream files = Files.list(fileSystem.getPath("/config"))) { + + TreeMap configs = new TreeMap<>(); + files.forEach(file -> { + Matcher matcher = CONFIG_FILE_PATTERN.matcher(file.getFileName().toString()); + if (matcher.matches()) { + configs.put(Version.parse(matcher.group(1)), file); + } + }); + + Map.Entry entry = configs.floorEntry(current); + if (entry == null) { + throw new IllegalStateException(String.format( + "no default config for minecraft version %s found (available: %s)", + current, configs.keySet())); + } + + Version configVersion = entry.getKey(); + if (configVersion.major() != current.major() || configVersion.minor() != current.minor()) { + ZIPLogger.warn(String.format( + "No dedicated config for minecraft version %s, falling back to config for %s", + current, configVersion)); + } + + Files.copy(entry.getValue(), target); + } + } + public GeneralConfig general() { return this.generalConfig; }