CameronOfoluwa CameronOfoluwa - 4 months ago 26
Java Question

Picking Random Item From List (Bukkit)

How would I pick a random reward out from this list?

Material[] superLucky = { Material.RECORD_10, Material.RECORD_9, Material.RECORD_8 };

for(Material m : superLucky) {
if(m == Material.RECORD_10) {
player.sendMessage(ChatColor.GRAY + "- Enchanted Skull Sword");
}
if(m == Material.RECORD_9) {
player.sendMessage(ChatColor.GRAY + "- Enchanted Skull Helmet");
}
if(m == Material.RECORD_8) {
player.sendMessage(ChatColor.GRAY + "- Enchanted Skull Pickaxe");
}
}

Answer

You would receive a random item from the array like this:

int idx = new Random().nextInt(superLucky.length);
Material randomItem = superLucky[idx];
Comments