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

    NuclearW

    Moved to Plugin Development where you're more likely to get the help you need.
     
  3. Offline

    tommycake50

    can we see your command :S
     
  4. Offline

    MiniDigger

    its no command if a user right clicks a sign method tpToLobby is called
     
  5. Offline

    Ewe Loon

    not sure but you might want to refrain from removing players from the list while enumerating it,

    Code:
        public void tpToMap() {
            for (Player p : LobbyPlayers) {
                p.teleport(SpawnPoint);
                p.sendMessage(ChatColor.GOLD + "Es geht gleich los!");
                //  LobbyPlayers.remove(p);    << this is probibly the problem here , it will screw up the for loop r
                Players.add(p);
            }
            LobbyPlayers.clear();  // this will clear the list for you
        }
     
  6. Offline

    tommycake50

    well can i see your event where you handle the sign-click cos i think i know what you are doing but i cant be sure.
     
  7. Offline

    MiniDigger

    Ewe Loon thx i will try it.
    tommycake50
    Here is the code:
    Code:
    @EventHandler
        public void onSignRightClick(PlayerInteractEvent e) {
            if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (e.getClickedBlock().getState() instanceof Sign) {
                    Sign s = (Sign) e.getClickedBlock().getState();
                                    if (s.getLine(2).contains("Map1")) {
                        Zombie.Map1.tpToLobby(e.getPlayer());
                    }
                }
            }
        }
    ok thank to all of u.
    It works!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
Thread Status:
Not open for further replies.

Share This Page