Solved Remove Players From ArrayList Simply Does Not Work

Discussion in 'Plugin Help/Development/Requests' started by Dsi_Mario, Dec 29, 2014.

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

    Dsi_Mario

    Hello,
    I use an ArrayList for storing every player online. The reason why I do this is because I have a for loop going around and around 20tps checking if the amount of online players is right to start a minigame. The problem is, the ArrayList simply won't delete a player from it. I did some debugging, and I found this. [​IMG]
    The multiple colors are the array being printed once again. This says that the server thinks that there are multiple players online, when there really are only one.

    My array was created by:
    Code:
        public static List<Player> onlinePlayers = new ArrayList<Player>();
    I haven't found any other type that actually works with a for loop.

    I add players to the array by:

    Code:
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e){
            Main.onlinePlayers.add(e.getPlayer());
    }
    I remove players from the array by:
    Code:
        public void onPlayerQuit(PlayerQuitEvent e){
            Main.onlinePlayers.remove(e.getPlayer());
        }
    The removing just does not do what it is supposed to do. Please help.
     
  2. Offline

    MisterErwin

    @Dsi_Mario
    It is generally not good to save Player Objects in a List/Map

    Try to save the playername (Player#getName())

    And you forgot the @EventHandler
     
  3. Offline

    Dsi_Mario

    Oh, whoops...
    That solves that problem.
    Even if it is not good to save player objects in that fashion, I most likely will still use it so that I can reference the player. Thank you.
     
Thread Status:
Not open for further replies.

Share This Page