Teleporting players in 2 lists to 2 different locations

Discussion in 'Spigot Plugin Development' started by Bravecity, Jun 10, 2017.

  1. Hey,

    I am working on a plugin that has 2 lists, playerone and playertwo and i want to send them to 2 separate locations on command in the console. I have done the command and have tried to figure out a way to teleport the players in the lists to separate locations.

    Thanks in advance for any help
    -Bravecity
     
  2. And whats your problem now when you already figured out how to send the players ?
     
  3. I said tried to figure it out
     
  4. Show us what you've got so far.
     
  5. Code (Text):
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if(sender instanceof Player) {
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "This command can only be used in the console!"));
                return true;
            }
           
            if(cmd.getName().equalsIgnoreCase("bca")) {
                if(args.length == 0) {
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "&cUsage: /bca <command>"));
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "&6/bca start: &fStart the battle"));
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "&6/bca disable <kit>: &fDisable a kit"));
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "&cUsage: /bca "));
                    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "&cUsage: /bca <command>"));
                }else if(args[0].equalsIgnoreCase("start")) {
                    if(playerone.isEmpty() || playertwo.isEmpty()) {
                        sender.sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "&cThere are not enough players!"));
                    }else{
                       
                    }
                }
            }
        }
     
  6. well, you have tried it but nothing that has todo with a location or teleporting exists.

    Show us what "playerone" & "playertwo" contains ( map? , List? ) ..
     
  7. I deleted it cuz it wasnt working. Also the lists contain player names

    Code (Text):
    ArrayList<String> playerone = new ArrayList<String>();
    ArrayList<String> playertwo = new ArrayList<String>();
     
  8. Just simply first initialize your locations like so:

    Code (Text):


    Location locationOne = new Location(...);
    Location locationTwo = new Location(...);

     
    Then use a loop to go through the two lists.

    Code (Text):


    for(String onePlayer : playerone){
      //Now get the player
       Player player = Bukkit.getPlayerExact(onePlayer);
       if(player != null){ // check if the player is online / exists.
       player.teleport(locationOne); // teleport to the "one" location
    }
    }

    //Now do the same for the "two" list

    for(String twoPlayer : playertwo){
      //Now get the player
       Player player = Bukkit.getPlayerExact(twoPlayer);
       if(player != null){ // check if the player is online / exists.
       player.teleport(locationTwo); // teleport to the "two" location
    }
    }


     
    Also change your list to

    Code (Text):

    List<String> playerOne = new ArrayList<String>();

     
    Or use Sets

    Code (Text):

    Set<String> playerOne = new HashSet<String>();