From ae8becafdda6660abdd4b02d863615a7c7c7305d Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 4 Apr 2014 16:09:05 -0700 Subject: [PATCH] Code cleanup. --- src/main/java/com/sk89q/util/StringUtil.java | 6 +++--- .../java/com/sk89q/worldedit/LocalSession.java | 4 ++-- .../java/com/sk89q/worldedit/WorldEdit.java | 2 +- .../internal/expression/runtime/Operators.java | 6 +++--- .../internal/expression/runtime/Switch.java | 2 +- .../internal/util/DocumentationPrinter.java | 18 ++++++++++++------ .../worldedit/math/convolution/HeightMap.java | 16 ++++++++-------- .../sk89q/worldedit/util/TreeGenerator.java | 4 ++-- .../sk89q/worldedit/world/chunk/OldChunk.java | 6 +++--- .../worldedit/world/snapshot/Snapshot.java | 4 ++-- 10 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/sk89q/util/StringUtil.java b/src/main/java/com/sk89q/util/StringUtil.java index ad26ae2c5..9158ffa2d 100644 --- a/src/main/java/com/sk89q/util/StringUtil.java +++ b/src/main/java/com/sk89q/util/StringUtil.java @@ -246,7 +246,7 @@ public final class StringUtil { int i; // iterates through s int j; // iterates through t - char t_j; // jth character of t + char tj; // jth character of t int cost; // cost @@ -255,11 +255,11 @@ public final class StringUtil { } for (j = 1; j <= m; ++j) { - t_j = t.charAt(j - 1); + tj = t.charAt(j - 1); d[0] = j; for (i = 1; i <= n; ++i) { - cost = s.charAt(i - 1) == t_j ? 0 : 1; + cost = s.charAt(i - 1) == tj ? 0 : 1; // minimum of cell to the left+1, to the top+1, diagonally left // and up +cost d[i] = Math.min(Math.min(d[i - 1] + 1, p[i] + 1), p[i - 1] diff --git a/src/main/java/com/sk89q/worldedit/LocalSession.java b/src/main/java/com/sk89q/worldedit/LocalSession.java index e20dbb2e2..61309df5f 100644 --- a/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -650,8 +650,8 @@ public class LocalSession { * * @param CUIVersion */ - public void setCUIVersion(int CUIVersion) { - this.cuiVersion = CUIVersion; + public void setCUIVersion(int cuiVersion) { + this.cuiVersion = cuiVersion; } /** diff --git a/src/main/java/com/sk89q/worldedit/WorldEdit.java b/src/main/java/com/sk89q/worldedit/WorldEdit.java index e8b0abf52..f3fbc5dfc 100644 --- a/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -818,7 +818,7 @@ public class WorldEdit { return false; } - if (!player.hasPermission("worldedit.navigation.jumpto.tool") ){ + if (!player.hasPermission("worldedit.navigation.jumpto.tool")) { return false; } diff --git a/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Operators.java b/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Operators.java index a8122cab0..8f69e8d00 100644 --- a/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Operators.java +++ b/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Operators.java @@ -209,16 +209,16 @@ public final class Operators { } // Usable AlmostEqual function, based on http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm - private static boolean almostEqual2sComplement(double A, double B, long maxUlps) { + private static boolean almostEqual2sComplement(double a, double b, long maxUlps) { // Make sure maxUlps is non-negative and small enough that the // default NAN won't compare as equal to anything. //assert(maxUlps > 0 && maxUlps < 4 * 1024 * 1024); // this is for floats, not doubles - long aLong = Double.doubleToRawLongBits(A); + long aLong = Double.doubleToRawLongBits(a); // Make aLong lexicographically ordered as a twos-complement long if (aLong < 0) aLong = 0x8000000000000000L - aLong; - long bLong = Double.doubleToRawLongBits(B); + long bLong = Double.doubleToRawLongBits(b); // Make bLong lexicographically ordered as a twos-complement long if (bLong < 0) bLong = 0x8000000000000000L - bLong; diff --git a/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Switch.java b/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Switch.java index b064ab78b..f56c053f8 100644 --- a/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Switch.java +++ b/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Switch.java @@ -136,7 +136,7 @@ public class Switch extends Node implements RValue { } boolean breakDetected = false; - for (int i = index; i < caseStatements.length && !breakDetected ; ++i) { + for (int i = index; i < caseStatements.length && !breakDetected; ++i) { final RValue invokable = caseStatements[i].optimize(); if (invokable instanceof Sequence) { diff --git a/src/main/java/com/sk89q/worldedit/internal/util/DocumentationPrinter.java b/src/main/java/com/sk89q/worldedit/internal/util/DocumentationPrinter.java index 4ce0886a5..26ba92d87 100644 --- a/src/main/java/com/sk89q/worldedit/internal/util/DocumentationPrinter.java +++ b/src/main/java/com/sk89q/worldedit/internal/util/DocumentationPrinter.java @@ -37,6 +37,12 @@ public final class DocumentationPrinter { private DocumentationPrinter() { } + /** + * Generates documentation. + * + * @param args arguments + * @throws IOException thrown on I/O error + */ public static void main(String[] args) throws IOException { File commandsDir = new File(args[0]); @@ -96,7 +102,7 @@ public final class DocumentationPrinter { try { stream = new FileOutputStream("wiki_permissions.txt"); PrintStream print = new PrintStream(stream); - _writePermissionsWikiTable(print, commandClasses, "/"); + writePermissionsWikiTable(print, commandClasses, "/"); } finally { if (stream != null) { stream.close(); @@ -104,8 +110,8 @@ public final class DocumentationPrinter { } } - private static void _writePermissionsWikiTable(PrintStream stream, - List> commandClasses, String prefix) { + private static void writePermissionsWikiTable(PrintStream stream, + List> commandClasses, String prefix) { for (Class cls : commandClasses) { for (Method method : cls.getMethods()) { @@ -162,7 +168,7 @@ public final class DocumentationPrinter { method.getAnnotation(NestedCommand.class); Class[] nestedClasses = nested.value(); - _writePermissionsWikiTable(stream, + writePermissionsWikiTable(stream, Arrays.asList(nestedClasses), prefix + cmd.aliases()[0] + " "); } @@ -176,7 +182,7 @@ public final class DocumentationPrinter { try { stream = new FileOutputStream("plugin.yml"); PrintStream print = new PrintStream(stream); - _writeBukkitYAML(print); + writeBukkitYAML(print); } finally { if (stream != null) { stream.close(); @@ -184,7 +190,7 @@ public final class DocumentationPrinter { } } - private static void _writeBukkitYAML(PrintStream stream) { + private static void writeBukkitYAML(PrintStream stream) { stream.println("name: WorldEdit"); stream.println("main: com.sk89q.worldedit.bukkit.WorldEditPlugin"); diff --git a/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java b/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java index 895e7766b..3d3768c85 100644 --- a/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java +++ b/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java @@ -128,8 +128,8 @@ public class HeightMap { int newHeight = Math.min(maxY, data[index]); // Offset x,z to be 'real' coordinates - int X = x + originX; - int Z = z + originZ; + int xr = x + originX; + int zr = z + originZ; // We are keeping the topmost blocks so take that in account for the scale double scale = (double) (curHeight - originY) / (double) (newHeight - originY); @@ -137,18 +137,18 @@ public class HeightMap { // Depending on growing or shrinking we need to start at the bottom or top if (newHeight > curHeight) { // Set the top block of the column to be the same type (this might go wrong with rounding) - BaseBlock existing = session.getBlock(new Vector(X, curHeight, Z)); + BaseBlock existing = session.getBlock(new Vector(xr, curHeight, zr)); // Skip water/lava if (existing.getType() != BlockID.WATER && existing.getType() != BlockID.STATIONARY_WATER && existing.getType() != BlockID.LAVA && existing.getType() != BlockID.STATIONARY_LAVA) { - session.setBlock(new Vector(X, newHeight, Z), existing); + session.setBlock(new Vector(xr, newHeight, zr), existing); ++blocksChanged; // Grow -- start from 1 below top replacing airblocks for (int y = newHeight - 1 - originY; y >= 0; --y) { int copyFrom = (int) (y * scale); - session.setBlock(new Vector(X, originY + y, Z), session.getBlock(new Vector(X, originY + copyFrom, Z))); + session.setBlock(new Vector(xr, originY + y, zr), session.getBlock(new Vector(xr, originY + copyFrom, zr))); ++blocksChanged; } } @@ -156,18 +156,18 @@ public class HeightMap { // Shrink -- start from bottom for (int y = 0; y < newHeight - originY; ++y) { int copyFrom = (int) (y * scale); - session.setBlock(new Vector(X, originY + y, Z), session.getBlock(new Vector(X, originY + copyFrom, Z))); + session.setBlock(new Vector(xr, originY + y, zr), session.getBlock(new Vector(xr, originY + copyFrom, zr))); ++blocksChanged; } // Set the top block of the column to be the same type // (this could otherwise go wrong with rounding) - session.setBlock(new Vector(X, newHeight, Z), session.getBlock(new Vector(X, curHeight, Z))); + session.setBlock(new Vector(xr, newHeight, zr), session.getBlock(new Vector(xr, curHeight, zr))); ++blocksChanged; // Fill rest with air for (int y = newHeight + 1; y <= curHeight; ++y) { - session.setBlock(new Vector(X, y, Z), fillerAir); + session.setBlock(new Vector(xr, y, zr), fillerAir); ++blocksChanged; } } diff --git a/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java b/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java index e0ba6ca57..c28400d76 100644 --- a/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java +++ b/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java @@ -47,7 +47,7 @@ public class TreeGenerator { return true; } }, - RANDOM_REDWOOD("Random redwood", "randredwood", "randomredwood", "anyredwood" ) { + RANDOM_REDWOOD("Random redwood", "randredwood", "randomredwood", "anyredwood") { public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException { TreeType[] choices = new TreeType[] { TreeType.REDWOOD, TreeType.TALL_REDWOOD @@ -70,7 +70,7 @@ public class TreeGenerator { DARK_OAK("Dark Oak", "darkoak"), MEGA_REDWOOD("Mega Redwood", "megaredwood"), TALL_BIRCH("Tall Birch", "tallbirch"), - RANDOM("Random", "rand", "random" ) { + RANDOM("Random", "rand", "random") { public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException { TreeType[] choices = new TreeType[] { TreeType.TREE, TreeType.BIG_TREE, TreeType.BIRCH, diff --git a/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java b/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java index 164e80fd1..30c5c12d6 100644 --- a/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java +++ b/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java @@ -60,9 +60,9 @@ public class OldChunk implements Chunk { blocks = NBTUtils.getChildTag(rootTag.getValue(), "Blocks", ByteArrayTag.class).getValue(); - data = NBTUtils.getChildTag( rootTag.getValue(), "Data", ByteArrayTag.class).getValue(); - rootX = NBTUtils.getChildTag( rootTag.getValue(), "xPos", IntTag.class).getValue(); - rootZ = NBTUtils.getChildTag( rootTag.getValue(), "zPos", IntTag.class).getValue(); + data = NBTUtils.getChildTag(rootTag.getValue(), "Data", ByteArrayTag.class).getValue(); + rootX = NBTUtils.getChildTag(rootTag.getValue(), "xPos", IntTag.class).getValue(); + rootZ = NBTUtils.getChildTag(rootTag.getValue(), "zPos", IntTag.class).getValue(); int size = 16 * 16 * 128; if (blocks.length != size) { diff --git a/src/main/java/com/sk89q/worldedit/world/snapshot/Snapshot.java b/src/main/java/com/sk89q/worldedit/world/snapshot/Snapshot.java index 1eeb5d1f7..9793521fa 100644 --- a/src/main/java/com/sk89q/worldedit/world/snapshot/Snapshot.java +++ b/src/main/java/com/sk89q/worldedit/world/snapshot/Snapshot.java @@ -68,7 +68,7 @@ public class Snapshot implements Comparable { * @throws DataException */ public ChunkStore getChunkStore() throws IOException, DataException { - ChunkStore chunkStore = _getChunkStore(); + ChunkStore chunkStore = internalGetChunkStore(); logger.info("WorldEdit: Using " + chunkStore.getClass().getCanonicalName() + " for loading snapshot '" + file.getAbsolutePath() + "'"); @@ -83,7 +83,7 @@ public class Snapshot implements Comparable { * @throws IOException * @throws DataException */ - public ChunkStore _getChunkStore() throws IOException, DataException { + private ChunkStore internalGetChunkStore() throws IOException, DataException { if (file.getName().toLowerCase().endsWith(".zip")) { try { ChunkStore chunkStore = new TrueZipMcRegionChunkStore(file);