Expression - TheComputerGeek2/MagicSpells GitHub Wiki

Description:

An expression is a syntax that evaluates to a final value when executed. Some examples of this are:

  • Messages with placeholders that are replaced with different values before being used. (e.g. "%a casted a spell", "Health: %var:meta_current_health:0%", etc.)
  • Variable Modification being triggered, where the value is stored back in the same variable.
  • SlimeSizeSpell spell, where the expression evaluated uses the slime's original size to apply the evaluated value to its size.

Placeholders:

Here's a list of MS placeholders:

  • For documentation, required parameters are in <>, optional are in [].
  • PAPI placeholders can be resolved by non-player entities - the expansion does its own logic for such cases.
  • Variable placeholders do not work for non-player entities unless the variable is of a global type.
  • You cannot put MS placeholders inside each other (e.g. %var:%arg:1:0%:0%). One must end before another is specified. You can however put PAPI's inner placeholders inside each other (e.g. %a_{b_{c}}%). MS has a PAPI Expansion with which you can do something like: str-cast-self: %papi:ms_cooldown_now_{ms_selectedspell},0% seconds left
Format Description
%var:<varName>:[precision]% Return the recipient's variable value. precision defines decimal places.
%castervar:<varName>:[precision]% Same as above, but for the caster.
%targetvar:<varName>:[precision]% Same as above, but for the target.
%playervar:<player>:<varName>:[precision]% player can be the username of a player.
%arg:<index>:<default>% Returns the spell's cast argument value. index starts at 1. Spell arguments are passed from subspell to subspell, created either with the cast command (e.g. /c spellName arg1 arg2 ...) or (since 4.0 Beta 13) with the args sub-spell cast argument.
%papi:<placeholder>% Since 4.0 Beta 13. For PlaceholderAPI placeholders (list). Returns the placeholder's value parsed against the recipient. Supports inner PAPI placeholders with {} (e.g. %papi:animations_<appear>{player_name}</appear>%).
%casterpapi:<placeholder>% Since 4.0 Beta 13. Same as above, but for the caster.
%targetpapi:<placeholder>% Since 4.0 Beta 13. Same as above, but for the target.
%playerpapi:<player>:<placeholder>% player can be a player's username.

String:

Entity Name:

  • If the entity is a player, this will return their username.
  • Since 4.0 Beta 14 if it's a non-player, it will return the entity's custom name first.
  • If they don't have a custom name, it will return their configured name from entity-names in general.yml.
  • If they don't have a configured name, it will return their custom or vanilla entity names (e.g., Zombie).

Recipient:

Usually, the caster is also the recipient. In Buff spells, the recipient is the true target of the spell. Some spell effects, like the Toast effect, have an option called use-viewer-as-default which defines if the recipient should be the effect's viewer.


Formatted Text:

  • Formatted Text is normal string text which adds the MiniMessage format with which you can add colors to your text (hex too), hover text, click actions, and some other features.
  • You can also color text with legacy color codes Minecraft uses, or Spigot's where the code starts with & instead of §. You can specify legacy hex colors (e.g. #c0ffee) by using &x&c&0&f&f&e&e or &#c0ffee (but in MiniMessage that would look like <color:#c0ffee>Text</color:#c0ffee>).

Rich Text:

Rich Text extends string expressions by adding Formatted Text to them. An example of Rich Text is: str-cast-self: "<aqua>Health<white>: <red>%var:meta_current_health:0%<black>/</black>%var:meta_current_health:0%</red>"

Rich Text


Function:

Warning

This is only possible since 4.0 Beta 13. It has to be an unchanging "constant" value in older versions.

Function expression evaluates into one numeric output. They support placeholder value replacement. Note: we use exp4j for this. An additional power placeholder is possible to use in these expressions, which refers to spell power (e.g. damage: "4 * power").

Operators:

Name Example
Addition 2 + 2
Subtraction 2 - 2
Multiplication 2 * 2
Division 2 / 2
Exponents 2 ^ 2
Unary Minus & Plus (Sign Operators) +2 - (-2)
Modulo (remainder of division) 2 % 2

Math Functions:

Name Function
Absolute value abs
Arc cosine acos
Arc sine asin
Arc tangent atan
Cubic root cbrt
Nearest upper integer ceil
Cosine cos
Hyperbolic cosine cosh
Euler's number raised to the power (e^x) exp
Nearest lower integer floor
Logarithmus naturalis (base e) log
Logarithm (base 10) log10
Logarithm (base 2) log2
Sine sin
Hyperbolic sine sinh
Square root sqrt
Tangent tan
Hyperbolic tangent tanh
Signum function signum

Extra Functions:

Function Description
rand(x,y) Generate a random number from x to y.
prob(p,x,y) A random (p%) chance to return x, else return y.
min(x,y) Return the minimum of x or y.
max(x,y) Return the maximum of x or y.
select(v,x,y,z) If v < 0, return x, if v = 0 return y, if v > 0 return z.

Testing:

If it isn't clear if an option has support for expressions instead of constant values, use a placeholder or a function with a predictable value that differs from its default value (e.g. 1+1 for functions, "%arg:10:x%" for strings - default value x is used since 10th arg wasn't supplied).

⚠️ **GitHub.com Fallback** ⚠️