package com.w00tmast3r.skquery.elements.conditions;

import org.bukkit.event.Event;

import com.w00tmast3r.skquery.api.Description;
import com.w00tmast3r.skquery.api.Name;
import com.w00tmast3r.skquery.api.Patterns;

import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.conditions.base.PropertyCondition.PropertyType;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;

@Name("Is Prime")
@Description("Checks whether or not a number is prime.")
@Patterns({"%numbers% (is|are) [a] prime [number]", "%numbers% (isn't|is not|aren't|are not) [a] prime [number]"})
public class CondIsPrime extends Condition {

	private Expression<Number> numbers;

	@SuppressWarnings("unchecked")
	@Override
	public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
		numbers = (Expression<Number>) expressions[0];
		setNegated(matchedPattern == 1);
		return true;
	}

	@Override
	public boolean check(Event event) {
		return numbers.check(event, number -> isPrime(number.intValue()), isNegated());
	}

	@Override
	public String toString(Event event, boolean debug) {
		return PropertyCondition.toString(this, PropertyType.BE, event, debug, numbers, "prime");
	}

	public static boolean isPrime(int number) {
		if (number % 2 == 0)
			return false;
		for (int i = 3; i * i <= number; i += 2) {
			if (number % i == 0)
				return false;
		}
		return true;
	}

}

@@ -1375,16 +1375,52 @@
 mber) %7B%0A
+%09%09if (number == 1)%0A%09%09%09return false;%0A
 %09%09if (nu

Fix 1 displaying as a prime number