Reputation: 1
I get this error in the IDE. The error shows up under Bukkit.getOnlinePlayers()
:
Required: org.bukkit.entity.Player[]
Found: java.util.Collection <capture<? extends org.bukkit.entity.Player>>
Here is the code.
public List<Player> getTargetV3(Arena arena, Player player, int maxRange, double aiming, boolean wallHack) {
ArrayList target = new ArrayList();
Location playerEyes = player.getEyeLocation();
Vector direction = playerEyes.getDirection().normalize();
ArrayList targets = new ArrayList();
Player[] lx;
int testLoc = (lx = Bukkit.getOnlinePlayers()).length;
for(int loc = 0; loc < testLoc; ++loc) {
Player block = lx[loc];
if(block != player && block.getLocation().distanceSquared(playerEyes) < (double)(maxRange * maxRange)) {
targets.add(block);
}
}}
Upvotes: 0
Views: 1269
Reputation: 11051
Spigot implementations overrides the Bukkit implementation:
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Bukkit.html#getOnlinePlayers()
Therefore, getOnlinePlayers()
returns Collection<? extends Player>
instead of Player[]
. You should switch out to calls to a collection, not an array:
Collection<? extends Player> lx = Bukkit.getOnlinePlayers();
int testLoc = lx.size();
for (int loc = 0; loc < testLoc; ++loc) {
Player block = lx.get(loc);
// ...
}
Upvotes: 0
Reputation: 1928
The error says that you used wrong data type (a Collection
instance). You should convert your collection of players into array.
You can do it like this:
Player[] players = playersCollection.toArray(new Player[playersCollection.size()]);
Note: I used random variables names. Adjust the names to your variables.
Upvotes: 2