Hey everyone! I am currently writing a Survival Games plugin from scratch. I have recently finished my regenerateChests method. I decided to share it with you! Code:java public static void regenerateChests() { for (Chunk chunks : Core.forsakenAscension.getLoadedChunks()) { for (BlockState chests : chunks.getTileEntities()) { if (chests instanceof Chest) { Chest chest = (Chest) chests; Random random = new Random(); int slot1 = random.nextInt(26); int slot2 = random.nextInt(26); int slot3 = random.nextInt(26); Material[] items = new Material[] { Material.WOOD_SWORD, Material.STONE_SWORD, Material.WOOD_AXE, Material.STONE_AXE, Material.LEATHER_HELMET, Material.LEATHER_CHESTPLATE, Material.LEATHER_LEGGINGS, Material.LEATHER_BOOTS, Material.IRON_HELMET, Material.IRON_LEGGINGS, Material.IRON_BOOTS, Material.IRON_CHESTPLATE }; chest.getInventory().clear(); chest.getInventory().setItem(slot1, new ItemStack(items[random.nextInt(items.length)])); chest.getInventory().setItem(slot2, new ItemStack(items[random.nextInt(items.length)])); chest.getInventory().setItem(slot3, new ItemStack(items[random.nextInt(items.length)])); } } } } NOTES * Change the "Core.forsakenAscension" to your world's name. You could also pass the world in the method parameters if you wanted to.
You might want to check if the next item your are setting doesn't have the same slot id as the other one, so they don't get overridden!
HeavyMine13 That was intentional. Sometimes the item will be overridden, therefore making it so there are less than three items. Thanks though
Maybe you should create the Random instance and items array outside the of the loops because you are creating a new Random instance and items array for every chest in the world.