IntelliJ Error

Discussion in 'Spigot Plugin Development' started by Angeles, Jun 11, 2016.

  1. Code (Text):
    package com.yofou.commands;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;

    import java.util.Collection;

    public class WhoCommand
            implements CommandExecutor
    {
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
            if (cmd.getName().equalsIgnoreCase("nwho"))
            {
                 int playercount = Bukkit.getServer().getOnlinePlayers().length;

                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&d&m--&8&m---------------&d&m-----&8&m---------------&d&m--"));
                sender.sendMessage("§dThere are §a" + playercount + ChatColor.YELLOW + "/" + ChatColor.GREEN + Bukkit.getMaxPlayers() + " §dplayers online.");
                sender.sendMessage("§dIf you require assistance join " + ("§6§lts.daftpvp.us") + "§7.");
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&d&m--&8&m---------------&d&m-----&8&m---------------&d&m--"));

                return true;
            }
            return false;
        }
    }
    Well on the
    Code (Text):
      int playercount = Bukkit.getServer().getOnlinePlayers().length;
    i have an error on https://gyazo.com/ca735e069d8f089320275992c5892acf
     
  2. Should be .size();
     
  3. When i put this on the end it tell me to get a collection of players and doesnt display the amount of players on the server in game
     
  4. Can resolve methord
     
  5. JamesJ

    Supporter

    .size()...
     

  6. Error:(21, 69) java: cannot find symbol
    symbol: method size()
    location: class org.bukkit.entity.Player[]
     
  7. .notcopyingcode()...
     
    • Agree Agree x 2
  8. JamesJ

    Supporter

    Please be honest;

    Do you know Java?

    If so, use the Java Docs. https://hub.spigotmc.org/javadocs/spigot/
     
    • Funny Funny x 4
  9. JamesJ

    Supporter


    getOnlinePlayers().length

    I'll be awaiting $50 to [email protected] :)
     
    • Winner Winner x 2
  10. it doesnt work
     
  11. JamesJ

    Supporter

    What version of Spigot are you building against?
     
  12. Code (Java):
    public List<Player> getOnlinePlayers()
    {
        ArrayList<Player> ret = new ArrayList<Player>();
        for (Player player : Bukkit.getOnlinePlayers())
            ret.add(player);
        return ret;
    }
    That'll have the size function.
    You could simply update to 1.8-1.10 tho, for the Collection or downgrade to 1.7 or less for a Player array.
     
  13. Okay thanks <3
     
  14. Better send him the money!
     
    • Winner Winner x 1
  15. Will do
     
  16. [​IMG] I think he forgot.. ;-;
     
  17. [​IMG]

    ...
     
    • Agree Agree x 1