jakobkmar / KSpigot

Extended Spigot and Bukkit API for Kotlin
https://jakobkmar.github.io/KSpigot
GNU General Public License v3.0
134 stars 35 forks source link

Add values() to KColors #45

Closed mooziii closed 2 years ago

mooziii commented 2 years ago

Would be nice to have this e.g to get random colors

l4zs commented 2 years ago

there are TextColors and TextDecorations in KColors now, so I'd suggest making two methods. And you'd have to add a type check as you'll get a ClassCastException in your current method.

btw it can be done with streams:

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());

although I guess that this will be a lot slower because of the low amount of fields

mooziii commented 2 years ago

bump?