Give players in arraylist items

Discussion in 'Plugin Development' started by Edvio, Sep 12, 2015.

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

    Edvio

    I'm making a minigame plugin with kits. How could i make it so players in one arraylist get some items and others get other items? I cant get it to work.
    My code:
    Code:
    			Bukkit.getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
    
    				@Override
    				public void run() {
    					Bukkit.broadcastMessage(ChatColor.RED.toString() + ChatColor.BOLD + "The game has started!");
    					State.GameState.gameState.setState(GameState.STARTED);
    					for(final Player all : Bukkit.getOnlinePlayers())
    					{
    							
    						if(sghg.playing.contains(all.getName())) {
    							
    			            Location teleportLocation = null;
    			            
    			            int x = 0;
    			            int y = 120;
    			            int z = 0;
    			            
    			            boolean isOnLand = false;
    			            
    			            while (isOnLand == false) {
    			                    teleportLocation = new Location(all.getWorld(), x, y, z);
    			                    
    			                    if (teleportLocation.getBlock().getType() != Material.AIR) {
    			                            isOnLand = true;
    			                    } else y--;
    			            
    			            }
    			            
    			            all.teleport(new Location(all.getWorld(), teleportLocation.getX(), teleportLocation.getY() + 5, teleportLocation.getZ()));
    			            
    						all.getInventory().clear();
    		   	            all.closeInventory();
    		   	    		all.setGameMode(GameMode.SURVIVAL);
    		   	    		all.getInventory().addItem(new ItemStack(Material.COMPASS));
    			            all.getWorld().setDifficulty(Difficulty.EASY);
    			            all.getWorld().setTime(0);
    			            sghg.pregame.remove(all.getName());
    			            sghg.invincibility.add(all.getName());
    					}
    					}
    				}
    			}, 350);
    [code]
     
  2. Offline

    Gamesareme

    @Edvio Well just have your array list of players and have a for loop to run through these. Then for each player in the loop give them the items that you want to give them
     
  3. public ArrayList<String> kit1 = new ArrayList<String>();

    for(Player pl : Bukkit.getOnlinePlayers()) {
    if(kit1.contains(pl.getUniqueId().toString()) {
    //add items to inventory
    }
    }

    If you mean that, btw: written on phone, so sorry for the formatting
     
    Last edited: Sep 12, 2015
  4. Offline

    Ruptur

    @xMichey
    Asumming you have two seperate lists then loop thorugh each one of them using foreach and then give them appropriate items.

    EDIT:
    If you only have thier names stored in the list then iterate through the lists and then get the player with getServer().getOnlinePlayer(abc).
    'abc' being the player name in the loop.
     
Thread Status:
Not open for further replies.

Share This Page