Solved Join Teleportation help

Discussion in 'Plugin Development' started by Yazan, Oct 17, 2013.

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

    Yazan

    Hello, this is what I'm trying to do, I'm trying to get players on the PlayerJoinEvent and add each one of them to a different arraylist, like this:
    First player will be added to arraylist "test"
    Second player will be added to arraylist "test2"
    ...etc

    Thanks for reading!

    Please tag me when you reply.

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

    mrCookieSlime

    Yazan
    ? Can you describe it a bit more clear?
    If you wanna know how to add Players to arrasylists just use test.add(player)
     
  3. Offline

    Yazan

    mrCookieSlime here's an example:
    Code:java
    1. ArrayList<String> player1 = new ArrayList<String>();
    2. ArrayList<String> player2 = new ArrayList<String>();
    3. ArrayList<String> player3 = new ArrayList<String>();
    4. ArrayList<String> player4 = new ArrayList<String>();
    5.  
    6. public void onPlayerJoin(PlayerJoinEvent e) {
    7. //I'm going to be teleporting all the players in the
    8. //other server to this server.
    9. //Get the 4 players and add EACH one to a different arraylist
    10. //get first player and add them to player1
    11. //get second player and add them to player2
    12. //get third player and add them to player3
    13. //get fourth player and add them to player4

    Hope this is clear enough :)
     
  4. Offline

    Pizza371

    Yazan why not Bukkit.getOnlinePlayers();?
     
  5. Offline

    Yazan

    Pizza371 That gets all the online players, I want to get separate players.
     
  6. Offline

    5pHiNxX


    @Yazan: could you please try to explain your intention or what you want to do with this array lists ... maybe there is a better way to do this...
     
    Pizza371 likes this.
  7. Offline

    Pizza371

    Yazan so you want the last 4 loaded?
     
  8. Offline

    Yazan

  9. Offline

    5pHiNxX

    @Yazan: ok ... then i would use only one ArrayList and call it players ... and append every new player to the end of the arraylist ...
    and you can iterate through the ArrayList by using:

    Code:java
    1. for (String playername : players) {
    2. Player player = getServer.getPlayer(playername);
    3. player.teleport(...);
    4. }

    Note: did not check the syntax but i thing the idea is clear...
     
    Yazan likes this.
  10. Offline

    Yazan

    5pHiNxX Hmm, okay I'll try this then if I have any problems I'll get back to you, thanks!

    Okay sorry for bumping but I'm stuck, can anyone help me?

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

    sgavster

    Yazan
    Code:java
    1. @EventHandler
    2. public void onJoin(PlayerJoinEvent e)
    3. {
    4. Player p = e.getPlayer();
    5. for(Player e : Bukkit.getOnlinePlayers()
    6. {
    7. if(test1.contains(p.getName()) && test2.contains(e.getName())
    8. {
    9. p.teleport(e.getLocation());
    10. }
    11. }
    12. }
     
  12. Offline

    Yazan

    sgavster Thanks for posting!, I'll try that tomorrow and other please feel free to post and try to help me.

    I found a better way to do this using scoreboard teams, thanks everyone for the help!

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

Share This Page