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

The following examples show how to use org.bukkit.event.entity.EntityExplodeEvent#getEntity() . 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: EntityExplodeListener.java    From ObsidianDestroyer with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent event) {
    if (event == null || ChunkManager.getInstance().getDisabledWorlds().contains(event.getLocation().getWorld().getName())) {
        return; // do not do anything in case explosions get cancelled
    }

    final Entity detonator = event.getEntity();
    if (detonator == null || detonator.hasMetadata("ObbyEntity")) {
        return;
    }
    if (event.getLocation().getBlock().hasMetadata("ObbyEntity")) {
        return;
    }
    if (event.getYield() <= 0.51) {
        return;
    }

    ChunkManager.getInstance().handleExplosion(event);
}
 
Example 2
Source File: FlyingMobEvents.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void MobExplosion(final EntityExplodeEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    // Only cover in the island world
    if (e.getEntity() == null || !IslandGuard.inWorld(e.getEntity())) {
        return;
    }
    if (mobSpawnInfo.containsKey(e.getEntity())) {
        // We know about this mob
        if (DEBUG) {
            plugin.getLogger().info("DEBUG: We know about this mob");
        }
        if (!mobSpawnInfo.get(e.getEntity()).inIslandSpace(e.getLocation())) {
            // Cancel the explosion and block damage
            if (DEBUG) {
                plugin.getLogger().info("DEBUG: cancel flying mob explosion");
            }
            e.blockList().clear();
            e.setCancelled(true);
        }
    }
}
 
Example 3
Source File: NetherPortals.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prevent the Nether spawn from being blown up
 * 
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onExplosion(final EntityExplodeEvent e) {
    if (Settings.newNether) {
        // Not used in the new nether
        return;
    }
    // Find out what is exploding
    Entity expl = e.getEntity();
    if (expl == null) {
        return;
    }
    // Check world
    if (!e.getEntity().getWorld().getName().equalsIgnoreCase(Settings.worldName + "_nether")
            || e.getEntity().getWorld().getName().equalsIgnoreCase(Settings.worldName + "_the_end")) {
        return;
    }
    Location spawn = e.getLocation().getWorld().getSpawnLocation();
    Location loc = e.getLocation();
    if (spawn.distance(loc) < Settings.netherSpawnRadius) {
        e.blockList().clear();
    }
}
 
Example 4
Source File: NetherTerraFormEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onGhastExplode(EntityExplodeEvent event) {
    if (!plugin.getWorldManager().isSkyNether(event.getEntity().getWorld())) {
        return; // Bail out, not our problem
    }
    // TODO: 23/09/2015 - R4zorax: Perhaps enable this when island has a certain level?
    if (event.getEntity() instanceof Fireball) {
        Fireball fireball = (Fireball) event.getEntity();
        fireball.setIsIncendiary(false);
        fireball.setFireTicks(0);
        event.setCancelled(true);
    }
}
 
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: CEListener.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void EntityExplodeEvent(EntityExplodeEvent e) {

    if (e.getEntity() != null && e.getEntity().hasMetadata("ce.explosive")) {
        e.getEntity().remove();
        e.setCancelled(true);
    }

}
 
Example 9
Source File: EntityExplodeListener.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
    try {
        final Entity entity = event.getEntity();
        final Location location = entity.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        if (!islandManager.isIslandWorld(location)) return;

        if (!IridiumSkyblock.getConfiguration().allowExplosions)
            event.setCancelled(true);
    } catch (Exception ex) {
        IridiumSkyblock.getInstance().sendErrorMessage(ex);
    }
}
 
Example 10
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 11
Source File: DWorldListener.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) {
    if (plugin.getGameWorld(event.getEntity().getWorld()) == null) {
        return;
    }
    if (event.getEntity() instanceof LivingEntity) {
        // Disable Creeper explosions in gameWorlds
        event.setCancelled(true);
    } else {// TODO respect block breaking game rules
        // Disable drops from TNT
        event.setYield(0);
    }
}
 
Example 12
Source File: ListenerCombatChecks.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onEntityExplode(EntityExplodeEvent e) {
    Entity entity = e.getEntity();
    if(!(entity instanceof Creeper)) return;

    Creeper creeper = (Creeper) entity;
    checkEnemyDeathUntag(creeper);
}
 
Example 13
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 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: 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 16
Source File: TNTMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void yieldSet(EntityExplodeEvent event) {
    if(this.properties.yield != null && event.getEntity() instanceof TNTPrimed) {
        event.setYield(this.properties.yield);
    }
}
 
Example 17
Source File: TNTMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void yieldSet(EntityExplodeEvent event) {
  if (this.properties.yield != null && event.getEntity() instanceof TNTPrimed) {
    event.setYield(this.properties.yield);
  }
}
 
Example 18
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 19
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);
    }
}