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!