use of me.botsko.prism.events.BlockStateChangeImpl in project Prism-Bukkit by prism.
the class BlockAction method removeBlock.
private ChangeResult removeBlock(Player player, PrismParameters parameters, boolean isPreview, Block block) {
BlockStateChangeImpl stateChange;
if (!block.getType().equals(AIR)) {
// Ensure it's acceptable to remove the current block
if (!Utilities.isAcceptableForBlockPlace(block.getType()) && !Utilities.areBlockIdsSameCoreItem(block.getType(), getMaterial()) && !parameters.hasFlag(Flag.OVERWRITE)) {
return new ChangeResultImpl(ChangeResultType.SKIPPED, null);
}
// Capture the block before we change it
final BlockState originalBlock = block.getState();
if (!isPreview) {
// Set
block.setType(AIR);
// Capture the new state
final BlockState newBlock = block.getState();
// Store the state change
stateChange = new BlockStateChangeImpl(originalBlock, newBlock);
} else {
// Otherwise, save the state so we can cancel if needed
// Note: we save the original state as both old/new so we can
// re-use blockStateChanges
stateChange = new BlockStateChangeImpl(originalBlock, originalBlock);
// Preview it
EntityUtils.sendBlockChange(player, block.getLocation(), Bukkit.createBlockData(AIR));
// Send preview to shared players
for (final CommandSender sharedPlayer : parameters.getSharedPlayers()) {
if (sharedPlayer instanceof Player) {
EntityUtils.sendBlockChange((Player) sharedPlayer, block.getLocation(), Bukkit.createBlockData(AIR));
}
}
}
return new ChangeResultImpl(ChangeResultType.APPLIED, stateChange);
}
return new ChangeResultImpl(ChangeResultType.SKIPPED, null);
}
use of me.botsko.prism.events.BlockStateChangeImpl in project Prism-Bukkit by prism.
the class Utilities method removeMaterialsFromRadius.
/**
* Remove materials in an radius.
*
* @param materials Material array
* @param loc Location
* @param radius integer
*/
@SuppressWarnings("WeakerAccess")
public static ArrayList<BlockStateChange> removeMaterialsFromRadius(Material[] materials, final Location loc, int radius) {
final ArrayList<BlockStateChange> blockStateChanges = new ArrayList<>();
if (loc != null && radius > 0 && materials != null && materials.length > 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;
}
if (Arrays.asList(materials).contains(testLocation.getBlock().getType())) {
final BlockState originalBlock = testLocation.getBlock().getState();
testLocation.getBlock().setType(Material.AIR);
final BlockState newBlock = testLocation.getBlock().getState();
blockStateChanges.add(new BlockStateChangeImpl(originalBlock, newBlock));
}
}
}
}
}
return blockStateChanges;
}
Aggregations