Skip to content

Commit 76cd50e

Browse files
authored
Add support for external items anywhere that accepts an item key (#335)
- Only oraxen and mythicmobs are currently supported
1 parent 1b91a7b commit 76cd50e

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

api/src/main/java/dev/aurelium/auraskills/api/registry/NamespacedId.java

+11
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ public class NamespacedId {
77

88
public static final String AURASKILLS = "auraskills";
99
private final String namespace;
10+
private final String originalKey;
1011
private final String key;
1112

1213
private NamespacedId(String namespace, String key) {
1314
this.namespace = namespace.toLowerCase(Locale.ROOT);
15+
this.originalKey = key;
1416
this.key = key.toLowerCase(Locale.ROOT);
1517
}
1618

@@ -33,6 +35,15 @@ public String getKey() {
3335
return key;
3436
}
3537

38+
/**
39+
* Gets the original key portion of the NamespacedId, which is the key in the case it was created with.
40+
*
41+
* @return the original key
42+
*/
43+
public String getOriginalKey() {
44+
return originalKey;
45+
}
46+
3647
/**
3748
* Returns the full String representation of the NamespacedId, with a / separating the
3849
* namespace and the key.

bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/MythicMobsHook.java

+7
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@ public MythicMobsHook(AuraSkills plugin, ConfigurationNode config) {
3232
this.plugin = plugin;
3333
this.damageHandler = new DamageHandler();
3434

35+
registerItemProvider();
36+
3537
// Wait for loot manager to be created, but add parser before it is loaded
3638
plugin.getScheduler().executeSync(() ->
3739
plugin.getLootTableManager().getLootManager().registerCustomEntityParser(new MythicEntityLootParser(plugin)));
3840
}
3941

42+
private void registerItemProvider() {
43+
plugin.getItemRegistry().registerExternalItemProvider("mythicmobs",
44+
(id) -> MythicBukkit.inst().getItemManager().getItemStack(id));
45+
}
46+
4047
@EventHandler
4148
public void onMythicSkillDamage(MythicDamageEvent event) {
4249
// This is always some sort of skill/mechanic damage.

bukkit/src/main/java/dev/aurelium/auraskills/bukkit/item/BukkitItemRegistry.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@ public ItemStack getItem(NamespacedId key) {
5858
ItemStack item = items.get(key);
5959
if (item != null) {
6060
return item.clone();
61-
} else {
62-
return null;
6361
}
62+
63+
ExternalItemProvider provider = externalItemProviders.get(key.getNamespace());
64+
if (provider != null) {
65+
return provider.getItem(key.getOriginalKey());
66+
}
67+
68+
return null;
6469
}
6570

6671
public Map<NamespacedId, ItemStack> getItems() {

0 commit comments

Comments
 (0)