From eeee8b47e2dbec103fa219cc9f60d50b694cdf66 Mon Sep 17 00:00:00 2001 From: Ayham Al-Ali <20037329+AyhamAl-Ali@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:16:47 +0300 Subject: [PATCH] Revert last commit to not include color-color band aid fix --- .../njol/skript/expressions/ExprColorOf.java | 1 - .../ch/njol/skript/expressions/ExprDyed.java | 25 +++++++------------ .../java/ch/njol/skript/util/ColorRGB.java | 2 +- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprColorOf.java b/src/main/java/ch/njol/skript/expressions/ExprColorOf.java index f9294beab42..326aa3bccd1 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprColorOf.java +++ b/src/main/java/ch/njol/skript/expressions/ExprColorOf.java @@ -88,7 +88,6 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override protected Color[] get(Event event, Object[] source) { - // TODO FIX // this approach has couple issues, users can't use multiple types in source like // 'broadcast colors of ((trailing burst firework colored blue and red) and targeted block)' and second // this check doesn't work with variables as it's not converted yet diff --git a/src/main/java/ch/njol/skript/expressions/ExprDyed.java b/src/main/java/ch/njol/skript/expressions/ExprDyed.java index e81a93d35e9..7a2599e92b1 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprDyed.java +++ b/src/main/java/ch/njol/skript/expressions/ExprDyed.java @@ -29,7 +29,6 @@ import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.skript.util.Color; -import ch.njol.skript.util.ColorRGB; import ch.njol.util.Kleenean; import org.bukkit.Material; import org.bukkit.event.Event; @@ -43,12 +42,11 @@ import java.util.regex.Matcher; @Name("Dyed") -@Description("An expression to return colored items.") +@Description("An expression to return items/entities with a color.") @Examples({ "give player leather chestplate dyed red", "give player potion of invisibility dyed rgb 200, 70, 88", - "give player filled map colored rgb(20, 60, 70)", - "give player wool painted red" + "give player filled map with color rgb(20, 60, 70)" }) @Since("INSERT VERSION") public class ExprDyed extends SimpleExpression { @@ -58,10 +56,8 @@ public class ExprDyed extends SimpleExpression { static { Skript.registerExpression(ExprDyed.class, ItemType.class, ExpressionType.COMBINED, "%itemtypes% (dyed|painted|colo[u]red) %color%"); } - - @SuppressWarnings("NotNullFieldNotInitialized") + private Expression items; - @SuppressWarnings("NotNullFieldNotInitialized") private Expression color; @Override @@ -79,17 +75,17 @@ protected ItemType[] get(Event event) { if (color == null) return new ItemType[0]; - ItemType[] items = this.items.getArray(event); + ItemType[] targets = this.items.getArray(event); org.bukkit.Color bukkitColor; bukkitColor = color.asBukkitColor(); - for (ItemType item : items) { + for (ItemType item : targets) { ItemMeta meta = item.getItemMeta(); if (meta instanceof LeatherArmorMeta) { - LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) meta; - leatherArmorMeta.setColor(bukkitColor); - item.setItemMeta(leatherArmorMeta); + LeatherArmorMeta m = (LeatherArmorMeta) meta; + m.setColor(bukkitColor); + item.setItemMeta(m); } else if (meta instanceof MapMeta && MAPS_AND_POTIONS_COLORS) { MapMeta mapMeta = (MapMeta) meta; mapMeta.setColor(bukkitColor); @@ -99,9 +95,6 @@ protected ItemType[] get(Event event) { potionMeta.setColor(bukkitColor); item.setItemMeta(potionMeta); } else { - if (color instanceof ColorRGB) // currently blocks don't support RGB - continue; - Material material = item.getMaterial(); Matcher matcher = ExprColorOf.MATERIAL_COLORS_PATTERN.matcher(material.name()); if (!matcher.matches()) @@ -112,7 +105,7 @@ protected ItemType[] get(Event event) { } catch (IllegalArgumentException ignored) {} } } - return items; + return targets; } @Override diff --git a/src/main/java/ch/njol/skript/util/ColorRGB.java b/src/main/java/ch/njol/skript/util/ColorRGB.java index 978b2f9c643..0658c41d7b9 100644 --- a/src/main/java/ch/njol/skript/util/ColorRGB.java +++ b/src/main/java/ch/njol/skript/util/ColorRGB.java @@ -32,7 +32,7 @@ public class ColorRGB implements Color { - private static final Pattern RGB_PATTERN = Pattern.compile("(?>rgb|RGB) (\\d+), ?(\\d+), ?(\\d+)"); + private static final Pattern RGB_PATTERN = Pattern.compile("(?>rgb|RGB) (\\d+), (\\d+), (\\d+)"); private org.bukkit.Color bukkit; @Nullable