2021-07-23 15:48:51 +00:00
|
|
|
package com.fastasyncworldedit.core.extent;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2021-07-01 20:16:25 +00:00
|
|
|
import com.fastasyncworldedit.core.FaweCache;
|
|
|
|
import com.fastasyncworldedit.core.object.FaweLimit;
|
|
|
|
import com.fastasyncworldedit.core.util.WEManager;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
|
|
|
import com.sk89q.worldedit.entity.BaseEntity;
|
|
|
|
import com.sk89q.worldedit.entity.Entity;
|
|
|
|
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
|
|
|
import com.sk89q.worldedit.extent.Extent;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.util.Location;
|
2019-04-03 05:53:58 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
2019-07-09 19:50:13 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
|
|
|
import com.sk89q.worldedit.world.block.BlockState;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
2019-06-23 18:05:14 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
public class ProcessedWEExtent extends AbstractDelegateExtent {
|
2020-04-30 20:26:52 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
private final FaweLimit limit;
|
2019-10-23 04:23:52 +00:00
|
|
|
private final Extent extent;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2019-09-22 01:00:45 +00:00
|
|
|
public ProcessedWEExtent(Extent parent, FaweLimit limit) {
|
2018-08-12 14:03:07 +00:00
|
|
|
super(parent);
|
|
|
|
this.limit = limit;
|
2019-10-23 04:23:52 +00:00
|
|
|
this.extent = parent;
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setLimit(FaweLimit other) {
|
|
|
|
this.limit.set(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-22 01:00:45 +00:00
|
|
|
public Entity createEntity(Location location, BaseEntity entity) {
|
2018-08-12 14:03:07 +00:00
|
|
|
if (entity == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (!limit.MAX_ENTITIES()) {
|
2020-01-29 20:01:38 +00:00
|
|
|
WEManager.IMP.cancelEditSafe(this, FaweCache.MAX_ENTITIES);
|
2018-08-12 14:03:07 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return super.createEntity(location, entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-28 20:31:22 +00:00
|
|
|
public BlockState getBlock(int x, int y, int z) {
|
2018-08-12 14:03:07 +00:00
|
|
|
if (!limit.MAX_CHECKS()) {
|
2020-01-29 20:01:38 +00:00
|
|
|
WEManager.IMP.cancelEditSafe(this, FaweCache.MAX_CHECKS);
|
2019-06-23 18:05:14 +00:00
|
|
|
return BlockTypes.AIR.getDefaultState();
|
2018-08-12 14:03:07 +00:00
|
|
|
} else {
|
2019-05-28 20:31:22 +00:00
|
|
|
return extent.getBlock(x, y, z);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-23 18:05:14 +00:00
|
|
|
|
2019-03-25 17:31:12 +00:00
|
|
|
@Override
|
|
|
|
public BaseBlock getFullBlock(BlockVector3 pos) {
|
|
|
|
if (!limit.MAX_CHECKS()) {
|
2020-01-29 20:01:38 +00:00
|
|
|
WEManager.IMP.cancelEditSafe(this, FaweCache.MAX_CHECKS);
|
2019-06-23 18:05:14 +00:00
|
|
|
return BlockTypes.AIR.getDefaultState().toBaseBlock();
|
2019-03-25 17:31:12 +00:00
|
|
|
} else {
|
|
|
|
return extent.getFullBlock(pos);
|
|
|
|
}
|
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
@Override
|
2020-04-30 20:26:52 +00:00
|
|
|
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block)
|
2021-07-24 15:34:05 +00:00
|
|
|
throws WorldEditException {
|
2018-08-12 14:03:07 +00:00
|
|
|
return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-28 20:31:22 +00:00
|
|
|
public BlockState getBlock(BlockVector3 location) {
|
|
|
|
return getBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-30 20:26:52 +00:00
|
|
|
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block)
|
2021-07-24 15:34:05 +00:00
|
|
|
throws WorldEditException {
|
2019-09-22 01:00:45 +00:00
|
|
|
boolean hasNbt = block instanceof BaseBlock && block.hasNbtData();
|
2019-03-25 17:31:12 +00:00
|
|
|
if (hasNbt) {
|
2018-08-12 14:03:07 +00:00
|
|
|
if (!limit.MAX_BLOCKSTATES()) {
|
2020-01-29 20:01:38 +00:00
|
|
|
WEManager.IMP.cancelEdit(this, FaweCache.MAX_TILES);
|
2018-08-12 14:03:07 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (!limit.MAX_CHANGES()) {
|
2020-01-29 20:01:38 +00:00
|
|
|
WEManager.IMP.cancelEdit(this, FaweCache.MAX_CHANGES);
|
2018-08-12 14:03:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return extent.setBlock(x, y, z, block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!limit.MAX_CHANGES()) {
|
2020-01-29 20:01:38 +00:00
|
|
|
WEManager.IMP.cancelEdit(this, FaweCache.MAX_CHANGES);
|
2018-08-12 14:03:07 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return extent.setBlock(x, y, z, block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-10-22 21:18:16 +00:00
|
|
|
public boolean setBiome(BlockVector3 position, BiomeType biome) {
|
2018-08-12 14:03:07 +00:00
|
|
|
if (!limit.MAX_CHANGES()) {
|
2020-01-29 20:01:38 +00:00
|
|
|
WEManager.IMP.cancelEditSafe(this, FaweCache.MAX_CHANGES);
|
2018-08-12 14:03:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return super.setBiome(position, biome);
|
|
|
|
}
|
2021-07-24 15:34:05 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|