lundi 29 décembre 2014

Random in a Int[]

I want to the player receive a random item in the Int[]



public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {


Player player = (Player) sender;

if(commandLabel.equalsIgnoreCase("surprise")){
Random random = new Random();

PlayerInventory inventory = player.getInventory();
int ItensIds[] = {274, 313, 314, 315, 316};
ItemStack item = new ItemStack(Material.AIR);



for(int Ids : ItensIds){

int randomNumber = random.nextInt(300);
do{
randomNumber = random.nextInt(300);
item.setTypeId(Ids);
inventory.addItem(item);
} while(randomNumber == Ids);

break;
}

}


Im trying to figure how it works but ends crashing the server or not working at all.


Im really new at this code stuff, please understand if I did something really wrong.





Aucun commentaire:

Enregistrer un commentaire