|
| 1 | +package fr.jamailun.ultimatespellsystem.api.spells; |
| 2 | + |
| 3 | +import fr.jamailun.ultimatespellsystem.api.entities.SpellEntity; |
| 4 | +import fr.jamailun.ultimatespellsystem.api.runner.RuntimeExpression; |
| 5 | +import fr.jamailun.ultimatespellsystem.api.runner.RuntimeStatement; |
| 6 | +import fr.jamailun.ultimatespellsystem.api.runner.SpellRuntime; |
| 7 | +import fr.jamailun.ultimatespellsystem.dsl.nodes.ExpressionNode; |
| 8 | +import fr.jamailun.ultimatespellsystem.dsl.nodes.StatementNode; |
| 9 | +import org.bukkit.entity.LivingEntity; |
| 10 | +import org.jetbrains.annotations.Contract; |
| 11 | +import org.jetbrains.annotations.NotNull; |
| 12 | +import org.jetbrains.annotations.Nullable; |
| 13 | +import org.jetbrains.annotations.UnmodifiableView; |
| 14 | + |
| 15 | +import java.util.List; |
| 16 | + |
| 17 | +/** |
| 18 | + * This allows for external APIs to evaluate expressions. |
| 19 | + */ |
| 20 | +public interface ExternalExecutor { |
| 21 | + |
| 22 | + /** |
| 23 | + * Create a new spell runtime instance. |
| 24 | + * @param caster spell entity to consider as "caster". |
| 25 | + * @return a new spell runtime. |
| 26 | + */ |
| 27 | + @Contract("_ -> new") |
| 28 | + @NotNull SpellRuntime generateRuntime(@NotNull SpellEntity caster); |
| 29 | + |
| 30 | + /** |
| 31 | + * Create a new spell runtime instance. |
| 32 | + * @param caster bukkit entity to consider as "caster". |
| 33 | + * @return a new spell runtime. |
| 34 | + */ |
| 35 | + @Contract("_ -> new") |
| 36 | + @NotNull SpellRuntime generateRuntime(@NotNull LivingEntity caster); |
| 37 | + |
| 38 | + /** |
| 39 | + * Evaluate an expression. |
| 40 | + * @param expression expression to evaluate |
| 41 | + * @param caster the spell-entity caster. |
| 42 | + * @return expression output. |
| 43 | + */ |
| 44 | + default @Nullable Object evaluateExpression(@NotNull RuntimeExpression expression, @NotNull SpellEntity caster) { |
| 45 | + return expression.evaluate( generateRuntime(caster) ); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Evaluate an expression. |
| 50 | + * @param expression expression to evaluate |
| 51 | + * @param caster the Bukkit caster. |
| 52 | + * @return expression output. |
| 53 | + */ |
| 54 | + default @Nullable Object evaluateExpression(@NotNull RuntimeExpression expression, @NotNull LivingEntity caster) { |
| 55 | + return expression.evaluate( generateRuntime(caster) ); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Implement DSL into a runnable statement. |
| 60 | + * @param dsl DSL to implement. |
| 61 | + * @return a new unmodifiable list of runnable statements. |
| 62 | + * @throws fr.jamailun.ultimatespellsystem.dsl.errors.UssException in case of issue. |
| 63 | + */ |
| 64 | + @NotNull @UnmodifiableView |
| 65 | + List<RuntimeStatement> handleImplementation(@NotNull List<StatementNode> dsl); |
| 66 | + |
| 67 | + /** |
| 68 | + * Implement DSL into a runnable expression. |
| 69 | + * @param dsl DSL to implement. |
| 70 | + * @return a single DSL expression. |
| 71 | + * @throws fr.jamailun.ultimatespellsystem.dsl.errors.UssException in case of issue. |
| 72 | + */ |
| 73 | + @NotNull RuntimeExpression handleImplementation(@NotNull ExpressionNode dsl); |
| 74 | + |
| 75 | +} |
0 commit comments