下面列出了怎么用org.bukkit.event.block.BlockIgniteEvent.IgniteCause的API类实例代码及写法,或者点击链接到github查看源代码。
public static BlockIgniteEvent callBlockIgniteEvent(World world, int x, int y, int z, int igniterX, int igniterY, int igniterZ) {
org.bukkit.World bukkitWorld = world.getWorld();
Block igniter = bukkitWorld.getBlockAt(igniterX, igniterY, igniterZ);
IgniteCause cause;
switch (igniter.getType()) {
case LAVA:
case STATIONARY_LAVA:
cause = IgniteCause.LAVA;
break;
case DISPENSER:
cause = IgniteCause.FLINT_AND_STEEL;
break;
case FIRE: // Fire or any other unknown block counts as SPREAD.
default:
cause = IgniteCause.SPREAD;
}
BlockIgniteEvent event = new BlockIgniteEvent(bukkitWorld.getBlockAt(x, y, z), cause, igniter);
world.getServer().getPluginManager().callEvent(event);
return event;
}
public static BlockIgniteEvent callBlockIgniteEvent(World world, int x, int y, int z, Entity igniter) {
org.bukkit.World bukkitWorld = world.getWorld();
org.bukkit.entity.Entity bukkitIgniter = igniter.getBukkitEntity();
IgniteCause cause;
switch (bukkitIgniter.getType()) {
case ENDER_CRYSTAL:
cause = IgniteCause.ENDER_CRYSTAL;
break;
case LIGHTNING:
cause = IgniteCause.LIGHTNING;
break;
case SMALL_FIREBALL:
case FIREBALL:
cause = IgniteCause.FIREBALL;
break;
default:
cause = IgniteCause.FLINT_AND_STEEL;
}
BlockIgniteEvent event = new BlockIgniteEvent(bukkitWorld.getBlockAt(x, y, z), cause, bukkitIgniter);
world.getServer().getPluginManager().callEvent(event);
return event;
}
public static BlockIgniteEvent callBlockIgniteEvent(net.minecraft.world.World world, int x, int y, int z, int igniterX, int igniterY, int igniterZ) {
org.bukkit.World bukkitWorld = world.getWorld();
Block igniter = bukkitWorld.getBlockAt(igniterX, igniterY, igniterZ);
IgniteCause cause;
switch (igniter.getType()) {
case LAVA:
case STATIONARY_LAVA:
cause = IgniteCause.LAVA;
break;
case DISPENSER:
cause = IgniteCause.FLINT_AND_STEEL;
break;
case FIRE: // Fire or any other unknown block counts as SPREAD.
default:
cause = IgniteCause.SPREAD;
}
BlockIgniteEvent event = new BlockIgniteEvent(bukkitWorld.getBlockAt(x, y, z), cause, igniter);
world.getServer().getPluginManager().callEvent(event);
return event;
}
public static BlockIgniteEvent callBlockIgniteEvent(net.minecraft.world.World world, int x, int y, int z, net.minecraft.entity.Entity igniter) {
org.bukkit.World bukkitWorld = world.getWorld();
org.bukkit.entity.Entity bukkitIgniter = igniter.getBukkitEntity();
IgniteCause cause;
switch (bukkitIgniter.getType()) {
case ENDER_CRYSTAL:
cause = IgniteCause.ENDER_CRYSTAL;
break;
case LIGHTNING:
cause = IgniteCause.LIGHTNING;
break;
case SMALL_FIREBALL:
case FIREBALL:
cause = IgniteCause.FIREBALL;
break;
default:
cause = IgniteCause.FLINT_AND_STEEL;
}
BlockIgniteEvent event = new BlockIgniteEvent(bukkitWorld.getBlockAt(x, y, z), cause, bukkitIgniter);
world.getServer().getPluginManager().callEvent(event);
return event;
}
public static BlockIgniteEvent callBlockIgniteEvent(World world, int x, int y, int z, Explosion explosion) {
org.bukkit.World bukkitWorld = world.getWorld();
org.bukkit.entity.Entity igniter = explosion.exploder == null ? null : explosion.exploder.getBukkitEntity();
BlockIgniteEvent event = new BlockIgniteEvent(bukkitWorld.getBlockAt(x, y, z), IgniteCause.EXPLOSION, igniter);
world.getServer().getPluginManager().callEvent(event);
return event;
}
public static BlockIgniteEvent callBlockIgniteEvent(net.minecraft.world.World world, int x, int y, int z, net.minecraft.world.Explosion explosion) {
org.bukkit.World bukkitWorld = world.getWorld();
org.bukkit.entity.Entity igniter = explosion.exploder == null ? null : explosion.exploder.getBukkitEntity();
BlockIgniteEvent event = new BlockIgniteEvent(bukkitWorld.getBlockAt(x, y, z), IgniteCause.EXPLOSION, igniter);
world.getServer().getPluginManager().callEvent(event);
return event;
}
@EventHandler(ignoreCancelled = true)
public void onBlockStartBurn(BlockIgniteEvent e) {
RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is BlockIgniteEvent event");
Block b = e.getBlock();
Block bignit = e.getIgnitingBlock();
if (b == null) {
return;
}
Region r = RedProtect.get().rm.getTopRegion(b.getLocation());
if (r != null && !r.canFire()) {
if (e.getIgnitingEntity() != null) {
if (e.getIgnitingEntity() instanceof Player) {
Player p = (Player) e.getIgnitingEntity();
if (!r.canBuild(p)) {
RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantplace");
e.setCancelled(true);
return;
}
} else {
e.setCancelled(true);
return;
}
}
if (bignit != null && (bignit.getType().equals(Material.FIRE) || bignit.getType().name().contains("LAVA"))) {
e.setCancelled(true);
return;
}
if (e.getCause().equals(IgniteCause.LIGHTNING) || e.getCause().equals(IgniteCause.EXPLOSION) || e.getCause().equals(IgniteCause.FIREBALL)) {
e.setCancelled(true);
}
}
}
public static BlockIgniteEvent callBlockIgniteEvent(World world, int x, int y, int z, IgniteCause cause, Entity igniter) {
BlockIgniteEvent event = new BlockIgniteEvent(world.getWorld().getBlockAt(x, y, z), cause, igniter.getBukkitEntity());
world.getServer().getPluginManager().callEvent(event);
return event;
}
public static BlockIgniteEvent callBlockIgniteEvent(net.minecraft.world.World world, int x, int y, int z, IgniteCause cause, net.minecraft.entity.Entity igniter) {
BlockIgniteEvent event = new BlockIgniteEvent(world.getWorld().getBlockAt(x, y, z), cause, igniter.getBukkitEntity());
world.getServer().getPluginManager().callEvent(event);
return event;
}
@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());
}
}