Code quality improvements.

This commit is contained in:
TomyLobo 2013-10-19 11:31:31 +02:00
parent 886b2ab720
commit 661484f858
15 changed files with 27 additions and 31 deletions

View File

@ -264,7 +264,7 @@ public class EditSession {
}
// }
current.put(pt.toBlockVector(), block);
current.put(blockPt, block);
return smartSetBlock(pt, block);
}

View File

@ -266,17 +266,17 @@ public abstract class LocalPlayer {
/**
* Just go up.
*
* @param distance
* @param distance How far up to teleport
* @return whether the player was moved
*/
public boolean ascendUpwards(int distance) {
Vector pos = getBlockIn();
int x = pos.getBlockX();
int initialY = Math.max(0, pos.getBlockY());
final Vector pos = getBlockIn();
final int x = pos.getBlockX();
final int initialY = Math.max(0, pos.getBlockY());
int y = Math.max(0, pos.getBlockY() + 1);
int z = pos.getBlockZ();
int maxY = Math.min(getWorld().getMaxY() + 1, initialY + distance);
LocalWorld world = getPosition().getWorld();
final int z = pos.getBlockZ();
final int maxY = Math.min(getWorld().getMaxY() + 1, initialY + distance);
final LocalWorld world = getPosition().getWorld();
while (y <= world.getMaxY() + 2) {
if (!BlockType.canPassThrough(world.getBlock(new Vector(x, y, z)))) {

View File

@ -108,7 +108,7 @@ public class RegionCommands {
to = we.getBlockPattern(player, args.getString(1));
}
int affected = 0;
final int affected;
if (to instanceof SingleBlockPattern) {
affected = editSession.replaceBlocks(session.getSelection(player.getWorld()), from,
((SingleBlockPattern) to).getBlock());

View File

@ -11,8 +11,7 @@ import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
public class BiomeTypeMask implements Mask {
private Set<BiomeType> biomes;
private final Set<BiomeType> biomes;
public BiomeTypeMask() {
this(new HashSet<BiomeType>());
@ -30,8 +29,8 @@ public class BiomeTypeMask implements Mask {
return biomes.contains(biome);
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
return matches2D(editSession, pos.toVector2D());
}
}

View File

@ -11,8 +11,7 @@ import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
public class BlockMask implements Mask {
protected Set<BaseBlock> blocks;
private final Set<BaseBlock> blocks;
public BlockMask() {
blocks = new HashSet<BaseBlock>();
@ -38,6 +37,7 @@ public class BlockMask implements Mask {
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
BaseBlock block = editSession.getBlock(pos);
return blocks.contains(block)

View File

@ -30,7 +30,6 @@ import com.sk89q.worldedit.blocks.BaseBlock;
*/
@Deprecated
public class BlockTypeMask extends BlockMask {
public BlockTypeMask() {
super();
}

View File

@ -27,8 +27,7 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
public class CombinedMask implements Mask {
private List<Mask> masks = new ArrayList<Mask>();
private final List<Mask> masks = new ArrayList<Mask>();
public CombinedMask() {
}
@ -53,12 +52,14 @@ public class CombinedMask implements Mask {
return masks.contains(mask);
}
@Override
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
for (Mask mask : masks) {
mask.prepare(session, player, target);
}
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
for (Mask mask : masks) {
if (!mask.matches(editSession, pos)) {

View File

@ -8,9 +8,9 @@ import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.Region;
public class DynamicRegionMask implements Mask {
private Region region;
@Override
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
try {
region = session.getSelection(player.getWorld());

View File

@ -26,10 +26,10 @@ import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID;
public class ExistingBlockMask implements Mask {
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
return editSession.getBlockType(pos) != BlockID.AIR;
}

View File

@ -51,5 +51,4 @@ public class InvertedBlockTypeMask extends BlockTypeMask {
public boolean matches(EditSession editSession, Vector pos) {
return !super.matches(editSession, pos);
}
}

View File

@ -6,8 +6,7 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
public class InvertedMask implements Mask {
private Mask mask;
private final Mask mask;
public InvertedMask(Mask mask) {
this.mask = mask;

View File

@ -39,7 +39,7 @@ public interface Mask {
* @param player
* @param target target of the brush, null if not a brush mask
*/
public void prepare(LocalSession session, LocalPlayer player, Vector target);
void prepare(LocalSession session, LocalPlayer player, Vector target);
/**
* Given a block position, this method returns true if the block at
@ -51,5 +51,5 @@ public interface Mask {
* @param pos
* @return
*/
public boolean matches(EditSession editSession, Vector pos);
boolean matches(EditSession editSession, Vector pos);
}

View File

@ -6,7 +6,6 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
public class RandomMask implements Mask {
private final double ratio;
public RandomMask(double ratio) {

View File

@ -26,8 +26,7 @@ import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.Region;
public class RegionMask implements Mask {
private Region region;
private final Region region;
public RegionMask(Region region) {
this.region = region.clone();
@ -36,8 +35,8 @@ public class RegionMask implements Mask {
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
return region.contains(pos);
}
}

View File

@ -31,9 +31,8 @@ import com.sk89q.worldedit.Vector;
* @author 1337
*/
public class UnderOverlayMask implements Mask {
private int yMod;
private Mask mask;
private final int yMod;
private Mask mask; // TODO: Make this final and remove the deprecated classes
@Deprecated
public UnderOverlayMask(Set<Integer> ids, boolean overlay) {
@ -57,10 +56,12 @@ public class UnderOverlayMask implements Mask {
}
}
@Override
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
mask.prepare(session, player, target);
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
return mask.matches(editSession, pos.add(0, yMod, 0));
}