Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/buildtools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -42,4 +44,3 @@ jobs:
with:
artifacts: "zip-*.jar"
name: Release ${{ env.RELEASE_VERSION }}
token: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@ protected static <T> 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);
}
Expand Down
62 changes: 52 additions & 10 deletions zip-plugin/src/main/java/dev/imprex/zip/config/BackpackConfig.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}

Expand All @@ -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<Path> files = Files.list(fileSystem.getPath("/config"))) {

TreeMap<Version, Path> 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<Version, Path> 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;
}
Expand Down
Loading