下面列出了org.bukkit.Material#LAVA 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static Location findNearbyLocationForTeleport(Location location, int radius, Player player) {
int times = 0;
Block targetBlock;
do {
times++;
int xRadius = (int) (Math.random()*radius);
if (Math.random() > .5) {
xRadius = xRadius *-1;
}
int x = location.getBlockX() + xRadius;
int zRadius = (int) ((Math.sqrt(radius*radius - xRadius*xRadius)));
if (Math.random() > .5) {
zRadius = zRadius *-1;
}
int z = location.getBlockZ() + zRadius;
targetBlock = location.getWorld().getHighestBlockAt(x, z);
} while (times < 5 && (targetBlock.getType() == Material.LAVA));
if (times == 5) {
return null;
}
return targetBlock.getLocation();
}
public static void sanitizeItem(ItemStack item) {
Material mat = item.getType();
if (mat == Material.RED_BED || mat == Material.BLACK_BED || mat == Material.BLUE_BED
|| mat == Material.BROWN_BED || mat == Material.CYAN_BED
|| mat == Material.GRAY_BED || mat == Material.GREEN_BED || mat == Material.LIGHT_BLUE_BED
|| mat == Material.LIGHT_GRAY_BED || mat == Material.LIME_BED || mat == Material.MAGENTA_BED
|| mat == Material.ORANGE_BED || mat == Material.PINK_BED || mat == Material.PURPLE_BED
|| mat == Material.WHITE_BED || mat == Material.YELLOW_BED) {
divideByTwo(item);
} else if (mat == Material.OAK_DOOR || mat == Material.IRON_DOOR || mat == Material.DARK_OAK_DOOR
|| mat == Material.BIRCH_DOOR || mat == Material.ACACIA_DOOR || mat == Material.SPRUCE_DOOR
|| mat == Material.JUNGLE_DOOR) {
divideByTwo(item);
} else if (mat == Material.REDSTONE_WIRE) {
item.setType(Material.REDSTONE);
} else if (mat == Material.WATER) {
item.setType(Material.WATER_BUCKET);
} else if (mat == Material.LAVA) {
item.setType(Material.LAVA_BUCKET);
} else if (mat == Material.POTATOES) {
item.setType(Material.POTATO);
} else if (mat == Material.CARROTS) {
item.setType(Material.CARROT);
}
}
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
public void onBucketEmpty(PlayerBucketEmptyEvent event) {
Material material = (event.getBucket().equals(Material.WATER_BUCKET) ? Material.WATER : (event.getBucket().equals(Material.LAVA_BUCKET) ? Material.LAVA : Material.AIR));
if (!event.isCancelled() && region.contains(new BlockRegion(null, event.getBlockClicked().getRelative(event.getBlockFace()).getLocation().toVector())) && filter.evaluate(event.getPlayer(), material, event).equals(FilterState.DENY)) {
event.setCancelled(true);
ChatUtil.sendWarningMessage(event.getPlayer(), message);
}
}
static Material materialInBucket(Material bucket) {
switch (bucket) {
case BUCKET:
case MILK_BUCKET:
return Material.AIR;
case LAVA_BUCKET:
return Material.LAVA;
case WATER_BUCKET:
return Material.WATER;
default:
throw new IllegalArgumentException(bucket + " is not a bucket");
}
}
/**
* Tests if the specified location is valid for a natural spawn position
*
* @param world The world we're testing on
* @param x X-coordinate of the block to test
* @param z Z-coordinate of the block to test
* @return true if the location is valid, otherwise false
*/
public boolean canSpawn(World world, int x, int z) {
Block highest = world.getBlockAt(x, world.getHighestBlockYAt(x, z), z);
switch (world.getEnvironment()) {
case NETHER:
return true;
case THE_END:
return highest.getType() != Material.AIR && highest.getType() != Material.WATER && highest.getType() != Material.LAVA;
case NORMAL:
default:
return highest.getType() == Material.SAND || highest.getType() == Material.GRAVEL;
}
}
private boolean testLiquid(Set<Material> mats) {
for(Material mat : mats) {
if(mat == Material.WATER || mat == Material.STATIONARY_WATER || mat == Material.LAVA || mat == Material.STATIONARY_LAVA)
return true;
}
return false;
}
@EventHandler
public void onBucketEmpty(PlayerBucketEmptyEvent event) {
Material material = (event.getBucket().equals(Material.WATER_BUCKET) ? Material.WATER : (event.getBucket().equals(Material.LAVA_BUCKET) ? Material.LAVA : Material.AIR));
if (!event.isCancelled() && region.contains(new BlockRegion(null, event.getBlockClicked().getRelative(event.getBlockFace()).getLocation().toVector()))
&& filter.evaluate(event.getPlayer(), material, event).equals(FilterState.DENY)) {
event.setCancelled(true);
ChatUtil.sendWarningMessage(event.getPlayer(), message);
}
}
public static Material materialInBucket(Material bucket) {
switch(bucket) {
case BUCKET:
case MILK_BUCKET:
return Material.AIR;
case LAVA_BUCKET: return Material.LAVA;
case WATER_BUCKET: return Material.WATER;
default: throw new IllegalArgumentException(bucket + " is not a bucket");
}
}
@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);
}
}
}
private boolean isLavaSource(BlockData blockData) {
if (blockData.getMaterial() == Material.LAVA) {
Levelled level = (Levelled) blockData;
return level.getLevel() == 0;
}
return false;
}
@EventHandler
public void onLavaAbsorption(EntityChangeBlockEvent event) {
if (!plugin.getWorldManager().isSkyWorld(event.getBlock().getWorld())) {
return;
}
if (isLavaSource(event.getBlock().getBlockData())) {
if (event.getTo() != Material.LAVA) {
event.setCancelled(true);
// TODO: R4zorax - 21-07-2018: missing datavalue (might convert stuff - exploit)
ItemStack item = new ItemStack(event.getTo(), 1);
Location above = event.getBlock().getLocation().add(0, 1, 0);
event.getBlock().getWorld().dropItemNaturally(above, item);
}
}
}
private Optional<ItemStack> getFilledBucket(Block fluid) {
if (fluid.getType() == Material.LAVA) {
return Optional.of(new ItemStack(Material.LAVA_BUCKET));
}
else if (fluid.getType() == Material.WATER) {
return Optional.of(new ItemStack(Material.WATER_BUCKET));
}
return Optional.empty();
}
private void generateLiquid(Block block, boolean water) {
if (block.getType() == (water ? Material.WATER : Material.LAVA)) {
addLiquidLevel(block, water);
}
else if (block.getType() == (water ? Material.LAVA : Material.WATER)) {
int level = ((Levelled) block.getBlockData()).getLevel();
block.setType(level == 0 || level == 8 ? Material.OBSIDIAN : Material.STONE);
block.getWorld().playSound(block.getLocation(), Sound.BLOCK_LAVA_EXTINGUISH, 1F, 1F);
}
else {
Slimefun.runSync(() -> placeLiquid(block, water), 50L);
}
}
static boolean isLava(Material material) {
return material == Material.LAVA || material == Material.STATIONARY_LAVA;
}
@Override
public boolean isLiquid(Material material) {
return material == Material.WATER || material == Material.LAVA;
}
public boolean isLiquid() {
return (getType() == Material.WATER) || (getType() == Material.STATIONARY_WATER) || (getType() == Material.LAVA) || (getType() == Material.STATIONARY_LAVA);
}
@Override
public boolean isLiquid(Material type) {
// TODO moving water and lava
return type == Material.WATER || type == Material.LAVA;
}
@Override
public boolean isLiquid(Material type) {
return type == Material.WATER || type == Material.LAVA;
}
public boolean isLiquid() {
return (getType() == Material.WATER) || (getType() == Material.STATIONARY_WATER) || (getType() == Material.LAVA) || (getType() == Material.STATIONARY_LAVA);
}