Skip to content

Instantly share code, notes, and snippets.

@Snow-Pyon
Last active March 10, 2018 05:41
Show Gist options
  • Save Snow-Pyon/b8419b73e90ceaad80bbe37987cb097f to your computer and use it in GitHub Desktop.
Save Snow-Pyon/b8419b73e90ceaad80bbe37987cb097f to your computer and use it in GitHub Desktop.
package me.iblitzkriegi.vixio.literals;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleLiteral;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import java.awt.Color;
public class LitHexColor extends SimpleLiteral<Color> {
static {
Skript.registerExpression(LitHexColor.class, Color.class, ExpressionType.SIMPLE, "<#.{1,6}>");
}
public LitHexColor(Color data) {
super(data, true);
}
private String color;
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
color = parseResult.regexes.get(0).group(0);
if (color.matches("#[a-fA-F0-9]{1,6}")) {
color = new LitHexColor(Color.decode(color));
return super.init();
}
Skript.error(color + " isn't a valid HEX color.");
return false;
}
@Override
public String toString(Event e, boolean debug) {
return "#" + color;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment