Skip to content

Commit

Permalink
Add support for items from Magic
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Jan 6, 2025
1 parent 8331b95 commit 2a39893
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
1 change: 1 addition & 0 deletions module/items-integration/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
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;
import org.bukkit.Bukkit;
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.
*/
Expand All @@ -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 <T extends PluginFeature<ItemsFeature> & ItemsFeature> void registerProvider(BattleArena plugin, String pluginName, Supplier<T> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<ItemsFeature> 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());
}
}

0 comments on commit 2a39893

Please sign in to comment.