From 906dfd7d8df2f0b1d2d9fb03fbc6b100deb7ac74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Convolte?= <16925280+theo546@users.noreply.github.com> Date: Mon, 30 Jun 2025 20:10:45 +0200 Subject: [PATCH 1/2] Fix self-mapping in loot table and update workflow --- .github/workflows/release.yml | 13 +++++++++++-- RandomDrop/pom.xml | 2 +- .../java/com/theo546/randomdrop/Main.java | 19 ++++++++++++++----- RandomDrop/src/main/resources/plugin.yml | 2 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 766c494..d4c93de 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,12 +23,21 @@ jobs: echo "version=$VERSION" >> "$GITHUB_OUTPUT" - id: commit run: echo "short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" + - id: tag + run: | + VERSION=${{ steps.version.outputs.version }} + COMMIT=${{ steps.commit.outputs.short }} + if [ "${{ github.ref }}" = "refs/heads/dev" ]; then + echo "tag=${VERSION}-${COMMIT}" >> "$GITHUB_OUTPUT" + else + echo "tag=${VERSION}" >> "$GITHUB_OUTPUT" + fi - name: Delete existing release if: github.ref != 'refs/heads/dev' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - TAG=${{ steps.version.outputs.version }} + TAG=${{ steps.tag.outputs.tag }} if state=$(gh release view "$TAG" --json draft -q .draft 2>/dev/null); then if [ "$state" = "false" ]; then gh release delete "$TAG" -y @@ -51,7 +60,7 @@ jobs: - name: Release uses: softprops/action-gh-release@v2 with: - tag_name: ${{ steps.version.outputs.version }} + tag_name: ${{ steps.tag.outputs.tag }} name: RandomDrop ${{ steps.version.outputs.version }} files: ${{ steps.prepare.outputs.file }} draft: ${{ github.ref == 'refs/heads/dev' }} diff --git a/RandomDrop/pom.xml b/RandomDrop/pom.xml index 9aed2a6..f91bf50 100644 --- a/RandomDrop/pom.xml +++ b/RandomDrop/pom.xml @@ -4,7 +4,7 @@ com.theo546 RandomDrop - 1.1.1 + 1.1.2 jar RandomDrop diff --git a/RandomDrop/src/main/java/com/theo546/randomdrop/Main.java b/RandomDrop/src/main/java/com/theo546/randomdrop/Main.java index 99e11fb..1851840 100644 --- a/RandomDrop/src/main/java/com/theo546/randomdrop/Main.java +++ b/RandomDrop/src/main/java/com/theo546/randomdrop/Main.java @@ -109,14 +109,22 @@ private void initLootTable() { } YamlConfiguration yaml = new YamlConfiguration(); + boolean yamlCorrupted = false; if (PERSIST_LOOT_TABLE && file.exists()) { try { yaml.load(file); for (String key : yaml.getKeys(false)) { Material k = Material.getMaterial(key); - Material v = Material.getMaterial(yaml.getString(key)); + String value = yaml.getString(key); + Material v = Material.getMaterial(value); if (k != null && v != null) { - LOOT_TABLE.put(k, v); + if (k != v) { + LOOT_TABLE.put(k, v); + } else { + yamlCorrupted = true; + } + } else { + yamlCorrupted = true; } } } catch (Exception e) { @@ -128,7 +136,7 @@ private void initLootTable() { Collections.shuffle(shuffled, new Random(SEED)); shuffled.removeAll(LOOT_TABLE.values()); - boolean updated = false; + boolean updated = yamlCorrupted; for (Material m : valid) { if (!LOOT_TABLE.containsKey(m)) { if (shuffled.isEmpty()) break; @@ -138,11 +146,12 @@ private void initLootTable() { } if (PERSIST_LOOT_TABLE && (updated || !file.exists())) { + YamlConfiguration out = new YamlConfiguration(); for (Map.Entry entry : LOOT_TABLE.entrySet()) { - yaml.set(entry.getKey().name(), entry.getValue().name()); + out.set(entry.getKey().name(), entry.getValue().name()); } try { - yaml.save(file); + out.save(file); } catch (IOException e) { getLogger().warning("Failed to save loot table: " + e.getMessage()); } diff --git a/RandomDrop/src/main/resources/plugin.yml b/RandomDrop/src/main/resources/plugin.yml index 543390a..5d043fc 100644 --- a/RandomDrop/src/main/resources/plugin.yml +++ b/RandomDrop/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ main: com.theo546.randomdrop.Main name: RandomDrop -version: "1.1.1" +version: "1.1.2" api-version: 1.21 author: theo546 description: A Paper plugin to randomize the Minecraft loot table! From 8c50250935abd90f6511dca8bbbb9fe0e02fb15f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Convolte?= <16925280+theo546@users.noreply.github.com> Date: Mon, 30 Jun 2025 20:27:13 +0200 Subject: [PATCH 2/2] Avoid self-mapping and regenerate loot table --- .github/workflows/release.yml | 13 ++++++++-- RandomDrop/pom.xml | 2 +- .../java/com/theo546/randomdrop/Main.java | 26 ++++++++++++++----- RandomDrop/src/main/resources/plugin.yml | 2 +- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 766c494..d4c93de 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,12 +23,21 @@ jobs: echo "version=$VERSION" >> "$GITHUB_OUTPUT" - id: commit run: echo "short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" + - id: tag + run: | + VERSION=${{ steps.version.outputs.version }} + COMMIT=${{ steps.commit.outputs.short }} + if [ "${{ github.ref }}" = "refs/heads/dev" ]; then + echo "tag=${VERSION}-${COMMIT}" >> "$GITHUB_OUTPUT" + else + echo "tag=${VERSION}" >> "$GITHUB_OUTPUT" + fi - name: Delete existing release if: github.ref != 'refs/heads/dev' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - TAG=${{ steps.version.outputs.version }} + TAG=${{ steps.tag.outputs.tag }} if state=$(gh release view "$TAG" --json draft -q .draft 2>/dev/null); then if [ "$state" = "false" ]; then gh release delete "$TAG" -y @@ -51,7 +60,7 @@ jobs: - name: Release uses: softprops/action-gh-release@v2 with: - tag_name: ${{ steps.version.outputs.version }} + tag_name: ${{ steps.tag.outputs.tag }} name: RandomDrop ${{ steps.version.outputs.version }} files: ${{ steps.prepare.outputs.file }} draft: ${{ github.ref == 'refs/heads/dev' }} diff --git a/RandomDrop/pom.xml b/RandomDrop/pom.xml index 9aed2a6..f91bf50 100644 --- a/RandomDrop/pom.xml +++ b/RandomDrop/pom.xml @@ -4,7 +4,7 @@ com.theo546 RandomDrop - 1.1.1 + 1.1.2 jar RandomDrop diff --git a/RandomDrop/src/main/java/com/theo546/randomdrop/Main.java b/RandomDrop/src/main/java/com/theo546/randomdrop/Main.java index 99e11fb..72c87e6 100644 --- a/RandomDrop/src/main/java/com/theo546/randomdrop/Main.java +++ b/RandomDrop/src/main/java/com/theo546/randomdrop/Main.java @@ -109,14 +109,17 @@ private void initLootTable() { } YamlConfiguration yaml = new YamlConfiguration(); + boolean updated = false; if (PERSIST_LOOT_TABLE && file.exists()) { try { yaml.load(file); for (String key : yaml.getKeys(false)) { Material k = Material.getMaterial(key); Material v = Material.getMaterial(yaml.getString(key)); - if (k != null && v != null) { + if (k != null && v != null && k != v) { LOOT_TABLE.put(k, v); + } else { + updated = true; } } } catch (Exception e) { @@ -128,21 +131,30 @@ private void initLootTable() { Collections.shuffle(shuffled, new Random(SEED)); shuffled.removeAll(LOOT_TABLE.values()); - boolean updated = false; for (Material m : valid) { if (!LOOT_TABLE.containsKey(m)) { - if (shuffled.isEmpty()) break; - LOOT_TABLE.put(m, shuffled.remove(0)); - updated = true; + Material candidate = null; + while (!shuffled.isEmpty()) { + Material choice = shuffled.remove(0); + if (choice != m) { + candidate = choice; + break; + } + } + if (candidate != null) { + LOOT_TABLE.put(m, candidate); + updated = true; + } } } if (PERSIST_LOOT_TABLE && (updated || !file.exists())) { + YamlConfiguration out = new YamlConfiguration(); for (Map.Entry entry : LOOT_TABLE.entrySet()) { - yaml.set(entry.getKey().name(), entry.getValue().name()); + out.set(entry.getKey().name(), entry.getValue().name()); } try { - yaml.save(file); + out.save(file); } catch (IOException e) { getLogger().warning("Failed to save loot table: " + e.getMessage()); } diff --git a/RandomDrop/src/main/resources/plugin.yml b/RandomDrop/src/main/resources/plugin.yml index 543390a..5d043fc 100644 --- a/RandomDrop/src/main/resources/plugin.yml +++ b/RandomDrop/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ main: com.theo546.randomdrop.Main name: RandomDrop -version: "1.1.1" +version: "1.1.2" api-version: 1.21 author: theo546 description: A Paper plugin to randomize the Minecraft loot table!