Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a condition for is divisible by #7104

Open
wants to merge 23 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/main/java/ch/njol/skript/conditions/CondIsDivisibleBy.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
@Name("Divisible By")
@Description("Check if a number is divisible by another number.")
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
@Examples("5 is divisible by 5")
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
@Since("INSERT VERSION")
public class CondIsDivisibleBy extends Condition {

static {
Skript.registerCondition(CondIsDivisibleBy.class,
"%number% is divisible by %number%",
"%number% can be divisible by %number%");
"%number% (is|can be) (divisible|divided) by %number%");
}

@SuppressWarnings("null")
Expand Down Expand Up @@ -48,7 +55,7 @@ public boolean check(Event event) {

@Override
public String toString(@Nullable Event event, boolean debug) {
return "is divisible by " + num1.toString(event, debug) + num2.toString(event, debug);
return num1.toString(event, debug) + " is divisible by " + num2.toString(event, debug);
}

}
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test "is divisible":
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
assert 5 can be divided by 5 with "5 can be divided by 5!"
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
assert 5 can be divided by 10 to fail with "5 cannot be divided by 10!"
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved