org.bukkit.block.data.Waterlogged Java Examples

The following examples show how to use org.bukkit.block.data.Waterlogged. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RainbowTickHandler.java    From Slimefun4 with GNU General Public License v3.0 7 votes vote down vote up
@Override
public void tick(Block b, SlimefunItem item, Config data) {
    if (b.getType() == Material.AIR) {
        // The block was broken, setting the Material now would result in a
        // duplication glitch
        return;
    }

    if (waterlogged) {
        BlockData blockData = b.getBlockData();
        b.setType(material, true);

        if (blockData instanceof Waterlogged && ((Waterlogged) blockData).isWaterlogged()) {
            Waterlogged block = (Waterlogged) b.getBlockData();
            block.setWaterlogged(true);
            b.setBlockData(block);
        }
    }
    else {
        b.setType(material, false);
    }
}
 
Example #2
Source File: Crucible.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private void placeLiquid(Block block, boolean water) {
    if (block.getType() == Material.AIR || block.getType() == Material.CAVE_AIR || block.getType() == Material.VOID_AIR) {
        block.setType(water ? Material.WATER : Material.LAVA);
    }
    else {
        if (water && block.getBlockData() instanceof Waterlogged) {
            Waterlogged wl = (Waterlogged) block.getBlockData();
            wl.setWaterlogged(true);
            block.setBlockData(wl, false);
            block.getWorld().playSound(block.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F);
            return;
        }

        if (BlockStorage.hasBlockInfo(block)) {
            BlockStorage.clearBlockInfo(block);
        }
    }

    runPostTask(block, water ? Sound.ENTITY_PLAYER_SPLASH : Sound.BLOCK_LAVA_POP, 1);
}
 
Example #3
Source File: RainbowTickHandler.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method checks whether a given {@link Material} array contains any {@link Material}
 * that would result in a {@link Waterlogged} {@link BlockData}.
 * This is done to save performance, so we don't have to validate {@link BlockData} at
 * runtime.
 * 
 * @param materials
 *            The {@link Material} Array to check
 * 
 * @return Whether the array contained any {@link Waterlogged} materials
 */
private boolean containsWaterlogged(Material[] materials) {
    if (SlimefunPlugin.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) {
        // BlockData is not available to us during Unit Tests :/
        return false;
    }

    for (Material type : materials) {
        // This BlockData is purely virtual and only created on startup, it should have
        // no impact on performance, in fact it should save performance as it preloads
        // the data but also saves heavy calls for non-waterlogged Materials
        if (type.createBlockData() instanceof Waterlogged) {
            return true;
        }
    }

    return false;
}
 
Example #4
Source File: PlantsListener.java    From ExoticGarden with GNU General Public License v3.0 5 votes vote down vote up
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;
        }
    }
}
 
Example #5
Source File: ShopManager.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Create a shop use Shop and Info object.
 *
 * @param shop The shop object
 * @param info The info object
 */
public void createShop(@NotNull Shop shop, @NotNull Info info) {
    Player player = Bukkit.getPlayer(shop.getOwner());
    if (player == null) {
        throw new IllegalStateException("The owner creating the shop is offline or not exist");
    }
    ShopCreateEvent shopCreateEvent = new ShopCreateEvent(shop, player);
    if (Util.fireCancellableEvent(shopCreateEvent)) {
        Util.debugLog("Cancelled by plugin");
        return;
    }
    if (info.getSignBlock() != null && autoSign) {
        if (Util.isAir(info.getSignBlock().getType()) || info.getSignBlock().getType() == Material.WATER) {
            info.getSignBlock().setType(Util.getSignMaterial());
            BlockState bs = info.getSignBlock().getState();
            if (info.getSignBlock().getType() == Material.WATER && (bs.getBlockData() instanceof Waterlogged)) {
                Waterlogged waterable = (Waterlogged) bs.getBlockData();
                waterable.setWaterlogged(true); // Looks like sign directly put in water
            }
            if (bs.getBlockData() instanceof WallSign) {
                WallSign signBlockDataType = (WallSign) bs.getBlockData();
                BlockFace bf = info.getLocation().getBlock().getFace(info.getSignBlock());
                if (bf != null) {
                    signBlockDataType.setFacing(bf);
                    bs.setBlockData(signBlockDataType);
                }
            } else {
                plugin.getLogger().warning("Sign material " + bs.getType().name() + " not a WallSign, make sure you using correct sign material.");
            }
            bs.update(true);
        } else {
            if (!plugin.getConfig().getBoolean("shop.allow-shop-without-space-for-sign")) {
                MsgUtil.sendMessage(player, MsgUtil.getMessage("failed-to-put-sign", player));
                Util.debugLog("Sign cannot placed cause no enough space(Not air block)");
                return;
            }
        }
    }
    //load the shop finally
    shop.onLoad();
    //first init
    shop.setSignText();
    //sync add to prevent compete issue
    addShop(shop.getLocation().getWorld().getName(), shop);
    //save to database
    plugin.getDatabaseHelper().createShop(
            shop,
            null,
            e -> Bukkit.getScheduler().runTask(plugin, () -> {
                //also remove from memory when failed
                shop.delete(true);
                plugin.getLogger().warning("Shop create failed, trying to auto fix the database...");
                boolean backupSuccess = Util.backupDatabase();
                if (backupSuccess) {
                    plugin.getDatabaseHelper().removeShop(shop);
                } else {
                    plugin.getLogger().warning("Failed to backup the database, all changes will revert after a reboot.");
                }
            }));
}