Java Code Examples for org.bukkit.event.entity.EntityExplodeEvent#isCancelled()

The following examples show how to use org.bukkit.event.entity.EntityExplodeEvent#isCancelled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onExplode(EntityExplodeEvent event) {
    if (event.isCancelled()) {
        return;
    }

    final String explosionExceptionTypeName = Main.getConfigurator().config.getString("destroy-placed-blocks-by-explosion-except", null);
    final boolean destroyPlacedBlocksByExplosion = Main.getConfigurator().config.getBoolean("destroy-placed-blocks-by-explosion", true);

    for (String gameName : Main.getGameNames()) {
        Game game = Main.getGame(gameName);
        if (game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) {
            if (GameCreator.isInArea(event.getLocation(), game.getPos1(), game.getPos2())) {
                if (destroyPlacedBlocksByExplosion) {
                    event.blockList().removeIf(block -> (explosionExceptionTypeName != null && !explosionExceptionTypeName.equals("") && block.getType().name().contains(explosionExceptionTypeName)) || !game.isBlockAddedDuringGame(block.getLocation()));
                } else {
                    event.blockList().clear();
                }
            }
        }
    }

}
 
Example 2
Source File: WorldListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onExplode(EntityExplodeEvent event) {
    if (event.isCancelled()) {
        return;
    }

    final String explosionExceptionTypeName = Main.getConfigurator().config.getString("destroy-placed-blocks-by-explosion-except", null);
    final boolean destroyPlacedBlocksByExplosion = Main.getConfigurator().config.getBoolean("destroy-placed-blocks-by-explosion", true);

    for (String gameName : Main.getGameNames()) {
        Game game = Main.getGame(gameName);
        if (game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) {
            if (GameCreator.isInArea(event.getLocation(), game.getPos1(), game.getPos2())) {
                if (destroyPlacedBlocksByExplosion) {
                    event.blockList().removeIf(block -> (explosionExceptionTypeName != null && !explosionExceptionTypeName.equals("") && block.getType().name().contains(explosionExceptionTypeName)) || !game.isBlockAddedDuringGame(block.getLocation()));
                } else {
                    event.blockList().clear();
                }
            }
        }
    }

}
 
Example 3
Source File: LWCEntityListener.java    From Modern-LWC with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onEntityExplode(EntityExplodeEvent event) {
    if (!LWC.ENABLED || event.isCancelled()) {
        return;
    }

    LWC lwc = LWC.getInstance();

    for (Block block : event.blockList()) {
        Protection protection = plugin.getLWC().findProtection(block.getLocation());

        if (protection != null) {
            boolean ignoreExplosions = Boolean
                    .parseBoolean(lwc.resolveProtectionConfiguration(protection.getBlock(), "ignoreExplosions"));

            if (!(ignoreExplosions || protection.hasFlag(Flag.Type.ALLOWEXPLOSIONS))) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 4
Source File: Blockdrops.java    From CardinalPGM with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityExplode(EntityExplodeEvent event) {
    if (!event.isCancelled()) {
        Player player = TntTracker.getWhoPlaced(event.getEntity()) != null && Bukkit.getOfflinePlayer(TntTracker.getWhoPlaced(event.getEntity())).isOnline() ? Bukkit.getPlayer(TntTracker.getWhoPlaced(event.getEntity())) : null;
        if (player != null) {
            List<Block> toRemove = new ArrayList<>();
            for (Block block : event.blockList()) {
                if (filter == null || filter.evaluate(player, block, event).equals(FilterState.ALLOW)) {
                    if (region == null || region.contains(block.getLocation().toVector().add(new Vector(0.5, 0.5, 0.5)))) {
                        for (ItemStack drop : this.drops) {
                            GameHandler.getGameHandler().getMatchWorld().dropItemNaturally(block.getLocation(), drop);
                        }
                        if (this.experience != 0) {
                            ExperienceOrb xp = GameHandler.getGameHandler().getMatchWorld().spawn(block.getLocation(), ExperienceOrb.class);
                            xp.setExperience(this.experience);
                        }
                        toRemove.add(block);
                        block.setType(replaceType);
                        block.setData((byte) replaceDamage);
                    }
                }
            }
            event.blockList().removeAll(toRemove);
        }
    }
}
 
Example 5
Source File: SpleefTracker.java    From CardinalPGM with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityExplode(EntityExplodeEvent event) {
    if (event.isCancelled() || GameHandler.getGameHandler().getMatch().getModules().getModule(TitleRespawn.class).isDeadUUID(event.getEntity().getUniqueId())) return;
    for (Block block : event.blockList()) {
        for (Player player : Bukkit.getOnlinePlayers()) {
            Location location = block.getLocation();
            location.setY(location.getY() + 1);
            Location playerLoc = player.getLocation();
            if (playerLoc.getBlockX() == location.getBlockX() && playerLoc.getBlockY() == location.getBlockY() && playerLoc.getBlockZ() == location.getBlockZ()) {
                Description description = null;
                if (player.getLocation().add(new Vector(0, 1, 0)).getBlock().getType().equals(Material.LADDER)) {
                    description = Description.OFF_A_LADDER;
                } else if (player.getLocation().add(new Vector(0, 1, 0)).getBlock().getType().equals(Material.VINE)) {
                    description = Description.OFF_A_VINE;
                } else if (player.getLocation().getBlock().getType().equals(Material.WATER) || player.getLocation().getBlock().getType().equals(Material.STATIONARY_WATER)) {
                    description = Description.OUT_OF_THE_WATER;
                } else if (player.getLocation().getBlock().getType().equals(Material.LAVA) || player.getLocation().getBlock().getType().equals(Material.STATIONARY_LAVA)) {
                    description = Description.OUT_OF_THE_LAVA;
                }
                OfflinePlayer damager = (TntTracker.getWhoPlaced(event.getEntity()) != null ? Bukkit.getOfflinePlayer(TntTracker.getWhoPlaced(event.getEntity())) : null);
                Bukkit.getServer().getPluginManager().callEvent(new TrackerDamageEvent(player, damager, damager != null && damager.getPlayer() != null ? ((Player) damager).getInventory().getItemInMainHand() : new ItemStack(Material.AIR), Cause.TNT, description, Type.SPLEEFED));
            }
        }
    }
}
 
Example 6
Source File: EntityEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityExplodeEvent(EntityExplodeEvent event) {
    final World world = event.getEntity().getLocation().getWorld();
    if (!GDFlags.EXPLOSION_BLOCK || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
        return;
    }

    GDCauseStackManager.getInstance().pushCause(event.getEntity());
    // check entity tracker
    final GDEntity gdEntity = EntityTracker.getCachedEntity(event.getEntity().getEntityId());
    GDPermissionUser user = null;
    if (gdEntity != null) {
        user = PermissionHolderCache.getInstance().getOrCreateUser(gdEntity.getOwnerUUID());
    }

    Entity source = event.getEntity();
    if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.EXPLOSION_BLOCK.toString(), source, world.getUID())) {
        return;
    }

    final String sourceId = GDPermissionManager.getInstance().getPermissionIdentifier(source);
    boolean denySurfaceExplosion = GriefDefenderPlugin.getActiveConfig(world.getUID()).getConfig().claim.explosionBlockSurfaceBlacklist.contains(sourceId);
    if (!denySurfaceExplosion) {
        denySurfaceExplosion = GriefDefenderPlugin.getActiveConfig(world.getUID()).getConfig().claim.explosionBlockSurfaceBlacklist.contains("any");
    }
    GDTimings.EXPLOSION_EVENT.startTiming();
    GDClaim targetClaim = null;
    final int cancelBlockLimit = GriefDefenderPlugin.getGlobalConfig().getConfig().claim.explosionCancelBlockLimit;
    final List<Block> filteredLocations = new ArrayList<>();
    for (Block block : event.blockList()) {
        final Location location = block.getLocation();
        targetClaim =  GriefDefenderPlugin.getInstance().dataStore.getClaimAt(location);
        if (denySurfaceExplosion && block.getWorld().getEnvironment() != Environment.NETHER && location.getBlockY() >= location.getWorld().getSeaLevel()) {
            filteredLocations.add(block);
            GDPermissionManager.getInstance().processEventLog(event, location, targetClaim, Flags.EXPLOSION_BLOCK.getPermission(), source, block, user, "explosion-surface", Tristate.FALSE);
            continue;
        }
        final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.EXPLOSION_BLOCK, source, block, user, true);
        if (result == Tristate.FALSE) {
            // Avoid lagging server from large explosions.
            if (event.blockList().size() > cancelBlockLimit) {
                event.setCancelled(true);
                break;
            }
            filteredLocations.add(block);
        }
    }

    if (event.isCancelled()) {
        event.blockList().clear();
    } else if (!filteredLocations.isEmpty()) {
        event.blockList().removeAll(filteredLocations);
    }
    GDTimings.EXPLOSION_EVENT.stopTiming();
}
 
Example 7
Source File: ChunkEventHelper.java    From ClaimChunk with MIT License 4 votes vote down vote up
public static void handleExplosionIfConfig(@Nonnull EntityExplodeEvent e) {
    if (e.isCancelled()) return;

    final ChunkHandler CHUNK_HANLDE = ClaimChunk.getInstance().getChunkHandler();

    final EntityType TYPE = e.getEntityType();
    final Chunk CHUNK = e.getLocation().getChunk();

    // If the explosion is within a claimed chunk, it will cancel the whole
    // event.
    boolean inClaimedChunk = CHUNK_HANLDE.isClaimed(CHUNK);
    boolean hardCancel = inClaimedChunk || blockUnclaimedChunk(CHUNK.getWorld().getName());

    // If the event is TNT/Mincart TNT related, it should be cancelled
    boolean isTnt = TYPE == EntityType.PRIMED_TNT || TYPE == EntityType.MINECART_TNT;
    boolean protectTnt = isTnt && config.getBool("protection", "blockTnt");
    // If TNT is blocked, check if the user has used `/chunk tnt` to enable
    // it in this chunk.
    if (protectTnt && CHUNK_HANLDE.isTntEnabled(CHUNK)) {
        protectTnt = false;
    }
    if (protectTnt) {
        cancelExplosionEvent(hardCancel, e);
        return;
    }

    // Cancel crepper explosions if protection against them is enabled
    // within the config.
    boolean isCreeper = TYPE == EntityType.CREEPER;
    if (isCreeper && config.getBool("protection", "blockCreeper")) {
        cancelExplosionEvent(hardCancel, e);
        return;
    }

    // If wither damage is prevented within the config, cancel this event
    // if it's a wither event.
    boolean isWither = TYPE == EntityType.WITHER || TYPE == EntityType.WITHER_SKULL;
    if (isWither && config.getBool("protection", "blockWither")) {
        cancelExplosionEvent(hardCancel, e);
    }
}
 
Example 8
Source File: EntityListener.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onExplodeDestroy(EntityExplodeEvent eev) {
  if (eev.isCancelled()) {
    return;
  }

  if (eev.getEntity() == null) {
    return;
  }

  if (eev.getEntity().getWorld() == null) {
    return;
  }

  Game game =
      BedwarsRel.getInstance().getGameManager().getGameByLocation(eev.getEntity().getLocation());

  if (game == null) {
    return;
  }

  if (game.getState() == GameState.STOPPED) {
    return;
  }

  Iterator<Block> explodeBlocks = eev.blockList().iterator();
  boolean tntDestroyEnabled =
      BedwarsRel.getInstance().getBooleanConfig("explodes.destroy-worldblocks", false);
  boolean tntDestroyBeds = BedwarsRel
      .getInstance().getBooleanConfig("explodes.destroy-beds", false);

  if (!BedwarsRel.getInstance().getBooleanConfig("explodes.drop-blocks", false)) {
    eev.setYield(0F);
  }

  Material targetMaterial = game.getTargetMaterial();
  while (explodeBlocks.hasNext()) {
    Block exploding = explodeBlocks.next();
    if (!game.getRegion().isInRegion(exploding.getLocation())) {
      explodeBlocks.remove();
      continue;
    }

    if ((!tntDestroyEnabled && !tntDestroyBeds) || (!tntDestroyEnabled && tntDestroyBeds
        && exploding.getType() != Material.BED_BLOCK && exploding.getType() != Material.BED)) {
      if (!game.getRegion().isPlacedBlock(exploding)) {
        if (BedwarsRel.getInstance().isBreakableType(exploding.getType())) {
          game.getRegion().addBreakedBlock(exploding);
          continue;
        }

        explodeBlocks.remove();
      } else {
        game.getRegion().removePlacedBlock(exploding);
      }

      continue;
    }

    if (game.getRegion().isPlacedBlock(exploding)) {
      game.getRegion().removePlacedBlock(exploding);
      continue;
    }

    if (exploding.getType().equals(targetMaterial)) {
      if (!tntDestroyBeds) {
        explodeBlocks.remove();
        continue;
      }

      // only destroyable by tnt
      if (!eev.getEntityType().equals(EntityType.PRIMED_TNT)
          && !eev.getEntityType().equals(EntityType.MINECART_TNT)) {
        explodeBlocks.remove();
        continue;
      }

      // when it wasn't player who ignited the tnt
      TNTPrimed primedTnt = (TNTPrimed) eev.getEntity();
      if (!(primedTnt.getSource() instanceof Player)) {
        explodeBlocks.remove();
        continue;
      }

      Player p = (Player) primedTnt.getSource();
      if (!game.handleDestroyTargetMaterial(p, exploding)) {
        explodeBlocks.remove();
        continue;
      }
    } else {
      game.getRegion().addBreakedBlock(exploding);
    }
  }
}
 
Example 9
Source File: WarListener.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onEntityExplode(EntityExplodeEvent event) {
		
	if (event.isCancelled()) {
		return;
	}
	
	if (!War.isWarTime()) {
		return;
	}
	
	if (event.getEntity() == null) {
		return;
	}
	
	if (event.getEntityType().equals(EntityType.UNKNOWN)) {
		return;
	}
	
	if (event.getEntityType().equals(EntityType.PRIMED_TNT) ||
			event.getEntityType().equals(EntityType.MINECART_TNT)) {
					
		int yield;
		try {
			yield = CivSettings.getInteger(CivSettings.warConfig, "cannon.yield");
		} catch (InvalidConfiguration e) {
			e.printStackTrace();
			return;
		}
	
		yield = yield / 2;
	
		for (int y = -yield; y <= yield; y++) {
			for (int x = -yield; x <= yield; x++) {
				for (int z = -yield; z <= yield; z++) {
					Location loc = event.getLocation().clone().add(new Vector(x,y,z));
				
					if (loc.distance(event.getLocation()) < yield) {
						WarRegen.saveBlock(loc.getBlock(), Cannon.RESTORE_NAME, false);
						ItemManager.setTypeIdAndData(loc.getBlock(), CivData.AIR, 0, false);
					}
				}	
			}
		}
		event.setCancelled(true);
	}
}
 
Example 10
Source File: LoggingManager.java    From Survival-Games with GNU General Public License v3.0 3 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void blockChange(EntityExplodeEvent e){
	if(e.isCancelled())return;

	for(Block b :e.blockList()){
		logBlockDestoryed(b);
		//        System.out.println(4);

	}

	i.put("BBLOW", i.get("BBLOW")+1);

}