Search in sources :

Example 11 with BlockState

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

the class SignCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    String direction = scriptEntry.hasObject("direction") ? ((Element) scriptEntry.getObject("direction")).asString() : null;
    Element typeElement = scriptEntry.getElement("type");
    dList text = (dList) scriptEntry.getObject("text");
    dLocation location = (dLocation) scriptEntry.getObject("location");
    // Report to dB
    dB.report(scriptEntry, getName(), typeElement.debug() + location.debug() + text.debug());
    Type type = Type.valueOf(typeElement.asString().toUpperCase());
    Block sign = location.getBlock();
    if (type != Type.AUTOMATIC || (sign.getType() != Material.WALL_SIGN && sign.getType() != Material.SIGN_POST)) {
        sign.setType(type == Type.WALL_SIGN ? Material.WALL_SIGN : Material.SIGN_POST, false);
    }
    BlockState signState = sign.getState();
    Utilities.setSignLines((Sign) signState, text.toArray(4));
    if (direction != null) {
        Utilities.setSignRotation(signState, direction);
    } else if (type == Type.WALL_SIGN) {
        Utilities.setSignRotation(signState);
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Block(org.bukkit.block.Block) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 12 with BlockState

use of org.bukkit.block.BlockState in project Minigames by AddstarMC.

the class SwapBlockAction method executeRegionAction.

@SuppressWarnings("deprecation")
@Override
public void executeRegionAction(MinigamePlayer player, Region region) {
    for (int y = region.getFirstPoint().getBlockY(); y <= region.getSecondPoint().getBlockY(); y++) {
        for (int x = region.getFirstPoint().getBlockX(); x <= region.getSecondPoint().getBlockX(); x++) {
            for (int z = region.getFirstPoint().getBlockZ(); z <= region.getSecondPoint().getBlockZ(); z++) {
                Block block = region.getFirstPoint().getWorld().getBlockAt(x, y, z);
                if (block.getType() == Material.getMaterial(matchType.getFlag())) {
                    if (matchData.getFlag() && block.getData() != matchDataValue.getFlag().byteValue()) {
                        continue;
                    }
                    // Block matches, now replace it
                    byte data = 0;
                    BlockFace facing = null;
                    if (toData.getFlag()) {
                        // Replace data
                        data = toDataValue.getFlag().byteValue();
                    } else if (keepAttachment.getFlag()) {
                        // Keep attachments if possible
                        MaterialData mat = block.getState().getData();
                        if (mat instanceof Directional) {
                            facing = ((Directional) mat).getFacing();
                        }
                    }
                    // Update block type
                    block.setType(Material.getMaterial(toType.getFlag()), false);
                    if (facing != null) {
                        BlockState state = block.getState();
                        MaterialData mat = block.getState().getData();
                        if (mat instanceof Directional) {
                            ((Directional) mat).setFacingDirection(facing);
                        }
                        state.setData(mat);
                        state.update(true, false);
                    } else {
                        block.setData(data, false);
                    }
                }
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) MaterialData(org.bukkit.material.MaterialData) Directional(org.bukkit.material.Directional)

Example 13 with BlockState

use of org.bukkit.block.BlockState in project Minigames by AddstarMC.

the class SetBlockAction method executeRegionAction.

@SuppressWarnings("deprecation")
@Override
public void executeRegionAction(MinigamePlayer player, Region region) {
    Location temp = region.getFirstPoint();
    for (int y = region.getFirstPoint().getBlockY(); y <= region.getSecondPoint().getBlockY(); y++) {
        temp.setY(y);
        for (int x = region.getFirstPoint().getBlockX(); x <= region.getSecondPoint().getBlockX(); x++) {
            temp.setX(x);
            for (int z = region.getFirstPoint().getBlockZ(); z <= region.getSecondPoint().getBlockZ(); z++) {
                temp.setZ(z);
                BlockState bs = temp.getBlock().getState();
                bs.setType(Material.getMaterial(type.getFlag()));
                if (usedur.getFlag()) {
                    bs.getData().setData(dur.getFlag().byteValue());
                }
                bs.update(true);
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Location(org.bukkit.Location)

Example 14 with BlockState

use of org.bukkit.block.BlockState in project Minigames by AddstarMC.

the class SetBlockAction method executeNodeAction.

@SuppressWarnings("deprecation")
@Override
public void executeNodeAction(MinigamePlayer player, Node node) {
    BlockState bs = node.getLocation().getBlock().getState();
    bs.setType(Material.getMaterial(type.getFlag()));
    if (usedur.getFlag()) {
        bs.getData().setData(dur.getFlag().byteValue());
    }
    bs.update(true);
}
Also used : BlockState(org.bukkit.block.BlockState)

Example 15 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class BlockMushroom method grow.

@Override
public void grow(GlowPlayer player, GlowBlock block) {
    TreeType type;
    if (mushroomType == Material.BROWN_MUSHROOM) {
        type = TreeType.BROWN_MUSHROOM;
    } else if (mushroomType == Material.RED_MUSHROOM) {
        type = TreeType.RED_MUSHROOM;
    } else {
        return;
    }
    Location loc = block.getLocation();
    BlockStateDelegate blockStateDelegate = new BlockStateDelegate();
    if (GlowTree.newInstance(type, random, loc, blockStateDelegate).generate()) {
        List<BlockState> blockStates = new ArrayList<>(blockStateDelegate.getBlockStates());
        StructureGrowEvent growEvent = new StructureGrowEvent(loc, type, true, player, blockStates);
        EventFactory.callEvent(growEvent);
        if (!growEvent.isCancelled()) {
            for (BlockState state : blockStates) {
                state.update(true);
            }
        }
    }
}
Also used : TreeType(org.bukkit.TreeType) BlockStateDelegate(net.glowstone.util.BlockStateDelegate) BlockState(org.bukkit.block.BlockState) GlowBlockState(net.glowstone.block.GlowBlockState) ArrayList(java.util.ArrayList) StructureGrowEvent(org.bukkit.event.world.StructureGrowEvent) Location(org.bukkit.Location)

Aggregations

BlockState (org.bukkit.block.BlockState)59 Block (org.bukkit.block.Block)26 EventHandler (org.bukkit.event.EventHandler)15 MaterialData (org.bukkit.material.MaterialData)12 Location (org.bukkit.Location)11 BlockFace (org.bukkit.block.BlockFace)8 Material (org.bukkit.Material)6 Player (org.bukkit.entity.Player)6 ArrayList (java.util.ArrayList)5 BlockStateChange (me.botsko.prism.events.BlockStateChange)5 World (org.bukkit.World)5 GlowBlockState (net.glowstone.block.GlowBlockState)4 CreatureSpawner (org.bukkit.block.CreatureSpawner)4 ItemStack (org.bukkit.inventory.ItemStack)4 GlowBlock (net.glowstone.block.GlowBlock)3 HashMap (java.util.HashMap)2 Handler (me.botsko.prism.actions.Handler)2 ChangeResult (me.botsko.prism.appliers.ChangeResult)2 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)2 Element (net.aufdemrand.denizencore.objects.Element)2