I need help with my plugin

Discussion in 'Spigot Plugin Development' started by alessio2010, May 10, 2017.

  1. hello, I'm making a plugin and i'm trying to get all online players and store them so i can do something like this
    but it doesn't work, so what do I do to get all online players and store them in something. I'm trying to make it so when the server meets the maximum players so == it does a certain thing else it does another thing
  2. Is that all your code?

    You probably want a PlayerJoinEvent, get the current number of people online if == to a number then do something.

    Your code is missing a lot though, so not really sure what you want?
  3. That's a part of my code but i was wondering how do i get all players and store to make an if else statement with it
  4. You are trying to get the amount of players, not the actual players. Bukkit.getOnlinePlayer().size() will return the number of players online. The if statement will perform the code if there are 30 players online.

    Hope this helped!

    Code (Text):
            int max = Bukkit.getOnlinePlayers().size();
            if (max == 30) {
                //what you want the code to do
            return true;
    EDIT: Yes, you should run this code with PlayerJoinEvent

    Another Edit: Learn basic java first please.
    • Useful Useful x 1
  5. Waldxn, thank you very much :)
  6. You are casting a Collection as a Player, you can't do that
    Your ide surely has given an error on (max==30);
    There is no semicolon on public Player max = (Player) Bukkit.getServer().getOnlinePlayers()
    You cannot set a local variable as Public

    EDIT: @Waldxn'c code is correct.
    Furthermore, there is a Server#getMaxPlayers method that could help you
    • Useful Useful x 1
  7. Alright, thank you guys. If i don't run it with the playerjoin event will it update itself or will it get the amount of players online once and not update it everything someone joins
  8. You can use the PlayerPreLoginEvent (even though I have never used it) to check the player player's number before it logs in, I think (Might be wrong). Check the Javadoc for more help (Docs are the best friend of developer, or was it the dog?)