Skip to content

Commit

Permalink
Revert last commit to not include color-color band aid fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AyhamAl-Ali committed Apr 8, 2024
1 parent e66ad6f commit eeee8b4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/main/java/ch/njol/skript/expressions/ExprColorOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 9 additions & 16 deletions src/main/java/ch/njol/skript/expressions/ExprDyed.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ItemType> {
Expand All @@ -58,10 +56,8 @@ public class ExprDyed extends SimpleExpression<ItemType> {
static {
Skript.registerExpression(ExprDyed.class, ItemType.class, ExpressionType.COMBINED, "%itemtypes% (dyed|painted|colo[u]red) %color%");
}

@SuppressWarnings("NotNullFieldNotInitialized")

private Expression<ItemType> items;
@SuppressWarnings("NotNullFieldNotInitialized")
private Expression<Color> color;

@Override
Expand All @@ -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);
Expand All @@ -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())
Expand All @@ -112,7 +105,7 @@ protected ItemType[] get(Event event) {
} catch (IllegalArgumentException ignored) {}
}
}
return items;
return targets;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/util/ColorRGB.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eeee8b4

Please sign in to comment.