From 2a3989323665cfce400368538c73e6ef71b3dbee Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Mon, 6 Jan 2025 15:18:43 -0600 Subject: [PATCH] Add support for items from Magic --- module/items-integration/build.gradle.kts | 1 + .../arena/module/items/ItemsIntegration.java | 36 +++++++++---------- .../module/items/magic/MagicFeature.java | 26 ++++++++++++++ 3 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 module/items-integration/src/main/java/org/battleplugins/arena/module/items/magic/MagicFeature.java diff --git a/module/items-integration/build.gradle.kts b/module/items-integration/build.gradle.kts index 0ab6609b..4ff67d84 100644 --- a/module/items-integration/build.gradle.kts +++ b/module/items-integration/build.gradle.kts @@ -14,4 +14,5 @@ dependencies { compileOnly("me.zombie_striker:QualityArmory:2.0.17") compileOnly("com.github.LoneDev6:api-itemsadder:3.6.1") compileOnly("io.lumine:Mythic-Dist:5.6.1") + compileOnly("com.elmakers.mine.bukkit:MagicAPI:10.2") } diff --git a/module/items-integration/src/main/java/org/battleplugins/arena/module/items/ItemsIntegration.java b/module/items-integration/src/main/java/org/battleplugins/arena/module/items/ItemsIntegration.java index f2dada8b..d6364e81 100644 --- a/module/items-integration/src/main/java/org/battleplugins/arena/module/items/ItemsIntegration.java +++ b/module/items-integration/src/main/java/org/battleplugins/arena/module/items/ItemsIntegration.java @@ -1,10 +1,14 @@ package org.battleplugins.arena.module.items; +import org.battleplugins.arena.BattleArena; import org.battleplugins.arena.event.BattleArenaPostInitializeEvent; +import org.battleplugins.arena.feature.PluginFeature; import org.battleplugins.arena.feature.items.Items; +import org.battleplugins.arena.feature.items.ItemsFeature; import org.battleplugins.arena.module.ArenaModule; import org.battleplugins.arena.module.ArenaModuleInitializer; import org.battleplugins.arena.module.items.itemsadder.ItemsAdderFeature; +import org.battleplugins.arena.module.items.magic.MagicFeature; import org.battleplugins.arena.module.items.mythiccrucible.MythicCrucibleFeature; import org.battleplugins.arena.module.items.oraxen.OraxenFeature; import org.battleplugins.arena.module.items.qualityarmory.QualityArmoryFeature; @@ -12,6 +16,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import java.util.function.Supplier; + /** * A module that allows for hooking into various item provider plugins. */ @@ -21,28 +27,20 @@ public class ItemsIntegration implements ArenaModuleInitializer { @EventHandler(priority = EventPriority.LOWEST) // Load before all other modules listening on this event public void onPostInitialize(BattleArenaPostInitializeEvent event) { - if (Bukkit.getPluginManager().isPluginEnabled("QualityArmory")) { - Items.register(new QualityArmoryFeature()); - - event.getBattleArena().info("QualityArmory found. Registering item integration."); - } + BattleArena plugin = event.getBattleArena(); - if (Bukkit.getPluginManager().isPluginEnabled("Oraxen")) { - Items.register(new OraxenFeature()); - - event.getBattleArena().info("Oraxen found. Registering item integration."); - } - - if (Bukkit.getPluginManager().isPluginEnabled("ItemsAdder")) { - Items.register(new ItemsAdderFeature()); - - event.getBattleArena().info("ItemsAdder found. Registering item integration."); - } + registerProvider(plugin, "QualityArmory", QualityArmoryFeature::new); + registerProvider(plugin, "Oraxen", OraxenFeature::new); + registerProvider(plugin, "ItemsAdder", ItemsAdderFeature::new); + registerProvider(plugin, "MythicCrucible", MythicCrucibleFeature::new); + registerProvider(plugin, "Magic", MagicFeature::new); + } - if (Bukkit.getPluginManager().isPluginEnabled("MythicCrucible")) { - Items.register(new MythicCrucibleFeature()); + private static & ItemsFeature> void registerProvider(BattleArena plugin, String pluginName, Supplier feature) { + if (Bukkit.getPluginManager().isPluginEnabled(pluginName)) { + Items.register(feature.get()); - event.getBattleArena().info("MythicCrucible found. Registering item integration."); + plugin.info("{} found. Registering item integration.", pluginName); } } } diff --git a/module/items-integration/src/main/java/org/battleplugins/arena/module/items/magic/MagicFeature.java b/module/items-integration/src/main/java/org/battleplugins/arena/module/items/magic/MagicFeature.java new file mode 100644 index 00000000..398368e5 --- /dev/null +++ b/module/items-integration/src/main/java/org/battleplugins/arena/module/items/magic/MagicFeature.java @@ -0,0 +1,26 @@ +package org.battleplugins.arena.module.items.magic; + +import com.elmakers.mine.bukkit.api.magic.MagicAPI; +import org.battleplugins.arena.feature.PluginFeature; +import org.battleplugins.arena.feature.items.ItemsFeature; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ItemStack; + +public class MagicFeature extends PluginFeature implements ItemsFeature { + private final MagicAPI magicAPI; + + public MagicFeature() { + super("Magic"); + + if (!(this.getPlugin() instanceof MagicAPI magicAPI)) { + throw new IllegalStateException("MagicAPI not found!"); + } + + this.magicAPI = magicAPI; + } + + @Override + public ItemStack createItem(NamespacedKey key) { + return this.magicAPI.createItem(key.value()); + } +}