forked from alkarinv/BattleArena
-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement item support for MMOItems and WeaponMechanics
- Loading branch information
Showing
7 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...egration/src/main/java/org/battleplugins/arena/module/items/mmoitems/MMOItemsFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ain/java/org/battleplugins/arena/module/items/weaponmechanics/WeaponMechanicsFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters