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

    BananaBitchs

    How can i take all the players from the config and checks whos online and and the number of the people whos online
    Code:java
    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

    excusemyluck

    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"

    Example:
    Code:java
    1. for (String playerName : playerCheck) {
    2. Player player = Bukkit.getPlayer(playerName);
    3. Boolean online = player.isOnline();
    4.  
    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

    BananaBitchs

    excusemyluck
    This code create an error in chat how can i fix it
    also Thanks for help.
    Code:java
    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

    excusemyluck

    What is the error?
     
  5. Offline

    BananaBitchs

    excusemyluck
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) ~[craftbukkit.jar:git-Spigot-1591]
    at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) ~[craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:1013) [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:850) [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:65) [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:184) [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:731) [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [craftbukkit.jar:git-Spigot-1591]
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Spigot-1591]
    Caused by: java.lang.NullPointerException
    at me.bananabitchs.teamapi.TeamAPI.GetOnlinePlayers(TeamAPI.java:259) ~[?:?]
    at me.bananabitchs.kpvpdemozone.Main.onCommand(Main.java:99) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Spigot-1591]
     
  6. Offline

    excusemyluck

    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

    BananaBitchs

  8. Offline

    fireblast709

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

    MineStein

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

    TnT

    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