#Get org.bukkit.entity.Player Array from the Player Collection

1 messages · Page 1 of 1 (latest)

blissful tide
placid yacht
#

Read what I mentioned

#

And ftr it’s a Collection<? extends Player>

#

important detail

#

I still don’t get what you wanted to do? Like converting the array type CraftPlayer[] to just Player[]?

blissful tide
#

The Idea was I could convert the Playerlist to the old format (Array) to allow for 1.8 compatibility. And Last I checked the old Version returned Player[]

placid yacht
#

That’s for like 1.7 and lower or smtng

blissful tide
#

Apparently it got changed during 1.8.3 Developement

placid yacht
#

No lol

blissful tide
placid yacht
#

Server::getOnlinePlayers has actually been returning the type Collection<out Player> even in 1.7

#

well as you mentioned yourself the type is erased

#

However at compile time Collection<? extends Player> means it could under the hood be a Collection<? extends CraftPlayer>

#

aaa Collection<? extends CraftPlayer> is a subtype of Collection<? extends Player>

#

anyways

blissful tide
placid yacht
#

If you just want a Collection<Player> or a Player[] do smtng like
getOnlinePlayers().stream().map(Player::getPlayer)
Then either
collect(Collectors.toList());
or
toArray(Player[]::new)

placid yacht
#

But generics is a bit special

#

aaa some types are erased at runtime and only lives at compile time, checking and converting might be unsafe