Add missing `replaceBlocks` method

This commit is contained in:
Telesphoreo 2024-04-25 14:53:08 -05:00
parent 53215be7ab
commit 9fc56831b6
1 changed files with 38 additions and 15 deletions

View File

@ -6,6 +6,7 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
@ -19,13 +20,15 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class CoreProtectLogger extends AbstractDelegateExtent {
public class CoreProtectLogger extends AbstractDelegateExtent
{
private final Actor eventActor;
private final World eventWorld;
private final Extent eventExtent;
protected CoreProtectLogger(Actor actor, World world, Extent extent) {
protected CoreProtectLogger(Actor actor, World world, Extent extent)
{
super(extent);
this.eventActor = actor;
this.eventWorld = world;
@ -33,12 +36,17 @@ public class CoreProtectLogger extends AbstractDelegateExtent {
}
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException
{
org.bukkit.World world = BukkitAdapter.adapt(eventWorld);
if (!Config.getConfig(world).WORLDEDIT) {
if (CoreProtectEditSessionEvent.isFAWE()) {
if (!Config.getConfig(world).WORLDEDIT)
{
if (CoreProtectEditSessionEvent.isFAWE())
{
return eventExtent.setBlock(position.getX(), position.getY(), position.getZ(), block);
} else {
}
else
{
return eventExtent.setBlock(position, block);
}
}
@ -53,13 +61,18 @@ public class CoreProtectLogger extends AbstractDelegateExtent {
// e.g. BaseBlock block = eventWorld.getBlock(position);
ItemStack[] containerData = CoreProtectEditSessionEvent.isFAWE() ? null : Util.getContainerContents(oldType, null, location);
if (CoreProtectEditSessionEvent.isFAWE()) {
if (eventExtent.setBlock(position.getX(), position.getY(), position.getZ(), block)) {
if (CoreProtectEditSessionEvent.isFAWE())
{
if (eventExtent.setBlock(position.getX(), position.getY(), position.getZ(), block))
{
WorldEditLogger.postProcess(eventExtent, eventActor, position, location, block, baseBlock, oldType, oldBlock, containerData);
return true;
}
} else {
if (eventExtent.setBlock(position, block)) {
}
else
{
if (eventExtent.setBlock(position, block))
{
WorldEditLogger.postProcess(eventExtent, eventActor, position, location, block, baseBlock, oldType, oldBlock, containerData);
return true;
}
@ -69,18 +82,28 @@ public class CoreProtectLogger extends AbstractDelegateExtent {
}
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException {
return setBlock(BlockVector3.at(x, y, z), block);
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException
{
return this.setBlock(BlockVector3.at(x, y, z), block);
}
@Override
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
public int replaceBlocks(final Region region, final Mask mask, final Pattern pattern) throws MaxChangedBlocksException
{
return this.setBlocks(region, pattern);
}
@Override
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException
{
org.bukkit.World world = BukkitAdapter.adapt(eventWorld);
if (!Config.getConfig(world).WORLDEDIT) {
if (!Config.getConfig(world).WORLDEDIT)
{
return eventExtent.setBlocks(region, pattern);
}
for (BlockVector3 position : region.clone()) {
for (BlockVector3 position : region.clone())
{
BlockState oldBlock = eventExtent.getBlock(position);
Material oldType = BukkitAdapter.adapt(oldBlock.getBlockType());
Location location = new Location(world, position.getBlockX(), position.getBlockY(), position.getBlockZ());