Advertisement
maol3

Untitled

Mar 9th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. @EventHandler
  2. public void onPlayerInteract(PlayerInteractEvent e) {
  3. if(player.getInventory().getItemInHand().getType() == Material.STORAGE_MINECART) {
  4. if(player.getInventory().getItemInHand().hasItemMeta() && player.getInventory().getItemInHand().getItemMeta().hasDisplayName() && player.getInventory().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("§cMystery Box")) {
  5. TitleAPI.sendTitle(player, 5, 30, 5, "§cTake cover!", " ");
  6. e.getClickedBlock().getLocation().getWorld().spawnFallingBlock(e.getClickedBlock().getLocation(), Material.CHEST, (byte) 0);
  7. player.getInventory().setItemInHand(null);
  8.  
  9. final Location chestLocation = new Location(e.getClickedBlock().getWorld(), e.getClickedBlock().getLocation().getBlockX(), e.getClickedBlock().getLocation().getBlockY() + 1, e.getClickedBlock().getLocation().getBlockZ());
  10.  
  11. Bukkit.getScheduler().scheduleSyncDelayedTask(main, new Runnable() {
  12. @Override
  13. public void run() {
  14. e.getClickedBlock().getWorld().createExplosion(e.getClickedBlock().getLocation().getX(), e.getClickedBlock().getLocation().getY(), e.getClickedBlock().getLocation().getZ(), 10F, false, false);
  15. e.getClickedBlock().getWorld().getBlockAt(chestLocation).setType(Material.CHEST);
  16. GameHandler.setMysteryBox(chestLocation);
  17. }
  18. }, 40L);
  19. }
  20. }
  21. }
  22.  
  23. public static void setMysteryBox(Location location) {
  24. Chest chest = (Chest) location.getBlock();
  25. Inventory chestInv = chest.getBlockInventory();
  26.  
  27. int success = 1 + (int) (Math.random() * 1);
  28.  
  29. if(success == 1) chestInv.setItem(13, new ItemStack(Material.DIAMOND_SWORD, 1));
  30. else if(success == 2) chestInv.setItem(13, new ItemStack(Material.IRON_CHESTPLATE, 1));
  31.  
  32. chest.update();
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement