Minigame, adding into list and teleporting.

Discussion in 'Plugin Development' started by RoaxZ, Jun 15, 2014.

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

    RoaxZ

    I can't seem to get this to work. The thing is, i let them click a sign, interact, works perfectly, broadcasts who joined etc. But then if i try to get the size of the list and if its bigger then > 1 [1 joined player] teleport all the players in the list, this doesn't work?

    What did i do wrong?

    Code:
        @EventHandler
        public void SignSetsClick(PlayerInteractEvent e) {
            List<String> runners = new ArrayList<String>();
            Player player = e.getPlayer();
            String playername = player.getDisplayName();
            if (e.getAction() == Action.RIGHT_CLICK_BLOCK
                    && e.getClickedBlock() != null) {
                if (e.getClickedBlock().getType() == Material.WALL_SIGN
                        || e.getClickedBlock().getType() == Material.SIGN_POST) {
                    Sign sign = (Sign) e.getClickedBlock().getState();
                    String[] lines = sign.getLines();
                    if (lines[0].equalsIgnoreCase(ChatColor.BLUE + "[Blizzard]"))
                        if (lines[1].equalsIgnoreCase(ChatColor.RED + "Join"))
                            if (lines[2]
                                    .equalsIgnoreCase(ChatColor.BLACK + "Lobby"))
                                player.sendMessage("You have joined the game lobby.");
                    int itemCount = runners.size();
                    Bukkit.broadcastMessage(ChatColor.YELLOW + playername
                            + ChatColor.RED + " has joined Blizzard!");
                    Location loc = new Location(player.getWorld(), -300, -300, -300);
                    String playernames = player.getDisplayName();
                    if (runners.contains(playernames)) {
                        player.sendMessage("You already joined!");
                    } else {
                        runners.add(playernames);
                    }
                    if (itemCount > 1) {
                        for (Player p : getServer().getOnlinePlayers()) {
                            if (runners.contains(getServer().getOnlinePlayers())) {
                                p.teleport(loc);
                            }
     
                        }
                    }
                }
            }
     
        }
    bumpy, bumpy bump.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  2. Offline

    WeDaBeast

    Are you registering the events? RoaxZ
     
  3. Offline

    RoaxZ

    Yes, i am. As i said everything works as i said.

    Except teleporting all players in the list or adding them.
     
  4. Offline

    gjossep

    RoaxZ First of all, make sure you are formating your code. This is really hard to read.... If you using a IDE, most of them have a option for auto-formating. From then i can help you find the error
     
  5. Offline

    RoaxZ


    Formatted and added new code.

    gjossep
     
  6. Offline

    RoaxZ

    Bumping this thread up .._..
     
  7. Offline

    Smartloser

    Code:java
    1.  
    2. [FONT=Consolas]if (runners.contains(getServer().getOnlinePlayers()))[/FONT]
    3. [FONT=Consolas][/FONT]

    I don't understand what you're checking here
     
  8. Offline

    RoaxZ

    I'm supposed to check the online names and if they're in the list tp them.

    But i didn't do this right i guess.
     
  9. Offline

    RoaxZ

    Bump still need help...
     
  10. Offline

    Konkz

    About that:

    PHP:
    for (Player bukkitPlayer Bukkit.getOnlinePlayers()) {
    if(
    myArrayList.contains(bukkitPlayer.getName())) {
      
    Bukkit.broadcastMessage(bukkitPlayer.getName() + " is in the ArrayList: myArrayList");
    }
    }
     
  11. Offline

    RoaxZ

    Yes, thank you! :)

    But how do i teleport the players now?
     
  12. Offline

    Konkz

    Did you even take time to learn Java and/or Bukkit?

    PHP:
    for (Player bukkitPlayer Bukkit.getOnlinePlayers()) {
    if(
    myArrayList.contains(bukkitPlayer.getName())) {
      
    bukkitPlayer.teleport(/* you'd put a location here */);
    }
    }
     
Thread Status:
Not open for further replies.

Share This Page