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);
}
}
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);
}
}
}
}
}
}
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);
}
}
}
}
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);
}
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);
}
}
}
}
Aggregations