Search in sources :

Example 1 with Waterlogged

use of org.bukkit.block.data.Waterlogged in project Prism-Bukkit by prism.

the class PrismPlayerEvents method onPlayerBucketFill.

/**
 * PlayerBucketFillEvent.
 *
 * @param event PlayerBucketFillEvent
 */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerBucketFill(final PlayerBucketFillEvent event) {
    final Player player = event.getPlayer();
    if (!Prism.getIgnore().event("bucket-fill", player)) {
        return;
    }
    final Block spot = event.getBlock();
    String liquidType = "milk";
    if (spot.getType() == Material.WATER) {
        liquidType = "water";
    } else if (spot.getBlockData() instanceof Waterlogged && ((Waterlogged) spot.getBlockData()).isWaterlogged()) {
        liquidType = "water";
    } else if (spot.getType() == Material.LAVA) {
        liquidType = "lava";
    }
    final Handler pa = ActionFactory.createPlayer("bucket-fill", player, liquidType);
    // Override the location with the area taken
    pa.setX(spot.getX());
    pa.setY(spot.getY());
    pa.setZ(spot.getZ());
    RecordingQueue.addToQueue(pa);
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler) Handler(me.botsko.prism.api.actions.Handler) Waterlogged(org.bukkit.block.data.Waterlogged) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Waterlogged

use of org.bukkit.block.data.Waterlogged in project Prism-Bukkit by prism.

the class Utilities method checkForWaterlogged.

private static ArrayList<BlockStateChangeImpl> checkForWaterlogged(final Location loc, int radius) {
    final ArrayList<BlockStateChangeImpl> blockStateChanges = new ArrayList<>();
    if (loc != null && radius > 0) {
        final int x1 = loc.getBlockX();
        final int y1 = loc.getBlockY();
        final int z1 = loc.getBlockZ();
        final World world = loc.getWorld();
        for (int x = x1 - radius; x <= x1 + radius; x++) {
            for (int y = y1 - radius; y <= y1 + radius; y++) {
                for (int z = z1 - radius; z <= z1 + radius; z++) {
                    Location testLocation = new Location(world, x, y, z);
                    final Block b = testLocation.getBlock();
                    if (b.getType().equals(Material.AIR)) {
                        continue;
                    }
                    BlockData data = testLocation.getBlock().getBlockData();
                    if (data instanceof Waterlogged) {
                        final BlockState originalBlock = testLocation.getBlock().getState();
                        BlockData modified = testLocation.getBlock().getBlockData();
                        ((Waterlogged) modified).setWaterlogged(false);
                        testLocation.getBlock().setBlockData(modified);
                        final BlockState newBlock = testLocation.getBlock().getState();
                        blockStateChanges.add(new BlockStateChangeImpl(originalBlock, newBlock));
                    }
                }
            }
        }
    }
    return blockStateChanges;
}
Also used : BlockState(org.bukkit.block.BlockState) BlockStateChangeImpl(me.botsko.prism.events.BlockStateChangeImpl) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) Waterlogged(org.bukkit.block.data.Waterlogged) World(org.bukkit.World) BlockData(org.bukkit.block.data.BlockData) Location(org.bukkit.Location)

Example 3 with Waterlogged

use of org.bukkit.block.data.Waterlogged in project Prism-Bukkit by prism.

the class PrismPlayerEvents method onPlayerBucketEmpty.

/**
 * PlayerBucketEmptyEvent.
 *
 * @param event PlayerBucketEmptyEvent
 */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerBucketEmpty(final PlayerBucketEmptyEvent event) {
    final Player player = event.getPlayer();
    String cause;
    Material newMat;
    Block spot = event.getBlockClicked().getRelative(event.getBlockFace());
    switch(event.getBucket()) {
        case LAVA_BUCKET:
            cause = "lava-bucket";
            newMat = Material.LAVA;
            break;
        case TROPICAL_FISH_BUCKET:
        case SALMON_BUCKET:
        case PUFFERFISH_BUCKET:
        case WATER_BUCKET:
        default:
            cause = "water-bucket";
            newMat = Material.WATER;
            break;
    }
    if (!Prism.getIgnore().event(cause, player)) {
        return;
    }
    BlockData oldData = spot.getBlockData();
    BlockData newData = Bukkit.createBlockData(newMat);
    BlockData clickedData = event.getBlockClicked().getBlockData();
    // TODO If "Lavalogged" blocks become a thing, please revisit.
    if (clickedData instanceof Waterlogged && event.getBucket() != Material.LAVA) {
        Waterlogged wl = (Waterlogged) clickedData;
        if (!wl.isWaterlogged()) {
            spot = event.getBlockClicked();
            newMat = spot.getType();
            oldData = wl;
            newData = wl.clone();
            ((Waterlogged) newData).setWaterlogged(true);
            cause = "water-bucket";
        }
    }
    RecordingQueue.addToQueue(ActionFactory.createBlockChange(cause, spot.getLocation(), spot.getType(), oldData, newMat, newData, player));
    if (plugin.getConfig().getBoolean("prism.alerts.uses.lava") && event.getBucket() == Material.LAVA_BUCKET && !player.hasPermission("prism.alerts.use.lavabucket.ignore") && !player.hasPermission("prism.alerts.ignore")) {
        plugin.useMonitor.alertOnItemUse(player, "poured lava", "prism.alerts.use.lavabucket");
    }
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) Material(org.bukkit.Material) Waterlogged(org.bukkit.block.data.Waterlogged) BlockData(org.bukkit.block.data.BlockData) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Block (org.bukkit.block.Block)3 Waterlogged (org.bukkit.block.data.Waterlogged)3 BlockData (org.bukkit.block.data.BlockData)2 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 ArrayList (java.util.ArrayList)1 Handler (me.botsko.prism.api.actions.Handler)1 BlockStateChangeImpl (me.botsko.prism.events.BlockStateChangeImpl)1 Location (org.bukkit.Location)1 Material (org.bukkit.Material)1 World (org.bukkit.World)1 BlockState (org.bukkit.block.BlockState)1