spawn 2 players in 2 positions

Discussion in 'Plugin Development' started by 22SugarStore, Jan 22, 2018.

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

    22SugarStore

    Hey everyone, How can i spawn 2 players in 2 positions, Like the 1vs1 so how i can do it? I didn't tried anything because i didn't know how to do it, I didn't find anything on google, So if anyone can help please help me.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @22SugarStore Get 2 players.
    Get 2 locations.
    Tp p1 to loc1
    P2 to loc 2
     
  3. Offline

    Colinus999

    Are you trying to do this with commands or Plugins?
     
  4. Offline

    22SugarStore

    Maybe your are not understanding me, I want if he clicked the sign he will be teleported to the lobby < he will be waiting the other player to join > , If there is 2 players the game will be start, how can i get the 2 players?


    I'm not understanding you, what you mean?
     
    Last edited: Jan 23, 2018
  5. Offline

    timtower Administrator Administrator Moderator

    I indeed didn't understand, initial explanation was missing that information.
    Add their UUID to a list when they click a sign, if the list sisze is 2: do stuff
     
  6. Offline

    22SugarStore

    So how i can get the first player who clicked the sign and the next player who clicked the sign?
     
  7. Offline

    timtower Administrator Administrator Moderator

    There are 2 players in the list. One is the first player, the other the second player.
     
  8. Offline

    Colinus999

    In a java ArrayList, you can get the elements by it's index value:
    Code:
    public List<UUID> queue = new ArrayList<>();
    
    public void joinQueue (Player p) {
        UUID id = p.getUniqueId();
        if(!queue.contains(id)
            queue.add(id);
        if(queue.size()>1) {
            Player p1 = Bukkit.getPlayer(queue.remove(0)),
                        p2 = Bukkit.getPlayer(queue.remove(0));
            // so stuff...
        }
    }
    
    public void leaveQueue(Player p) {
        queue.remove(p.getUniqueId());
    }
    
    // Remove player when he leaves
    @EventHandler
    public void onQuit(PlayerQuitEvent e) {
        leaveQueue(e.getPlayer());
    }
     
Thread Status:
Not open for further replies.

Share This Page