Solved [NEED HELP] getonlineplayers from configStringlist

Discussion in 'Plugin Development' started by BananaBitchs, Aug 17, 2014.

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


    How can i take all the players from the config and checks whos online and and the number of the people whos online
    1. public static void GetOnlinePlayers(Player p, String teamname){
    2. List<String> pq = teamapi.getStringList(teamname);
    3. StringBuilder sb = new StringBuilder();
    4. List<String> pqs = new ArrayList<String>();
    5. for(Player pall : Bukkit.getOnlinePlayers()){
    6. Player p1 = pall.getPlayer();
    7. for(String p2 : pq) {
    8. if(p2.equals(p1)){
    9. pqs.add(p2);
    10. }
    11. }
    12. }
    13. sb1.append("§bOnline: §2" + [B]pqs.size()[/B] + "§f/§e" + pq.size());
  2. Offline


    Well I'm a little confused with your code (what all of the variables stand for), but I can help you with a kind of generic response.

    So, what you can do is save the players to a list in your config. I will call my list "BlueTeam".

    When you want to check which team members are online, fetch all of the player names (better to use UUID's, but your choice) and add them to a local list. I will call this list "playerCheck". Then make a for loop that checks each players online status. If the player is online, add them to a list. We will call this list "onlineBlueTeamPlayers". Also make an int that stores the amount of online players. This int will be called "intOnlineBlueTeamPlayers"

    1. for (String playerName : playerCheck) {
    2. Player player = Bukkit.getPlayer(playerName);
    3. Boolean online = player.isOnline();
    5. if (online == true) {
    6. onlineBlueTeamPlayers.add(playerName);
    7. intOnlineBlueTeamPlayers++;
    8. }
    9. }

    Sorry if it seems like I "spoonfed" you the code but I couldn't think of any other way to explain it. I hope this helped!
  3. Offline


    This code create an error in chat how can i fix it
    also Thanks for help.
    1. List<String> pq1 = teamapi.getStringList(teamname);
    2. StringBuilder sb1 = new StringBuilder();
    3. List<String> pqs = new ArrayList<String>();
    4. int df = 0;
    5. for (String playerName : pq1) {
    6. Player player = Bukkit.getPlayer(playerName);
    7. Boolean online = player.isOnline();
    8. if (online == true) {
    9. pqs.add(playerName);
    10. df++;
    11. }
    12. }
    13. sb1.append("§bOnline: §2" + pqs.size() + "§f/§e" + pq.size());
    14. player.sendMessage(sb1.toString());
  4. Offline


    What is the error?
  5. Offline


    at org.bukkit.command.SimpleCommandMap.dispatch( ~[craftbukkit.jar:git-Spigot-1591]
    at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand( ~[craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand( [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.PlayerConnection.a( [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat.a( [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle( [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.NetworkManager.a( [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.ServerConnection.c( [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.MinecraftServer.v( [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.DedicatedServer.v( [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.MinecraftServer.u( [craftbukkit.jar:git-Spigot-1591]
    at [craftbukkit.jar:git-Spigot-1591]
    at [craftbukkit.jar:git-Spigot-1591]
    Caused by: java.lang.NullPointerException
    at me.bananabitchs.teamapi.TeamAPI.GetOnlinePlayers( ~[?:?]
    at me.bananabitchs.kpvpdemozone.Main.onCommand( ~[?:?]
    at org.bukkit.command.PluginCommand.execute( ~[craftbukkit.jar:git-Spigot-1591]
  6. Offline


    BananaBitchs Which line is numbered 259 in your code?

    I wont be able to respond for like 30 minutes cause i have to go. But I can help you when i come back

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 9, 2016
  7. Offline


  8. Offline


    BananaBitchs it seems to be pretty straightforward to me. What exactly don't you understand?
  9. Offline


    BananaBitchs They are trying to help you. You should follow along with what they are saying.
  10. Offline


    Locked. Please seek support for the software you use from the site you found the software.
Thread Status:
Not open for further replies.

Share This Page