Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private HashSet<Block> opened = new HashSet<>();
- @EventHandler
- public void onOpen(InventoryOpenEvent e){
- if (GameStateManager.getGameState() != GameStates.INGAME) return;
- if (e.getInventory().getHolder() instanceof Chest){
- Block b = (Block) e.getInventory().getHolder();
- if (!opened.contains(b)){
- opened.add(b);
- addItems(e.getInventory(), 1);
- }
- } else if (e.getInventory().getHolder() instanceof EnderChest){
- Block b = (Block) e.getInventory().getHolder();
- if (!opened.contains(b)){
- opened.add(b);
- addItems(e.getInventory(), 2);
- }
- }
- }
- private void addItems(Inventory inventory, Integer tier){
- Random rand = new Random();
- int x = rand.nextInt(7) + 2;
- for (int i = 0; i < x; i++){
- int randomslot = rand.nextInt(inventory.getSize());
- int randomarray = rand.nextInt(randomItems(tier).size());
- inventory.setItem(randomslot, randomItems(tier).get(randomarray));
- }
- }
- private List<ItemStack> randomItems(Integer tier){
- Random r = new Random();
- ItemStack is;
- int x = r.nextInt(4) + 1;
- if (tier == 1) {
- is = new ItemStack(Material.ENDER_PEARL);
- is.setAmount(x);
- randomItems(tier).add(is);
- is = new ItemStack(Material.GOLDEN_APPLE);
- x = r.nextInt(5) + 1;
- is.setAmount(x);
- randomItems(tier).add(is);
- is = new ItemStack(Material.ARROW);
- x = r.nextInt(17) + 4;
- is.setAmount(x);
- randomItems(tier).add(is);
- is = new ItemStack(Material.BOW);
- is.addEnchantment(Enchantment.ARROW_DAMAGE, 1);
- randomItems(tier).add(is);
- is = new ItemStack(Material.ENCHANTED_BOOK);
- EnchantmentStorageMeta meta = (EnchantmentStorageMeta) is.getItemMeta();
- meta.addStoredEnchant(Enchantment.DAMAGE_ALL, 1, true);
- is.setItemMeta(meta);
- randomItems(tier).add(is);
- is = new ItemStack(Material.ENCHANTED_BOOK);
- meta = (EnchantmentStorageMeta) is.getItemMeta();
- meta.addStoredEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1, true);
- is.setItemMeta(meta);
- randomItems(tier).add(is);
- is = new ItemStack(Material.ENCHANTED_BOOK);
- meta = (EnchantmentStorageMeta) is.getItemMeta();
- meta.addStoredEnchant(Enchantment.ARROW_DAMAGE, 1, true);
- is.setItemMeta(meta);
- randomItems(tier).add(is);
- is = new ItemStack(Material.STICK);
- x = r.nextInt(6) + 1;
- is.setAmount(x);
- randomItems(tier).add(is);
- is = new ItemStack(Material.FLINT);
- x = r.nextInt(6) + 1;
- is.setAmount(x);
- randomItems(tier).add(is);
- is = new ItemStack(Material.FEATHER);
- x = r.nextInt(6) + 1;
- is.setAmount(x);
- randomItems(tier).add(is);
- is = new ItemStack(Material.STRING);
- x = r.nextInt(3) + 1;
- is.setAmount(x);
- randomItems(tier).add(is);
- is = new ItemStack(Material.APPLE);
- x = r.nextInt(3) + 1;
- is.setAmount(x);
- randomItems(tier).add(is);
- is = new ItemStack(Material.GOLD_INGOT);
- x = r.nextInt(6) + 1;
- is.setAmount(x);
- randomItems(tier).add(is);
- is = new ItemStack(Material.COBBLESTONE);
- x = r.nextInt(17) + 1;
- is.setAmount(x);
- randomItems(tier).add(is);
- is = new ItemStack(Material.WATER);
- randomItems(tier).add(is);
- is = new ItemStack(Material.DIAMOND);
- randomItems(tier).add(is);
- } else {
- is = new ItemStack(Material.ENDER_PEARL);
- x = r.nextInt(6) + 1;
- is.setAmount(x);
- randomItems(tier).add(is);
- is = new ItemStack(Material.GOLDEN_APPLE);
- x = r.nextInt(7) + 2;
- is.setAmount(x);
- randomItems(tier).add(is);
- is = new ItemStack(Material.ARROW);
- x = r.nextInt(17) + 4;
- is.setAmount(x);
- randomItems(tier).add(is);
- is = new ItemStack(Material.DIAMOND_SWORD);
- randomItems(tier).add(is);
- is = new ItemStack(Material.IRON_SWORD);
- randomItems(tier).add(is);
- is = new ItemStack(Material.ENCHANTED_BOOK);
- EnchantmentStorageMeta meta = (EnchantmentStorageMeta) is.getItemMeta();
- meta.addStoredEnchant(Enchantment.DAMAGE_ALL, 2, true);
- is.setItemMeta(meta);
- randomItems(tier).add(is);
- is = new ItemStack(Material.ENCHANTED_BOOK);
- meta = (EnchantmentStorageMeta) is.getItemMeta();
- meta.addStoredEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 2, true);
- is.setItemMeta(meta);
- randomItems(tier).add(is);
- is = new ItemStack(Material.ENCHANTED_BOOK);
- meta = (EnchantmentStorageMeta) is.getItemMeta();
- meta.addStoredEnchant(Enchantment.ARROW_DAMAGE, 2, true);
- is.setItemMeta(meta);
- randomItems(tier).add(is);
- is = new ItemStack(Material.ENCHANTED_BOOK);
- meta = (EnchantmentStorageMeta) is.getItemMeta();
- meta.addStoredEnchant(Enchantment.DAMAGE_ALL, 3, true);
- is.setItemMeta(meta);
- randomItems(tier).add(is);
- is = new ItemStack(Material.ENCHANTED_BOOK);
- meta = (EnchantmentStorageMeta) is.getItemMeta();
- meta.addStoredEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 3, true);
- is.setItemMeta(meta);
- randomItems(tier).add(is);
- is = new ItemStack(Material.ENCHANTED_BOOK);
- meta = (EnchantmentStorageMeta) is.getItemMeta();
- meta.addStoredEnchant(Enchantment.ARROW_DAMAGE, 3, true);
- is.setItemMeta(meta);
- randomItems(tier).add(is);
- is = new ItemStack(Material.DIAMOND_CHESTPLATE);
- randomItems(tier).add(is);
- is = new ItemStack(Material.DIAMOND_LEGGINGS);
- randomItems(tier).add(is);
- is = new ItemStack(Material.DIAMOND_HELMET);
- randomItems(tier).add(is);
- is = new ItemStack(Material.DIAMOND_BOOTS);
- randomItems(tier).add(is);
- }
- return new ArrayList<>(randomItems(tier));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement