Skip to content

Commit 67552cc

Browse files
committed
Implement item support for MMOItems and WeaponMechanics
1 parent 2a39893 commit 67552cc

File tree

7 files changed

+119
-2
lines changed

7 files changed

+119
-2
lines changed

module/items-integration/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ repositories {
77
artifact()
88
}
99
}
10+
maven("https://nexus.phoenixdevt.fr/repository/maven-public/")
1011
}
1112

1213
dependencies {
1314
compileOnly("io.th0rgal:oraxen:1.173.0")
1415
compileOnly("me.zombie_striker:QualityArmory:2.0.17")
1516
compileOnly("com.github.LoneDev6:api-itemsadder:3.6.1")
1617
compileOnly("io.lumine:Mythic-Dist:5.6.1")
18+
compileOnly("io.lumine:MythicLib-dist:1.6.2-SNAPSHOT")
1719
compileOnly("com.elmakers.mine.bukkit:MagicAPI:10.2")
20+
compileOnly("net.Indyuce:MMOItems-API:6.9.5-SNAPSHOT")
21+
compileOnly("com.cjcrafter:weaponmechanics:3.4.1")
1822
}

module/items-integration/src/main/java/org/battleplugins/arena/module/items/ItemsIntegration.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import org.battleplugins.arena.module.ArenaModuleInitializer;
1010
import org.battleplugins.arena.module.items.itemsadder.ItemsAdderFeature;
1111
import org.battleplugins.arena.module.items.magic.MagicFeature;
12+
import org.battleplugins.arena.module.items.mmoitems.MMOItemsFeature;
1213
import org.battleplugins.arena.module.items.mythiccrucible.MythicCrucibleFeature;
1314
import org.battleplugins.arena.module.items.oraxen.OraxenFeature;
1415
import org.battleplugins.arena.module.items.qualityarmory.QualityArmoryFeature;
16+
import org.battleplugins.arena.module.items.weaponmechanics.WeaponMechanicsFeature;
1517
import org.bukkit.Bukkit;
1618
import org.bukkit.event.EventHandler;
1719
import org.bukkit.event.EventPriority;
@@ -34,6 +36,8 @@ public void onPostInitialize(BattleArenaPostInitializeEvent event) {
3436
registerProvider(plugin, "ItemsAdder", ItemsAdderFeature::new);
3537
registerProvider(plugin, "MythicCrucible", MythicCrucibleFeature::new);
3638
registerProvider(plugin, "Magic", MagicFeature::new);
39+
registerProvider(plugin, "MMOItems", MMOItemsFeature::new);
40+
registerProvider(plugin, "WeaponMechanics", WeaponMechanicsFeature::new);
3741
}
3842

3943
private static <T extends PluginFeature<ItemsFeature> & ItemsFeature> void registerProvider(BattleArena plugin, String pluginName, Supplier<T> feature) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package org.battleplugins.arena.module.items.mmoitems;
2+
3+
import net.Indyuce.mmoitems.MMOItems;
4+
import net.Indyuce.mmoitems.api.ItemTier;
5+
import net.Indyuce.mmoitems.api.Type;
6+
import org.battleplugins.arena.BattleArena;
7+
import org.battleplugins.arena.config.ItemStackParser;
8+
import org.battleplugins.arena.config.ParseException;
9+
import org.battleplugins.arena.config.SingularValueParser;
10+
import org.battleplugins.arena.feature.PluginFeature;
11+
import org.battleplugins.arena.feature.items.ItemsFeature;
12+
import org.bukkit.Material;
13+
import org.bukkit.NamespacedKey;
14+
import org.bukkit.inventory.ItemStack;
15+
16+
import java.util.ArrayDeque;
17+
import java.util.Locale;
18+
import java.util.Queue;
19+
20+
public class MMOItemsFeature extends PluginFeature<ItemsFeature> implements ItemsFeature {
21+
22+
public MMOItemsFeature() {
23+
super("MMOItems");
24+
}
25+
26+
@Override
27+
public ItemStack createItem(NamespacedKey key) {
28+
throw new UnsupportedOperationException("Cannot create MMOItem without arguments!");
29+
}
30+
31+
@Override
32+
public ItemStack createItem(NamespacedKey key, SingularValueParser.ArgumentBuffer arguments) {
33+
Queue<SingularValueParser.Argument> argumentQueue = new ArrayDeque<>();
34+
while (arguments.hasNext()) {
35+
argumentQueue.add(arguments.pop());
36+
}
37+
38+
String type = null;
39+
Integer itemLevel = null;
40+
String itemTier = null;
41+
for (SingularValueParser.Argument argument : argumentQueue) {
42+
switch (argument.key()) {
43+
case "type" -> type = argument.value();
44+
case "level" -> itemLevel = Integer.parseInt(argument.value());
45+
case "tier" -> itemTier = argument.value();
46+
}
47+
}
48+
49+
if (type == null) {
50+
BattleArena.getInstance().warn("No type provided for MMOItem {}!", key);
51+
return new ItemStack(Material.AIR);
52+
}
53+
54+
Type mmoType = Type.get(type.toUpperCase(Locale.ROOT));
55+
if (mmoType == null) {
56+
BattleArena.getInstance().warn("Invalid type {} provided for MMOItem {}!", type, key);
57+
return new ItemStack(Material.AIR);
58+
}
59+
60+
ItemStack itemStack;
61+
if (itemLevel != null) {
62+
ItemTier tier = itemTier == null ? null : MMOItems.plugin.getTiers().get(itemTier.toUpperCase(Locale.ROOT));
63+
itemStack = MMOItems.plugin.getItem(mmoType, key.value(), itemLevel, tier);
64+
} else {
65+
itemStack = MMOItems.plugin.getItem(mmoType, key.value());
66+
}
67+
68+
if (itemStack == null) {
69+
BattleArena.getInstance().warn("No MMOItem found for key {}!", key);
70+
return new ItemStack(Material.AIR);
71+
}
72+
73+
try {
74+
return ItemStackParser.applyItemProperties(itemStack, arguments);
75+
} catch (ParseException e) {
76+
ParseException.handle(e);
77+
78+
return new ItemStack(Material.AIR);
79+
}
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.battleplugins.arena.module.items.weaponmechanics;
2+
3+
import me.deecaad.weaponmechanics.WeaponMechanicsAPI;
4+
import org.battleplugins.arena.feature.PluginFeature;
5+
import org.battleplugins.arena.feature.items.ItemsFeature;
6+
import org.bukkit.NamespacedKey;
7+
import org.bukkit.inventory.ItemStack;
8+
9+
public class WeaponMechanicsFeature extends PluginFeature<ItemsFeature> implements ItemsFeature {
10+
11+
public WeaponMechanicsFeature() {
12+
super("WeaponMechanics");
13+
}
14+
15+
@Override
16+
public ItemStack createItem(NamespacedKey key) {
17+
return WeaponMechanicsAPI.generateWeapon(key.value());
18+
}
19+
}

plugin/src/main/java/org/battleplugins/arena/config/SingularValueParser.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,15 @@ private static List<String> parseArguments(String contents, BraceStyle style, ch
8989
}
9090

9191
public static final class ArgumentBuffer {
92-
private final Queue<Argument> values = new ArrayDeque<>();
92+
private final Queue<Argument> values;
93+
94+
public ArgumentBuffer() {
95+
this(new ArrayDeque<>());
96+
}
97+
98+
public ArgumentBuffer(Queue<Argument> values) {
99+
this.values = values;
100+
}
93101

94102
public void push(String key, String value) {
95103
this.values.add(new Argument(key, value));

plugin/src/main/java/org/battleplugins/arena/feature/items/ItemsFeature.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ default ItemStack createItem(NamespacedKey key, SingularValueParser.ArgumentBuff
4545
return ItemStackParser.applyItemProperties(itemStack, arguments, (itemMeta, argument) -> this.onUnknownArgument(itemStack, itemMeta, argument.key(), argument.value()));
4646
} catch (ParseException e) {
4747
ParseException.handle(e);
48+
4849
return new ItemStack(Material.AIR);
4950
}
5051
}

plugin/src/main/java/org/battleplugins/arena/feature/items/VanillaItemsFeature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private VanillaItemsFeature() {
1515

1616
@Override
1717
public ItemStack createItem(NamespacedKey key) {
18-
throw new UnsupportedOperationException("Cannot create vanilla item without arguments");
18+
throw new UnsupportedOperationException("Cannot create vanilla item without arguments!");
1919
}
2020

2121
@Override

0 commit comments

Comments
 (0)