下面列出了怎么用org.bukkit.event.block.BlockFromToEvent的API类实例代码及写法,或者点击链接到github查看源代码。
@EventHandler
public void onLiquidFlow(BlockFromToEvent event) {
if (event.isCancelled()) {
return;
}
for (String gameName : Main.getGameNames()) {
Game game = Main.getGame(gameName);
if (GameCreator.isInArea(event.getBlock().getLocation(), game.getPos1(), game.getPos2())) {
if (game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) {
Block block = event.getToBlock();
if (block.getType() == Material.AIR
|| game.getRegion().isBlockAddedDuringGame(block.getLocation())) {
game.getRegion().addBuiltDuringGame(block.getLocation());
} else {
event.setCancelled(true);
}
} else if (game.getStatus() != GameStatus.DISABLED) {
event.setCancelled(true);
}
}
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void block(BlockFromToEvent event) {
if (!useEnhanceProtection) {
return;
}
if (DisplayItem.getNowUsing() != DisplayType.REALITEM) {
return;
}
final Block targetBlock = event.getToBlock();
final Block shopBlock = targetBlock.getRelative(BlockFace.DOWN);
final Shop shop = getShopNature(shopBlock.getLocation(),true);
if (shop == null) {
return;
}
event.setCancelled(true);
if (shop.getDisplay() != null) {
shop.getDisplay().remove();
}
sendAlert(
"[DisplayGuard] Liuqid "
+ targetBlock.getLocation()
+ " trying flow to top of shop, QuickShop already cancel it.");
}
@EventHandler
public void onLiquidFlow(BlockFromToEvent event) {
if (event.isCancelled()) {
return;
}
for (String gameName : Main.getGameNames()) {
Game game = Main.getGame(gameName);
if (GameCreator.isInArea(event.getBlock().getLocation(), game.getPos1(), game.getPos2())) {
if (game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) {
Block block = event.getToBlock();
if (block.getType() == Material.AIR
|| game.getRegion().isBlockAddedDuringGame(block.getLocation())) {
game.getRegion().addBuiltDuringGame(block.getLocation());
} else {
event.setCancelled(true);
}
} else if (game.getStatus() != GameStatus.DISABLED) {
event.setCancelled(true);
}
}
}
}
/**
* Only allow sea-level blocks to flow if they are below the custom sea-level
* - Track any new blocks originating from sea-level blocks
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockFromToEvent(BlockFromToEvent event) {
if (event.getBlock().hasMetadata(SEALEVEL_BLOCK)) {
boolean isWaterFixed = isOverride;
if (!isWaterFixed) {
final World world = event.getBlock().getWorld();
final WorldClimateEngine climateEngine = ClimateEngine.getInstance().getClimateEngine(world.getUID());
final int deltaSeaLevel = (int) seaMap.getValue(climateEngine.getTemperature());
final int customSeaLevel = baseSeaLevel + deltaSeaLevel;
isWaterFixed = event.getBlock().getY() == event.getToBlock().getY() &&
event.getBlock().getY() > customSeaLevel;
}
if (!isWaterFixed) {
isWaterFixed = !isSameChunk(event.getBlock().getChunk(), event.getToBlock().getChunk());
}
if (isWaterFixed) {
event.setCancelled(true);
} else {
event.getToBlock().setMetadata(SEALEVEL_BLOCK, BLOCK_TAG);
}
}
}
public static void handleToFromEvent(@Nonnull BlockFromToEvent e) {
if (e.isCancelled()) return;
// Only continue if we should stop the spread from the config.
if (!config.getBool("protection", "blockFluidSpreadIntoClaims")) return;
// If the block isn't water or lava, we don't protect it.
Material blockType = e.getBlock().getType();
if (blockType != Material.WATER && blockType != Material.LAVA) return;
Chunk from = e.getBlock().getChunk();
Chunk to = e.getToBlock().getChunk();
// If the from and to chunks have the same owner or if the to chunk is
// unclaimed, the flow is allowed.
final ChunkHandler CHUNK = ClaimChunk.getInstance().getChunkHandler();
if (getChunksSameOwner(CHUNK, from, to) || !CHUNK.isClaimed(to)) return;
// Cancel the flow
e.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onBlockFromTo(BlockFromToEvent event) {
final Block fromBlock = event.getBlock();
final Block toBlock = event.getToBlock();
final World world = fromBlock.getWorld();
if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
return;
}
final GDPermissionUser user = CauseContextHelper.getEventUser(fromBlock.getLocation(), PlayerTracker.Type.NOTIFIER);
if (user == null) {
return;
}
Location location = toBlock.getLocation();
GDClaim targetClaim = this.storage.getClaimAt(location);
if (targetClaim.isWilderness()) {
return;
}
if (fromBlock.isLiquid()) {
final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.LIQUID_FLOW, fromBlock, toBlock, user, TrustTypes.BUILDER, true);
if (result == Tristate.FALSE) {
event.setCancelled(true);
return;
}
} else if (handleBlockBreak(event, location, targetClaim, event.getBlock(), event.getToBlock(), user, false)) {
event.setCancelled(true);
}
}
@SuppressWarnings("deprecation")
@EventWrapper
public void onBlockFromTo(BlockFromToEvent event) {
if (event.getToBlock().getType() != event.getBlock().getType()) {
BlockState oldState = event.getToBlock().getState();
BlockState newState = event.getToBlock().getState();
newState.setType(event.getBlock().getType());
newState.setRawData(event.getBlock().getData());
// Check for lava ownership
this.callEvent(event, oldState, newState, Trackers.getOwner(event.getBlock()));
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockFromTo(BlockFromToEvent event) {
Block block = event.getBlock();
LWC lwc = this.plugin.getLWC();
if (block.getType() == Material.WATER && lwc.isProtectable(event.getToBlock())) {
if (lwc.findProtection(event.getToBlock().getLocation()) != null) {
event.setCancelled(true);
return;
}
}
}
@SuppressWarnings("deprecation")
@EventWrapper
public void onBlockFromTo(BlockFromToEvent event) {
if(event.getToBlock().getType() != event.getBlock().getType()) {
BlockState oldState = event.getToBlock().getState();
BlockState newState = event.getToBlock().getState();
newState.setType(event.getBlock().getType());
newState.setRawData(event.getBlock().getData());
// Check for lava ownership
this.callEvent(event, oldState, newState, blockResolver.getOwner(event.getBlock()));
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onLiquidFlow(BlockFromToEvent e) {
Block b = e.getToBlock();
Block below = b.getRelative(BlockFace.DOWN);
if (shopUtils.isShop(below.getLocation())) e.setCancelled(true);
}
@EventHandler
public void onBlockFromTo(BlockFromToEvent event) {
if(!Config.REGION_WATERFLOW.getBoolean()) {
Material type = event.getBlock().getType();
if((type == Material.WATER || type == CompatibilityUtils.Mat.WATER.get() || type == Material.LAVA || type == CompatibilityUtils.Mat.LAVA.get())
&& RegionManager.get(event.getBlock()) == null
&& RegionManager.get(event.getToBlock()) != null) {
event.setCancelled(true);
}
}
}
@EventHandler(ignoreCancelled = true)
public void onLiquidFlow(BlockFromToEvent e) {
Block block = e.getToBlock();
if (block.getType() == Material.PLAYER_HEAD || block.getType() == Material.PLAYER_WALL_HEAD || Tag.SAPLINGS.isTagged(block.getType())) {
String item = BlockStorage.checkID(block);
if (item != null) {
e.setCancelled(true);
}
}
}
/**
* Removes stone generated by lava pouring onto water
*
* @param e - event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onCleanstoneGen(BlockFromToEvent e) {
// Only do this in ASkyBlock world
if (!e.getBlock().getWorld().equals(ASkyBlock.getIslandWorld())) {
return;
}
// Do nothing if a new island is being created
if (plugin.isNewIsland())
return;
final Block to = e.getToBlock();
/*
plugin.getLogger().info("From material is " + e.getBlock().toString());
plugin.getLogger().info("To material is " + to.getType().toString());
plugin.getLogger().info("---------------------------------");
*/
if (Settings.acidDamage > 0) {
if (DEBUG)
plugin.getLogger().info("DEBUG: cleanstone gen " + e.getEventName());
final Material prev = to.getType();
// plugin.getLogger().info("To material was " +
// to.getType().toString());
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
// plugin.getLogger().info("To material is after 1 tick " +
// to.getType().toString());
if ((prev.equals(Material.WATER) || prev.equals(Material.STATIONARY_WATER)) && to.getType().equals(Material.STONE)) {
to.setType(prev);
if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
to.getWorld().playSound(to.getLocation(), Sound.valueOf("FIZZ"), 1F, 2F);
} else {
to.getWorld().playSound(to.getLocation(), Sound.ENTITY_CREEPER_PRIMED, 1F, 2F);
}
}
}
});
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockFromTo(BlockFromToEvent event) {
Location location = BukkitUtil.adapt(event.getBlock().getLocation());
if (manager.isPlotWorld(location)) {
PlotId id = manager.getPlotId(location);
if (id == null) {
event.setCancelled(true);
} else {
event.setCancelled(api.isPlotLocked(id));
}
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockFromTo(BlockFromToEvent event) {
if (lava.contains(event.getToBlock())){
event.setCancelled(true);
}
if (!event.isCancelled()) {
Block to = event.getToBlock();
Block from = event.getBlock();
if (CoreObjective.getClosestCore(to.getX(), to.getY(), to.getZ()).equals(this)) {
if ((from.getType().equals(Material.LAVA) || from.getType().equals(Material.STATIONARY_LAVA)) && to.getType().equals(Material.AIR)) {
double minY = 256;
for (Block block : getCore()) {
if (block.getY() < minY)
minY = block.getY();
}
if (minY - to.getY() >= leak && !this.complete) {
this.complete = true;
event.setCancelled(false);
if (this.show)
ChatUtil.getGlobalChannel().sendLocalizedMessage(new UnlocalizedChatMessage(ChatColor.RED + "{0}", new LocalizedChatMessage(ChatConstant.UI_OBJECTIVE_LEAKED, team.getCompleteName() + ChatColor.RED, name)));
ObjectiveCompleteEvent compEvent = new ObjectiveCompleteEvent(this, null);
Bukkit.getServer().getPluginManager().callEvent(compEvent);
}
}
}
}
}
@EventHandler
public void onBlockFromTo(BlockFromToEvent 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 Material material = block.getType();
final Block toBlock = event.getToBlock();
final Location toLocation = toBlock.getLocation();
if (material.equals(Material.WATER) || material.equals(Material.LAVA)) {
final Island toIsland = islandManager.getIslandViaLocation(toLocation);
if (island != toIsland)
event.setCancelled(true);
}
if (!IridiumSkyblock.getUpgrades().oresUpgrade.enabled) return;
if (event.getFace() == BlockFace.DOWN) return;
if (!isSurroundedByWater(toLocation))
return;
final int oreLevel = island.getOreLevel();
final World world = location.getWorld();
if (world == null) return;
final String worldName = world.getName();
final Config config = IridiumSkyblock.getConfiguration();
List<String> islandOreUpgrades;
if (worldName.equals(config.worldName)) islandOreUpgrades = IridiumSkyblock.oreUpgradeCache.get(oreLevel);
else if (worldName.equals(config.netherWorldName)) islandOreUpgrades = IridiumSkyblock.netherOreUpgradeCache.get(oreLevel);
else return;
Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> {
final Material toMaterial = toBlock.getType();
if (!(toMaterial.equals(Material.COBBLESTONE) || toMaterial.equals(Material.STONE)))
return;
final Random random = new Random();
final String oreUpgrade = islandOreUpgrades.get(random.nextInt(islandOreUpgrades.size()));
final XMaterial oreUpgradeXmaterial = XMaterial.valueOf(oreUpgrade);
final Material oreUpgradeMaterial = oreUpgradeXmaterial.parseMaterial(true);
if (oreUpgradeMaterial == null) return;
toBlock.setType(oreUpgradeMaterial);
final BlockState blockState = toBlock.getState();
blockState.update(true);
if (Utils.isBlockValuable(toBlock)) {
final XMaterial xmaterial = XMaterial.matchXMaterial(material);
island.valuableBlocks.compute(xmaterial.name(), (name, original) -> {
if (original == null) return 1;
return original + 1;
});
if (island.updating)
island.tempValues.add(location);
island.calculateIslandValue();
}
});
} catch (Exception ex) {
IridiumSkyblock.getInstance().sendErrorMessage(ex);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void noMelt(final BlockFromToEvent event) {
event.setCancelled(true);
}
@EventHandler
public void onFireSpread(BlockFromToEvent e) {
if (e != null) {
ChunkEventHelper.handleToFromEvent(e);
}
}
@EventHandler
public void onBlockFromTo(BlockFromToEvent blockFromToEvent) {
checkSafety(blockFromToEvent);
}
@EventHandler
public void onBlockFromTo(BlockFromToEvent blockFromToEvent) {
checkSafety(blockFromToEvent);
}
@EventHandler
public void onLiquidFlow(BlockFromToEvent event) {
if (!match.isRunning()) {
event.setCancelled(true);
}
}
@EventHandler
public void onBLiquidFlow(BlockFromToEvent event) {
if (!event.isCancelled() && region.contains(new BlockRegion(null, event.getToBlock().getLocation().toVector())) && filter.evaluate(event.getToBlock(), event).equals(FilterState.DENY)) {
event.setCancelled(true);
}
}
@EventHandler
public void onBlockFromTo(BlockFromToEvent event) {
if (filter.evaluate(event.getToBlock(), event).equals(FilterState.DENY) && region.contains(new BlockRegion(null, event.getToBlock().getLocation().toVector()))) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void BlockFromToEvent(BlockFromToEvent e) {
if (e.getBlock().hasMetadata("ce.Ice"))
e.setCancelled(true);
}