TextColor arrays?

I’m trying to create an array of text colors to be selected at random later. However, whenever I call my array, my TextColor returns null. This is my best guess of what it should be:

TextColor[] colors = new TextColor[] { TextColors.AQUA, TextColors.BLACK, TextColors.GOLD};

What is the best or recommended way to go about this?

This is probably because the TextColors.AQUA, etc. objects actually do point to null in the API sources. If you’re actually testing with a Sponge build I would find this behavior highly unusualy except for the fact that you are using an array. I’m not sure if the compiler decides that the array can be optimized away by putting the nulls that the API defines.

If you post a more complete code example and also perhaps file a bug on GitHub that would be most helpful.

2 Likes

So I figured out why this was being caused, and it was because of my shitty practices I had back when I originally wrote the Bukkit plugin i’m porting now. I was declaring and assigning my array in my class (I’m not even sure why it worked in Bukkit in the first place) when I should be assigning it in a ServerStartedEvent or something similar.