Solved Problems with ArrayLists

Discussion in 'Plugin Development' started by MiniDigger, Dec 30, 2012.

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

    MiniDigger

    Hey Guys
    I want to write a plugin for my server. And I get no further.
    Via a command, the following method is called:
    Code:
    public void tpToLobby(Player p) {
        LobbyPlayers.add(p);
        p.teleport(LobbyPoint);
        p.sendMessage("You are in the lobby now.");
        if (LobbyPlayers.size() == maxPlayers) {
        start();
        }
    }
    This method adds the player who executed the command added to the ArrayList player lobby and teleports him to the lobby.
    If the lobby is full, the start () method is called:
    Code:
        public void start() {
            tpToMap();
            sendMessage("The first wave starts in");
            sendMessage("5");
            sendMessage("4");
            sendMessage("3");
            sendMessage("2");
            sendMessage("1");
            sendMessage("NOW!");
            startWave(1);
        }
    This method calls the method tpToMap (), which will teleport the player to the map:
    Code:
        public void tpToMap() {
            for (Player p : LobbyPlayers) {
                p.teleport(SpawnPoint);
                p.sendMessage(ChatColor.GOLD + "Es geht gleich los!");
                LobbyPlayers.remove(p);
                Players.add(p);
            }
        }
    But it will only teleport the player who performed command first.

    What am I doing wrong?

    I sit the whole day in front of my computer and can not find the errro.

    Please help me :D
     
  2. Offline

    DarkBladee12

    MiniDigger where did you define "LobbyPlayers"?
     
  3. Offline

    EnvisionRed

    Not just that, but your plugin also causes huge memory leaks. You are saving actual Player instances to a hashmap, which inhibits the Garbage Collector from collecting them. Save player USERNAMES, not player instances.
     
    MiniDigger likes this.
  4. Offline

    DarkBladee12

    Yes, what EnvisionRed said is right, saving just the playernames and using "Bukkit.getPlayer(name);" if you need the player instance would be more efficient ^^
     
    MiniDigger likes this.
  5. Offline

    MiniDigger

    Thanks guys i will try it

    It works! Thx to all of u

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  6. Offline

    Assult

    Why did you make 2 threads?
     
  7. Offline

    MiniDigger

    first I made a topic in the wrong forum. I saw that and edited my post that someone should delete it. Then I created a topic in the right forum. But somehow the editing was not accepted. Then have a moderator move the topic, and now there are two threads :D
     
Thread Status:
Not open for further replies.

Share This Page