Skip to content

Commit

Permalink
Reimplement item key parsing for loot
Browse files Browse the repository at this point in the history
  • Loading branch information
Archy-X committed May 30, 2022
1 parent a6bfb2a commit 9a738b3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
<dependency>
<groupId>com.github.Archy-X</groupId>
<artifactId>LootManager</artifactId>
<version>9bec6177c7</version>
<version>12d4d332b1</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/archyx/aureliumskills/loot/ItemKeyParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.archyx.aureliumskills.loot;

import com.archyx.aureliumskills.AureliumSkills;
import com.archyx.aureliumskills.util.misc.Parser;
import com.archyx.lootmanager.loot.parser.CustomItemParser;
import org.bukkit.inventory.ItemStack;

import java.util.Map;

public class ItemKeyParser extends Parser implements CustomItemParser {

private final AureliumSkills plugin;

public ItemKeyParser(AureliumSkills plugin) {
this.plugin = plugin;
}

@Override
public boolean shouldUseParser(Map<?, ?> map) {
return map.containsKey("key");
}

@Override
public ItemStack parseCustomItem(Map<?, ?> map) {
String itemKey = getString(map, "key");
ItemStack item = plugin.getItemRegistry().getItem(itemKey);
if (item != null) {
return item;
} else {
throw new IllegalArgumentException("Item with key " + itemKey + " not found in item registry");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public LootTableManager(AureliumSkills plugin) {

public void initLootManager() {
lootManager.registerContextManager(new SourceContextManager(plugin));
lootManager.registerCustomItemParser(new ItemKeyParser(plugin));
lootManager.addLootOptionKeys("xp");
lootManager.addPoolOptionKeys("chance_per_luck", "require_open_water");
}
Expand Down

0 comments on commit 9a738b3

Please sign in to comment.