Advertisement
phanatic

Untitled

Nov 4th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.72 KB | None | 0 0
  1. private HashSet<Block> opened = new HashSet<>();
  2. @EventHandler
  3. public void onOpen(InventoryOpenEvent e){
  4. if (GameStateManager.getGameState() != GameStates.INGAME) return;
  5. if (e.getInventory().getHolder() instanceof Chest){
  6. Block b = (Block) e.getInventory().getHolder();
  7. if (!opened.contains(b)){
  8. opened.add(b);
  9.  
  10. addItems(e.getInventory(), 1);
  11. }
  12. } else if (e.getInventory().getHolder() instanceof EnderChest){
  13. Block b = (Block) e.getInventory().getHolder();
  14. if (!opened.contains(b)){
  15. opened.add(b);
  16. addItems(e.getInventory(), 2);
  17.  
  18. }
  19. }
  20. }
  21.  
  22. private void addItems(Inventory inventory, Integer tier){
  23. Random rand = new Random();
  24. int x = rand.nextInt(7) + 2;
  25. for (int i = 0; i < x; i++){
  26. int randomslot = rand.nextInt(inventory.getSize());
  27. int randomarray = rand.nextInt(randomItems(tier).size());
  28. inventory.setItem(randomslot, randomItems(tier).get(randomarray));
  29. }
  30. }
  31.  
  32. private List<ItemStack> randomItems(Integer tier){
  33. Random r = new Random();
  34. ItemStack is;
  35. int x = r.nextInt(4) + 1;
  36. if (tier == 1) {
  37. is = new ItemStack(Material.ENDER_PEARL);
  38. is.setAmount(x);
  39. randomItems(tier).add(is);
  40.  
  41. is = new ItemStack(Material.GOLDEN_APPLE);
  42. x = r.nextInt(5) + 1;
  43. is.setAmount(x);
  44. randomItems(tier).add(is);
  45.  
  46. is = new ItemStack(Material.ARROW);
  47. x = r.nextInt(17) + 4;
  48. is.setAmount(x);
  49. randomItems(tier).add(is);
  50.  
  51. is = new ItemStack(Material.BOW);
  52. is.addEnchantment(Enchantment.ARROW_DAMAGE, 1);
  53. randomItems(tier).add(is);
  54.  
  55. is = new ItemStack(Material.ENCHANTED_BOOK);
  56. EnchantmentStorageMeta meta = (EnchantmentStorageMeta) is.getItemMeta();
  57. meta.addStoredEnchant(Enchantment.DAMAGE_ALL, 1, true);
  58. is.setItemMeta(meta);
  59. randomItems(tier).add(is);
  60.  
  61. is = new ItemStack(Material.ENCHANTED_BOOK);
  62. meta = (EnchantmentStorageMeta) is.getItemMeta();
  63. meta.addStoredEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1, true);
  64. is.setItemMeta(meta);
  65. randomItems(tier).add(is);
  66.  
  67. is = new ItemStack(Material.ENCHANTED_BOOK);
  68. meta = (EnchantmentStorageMeta) is.getItemMeta();
  69. meta.addStoredEnchant(Enchantment.ARROW_DAMAGE, 1, true);
  70. is.setItemMeta(meta);
  71. randomItems(tier).add(is);
  72.  
  73. is = new ItemStack(Material.STICK);
  74. x = r.nextInt(6) + 1;
  75. is.setAmount(x);
  76. randomItems(tier).add(is);
  77.  
  78. is = new ItemStack(Material.FLINT);
  79. x = r.nextInt(6) + 1;
  80. is.setAmount(x);
  81. randomItems(tier).add(is);
  82.  
  83. is = new ItemStack(Material.FEATHER);
  84. x = r.nextInt(6) + 1;
  85. is.setAmount(x);
  86. randomItems(tier).add(is);
  87.  
  88. is = new ItemStack(Material.STRING);
  89. x = r.nextInt(3) + 1;
  90. is.setAmount(x);
  91. randomItems(tier).add(is);
  92.  
  93. is = new ItemStack(Material.APPLE);
  94. x = r.nextInt(3) + 1;
  95. is.setAmount(x);
  96. randomItems(tier).add(is);
  97.  
  98. is = new ItemStack(Material.GOLD_INGOT);
  99. x = r.nextInt(6) + 1;
  100. is.setAmount(x);
  101. randomItems(tier).add(is);
  102.  
  103. is = new ItemStack(Material.COBBLESTONE);
  104. x = r.nextInt(17) + 1;
  105. is.setAmount(x);
  106. randomItems(tier).add(is);
  107.  
  108. is = new ItemStack(Material.WATER);
  109. randomItems(tier).add(is);
  110.  
  111. is = new ItemStack(Material.DIAMOND);
  112. randomItems(tier).add(is);
  113.  
  114. } else {
  115. is = new ItemStack(Material.ENDER_PEARL);
  116. x = r.nextInt(6) + 1;
  117. is.setAmount(x);
  118. randomItems(tier).add(is);
  119.  
  120. is = new ItemStack(Material.GOLDEN_APPLE);
  121. x = r.nextInt(7) + 2;
  122. is.setAmount(x);
  123. randomItems(tier).add(is);
  124.  
  125. is = new ItemStack(Material.ARROW);
  126. x = r.nextInt(17) + 4;
  127. is.setAmount(x);
  128. randomItems(tier).add(is);
  129.  
  130. is = new ItemStack(Material.DIAMOND_SWORD);
  131. randomItems(tier).add(is);
  132.  
  133. is = new ItemStack(Material.IRON_SWORD);
  134. randomItems(tier).add(is);
  135.  
  136. is = new ItemStack(Material.ENCHANTED_BOOK);
  137. EnchantmentStorageMeta meta = (EnchantmentStorageMeta) is.getItemMeta();
  138. meta.addStoredEnchant(Enchantment.DAMAGE_ALL, 2, true);
  139. is.setItemMeta(meta);
  140. randomItems(tier).add(is);
  141.  
  142. is = new ItemStack(Material.ENCHANTED_BOOK);
  143. meta = (EnchantmentStorageMeta) is.getItemMeta();
  144. meta.addStoredEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 2, true);
  145. is.setItemMeta(meta);
  146. randomItems(tier).add(is);
  147.  
  148. is = new ItemStack(Material.ENCHANTED_BOOK);
  149. meta = (EnchantmentStorageMeta) is.getItemMeta();
  150. meta.addStoredEnchant(Enchantment.ARROW_DAMAGE, 2, true);
  151. is.setItemMeta(meta);
  152. randomItems(tier).add(is);
  153.  
  154. is = new ItemStack(Material.ENCHANTED_BOOK);
  155. meta = (EnchantmentStorageMeta) is.getItemMeta();
  156. meta.addStoredEnchant(Enchantment.DAMAGE_ALL, 3, true);
  157. is.setItemMeta(meta);
  158. randomItems(tier).add(is);
  159.  
  160. is = new ItemStack(Material.ENCHANTED_BOOK);
  161. meta = (EnchantmentStorageMeta) is.getItemMeta();
  162. meta.addStoredEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 3, true);
  163. is.setItemMeta(meta);
  164. randomItems(tier).add(is);
  165.  
  166. is = new ItemStack(Material.ENCHANTED_BOOK);
  167. meta = (EnchantmentStorageMeta) is.getItemMeta();
  168. meta.addStoredEnchant(Enchantment.ARROW_DAMAGE, 3, true);
  169. is.setItemMeta(meta);
  170. randomItems(tier).add(is);
  171.  
  172. is = new ItemStack(Material.DIAMOND_CHESTPLATE);
  173. randomItems(tier).add(is);
  174.  
  175. is = new ItemStack(Material.DIAMOND_LEGGINGS);
  176. randomItems(tier).add(is);
  177.  
  178. is = new ItemStack(Material.DIAMOND_HELMET);
  179. randomItems(tier).add(is);
  180.  
  181. is = new ItemStack(Material.DIAMOND_BOOTS);
  182. randomItems(tier).add(is);
  183.  
  184. }
  185. return new ArrayList<>(randomItems(tier));
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement