Conditions - amnoah/BetterScoreboard GitHub Wiki
What is a Condition?
A condition is a way to perform a certain task given that a placeholder gives a certain value.
This can be used to make placeholders user-friendly (like displayed Nether
when the output of %world%
is actually world_nether
) or to make lines on the scoreboard hide/display in given scenarios.
Writing Conditions
Creating Conditional Placeholders
A conditional placeholder is a placeholder that will display one set of text if the criteria attached to it evaluates as true or a different set of text if it evaluates to false. Conditional placeholders can specify multiple criteria and can reference other conditional placeholders, allowing for in-depth evaluation to display certain text.
Registering
To create a new Conditional Placeholder, we need to add it as a node in the conditions.yml file.
Conditional Placeholder Example
Example of how to create a new condition:
newcondition:
Essential Conditional Placeholder Options
Next, we have to add the following to the condition:
mode
This determines how the scoreboard will deal with the criteria. Currently there are two mode options, "AND" and "OR".
If the mode is set to "AND", all criteria must be true for the true message to be returned by the condition. If the mode is set to "OR", only one criteria must be true for the true message to be returned by the condition.
If no mode is specified, it will be assumed to be in "AND" mode.
yes-result
This is the message that should be displayed by the placeholder if it is determined that the player meets the criteria. This can include placeholders and color codes.
You can reference other conditional placeholders in here too!
no-result
This is the message that should be displayed by the placeholder if it is determined that the player does not meet the criteria. This can include placeholders and color codes.
You can reference other conditional placeholders in here too!
criteria
This is a list of strings that should be used to determine whether the player qualifies for this condition. It should be composed of three parts: leftPlaceholder conditionCheck rightText
The left placeholder should be a placeholder.
For more information on condition checks, please check here.
The right text can include placeholders, static text, or be completely empty.
Alternatively, if you would like to check for a permission you could just write permission:node
in the criteria (replacing node with your specific node).
Essential Condition Options Example
newcondition:
mode: OR
yes-result: "&aYou are not in the overworld!"
no-result: "&aYou are in the overworld!"
criteria:
- "%world% -| nether"
- "%world% -| end"
Creating Conditional Lines
A conditional line is a line that will only display if given criteria evaluates to true. If it evaluates to false and the other side also evaluates to false (or doesn't exist) the line will not display on the board at all.
To create a conditional line, simply add the node for criteria underneath your left-aligned/right-aligned node. You can also include the mode, but it will be automatically assumed to be AND
if not specified.
Conditional Line Example
left-aligned:
speed: -1
text:
- "This will always display!"
right-aligned:
mode: OR
criteria:
- "%world% -| nether"
speed: -1
text:
- "This will only display in the nether!"
Condition Checks
These are comparators that can be used inside of a criteria to check whether it is true or false. Here are the current condition checks:
Numeric Operations
These require the placeholders on both side of the condition check to be number values. They will be parsed as doubles.
>
Returns true if the left value is larger than the right value.
>=
Returns true if the left value is larger than or equal to the right value.
<
Returns true if the left value is smaller than the right value.
<=
Returns true if the left value is smaller than or equal to the right value.
String Operations
=
Returns true if both pieces of text are the same (ignoring case).
==
Returns true if both pieces of text are the same (considering case).
!=
Returns true if the pieces of text are different (ignoring case).
!==
Returns true if the pieces of text are different (considering case).
|-
Returns true if the left text starts with the right text (ignoring case).
||-
Returns true if the left text starts with the right text (considering case).
-|
Returns true if the left text ends with the right text (ignoring case).
-||
Returns true if the left text ends with the right text (considering case).
$
Returns true if the left text contains the right text (ignoring case).
$$
Returns true if the left text contains the right text (considering case).
Using Condition Placeholders
To use a condition placeholders, input %condition:name%
with name replaced by your condition's name.
We could use the condition shown earlier by using %condition:newcondition%
.