Cannot convert from Collection to Player

Discussion in 'Plugin Development' started by sykoztesao, Jul 4, 2019.

  1. Offline

    sykoztesao

    Hi guys, I'm getting and error message in eclipse > "Type mismatch: cannot convert from Collection<capture#1-of ? extends Player> to Player[]" at

    Code:
    for (int length = (onlinePlayers = Bukkit.getOnlinePlayers()).length, i = 0; i < length; ++i) {
    at

    Code:
    @EventHandler
        public void onClick(final InventoryClickEvent event) {
            if (event.getCurrentItem() != null && event.getCurrentItem().getType() == Material.BOOK && event.getClickedInventory().getName().contains(ChatColor.RED + "You are frozen")) {
                event.setCancelled(true);
                Player[] onlinePlayers;
                for (int length = (onlinePlayers = Bukkit.getOnlinePlayers()).length, i = 0; i < length; ++i) {
                    final Player allPlayers = onlinePlayers[i];
                    if (allPlayers.hasPermission("ss.see")) {
                        allPlayers.sendMessage(ChatColor.RED + event.getWhoClicked().getName() + " has admitted it was cheating.");
                    }
                    event.getWhoClicked().closeInventory();
                }
            }
    I tried (Player player : getServer().getOnlinePlayers()).length instead of
    Bukkit.getOnlinePlayers().length but it wouldn't fix. Could anyone help me?
     
  2. Online

    timtower Ninja on the waves Moderator

    @sykoztesao for(Player p : getServer().getOnlinePlayers())
    You are using a very, very outdated tutorial.
     

Share This Page