Andre601
e11cc30d39

2 weeks ago  

.gitea  3 months ago  
src/main/java/ch/andre601/mathexpansion  2 weeks ago  
.gitignore  1 year ago  
CHANGELOG.md  9 months ago  
LICENSE  4 years ago  
README.md  6 months ago  
build.gradle  2 weeks ago  
gradlew  1 year ago  
gradlew.bat  1 year ago  
settings.gradle  1 year ago 
README.md
MathExpansion
Note
Versions 1.2.7 and newer require Java 11 or higher to work!
This is due to some required dependencies needing it.
The MathExpansion is an Expansion for PlaceholderAPI which allows you to do mathexpressions.
Supported are all expression supported by EvalEx, which this Expansion uses. See the examples below for some features.
Syntax
The expansion has two specific Placeholder patterns to use.
%math_<expression>%
Used for normal calculations while using the default decimal count and rounding behaviour
%math_[decimals]:[rounding]_<expression>%
Used for calculations using your own decimal count and rounding behaviour.
Either value is optional and not providing one uses the default values set in the Config.
Features
Normal Math expressions
MathExpansion supports all common math expressions such as 1+2
, 34
, 5*6
or 7/8
Those expressions can be used asis without any real problem. Just keep in mind that expressions follow common logic which is that multiplication and division come before addition and substraction.
If you want specific expressions to be done first, even tho logic would prioritize others can you put them into brackets (i.e. (1+2)*3
would result in 1+2
being done first before multiplying by 3).
Placeholders in Math expressions
You can use any placeholders from PlaceholderAPI that return valid numbers.
When using placeholders will you need to use the curly brackets format ({some_placeholder}
) rather than the percent placeholders.
As an example can you use {server_online}
in your expressions to use the amount of online players in your server.
Using percent symbol
Due to how PlaceholderAPI handles placeholders can you not use the percent symbol (%
) inside math expressions, as PlaceholderAPI would assume this to be the end of a placeholder.
To bypass this limitation does the MathExpansion add a [prc]
placeholder that you can use. This text will be replaced with an actual percent symbol before doing calculations.
Warning
The[prc]
can NOT be used for placeholders in PlaceholderAPI. See the Previous section for more info.
Special expressions
Certain expressions cannot be reproduced with letters in the MathExpansion. For example can \sqrt{100*10}
not be used as shown.
Because of this does EvalEx, the library used by MathExpansion, provide specific custom patterns that allow to do these kinds of special calculations.
To f.e. do the above expression would you use SQRT(100*10)
as the expression, which would now get the square root of 100*10
.
EvalEx offers a lot of different formats you can use, so check out their readme for more information.
Note: Those patterns are caseinsensitive.
Set amount of shown decimals
Sometimes an expression can return a relatively large number such as 3.333333...
.
The MathExpansion does by default only show the first three decimals of a number, turning the above shown one into 3.333
.
If you want to lower or increase the amount of decimals without altering the config option can you set your own decimals count using the advanced placeholderpattern.
For example will %math_5:_8+1.234567%
set the amount of decimals to 5, resulting in the returned number looking like this: 9.23457
Note
The final number depends on what rounding behaviour has been set.
Set rounding behaviour
By default, is the MathExpression using Half Up
as rounding behaviour, which means that numbers between 1 and 4 will be rounded down while numbers 5 to 9 will be rounded up.
If you would like to use a different rounding behaviour while not altering the config option can you provide a valid rounding behaviour in the advanced placeholderpattern like this: %math_:ceiling_8+1.2222%
The above shown expression would  assuming a default decimals count of 3 is used  result in 9.223
even tho by normal standards would it be 9.222
.
You may find more detailed explanations and examples of this option on the wiki.
Config options
The expansion adds a few specific settings to the config.yml of PlaceholderAPI, which can be changed if desired.
Debug
The Debug option enables or disables the expansion's debug mode.
With debug enabled will warnings also print an exception, if the warning is a result of an exception.
This is mostly useful for support and could increase the size of your server log files.
Decimals
Sets the amount of decimal points (digits after the dot) should be shown by default in the final number.
The default value  which is also used whenever an invalid value has been set in the config  is 3
meaning a number such as 123.456789
will be displayed as 123.457
.
Keep in mind that the actual number also depends on what rounding behaviour is used.
If the number is lower than 0 will it default to 0.
Rounding
The default rounding behaviour to use.
When the number returns more decimals than what should be displayed will it get rounded to the set decimal count.
Example: 5.684
with half up
as rounding (Default) and a decimal count set to 2 returns 5.68
while a decimal count of 1 returns 6.7
.
The default rounding is halfup
which means that any number greater or equal to 5 is rounded up and anything below is rounded down.
Take a look at the wiki for a list of supported options.
Credits
Mathexpansion uses EvalEx for evaluating the mathexpressions.
Check the repository for available mathexpressions.
Changelog
Take a look at the CHANGELOG.md for all versions and their changes.