Search in sources :

Example 11 with BlockData

use of org.bukkit.block.data.BlockData in project Denizen-For-Bukkit by DenizenScript.

the class SwitchCommand method switchBlock.

// Break off this portion of the code from execute() so it can be used in both execute and the delayed runnable
public void switchBlock(ScriptEntry scriptEntry, Location interactLocation, SwitchState switchState, boolean physics) {
    Block block = interactLocation.getBlock();
    BlockData data1 = block.getBlockData();
    MaterialTag materialTag = new MaterialTag(data1);
    MaterialSwitchable switchable = MaterialSwitchable.getFrom(materialTag);
    if (switchable == null) {
        Debug.echoError("Cannot switch block of type '" + materialTag.getMaterial().name() + "'");
        return;
    }
    if (materialTag.getMaterial() == Material.BELL) {
        NMSHandler.getBlockHelper().ringBell((Bell) block.getState());
        return;
    }
    boolean currentState = switchable.getState();
    if ((switchState.equals(SwitchState.ON) && !currentState) || (switchState.equals(SwitchState.OFF) && currentState) || switchState.equals(SwitchState.TOGGLE)) {
        switchable.setState(!currentState);
        if (physics) {
            block.setBlockData(switchable.material.getModernData());
        } else {
            ModifyBlockCommand.setBlock(block.getLocation(), materialTag, false, null);
        }
        if (data1 instanceof Bisected && !(data1 instanceof TrapDoor)) {
            // TrapDoor implements Bisected, but is not actually bisected???
            Location other = interactLocation.clone();
            if (((Bisected) data1).getHalf() == Bisected.Half.TOP) {
                other = other.add(0, -1, 0);
            } else {
                other = other.add(0, 1, 0);
            }
            BlockData data2 = other.getBlock().getBlockData();
            if (data2.getMaterial() == data1.getMaterial()) {
                MaterialSwitchable switchable2 = MaterialSwitchable.getFrom(new MaterialTag(data2));
                switchable2.setState(!currentState);
                other.getBlock().setBlockData(switchable2.material.getModernData());
                if (physics) {
                    AdjustBlockCommand.applyPhysicsAt(other);
                }
            }
        }
        if (physics) {
            AdjustBlockCommand.applyPhysicsAt(interactLocation);
        }
        if (scriptEntry.dbCallShouldDebug()) {
            Debug.echoDebug(scriptEntry, "Switched " + block.getType().toString() + "! Current state now: " + (switchState(block) ? "ON" : "OFF"));
        }
    }
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) TrapDoor(org.bukkit.block.data.type.TrapDoor) Block(org.bukkit.block.Block) BlockData(org.bukkit.block.data.BlockData) MaterialSwitchable(com.denizenscript.denizen.objects.properties.material.MaterialSwitchable) Bisected(org.bukkit.block.data.Bisected) Location(org.bukkit.Location)

Example 12 with BlockData

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

the class PrismWorldEditLogger method setBlock.

@Override
public boolean setBlock(BlockVector3 pt, BlockStateHolder newBlock) throws WorldEditException {
    if (Prism.config.getBoolean("prism.tracking.world-edit")) {
        Location loc = BukkitAdapter.adapt(world, pt);
        Block oldBlock = loc.getBlock();
        Material newMaterial = BukkitAdapter.adapt(newBlock.getBlockType());
        BlockData newData = BukkitAdapter.adapt(newBlock);
        RecordingQueue.addToQueue(ActionFactory.createBlockChange("world-edit", loc, oldBlock.getType(), oldBlock.getBlockData(), newMaterial, newData, Bukkit.getPlayer(player.getUniqueId())));
    }
    return super.setBlock(pt, newBlock);
}
Also used : Block(org.bukkit.block.Block) Material(org.bukkit.Material) BlockData(org.bukkit.block.data.BlockData) Location(org.bukkit.Location)

Example 13 with BlockData

use of org.bukkit.block.data.BlockData 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 14 with BlockData

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

the class ProfileWand method showLocationProfile.

protected void showLocationProfile(Player player, Location loc) {
    final Block block = loc.getBlock();
    Prism.messenger.sendMessage(player, Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("profile-location")));
    BlockData data = block.getBlockData();
    Prism.messenger.sendMessage(player, Il8nHelper.formatMessage("profile-detail", block.getType().toString().toLowerCase(), block.getType() + " " + Utilities.dataString(data), Prism.getItems().getAlias(block.getType(), data), block.getX(), block.getY(), block.getZ()));
}
Also used : Block(org.bukkit.block.Block) BlockData(org.bukkit.block.data.BlockData)

Example 15 with BlockData

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

the class SqlBlockReportQueryBuilder method report.

@Override
public void report(CommandSender sender) {
    String playerName = null;
    for (String name : parameters.getPlayerNames().keySet()) {
        playerName = name;
    }
    Prism.messenger.sendMessage(sender, Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.formatMessage("actionreport-blockChange", playerName)));
    final int colTextLen = 20;
    final int colIntLen = 12;
    try (Connection conn = dataSource.getDataSource().getConnection();
        PreparedStatement s = conn.prepareStatement(getQuery(parameters, shouldGroup));
        ResultSet rs = s.executeQuery()) {
        Prism.messenger.sendMessage(sender, Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("report-block-changes").replaceText("<player>", Component.text(playerName).color(NamedTextColor.DARK_AQUA))));
        Prism.messenger.sendMessage(sender, Prism.messenger.playerMsg(Component.text(TypeUtils.padStringRight("Block", colTextLen) + TypeUtils.padStringRight("Placed", colIntLen) + TypeUtils.padStringRight("Broken", colIntLen))));
        while (rs.next()) {
            int blockId = rs.getInt(1);
            MaterialState state = Prism.getItems().idsToMaterial(blockId, 0, true);
            final String alias;
            if (state == null) {
                alias = "UnknownMaterial_BlockId_" + blockId;
            } else {
                BlockData block = state.asBlockData();
                ItemStack item = state.asItem();
                if (block != null) {
                    alias = Prism.getItems().getAlias(block.getMaterial(), block);
                } else if (item != null) {
                    alias = Prism.getItems().getAlias(item);
                } else {
                    alias = "InvalidState_" + state + "_BlockId_" + blockId;
                }
            }
            final int placed = rs.getInt(2);
            final int broken = rs.getInt(3);
            final String colAlias = TypeUtils.padStringRight(alias, colTextLen);
            final String colPlaced = TypeUtils.padStringRight("" + placed, colIntLen);
            final String colBroken = TypeUtils.padStringRight("" + broken, colIntLen);
            Prism.messenger.sendMessage(sender, Prism.messenger.playerMsg(Component.text(colAlias).color(NamedTextColor.DARK_AQUA).append(Component.text(colPlaced).color(NamedTextColor.GREEN)).append(Component.text(colBroken).color(NamedTextColor.RED))));
        }
    } catch (SQLException e) {
        dataSource.handleDataSourceException(e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) BlockData(org.bukkit.block.data.BlockData) ItemStack(org.bukkit.inventory.ItemStack) MaterialState(me.botsko.prism.api.objects.MaterialState)

Aggregations

BlockData (org.bukkit.block.data.BlockData)34 Block (org.bukkit.block.Block)10 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)8 Location (org.bukkit.Location)7 MinigamePlayer (au.com.mineauz.minigames.objects.MinigamePlayer)3 ArrayList (java.util.ArrayList)3 Material (org.bukkit.Material)3 BlockState (org.bukkit.block.BlockState)3 Lightable (org.bukkit.block.data.Lightable)3 ItemStack (org.bukkit.inventory.ItemStack)3 LocationTag (com.denizenscript.denizen.objects.LocationTag)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 MaterialState (me.botsko.prism.api.objects.MaterialState)2 BlockStateChangeImpl (me.botsko.prism.events.BlockStateChangeImpl)2 Bisected (org.bukkit.block.data.Bisected)2 Bed (org.bukkit.block.data.type.Bed)2 Player (org.bukkit.entity.Player)2