下面列出了怎么用org.bukkit.event.block.BlockExplodeEvent的API类实例代码及写法,或者点击链接到github查看源代码。
@EventHandler(priority = EventPriority.HIGH)
public void onBlockExplode(BlockExplodeEvent event) {
if (!LWC.ENABLED || event.isCancelled()) {
return;
}
LWC lwc = plugin.getLWC();
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);
}
}
}
}
@EventHandler
public void onBlockExplode(BlockExplodeEvent e) {
RedProtect.get().logger.debug(LogLevel.DEFAULT, "Is BlockListener - BlockExplodeEvent event");
List<Block> toRemove = new ArrayList<>();
for (Block b : e.blockList()) {
Region r = RedProtect.get().rm.getTopRegion(b.getLocation());
if (!cont.canWorldBreak(b)) {
toRemove.add(b);
continue;
}
if (r != null && !r.canFire()) {
toRemove.add(b);
}
}
if (!toRemove.isEmpty()) {
e.blockList().removeAll(toRemove);
}
}
public ChunkListener() {
if (Settings.IMP.TICK_LIMITER.ENABLED) {
PluginManager plm = Bukkit.getPluginManager();
Plugin plugin = Fawe.<FaweBukkit>imp().getPlugin();
plm.registerEvents(this, plugin);
try {
Fawe.debug("Detected " + BlockExplodeEvent.class);
plm.registerEvents(new ChunkListener_8Plus(this), plugin);
} catch (Throwable ignore) {}
TaskManager.IMP.repeat(new Runnable() {
@Override
public void run() {
rateLimit--;
physicsFreeze = false;
itemFreeze = false;
lastZ = Integer.MIN_VALUE;
physSkip = 0;
physCancelPair = Long.MIN_VALUE;
physCancel = false;
counter.clear();
for (Long2ObjectMap.Entry<Boolean> entry : badChunks.long2ObjectEntrySet()) {
long key = entry.getLongKey();
int x = MathMan.unpairIntX(key);
int z = MathMan.unpairIntY(key);
counter.put(key, badLimit);
}
badChunks.clear();
}
}, Settings.IMP.TICK_LIMITER.INTERVAL);
}
}
@EventHandler
public void onBlockExplode(BlockExplodeEvent 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 (plugin.getShopUtils().isShop(b.getLocation())) e.blockList().remove(b);
}
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockExplode(BlockExplodeEvent event) {
Location location = BukkitUtil.adapt(event.getBlock().getLocation());
PlotMapInfo pmi = manager.getMap(location);
if (pmi != null && pmi.isDisableExplosion()) {
event.setCancelled(true);
} else {
PlotId id = manager.getPlotId(location);
if (id == null) {
event.setCancelled(true);
}
}
}
@EventHandler(ignoreCancelled = true)
public void onEntityExplode(BlockExplodeEvent event) {
if (event == null || ChunkManager.getInstance().getDisabledWorlds().contains(event.getBlock().getLocation().getWorld().getName())) {
return; // do not do anything in case explosions get cancelled
}
final Block detonatorBlock = event.getBlock();
if (detonatorBlock == null) {
return;
}
if (detonatorBlock.hasMetadata("ObbyEntity")) {
return;
}
if (event.getYield() <= 0) {
return;
}
// feeling batty?! Spawn a bat to tie onto the EntityExplodeEvent.
try {
Bat bat = (Bat) Bukkit.getWorld(detonatorBlock.getWorld().getName()).spawnEntity(detonatorBlock.getLocation(), EntityType.BAT);
if (bat != null) {
bat.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 100, 1), true);
}
// Construct a new event but don't call it.
EntityExplodeEvent entityExplodeEvent = new EntityExplodeEvent(bat, event.getBlock().getLocation(), event.blockList(), event.getYield());
ChunkManager.getInstance().handleExplosion(entityExplodeEvent, event.getBlock().getLocation());
if (bat != null) {
bat.remove(); // bye
}
} catch (Exception e) {
ObsidianDestroyer.debug(e.toString());
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockChange(BlockExplodeEvent evt) {
onBlockChange(evt.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.LOWEST)
public void onExplosionEvent(BlockExplodeEvent event) {
final World world = event.getBlock().getLocation().getWorld();
if (!GDFlags.EXPLOSION_BLOCK || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
return;
}
Block source = event.getBlock();
GDCauseStackManager.getInstance().pushCause(source);
if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.EXPLOSION_BLOCK.toString(), source, world.getUID())) {
return;
}
final GDPermissionUser user = CauseContextHelper.getEventUser(event.getBlock().getLocation(), PlayerTracker.Type.OWNER);
GDTimings.EXPLOSION_EVENT.startTiming();
GDClaim targetClaim = null;
final List<Block> filteredLocations = new ArrayList<>();
final String sourceId = GDPermissionManager.getInstance().getPermissionIdentifier(source);
final int cancelBlockLimit = GriefDefenderPlugin.getGlobalConfig().getConfig().claim.explosionCancelBlockLimit;
boolean denySurfaceExplosion = GriefDefenderPlugin.getActiveConfig(world.getUID()).getConfig().claim.explosionBlockSurfaceBlacklist.contains(sourceId);
if (!denySurfaceExplosion) {
denySurfaceExplosion = GriefDefenderPlugin.getActiveConfig(world.getUID()).getConfig().claim.explosionBlockSurfaceBlacklist.contains("any");
}
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;
}
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();
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void blockExplode(BlockExplodeEvent event) {
render(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockExplode(BlockExplodeEvent e) {
for (Block b : e.blockList()) {
notifyBlockUpdate(b, false);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockExplode(BlockExplodeEvent e) {
e.blockList().removeAll(getAffectedBlocks(e.blockList()));
}
@EventHandler
public void onBlockExplode(BlockExplodeEvent event) {
if (isGuildHeart(event.getBlock())) {
event.setCancelled(true);
}
}