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
31 changes: 31 additions & 0 deletions .github/workflows/build-jar.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Object, Object>) map).get();
ItemStack it = ItemBuilder.create(normalizeItemMap(map)).get();
ContainerUtils.INSTANCE.addOrDrop(player.getInventory(), List.of(it), player.getLocation());
}
});
Expand Down Expand Up @@ -171,4 +173,39 @@ public Player getPlayer() {
public static Set<RewardGui> getOpenMenus() {
return openMenus;
}

private static Map<Object, Object> normalizeItemMap(Map<?, ?> original) {
final Map<Object, Object> 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;
}
}
Loading