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

The following examples show how to use org.bukkit.event.entity.EntityExplodeEvent#blockList() . 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: 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 2
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 3
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 4
Source File: BlockListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityExplode(EntityExplodeEvent e) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockListener - EntityExplodeEvent event");
    List<Block> toRemove = new ArrayList<>();

    Region or = RedProtect.get().rm.getTopRegion(e.getEntity().getLocation());
    for (Block b : e.blockList()) {
        if (b == null) {
            continue;
        }
        RedProtect.get().logger.debug(LogLevel.BLOCKS, "Blocks: " + b.getType().name());
        Location l = b.getLocation();
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canFire() || !cont.canWorldBreak(b)) {
            RedProtect.get().logger.debug(LogLevel.BLOCKS, "canWorldBreak Called!");
            //e.setCancelled(true);
            toRemove.add(b);
            continue;
        }

        if (r == null) {
            continue;
        }

        if (r != or) {
            toRemove.add(b);
            continue;
        }

        if (e.getEntity() instanceof LivingEntity && !r.canMobLoot()) {
            toRemove.add(b);
        }
    }
    if (!toRemove.isEmpty()) {
        e.blockList().removeAll(toRemove);
    }
}
 
Example 5
Source File: FlagSplegg.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
	Entity entity = event.getEntity();
	
	Game game = null;
	List<MetadataValue> metadatas = entity.getMetadata(TNT_METADATA_KEY);
	for (MetadataValue value : metadatas) {
		if (value.getOwningPlugin() != getHeavySpleef().getPlugin()) {
			continue;
		}
		
		game = (Game) value.value();
	}
	
	if (game != null) {
		List<Block> blocks = event.blockList();
		for (Block block : blocks) {
			if (!game.canSpleef(block)) {
				continue;
			}
			
			block.setType(Material.AIR);
		}
		
		blocks.clear();
	}
}
 
Example 6
Source File: Tnt.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityExplode(EntityExplodeEvent event) {
    if (GameHandler.getGameHandler().getMatch().isRunning() && event.getEntity() instanceof TNTPrimed) {
        if (!blockDamage) {
            event.blockList().clear();
        } else if (yield != 0.3){
            event.setYield((float)yield);
        }
        UUID player = TntTracker.getWhoPlaced(event.getEntity());
        for (Block block : event.blockList()) {
            if (block.getState() instanceof Dispenser) {
                Inventory inventory = ((Dispenser) block.getState()).getInventory();
                Location location = block.getLocation();
                double tntCount = 0;
                for (ItemStack itemstack : inventory.getContents()) {
                    if (itemstack != null && itemstack.getType() == Material.TNT) tntCount += itemstack.getAmount() * multiplier;
                    if (tntCount >= limit) {
                        tntCount = limit;
                        break;
                    }
                }
                inventory.remove(Material.TNT);
                if (tntCount > 0) {
                    Random random = new Random();
                    for (double i = tntCount; i > 0; i--) {
                        TNTPrimed tnt = event.getWorld().spawn(location, TNTPrimed.class);
                        Vector velocity = new Vector((1.5 * random.nextDouble()) - 0.75, (1.5 * random.nextDouble()) - 0.75, (1.5 * random.nextDouble()) - 0.75);
                        tnt.setVelocity(velocity);
                        tnt.setFuseTicks(random.nextInt(10) + 10);
                        if (player != null) {
                            tnt.setMetadata("source", new FixedMetadataValue(Cardinal.getInstance(), player));
                        }
                    }
                }
            }
        }
    }
}
 
Example 7
Source File: TntTracker.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
    if (event.getEntity() != null) {
        if (event.getEntity().getType() == EntityType.PRIMED_TNT) {
            for (Block block : event.blockList()) {
                if (block.getType() == Material.TNT && getWhoPlaced(event.getEntity()) != null) {
                    Location location = block.getLocation();
                    tntPlaced.put(location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ(), getWhoPlaced(event.getEntity()));
                }
            }
        }
    }
}
 
Example 8
Source File: RegionInteractListener.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onExplosion(EntityExplodeEvent event) {
	Location loc = event.getLocation();
	NovaRegion region = RegionManager.get(loc);

	if(region != null) {
		for(Block block : new ArrayList<>(event.blockList())) {
			if(plugin.getGuildManager().isVaultBlock(block) && !region.getGuild().isRaid()) {
				event.blockList().remove(block);
			}
		}

		Message.CHAT_GUILD_EXPLOSIONATREGION.broadcast(region.getGuild());
	}
}
 
Example 9
Source File: ChestProtectListener.java    From ShopChest with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent e) {
    ArrayList<Block> bl = new ArrayList<>(e.blockList());
    for (Block b : bl) {
        if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
            if (shopUtils.isShop(b.getLocation())) e.blockList().remove(b);
        }
    }
}
 
Example 10
Source File: GlobalProtectionListener.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEntityExplode(EntityExplodeEvent event) {
    List<Block> blocklist = event.blockList();
    for (Block block : blocklist) {
        if (plugin.getGlobalProtectionCache().isProtectedBlock(block)) {
            event.setCancelled(true);
        }
    }
}
 
Example 11
Source File: BlockTransformListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventWrapper
public void onEntityExplode(final EntityExplodeEvent event) {
    ParticipantState playerState = entityResolver.getOwner(event.getEntity());

    for(Block block : event.blockList()) {
        if(block.getType() != Material.TNT) {
            // Don't cancel the explosion when individual blocks are cancelled
            callEvent(event, block.getState(), BlockStateUtils.toAir(block), playerState).setPropagateCancel(false);
        }
    }
}
 
Example 12
Source File: BlockTransformListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventWrapper
public void onEntityExplode(final EntityExplodeEvent event) {
  ParticipantState playerState = Trackers.getOwner(event.getEntity());

  for (Block block : event.blockList()) {
    if (block.getType() != Material.TNT) {
      // Don't cancel the explosion when individual blocks are cancelled
      callEvent(event, block.getState(), BlockStates.toAir(block), playerState)
          .setPropagateCancel(false);
    }
  }
}
 
Example 13
Source File: EntityExplodeListener.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMonitorEntityExplode(EntityExplodeEvent event) {
    try {
        final Entity entity = event.getEntity();
        final Location location = entity.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        if (!islandManager.isIslandWorld(location)) return;

        final UUID uuid = entity.getUniqueId();
        final IridiumSkyblock plugin = IridiumSkyblock.getInstance();
        final Map<UUID, Island> entities = plugin.entities;
        Island island = entities.get(uuid);
        if (island != null && island.isInIsland(location)) {
            event.setCancelled(true);
            entity.remove();
            entities.remove(uuid);
            return;
        }

        island = islandManager.getIslandViaLocation(location);
        if (island == null) return;

        for (Block block : event.blockList()) {
            if (!island.isInIsland(block.getLocation())) {
                final BlockState state = block.getState();
                IridiumSkyblock.nms.setBlockFast(block, 0, (byte) 0);
                Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> state.update(true, true));
            }

            if (!Utils.isBlockValuable(block)) continue;

            if (!(block.getState() instanceof CreatureSpawner)) {
                final Material material = block.getType();
                final XMaterial xmaterial = XMaterial.matchXMaterial(material);
                island.valuableBlocks.computeIfPresent(xmaterial.name(), (name, original) -> original - 1);
            }

            if (island.updating)
                island.tempValues.remove(block.getLocation());
        }
        island.calculateIslandValue();
    } catch (Exception ex) {
        IridiumSkyblock.getInstance().sendErrorMessage(ex);
    }
}
 
Example 14
Source File: BlockListener.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void OnEntityExplodeEvent(EntityExplodeEvent event) {
	if (event.getEntity() == null) {
		return;
	}
	/* prevent ender dragons from breaking blocks. */
	if (event.getEntityType().equals(EntityType.COMPLEX_PART)) {
		event.setCancelled(true);
	} else if (event.getEntityType().equals(EntityType.ENDER_DRAGON)) {
		event.setCancelled(true);
	}

	for (Block block : event.blockList()) {
		bcoord.setFromLocation(block.getLocation());
		StructureBlock sb = CivGlobal.getStructureBlock(bcoord);
		if (sb != null) {
			event.setCancelled(true);
			return;
		}

		RoadBlock rb = CivGlobal.getRoadBlock(bcoord);
		if (rb != null) {
			event.setCancelled(true);
			return;
		}

		CampBlock cb = CivGlobal.getCampBlock(bcoord);
		if (cb != null) {
			event.setCancelled(true);
			return;
		}

		StructureSign structSign = CivGlobal.getStructureSign(bcoord);
		if (structSign != null) {
			event.setCancelled(true);
			return;
		}

		StructureChest structChest = CivGlobal.getStructureChest(bcoord);
		if (structChest != null) {
			event.setCancelled(true);
			return;
		}

		coord.setFromLocation(block.getLocation());

		HashSet<Wall> walls = CivGlobal.getWallChunk(coord);
		if (walls != null) {
			for (Wall wall : walls) {
				if (wall.isProtectedLocation(block.getLocation())) {
					event.setCancelled(true);
					return;
				}
			}
		}

		TownChunk tc = CivGlobal.getTownChunk(coord);
		if (tc == null) {
			continue;
		}

		event.setCancelled(true);
		return;
	}

}
 
Example 15
Source File: TPContainerListener.java    From Transport-Pipes with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent e) {
    for (Block b : e.blockList()) {
        notifyBlockUpdate(b, false);
    }
}
 
Example 16
Source File: SpawnerExplodeListener.java    From MineableSpawners with MIT License 4 votes vote down vote up
@EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onSpawnerExplode(EntityExplodeEvent e) {
    if (!plugin.getConfigurationHandler().getBoolean("explode", "drop")) {
        return;
    }

    for (Block block : e.blockList()) {
        if (!block.getType().equals(XMaterial.SPAWNER.parseMaterial())) {
            continue;
        }

        double dropChance = plugin.getConfigurationHandler().getDouble("explode", "chance")/100;

        if (dropChance != 1) {
            double random = Math.random();
            if (random >= dropChance) {
                return;
            }
        }

        CreatureSpawner spawner = (CreatureSpawner) block.getState();

        ItemStack item = new ItemStack(XMaterial.SPAWNER.parseMaterial());
        ItemMeta meta = item.getItemMeta();
        String mobFormatted = Chat.uppercaseStartingLetters(spawner.getSpawnedType().toString());

        meta.setDisplayName(plugin.getConfigurationHandler().getMessage("global", "name").replace("%mob%", mobFormatted));
        List<String> newLore = new ArrayList<>();
        if (plugin.getConfigurationHandler().getList("global", "lore") != null && plugin.getConfigurationHandler().getBoolean("global", "lore-enabled")) {
            for (String line : plugin.getConfigurationHandler().getList("global", "lore")) {
                newLore.add(Chat.format(line).replace("%mob%", mobFormatted));
            }
            meta.setLore(newLore);
        }
        item.setItemMeta(meta);

        item = plugin.getNmsHandler().setType(item, spawner.getSpawnedType());

        block.getLocation().getWorld().dropItemNaturally(block.getLocation(), item);
    }
}
 
Example 17
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 18
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);

}