下面列出了怎么用org.bukkit.event.block.BlockPistonExtendEvent的API类实例代码及写法,或者点击链接到github查看源代码。
@EventHandler
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
try {
final Block block = event.getBlock();
final Location location = block.getLocation();
final IslandManager islandManager = IridiumSkyblock.getIslandManager();
final Island island = islandManager.getIslandViaLocation(location);
if (island == null) return;
final BlockFace face = event.getDirection();
for (Block extendedBlock : event.getBlocks()) {
final Location extendedBlockLocation = extendedBlock.getLocation();
final int[] offset = offsets.get(face);
extendedBlockLocation.add(offset[0], offset[1], offset[2]);
if (!island.isInIsland(extendedBlockLocation)) {
event.setCancelled(true);
return;
}
}
} catch (Exception e) {
IridiumSkyblock.getInstance().sendErrorMessage(e);
}
}
/**
* This handler only checks to see if the event should be cancelled. It does not change the
* state of any Destroyables.
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void testBlockChange(BlockTransformEvent event) {
if(this.match.getWorld() != event.getWorld() || !this.anyDestroyableAffected(event)) {
return;
}
// This is a temp fix until there is a tracker for placed minecarts (only dispensed are tracked right now)
if((event.getCause() instanceof EntityExplodeEvent &&
((EntityExplodeEvent) event.getCause()).getEntity() instanceof ExplosiveMinecart) ||
event.getCause() instanceof BlockPistonExtendEvent ||
event.getCause() instanceof BlockPistonRetractEvent) {
event.setCancelled(true);
return;
}
for(Destroyable destroyable : this.destroyables) {
String reasonKey = destroyable.testBlockChange(event.getOldState(), event.getNewState(), ParticipantBlockTransformEvent.getPlayerState(event));
if(reasonKey != null) {
event.setCancelled(true, new TranslatableComponent(reasonKey));
return;
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onPistonExtend(BlockPistonExtendEvent e) {
// If the piston would only move itself
Block airAfterPiston = e.getBlock().getRelative(e.getDirection());
Block belowAir = airAfterPiston.getRelative(BlockFace.DOWN);
if (shopUtils.isShop(belowAir.getLocation())) {
e.setCancelled(true);
return;
}
for (Block b : e.getBlocks()) {
Block newBlock = b.getRelative(e.getDirection());
Block belowNewBlock = newBlock.getRelative(BlockFace.DOWN);
if (shopUtils.isShop(belowNewBlock.getLocation())) e.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOW)
public void onPistonExtend(BlockPistonExtendEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
Location pistonLoc = e.getBlock().getLocation();
if (Settings.allowPistonPush || !inWorld(pistonLoc)) {
//plugin.getLogger().info("DEBUG: Not in world");
return;
}
Island island = plugin.getGrid().getProtectedIslandAt(pistonLoc);
if (island == null || !island.onIsland(pistonLoc)) {
//plugin.getLogger().info("DEBUG: Not on is island protection zone");
return;
}
// We need to check where the blocks are going to go, not where they are
for (Block b : e.getBlocks()) {
if (!island.onIsland(b.getRelative(e.getDirection()).getLocation())) {
//plugin.getLogger().info("DEBUG: Block is outside protected area");
e.setCancelled(true);
return;
}
}
}
@EventHandler(priority=EventPriority.LOW)
public void onEvent(BlockPistonExtendEvent event)
{
if (!Settings.allowTNTPushing) {
// Check world
if (!inWorld(event.getBlock())) {
return;
}
for (Block block: event.getBlocks()) {
if (block.getType() == Material.TNT) {
event.setCancelled(true);
break;
}
}
}
/* JAVA 8
if (event.getBlocks()..stream().anyMatch(it->it.getType()==Material.TNT))
event.setCancelled(true);
*/
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
BukkitWorld world = BukkitUtil.adapt(event.getBlock().getWorld());
if (manager.isPlotWorld(world)) {
BlockFace face = event.getDirection();
for (Block block : event.getBlocks()) {
PlotId id = manager.getPlotId(new Location(world, BukkitUtil.locationToVector(
block.getLocation().add(face.getModX(), face.getModY(),
face.getModZ()))));
if (id == null) {
event.setCancelled(true);
}
}
}
}
/**
* This handler only checks to see if the event should be cancelled. It does not change the state
* of any Destroyables.
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void testBlockChange(BlockTransformEvent event) {
if (this.match.getWorld() != event.getWorld() || !this.anyDestroyableAffected(event)) {
return;
}
// This is a temp fix until there is a tracker for placed minecarts (only dispensed are tracked
// right now)
if ((event.getCause() instanceof EntityExplodeEvent
&& ((EntityExplodeEvent) event.getCause()).getEntity() instanceof ExplosiveMinecart)
|| event.getCause() instanceof BlockPistonExtendEvent
|| event.getCause() instanceof BlockPistonRetractEvent) {
event.setCancelled(true);
return;
}
for (Destroyable destroyable : this.destroyables) {
String reasonKey =
destroyable.testBlockChange(
event.getOldState(),
event.getNewState(),
ParticipantBlockTransformEvent.getPlayerState(event));
if (reasonKey != null) {
event.setCancelled(true, TranslatableComponent.of(reasonKey));
return;
}
}
}
@EventWrapper
public void onBlockPistonExtend(final BlockPistonExtendEvent event) {
Map<Block, BlockState> newStates = new HashMap<>();
// Add the arm of the piston, which will extend into the adjacent block.
PistonExtensionMaterial pistonExtension =
new PistonExtensionMaterial(Material.PISTON_EXTENSION);
pistonExtension.setFacingDirection(event.getDirection());
BlockState pistonExtensionState = event.getBlock().getRelative(event.getDirection()).getState();
pistonExtensionState.setType(pistonExtension.getItemType());
pistonExtensionState.setData(pistonExtension);
newStates.put(event.getBlock(), pistonExtensionState);
this.onPistonMove(event, event.getBlocks(), newStates);
}
@EventHandler
public void pistonExtend(BlockPistonExtendEvent e) {
World world = e.getBlock().getWorld();
BlockFace bf = e.getDirection();
Vector offset = new Vector(0, 0, 0);
switch (bf) {
case UP:
offset.setY(1);
break;
case DOWN:
offset.setY(-1);
break;
case EAST:
offset.setX(1);
break;
case WEST:
offset.setX(-1);
break;
case NORTH:
offset.setZ(-1);
break;
case SOUTH:
offset.setZ(1);
}
long currTime = System.currentTimeMillis();
pistonPushes.add(new PistonPush(world, e.getBlock().getLocation().toVector().add(offset), bf, currTime));
for(Block b : e.getBlocks()) {
pistonPushes.add(new PistonPush(world, b.getLocation().toVector().add(offset), bf, currTime));
}
}
@EventHandler
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
if (!LWC.ENABLED || event.isCancelled()) {
return;
}
LWC lwc = this.plugin.getLWC();
for (Block block : event.getBlocks()) {
Protection protection = lwc.findProtection(block);
if (protection != null) {
event.setCancelled(true);
return;
}
}
}
@EventWrapper
public void onBlockPistonExtend(final BlockPistonExtendEvent event) {
Map<Block, BlockState> newStates = new HashMap<>();
// Add the arm of the piston, which will extend into the adjacent block.
PistonExtensionMaterial pistonExtension = new PistonExtensionMaterial(Material.PISTON_EXTENSION);
pistonExtension.setFacingDirection(event.getDirection());
BlockState pistonExtensionState = event.getBlock().getRelative(event.getDirection()).getState();
pistonExtensionState.setType(pistonExtension.getItemType());
pistonExtensionState.setData(pistonExtension);
newStates.put(event.getBlock(), pistonExtensionState);
this.onPistonMove(event, event.getBlocks(), newStates);
}
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (!ScriptLoader.isCurrentEvent(BlockPistonExtendEvent.class, BlockPistonRetractEvent.class)) {
Skript.error("The moved blocks are only usable in piston extend and retract events", ErrorQuality.SEMANTIC_ERROR);
return false;
}
return true;
}
public void blockChange(BlockPistonExtendEvent e){
if(e.isCancelled())return;
for(Block b: e.getBlocks()){
logBlockCreated(b);
}
i.put("BPISTION", i.get("BPISTION")+1);
}
@EventHandler
public void onPistonExtend(BlockPistonExtendEvent e) {
for (Block b : e.getBlocks()) {
if (BlockStorage.hasBlockInfo(b) || (b.getRelative(e.getDirection()).getType() == Material.AIR && BlockStorage.hasBlockInfo(b.getRelative(e.getDirection())))) {
e.setCancelled(true);
return;
}
}
}
@EventHandler
public void onPistonExtend(BlockPistonExtendEvent event) {
for (Block block : event.getBlocks()) {
if (isGuildHeart(block)) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPistonPush(BlockPistonExtendEvent event) {
if (!event.isCancelled()) {
if (event.getBlock().getRelative(event.getDirection()).equals(place.getBlock())) {
event.setCancelled(true);
} else {
for (Block block : event.getBlocks()) {
if (block.equals(place.getBlock()) || block.equals(place.getBlock().getRelative(event.getDirection().getOppositeFace()))) {
event.setCancelled(true);
}
}
}
}
}
@EventHandler
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
if (event.getBlock().getRelative(event.getDirection()).getY() >= height){
event.setCancelled(true);
} else {
for (Block block : event.getBlocks()) {
if (block.getRelative(event.getDirection()).getY() >= height) {
event.setCancelled(true);
}
}
}
}
@EventHandler
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
if (region.contains(event.getBlock().getRelative(event.getDirection()).getLocation().toVector()) && filter.evaluate(event.getBlock().getRelative(event.getDirection()), event).equals(FilterState.DENY)) {
event.setCancelled(true);
} else {
for (Block block : event.getBlocks()) {
if (region.contains(block.getRelative(event.getDirection()).getLocation().toVector()) && filter.evaluate(block.getRelative(event.getDirection()), event).equals(FilterState.DENY)) {
event.setCancelled(true);
break;
}
}
}
}
@EventHandler
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
if (region.contains(event.getBlock().getRelative(event.getDirection()).getLocation().toVector()) && filter.evaluate(event.getBlock().getRelative(event.getDirection()), event).equals(FilterState.DENY)) {
event.setCancelled(true);
} else {
for (Block block : event.getBlocks()) {
if ((region.contains(block.getLocation().toVector()) && filter.evaluate(block, event).equals(FilterState.DENY)) || (region.contains(block.getRelative(event.getDirection()).getLocation().toVector()) && filter.evaluate(block.getRelative(event.getDirection()), event).equals(FilterState.DENY))) {
event.setCancelled(true);
break;
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPistonPush(BlockPistonExtendEvent event) {
for (Block block : event.getBlocks()) {
if (monument.contains(block) && partOfObjective(block)) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPistonPush(BlockPistonExtendEvent event) {
for (Block block : event.getBlocks()) {
if (core.contains(block) && partOfObjective(block)) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPistonExtend(BlockPistonExtendEvent event) {
handleMove(event.getBlocks(), event.getDirection());
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void breakCheck(final BlockTransformEvent event) {
if (event.getWorld() != this.match.getWorld()) return;
ParticipantState player = ParticipantBlockTransformEvent.getPlayerState(event);
Vector blockVector = BlockVectors.center(event.getNewState()).toVector();
for (Core core : this.cores) {
if (!core.hasLeaked() && core.getCasingRegion().contains(blockVector)) {
if (event.getNewState().getType() == Material.AIR) {
if (player != null) {
Competitor team = player.getParty();
if (team == core.getOwner()) {
event.setCancelled(true, TranslatableComponent.of("core.damageOwn"));
} else if (event.getOldState().getData().equals(core.getMaterial())) {
this.match.callEvent(new CoreBlockBreakEvent(core, player, event.getOldState()));
core.touch(player);
// Note: team may not have touched a broken core if a different team broke it
if (!core.isCompleted(team) && !core.hasTouched(team)) {
this.match.callEvent(new GoalStatusChangeEvent(this.match, core));
}
}
} else if (event.getCause() instanceof EntityExplodeEvent) {
// this is a temp fix until there is a tracker for placed minecarts (only dispensed are
// tracked right now)
if (((EntityExplodeEvent) event.getCause()).getEntity() instanceof ExplosiveMinecart) {
event.setCancelled(true);
}
} else if (event.getCause() instanceof BlockPistonRetractEvent) {
event.setCancelled(true);
}
} else if (event.getCause() instanceof BlockPistonExtendEvent) {
event.setCancelled(true);
} else if (event.getCause() instanceof BlockDispenseEvent) {
event.setCancelled(true);
}
break;
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPistonExtend(BlockPistonExtendEvent event) {
handleMove(event.getBlocks(), event.getDirection());
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void breakCheck(final BlockTransformEvent event) {
if(event.getWorld() != this.match.getWorld()) return;
ParticipantState player = ParticipantBlockTransformEvent.getPlayerState(event);
Vector blockVector = BlockUtils.center(event.getNewState()).toVector();
for(Core core : this.cores) {
if(!core.hasLeaked() && core.getCasingRegion().contains(blockVector)) {
if(event.getNewState().getType() == Material.AIR) {
if(player != null) {
Competitor team = player.getParty();
if(team == core.getOwner()) {
event.setCancelled(true, new TranslatableComponent("match.core.damageOwn"));
} else if (event.getOldState().getData().equals(core.getMaterial())) {
this.match.getPluginManager().callEvent(new CoreBlockBreakEvent(core, player, event.getOldState()));
core.touch(player);
// Note: team may not have touched a broken core if a different team broke it
if(!core.isCompleted(team) && !core.hasTouched(team)) {
this.match.getPluginManager().callEvent(new GoalStatusChangeEvent(core));
}
}
} else if(event.getCause() instanceof EntityExplodeEvent) {
// this is a temp fix until there is a tracker for placed minecarts (only dispensed are tracked right now)
if(((EntityExplodeEvent) event.getCause()).getEntity() instanceof ExplosiveMinecart) {
event.setCancelled(true);
}
} else if(event.getCause() instanceof BlockPistonRetractEvent) {
event.setCancelled(true);
}
} else if(event.getCause() instanceof BlockPistonExtendEvent) {
event.setCancelled(true);
} else if(event.getCause() instanceof BlockDispenseEvent) {
event.setCancelled(true);
}
break;
}
}
}
public static void handlePistonExtendEvent(@Nonnull BlockPistonExtendEvent e) {
handlePistonEvent(e.getBlock(), e.getBlocks(), e.getDirection(), e);
}
@EventHandler
public void onPistonExtend(BlockPistonExtendEvent e) {
if (e != null) {
ChunkEventHelper.handlePistonExtendEvent(e);
}
}
@Override
@Nullable
protected Block[] get(Event e) {
return (e instanceof BlockPistonExtendEvent) ? ((BlockPistonExtendEvent) e).getBlocks().toArray(new Block[0])
: ((BlockPistonRetractEvent) e).getBlocks().toArray(new Block[0]);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPistonExtendEvent(BlockPistonExtendEvent event) {
/* UGH. If we extend into 'air' it doesnt count them as blocks...
* we need to check air to prevent breaking of item frames...
*/
final int PISTON_EXTEND_LENGTH = 13;
Block currentBlock = event.getBlock().getRelative(event.getDirection());
for (int i = 0; i < PISTON_EXTEND_LENGTH; i++) {
if(ItemManager.getId(currentBlock) == CivData.AIR) {
if (!allowPistonAction(currentBlock.getLocation())) {
event.setCancelled(true);
return;
}
}
currentBlock = currentBlock.getRelative(event.getDirection());
}
if (War.isWarTime()) {
event.setCancelled(true);
return;
}
// if (event.getBlocks().size() == 0) {
// Block extendInto = event.getBlock().getRelative(event.getDirection());
// if (!allowPistonAction(extendInto.getLocation())) {
// event.setCancelled(true);
// return;
// }
// }
coord.setFromLocation(event.getBlock().getLocation());
FarmChunk fc = CivGlobal.getFarmChunk(coord);
if (fc == null) {
event.setCancelled(true);
}
for (Block block : event.getBlocks()) {
if (!allowPistonAction(block.getLocation())) {
event.setCancelled(true);
break;
}
}
}
public static HandlerList getHandlerList() {
return BlockPistonExtendEvent.getHandlerList();
}