Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @EventHandler
- public void onPlayerInteract(PlayerInteractEvent e) {
- if(player.getInventory().getItemInHand().getType() == Material.STORAGE_MINECART) {
- if(player.getInventory().getItemInHand().hasItemMeta() && player.getInventory().getItemInHand().getItemMeta().hasDisplayName() && player.getInventory().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("§cMystery Box")) {
- TitleAPI.sendTitle(player, 5, 30, 5, "§cTake cover!", " ");
- e.getClickedBlock().getLocation().getWorld().spawnFallingBlock(e.getClickedBlock().getLocation(), Material.CHEST, (byte) 0);
- player.getInventory().setItemInHand(null);
- final Location chestLocation = new Location(e.getClickedBlock().getWorld(), e.getClickedBlock().getLocation().getBlockX(), e.getClickedBlock().getLocation().getBlockY() + 1, e.getClickedBlock().getLocation().getBlockZ());
- Bukkit.getScheduler().scheduleSyncDelayedTask(main, new Runnable() {
- @Override
- public void run() {
- e.getClickedBlock().getWorld().createExplosion(e.getClickedBlock().getLocation().getX(), e.getClickedBlock().getLocation().getY(), e.getClickedBlock().getLocation().getZ(), 10F, false, false);
- e.getClickedBlock().getWorld().getBlockAt(chestLocation).setType(Material.CHEST);
- GameHandler.setMysteryBox(chestLocation);
- }
- }, 40L);
- }
- }
- }
- public static void setMysteryBox(Location location) {
- Chest chest = (Chest) location.getBlock();
- Inventory chestInv = chest.getBlockInventory();
- int success = 1 + (int) (Math.random() * 1);
- if(success == 1) chestInv.setItem(13, new ItemStack(Material.DIAMOND_SWORD, 1));
- else if(success == 2) chestInv.setItem(13, new ItemStack(Material.IRON_CHESTPLATE, 1));
- chest.update();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement