mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-03 06:37:47 +01:00
Type sets
This commit is contained in:
parent
0ded0879da
commit
8768f1b9fe
@ -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(" ", "_"));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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) {
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user