Wrong 1st argument type. Found: 'java.lang.Class<org.spongepowered.api.text.format.TextStyle>', require: 'java.lang.Class<T>'

So I’m trying to get a style, or colour that I can pass to Text#of, from a string. I was told on the IRC to use Sponge.getRegistry().getType() to accomplish this, and it works fine if I try to get the value of a TextColor object with this method, but when I replace that with TextStyle (In the event the string passed was BOLD, not something like GREEN), I get the error in the title. Here’s my code: http://hastebin.com/egapesoziw.coffee

Can you post the code of the CommandSpecs ?

I found what the issue was, the TextStyle interface doesn’t extend CatalogType, which is necessary for this lookup to function. Thanks though!

If you want to get a TextStyle by name from the registry, you can use TextStyle.Base

You could always try using this:

public static TextFormat getFormat(String name) {
	for (Field f : TextColors.class.getDeclaredFields()) {
		boolean b = f.isAccessible();
		f.setAccessible(true);
		if (f.getName().equalsIgnoreCase(name)) {
			try {
				TextColor c = (TextColor) f.get(null);
				f.setAccessible(b);
				return TextFormat.of(c);
			} catch (IllegalArgumentException | IllegalAccessException e) {
				// should not happen, can be ignored
			}
		}
	}
	for (Field f : TextStyles.class.getDeclaredFields()) {
		boolean b = f.isAccessible();
		f.setAccessible(true);
		if (f.getName().equalsIgnoreCase(name)) {
			try {
				TextStyle c = (TextStyle) f.get(null);
				f.setAccessible(b);
				return TextFormat.of(c);
			} catch (IllegalArgumentException | IllegalAccessException e) {
				// should not happen, can be ignored
			}
		}
	}
	return TextFormat.of();
}

(Sorry for the reflection, I couldn’t find a simple way to switch or iterate over colours or styles)
As suggested by simon, you could try to get TextStyles from the registry using the Base class, but this works just as well.

EDIT: I should note that this is considerably slow than using the registry, something always present with reflection.