From 426cc906db3a24b5d112df72d7a1045b3e80dc55 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sun, 28 Nov 2021 09:34:06 +0100 Subject: [PATCH] New api methods --- .../net/Indyuce/mmoitems/api/MMOItemsAPI.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/main/java/net/Indyuce/mmoitems/api/MMOItemsAPI.java b/src/main/java/net/Indyuce/mmoitems/api/MMOItemsAPI.java index 86dd0980..00289383 100644 --- a/src/main/java/net/Indyuce/mmoitems/api/MMOItemsAPI.java +++ b/src/main/java/net/Indyuce/mmoitems/api/MMOItemsAPI.java @@ -1,8 +1,22 @@ package net.Indyuce.mmoitems.api; +import io.lumine.mythic.lib.api.player.EquipmentSlot; +import io.lumine.mythic.lib.api.player.MMOPlayerData; +import io.lumine.mythic.lib.damage.AttackMetadata; +import io.lumine.mythic.lib.damage.DamageMetadata; +import io.lumine.mythic.lib.skill.trigger.TriggerType; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.ability.Ability; +import net.Indyuce.mmoitems.api.player.PlayerData; +import net.Indyuce.mmoitems.api.player.RPGPlayer; +import net.Indyuce.mmoitems.stat.data.AbilityData; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; +import java.util.Objects; public class MMOItemsAPI { private final JavaPlugin plugin; @@ -28,4 +42,70 @@ public class MMOItemsAPI { public void registerAbility(Ability ability) { MMOItems.plugin.getAbilities().registerAbility(ability); } + + /** + * @return Ability with the specified identifier like FIREBOLT + */ + public Ability getAbilityById(String id) { + return Objects.requireNonNull(MMOItems.plugin.getAbilities().getAbility(id), "Could not find ability with ID '" + id + "'"); + } + + public PlayerData getPlayerData(Player player) { + return PlayerData.get(player); + } + + public RPGPlayer getRPGInfo(Player player) { + return PlayerData.get(player).getRPG(); + } + + /** + * Forces a player to cast an ability + * + * @param player Player casting the ability + * @param abilityName Ability name. The ability is found using {@link #getAbilityById(String)} + * @param modifiers Ability modifiers + * @param target The ability target (null if no target) + */ + public AttackMetadata castAbility(Player player, String abilityName, Map modifiers, @NotNull LivingEntity target) { + AttackMetadata attackMeta = new AttackMetadata(new DamageMetadata(), MMOPlayerData.get(player).getStatMap().cache(EquipmentSlot.MAIN_HAND)); + return castAbility(player, abilityName, modifiers, target, attackMeta); + } + + /** + * Forces a player to cast an ability + * + * @param player Player casting the ability + * @param abilityName Ability name. The ability is found using {@link #getAbilityById(String)} + * @param modifiers Ability modifiers + * @param target The ability target (null if no target) + * @param attackMeta If the trigger type is ATTACK, the corresponding AttackMetadata is provided. This allows + * MMOItems to increase the damage of the current attack or even add new damage packets. + * This parameter is useless for trigger types like RIGHT_CLICK or SNEAK which aren't + * based on entity attacks; in that case the attackMeta will have an empty DamageMetadata + */ + public AttackMetadata castAbility(Player player, String abilityName, Map modifiers, @NotNull LivingEntity target, AttackMetadata attackMeta) { + + // Setup ability + AbilityData abilityData = new AbilityData(getAbilityById(abilityName), TriggerType.RIGHT_CLICK); + modifiers.forEach((key, value) -> abilityData.setModifier(key, value)); + + // Cast ability + return castAbility(PlayerData.get(player), abilityData, target, attackMeta); + } + + /** + * Forces a player to cast an ability + * + * @param playerData The player data from the player casting the spell + * @param ability Ability with modifiers + * @param target The ability target (null if no target) + * @param attackMeta If the trigger type is ATTACK, the corresponding AttackMetadata is provided. This allows + * MMOItems to increase the damage of the current attack or even add new damage packets. + * This parameter is useless for trigger types like RIGHT_CLICK or SNEAK which aren't + * based on entity attacks; in that case the attackMeta will have an empty DamageMetadata + */ + public AttackMetadata castAbility(PlayerData playerData, AbilityData ability, @NotNull LivingEntity target, AttackMetadata attackMeta) { + playerData.cast(attackMeta, target, ability); + return attackMeta; + } }