下面列出了怎么用org.bukkit.event.block.BlockGrowEvent的API类实例代码及写法,或者点击链接到github查看源代码。
@EventHandler
public void onBlockGrow(BlockGrowEvent 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;
if (island.getFarmingBooster() == 0) return;
final Material material = block.getType();
if (!XBlock.isCrops(material)) return;
event.setCancelled(true);
final Crops crops = new Crops(CropState.RIPE);
final BlockState blockState = block.getState();
blockState.setData(crops);
blockState.update();
} catch (Exception e) {
IridiumSkyblock.getInstance().sendErrorMessage(e);
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onBlockGrow(BlockGrowEvent event) {
final Block block = event.getBlock();
final World world = event.getBlock().getWorld();
if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
return;
}
final Location location = block.getLocation();
final GDClaim targetClaim = this.storage.getClaimAt(location);
if (targetClaim.isWilderness()) {
return;
}
final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.BLOCK_GROW, null, event.getBlock(), (GDPermissionUser) null, TrustTypes.BUILDER, false);
if (result == Tristate.FALSE) {
event.setCancelled(true);
return;
}
}
@EventHandler
public void onCropGrow(BlockGrowEvent event) {
WorldClimateEngine worldEngine = ClimateEngine.getInstance().getClimateEngine(event.getBlock().getWorld().getUID());
if (worldEngine != null && worldEngine.isEffectEnabled(ClimateEffectType.FARM_YIELD)) {
Distribution distribution = cropDistribution.get(event.getBlock().getType());
if (distribution != null) {
double random = GlobalWarming.getInstance().getRandom().nextDouble();
double chance = distribution.getValue(worldEngine.getTemperature());
if (chance / 100.f <= random) {
event.setCancelled(true);
}
}
}
}
@SuppressWarnings("null")
@Override
public boolean check(Event e) {
if (types != null) {
for (ItemType type : types.getAll()) {
if (new ItemType(((BlockGrowEvent) e).getBlock()).equals(type))
return true;
}
return false; // Not one of given types
}
return true;
}
@EventHandler(priority = EventPriority.MONITOR)
public void blockChanged(BlockGrowEvent e){
if(e.isCancelled())return;
logBlockCreated(e.getBlock());
// System.out.println(7);
}
@EventHandler(ignoreCancelled = true)
public void onBlockGrow(BlockGrowEvent grow) {
Game game =
BedwarsRel.getInstance().getGameManager().getGameByLocation(grow.getBlock().getLocation());
if (game == null) {
return;
}
grow.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockGrow(BlockGrowEvent e) {
Block newBlock = e.getNewState().getBlock();
if (shopUtils.isShop(newBlock.getLocation()) || shopUtils.isShop(newBlock.getRelative(BlockFace.DOWN).getLocation())) {
e.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockGrowEvent(BlockGrowEvent event) {
bcoord.setFromLocation(event.getBlock().getLocation().add(0, -1, 0));
if (CivGlobal.vanillaGrowthLocations.contains(bcoord)) {
/* Allow vanilla growth on these plots. */
return;
}
Block b = event.getBlock();
if (Farm.isBlockControlled(b)) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockGrow(BlockGrowEvent 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.MONITOR, ignoreCancelled = true)
public void onBlockChange(BlockGrowEvent evt) {
onBlockChange(evt.getBlock().getLocation());
}
@EventWrapper
public void onBlockForm(final BlockGrowEvent event) {
this.callEvent(
new BlockTransformEvent(event, event.getBlock().getState(), event.getNewState()));
}
@EventWrapper
public void onBlockForm(final BlockGrowEvent event) {
this.callEvent(new BlockTransformEvent(event, event.getBlock().getState(), event.getNewState()));
}
@EventHandler
public void onBlockGrow(BlockGrowEvent event) {
if (!match.isRunning()) {
event.setCancelled(true);
}
}
@EventHandler
public void onBlockGrow(BlockGrowEvent event) {
if (filter.evaluate(event.getBlock(), event).equals(FilterState.DENY) && region.contains(new BlockRegion(null, event.getBlock().getLocation().toVector()))) {
event.setCancelled(true);
}
}