-
-
Notifications
You must be signed in to change notification settings - Fork 0
PLUGIN Expression Parser
Eisi05 edited this page May 2, 2026
·
1 revision
Create dynamic NPC behavior using mathematical expressions with variables, functions, and boolean logic. Use expressions in click actions, goal conditions, and variable calculations.
Expressions are evaluated in this order (highest to lowest):
-
Parentheses:
()- Grouping and function calls -
Functions:
sin(),cos(),sqrt(), etc. -
Power:
^- Exponentiation -
Unary Operators:
+,-(prefix),!(NOT) -
Multiplication/Division:
*,/ -
Addition/Subtraction:
+,- -
Comparisons:
==,!=,<,>,<=,>= -
Boolean AND:
&& -
Boolean OR:
||
123 // Integer
45.67 // Decimal
1.23e-4 // Scientific notation
-5.5 // Negative number
PI // 3.141592653589793...
E // 2.718281828459045...
-
sin(x)- Sine -
cos(x)- Cosine -
tan(x)- Tangent
-
sqrt(x)- Square root -
log(x)- Natural logarithm -
exp(x)- Exponential function
-
ceil(x)- Round up to nearest integer -
floor(x)- Round down to nearest integer -
round(x)- Round to nearest integer -
trunc(x)- Truncate decimal part -
abs(x)- Absolute value
-
&&- Logical AND -
||- Logical OR -
!- Logical NOT
-
==- Equal to -
!=- Not equal to -
<- Less than -
>- Greater than -
<=- Less than or equal to -
>=- Greater than or equal to
$varName // Auto-resolve scope (local → instance → global)
$global.varName // Explicit global variable
$instance.varName // Explicit instance variable
$local.varName // Explicit local variable
$self.varName // Self/player scoped variable
$loop.index // Loop-specific variable (only 'index' supported)
$self.rightClick // 1 if right-click, 0 otherwise
$self.right_click // Alternative syntax (snake_case)
$self.leftClick // 1 if left-click, 0 otherwise
$self.left_click // Alternative syntax (snake_case)
$self.sneaking // 1 if player is sneaking, 0 otherwise
$self.flying // 1 if player is flying, 0 otherwise
$self.op // 1 if player is operator, 0 otherwise
$loop.index // Current loop iteration index
Commands can be executed in two ways:
2 + (/count players) // Execute command, use result in calculation
sin(PI) + (/scoreboard players get @p score)
/count players // Returns command success count
/scoreboard players get @p score
Commands execute with maximum permissions (admin level). Failed commands return 0.
2 + 3 * 4 // 14
(10 - 5) * 2 // 10
15 / 3 // 5
2 ^ 8 // 256
sin(PI / 2) // 1.0
sqrt(16) + 4 // 8.0
log(E) // 1.0
ceil(3.7) // 4
floor(3.7) // 3
round(3.5) // 4
abs(-5) // 5
1 && 1 // 1 (true - both non-zero)
1 || 0 // 1 (true - first is non-zero)
!0 // 1 (true - negation of zero)
5 > 3 && 2 < 4 // 1 (true)
Boolean Values:
- True: Any non-zero value (typically 1)
- False: Zero (0)
- Comparison operators return 1.0 for true, 0.0 for false
- Logical operators treat non-zero as true, zero as false
5 == 5 // 1 (true)
5 != 3 // 1 (true)
10 > 5 // 1 (true)
3 <= 3 // 1 (true)
7 >= 8 // 0 (false)
$global.score + 1 // Global score + 1
$local.health * 0.5 // Half local health
$instance.cooldown - 1 // Decrease cooldown
2 + 3 * 4
$global.score + 1
sin(PI / 2) + cos(0)
2 + * 3 // Invalid operator sequence
$global.123var // Invalid variable name
sin( // Missing closing parenthesis
unknown_function(5) // Unknown function
| Error | Cause | Solution |
|---|---|---|
| Unexpected character | Invalid symbol in expression | Check for typos |
| Missing ')' | Unclosed parenthesis | Add closing parenthesis |
| Unknown function | Function not recognized | Use supported functions only |
| Invalid variable name | Name starts with number | Start with letter or _ |
| Division by zero | Dividing by 0 | Check values before division |
Error messages show the exact position with a visual pointer:
2 + * 3
^
Unexpected character at position 4
Combine multiple features for sophisticated logic:
// Health-based conditional damage
($entity.health < 10) * 5 + ($entity.health >= 10) * 2
// Distance-weighted scoring
(10 - $distance) * $self.rightClick
// Command-integrated calculations
(/scoreboard players get @p kills) * 100 + $global.bonus
// Boolean logic with variables
$self.op || ($global.level > 50 && $self.sneaking)
// Nested function calls
round(sqrt($distance) * 10) + abs($entity.health - 20)
Using Command Results:
// Check if players are online
(/execute if entity @p) * 1
// Get scoreboard values
(/scoreboard players get @p myScore)
// Conditional execution
(/execute if score @p myScore matches 10.. run say HighScore) * 1
When using $varName without a scope prefix, the parser searches:
- Local (player-specific) variables first
- Instance (NPC-specific) variables second
- Global (server-wide) variables last
Returns 0 if variable is not found in any scope.