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