diff --git a/src/main/java/net/axay/kspigot/chat/KColors.java b/src/main/java/net/axay/kspigot/chat/KColors.java index 2710ea03..cbcd6e92 100644 --- a/src/main/java/net/axay/kspigot/chat/KColors.java +++ b/src/main/java/net/axay/kspigot/chat/KColors.java @@ -4,10 +4,7 @@ import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextDecoration; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; @SuppressWarnings("unused") @@ -739,14 +736,31 @@ public class KColors { */ public static final TextColor YELLOWGREEN = TextColor.color(154, 205, 50); - public static List values() { - Field[] fields = KColors.class.getFields(); - List finalList = new ArrayList<>(); //yes this could be done with a simple Arrays.stream but didn't work because java is stupid (because of the exception) - for (Field field : fields) { - try { - finalList.add((TextColor) field.get(null)); - } catch (IllegalAccessException ignored) {} - } - return finalList; + public static List allColors() { + return Arrays.stream(KColors.class.getFields()) + .filter(field -> field.getType() == TextColor.class) + .map(field -> { + try { + return (TextColor) field.get(null); + } catch (IllegalArgumentException | IllegalAccessException ignored) { + return null; + } + }) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } + + public static List allDecorations() { + return Arrays.stream(KColors.class.getFields()) + .filter(field -> field.getType() == TextDecoration.class) + .map(field -> { + try { + return (TextDecoration) field.get(null); + } catch (IllegalArgumentException | IllegalAccessException ignored) { + return null; + } + }) + .filter(Objects::nonNull) + .collect(Collectors.toList()); } }