#1182: Consolidate Preconditions use and minor cleanup
By: Doc <nachito94@msn.com>
This commit is contained in:
@@ -31,7 +31,6 @@ import net.minecraft.world.phys.MovingObjectPosition;
|
||||
import net.minecraft.world.phys.MovingObjectPositionBlock;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.FluidCollisionMode;
|
||||
@@ -392,10 +391,9 @@ public class CraftBlock implements Block {
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof CraftBlock)) {
|
||||
if (!(o instanceof CraftBlock other)) {
|
||||
return false;
|
||||
}
|
||||
CraftBlock other = (CraftBlock) o;
|
||||
|
||||
return this.position.equals(other.position) && this.getWorld().equals(other.getWorld());
|
||||
}
|
||||
@@ -593,15 +591,15 @@ public class CraftBlock implements Block {
|
||||
|
||||
@Override
|
||||
public RayTraceResult rayTrace(Location start, Vector direction, double maxDistance, FluidCollisionMode fluidCollisionMode) {
|
||||
Validate.notNull(start, "Start location is null!");
|
||||
Validate.isTrue(this.getWorld().equals(start.getWorld()), "Start location is from different world!");
|
||||
Preconditions.checkArgument(start != null, "Location start cannot be null");
|
||||
Preconditions.checkArgument(this.getWorld().equals(start.getWorld()), "Location start cannot be a different world");
|
||||
start.checkFinite();
|
||||
|
||||
Validate.notNull(direction, "Direction is null!");
|
||||
Preconditions.checkArgument(direction != null, "Vector direction cannot be null");
|
||||
direction.checkFinite();
|
||||
Validate.isTrue(direction.lengthSquared() > 0, "Direction's magnitude is 0!");
|
||||
Preconditions.checkArgument(direction.lengthSquared() > 0, "Direction's magnitude (%s) must be greater than 0", direction.lengthSquared());
|
||||
|
||||
Validate.notNull(fluidCollisionMode, "Fluid collision mode is null!");
|
||||
Preconditions.checkArgument(fluidCollisionMode != null, "FluidCollisionMode cannot be null");
|
||||
if (maxDistance < 0.0D) {
|
||||
return null;
|
||||
}
|
||||
@@ -634,7 +632,7 @@ public class CraftBlock implements Block {
|
||||
|
||||
@Override
|
||||
public boolean canPlace(BlockData data) {
|
||||
Preconditions.checkArgument(data != null, "Provided block data is null!");
|
||||
Preconditions.checkArgument(data != null, "BlockData cannot be null");
|
||||
net.minecraft.world.level.block.state.IBlockData iblockdata = ((CraftBlockData) data).getState();
|
||||
net.minecraft.world.level.World world = this.world.getMinecraftWorld();
|
||||
|
||||
|
||||
@@ -80,9 +80,7 @@ public class CraftBlockState implements BlockState {
|
||||
}
|
||||
|
||||
protected final void ensureNoWorldGeneration() {
|
||||
if (isWorldGeneration()) {
|
||||
throw new IllegalStateException("This operation is not supported during world generation!");
|
||||
}
|
||||
Preconditions.checkState(!isWorldGeneration(), "This operation is not supported during world generation!");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,12 +140,8 @@ public class CraftBlockState implements BlockState {
|
||||
if ((mat == null) || (mat.getData() == null)) {
|
||||
this.data = CraftMagicNumbers.getBlock(data);
|
||||
} else {
|
||||
if ((data.getClass() == mat.getData()) || (data.getClass() == MaterialData.class)) {
|
||||
this.data = CraftMagicNumbers.getBlock(data);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Provided data is not of type "
|
||||
+ mat.getData().getName() + ", found " + data.getClass().getName());
|
||||
}
|
||||
Preconditions.checkArgument((data.getClass() == mat.getData()) || (data.getClass() == MaterialData.class), "Provided data is not of type %s, found %s", mat.getData().getName(), data.getClass().getName());
|
||||
this.data = CraftMagicNumbers.getBlock(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,8 +316,6 @@ public class CraftBlockState implements BlockState {
|
||||
}
|
||||
|
||||
protected void requirePlaced() {
|
||||
if (!isPlaced()) {
|
||||
throw new IllegalStateException("The blockState must be placed to call this method");
|
||||
}
|
||||
Preconditions.checkState(isPlaced(), "The blockState must be placed to call this method");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.level.block.EnumBlockMirror;
|
||||
import net.minecraft.world.level.block.EnumBlockRotation;
|
||||
import net.minecraft.world.level.block.entity.TileEntityStructure;
|
||||
import net.minecraft.world.level.block.state.properties.BlockPropertyStructureMode;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Structure;
|
||||
import org.bukkit.block.structure.Mirror;
|
||||
@@ -32,7 +30,7 @@ public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructu
|
||||
|
||||
@Override
|
||||
public void setStructureName(String name) {
|
||||
Preconditions.checkArgument(name != null, "Structure Name cannot be null");
|
||||
Preconditions.checkArgument(name != null, "Structure name cannot be null");
|
||||
getSnapshot().setStructureName(name);
|
||||
}
|
||||
|
||||
@@ -43,7 +41,8 @@ public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructu
|
||||
|
||||
@Override
|
||||
public void setAuthor(String author) {
|
||||
Preconditions.checkArgument(author != null && !author.isEmpty(), "Author name cannot be null nor empty");
|
||||
Preconditions.checkArgument(author != null, "Author name cannot be null");
|
||||
Preconditions.checkArgument(!author.isBlank(), "Author name cannot be empty");
|
||||
getSnapshot().author = author;
|
||||
}
|
||||
|
||||
@@ -60,9 +59,9 @@ public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructu
|
||||
|
||||
@Override
|
||||
public void setRelativePosition(BlockVector vector) {
|
||||
Validate.isTrue(isBetween(vector.getBlockX(), -MAX_SIZE, MAX_SIZE), "Structure Size (X) must be between -" + MAX_SIZE + " and " + MAX_SIZE);
|
||||
Validate.isTrue(isBetween(vector.getBlockY(), -MAX_SIZE, MAX_SIZE), "Structure Size (Y) must be between -" + MAX_SIZE + " and " + MAX_SIZE);
|
||||
Validate.isTrue(isBetween(vector.getBlockZ(), -MAX_SIZE, MAX_SIZE), "Structure Size (Z) must be between -" + MAX_SIZE + " and " + MAX_SIZE);
|
||||
Preconditions.checkArgument(isBetween(vector.getBlockX(), -MAX_SIZE, MAX_SIZE), "Structure Size (X) must be between -%s and %s but got %s", MAX_SIZE, MAX_SIZE, vector.getBlockX());
|
||||
Preconditions.checkArgument(isBetween(vector.getBlockY(), -MAX_SIZE, MAX_SIZE), "Structure Size (Y) must be between -%s and %s but got %s", MAX_SIZE, MAX_SIZE, vector.getBlockY());
|
||||
Preconditions.checkArgument(isBetween(vector.getBlockZ(), -MAX_SIZE, MAX_SIZE), "Structure Size (Z) must be between -%s and %s but got %s", MAX_SIZE, MAX_SIZE, vector.getBlockZ());
|
||||
getSnapshot().structurePos = CraftBlockVector.toBlockPosition(vector);
|
||||
}
|
||||
|
||||
@@ -73,14 +72,15 @@ public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructu
|
||||
|
||||
@Override
|
||||
public void setStructureSize(BlockVector vector) {
|
||||
Validate.isTrue(isBetween(vector.getBlockX(), 0, MAX_SIZE), "Structure Size (X) must be between 0 and " + MAX_SIZE);
|
||||
Validate.isTrue(isBetween(vector.getBlockY(), 0, MAX_SIZE), "Structure Size (Y) must be between 0 and " + MAX_SIZE);
|
||||
Validate.isTrue(isBetween(vector.getBlockZ(), 0, MAX_SIZE), "Structure Size (Z) must be between 0 and " + MAX_SIZE);
|
||||
Preconditions.checkArgument(isBetween(vector.getBlockX(), 0, MAX_SIZE), "Structure Size (X) must be between %s and %s but got %s", 0, MAX_SIZE, vector.getBlockX());
|
||||
Preconditions.checkArgument(isBetween(vector.getBlockY(), 0, MAX_SIZE), "Structure Size (Y) must be between %s and %s but got %s", 0, MAX_SIZE, vector.getBlockY());
|
||||
Preconditions.checkArgument(isBetween(vector.getBlockZ(), 0, MAX_SIZE), "Structure Size (Z) must be between %s and %s but got %s", 0, MAX_SIZE, vector.getBlockZ());
|
||||
getSnapshot().structureSize = CraftBlockVector.toBlockPosition(vector);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMirror(Mirror mirror) {
|
||||
Preconditions.checkArgument(mirror != null, "Mirror cannot be null");
|
||||
getSnapshot().mirror = EnumBlockMirror.valueOf(mirror.name());
|
||||
}
|
||||
|
||||
@@ -91,6 +91,7 @@ public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructu
|
||||
|
||||
@Override
|
||||
public void setRotation(StructureRotation rotation) {
|
||||
Preconditions.checkArgument(rotation != null, "StructureRotation cannot be null");
|
||||
getSnapshot().rotation = EnumBlockRotation.valueOf(rotation.name());
|
||||
}
|
||||
|
||||
@@ -101,6 +102,7 @@ public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructu
|
||||
|
||||
@Override
|
||||
public void setUsageMode(UsageMode mode) {
|
||||
Preconditions.checkArgument(mode != null, "UsageMode cannot be null");
|
||||
getSnapshot().mode = BlockPropertyStructureMode.valueOf(mode.name());
|
||||
}
|
||||
|
||||
@@ -141,7 +143,7 @@ public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructu
|
||||
|
||||
@Override
|
||||
public void setIntegrity(float integrity) {
|
||||
Validate.isTrue(isBetween(integrity, 0.0f, 1.0f), "Integrity must be between 0.0f and 1.0f");
|
||||
Preconditions.checkArgument(isBetween(integrity, 0.0f, 1.0f), "Integrity must be between 0.0f and 1.0f but got %s", integrity);
|
||||
getSnapshot().integrity = integrity;
|
||||
}
|
||||
|
||||
@@ -162,7 +164,7 @@ public class CraftStructureBlock extends CraftBlockEntityState<TileEntityStructu
|
||||
|
||||
@Override
|
||||
public void setMetadata(String metadata) {
|
||||
Validate.notNull(metadata, "Structure metadata cannot be null");
|
||||
Preconditions.checkArgument(metadata != null, "Structure metadata cannot be null");
|
||||
if (getUsageMode() == UsageMode.DATA) {
|
||||
getSnapshot().metaData = metadata;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user