How to get total players online out of max? VERY EASY

Discussion in 'Plugin Development' started by BJCxMC, Aug 2, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    BJCxMC

    This is probably a very easy question to answer, all I'm trying to do is make a /who command and show how many players are on out of the max number of players and list the online players, if you need a better example, player executes command "/who" and it sends them a message saying (#/#ofmax) and then sends the all the names of the people online. # Obviously means number of players. This seems like it would be very easy but I'm just not too sure on how to write it.
     
  2. Have you looked at the API at all to see if any methods stand out as being potentially useful?
     
  3. Offline

    BJCxMC

    I mean some seemed like it, but as I stated, I'm not too sure on how to make it and would just like some help is all

    All I need is how to list all the players online by their names.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  4. I'll help, I just wanted to make sure you've at least put some effort into it before asking for help. Looking at the API, you're going to need the methods getMaxPlayers() which returns an int and getOnlinePlayer() which returns an array of Players. These are both in the Server class. You can get the number of current online players by getting the size of the array of Players. Try working with these and if you still need help let me know.
     
  5. Offline

    Necrodoom

  6. Offline

    BaranCODE

    Edit: Decided not to give the code directly. Use the advice the others gave you.
     
  7. Offline

    BJCxMC

    Can you give me a hint on what do do next with this code? I know you said something about returning an array but I'm not sure how to show the names and the number isn't working for online players, here is the code, and if you click the gyazo it will show you what the chat returns.

    Code:
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("who")) {
    2. p.sendMessage(prefix + "There are " + green + Bukkit.getServer().getOnlinePlayers() + white + "/" + green + Bukkit.getMaxPlayers() + white + " online!");
    3. p.sendMessage(prefix + "Players: " + Bukkit.getServer().getOnlinePlayers());
    4. }


    What chat looks like:
    http://gyazo.com/29fc5258e1dbdc76544c588c11d9f8d6
     
  8. Offline

    Necrodoom

    BJCxMC you are trying to print a collection/array directly. That's not how it works. Use size/length method to get amount of players, and in order to get each player out of the collection/array, iterate.
    If you still have no idea what to do, head to a Java tutorial.
     
  9. Basically what Necrodoom said. It looks like you don't understand what arrays are or how they work. You'll learn the most if you read or watch tutorials that explain arrays and their importance.
     
  10. Offline

    BJCxMC

    Any videos you'd suggest I watch?
     
  11. Sorry, I've never been one for video tutorials so I don't have any I can recommend. However, there's a free book called Thinking in Java that I used in my data structures class. I just googled it and you can read it here. There are also pdf download options somewhere but I'm hesitant to provide one as I'm not sure about the legality. Chapter 11 covers all kinds of collections including arrays.

    Edit: Here's another link. This one opens it as a pdf so you can easily download it but it looks like an older edition of the book.

    Edit: I just looked up video tutorials and watched this one. It does a decent job explaining the basics of arrays. The guy also talks about multidimensional arrays which may seem daunting but they're really not that bad. Make sure you pay attention to the stuff about the for loop and the enhanced for loop. I'm tagging you in case you're not checking this anymore BJCxMC
     
Thread Status:
Not open for further replies.

Share This Page