Skip to content

Commit

Permalink
Address reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
AyhamAl-Ali committed Apr 9, 2024
1 parent e96f91d commit 8599e0c
Showing 1 changed file with 40 additions and 41 deletions.
81 changes: 40 additions & 41 deletions src/main/java/ch/njol/skript/expressions/ExprColorOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,17 @@ public Class<?>[] acceptChange(ChangeMode mode) {
if (FireworkEffect.class.isAssignableFrom(returnType))
return CollectionUtils.array(Color[].class);

switch (mode) { // items/blocks/entities don't accept these change modes
case ADD:
case REMOVE:
case REMOVE_ALL:
return null;
}

if (mode != ChangeMode.SET && !getExpr().isSingle())
return null;

return CollectionUtils.array(Color.class);
switch (mode) { // items/blocks/entities don't accept these change modes
case RESET:
case DELETE:
case SET:
return CollectionUtils.array(Color.class);
}

return null;
}

@Override
Expand All @@ -204,39 +204,37 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) {
if (stack == null)
continue;

if (!(obj instanceof Colorable)) {
org.bukkit.Color bukkitColor = (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) ? null : ((Color) delta[0]).asBukkitColor();
ItemMeta meta = stack.getItemMeta();
if (meta instanceof LeatherArmorMeta) {
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) meta;
leatherArmorMeta.setColor(bukkitColor);
stack.setItemMeta(leatherArmorMeta);
} else if (meta instanceof MapMeta && MAPS_AND_POTIONS_COLORS) {
MapMeta mapMeta = (MapMeta) meta;
mapMeta.setColor(bukkitColor);
stack.setItemMeta(mapMeta);
} else if (meta instanceof PotionMeta && MAPS_AND_POTIONS_COLORS) {
PotionMeta potionMeta = (PotionMeta) meta;
potionMeta.setColor(bukkitColor);
stack.setItemMeta(potionMeta);
} else {
if (color == null)
color = DEFAULT_MATERIAL_COLOR;
Material newItem = setMaterialColor(stack.getType(), color);
if (newItem == null)
continue;
ItemMeta oldItemMeta = stack.getItemMeta();
stack.setType(newItem);
stack.setItemMeta(oldItemMeta);
if (obj instanceof ItemType) {
ItemType newItemType = new ItemType(newItem);
newItemType.setItemMeta(oldItemMeta);
((ItemType) obj).setTo(newItemType);
} else if (obj instanceof Item) {
((Item) obj).setItemStack(stack);
} else if (obj instanceof Slot)
((Slot) obj).setItem(stack);
}
org.bukkit.Color bukkitColor = (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) ? null : ((Color) delta[0]).asBukkitColor();
ItemMeta meta = stack.getItemMeta();
if (meta instanceof LeatherArmorMeta) {
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) meta;
leatherArmorMeta.setColor(bukkitColor);
stack.setItemMeta(leatherArmorMeta);
} else if (meta instanceof MapMeta && MAPS_AND_POTIONS_COLORS) {
MapMeta mapMeta = (MapMeta) meta;
mapMeta.setColor(bukkitColor);
stack.setItemMeta(mapMeta);
} else if (meta instanceof PotionMeta && MAPS_AND_POTIONS_COLORS) {
PotionMeta potionMeta = (PotionMeta) meta;
potionMeta.setColor(bukkitColor);
stack.setItemMeta(potionMeta);
} else {
if (color == null)
color = DEFAULT_MATERIAL_COLOR;
Material newItem = setMaterialColor(stack.getType(), color);
if (newItem == null)
continue;
ItemMeta oldItemMeta = stack.getItemMeta();
stack.setType(newItem);
stack.setItemMeta(oldItemMeta);
if (obj instanceof ItemType) {
ItemType newItemType = new ItemType(newItem);
newItemType.setItemMeta(oldItemMeta);
((ItemType) obj).setTo(newItemType);
} else if (obj instanceof Item) {
((Item) obj).setItemStack(stack);
} else if (obj instanceof Slot)
((Slot) obj).setItem(stack);
}
} else if (obj instanceof Colorable) {
Colorable colorable = getColorable(obj);
Expand All @@ -245,6 +243,7 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) {
try {
colorable.setColor(color);
} catch (Exception ex) {
// TODO remove this as it's too old now
if (ex instanceof UnsupportedOperationException) {
// https://github.com/SkriptLang/Skript/issues/2931
Skript.error(
Expand Down

0 comments on commit 8599e0c

Please sign in to comment.