mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 20:16:41 +00:00
Remove all raw usages of BSH, improve API generics
This commit is contained in:
@ -76,7 +76,7 @@ public abstract class AbstractDelegateExtent implements Extent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 location, T block) throws WorldEditException {
|
||||
return extent.setBlock(location, block);
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class ChangeSetExtent extends AbstractDelegateExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
BaseBlock previous = getFullBlock(location);
|
||||
changeSet.add(new BlockChange(location, previous, block));
|
||||
return super.setBlock(location, block);
|
||||
|
@ -65,7 +65,7 @@ public class MaskingExtent extends AbstractDelegateExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
return mask.test(location) && super.setBlock(location, block);
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class NullExtent implements Extent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ public interface OutputExtent {
|
||||
* @return true if the block was successfully set (return value may not be accurate)
|
||||
* @throws WorldEditException thrown on an error
|
||||
*/
|
||||
boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException;
|
||||
<T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException;
|
||||
|
||||
/**
|
||||
* Set the biome.
|
||||
|
@ -31,6 +31,7 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.AbstractRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionOperationException;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
@ -47,7 +48,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pattern {
|
||||
|
||||
private final Map<BlockVector3, BlockStateHolder> buffer = new LinkedHashMap<>();
|
||||
private final Map<BlockVector3, BaseBlock> buffer = new LinkedHashMap<>();
|
||||
private final Mask mask;
|
||||
private BlockVector3 min = null;
|
||||
private BlockVector3 max = null;
|
||||
@ -76,7 +77,7 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
// Update minimum
|
||||
if (min == null) {
|
||||
min = location;
|
||||
@ -93,7 +94,7 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
|
||||
|
||||
BlockVector3 blockVector = location;
|
||||
if (mask.test(blockVector)) {
|
||||
buffer.put(blockVector, block);
|
||||
buffer.put(blockVector, block.toBaseBlock());
|
||||
return true;
|
||||
} else {
|
||||
return getExtent().setBlock(location, block);
|
||||
@ -101,12 +102,12 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder apply(BlockVector3 pos) {
|
||||
BlockStateHolder block = buffer.get(pos);
|
||||
public BaseBlock apply(BlockVector3 pos) {
|
||||
BaseBlock block = buffer.get(pos);
|
||||
if (block != null) {
|
||||
return block;
|
||||
} else {
|
||||
return BlockTypes.AIR.getDefaultState();
|
||||
return BlockTypes.AIR.getDefaultState().toBaseBlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class BlockArrayClipboard implements Clipboard {
|
||||
|
||||
private final Region region;
|
||||
private BlockVector3 origin;
|
||||
private final BlockStateHolder[][][] blocks;
|
||||
private final BaseBlock[][][] blocks;
|
||||
private final List<ClipboardEntity> entities = new ArrayList<>();
|
||||
|
||||
/**
|
||||
@ -65,7 +65,7 @@ public class BlockArrayClipboard implements Clipboard {
|
||||
this.origin = region.getMinimumPoint();
|
||||
|
||||
BlockVector3 dimensions = getDimensions();
|
||||
blocks = new BlockStateHolder[dimensions.getBlockX()][dimensions.getBlockY()][dimensions.getBlockZ()];
|
||||
blocks = new BaseBlock[dimensions.getBlockX()][dimensions.getBlockY()][dimensions.getBlockZ()];
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -126,7 +126,7 @@ public class BlockArrayClipboard implements Clipboard {
|
||||
public BlockState getBlock(BlockVector3 position) {
|
||||
if (region.contains(position)) {
|
||||
BlockVector3 v = position.subtract(region.getMinimumPoint());
|
||||
BlockStateHolder block = blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()];
|
||||
BaseBlock block = blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()];
|
||||
if (block != null) {
|
||||
return block.toImmutableState();
|
||||
}
|
||||
@ -139,9 +139,9 @@ public class BlockArrayClipboard implements Clipboard {
|
||||
public BaseBlock getFullBlock(BlockVector3 position) {
|
||||
if (region.contains(position)) {
|
||||
BlockVector3 v = position.subtract(region.getMinimumPoint());
|
||||
BlockStateHolder block = blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()];
|
||||
BaseBlock block = blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()];
|
||||
if (block != null) {
|
||||
return block.toBaseBlock();
|
||||
return block;
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,10 +149,10 @@ public class BlockArrayClipboard implements Clipboard {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
|
||||
if (region.contains(position)) {
|
||||
BlockVector3 v = position.subtract(region.getMinimumPoint());
|
||||
blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()] = block;
|
||||
blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()] = block.toBaseBlock();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -25,6 +25,6 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import java.util.Map;
|
||||
|
||||
public interface NBTCompatibilityHandler {
|
||||
boolean isAffectedBlock(BlockStateHolder block);
|
||||
void updateNBT(BlockStateHolder block, Map<String, Tag> values);
|
||||
<B extends BlockStateHolder<B>> boolean isAffectedBlock(B block);
|
||||
<B extends BlockStateHolder<B>> void updateNBT(B block, Map<String, Tag> values);
|
||||
}
|
||||
|
@ -32,13 +32,14 @@ import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import java.util.Map;
|
||||
|
||||
public class SignCompatibilityHandler implements NBTCompatibilityHandler {
|
||||
|
||||
@Override
|
||||
public boolean isAffectedBlock(BlockStateHolder block) {
|
||||
public <B extends BlockStateHolder<B>> boolean isAffectedBlock(B block) {
|
||||
return block.getBlockType() == BlockTypes.SIGN || block.getBlockType() == BlockTypes.WALL_SIGN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNBT(BlockStateHolder block, Map<String, Tag> values) {
|
||||
public <B extends BlockStateHolder<B>> void updateNBT(B block, Map<String, Tag> values) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
String key = "Text" + (i + 1);
|
||||
Tag value = values.get(key);
|
||||
|
@ -82,7 +82,7 @@ public class BlockBagExtent extends AbstractDelegateExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
|
||||
if (blockBag != null) {
|
||||
BlockState existing = getExtent().getBlock(position);
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class ChunkBatchingExtent extends AbstractDelegateExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
if (!enabled) {
|
||||
return getExtent().setBlock(location, block);
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import com.sk89q.worldedit.function.operation.OperationQueue;
|
||||
import com.sk89q.worldedit.function.operation.SetLocatedBlocks;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.collection.LocatedBlockList;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockCategories;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
@ -201,12 +202,12 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
||||
* @param block The block
|
||||
* @return The priority
|
||||
*/
|
||||
private PlacementPriority getPlacementPriority(BlockStateHolder block) {
|
||||
private <B extends BlockStateHolder<B>> PlacementPriority getPlacementPriority(B block) {
|
||||
return priorityMap.getOrDefault(block.getBlockType(), PlacementPriority.FIRST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
if (!enabled) {
|
||||
return super.setBlock(location, block);
|
||||
}
|
||||
@ -216,7 +217,7 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
||||
PlacementPriority srcPriority = getPlacementPriority(existing);
|
||||
|
||||
if (srcPriority != PlacementPriority.FIRST) {
|
||||
BlockStateHolder replacement = block.getBlockType().getMaterial().isAir() ? block : BlockTypes.AIR.getDefaultState();
|
||||
BaseBlock replacement = (block.getBlockType().getMaterial().isAir() ? block : BlockTypes.AIR.getDefaultState()).toBaseBlock();
|
||||
|
||||
switch (srcPriority) {
|
||||
case FINAL:
|
||||
|
@ -79,7 +79,7 @@ public class BlockTransformExtent extends AbstractDelegateExtent {
|
||||
* @param reverse true to transform in the opposite direction
|
||||
* @return the same block
|
||||
*/
|
||||
private <T extends BlockStateHolder> T transformBlock(T block, boolean reverse) {
|
||||
private <T extends BlockStateHolder<T>> T transformBlock(T block, boolean reverse) {
|
||||
return transform(block, reverse ? transform.inverse() : transform);
|
||||
}
|
||||
|
||||
@ -94,50 +94,40 @@ public class BlockTransformExtent extends AbstractDelegateExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
return super.setBlock(location, transformBlock(block, true));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Transform the given block using the given transform.
|
||||
*
|
||||
* <p>The provided block is modified.</p>
|
||||
*
|
||||
* @param block the block
|
||||
* @param transform the transform
|
||||
* @return the same block
|
||||
*/
|
||||
public static <T extends BlockStateHolder> T transform(T block, Transform transform) {
|
||||
return transform(block, transform, block);
|
||||
}
|
||||
|
||||
private static final Set<String> directionNames = Sets.newHashSet("north", "south", "east", "west");
|
||||
|
||||
/**
|
||||
* Transform the given block using the given transform.
|
||||
*
|
||||
* <p>The provided block is <em>not</em> modified.</p>
|
||||
*
|
||||
* @param block the block
|
||||
* @param transform the transform
|
||||
* @param changedBlock the block to change
|
||||
* @return the changed block
|
||||
* @return the same block
|
||||
*/
|
||||
private static <T extends BlockStateHolder> T transform(T block, Transform transform, T changedBlock) {
|
||||
public static <B extends BlockStateHolder<B>> B transform(B block, Transform transform) {
|
||||
checkNotNull(block);
|
||||
checkNotNull(transform);
|
||||
|
||||
List<? extends Property> properties = block.getBlockType().getProperties();
|
||||
B result = block;
|
||||
List<? extends Property<?>> properties = block.getBlockType().getProperties();
|
||||
|
||||
for (Property<?> property : properties) {
|
||||
if (property instanceof DirectionalProperty) {
|
||||
DirectionalProperty dirProp = (DirectionalProperty) property;
|
||||
Direction value = (Direction) block.getState(property);
|
||||
if (value != null) {
|
||||
Vector3 newValue = getNewStateValue((List<Direction>) property.getValues(), transform, value.toVector());
|
||||
Vector3 newValue = getNewStateValue(dirProp.getValues(), transform, value.toVector());
|
||||
if (newValue != null) {
|
||||
changedBlock = (T) changedBlock.with(property, Direction.findClosest(newValue, Direction.Flag.ALL));
|
||||
result = result.with(dirProp, Direction.findClosest(newValue, Direction.Flag.ALL));
|
||||
}
|
||||
}
|
||||
} else if (property instanceof EnumProperty) {
|
||||
EnumProperty enumProp = (EnumProperty) property;
|
||||
if (property.getName().equals("axis")) {
|
||||
// We have an axis - this is something we can do the rotations to :sunglasses:
|
||||
Direction value = null;
|
||||
@ -165,7 +155,7 @@ public class BlockTransformExtent extends AbstractDelegateExtent {
|
||||
axis = "y";
|
||||
}
|
||||
if (axis != null) {
|
||||
changedBlock = (T) changedBlock.with(property, axis);
|
||||
result = result.with(enumProp, axis);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -188,11 +178,11 @@ public class BlockTransformExtent extends AbstractDelegateExtent {
|
||||
|
||||
if (directionalProperties.size() > 0) {
|
||||
for (String directionName : directionNames) {
|
||||
changedBlock = (T) changedBlock.with(block.getBlockType().getProperty(directionName), directionalProperties.contains(directionName));
|
||||
result = result.with(block.getBlockType().getProperty(directionName), directionalProperties.contains(directionName));
|
||||
}
|
||||
}
|
||||
|
||||
return changedBlock;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,7 +77,7 @@ public class BlockChangeLimiter extends AbstractDelegateExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
if (limit >= 0) {
|
||||
if (count >= limit) {
|
||||
throw new MaxChangedBlocksException(limit);
|
||||
|
@ -49,7 +49,7 @@ public class DataValidatorExtent extends AbstractDelegateExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
final int y = location.getBlockY();
|
||||
final BlockType type = block.getBlockType();
|
||||
if (y < 0 || y > world.getMaxY()) {
|
||||
|
@ -51,7 +51,7 @@ public class BlockQuirkExtent extends AbstractDelegateExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
|
||||
BlockType existing = getExtent().getBlock(position).getBlockType();
|
||||
|
||||
if (existing.getMaterial().hasContainer()) {
|
||||
|
@ -61,7 +61,7 @@ public class ChunkLoadingExtent extends AbstractDelegateExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
world.checkLoadedChunk(location);
|
||||
return super.setBlock(location, block);
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ public class FastModeExtent extends AbstractDelegateExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
if (enabled || postEditSimulation) {
|
||||
dirtyChunks.add(BlockVector2.at(location.getBlockX() >> 4, location.getBlockZ() >> 4));
|
||||
|
||||
|
@ -79,7 +79,7 @@ public class SurvivalModeExtent extends AbstractDelegateExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
if (toolUse && block.getBlockType().getMaterial().isAir()) {
|
||||
world.simulateBlockMine(location);
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user