Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
- RGB pattern now don't require a space after the commas
- renamed couple variables
- added a fail shortcut for dying blocks with RGB
- Removed color-color comparator as it's not the proper fix, it should be fixed in CondCompare
  • Loading branch information
AyhamAl-Ali committed Apr 8, 2024
1 parent fbd6b62 commit e66ad6f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
13 changes: 0 additions & 13 deletions src/main/java/ch/njol/skript/classes/data/DefaultComparators.java
Original file line number Diff line number Diff line change
Expand Up @@ -654,19 +654,6 @@ public boolean supportsOrdering() {
return false;
}
});

// Color - Color
Comparators.registerComparator(Color.class, Color.class, new Comparator<Color, Color>() {
@Override
public Relation compare(Color color1, Color color2) {
return Relation.get(color1.getName().equals(color2.getName()));
}

@Override
public boolean supportsOrdering() {
return false;
}
});
}

}
1 change: 1 addition & 0 deletions src/main/java/ch/njol/skript/expressions/ExprColorOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ 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: 16 additions & 9 deletions src/main/java/ch/njol/skript/expressions/ExprDyed.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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 @@ -42,11 +43,12 @@
import java.util.regex.Matcher;

@Name("Dyed")
@Description("An expression to return items/entities with a color.")
@Description("An expression to return colored items.")
@Examples({
"give player leather chestplate dyed red",
"give player potion of invisibility dyed rgb 200, 70, 88",
"give player filled map with color rgb(20, 60, 70)"
"give player filled map colored rgb(20, 60, 70)",
"give player wool painted red"
})
@Since("INSERT VERSION")
public class ExprDyed extends SimpleExpression<ItemType> {
Expand All @@ -56,8 +58,10 @@ 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 @@ -75,17 +79,17 @@ protected ItemType[] get(Event event) {
if (color == null)
return new ItemType[0];

ItemType[] targets = this.items.getArray(event);
ItemType[] items = this.items.getArray(event);
org.bukkit.Color bukkitColor;
bukkitColor = color.asBukkitColor();

for (ItemType item : targets) {
for (ItemType item : items) {
ItemMeta meta = item.getItemMeta();

if (meta instanceof LeatherArmorMeta) {
LeatherArmorMeta m = (LeatherArmorMeta) meta;
m.setColor(bukkitColor);
item.setItemMeta(m);
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) meta;
leatherArmorMeta.setColor(bukkitColor);
item.setItemMeta(leatherArmorMeta);
} else if (meta instanceof MapMeta && MAPS_AND_POTIONS_COLORS) {
MapMeta mapMeta = (MapMeta) meta;
mapMeta.setColor(bukkitColor);
Expand All @@ -95,6 +99,9 @@ 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 @@ -105,7 +112,7 @@ protected ItemType[] get(Event event) {
} catch (IllegalArgumentException ignored) {}
}
}
return targets;
return items;
}

@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 e66ad6f

Please sign in to comment.