diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java index 50ccc572..e09ade48 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java @@ -314,5 +314,6 @@ public class Type { */ public static boolean isValid(@Nullable String id) { return id != null && MMOItems.plugin.getTypes().has(id.toUpperCase().replace("-", "_").replace(" ", "_")); + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java index 2bf9cc48..8351cfb8 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java @@ -134,11 +134,11 @@ public enum TypeSet { private final SetAttackHandler attackHandler; private final String name; - private TypeSet() { + TypeSet() { this(null); } - private TypeSet(SetAttackHandler attackHandler) { + TypeSet(SetAttackHandler attackHandler) { this.attackHandler = attackHandler; this.name = MMOUtils.caseOnWords(name().toLowerCase()); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/set/AbstractTypeSet.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/set/AbstractTypeSet.java new file mode 100644 index 00000000..182f2bba --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/set/AbstractTypeSet.java @@ -0,0 +1,31 @@ +package net.Indyuce.mmoitems.api.item.type.set; + +import org.jetbrains.annotations.ApiStatus; + +/** + * mmoitems + * 21/02/2023 + * + * @author Roch Blondiaux (Kiwix). + */ +@ApiStatus.Internal +public abstract class AbstractTypeSet implements MMOTypeSet { + + private final String name; + private final boolean hasAttackEffect; + + public AbstractTypeSet(String name, boolean hasAttackEffect) { + this.name = name; + this.hasAttackEffect = hasAttackEffect; + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean hasAttackEffect() { + return hasAttackEffect; + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/set/DummyTypeSet.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/set/DummyTypeSet.java new file mode 100644 index 00000000..cefa2bfd --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/set/DummyTypeSet.java @@ -0,0 +1,23 @@ +package net.Indyuce.mmoitems.api.item.type.set; + +import io.lumine.mythic.lib.damage.AttackMetadata; +import net.Indyuce.mmoitems.api.interaction.weapon.Weapon; +import net.Indyuce.mmoitems.api.player.PlayerData; +import org.bukkit.entity.LivingEntity; + +/** + * mmoitems + * 21/02/2023 + * + * @author Roch Blondiaux (Kiwix). + */ +public class DummyTypeSet extends AbstractTypeSet { + + public DummyTypeSet(String name) { + super(name, false); + } + + @Override + public void apply(AttackMetadata attackData, PlayerData source, LivingEntity target, Weapon weapon) { + } +} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/set/MMOTypeSet.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/set/MMOTypeSet.java index 9389893d..4c0e231d 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/set/MMOTypeSet.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/set/MMOTypeSet.java @@ -1,5 +1,10 @@ package net.Indyuce.mmoitems.api.item.type.set; +import io.lumine.mythic.lib.damage.AttackMetadata; +import net.Indyuce.mmoitems.api.interaction.weapon.Weapon; +import net.Indyuce.mmoitems.api.player.PlayerData; +import org.bukkit.entity.LivingEntity; + /** * mmoitems * 20/02/2023 @@ -8,5 +13,15 @@ package net.Indyuce.mmoitems.api.item.type.set; */ public interface MMOTypeSet { + String getName(); + + void apply(AttackMetadata attackData, PlayerData source, LivingEntity target, Weapon weapon); + + boolean hasAttackEffect(); + + default void applyAttackEffect(AttackMetadata attackMeta, PlayerData damager, LivingEntity target, Weapon weapon) { + if (this.hasAttackEffect()) + this.apply(attackMeta, damager, target, weapon); + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/set/ScriptTypeSet.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/set/ScriptTypeSet.java new file mode 100644 index 00000000..8e1a5849 --- /dev/null +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/item/type/set/ScriptTypeSet.java @@ -0,0 +1,53 @@ +package net.Indyuce.mmoitems.api.item.type.set; + +import io.lumine.mythic.lib.MythicLib; +import io.lumine.mythic.lib.damage.AttackMetadata; +import io.lumine.mythic.lib.script.Script; +import io.lumine.mythic.lib.skill.SkillMetadata; +import net.Indyuce.mmoitems.api.interaction.weapon.Weapon; +import net.Indyuce.mmoitems.api.player.PlayerData; +import org.apache.commons.lang3.Validate; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.LivingEntity; +import org.jetbrains.annotations.NotNull; + +/** + * mmoitems + * 21/02/2023 + * + * @author Roch Blondiaux (Kiwix). + */ +public class ScriptTypeSet extends AbstractTypeSet { + + private final Script script; + + public ScriptTypeSet(String name, boolean hasAttackEffect, Script script) { + super(name, hasAttackEffect); + this.script = script; + } + + @Override + public void apply(AttackMetadata attackData, PlayerData source, LivingEntity target, Weapon weapon) { + final SkillMetadata skillMetadata = new SkillMetadata(null, source.getMMOPlayerData()); + // TODO: check if the scripts are working + script.cast(skillMetadata); + } + + + public Script getScript() { + return script; + } + + public static ScriptTypeSet load(@NotNull ConfigurationSection section) { + Validate.notNull(section, "The section cannot be null"); + Validate.isTrue(section.contains("name"), "The section must contain a name"); + Validate.isTrue(section.contains("attack-effect"), "The section must contain a has-attack-effect"); + Validate.isTrue(section.contains("script"), "The section must contain a script"); + + final String name = section.getString("name"); + final boolean hasAttackEffect = section.getBoolean("has-attack-effect"); + final Script script = MythicLib.plugin.getSkills().getScriptOrThrow(section.getString("script")); + + return new ScriptTypeSet(name, hasAttackEffect, script); + } +}