As part of a personal project I need a way to pick a random item from minecrafts full list of items/blocks. Previously I was using someone elses plugin, however it only supported up to 1.14.1, so it wasn't giving us any of the latest items. How can I achieve this in code? Thanks!
I think this should work, please correct me if I am wrong, couldn't test it yet. Code (Text): Random random = new Random(); Player player = ... int randomIndex = random.nextInt(Material.values().length); ItemStack randomItem = new ItemStack(Material.values()[randomIndex]); player.getInventory().addItem(randomItem);
Just remember to make that Random object outside the scope of the function so it isn't being created each time, that or use ThreadLocalRandom.