Exemplo n.º 1
0
 /**
  * Handles explosion block damage caused by TnT, Creepers, or Fireballs.<br>
  * If the arena allows explosion block breaking, each block is handled separately<br>
  * as if a player attempted to destroy it. If the arena doesn't allow explosion block breaking,
  * <br>
  * no blocks are broken.
  */
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onTntExplode(EntityExplodeEvent event) {
   Entity entity = event.getEntity();
   if (entity instanceof TNTPrimed || entity instanceof Creeper || entity instanceof Fireball) {
     Arena arena = ultimateGames.getArenaManager().getLocationArena(entity.getLocation());
     if (arena != null) {
       if (arena.getStatus() == ArenaStatus.RUNNING) {
         if (arena.allowExplosionBlockBreaking()) {
           Set<Block> canBeBroken =
               ultimateGames
                   .getWhitelistManager()
                   .getBlockBreakWhitelist()
                   .blocksWhitelisted(arena.getGame(), new HashSet<Block>(event.blockList()));
           event.blockList().clear();
           event.blockList().addAll(canBeBroken);
           arena.getGame().getGamePlugin().onEntityExplode(arena, event);
         } else if (arena.allowExplosionDamage()) {
           event.blockList().clear();
           arena.getGame().getGamePlugin().onEntityExplode(arena, event);
         } else {
           event.setCancelled(true);
         }
       } else {
         event.setCancelled(true);
       }
     }
   }
 }
Exemplo n.º 2
0
  @SuppressWarnings("deprecation")
  public void onExpload(EntityExplodeEvent event) {
    List<Block> blocks = event.blockList();
    final ArrayList<Block> replaceBlocks = new ArrayList<Block>();
    Land land = new Land();
    for (Block block : blocks) {
      Location blockLoc = block.getLocation();
      if (land.getInVillage(blockLoc)) {
        replaceBlocks.add(block);
      }
    }
    Bukkit.getScheduler()
        .scheduleAsyncDelayedTask(
            instance,
            new Runnable() {

              @Override
              public void run() {
                for (Block block : replaceBlocks) {}
              }
            },
            5L);
  }