diff --git a/.github/workflows/build-jar.yml b/.github/workflows/build-jar.yml new file mode 100644 index 0000000..8738ca1 --- /dev/null +++ b/.github/workflows/build-jar.yml @@ -0,0 +1,31 @@ +name: Build AxRewards Jar + +on: + push: + branches: + - "**" + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Java 21 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "21" + cache: maven + + - name: Build plugin jar + run: mvn -B -DskipTests package + + - name: Upload jar artifact + uses: actions/upload-artifact@v4 + with: + name: AxRewards-jar + path: target/*.jar + if-no-files-found: error diff --git a/src/main/java/com/artillexstudios/axrewards/guis/impl/RewardGui.java b/src/main/java/com/artillexstudios/axrewards/guis/impl/RewardGui.java index d19e71e..5a51dfa 100644 --- a/src/main/java/com/artillexstudios/axrewards/guis/impl/RewardGui.java +++ b/src/main/java/com/artillexstudios/axrewards/guis/impl/RewardGui.java @@ -23,11 +23,13 @@ import org.bukkit.inventory.ItemStack; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.WeakHashMap; import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; import static com.artillexstudios.axrewards.AxRewards.CONFIG; import static com.artillexstudios.axrewards.AxRewards.LANG; @@ -122,7 +124,7 @@ public void open() { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), AxRewards.getPlaceholderParser().setPlaceholders(player, command)); } for (Map map : reward.claimItems()) { - ItemStack it = ItemBuilder.create((Map) map).get(); + ItemStack it = ItemBuilder.create(normalizeItemMap(map)).get(); ContainerUtils.INSTANCE.addOrDrop(player.getInventory(), List.of(it), player.getLocation()); } }); @@ -171,4 +173,39 @@ public Player getPlayer() { public static Set getOpenMenus() { return openMenus; } + + private static Map normalizeItemMap(Map original) { + final Map copy = new LinkedHashMap<>(); + for (Map.Entry entry : original.entrySet()) { + Object key = entry.getKey(); + Object value = entry.getValue(); + + if (value instanceof Map nested) { + value = normalizeItemMap(nested); + } else if (value instanceof List list) { + value = list.stream().map(element -> { + if (element instanceof Map map) { + if (map.size() == 1) { + Map.Entry mapEntry = map.entrySet().iterator().next(); + return mapEntry.getKey() + ":" + mapEntry.getValue(); + } + + return normalizeItemMap(map); + } + + return element; + }).collect(Collectors.toList()); + } + + if (("enchants".equals(key) || "enchantments".equals(key)) && value instanceof Map enchants) { + value = enchants.entrySet().stream() + .map(e -> e.getKey() + ":" + e.getValue()) + .collect(Collectors.toList()); + } + + copy.put(key, value); + } + + return copy; + } }