Skip to content

Commit

Permalink
Implement item support for MMOItems and WeaponMechanics
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Jan 6, 2025
1 parent 2a39893 commit 67552cc
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 2 deletions.
4 changes: 4 additions & 0 deletions module/items-integration/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ repositories {
artifact()
}
}
maven("https://nexus.phoenixdevt.fr/repository/maven-public/")
}

dependencies {
compileOnly("io.th0rgal:oraxen:1.173.0")
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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 <T extends PluginFeature<ItemsFeature> & ItemsFeature> void registerProvider(BattleArena plugin, String pluginName, Supplier<T> feature) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ItemsFeature> 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<SingularValueParser.Argument> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<ItemsFeature> implements ItemsFeature {

public WeaponMechanicsFeature() {
super("WeaponMechanics");
}

@Override
public ItemStack createItem(NamespacedKey key) {
return WeaponMechanicsAPI.generateWeapon(key.value());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ private static List<String> parseArguments(String contents, BraceStyle style, ch
}

public static final class ArgumentBuffer {
private final Queue<Argument> values = new ArrayDeque<>();
private final Queue<Argument> values;

public ArgumentBuffer() {
this(new ArrayDeque<>());
}

public ArgumentBuffer(Queue<Argument> values) {
this.values = values;
}

public void push(String key, String value) {
this.values.add(new Argument(key, value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 67552cc

Please sign in to comment.