Skip to content

Colours Are Cool 🌈 #7246

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

Open
wants to merge 45 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
401baaf
Still a WIP, implements some functions and expressions
cheeezburga Dec 7, 2024
bd64435
Adds blend expression
cheeezburga Dec 7, 2024
ae81c9e
Adds complement expression
cheeezburga Dec 7, 2024
d5985d6
Small change
cheeezburga Dec 7, 2024
fc342b8
Fixed invalid spelling of colour throwing a pattern exception
cheeezburga Dec 7, 2024
50e064c
Fixed invalid spelling of colour throwing a pattern exception
cheeezburga Dec 7, 2024
a1cadb7
Adds hex code expression
cheeezburga Dec 7, 2024
e2d9081
Adds channel as an option in ExprARGB's patterns
cheeezburga Dec 8, 2024
b50ed36
Fixes number logic and adds another pattern to ExprBlend
cheeezburga Dec 8, 2024
2427be4
Removes the <> being included in the hex code util method
cheeezburga Dec 8, 2024
d725215
Adds hex codes test
cheeezburga Dec 8, 2024
9875ffe
Adds colour blending test
cheeezburga Dec 8, 2024
67320f9
Adds colour complements test
cheeezburga Dec 8, 2024
3123bdb
Fixes tests
cheeezburga Dec 8, 2024
34d2024
Adds function tests (shade, tint, brightness, grayscale, sepiatone)
cheeezburga Dec 8, 2024
d07ce14
Fixes brightness test
cheeezburga Dec 8, 2024
c0e9cd7
Adds documentation to ColourUtils
cheeezburga Dec 8, 2024
e1f6364
Changes all 'colour's to 'color's and adds better descriptions and ex…
cheeezburga Dec 9, 2024
ed49cfd
Changes all 'colour's to 'color's and adds better descriptions and ex…
cheeezburga Dec 9, 2024
a8758b3
Moves hex conversion to Color class in lieu of static util method and…
cheeezburga Dec 9, 2024
99fb214
Adds some comments and changes variable names to not be just single c…
cheeezburga Dec 9, 2024
b6b4dee
Adds doc annotations to ExprHex
cheeezburga Dec 11, 2024
641fa49
Some small doc/pattern changes
cheeezburga Dec 11, 2024
7340a72
First attempt at serialization of colors
cheeezburga Dec 14, 2024
eab6820
Merge branch 'dev/feature' into cool-colours
Moderocky Dec 17, 2024
82418fc
Adds a 'hex to colour' method, and docs for it and fromInt
cheeezburga Dec 19, 2024
c83b09a
Merge branch 'dev/feature' into cool-colours
cheeezburga Dec 19, 2024
9e00d48
Merge remote-tracking branch 'origin/cool-colours' into cool-colours
cheeezburga Dec 19, 2024
68204ea
Uncomments the SSB in ExprBlend using updated append methods
cheeezburga Dec 19, 2024
ccdf611
Moves colour classinfo registration into module
cheeezburga Dec 19, 2024
c535d1a
Some of Pickle's requested changes
cheeezburga Dec 19, 2024
36c8dec
Some more of Pickle's requested changes
cheeezburga Dec 19, 2024
b39a6fb
Changes misc.colors package to common.colors
cheeezburga Dec 19, 2024
4594afe
Moves some stuff around and fixes registration order
cheeezburga Dec 23, 2024
0cb98a8
Merge branch 'dev/feature' into cool-colours
cheeezburga Dec 27, 2024
935df98
Merge branch 'dev/feature' into cool-colours
cheeezburga May 25, 2025
0456227
Implements ColorHSL and ColorHSB classes for clarity and extensibility
cheeezburga May 27, 2025
7a50aa0
Move syntax classes to a new elements package
cheeezburga May 29, 2025
1cc0d95
Fix incorrect spelling in brightness.sk test
cheeezburga May 29, 2025
eddd77d
Split a line for clarity
cheeezburga May 29, 2025
3bd10a6
Add deprecation parameters back in to SkriptColor
cheeezburga May 29, 2025
a809fb4
Move Color class registration back to SkriptClasses
cheeezburga May 29, 2025
61f1441
Fix tests
cheeezburga Jun 3, 2025
b67b094
Fix serialization JUnit test
cheeezburga Jun 3, 2025
89fe934
Merge branch 'dev/feature' into cool-colours
cheeezburga Jun 3, 2025
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
2 changes: 2 additions & 0 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import org.skriptlang.skript.lang.script.Script;
import org.skriptlang.skript.lang.structure.Structure;
import org.skriptlang.skript.lang.structure.StructureInfo;
import org.skriptlang.skript.common.colors.ColorModule;
import org.skriptlang.skript.log.runtime.RuntimeErrorManager;
import org.skriptlang.skript.registration.SyntaxInfo;
import org.skriptlang.skript.registration.SyntaxOrigin;
Expand Down Expand Up @@ -557,6 +558,7 @@ public void onEnable() {
BreedingModule.load();
DisplayModule.load();
InputModule.load();
ColorModule.load();
TagModule.load();
FurnaceModule.load();
LootTableModule.load();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ch.njol.skript.lang.util.SimpleLiteral;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.registrations.DefaultClasses;
import ch.njol.skript.util.Contract;
import ch.njol.skript.util.Date;
import ch.njol.skript.util.*;
import ch.njol.util.Math2;
Expand Down Expand Up @@ -503,29 +504,6 @@ public Long[] executeSimple(Object[][] params) {
}.description("Calculates the total amount of experience needed to achieve given level from scratch in Minecraft.")
.since("2.2-dev32"));

Functions.registerFunction(new SimpleJavaFunction<Color>("rgb", new Parameter[] {
new Parameter<>("red", DefaultClasses.LONG, true, null),
new Parameter<>("green", DefaultClasses.LONG, true, null),
new Parameter<>("blue", DefaultClasses.LONG, true, null),
new Parameter<>("alpha", DefaultClasses.LONG, true, new SimpleLiteral<>(255L,true))
}, DefaultClasses.COLOR, true) {
@Override
public ColorRGB[] executeSimple(Object[][] params) {
Long red = (Long) params[0][0];
Long green = (Long) params[1][0];
Long blue = (Long) params[2][0];
Long alpha = (Long) params[3][0];

return CollectionUtils.array(ColorRGB.fromRGBA(red.intValue(), green.intValue(), blue.intValue(), alpha.intValue()));
}
}).description("Returns a RGB color from the given red, green and blue parameters. Alpha values can be added optionally, " +
"but these only take affect in certain situations, like text display backgrounds.")
.examples(
"dye player's leggings rgb(120, 30, 45)",
"set the colour of a text display to rgb(10, 50, 100, 50)"
)
.since("2.5, 2.10 (alpha)");

Functions.registerFunction(new SimpleJavaFunction<Player>("player", new Parameter[] {
new Parameter<>("nameOrUUID", DefaultClasses.STRING, true, null),
new Parameter<>("getExactPlayer", DefaultClasses.BOOLEAN, true, new SimpleLiteral<Boolean>(false, true)) // getExactPlayer -- grammar ¯\_ (ツ)_/¯
Expand Down
59 changes: 23 additions & 36 deletions src/main/java/ch/njol/skript/classes/data/SkriptClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.common.colors.ColorUtils;
import org.skriptlang.skript.lang.script.Script;
import org.skriptlang.skript.lang.util.SkriptQueue;
import org.skriptlang.skript.util.Executable;
Expand Down Expand Up @@ -65,8 +66,7 @@ public SkriptClasses() {}
.supplier(() -> (Iterator) Classes.getClassInfos().iterator())
.parser(new Parser<ClassInfo>() {
@Override
@Nullable
public ClassInfo parse(final String s, final ParseContext context) {
public @Nullable ClassInfo parse(final String s, final ParseContext context) {
return Classes.getClassInfoFromUserInput(Noun.stripIndefiniteArticle(s));
}

Expand Down Expand Up @@ -114,11 +114,9 @@ protected ClassInfo deserialize(final Fields fields) throws StreamCorruptedExcep
throw new StreamCorruptedException("Invalid ClassInfo " + codeName);
return ci;
}

// return c.getCodeName();

@Override
@Nullable
public ClassInfo deserialize(final String s) {
public @Nullable ClassInfo deserialize(final String s) {
return Classes.getClassInfoNoError(s);
}

Expand All @@ -140,8 +138,7 @@ public boolean mustSyncDeserialization() {
.defaultExpression(new SimpleLiteral<>(WeatherType.CLEAR, true))
.parser(new Parser<WeatherType>() {
@Override
@Nullable
public WeatherType parse(final String s, final ParseContext context) {
public @Nullable WeatherType parse(final String s, final ParseContext context) {
return WeatherType.parse(s);
}

Expand All @@ -152,7 +149,7 @@ public String toString(final WeatherType o, final int flags) {

@Override
public String toVariableNameString(final WeatherType o) {
return "" + o.name().toLowerCase(Locale.ENGLISH);
return o.name().toLowerCase(Locale.ENGLISH);
}

})
Expand All @@ -178,8 +175,7 @@ public String toVariableNameString(final WeatherType o) {
.iterator())
.parser(new Parser<ItemType>() {
@Override
@Nullable
public ItemType parse(final String s, final ParseContext context) {
public @Nullable ItemType parse(final String s, final ParseContext context) {
return Aliases.parseItemType(s);
}

Expand Down Expand Up @@ -213,7 +209,7 @@ public String toVariableNameString(final ItemType t) {
b.append(":" + ench.getLevel());
}
}
return "" + b.toString();
return b.toString();
}
})
.cloner(ItemType::clone)
Expand All @@ -233,8 +229,7 @@ public String toVariableNameString(final ItemType t) {
.defaultExpression(new EventValueExpression<>(Time.class))
.parser(new Parser<Time>() {
@Override
@Nullable
public Time parse(final String s, final ParseContext context) {
public @Nullable Time parse(final String s, final ParseContext context) {
return Time.parse(s);
}

Expand Down Expand Up @@ -266,8 +261,7 @@ public String toVariableNameString(final Time o) {
.since("1.0, 2.6.1 (weeks, months, years)")
.parser(new Parser<Timespan>() {
@Override
@Nullable
public Timespan parse(final String s, final ParseContext context) {
public @Nullable Timespan parse(final String s, final ParseContext context) {
try {
return Timespan.parse(s, context);
} catch (IllegalArgumentException e) {
Expand Down Expand Up @@ -301,8 +295,7 @@ public String toVariableNameString(final Timespan o) {
.defaultExpression(new SimpleLiteral<>(new Timeperiod(0, 23999), true))
.parser(new Parser<Timeperiod>() {
@Override
@Nullable
public Timeperiod parse(final String s, final ParseContext context) {
public @Nullable Timeperiod parse(final String s, final ParseContext context) {
if (s.equalsIgnoreCase("day")) {
return new Timeperiod(0, 11999);
} else if (s.equalsIgnoreCase("dusk")) {
Expand Down Expand Up @@ -398,8 +391,7 @@ protected boolean canBeInstantiated() {
.defaultExpression(new SimpleLiteral<>(new Direction(new double[] {0, 0, 0}), true))
.parser(new Parser<Direction>() {
@Override
@Nullable
public Direction parse(final String s, final ParseContext context) {
public @Nullable Direction parse(final String s, final ParseContext context) {
return null;
}

Expand Down Expand Up @@ -437,10 +429,9 @@ public String toVariableNameString(final Direction o) {
.since("")
.defaultExpression(new EventValueExpression<>(Slot.class))
.changer(new Changer<Slot>() {
@SuppressWarnings("unchecked")
@Override
@Nullable
public Class<Object>[] acceptChange(final ChangeMode mode) {
@SuppressWarnings("unchecked")
public @Nullable Class<Object>[] acceptChange(final ChangeMode mode) {
if (mode == ChangeMode.RESET)
return null;
if (mode == ChangeMode.SET)
Expand Down Expand Up @@ -543,14 +534,13 @@ public String toVariableNameString(Slot o) {
.description("Wool, dye and chat colors.")
.usage("black, dark grey/dark gray, grey/light grey/gray/light gray/silver, white, blue/dark blue, cyan/aqua/dark cyan/dark aqua, light blue/light cyan/light aqua, green/dark green, light green/lime/lime green, yellow/light yellow, orange/gold/dark yellow, red/dark red, pink/light red, purple/dark purple, magenta/light purple, brown/indigo")
.examples("color of the sheep is red or black",
"set the color of the block to green",
"message \"You're holding a <%color of tool%>%color of tool%<reset> wool block\"")
"set the color of the block to green",
"message \"You're holding a <%color of tool%>%color of tool%<reset> wool block\"")
.since("")
.supplier(SkriptColor.values())
.parser(new Parser<Color>() {
@Override
@Nullable
public Color parse(String input, ParseContext context) {
public @Nullable Color parse(String input, ParseContext context) {
Color rgbColor = ColorRGB.fromString(input);
if (rgbColor != null)
return rgbColor;
Expand All @@ -564,7 +554,7 @@ public String toString(Color c, int flags) {

@Override
public String toVariableNameString(Color color) {
return "" + color.getName().toLowerCase(Locale.ENGLISH).replace('_', ' ');
return color.getName().toLowerCase(Locale.ENGLISH).replace('_', ' ');
}
}));

Expand All @@ -579,8 +569,7 @@ public String toVariableNameString(Color color) {
.defaultExpression(new SimpleLiteral<>(StructureType.TREE, true))
.parser(new Parser<StructureType>() {
@Override
@Nullable
public StructureType parse(final String s, final ParseContext context) {
public @Nullable StructureType parse(final String s, final ParseContext context) {
return StructureType.fromName(s);
}

Expand All @@ -591,7 +580,7 @@ public String toString(final StructureType o, final int flags) {

@Override
public String toVariableNameString(final StructureType o) {
return "" + o.name().toLowerCase(Locale.ENGLISH);
return o.name().toLowerCase(Locale.ENGLISH);
}
}).serializer(new EnumSerializer<>(StructureType.class)));

Expand Down Expand Up @@ -634,8 +623,7 @@ public String toVariableNameString(final EnchantmentType o) {
private final RegexMessage pattern = new RegexMessage("types.experience.pattern", Pattern.CASE_INSENSITIVE);

@Override
@Nullable
public Experience parse(String s, final ParseContext context) {
public @Nullable Experience parse(String s, final ParseContext context) {
int xp = -1;
if (s.matches("\\d+ .+")) {
xp = Utils.parseInt("" + s.substring(0, s.indexOf(' ')));
Expand Down Expand Up @@ -670,8 +658,7 @@ public String toVariableNameString(final Experience xp) {
.after("itemtype")
.parser(new Parser<VisualEffect>() {
@Override
@Nullable
public VisualEffect parse(String s, ParseContext context) {
public @Nullable VisualEffect parse(String s, ParseContext context) {
return VisualEffects.parse(s);
}

Expand All @@ -695,7 +682,7 @@ public String toVariableNameString(VisualEffect e) {
.usage("")
.examples("")
.since("2.5")
.serializer(new YggdrasilSerializer<GameruleValue>())
.serializer(new YggdrasilSerializer<>())
);

Classes.registerClass(new ClassInfo<>(SkriptQueue.class, "queue")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/expressions/ExprARGB.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class ExprARGB extends SimplePropertyExpression<Color, Integer> {

static {
register(ExprARGB.class, Integer.class, "(:alpha|:red|:green|:blue) (value|component)", "colors");
register(ExprARGB.class, Integer.class, "(:alpha|:red|:green|:blue) (value|component|channel)", "colors");
}

private RGB color;
Expand Down
35 changes: 27 additions & 8 deletions src/main/java/ch/njol/skript/util/Color.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,53 @@
package ch.njol.skript.util;

import ch.njol.yggdrasil.YggdrasilSerializable.YggdrasilExtendedSerializable;
import org.bukkit.DyeColor;
import org.jetbrains.annotations.Nullable;

public interface Color extends YggdrasilExtendedSerializable {
public interface Color {

/**
* Gets Bukkit color representing this color.
* @return Bukkit color.
* @return The Bukkit color representing this color.
*/
org.bukkit.Color asBukkitColor();

/**
* @return The alpha component of this color.
* @return The hexadecimal code representing this color. Can be used to color text.
*/
default String getHex() {
return String.format("#%02X%02X%02X", getRed(), getGreen(), getBlue());
}

/**
* @return The hexadecimal code representing this color, including the alpha channel. Cannot be used to color text.
*/
default String getFullHex() {
return String.format("#%02X%02X%02X%02X", getAlpha(), getRed(), getGreen(), getBlue());
}

/**
* @return The integer representing this color.
*/
default int asInt() {
return (getAlpha() << 24) | (getRed() << 16) | (getGreen() << 8) | getBlue();
}

/**
* @return The alpha channel of this color.
*/
int getAlpha();

/**
* @return The red component of this color.
* @return The red channel of this color.
*/
int getRed();

/**
* @return The green component of this color.
* @return The green channel of this color.
*/
int getGreen();

/**
* @return The blue component of this color.
* @return The blue channel of this color.
*/
int getBlue();

Expand Down
Loading