ArrayList

Discussion in 'Plugin Development' started by JustForNothing, Feb 3, 2013.

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

    JustForNothing

    Hey how can i get all players from arrayList and teleport them?
     
  2. Offline

    przemek3697

    Code:java
    1.  
    2. for(Player p: getServer().getOnlinePlayers()){
    3. p.teleport(new Location(world, x, y, z));
    4. }
    5.  

    That's what you mean
     
  3. Offline

    logangorence

    I am not sure but I think he may have stored Players in an arraylist, which isn't really the proper way to do it, it may be easier, but its not the best for some more advanced things you want to do.
     
  4. Offline

    JustForNothing

    I have an ArrayList <String>. To this arrayList player can join (.add), but i don't know how to teleport players from ArrayList to location.
     
  5. Offline

    logangorence

    Will this do it for you?

    Code:
    for(int i = 0; i > arraylist.length; i++) {
      Player targetPlayer = Bukkit.getPlayerExact(arraylist.get(i));
      targetPlayer.teleport(new Location(world, x, y, z);
    }
     
  6. Offline

    teunie75

    Another one here:
    Code:
    public final ArrayList<Player> al = new ArrayList<Player>();
    int size = al.size();
    while (size >= 0){
            player.teleport(al.get(size).getLocation());
            size = size - 1;
            }
     
  7. Offline

    logangorence

    I'm not sure if thats what he's going for. I think he wants to teleport all that are in the ArrayList to a certain location. All though, I am not exactly sure what you're going for there either, from what I see, that the sender of the command(player) is getting teleported from player to player within the ArrayList. Correct me if I am wrong.
     
  8. Offline

    JustForNothing

    I cannot test now but how do you think will it work?:
    Code:java
    1.  
    2. for (String s : arraylist) {
    3. Player player = Bukkit.getServer().getPlayer(s);
    4. if (player == null) {
    5. continue;
    6. }
    7. player.teleport(loc);
    8. }
    9.  
     
  9. Offline

    logangorence

    Instead of Bukkit.getServer().getPlayer(s), I would use Bukkit.getPlayerExact(s);. I think its supposed to work better than getPlayer(s);
     
  10. Offline

    JustForNothing

    It doesn't work. It just do nothing, and my new commands too ;/
    Can anyone say me why?
    Code:java
    1.  
    2. else if(args.length == 2)
    3. {
    4. if(args[0].equalsIgnoreCase("test"))
    5. {
    6. if(sender.hasPermission("test.size"))
    7. {
    8. if(args[1].equalsIgnoreCase("size"))
    9. {
    10. player.sendMessage("SIZE:" + array.size());
    11. }else if(args[1].equalsIgnoreCase("lol"))
    12. {
    13. player.sendMessage( "LOL:" + array2.size());
    14. }
    15. }
    16. }
    17. }
    18.  
     
  11. Offline

    logangorence

    Can you copy and paste the whole onCommand code?
     
  12. Offline

    JustForNothing

    Code:java
    1.  
    2. @Override
    3. public boolean onCommand(CommandSender sender, Command cmd,
    4. String label, String[] args)
    5. {
    6. if(!(sender instanceof Player)
    7. {
    8.  
    9. return false;
    10. }else{
    11. if(cmd.getName().equalsIgnoreCase("just")
    12. {
    13. if(args.length== 1)
    14. {
    15. if(args[0].equalsIgnoreCase("aut")
    16. {
    17. sender.sendMessage("Test For Author:");
    18. }
    19. }else if(args.length == 2)
    20. {
    21. if(args[0].equalsIgnoreCase("test")
    22. {
    23.  
    24.  
    25.  
    26. if(sender.hasPermission("test.size"))
    27.  
    28.  
    29. [LIST]
    30. [*]
    31.  
    32. {
    33.  
    34.  
    35.  
    36. [*]
    37.  
    38. if(args[1].equalsIgnoreCase("size"))
    39.  
    40.  
    41.  
    42. [*]
    43.  
    44. {
    45.  
    46.  
    47.  
    48. [*]
    49.  
    50. player.sendMessage("SIZE:" + array.size());
    51.  
    52.  
    53.  
    54. [*]
    55.  
    56. }else if(args[1].equalsIgnoreCase("lol"))
    57.  
    58.  
    59.  
    60. [*]
    61.  
    62. {
    63.  
    64.  
    65.  
    66. [*]
    67.  
    68. player.sendMessage( "LOL:" + array2.size());
    69.  
    70.  
    71.  
    72. [*]
    73.  
    74. }
    75.  
    76.  
    77.  
    78. [*]
    79.  
    80. }
    81.  
    82.  
    83. [/LIST]
    84.  
    85. }
    86. }
    87. }
    88.  
    89. }
    90.  
     
  13. Offline

    logangorence

    Did you insert your commands into the plugin.yml file?
     
  14. Offline

    JustForNothing

  15. Offline

    logangorence

    That is very weird then. I don't know what the problem is :(
     
  16. Offline

    teunie75

    Woops, it was this:
    Code:
    public final ArrayList<Player> al = new ArrayList<Player>();
    int size = al.size();
    while (size >= 0){
            al.get(size).teleport(player.getLocation());
            size = size - 1;
            }
    Don't know if this is correct, didn't test it.
     
Thread Status:
Not open for further replies.

Share This Page