下面列出了怎么用org.bukkit.event.block.BlockIgniteEvent的API类实例代码及写法,或者点击链接到github查看源代码。
@EventHandler(priority = EventPriority.LOWEST)
public void onBlockIgnite(BlockIgniteEvent event) {
if (!GDFlags.BLOCK_MODIFY) {
return;
}
final World world = event.getBlock().getWorld();
if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
return;
}
if (event.getPlayer() != null) {
GDCauseStackManager.getInstance().pushCause(event.getPlayer());
}
final Object source = event.getIgnitingBlock() != null ? event.getIgnitingBlock() : event.getIgnitingEntity();
CommonBlockEventHandler.getInstance().handleBlockModify(event, source, event.getBlock().getState());
}
/**
* Get whether the {@link Block} was probably transformed by a player.
*
* @return Whether the event is considered "manual."
*/
public final boolean isManual() {
final Event event = getCause();
if (event instanceof BlockPlaceEvent
|| event instanceof BlockBreakEvent
|| event instanceof PlayerBucketEmptyEvent
|| event instanceof PlayerBucketFillEvent) return true;
if (event instanceof BlockIgniteEvent) {
BlockIgniteEvent igniteEvent = (BlockIgniteEvent) event;
if (igniteEvent.getCause() == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL
&& igniteEvent.getIgnitingEntity() != null) {
return true;
}
}
if (event instanceof ExplosionPrimeByEntityEvent
&& ((ExplosionPrimeByEntityEvent) event).getPrimer() instanceof Player) {
return true;
}
return false;
}
@EventWrapper
public void onBlockIgnite(final BlockIgniteEvent event) {
// Flint & steel generates a BlockPlaceEvent
if (event.getCause() == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) return;
BlockState oldState = event.getBlock().getState();
BlockState newState = BlockStates.cloneWithMaterial(event.getBlock(), Material.FIRE);
ParticipantState igniter = null;
if (event.getIgnitingEntity() != null) {
// The player themselves using flint & steel, or any of
// several types of owned entity starting or spreading a fire.
igniter = Trackers.getOwner(event.getIgnitingEntity());
} else if (event.getIgnitingBlock() != null) {
// Fire, lava, or flint & steel in a dispenser
igniter = Trackers.getOwner(event.getIgnitingBlock());
}
callEvent(event, oldState, newState, igniter);
}
/**
* Return true if the block transformation was performed "by hand".
*
* Handled:
* - place
* - mine
* - bucket fill/empty
* - flint & steel fire/tnt
*
* Not handled:
* - bonemeal
* - probably lots of other things
*/
public boolean isManual() {
final Event event = getCause();
if(Types.instanceOfAny(
event,
BlockPlaceEvent.class,
BlockBreakEvent.class,
PlayerBucketEmptyEvent.class,
PlayerBucketFillEvent.class
)) return true;
if(event instanceof BlockIgniteEvent) {
BlockIgniteEvent igniteEvent = (BlockIgniteEvent) event;
if(igniteEvent.getCause() == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL && igniteEvent.getIgnitingEntity() != null) {
return true;
}
}
if(event instanceof ExplosionPrimeByEntityEvent && ((ExplosionPrimeByEntityEvent) event).getPrimer() instanceof Player) {
return true;
}
return false;
}
@EventWrapper
public void onBlockIgnite(final BlockIgniteEvent event) {
// Flint & steel generates a BlockPlaceEvent
if(event.getCause() == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) return;
BlockState oldState = event.getBlock().getState();
BlockState newState = BlockStateUtils.cloneWithMaterial(event.getBlock(), Material.FIRE);
ParticipantState igniter = null;
if(event.getIgnitingEntity() != null) {
// The player themselves using flint & steel, or any of
// several types of owned entity starting or spreading a fire.
igniter = entityResolver.getOwner(event.getIgnitingEntity());
} else if(event.getIgnitingBlock() != null) {
// Fire, lava, or flint & steel in a dispenser
igniter = blockResolver.getOwner(event.getIgnitingBlock());
}
callEvent(event, oldState, newState, igniter);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onCustomItemBlockIgniteLowest(CustomItemBlockIgniteEvent customEvent) {
if (customEvent.isCancelled())
return;
CustomItem cItem = customEvent.getCustomItem();
if (!(cItem.getPermissions() instanceof FlintAndSteelPermissions))
return;
FlintAndSteelPermissions perm = (FlintAndSteelPermissions) cItem.getPermissions();
BlockIgniteEvent event = customEvent.getBlockIgniteEvent();
if (!PermissionUtils.allowedAction(event.getPlayer(), perm.getType(), perm.getFire()))
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockIgnite(BlockIgniteEvent event) {
if (event.getPlayer() == null)
return;
PlayerInventory inv = event.getPlayer().getInventory();
ItemStack item = inv.getItemInMainHand();
if (ItemType.getItemType(item) != ItemType.FLINT_AND_STEEL) {
item = inv.getItemInOffHand();
if (ItemType.getItemType(item) != ItemType.FLINT_AND_STEEL)
return;
}
if (AdditionsAPI.isCustomItem(item)) {
CustomItemBlockIgniteEvent customEvent = new CustomItemBlockIgniteEvent(event, new CustomItemStack(item));
Bukkit.getServer().getPluginManager().callEvent(customEvent);
}
}
@EventHandler
public void onBlockIgnites(BlockIgniteEvent event) {
if (event.isCancelled()) {
return;
}
if (!SentinelPlugin.instance.preventExplosionBlockDamage) {
return;
}
if (event.getIgnitingEntity() instanceof Projectile) {
ProjectileSource source = ((Projectile) event.getIgnitingEntity()).getShooter();
if (source instanceof Entity) {
SentinelTrait sourceSentinel = SentinelUtilities.tryGetSentinel((Entity) source);
if (sourceSentinel != null) {
event.setCancelled(true);
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockIgnite(BlockIgniteEvent event) {
//event
final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(event.getBlock().getWorld().getUID());
final GDChunk gpChunk = claimWorldManager.getChunk(event.getBlock().getChunk());
if (event.getPlayer() != null) {
gpChunk.addTrackedBlockPosition(event.getBlock(), event.getPlayer().getUniqueId(), PlayerTracker.Type.NOTIFIER);
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onCustomItemBlockIgnite(CustomItemBlockIgniteEvent customEvent) {
if (customEvent.isCancelled())
return;
CustomItem cItem = customEvent.getCustomItem();
BlockIgniteEvent event = customEvent.getBlockIgniteEvent();
Player player = event.getPlayer();
ItemDurability mechanics = cItem.getDurabilityMechanics();
if (mechanics instanceof FlintAndSteelDurability) {
ItemStack item = customEvent.getCustomItemStack().getItemStack();
FlintAndSteelDurability fsMechanics = (FlintAndSteelDurability) cItem.getDurabilityMechanics();
Bukkit.getServer().getPluginManager().callEvent(new PlayerCustomItemDamageEvent(player, item, fsMechanics.getFire(), cItem));
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockIgnite(BlockIgniteEvent event) {
if (!plugin.isInstance(event.getBlock().getWorld())) {
return;
}
if (event.getCause() != BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockIgnite(BlockIgniteEvent event) {
if (event.getIgnitingEntity() == null) {
return;
}
Location location = BukkitUtil.adapt(event.getBlock().getLocation());
PlotMapInfo pmi = manager.getMap(location);
if (pmi != null) {
if (pmi.isDisableIgnition()) {
event.setCancelled(true);
} else {
Plot plot = manager.getPlot(location);
if (plot == null) {
event.setCancelled(true);
} else {
if (plot.getOwnerId().equals(event.getPlayer().getUniqueId())) {
return;
}
Optional<Plot.AccessLevel> member = plot.isMember(event.getIgnitingEntity().getUniqueId());
if (member.isPresent()) {
if (member.get().equals(Plot.AccessLevel.TRUSTED) && !api.getServerBridge().getOfflinePlayer(plot.getOwnerId()).isOnline()) {
event.setCancelled(true);
} else if (api.isPlotLocked(plot.getId())) {
event.setCancelled(true);
}
} else {
event.setCancelled(true);
}
}
}
}
}
public CustomItemBlockIgniteEvent(BlockIgniteEvent event, CustomItemStack cStack) {
super(cStack);
this.blockIgniteEvent = event;
}
public BlockIgniteEvent getBlockIgniteEvent() {
return blockIgniteEvent;
}
@EventHandler(ignoreCancelled = true)
public void onIgnite(BlockIgniteEvent ignite) {
if (ignite.getIgnitingBlock() == null && ignite.getIgnitingEntity() == null) {
return;
}
Game game = null;
if (ignite.getIgnitingBlock() == null) {
if (ignite.getIgnitingEntity() instanceof Player) {
game = BedwarsRel.getInstance().getGameManager()
.getGameOfPlayer((Player) ignite.getIgnitingEntity());
} else {
game = BedwarsRel.getInstance().getGameManager()
.getGameByLocation(ignite.getIgnitingEntity().getLocation());
}
} else {
game = BedwarsRel.getInstance().getGameManager()
.getGameByLocation(ignite.getIgnitingBlock().getLocation());
}
if (game == null) {
return;
}
if (game.getState() == GameState.STOPPED) {
return;
}
if (ignite.getCause() == IgniteCause.ENDER_CRYSTAL || ignite.getCause() == IgniteCause.LIGHTNING
|| ignite.getCause() == IgniteCause.SPREAD) {
ignite.setCancelled(true);
return;
}
if (ignite.getIgnitingEntity() == null) {
ignite.setCancelled(true);
return;
}
if (game.getState() == GameState.WAITING) {
return;
}
if (!game.getRegion().isPlacedBlock(ignite.getIgnitingBlock())
&& ignite.getIgnitingBlock() != null) {
game.getRegion().addPlacedBlock(ignite.getIgnitingBlock(),
ignite.getIgnitingBlock().getState());
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockIgniteEvent(BlockIgniteEvent event) {
// CivLog.debug("block ignite event");
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
for (int z = -1; z <= 1; z++) {
Block b = event.getBlock().getRelative(x, y, z);
bcoord.setFromLocation(b.getLocation());
StructureBlock sb = CivGlobal.getStructureBlock(bcoord);
if (sb != null) {
if (b.getType().isBurnable()) {
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(event.getBlock().getLocation());
TownChunk tc = CivGlobal.getTownChunk(coord);
if (tc == null) {
return;
}
if (tc.perms.isFire() == false) {
CivMessage.sendError(event.getPlayer(), "Fire disabled in this chunk.");
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onBlockIgniteEvent(BlockIgniteEvent event) {
if (ArenaManager.activeArenas.containsKey(event.getBlock().getWorld().getName())) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockIgnite(final BlockIgniteEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
plugin.getLogger().info(e.getCause().name());
}
if (!inWorld(e.getBlock())) {
//plugin.getLogger().info("DEBUG: Not in world");
return;
}
// Check if this is a portal lighting
if (e.getBlock() != null && e.getBlock().getType().equals(Material.OBSIDIAN)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: portal lighting");
return;
}
if (e.getCause() != null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: ignite cause = " + e.getCause());
switch (e.getCause()) {
case ENDER_CRYSTAL:
case EXPLOSION:
case FIREBALL:
case LIGHTNING:
if (!actionAllowed(e.getBlock().getLocation(), SettingsFlag.FIRE)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: canceling fire");
e.setCancelled(true);
}
break;
case FLINT_AND_STEEL:
Set<Material> transparent = new HashSet<Material>();
transparent.add(Material.AIR);
if (DEBUG) {
plugin.getLogger().info("DEBUG: block = " + e.getBlock());
//plugin.getLogger().info("DEBUG: target block = " + e.getPlayer().getTargetBlock(transparent, 10));
}
// Check if this is allowed
if (e.getPlayer() != null && (e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypass"))) {
return;
}
if (!actionAllowed(e.getBlock().getLocation(), SettingsFlag.FIRE)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: canceling fire");
// If this was not a player, just stop it
if (e.getPlayer() == null) {
e.setCancelled(true);
break;
}
// Get target block
Block targetBlock = e.getPlayer().getTargetBlock(transparent, 10);
if (targetBlock.getType().equals(Material.OBSIDIAN)) {
final MaterialData md = new MaterialData(e.getBlock().getType(), e.getBlock().getData());
new BukkitRunnable() {
@Override
public void run() {
if (e.getBlock().getType().equals(Material.FIRE)) {
e.getBlock().setType(md.getItemType());
e.getBlock().setData(md.getData());
}
}
}.runTask(plugin);
} else {
e.setCancelled(true);
}
}
break;
case LAVA:
case SPREAD:
// Check if this is a portal lighting
if (e.getBlock() != null && e.getBlock().getType().equals(Material.OBSIDIAN)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: obsidian lighting");
return;
}
if (!actionAllowed(e.getBlock().getLocation(), SettingsFlag.FIRE_SPREAD)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: canceling fire spread");
e.setCancelled(true);
}
break;
default:
break;
}
}
}
@EventHandler
public void onIgnite(BlockIgniteEvent e) {
if (ProtectionSystem.build(e.getPlayer(), e.getBlock().getLocation())) {
e.setCancelled(true);
}
}
@EventHandler
public void onBlockIgnite(BlockIgniteEvent event) {
if (!match.isRunning()) {
event.setCancelled(true);
}
}
@EventHandler
public void onBlockIgnite(BlockIgniteEvent event) {
if (filter.evaluate(event.getBlock(), event).equals(FilterState.DENY) && region.contains(new BlockRegion(null, event.getBlock().getLocation().toVector()))) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void blockChange(BlockIgniteEvent e){
if(e.isCancelled())return;
logBlockCreated(e.getBlock());
i.put("BSTARTFIRE", i.get("BSTARTFIRE")+1);
// System.out.println(5);
}