diff --git a/module/items-integration/build.gradle.kts b/module/items-integration/build.gradle.kts index 4ff67d84..b7bd2aa0 100644 --- a/module/items-integration/build.gradle.kts +++ b/module/items-integration/build.gradle.kts @@ -7,6 +7,7 @@ repositories { artifact() } } + maven("https://nexus.phoenixdevt.fr/repository/maven-public/") } dependencies { @@ -14,5 +15,8 @@ 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("io.lumine:MythicLib-dist:1.6.2-SNAPSHOT") compileOnly("com.elmakers.mine.bukkit:MagicAPI:10.2") + compileOnly("net.Indyuce:MMOItems-API:6.9.5-SNAPSHOT") + compileOnly("com.cjcrafter:weaponmechanics:3.4.1") } 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 d6364e81..b7251085 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 @@ -9,9 +9,11 @@ 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.mmoitems.MMOItemsFeature; 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.battleplugins.arena.module.items.weaponmechanics.WeaponMechanicsFeature; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -34,6 +36,8 @@ public void onPostInitialize(BattleArenaPostInitializeEvent event) { registerProvider(plugin, "ItemsAdder", ItemsAdderFeature::new); registerProvider(plugin, "MythicCrucible", MythicCrucibleFeature::new); registerProvider(plugin, "Magic", MagicFeature::new); + registerProvider(plugin, "MMOItems", MMOItemsFeature::new); + registerProvider(plugin, "WeaponMechanics", WeaponMechanicsFeature::new); } private static & ItemsFeature> void registerProvider(BattleArena plugin, String pluginName, Supplier feature) { diff --git a/module/items-integration/src/main/java/org/battleplugins/arena/module/items/mmoitems/MMOItemsFeature.java b/module/items-integration/src/main/java/org/battleplugins/arena/module/items/mmoitems/MMOItemsFeature.java new file mode 100644 index 00000000..5044f4dc --- /dev/null +++ b/module/items-integration/src/main/java/org/battleplugins/arena/module/items/mmoitems/MMOItemsFeature.java @@ -0,0 +1,81 @@ +package org.battleplugins.arena.module.items.mmoitems; + +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.ItemTier; +import net.Indyuce.mmoitems.api.Type; +import org.battleplugins.arena.BattleArena; +import org.battleplugins.arena.config.ItemStackParser; +import org.battleplugins.arena.config.ParseException; +import org.battleplugins.arena.config.SingularValueParser; +import org.battleplugins.arena.feature.PluginFeature; +import org.battleplugins.arena.feature.items.ItemsFeature; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayDeque; +import java.util.Locale; +import java.util.Queue; + +public class MMOItemsFeature extends PluginFeature implements ItemsFeature { + + public MMOItemsFeature() { + super("MMOItems"); + } + + @Override + public ItemStack createItem(NamespacedKey key) { + throw new UnsupportedOperationException("Cannot create MMOItem without arguments!"); + } + + @Override + public ItemStack createItem(NamespacedKey key, SingularValueParser.ArgumentBuffer arguments) { + Queue argumentQueue = new ArrayDeque<>(); + while (arguments.hasNext()) { + argumentQueue.add(arguments.pop()); + } + + String type = null; + Integer itemLevel = null; + String itemTier = null; + for (SingularValueParser.Argument argument : argumentQueue) { + switch (argument.key()) { + case "type" -> type = argument.value(); + case "level" -> itemLevel = Integer.parseInt(argument.value()); + case "tier" -> itemTier = argument.value(); + } + } + + if (type == null) { + BattleArena.getInstance().warn("No type provided for MMOItem {}!", key); + return new ItemStack(Material.AIR); + } + + Type mmoType = Type.get(type.toUpperCase(Locale.ROOT)); + if (mmoType == null) { + BattleArena.getInstance().warn("Invalid type {} provided for MMOItem {}!", type, key); + return new ItemStack(Material.AIR); + } + + ItemStack itemStack; + if (itemLevel != null) { + ItemTier tier = itemTier == null ? null : MMOItems.plugin.getTiers().get(itemTier.toUpperCase(Locale.ROOT)); + itemStack = MMOItems.plugin.getItem(mmoType, key.value(), itemLevel, tier); + } else { + itemStack = MMOItems.plugin.getItem(mmoType, key.value()); + } + + if (itemStack == null) { + BattleArena.getInstance().warn("No MMOItem found for key {}!", key); + return new ItemStack(Material.AIR); + } + + try { + return ItemStackParser.applyItemProperties(itemStack, arguments); + } catch (ParseException e) { + ParseException.handle(e); + + return new ItemStack(Material.AIR); + } + } +} diff --git a/module/items-integration/src/main/java/org/battleplugins/arena/module/items/weaponmechanics/WeaponMechanicsFeature.java b/module/items-integration/src/main/java/org/battleplugins/arena/module/items/weaponmechanics/WeaponMechanicsFeature.java new file mode 100644 index 00000000..314fc53d --- /dev/null +++ b/module/items-integration/src/main/java/org/battleplugins/arena/module/items/weaponmechanics/WeaponMechanicsFeature.java @@ -0,0 +1,19 @@ +package org.battleplugins.arena.module.items.weaponmechanics; + +import me.deecaad.weaponmechanics.WeaponMechanicsAPI; +import org.battleplugins.arena.feature.PluginFeature; +import org.battleplugins.arena.feature.items.ItemsFeature; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ItemStack; + +public class WeaponMechanicsFeature extends PluginFeature implements ItemsFeature { + + public WeaponMechanicsFeature() { + super("WeaponMechanics"); + } + + @Override + public ItemStack createItem(NamespacedKey key) { + return WeaponMechanicsAPI.generateWeapon(key.value()); + } +} diff --git a/plugin/src/main/java/org/battleplugins/arena/config/SingularValueParser.java b/plugin/src/main/java/org/battleplugins/arena/config/SingularValueParser.java index f11db30c..888b4245 100644 --- a/plugin/src/main/java/org/battleplugins/arena/config/SingularValueParser.java +++ b/plugin/src/main/java/org/battleplugins/arena/config/SingularValueParser.java @@ -89,7 +89,15 @@ private static List parseArguments(String contents, BraceStyle style, ch } public static final class ArgumentBuffer { - private final Queue values = new ArrayDeque<>(); + private final Queue values; + + public ArgumentBuffer() { + this(new ArrayDeque<>()); + } + + public ArgumentBuffer(Queue values) { + this.values = values; + } public void push(String key, String value) { this.values.add(new Argument(key, value)); diff --git a/plugin/src/main/java/org/battleplugins/arena/feature/items/ItemsFeature.java b/plugin/src/main/java/org/battleplugins/arena/feature/items/ItemsFeature.java index 9b705646..26c0d1fa 100644 --- a/plugin/src/main/java/org/battleplugins/arena/feature/items/ItemsFeature.java +++ b/plugin/src/main/java/org/battleplugins/arena/feature/items/ItemsFeature.java @@ -45,6 +45,7 @@ default ItemStack createItem(NamespacedKey key, SingularValueParser.ArgumentBuff return ItemStackParser.applyItemProperties(itemStack, arguments, (itemMeta, argument) -> this.onUnknownArgument(itemStack, itemMeta, argument.key(), argument.value())); } catch (ParseException e) { ParseException.handle(e); + return new ItemStack(Material.AIR); } } diff --git a/plugin/src/main/java/org/battleplugins/arena/feature/items/VanillaItemsFeature.java b/plugin/src/main/java/org/battleplugins/arena/feature/items/VanillaItemsFeature.java index 9c1d16d3..b56405e6 100644 --- a/plugin/src/main/java/org/battleplugins/arena/feature/items/VanillaItemsFeature.java +++ b/plugin/src/main/java/org/battleplugins/arena/feature/items/VanillaItemsFeature.java @@ -15,7 +15,7 @@ private VanillaItemsFeature() { @Override public ItemStack createItem(NamespacedKey key) { - throw new UnsupportedOperationException("Cannot create vanilla item without arguments"); + throw new UnsupportedOperationException("Cannot create vanilla item without arguments!"); } @Override