From 661484f8587397da776135e34165abcf7b2dcc32 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sat, 19 Oct 2013 11:31:31 +0200 Subject: [PATCH] Code quality improvements. --- src/main/java/com/sk89q/worldedit/EditSession.java | 2 +- src/main/java/com/sk89q/worldedit/LocalPlayer.java | 14 +++++++------- .../sk89q/worldedit/commands/RegionCommands.java | 2 +- .../com/sk89q/worldedit/masks/BiomeTypeMask.java | 5 ++--- .../java/com/sk89q/worldedit/masks/BlockMask.java | 4 ++-- .../com/sk89q/worldedit/masks/BlockTypeMask.java | 1 - .../com/sk89q/worldedit/masks/CombinedMask.java | 5 +++-- .../sk89q/worldedit/masks/DynamicRegionMask.java | 2 +- .../sk89q/worldedit/masks/ExistingBlockMask.java | 2 +- .../worldedit/masks/InvertedBlockTypeMask.java | 1 - .../com/sk89q/worldedit/masks/InvertedMask.java | 3 +-- src/main/java/com/sk89q/worldedit/masks/Mask.java | 4 ++-- .../java/com/sk89q/worldedit/masks/RandomMask.java | 1 - .../java/com/sk89q/worldedit/masks/RegionMask.java | 5 ++--- .../sk89q/worldedit/masks/UnderOverlayMask.java | 7 ++++--- 15 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index 105e772ed..4e975d9ea 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -264,7 +264,7 @@ public class EditSession { } // } - current.put(pt.toBlockVector(), block); + current.put(blockPt, block); return smartSetBlock(pt, block); } diff --git a/src/main/java/com/sk89q/worldedit/LocalPlayer.java b/src/main/java/com/sk89q/worldedit/LocalPlayer.java index 672bf877f..43db697f5 100644 --- a/src/main/java/com/sk89q/worldedit/LocalPlayer.java +++ b/src/main/java/com/sk89q/worldedit/LocalPlayer.java @@ -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)))) { diff --git a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java index 7faeaff07..405901aa4 100644 --- a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java @@ -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()); diff --git a/src/main/java/com/sk89q/worldedit/masks/BiomeTypeMask.java b/src/main/java/com/sk89q/worldedit/masks/BiomeTypeMask.java index ea448cbcf..d86ac3334 100644 --- a/src/main/java/com/sk89q/worldedit/masks/BiomeTypeMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/BiomeTypeMask.java @@ -11,8 +11,7 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector2D; public class BiomeTypeMask implements Mask { - - private Set biomes; + private final Set biomes; public BiomeTypeMask() { this(new HashSet()); @@ -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()); } - } diff --git a/src/main/java/com/sk89q/worldedit/masks/BlockMask.java b/src/main/java/com/sk89q/worldedit/masks/BlockMask.java index 7172d3b10..95bca93c2 100644 --- a/src/main/java/com/sk89q/worldedit/masks/BlockMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/BlockMask.java @@ -11,8 +11,7 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; public class BlockMask implements Mask { - - protected Set blocks; + private final Set blocks; public BlockMask() { blocks = new HashSet(); @@ -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) diff --git a/src/main/java/com/sk89q/worldedit/masks/BlockTypeMask.java b/src/main/java/com/sk89q/worldedit/masks/BlockTypeMask.java index c1eab46f5..5a9dee9fc 100644 --- a/src/main/java/com/sk89q/worldedit/masks/BlockTypeMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/BlockTypeMask.java @@ -30,7 +30,6 @@ import com.sk89q.worldedit.blocks.BaseBlock; */ @Deprecated public class BlockTypeMask extends BlockMask { - public BlockTypeMask() { super(); } diff --git a/src/main/java/com/sk89q/worldedit/masks/CombinedMask.java b/src/main/java/com/sk89q/worldedit/masks/CombinedMask.java index 7ec96fdc6..148557830 100644 --- a/src/main/java/com/sk89q/worldedit/masks/CombinedMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/CombinedMask.java @@ -27,8 +27,7 @@ import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.Vector; public class CombinedMask implements Mask { - - private List masks = new ArrayList(); + private final List masks = new ArrayList(); 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)) { diff --git a/src/main/java/com/sk89q/worldedit/masks/DynamicRegionMask.java b/src/main/java/com/sk89q/worldedit/masks/DynamicRegionMask.java index c7cec61d3..bb4536df1 100644 --- a/src/main/java/com/sk89q/worldedit/masks/DynamicRegionMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/DynamicRegionMask.java @@ -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()); diff --git a/src/main/java/com/sk89q/worldedit/masks/ExistingBlockMask.java b/src/main/java/com/sk89q/worldedit/masks/ExistingBlockMask.java index cd5be8199..d32de39fa 100644 --- a/src/main/java/com/sk89q/worldedit/masks/ExistingBlockMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/ExistingBlockMask.java @@ -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; } diff --git a/src/main/java/com/sk89q/worldedit/masks/InvertedBlockTypeMask.java b/src/main/java/com/sk89q/worldedit/masks/InvertedBlockTypeMask.java index c4856ab09..9fef49649 100644 --- a/src/main/java/com/sk89q/worldedit/masks/InvertedBlockTypeMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/InvertedBlockTypeMask.java @@ -51,5 +51,4 @@ public class InvertedBlockTypeMask extends BlockTypeMask { public boolean matches(EditSession editSession, Vector pos) { return !super.matches(editSession, pos); } - } diff --git a/src/main/java/com/sk89q/worldedit/masks/InvertedMask.java b/src/main/java/com/sk89q/worldedit/masks/InvertedMask.java index d4c222551..e58db6ed3 100644 --- a/src/main/java/com/sk89q/worldedit/masks/InvertedMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/InvertedMask.java @@ -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; diff --git a/src/main/java/com/sk89q/worldedit/masks/Mask.java b/src/main/java/com/sk89q/worldedit/masks/Mask.java index 322ffdb72..277e61f94 100644 --- a/src/main/java/com/sk89q/worldedit/masks/Mask.java +++ b/src/main/java/com/sk89q/worldedit/masks/Mask.java @@ -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); } diff --git a/src/main/java/com/sk89q/worldedit/masks/RandomMask.java b/src/main/java/com/sk89q/worldedit/masks/RandomMask.java index 22fd8428a..3425c6035 100644 --- a/src/main/java/com/sk89q/worldedit/masks/RandomMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/RandomMask.java @@ -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) { diff --git a/src/main/java/com/sk89q/worldedit/masks/RegionMask.java b/src/main/java/com/sk89q/worldedit/masks/RegionMask.java index 18cad9683..f9260dc07 100644 --- a/src/main/java/com/sk89q/worldedit/masks/RegionMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/RegionMask.java @@ -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); } - } diff --git a/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java b/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java index 5c5dff6c9..c5a5add08 100644 --- a/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java @@ -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 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)); }