下面列出了org.bukkit.Material#WATER 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
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");
}
}
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();
}
/**
* 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;
}
private void consumeFluid(Block fluid) {
if (fluid.getType() == Material.WATER) {
fluid.setType(Material.AIR);
return;
}
List<Block> list = Vein.find(fluid, RANGE, block -> block.isLiquid() && block.getType() == fluid.getType());
list.get(list.size() - 1).setType(Material.AIR);
}
@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;
}
}
}
@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() && filter.evaluate(event.getPlayer(), material, event).equals(FilterState.DENY)
&& region.contains(new BlockRegion(null, event.getBlockClicked().getRelative(event.getBlockFace()).getLocation().toVector()))) {
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");
}
}
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);
}
}
private void pasteTree(ChunkPopulateEvent e, int x, int z, Tree tree) {
for (int y = e.getWorld().getMaxHeight(); y > 30; y--) {
Block current = e.getWorld().getBlockAt(x, y, z);
if (!current.getType().isSolid() && current.getType() != Material.WATER && current.getType() != Material.SEAGRASS && current.getType() != Material.TALL_SEAGRASS && !(current.getBlockData() instanceof Waterlogged && ((Waterlogged) current.getBlockData()).isWaterlogged()) && tree.isSoil(current.getRelative(0, -1, 0).getType()) && isFlat(current)) {
Schematic.pasteSchematic(new Location(e.getWorld(), x, y, z), tree);
break;
}
}
}
@Override
public boolean isLiquid(Material material) {
return material == Material.WATER || material == Material.LAVA;
}
static boolean isWater(Material material) {
return material == Material.WATER || material == Material.STATIONARY_WATER;
}
@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);
}
/**
* Check if player can be burned by acid
* @param player
* @return true if player is not safe
*/
private boolean isSafeFromAcid(Player player) {
if (DEBUG)
plugin.getLogger().info("DEBUG: safe from acid");
if (!player.getWorld().equals(ASkyBlock.getIslandWorld())) {
if (DEBUG)
plugin.getLogger().info("DEBUG: wrong world");
return true;
}
// In liquid
Material bodyMat = player.getLocation().getBlock().getType();
Material headMat = player.getLocation().getBlock().getRelative(BlockFace.UP).getType();
if (bodyMat.equals(Material.STATIONARY_WATER))
bodyMat = Material.WATER;
if (headMat.equals(Material.STATIONARY_WATER))
headMat = Material.WATER;
if (bodyMat != Material.WATER && headMat != Material.WATER) {
if (DEBUG)
plugin.getLogger().info("DEBUG: not in water " + player.getLocation().getBlock().isLiquid() + " " + player.getLocation().getBlock().getRelative(BlockFace.UP).isLiquid());
return true;
}
// Check if player is in a boat
Entity playersVehicle = player.getVehicle();
if (playersVehicle != null) {
// They are in a Vehicle
if (playersVehicle.getType().equals(EntityType.BOAT)) {
// I'M ON A BOAT! I'M ON A BOAT! A %^&&* BOAT!
if (DEBUG)
plugin.getLogger().info("DEBUG: boat");
return true;
}
}
// Check if full armor protects
if (Settings.fullArmorProtection) {
boolean fullArmor = true;
for (ItemStack item : player.getInventory().getArmorContents()) {
if (item == null || (item != null && item.getType().equals(Material.AIR))) {
fullArmor = false;
break;
}
}
if (fullArmor) {
if (DEBUG)
plugin.getLogger().info("DEBUG: full armor");
return true;
}
}
// Check if player has an active water potion or not
Collection<PotionEffect> activePotions = player.getActivePotionEffects();
for (PotionEffect s : activePotions) {
// plugin.getLogger().info("Potion is : " +
// s.getType().toString());
if (s.getType().equals(PotionEffectType.WATER_BREATHING)) {
// Safe!
if (DEBUG)
plugin.getLogger().info("DEBUG: Water breathing potion protection!");
return true;
}
}
// Check if water above sea-level is not acid
Island island = plugin.getGrid().getIslandAt(player.getLocation());
if (island != null && !island.getIgsFlag(SettingsFlag.ACID_DAMAGE) && player.getLocation().getBlockY() > Settings.seaHeight) {
if (DEBUG)
plugin.getLogger().info("DEBUG:no acid damage above sea level 1");
return true;
}
if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.ACID_DAMAGE) && player.getLocation().getBlockY() > Settings.seaHeight) {
if (DEBUG)
plugin.getLogger().info("DEBUG: no acid damage above sea level");
return true;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: burn in acid");
return false;
}
public static boolean isWater(Material material) {
return material == Material.WATER || material == Material.STATIONARY_WATER;
}
@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;
}