Players ArrayList not working

Discussion in 'Plugin Development' started by HerohollandYT, Apr 13, 2020.

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


    Hello I am trying to build a minigame currently and my main problem is my players arraylist. Basically, when the player does the command to join the plugin adds their name to the ArrayList players. After that, the minigame is supposed to give the players a countdown by using
    for (String name  =  players) {
    Player p = Bukkit.getPlayerExact(name);
    Then for some reason when I send them the messages for the countdown it says
    for player 1,
    for player 2,
    for player 1 and
    for player 2. I am not sure why this was happening where it does one player after another.

    For another example when I try to do this same method with teams for 2 players, the plugin puts one player on a team and nothing happens for the other player.

    I have also tried this method with no success:
    for (int i = -1; i > player.size(); i++) {
    Player p = Bukkit.getPlayerExact(players.get(i));
    I am looking for anyone who knows how to fix this. The way I registered the ArrayList is as follows in the Main Command Class that is a command executor class for the main class:
    static ArrayList<String> players = new ArrayList<String>();
    Tell me if there is more info needed.
  2. Offline


    @HerohollandYT You should probably look up tutorials for Java loops.

    That won't compile.

    That won't run even once.
  3. Offline


    Yea, that's a mess OP. I'd suggest learning basic Java first. You can save a step by making the list hold Players instead. You should removing them when they log out too, which I'd bet you aren't. Not doing that will cause a memory leak. There is also no need for it to be static and it should be declared List<String> players = new ArrayList<String>();

    Also when you need help, it's better to post the whole class without redaction. The problem is the messages that go to the players, but you redacted that and put a comment. How are we supposed to debug that?
  4. Offline


    Okay thanks for the help, and yes I am removing the players when they leave. The message was not the focus of what I was trying to debug, it was just the sending. Thanks!
Thread Status:
Not open for further replies.

Share This Page