From 7e13b60a51cc1cfc50c6668a7016e0c5a4583c63 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Wed, 23 Nov 2011 02:29:48 +0100 Subject: [PATCH] Cleanup --- .../ConfigurationPermissionsResolver.java | 8 +- .../bukkit/migration/DinnerPermsResolver.java | 18 +- .../bukkit/migration/PermissionsProvider.java | 3 + .../migration/PermissionsResolverManager.java | 14 +- .../minecraft/util/commands/Command.java | 11 +- .../util/commands/CommandContext.java | 4 +- .../util/commands/CommandUsageException.java | 6 +- .../util/commands/CommandsManager.java | 119 ++++----- .../util/commands/SimpleInjector.java | 1 + .../commands/WrappedCommandException.java | 2 +- src/main/java/com/sk89q/util/StringUtil.java | 4 +- .../java/com/sk89q/util/yaml/YAMLFormat.java | 2 +- .../java/com/sk89q/util/yaml/YAMLNode.java | 161 ++++++------- .../com/sk89q/util/yaml/YAMLProcessor.java | 23 +- .../util/yaml/YAMLProcessorException.java | 4 +- .../com/sk89q/worldedit/ArbitraryShape.java | 10 +- .../java/com/sk89q/worldedit/BlockVector.java | 12 +- .../com/sk89q/worldedit/BlockVector2D.java | 8 +- .../com/sk89q/worldedit/BlockWorldVector.java | 16 +- .../sk89q/worldedit/BlockWorldVector2D.java | 2 +- .../com/sk89q/worldedit/CuboidClipboard.java | 79 +++--- .../com/sk89q/worldedit/DoubleArrayList.java | 26 +- .../java/com/sk89q/worldedit/EditSession.java | 47 ++-- .../java/com/sk89q/worldedit/EntityType.java | 2 +- .../FileSelectionAbortedException.java | 4 +- .../sk89q/worldedit/FilenameException.java | 8 +- .../FilenameResolutionException.java | 4 +- .../java/com/sk89q/worldedit/HeightMap.java | 3 +- .../worldedit/InvalidFilenameException.java | 4 +- .../worldedit/InvalidToolBindException.java | 4 +- .../sk89q/worldedit/LocalConfiguration.java | 5 +- .../java/com/sk89q/worldedit/LocalPlayer.java | 11 +- .../com/sk89q/worldedit/LocalSession.java | 5 +- .../java/com/sk89q/worldedit/LocalWorld.java | 27 ++- .../com/sk89q/worldedit/PlayerDirection.java | 12 +- .../com/sk89q/worldedit/SessionCheck.java | 4 +- src/main/java/com/sk89q/worldedit/Vector.java | 36 +-- .../java/com/sk89q/worldedit/Vector2D.java | 8 +- .../java/com/sk89q/worldedit/WorldEdit.java | 226 +++++++++--------- .../java/com/sk89q/worldedit/WorldVector.java | 10 +- .../com/sk89q/worldedit/WorldVector2D.java | 4 +- .../com/sk89q/worldedit/bags/BlockBag.java | 11 +- .../worldedit/bags/OutOfSpaceException.java | 2 +- .../bags/UnplaceableBlockException.java | 1 - .../com/sk89q/worldedit/blocks/BaseBlock.java | 3 +- .../sk89q/worldedit/blocks/BaseItemStack.java | 2 +- .../com/sk89q/worldedit/blocks/BlockData.java | 4 +- .../com/sk89q/worldedit/blocks/BlockType.java | 14 +- .../sk89q/worldedit/blocks/ChestBlock.java | 33 ++- .../sk89q/worldedit/blocks/ClothColor.java | 22 +- .../worldedit/blocks/DispenserBlock.java | 33 ++- .../sk89q/worldedit/blocks/FurnaceBlock.java | 40 ++-- .../com/sk89q/worldedit/blocks/ItemID.java | 2 +- .../com/sk89q/worldedit/blocks/ItemType.java | 26 +- .../worldedit/blocks/MobSpawnerBlock.java | 14 +- .../com/sk89q/worldedit/blocks/NoteBlock.java | 16 +- .../com/sk89q/worldedit/blocks/SignBlock.java | 22 +- .../worldedit/blocks/TileEntityBlock.java | 6 +- .../worldedit/bukkit/BukkitConfiguration.java | 21 +- .../sk89q/worldedit/bukkit/BukkitPlayer.java | 8 +- .../bukkit/BukkitPlayerBlockBag.java | 14 +- .../bukkit/BukkitServerInterface.java | 2 +- .../sk89q/worldedit/bukkit/BukkitUtil.java | 39 +-- .../sk89q/worldedit/bukkit/BukkitWorld.java | 184 +++++++------- .../EditSessionBlockChangeDelegate.java | 2 +- .../sk89q/worldedit/bukkit/SessionTimer.java | 4 +- .../sk89q/worldedit/bukkit/WorldEditAPI.java | 6 +- .../WorldEditCriticalPlayerListener.java | 2 +- .../bukkit/WorldEditPlayerListener.java | 10 +- .../worldedit/bukkit/WorldEditPlugin.java | 85 +++---- .../bukkit/selections/CuboidSelection.java | 16 +- .../selections/Polygonal2DSelection.java | 8 +- .../bukkit/selections/RegionSelection.java | 14 +- .../bukkit/selections/Selection.java | 20 +- .../worldedit/commands/BrushCommands.java | 16 +- .../worldedit/commands/ChunkCommands.java | 6 +- .../worldedit/commands/ClipboardCommands.java | 18 +- .../worldedit/commands/GeneralCommands.java | 26 +- .../commands/GenerationCommands.java | 16 +- .../worldedit/commands/HistoryCommands.java | 8 +- .../commands/NavigationCommands.java | 4 +- .../worldedit/commands/RegionCommands.java | 16 +- .../worldedit/commands/ScriptingCommands.java | 14 +- .../worldedit/commands/SelectionCommands.java | 81 ++++--- .../worldedit/commands/SnapshotCommands.java | 4 +- .../commands/SuperPickaxeCommands.java | 14 +- .../worldedit/commands/ToolCommands.java | 4 +- .../worldedit/commands/ToolUtilCommands.java | 4 +- .../worldedit/commands/UtilityCommands.java | 11 +- .../worldedit/commands/WorldEditCommands.java | 2 +- .../com/sk89q/worldedit/cui/CUIEvent.java | 1 + .../worldedit/cui/SelectionMinMaxEvent.java | 2 +- .../worldedit/cui/SelectionPointEvent.java | 2 +- .../worldedit/cui/SelectionShapeEvent.java | 4 +- .../java/com/sk89q/worldedit/data/Chunk.java | 41 ++-- .../com/sk89q/worldedit/data/ChunkStore.java | 4 +- .../data/FileMcRegionChunkStore.java | 2 +- .../data/ForwardSeekableInputStream.java | 12 +- .../worldedit/data/LegacyChunkStore.java | 8 +- .../worldedit/data/McRegionChunkStore.java | 15 +- .../sk89q/worldedit/data/McRegionReader.java | 16 +- .../data/TrueZipLegacyChunkStore.java | 5 +- .../data/TrueZipMcRegionChunkStore.java | 6 +- .../data/ZippedLegacyChunkStore.java | 5 +- .../data/ZippedMcRegionChunkStore.java | 10 +- .../worldedit/dev/DocumentationPrinter.java | 40 ++-- .../worldedit/expression/Expression.java | 3 +- .../worldedit/expression/lexer/Lexer.java | 88 +++---- .../worldedit/expression/parser/Parser.java | 8 +- .../expression/parser/ParserProcessors.java | 58 +++-- .../expression/parser/UnaryOperator.java | 2 +- .../expression/runtime/Conditional.java | 7 +- .../worldedit/expression/runtime/For.java | 5 +- .../expression/runtime/Functions.java | 6 +- .../worldedit/expression/runtime/RValue.java | 1 + .../worldedit/expression/runtime/Return.java | 2 +- .../worldedit/expression/runtime/While.java | 10 +- .../worldedit/filtering/GaussianKernel.java | 6 +- .../worldedit/filtering/HeightMapFilter.java | 16 +- .../worldedit/filtering/LinearKernel.java | 6 +- .../sk89q/worldedit/masks/BlockTypeMask.java | 10 +- .../com/sk89q/worldedit/masks/RegionMask.java | 4 +- .../worldedit/masks/UnderOverlayMask.java | 3 +- .../sk89q/worldedit/regions/CuboidRegion.java | 6 +- .../regions/CuboidRegionSelector.java | 24 +- .../worldedit/regions/Polygonal2DRegion.java | 56 ++--- .../regions/Polygonal2DRegionSelector.java | 12 +- .../com/sk89q/worldedit/regions/Region.java | 9 + .../regions/RegionOperationException.java | 2 +- .../worldedit/regions/RegionSelector.java | 26 +- .../scripting/CraftScriptContext.java | 26 +- .../scripting/CraftScriptEngine.java | 2 + .../scripting/CraftScriptEnvironment.java | 2 +- .../scripting/RhinoContextFactory.java | 14 +- .../scripting/RhinoCraftScriptEngine.java | 12 +- .../scripting/java/RhinoScriptEngine.java | 30 +-- .../java/RhinoScriptEngineFactory.java | 10 +- .../worldedit/snapshots/SnapshotRestore.java | 10 +- .../snapshots/YYMMDDHHIISSParser.java | 2 +- .../sk89q/worldedit/tools/AreaPickaxe.java | 16 +- .../sk89q/worldedit/tools/BlockReplacer.java | 16 +- .../com/sk89q/worldedit/tools/BrushTool.java | 24 +- .../worldedit/tools/FloatingTreeRemover.java | 16 +- .../sk89q/worldedit/tools/FloodFillTool.java | 12 +- .../com/sk89q/worldedit/tools/QueryTool.java | 10 +- .../worldedit/tools/RecursivePickaxe.java | 12 +- .../sk89q/worldedit/tools/SinglePickaxe.java | 10 +- .../java/com/sk89q/worldedit/tools/Tool.java | 4 +- .../sk89q/worldedit/tools/TreePlanter.java | 12 +- .../tools/brushes/ClipboardBrush.java | 4 +- .../tools/brushes/CylinderBrush.java | 4 +- .../tools/brushes/HollowCylinderBrush.java | 4 +- .../tools/brushes/HollowSphereBrush.java | 2 +- .../worldedit/tools/brushes/SmoothBrush.java | 4 +- .../worldedit/tools/brushes/SphereBrush.java | 2 +- .../sk89q/worldedit/util/FileDialogUtil.java | 18 +- .../com/sk89q/worldedit/util/TargetBlock.java | 18 +- .../sk89q/worldedit/util/TreeGenerator.java | 94 ++++---- .../util/commands/CommandContextTest.java | 2 +- .../sk89q/worldedit/blocks/BlockDataTest.java | 13 +- .../worldedit/expression/ExpressionTest.java | 10 +- 161 files changed, 1433 insertions(+), 1412 deletions(-) diff --git a/src/main/java/com/sk89q/bukkit/migration/ConfigurationPermissionsResolver.java b/src/main/java/com/sk89q/bukkit/migration/ConfigurationPermissionsResolver.java index 97ee535ba..068103de9 100644 --- a/src/main/java/com/sk89q/bukkit/migration/ConfigurationPermissionsResolver.java +++ b/src/main/java/com/sk89q/bukkit/migration/ConfigurationPermissionsResolver.java @@ -38,10 +38,10 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver { section.setProperty("permissions.groups.default.permissions", new String[] { "worldedit.reload", "worldedit.selection", - "worlds.creative.worldedit.region"}); - section.setProperty("permissions.groups.admins.permissions", new String[] {"*"}); - section.setProperty("permissions.users.sk89q.permissions", new String[] {"worldedit"}); - section.setProperty("permissions.users.sk89q.groups", new String[] {"admins"}); + "worlds.creative.worldedit.region" }); + section.setProperty("permissions.groups.admins.permissions", new String[] { "*" }); + section.setProperty("permissions.users.sk89q.permissions", new String[] { "worldedit" }); + section.setProperty("permissions.users.sk89q.groups", new String[] { "admins" }); return section; } diff --git a/src/main/java/com/sk89q/bukkit/migration/DinnerPermsResolver.java b/src/main/java/com/sk89q/bukkit/migration/DinnerPermsResolver.java index 09b3edac9..ce74cfc19 100644 --- a/src/main/java/com/sk89q/bukkit/migration/DinnerPermsResolver.java +++ b/src/main/java/com/sk89q/bukkit/migration/DinnerPermsResolver.java @@ -50,18 +50,18 @@ public class DinnerPermsResolver implements PermissionsResolver { return false; // Permissions are only registered for online players } switch (internalHasPermission(perms, permission)) { - case -1: - return false; - case 1: - return true; + case -1: + return false; + case 1: + return true; } int dotPos = permission.lastIndexOf("."); while (dotPos > -1) { switch (internalHasPermission(perms, permission.substring(0, dotPos + 1) + "*")) { - case -1: - return false; - case 1: - return true; + case -1: + return false; + case 1: + return true; } dotPos = permission.lastIndexOf(".", dotPos - 1); } @@ -115,7 +115,7 @@ public class DinnerPermsResolver implements PermissionsResolver { } } } - + public String getDetectionMessage() { return "Using the Bukkit Permissions API."; } diff --git a/src/main/java/com/sk89q/bukkit/migration/PermissionsProvider.java b/src/main/java/com/sk89q/bukkit/migration/PermissionsProvider.java index 04688e9bf..8f60851a5 100644 --- a/src/main/java/com/sk89q/bukkit/migration/PermissionsProvider.java +++ b/src/main/java/com/sk89q/bukkit/migration/PermissionsProvider.java @@ -21,7 +21,10 @@ package com.sk89q.bukkit.migration; public interface PermissionsProvider { public boolean hasPermission(String name, String permission); + public boolean hasPermission(String worldName, String name, String permission); + public boolean inGroup(String player, String group); + public String[] getGroups(String player); } diff --git a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java index 2e223f3e6..ee8ebb324 100644 --- a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java +++ b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java @@ -64,11 +64,11 @@ public class PermissionsResolverManager implements PermissionsResolver { @SuppressWarnings("unchecked") protected Class[] availableResolvers = new Class[] { - PluginPermissionsResolver.class, - PermissionsExResolver.class, - NijiPermissionsResolver.class, - DinnerPermsResolver.class, - FlatFilePermissionsResolver.class + PluginPermissionsResolver.class, + PermissionsExResolver.class, + NijiPermissionsResolver.class, + DinnerPermsResolver.class, + FlatFilePermissionsResolver.class }; @Deprecated @@ -167,8 +167,8 @@ public class PermissionsResolverManager implements PermissionsResolver { } if (!keys.contains("resolvers")) { - //List resolverKeys = config.getKeys("resolvers"); - List resolvers = new ArrayList(); + //List resolverKeys = config.getKeys("resolvers"); + List resolvers = new ArrayList(); for (Class clazz : availableResolvers) { resolvers.add(clazz.getSimpleName()); } diff --git a/src/main/java/com/sk89q/minecraft/util/commands/Command.java b/src/main/java/com/sk89q/minecraft/util/commands/Command.java index ca4ef0269..0efb36b31 100644 --- a/src/main/java/com/sk89q/minecraft/util/commands/Command.java +++ b/src/main/java/com/sk89q/minecraft/util/commands/Command.java @@ -36,29 +36,29 @@ public @interface Command { * is never used for anything). */ String[] aliases(); - + /** * Usage instruction. Example text for usage could be * [-h] [name] [message]. */ String usage() default ""; - + /** * A short description for the command. */ String desc(); - + /** * The minimum number of arguments. This should be 0 or above. */ int min() default 0; - + /** * The maximum number of arguments. Use -1 for an unlimited number * of arguments. */ int max() default -1; - + /** * Flags allow special processing for flags such as -h in the command, * allowing users to easily turn on a flag. This is a string with @@ -67,5 +67,4 @@ public @interface Command { * meaning that if it is given it must have a value */ String flags() default ""; - } diff --git a/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java b/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java index d60fd527c..7a73fe09c 100644 --- a/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java +++ b/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java @@ -110,7 +110,7 @@ public class CommandContext { // Not a flag? if (arg.charAt(0) != '-' || arg.length() == 1 || !arg.matches("^-[a-zA-Z]+$")) { - originalArgIndices.add(argIndexList.get(nextArg-1)); + originalArgIndices.add(argIndexList.get(nextArg - 1)); parsedArgs.add(arg); continue; } @@ -134,7 +134,7 @@ public class CommandContext { } if (nextArg >= argList.size()) { - throw new CommandException("No value specified for the '-"+flagName+"' flag."); + throw new CommandException("No value specified for the '-" + flagName + "' flag."); } // If it is a value flag, read another argument and add it diff --git a/src/main/java/com/sk89q/minecraft/util/commands/CommandUsageException.java b/src/main/java/com/sk89q/minecraft/util/commands/CommandUsageException.java index 35ec61330..db2f86c34 100644 --- a/src/main/java/com/sk89q/minecraft/util/commands/CommandUsageException.java +++ b/src/main/java/com/sk89q/minecraft/util/commands/CommandUsageException.java @@ -21,14 +21,14 @@ package com.sk89q.minecraft.util.commands; public class CommandUsageException extends CommandException { private static final long serialVersionUID = -6761418114414516542L; - + protected String usage; - + public CommandUsageException(String message, String usage) { super(message); this.usage = usage; } - + public String getUsage() { return usage; } diff --git a/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java b/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java index cc729ee7f..8bbdb8f3c 100644 --- a/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java +++ b/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java @@ -56,13 +56,12 @@ import com.sk89q.util.StringUtil; * @param command sender class */ public abstract class CommandsManager { - /** * Logger for general errors. */ protected static final Logger logger = Logger.getLogger(CommandsManager.class.getCanonicalName()); - + /** * Mapping of commands (including aliases) with a description. Root * commands are stored under a key of null, whereas child commands are @@ -70,14 +69,13 @@ public abstract class CommandsManager { * the key of the command name (one for each alias) with the * method. */ - protected Map> commands - = new HashMap>(); + protected Map> commands = new HashMap>(); /** * Used to store the instances associated with a method. */ protected Map instances = new HashMap(); - + /** * Mapping of commands (not including aliases) with a description. This * is only for top level commands. @@ -88,7 +86,7 @@ public abstract class CommandsManager { * Stores the injector used to getInstance. */ protected Injector injector; - + /** * Register an class that contains commands (denoted by {@link Command}. * If no dependency injector is specified, then the methods of the @@ -144,7 +142,7 @@ public abstract class CommandsManager { } return null; } - + /** * Register the methods of a class. * @@ -154,7 +152,7 @@ public abstract class CommandsManager { private List registerMethods(Class cls, Method parent, Object obj) { Map map; List registered = new ArrayList(); - + // Make a new hash map to cache the commands for this class // as looking up methods via reflection is fairly slow if (commands.containsKey(parent)) { @@ -163,7 +161,7 @@ public abstract class CommandsManager { map = new HashMap(); commands.put(parent, map); } - + for (Method method : cls.getMethods()) { if (!method.isAnnotationPresent(Command.class)) { continue; @@ -172,7 +170,7 @@ public abstract class CommandsManager { boolean isStatic = Modifier.isStatic(method.getModifiers()); Command cmd = method.getAnnotation(Command.class); - + // Cache the aliases too for (String alias : cmd.aliases()) { map.put(alias, method); @@ -184,10 +182,10 @@ public abstract class CommandsManager { if (obj == null) { continue; } - + instances.put(method, obj); } - + // Build a list of commands and their usage details, at least for // root level commands if (parent == null) { @@ -200,13 +198,13 @@ public abstract class CommandsManager { // Add the command to the registered command list for return registered.add(cmd); - + // Look for nested commands -- if there are any, those have // to be cached too so that they can be quickly looked // up when processing commands if (method.isAnnotationPresent(NestedCommand.class)) { NestedCommand nestedCmd = method.getAnnotation(NestedCommand.class); - + for (Class nestedCls : nestedCmd.value()) { registerMethods(nestedCls, method); } @@ -214,7 +212,7 @@ public abstract class CommandsManager { } return registered; } - + /** * Checks to see whether there is a command named such at the root level. * This will check aliases as well. @@ -225,7 +223,7 @@ public abstract class CommandsManager { public boolean hasCommand(String command) { return commands.get(null).containsKey(command.toLowerCase()); } - + /** * Get a list of command descriptions. This is only for root commands. * @@ -234,7 +232,7 @@ public abstract class CommandsManager { public Map getCommands() { return descs; } - + /** * Get the usage string for a command. * @@ -245,9 +243,9 @@ public abstract class CommandsManager { */ protected String getUsage(String[] args, int level, Command cmd) { StringBuilder command = new StringBuilder(); - + command.append("/"); - + for (int i = 0; i <= level; ++i) { command.append(args[i] + " "); } @@ -256,7 +254,8 @@ public abstract class CommandsManager { char[] flags = cmd.flags().toCharArray(); for (int i = 0; i < flags.length; ++i) { if (flags.length > i + 1 && flags[i + 1] == ':') { - i++; continue; + i++; + continue; } flagChars.add(flags[i]); } @@ -269,10 +268,10 @@ public abstract class CommandsManager { } } command.append(cmd.usage()); - + return command.toString(); } - + /** * Get the usage string for a nested command. * @@ -285,34 +284,33 @@ public abstract class CommandsManager { */ protected String getNestedUsage(String[] args, int level, Method method, T player) throws CommandException { - + StringBuilder command = new StringBuilder(); - + command.append("/"); - + for (int i = 0; i <= level; ++i) { command.append(args[i] + " "); } - Map map = commands.get(method); boolean found = false; - + command.append("<"); - + Set allowedCommands = new HashSet(); - + for (Map.Entry entry : map.entrySet()) { Method childMethod = entry.getValue(); found = true; - + if (hasPermission(childMethod, player)) { Command childCmd = childMethod.getAnnotation(Command.class); - + allowedCommands.add(childCmd.aliases()[0]); } } - + if (allowedCommands.size() > 0) { command.append(StringUtil.joinString(allowedCommands, "|", 0)); } else { @@ -323,12 +321,12 @@ public abstract class CommandsManager { throw new CommandPermissionsException(); } } - + command.append(">"); - + return command.toString(); } - + /** * Attempt to execute a command. This version takes a separate command * name (for the root command) and then a list of following arguments. @@ -340,17 +338,17 @@ public abstract class CommandsManager { * @throws CommandException */ public void execute(String cmd, String[] args, T player, - Object ... methodArgs) throws CommandException { - + Object... methodArgs) throws CommandException { + String[] newArgs = new String[args.length + 1]; System.arraycopy(args, 0, newArgs, 1, args.length); newArgs[0] = cmd; Object[] newMethodArgs = new Object[methodArgs.length + 1]; System.arraycopy(methodArgs, 0, newMethodArgs, 1, methodArgs.length); - + executeMethod(null, newArgs, player, newMethodArgs, 0); } - + /** * Attempt to execute a command. * @@ -360,13 +358,13 @@ public abstract class CommandsManager { * @throws CommandException */ public void execute(String[] args, T player, - Object ... methodArgs) throws CommandException { - + Object... methodArgs) throws CommandException { + Object[] newMethodArgs = new Object[methodArgs.length + 1]; System.arraycopy(methodArgs, 0, newMethodArgs, 1, methodArgs.length); executeMethod(null, args, player, newMethodArgs, 0); } - + /** * Attempt to execute a command. * @@ -379,12 +377,12 @@ public abstract class CommandsManager { */ public void executeMethod(Method parent, String[] args, T player, Object[] methodArgs, int level) throws CommandException { - + String cmdName = args[level]; - + Map map = commands.get(parent); Method method = map.get(cmdName.toLowerCase()); - + if (method == null) { if (parent == null) { // Root throw new UnhandledCommandException(); @@ -393,16 +391,16 @@ public abstract class CommandsManager { getNestedUsage(args, level - 1, parent, player)); } } - + if (!hasPermission(method, player)) { throw new CommandPermissionsException(); } - + int argsCount = args.length - 1 - level; if (method.isAnnotationPresent(NestedCommand.class)) { if (argsCount == 0) { - throw new MissingNestedCommandException("Sub-command required.", + throw new MissingNestedCommandException("Sub-command required.", getNestedUsage(args, level, method, player)); } else { executeMethod(method, args, player, methodArgs, level + 1); @@ -410,7 +408,7 @@ public abstract class CommandsManager { } else if (method.isAnnotationPresent(CommandAlias.class)) { CommandAlias aCmd = method.getAnnotation(CommandAlias.class); executeMethod(parent, aCmd.value(), player, methodArgs, level); - } else { + } else { Command cmd = method.getAnnotation(Command.class); String[] newArgs = new String[args.length - level]; @@ -422,23 +420,26 @@ public abstract class CommandsManager { Set newFlags = new HashSet(); for (int i = 0; i < flags.length; ++i) { if (flags.length > i + 1 && flags[i + 1] == ':') { - valueFlags.add(flags[i]); - ++i; + valueFlags.add(flags[i]); + ++i; } newFlags.add(flags[i]); } CommandContext context = new CommandContext(newArgs, valueFlags); - if (context.argsLength() < cmd.min()) + if (context.argsLength() < cmd.min()) { throw new CommandUsageException("Too few arguments.", getUsage(args, level, cmd)); + } - if (cmd.max() != -1 && context.argsLength() > cmd.max()) + if (cmd.max() != -1 && context.argsLength() > cmd.max()) { throw new CommandUsageException("Too many arguments.", getUsage(args, level, cmd)); + } for (char flag : context.getFlags()) { - if (!newFlags.contains(flag)) + if (!newFlags.contains(flag)) { throw new CommandUsageException("Unknown flag: " + flag, getUsage(args, level, cmd)); + } } methodArgs[0] = context; @@ -461,11 +462,11 @@ public abstract class CommandsManager { if (e.getCause() instanceof CommandException) { throw (CommandException) e.getCause(); } - + throw new WrappedCommandException(e.getCause()); } } - + /** * Returns whether a player has access to a command. * @@ -478,16 +479,16 @@ public abstract class CommandsManager { if (perms == null) { return true; } - + for (String perm : perms.value()) { if (hasPermission(player, perm)) { return true; } } - + return false; } - + /** * Returns whether a player permission.. * diff --git a/src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java b/src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java index 22bf16bf9..d3e4cd411 100644 --- a/src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java +++ b/src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java @@ -5,6 +5,7 @@ import java.lang.reflect.InvocationTargetException; public class SimpleInjector implements Injector { private final T injectionObject; + public SimpleInjector(T injectionObject) { this.injectionObject = injectionObject; } diff --git a/src/main/java/com/sk89q/minecraft/util/commands/WrappedCommandException.java b/src/main/java/com/sk89q/minecraft/util/commands/WrappedCommandException.java index bd0eb1dd6..089aa4608 100644 --- a/src/main/java/com/sk89q/minecraft/util/commands/WrappedCommandException.java +++ b/src/main/java/com/sk89q/minecraft/util/commands/WrappedCommandException.java @@ -21,7 +21,7 @@ package com.sk89q.minecraft.util.commands; public class WrappedCommandException extends CommandException { private static final long serialVersionUID = -4075721444847778918L; - + public WrappedCommandException(Throwable t) { super(t); } diff --git a/src/main/java/com/sk89q/util/StringUtil.java b/src/main/java/com/sk89q/util/StringUtil.java index 78364809b..37b4362e5 100644 --- a/src/main/java/com/sk89q/util/StringUtil.java +++ b/src/main/java/com/sk89q/util/StringUtil.java @@ -37,7 +37,7 @@ public class StringUtil { if (str.length() > len) { return str.substring(0, len); } - + return str; } @@ -156,7 +156,7 @@ public class StringUtil { if (i > 0) { buffer.append(delimiter); } - + buffer.append(o.toString()); } ++i; diff --git a/src/main/java/com/sk89q/util/yaml/YAMLFormat.java b/src/main/java/com/sk89q/util/yaml/YAMLFormat.java index bacd18baf..66686238b 100644 --- a/src/main/java/com/sk89q/util/yaml/YAMLFormat.java +++ b/src/main/java/com/sk89q/util/yaml/YAMLFormat.java @@ -5,7 +5,7 @@ import org.yaml.snakeyaml.DumperOptions.FlowStyle; public enum YAMLFormat { EXTENDED(FlowStyle.BLOCK), COMPACT(FlowStyle.AUTO); - + private final FlowStyle style; YAMLFormat(FlowStyle style) { diff --git a/src/main/java/com/sk89q/util/yaml/YAMLNode.java b/src/main/java/com/sk89q/util/yaml/YAMLNode.java index b1f94eea7..4c1a79370 100644 --- a/src/main/java/com/sk89q/util/yaml/YAMLNode.java +++ b/src/main/java/com/sk89q/util/yaml/YAMLNode.java @@ -36,6 +36,7 @@ import java.util.Map; public class YAMLNode { protected Map root; private boolean writeDefaults; + public YAMLNode(Map root, boolean writeDefaults) { this.root = root; this.writeDefaults = writeDefaults; @@ -49,14 +50,14 @@ public class YAMLNode { public Map getMap() { return root; } - + /** * Clear all nodes. */ public void clear() { root.clear(); } - + /** * Gets a property at a location. This will either return an Object * or null, with null meaning that no configuration value exists at @@ -76,31 +77,31 @@ public class YAMLNode { } return val; } - + String[] parts = path.split("\\."); Map node = root; - + for (int i = 0; i < parts.length; i++) { Object o = node.get(parts[i]); - + if (o == null) { return null; } - + if (i == parts.length - 1) { return o; } - + try { - node = (Map)o; + node = (Map) o; } catch (ClassCastException e) { return null; } } - + return null; } - + /** * Prepare a value for serialization, in case it's not a native type * (and we don't want to serialize objects as YAML objects). @@ -117,10 +118,10 @@ public class YAMLNode { out.put("z", vec.getZ()); return out; } - + return value; } - + /** * Set the property at a location. This will override existing * configuration data to have it conform to key/value mappings. @@ -131,34 +132,34 @@ public class YAMLNode { @SuppressWarnings("unchecked") public void setProperty(String path, Object value) { value = prepareSerialization(value); - + if (!path.contains(".")) { root.put(path, value); return; } - + String[] parts = path.split("\\."); Map node = root; - + for (int i = 0; i < parts.length; i++) { Object o = node.get(parts[i]); - + // Found our target! if (i == parts.length - 1) { node.put(parts[i], value); return; } - + if (o == null || !(o instanceof Map)) { // This will override existing configuration data! o = new HashMap(); node.put(parts[i], o); } - - node = (Map)o; + + node = (Map) o; } } - + /** * Adds a new node to the given path. The returned object is a reference * to the new node. This method will replace an existing node at @@ -204,15 +205,15 @@ public class YAMLNode { if (o == null) { return null; } - + Double x = o.getDouble("x"); Double y = o.getDouble("y"); Double z = o.getDouble("z"); - + if (x == null || y == null || z == null) { return null; } - + return new Vector(x, y, z); } @@ -229,14 +230,14 @@ public class YAMLNode { if (o == null) { return null; } - + Double x = o.getDouble("x"); Double z = o.getDouble("z"); - + if (x == null || z == null) { return null; } - + return new Vector2D(x, z); } @@ -387,7 +388,7 @@ public class YAMLNode { return o; } } - + /** * Get a list of keys at a location. If the map at the particular location * does not exist or it is not a map, null will be returned. @@ -402,7 +403,7 @@ public class YAMLNode { if (o == null) { return null; } else if (o instanceof Map) { - return new ArrayList(((Map)o).keySet()); + return new ArrayList(((Map) o).keySet()); } else { return null; } @@ -421,12 +422,12 @@ public class YAMLNode { if (o == null) { return null; } else if (o instanceof List) { - return (List)o; + return (List) o; } else { return null; } } - + /** * Gets a list of strings. Non-valid entries will not be in the list. * There will be no null slots. If the list is not defined, the @@ -450,13 +451,13 @@ public class YAMLNode { if (o == null) { continue; } - + list.add(o.toString()); } - + return list; } - + /** * Gets a list of integers. Non-valid entries will not be in the list. * There will be no null slots. If the list is not defined, the @@ -481,10 +482,10 @@ public class YAMLNode { list.add(i); } } - + return list; } - + /** * Gets a list of doubles. Non-valid entries will not be in the list. * There will be no null slots. If the list is not defined, the @@ -509,10 +510,10 @@ public class YAMLNode { list.add(i); } } - + return list; } - + /** * Gets a list of booleans. Non-valid entries will not be in the list. * There will be no null slots. If the list is not defined, the @@ -537,10 +538,10 @@ public class YAMLNode { list.add(tetsu); } } - + return list; } - + /** * Gets a list of vectors. Non-valid entries will not be in the list. * There will be no null slots. If the list is not defined, the @@ -554,25 +555,25 @@ public class YAMLNode { */ public List getVectorList( String path, List def) { - + List raw = getNodeList(path, null); List list = new ArrayList(); - + for (YAMLNode o : raw) { Double x = o.getDouble("x"); Double y = o.getDouble("y"); Double z = o.getDouble("z"); - + if (x == null || y == null || z == null) { continue; } - + list.add(new Vector(x, y, z)); } - + return list; } - + /** * Gets a list of 2D vectors. Non-valid entries will not be in the list. * There will be no null slots. If the list is not defined, the @@ -586,24 +587,24 @@ public class YAMLNode { */ public List getVector2dList( String path, List def) { - + List raw = getNodeList(path, null); List list = new ArrayList(); - + for (YAMLNode o : raw) { Double x = o.getDouble("x"); Double z = o.getDouble("z"); - + if (x == null || z == null) { continue; } - + list.add(new Vector2D(x, z)); } - + return list; } - + /** * Gets a list of 2D vectors. Non-valid entries will not be in the list. * There will be no null slots. If the list is not defined, the @@ -617,24 +618,24 @@ public class YAMLNode { */ public List getBlockVector2dList( String path, List def) { - + List raw = getNodeList(path, null); List list = new ArrayList(); - + for (YAMLNode o : raw) { Double x = o.getDouble("x"); Double z = o.getDouble("z"); - + if (x == null || z == null) { continue; } - + list.add(new BlockVector2D(x, z)); } - + return list; } - + /** * Gets a list of nodes. Non-valid entries will not be in the list. * There will be no null slots. If the list is not defined, the @@ -656,13 +657,13 @@ public class YAMLNode { List list = new ArrayList(); for (Object o : raw) { if (o instanceof Map) { - list.add(new YAMLNode((Map)o, writeDefaults)); + list.add(new YAMLNode((Map) o, writeDefaults)); } } - + return list; } - + /** * Get a configuration node at a path. If the node doesn't exist or the * path does not lead to a node, null will be returned. A node has @@ -675,12 +676,12 @@ public class YAMLNode { public YAMLNode getNode(String path) { Object raw = getProperty(path); if (raw instanceof Map) { - return new YAMLNode((Map)raw, writeDefaults); + return new YAMLNode((Map) raw, writeDefaults); } - + return null; } - + /** * Get a list of nodes at a location. If the map at the particular location * does not exist or it is not a map, null will be returned. @@ -695,21 +696,21 @@ public class YAMLNode { return null; } else if (o instanceof Map) { Map nodes = - new HashMap(); - - for (Map.Entry entry : ((Map)o).entrySet()) { + new HashMap(); + + for (Map.Entry entry : ((Map) o).entrySet()) { if (entry.getValue() instanceof Map) { nodes.put(entry.getKey(), new YAMLNode((Map) entry.getValue(), writeDefaults)); } } - + return nodes; } else { return null; } } - + /** * Casts a value to an integer. May return null. * @@ -720,12 +721,12 @@ public class YAMLNode { if (o == null) { return null; } else if (o instanceof Number) { - return ((Number)o).intValue(); + return ((Number) o).intValue(); } else { return null; } } - + /** * Casts a value to a double. May return null. * @@ -736,12 +737,12 @@ public class YAMLNode { if (o == null) { return null; } else if (o instanceof Number) { - return ((Number)o).doubleValue(); + return ((Number) o).doubleValue(); } else { return null; } } - + /** * Casts a value to a boolean. May return null. * @@ -752,12 +753,12 @@ public class YAMLNode { if (o == null) { return null; } else if (o instanceof Boolean) { - return (Boolean)o; + return (Boolean) o; } else { return null; } } - + /** * Remove the property at a location. This will override existing * configuration data to have it conform to key/value mappings. @@ -770,20 +771,20 @@ public class YAMLNode { root.remove(path); return; } - + String[] parts = path.split("\\."); Map node = root; - + for (int i = 0; i < parts.length; i++) { Object o = node.get(parts[i]); - + // Found our target! if (i == parts.length - 1) { node.remove(parts[i]); return; } - - node = (Map)o; + + node = (Map) o; } } @@ -794,4 +795,4 @@ public class YAMLNode { public void setWriteDefaults(boolean writeDefaults) { this.writeDefaults = writeDefaults; } -} \ No newline at end of file +} diff --git a/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java b/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java index 989f61530..ac02685bc 100644 --- a/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java +++ b/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java @@ -66,10 +66,10 @@ public class YAMLProcessor extends YAMLNode { private Yaml yaml; private File file; private String header = null; - + public YAMLProcessor(File file, boolean writeDefaults, YAMLFormat format) { super(new HashMap(), writeDefaults); - + DumperOptions options = new DumperOptions(); options.setIndent(4); options.setDefaultFlowStyle(format.getStyle()); @@ -77,22 +77,22 @@ public class YAMLProcessor extends YAMLNode { representer.setDefaultFlowStyle(format.getStyle()); yaml = new Yaml(new SafeConstructor(), representer, options); - + this.file = file; } public YAMLProcessor(File file, boolean writeDefaults) { this(file, writeDefaults, YAMLFormat.COMPACT); } - + /** * Loads the configuration file. * * @throws java.io.IOException */ - public void load() throws IOException { + public void load() throws IOException { FileInputStream stream = null; - + try { stream = new FileInputStream(file); read(yaml.load(new UnicodeReader(stream))); @@ -171,7 +171,8 @@ public class YAMLProcessor extends YAMLNode { } yaml.dump(root, writer); return true; - } catch (IOException e) {} finally { + } catch (IOException e) { + } finally { try { if (stream != null) { stream.close(); @@ -181,20 +182,20 @@ public class YAMLProcessor extends YAMLNode { return false; } - + @SuppressWarnings("unchecked") private void read(Object input) throws YAMLProcessorException { try { - if ( null == input ) { + if (null == input) { root = new HashMap(); } else { - root = (Map)input; + root = (Map) input; } } catch (ClassCastException e) { throw new YAMLProcessorException("Root document must be an key-value structure"); } } - + /** * This method returns an empty ConfigurationNode for using as a * default in methods that select a node from a node list. diff --git a/src/main/java/com/sk89q/util/yaml/YAMLProcessorException.java b/src/main/java/com/sk89q/util/yaml/YAMLProcessorException.java index c53ffb0d2..642b826dc 100644 --- a/src/main/java/com/sk89q/util/yaml/YAMLProcessorException.java +++ b/src/main/java/com/sk89q/util/yaml/YAMLProcessorException.java @@ -26,11 +26,11 @@ package com.sk89q.util.yaml; */ public class YAMLProcessorException extends Exception { private static final long serialVersionUID = -2442886939908724203L; - + public YAMLProcessorException() { super(); } - + public YAMLProcessorException(String msg) { super(msg); } diff --git a/src/main/java/com/sk89q/worldedit/ArbitraryShape.java b/src/main/java/com/sk89q/worldedit/ArbitraryShape.java index 5b9a87b0f..589d8109d 100644 --- a/src/main/java/com/sk89q/worldedit/ArbitraryShape.java +++ b/src/main/java/com/sk89q/worldedit/ArbitraryShape.java @@ -38,9 +38,9 @@ public abstract class ArbitraryShape { Vector min = extent.getMinimumPoint(); Vector max = extent.getMaximumPoint(); - cacheSizeX = (int)(max.getX() - min.getX() + 1 + 2); - cacheSizeY = (int)(max.getY() - min.getY() + 1 + 2); - cacheSizeZ = (int)(max.getZ() - min.getZ() + 1 + 2); + cacheSizeX = (int) (max.getX() - min.getX() + 1 + 2); + cacheSizeY = (int) (max.getY() - min.getY() + 1 + 2); + cacheSizeZ = (int) (max.getZ() - min.getZ() + 1 + 2); cacheX = min.getBlockX() - 1; cacheY = min.getBlockY() - 1; @@ -79,7 +79,7 @@ public abstract class ArbitraryShape { return null; } - short newCacheEntry = (short) (material.getType() | ((material.getData()+1) << 8)); + short newCacheEntry = (short) (material.getType() | ((material.getData() + 1) << 8)); if (newCacheEntry == 0) { // type and data 0 newCacheEntry = -2; @@ -102,7 +102,7 @@ public abstract class ArbitraryShape { private boolean isInsideCached(int x, int y, int z, Pattern pattern) { final int index = (y - cacheY) + (z - cacheZ) * cacheSizeY + (x - cacheX) * cacheSizeY * cacheSizeZ; - + switch (cache[index]) { case 0: // unknown block, meaning they must be outside the extent at this stage, but might still be inside the shape diff --git a/src/main/java/com/sk89q/worldedit/BlockVector.java b/src/main/java/com/sk89q/worldedit/BlockVector.java index ab54bdf55..660ec6744 100644 --- a/src/main/java/com/sk89q/worldedit/BlockVector.java +++ b/src/main/java/com/sk89q/worldedit/BlockVector.java @@ -80,9 +80,9 @@ public class BlockVector extends Vector { if (!(obj instanceof Vector)) { return false; } - Vector other = (Vector)obj; - return (int)other.getX() == (int)this.x && (int)other.getY() == (int)this.y - && (int)other.getZ() == (int)this.z; + Vector other = (Vector) obj; + return (int) other.getX() == (int) this.x && (int) other.getY() == (int) this.y + && (int) other.getZ() == (int) this.z; } @@ -93,8 +93,8 @@ public class BlockVector extends Vector { */ @Override public int hashCode() { - return (Integer.valueOf((int)x).hashCode() << 19) ^ - (Integer.valueOf((int)y).hashCode() << 12) ^ - Integer.valueOf((int)z).hashCode(); + return (Integer.valueOf((int) x).hashCode() << 19) ^ + (Integer.valueOf((int) y).hashCode() << 12) ^ + Integer.valueOf((int) z).hashCode(); } } diff --git a/src/main/java/com/sk89q/worldedit/BlockVector2D.java b/src/main/java/com/sk89q/worldedit/BlockVector2D.java index c1119f896..8b57346ea 100644 --- a/src/main/java/com/sk89q/worldedit/BlockVector2D.java +++ b/src/main/java/com/sk89q/worldedit/BlockVector2D.java @@ -75,8 +75,8 @@ public class BlockVector2D extends Vector2D { if (!(obj instanceof Vector2D)) { return false; } - Vector2D other = (Vector2D)obj; - return (int)other.x == (int)this.x && (int)other.z == (int)this.z; + Vector2D other = (Vector2D) obj; + return (int) other.x == (int) this.x && (int) other.z == (int) this.z; } @@ -87,7 +87,7 @@ public class BlockVector2D extends Vector2D { */ @Override public int hashCode() { - return (Integer.valueOf((int)x).hashCode() >> 13) ^ - Integer.valueOf((int)z).hashCode(); + return (Integer.valueOf((int) x).hashCode() >> 13) ^ + Integer.valueOf((int) z).hashCode(); } } diff --git a/src/main/java/com/sk89q/worldedit/BlockWorldVector.java b/src/main/java/com/sk89q/worldedit/BlockWorldVector.java index 9de1ae59f..dee84bef2 100644 --- a/src/main/java/com/sk89q/worldedit/BlockWorldVector.java +++ b/src/main/java/com/sk89q/worldedit/BlockWorldVector.java @@ -33,7 +33,7 @@ public class BlockWorldVector extends WorldVector { public BlockWorldVector(WorldVector pt) { super(pt.getWorld(), pt); } - + /** * Construct the Vector object. * @param world @@ -101,7 +101,7 @@ public class BlockWorldVector extends WorldVector { public BlockWorldVector(LocalWorld world, double x, double y, double z) { super(world, x, y, z); } - + /** * Checks if another object is equivalent. * @@ -113,9 +113,9 @@ public class BlockWorldVector extends WorldVector { if (!(obj instanceof WorldVector)) { return false; } - WorldVector other = (WorldVector)obj; - return (int)other.getX() == (int)this.x && (int)other.getY() == (int)this.y - && (int)other.getZ() == (int)this.z; + WorldVector other = (WorldVector) obj; + return (int) other.getX() == (int) this.x && (int) other.getY() == (int) this.y + && (int) other.getZ() == (int) this.z; } @@ -126,8 +126,8 @@ public class BlockWorldVector extends WorldVector { */ @Override public int hashCode() { - return (Integer.valueOf((int)x).hashCode() << 19) ^ - (Integer.valueOf((int)y).hashCode() << 12) ^ - Integer.valueOf((int)z).hashCode(); + return (Integer.valueOf((int) x).hashCode() << 19) ^ + (Integer.valueOf((int) y).hashCode() << 12) ^ + Integer.valueOf((int) z).hashCode(); } } diff --git a/src/main/java/com/sk89q/worldedit/BlockWorldVector2D.java b/src/main/java/com/sk89q/worldedit/BlockWorldVector2D.java index 1ba694698..5f588fe3d 100644 --- a/src/main/java/com/sk89q/worldedit/BlockWorldVector2D.java +++ b/src/main/java/com/sk89q/worldedit/BlockWorldVector2D.java @@ -58,4 +58,4 @@ public class BlockWorldVector2D extends WorldVector2D { && (int) other.getZ() == (int) this.z; } -} \ No newline at end of file +} diff --git a/src/main/java/com/sk89q/worldedit/CuboidClipboard.java b/src/main/java/com/sk89q/worldedit/CuboidClipboard.java index 823e6bb41..fbb91e947 100644 --- a/src/main/java/com/sk89q/worldedit/CuboidClipboard.java +++ b/src/main/java/com/sk89q/worldedit/CuboidClipboard.java @@ -126,7 +126,7 @@ public class CuboidClipboard { return; } boolean reverse = angle < 0; - int numRotations = Math.abs((int)Math.floor(angle / 90.0)); + int numRotations = Math.abs((int) Math.floor(angle / 90.0)); int width = getWidth(); int length = getLength(); @@ -260,7 +260,7 @@ public class CuboidClipboard { for (int y = 0; y < size.getBlockY(); ++y) { for (int z = 0; z < size.getBlockZ(); ++z) { data[x][y][z] = - editSession.getBlock(new Vector(x, y, z).add(getOrigin())); + editSession.getBlock(new Vector(x, y, z).add(getOrigin())); } } } @@ -287,16 +287,15 @@ public class CuboidClipboard { * @param noAir * @throws MaxChangedBlocksException */ - public void place(EditSession editSession, Vector pos, boolean noAir) - throws MaxChangedBlocksException { + public void place(EditSession editSession, Vector pos, boolean noAir) throws MaxChangedBlocksException { for (int x = 0; x < size.getBlockX(); ++x) { for (int y = 0; y < size.getBlockY(); ++y) { for (int z = 0; z < size.getBlockZ(); ++z) { - if (noAir && data[x][y][z].isAir()) + if (noAir && data[x][y][z].isAir()) { continue; + } - editSession.setBlock(new Vector(x, y, z).add(pos), - data[x][y][z]); + editSession.setBlock(new Vector(x, y, z).add(pos), data[x][y][z]); } } } @@ -345,10 +344,10 @@ public class CuboidClipboard { throw new DataException("Length of region too large for a .schematic"); } - HashMap schematic = new HashMap(); - schematic.put("Width", new ShortTag("Width", (short)width)); - schematic.put("Length", new ShortTag("Length", (short)length)); - schematic.put("Height", new ShortTag("Height", (short)height)); + HashMap schematic = new HashMap(); + schematic.put("Width", new ShortTag("Width", (short) width)); + schematic.put("Length", new ShortTag("Length", (short) length)); + schematic.put("Height", new ShortTag("Height", (short) height)); schematic.put("Materials", new StringTag("Materials", "Alpha")); schematic.put("WEOriginX", new IntTag("WEOriginX", getOrigin().getBlockX())); schematic.put("WEOriginY", new IntTag("WEOriginY", getOrigin().getBlockY())); @@ -366,16 +365,16 @@ public class CuboidClipboard { for (int y = 0; y < height; ++y) { for (int z = 0; z < length; ++z) { int index = y * width * length + z * width + x; - blocks[index] = (byte)data[x][y][z].getType(); - blockData[index] = (byte)data[x][y][z].getData(); + blocks[index] = (byte) data[x][y][z].getType(); + blockData[index] = (byte) data[x][y][z].getData(); // Store TileEntity data if (data[x][y][z] instanceof TileEntityBlock) { TileEntityBlock tileEntityBlock = - (TileEntityBlock)data[x][y][z]; + (TileEntityBlock) data[x][y][z]; // Get the list of key/values from the block - Map values = tileEntityBlock.toTileEntityNBT(); + Map values = tileEntityBlock.toTileEntityNBT(); if (values != null) { values.put("id", new StringTag("id", tileEntityBlock.getTileEntityID())); @@ -421,78 +420,78 @@ public class CuboidClipboard { Vector offset = new Vector(); // Schematic tag - CompoundTag schematicTag = (CompoundTag)nbtStream.readTag(); + CompoundTag schematicTag = (CompoundTag) nbtStream.readTag(); if (!schematicTag.getName().equals("Schematic")) { throw new DataException("Tag \"Schematic\" does not exist or is not first"); } // Check - Map schematic = schematicTag.getValue(); + Map schematic = schematicTag.getValue(); if (!schematic.containsKey("Blocks")) { throw new DataException("Schematic file is missing a \"Blocks\" tag"); } // Get information - short width = (Short)getChildTag(schematic, "Width", ShortTag.class).getValue(); - short length = (Short)getChildTag(schematic, "Length", ShortTag.class).getValue(); - short height = (Short)getChildTag(schematic, "Height", ShortTag.class).getValue(); + short width = (Short) getChildTag(schematic, "Width", ShortTag.class).getValue(); + short length = (Short) getChildTag(schematic, "Length", ShortTag.class).getValue(); + short height = (Short) getChildTag(schematic, "Height", ShortTag.class).getValue(); try { - int originX = (Integer)getChildTag(schematic, "WEOriginX", IntTag.class).getValue(); - int originY = (Integer)getChildTag(schematic, "WEOriginY", IntTag.class).getValue(); - int originZ = (Integer)getChildTag(schematic, "WEOriginZ", IntTag.class).getValue(); + int originX = (Integer) getChildTag(schematic, "WEOriginX", IntTag.class).getValue(); + int originY = (Integer) getChildTag(schematic, "WEOriginY", IntTag.class).getValue(); + int originZ = (Integer) getChildTag(schematic, "WEOriginZ", IntTag.class).getValue(); origin = new Vector(originX, originY, originZ); } catch (DataException e) { // No origin data } try { - int offsetX = (Integer)getChildTag(schematic, "WEOffsetX", IntTag.class).getValue(); - int offsetY = (Integer)getChildTag(schematic, "WEOffsetY", IntTag.class).getValue(); - int offsetZ = (Integer)getChildTag(schematic, "WEOffsetZ", IntTag.class).getValue(); + int offsetX = (Integer) getChildTag(schematic, "WEOffsetX", IntTag.class).getValue(); + int offsetY = (Integer) getChildTag(schematic, "WEOffsetY", IntTag.class).getValue(); + int offsetZ = (Integer) getChildTag(schematic, "WEOffsetZ", IntTag.class).getValue(); offset = new Vector(offsetX, offsetY, offsetZ); } catch (DataException e) { // No offset data } // Check type of Schematic - String materials = (String)getChildTag(schematic, "Materials", StringTag.class).getValue(); + String materials = (String) getChildTag(schematic, "Materials", StringTag.class).getValue(); if (!materials.equals("Alpha")) { throw new DataException("Schematic file is not an Alpha schematic"); } // Get blocks - byte[] blocks = (byte[])getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue(); - byte[] blockData = (byte[])getChildTag(schematic, "Data", ByteArrayTag.class).getValue(); + byte[] blocks = (byte[]) getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue(); + byte[] blockData = (byte[]) getChildTag(schematic, "Data", ByteArrayTag.class).getValue(); // Need to pull out tile entities - List tileEntities = (List)((ListTag)getChildTag(schematic, "TileEntities", ListTag.class)) + List tileEntities = (List) ((ListTag) getChildTag(schematic, "TileEntities", ListTag.class)) .getValue(); - Map> tileEntitiesMap = - new HashMap>(); + Map> tileEntitiesMap = + new HashMap>(); for (Tag tag : tileEntities) { if (!(tag instanceof CompoundTag)) continue; - CompoundTag t = (CompoundTag)tag; + CompoundTag t = (CompoundTag) tag; int x = 0; int y = 0; int z = 0; - Map values = new HashMap(); + Map values = new HashMap(); - for (Map.Entry entry : t.getValue().entrySet()) { + for (Map.Entry entry : t.getValue().entrySet()) { if (entry.getKey().equals("x")) { if (entry.getValue() instanceof IntTag) { - x = ((IntTag)entry.getValue()).getValue(); + x = ((IntTag) entry.getValue()).getValue(); } } else if (entry.getKey().equals("y")) { if (entry.getValue() instanceof IntTag) { - y = ((IntTag)entry.getValue()).getValue(); + y = ((IntTag) entry.getValue()).getValue(); } } else if (entry.getKey().equals("z")) { if (entry.getValue() instanceof IntTag) { - z = ((IntTag)entry.getValue()).getValue(); + z = ((IntTag) entry.getValue()).getValue(); } } @@ -549,7 +548,7 @@ public class CuboidClipboard { if (block instanceof TileEntityBlock && tileEntitiesMap.containsKey(pt)) { - ((TileEntityBlock)block).fromTileEntityNBT( + ((TileEntityBlock) block).fromTileEntityNBT( tileEntitiesMap.get(pt)); } @@ -570,7 +569,7 @@ public class CuboidClipboard { * @return child tag * @throws DataException */ - private static Tag getChildTag(Map items, String key, + private static Tag getChildTag(Map items, String key, Class expected) throws DataException { if (!items.containsKey(key)) { diff --git a/src/main/java/com/sk89q/worldedit/DoubleArrayList.java b/src/main/java/com/sk89q/worldedit/DoubleArrayList.java index 8310d3f1d..362c9f5e6 100644 --- a/src/main/java/com/sk89q/worldedit/DoubleArrayList.java +++ b/src/main/java/com/sk89q/worldedit/DoubleArrayList.java @@ -33,7 +33,7 @@ import java.util.NoSuchElementException; * @param * @param */ -public class DoubleArrayList implements Iterable> { +public class DoubleArrayList implements Iterable> { /** * First list. */ @@ -88,13 +88,13 @@ public class DoubleArrayList implements Iterable> { * * @return */ - public Iterator> iterator() { + public Iterator> iterator() { if (isReversed) { - return new ReverseEntryIterator>( + return new ReverseEntryIterator>( listA.listIterator(listA.size()), listB.listIterator(listB.size())); } else { - return new ForwardEntryIterator>( + return new ForwardEntryIterator>( listA.iterator(), listB.iterator()); } @@ -105,8 +105,8 @@ public class DoubleArrayList implements Iterable> { * * @param */ - public class ForwardEntryIterator> - implements Iterator> { + public class ForwardEntryIterator> + implements Iterator> { private Iterator keyIterator; private Iterator valueIterator; @@ -120,8 +120,8 @@ public class DoubleArrayList implements Iterable> { return keyIterator.hasNext(); } - public Map.Entry next() throws NoSuchElementException { - return new Entry(keyIterator.next(), valueIterator.next()); + public Map.Entry next() throws NoSuchElementException { + return new Entry(keyIterator.next(), valueIterator.next()); } public void remove() { @@ -134,8 +134,8 @@ public class DoubleArrayList implements Iterable> { * * @param */ - public class ReverseEntryIterator> - implements Iterator> { + public class ReverseEntryIterator> + implements Iterator> { private ListIterator keyIterator; private ListIterator valueIterator; @@ -149,8 +149,8 @@ public class DoubleArrayList implements Iterable> { return keyIterator.hasPrevious(); } - public Map.Entry next() throws NoSuchElementException { - return new Entry(keyIterator.previous(), valueIterator.previous()); + public Map.Entry next() throws NoSuchElementException { + return new Entry(keyIterator.previous(), valueIterator.previous()); } public void remove() { @@ -164,7 +164,7 @@ public class DoubleArrayList implements Iterable> { * @param * @param */ - public class Entry implements Map.Entry { + public class Entry implements Map.Entry { private A key; private B value; diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index 7de40b5ee..e7eeea9f1 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -66,31 +66,31 @@ public class EditSession { * Stores the original blocks before modification. */ private DoubleArrayList original = - new DoubleArrayList(true); + new DoubleArrayList(true); /** * Stores the current blocks. */ private DoubleArrayList current = - new DoubleArrayList(false); + new DoubleArrayList(false); /** * Blocks that should be placed before last. */ private DoubleArrayList queueAfter = - new DoubleArrayList(false); + new DoubleArrayList(false); /** * Blocks that should be placed last. */ private DoubleArrayList queueLast = - new DoubleArrayList(false); + new DoubleArrayList(false); /** * Blocks that should be placed after all other blocks. */ private DoubleArrayList queueFinal = - new DoubleArrayList(false); + new DoubleArrayList(false); /** * The maximum number of blocks to change at a time. If this number is @@ -327,20 +327,17 @@ public class EditSession { if (BlockType.shouldPlaceLast(block.getType())) { // Place torches, etc. last queueLast.put(pt.toBlockVector(), block); - return !(getBlockType(pt) == block.getType() - && getBlockData(pt) == block.getData()); + return !(getBlockType(pt) == block.getType() && getBlockData(pt) == block.getData()); } else if (BlockType.shouldPlaceFinal(block.getType())) { // Place signs, reed, etc even later queueFinal.put(pt.toBlockVector(), block); - return !(getBlockType(pt) == block.getType() - && getBlockData(pt) == block.getData()); + return !(getBlockType(pt) == block.getType() && getBlockData(pt) == block.getData()); } else if (BlockType.shouldPlaceLast(getBlockType(pt))) { // Destroy torches, etc. first rawSetBlock(pt, new BaseBlock(BlockID.AIR)); } else { queueAfter.put(pt.toBlockVector(), block); - return !(getBlockType(pt) == block.getType() - && getBlockData(pt) == block.getData()); + return !(getBlockType(pt) == block.getType() && getBlockData(pt) == block.getData()); } } @@ -403,6 +400,7 @@ public class EditSession { return world.getBlockData(pt); } + /** * Gets the block type at a position x, y, z. * @@ -765,7 +763,7 @@ public class EditSession { continue; } - final Deque walked = new LinkedList(); + final Deque walked = new LinkedList(); while (true) { walked.addFirst(current); @@ -1962,7 +1960,7 @@ public class EditSession { visited.add(cur); - if (setBlock(cur, stationaryBlock)){ + if (setBlock(cur, stationaryBlock)) { ++affected; } @@ -2033,13 +2031,11 @@ public class EditSession { final int ceilRadiusZ = (int) Math.ceil(radiusZ); double nextXn = 0; - forX: - for (int x = 0; x <= ceilRadiusX; ++x) { + forX: for (int x = 0; x <= ceilRadiusX; ++x) { final double xn = nextXn; nextXn = (x + 1) * invRadiusX; double nextZn = 0; - forZ: - for (int z = 0; z <= ceilRadiusZ; ++z) { + forZ: for (int z = 0; z <= ceilRadiusZ; ++z) { final double zn = nextZn; nextZn = (z + 1) * invRadiusZ; @@ -2119,18 +2115,15 @@ public class EditSession { final int ceilRadiusZ = (int) Math.ceil(radiusZ); double nextXn = 0; - forX: - for (int x = 0; x <= ceilRadiusX; ++x) { + forX: for (int x = 0; x <= ceilRadiusX; ++x) { final double xn = nextXn; nextXn = (x + 1) * invRadiusX; double nextYn = 0; - forY: - for (int y = 0; y <= ceilRadiusY; ++y) { + forY: for (int y = 0; y <= ceilRadiusY; ++y) { final double yn = nextYn; nextYn = (y + 1) * invRadiusY; double nextZn = 0; - forZ: - for (int z = 0; z <= ceilRadiusZ; ++z) { + forZ: for (int z = 0; z <= ceilRadiusZ; ++z) { final double zn = nextZn; nextZn = (z + 1) * invRadiusZ; @@ -2244,7 +2237,7 @@ public class EditSession { public int thaw(Vector pos, double radius) throws MaxChangedBlocksException { int affected = 0; - double radiusSq = radius*radius; + double radiusSq = radius * radius; int ox = pos.getBlockX(); int oy = pos.getBlockY(); @@ -2303,7 +2296,7 @@ public class EditSession { public int simulateSnow(Vector pos, double radius) throws MaxChangedBlocksException { int affected = 0; - double radiusSq = radius*radius; + double radiusSq = radius * radius; int ox = pos.getBlockX(); int oy = pos.getBlockY(); @@ -2368,7 +2361,7 @@ public class EditSession { public int green(Vector pos, double radius) throws MaxChangedBlocksException { int affected = 0; - double radiusSq = radius*radius; + double radiusSq = radius * radius; int ox = pos.getBlockX(); int oy = pos.getBlockY(); @@ -2655,7 +2648,7 @@ public class EditSession { return null; } - return new BaseBlock((int)typeVariable.getValue(), (int)dataVariable.getValue()); + return new BaseBlock((int) typeVariable.getValue(), (int) dataVariable.getValue()); } catch (Exception e) { e.printStackTrace(); return null; diff --git a/src/main/java/com/sk89q/worldedit/EntityType.java b/src/main/java/com/sk89q/worldedit/EntityType.java index a3eb80c85..00fd852d5 100644 --- a/src/main/java/com/sk89q/worldedit/EntityType.java +++ b/src/main/java/com/sk89q/worldedit/EntityType.java @@ -30,4 +30,4 @@ public enum EntityType { MINECARTS, TNT, XP_ORBS -} \ No newline at end of file +} diff --git a/src/main/java/com/sk89q/worldedit/FileSelectionAbortedException.java b/src/main/java/com/sk89q/worldedit/FileSelectionAbortedException.java index b7cf89e9c..f3b6ce9ae 100644 --- a/src/main/java/com/sk89q/worldedit/FileSelectionAbortedException.java +++ b/src/main/java/com/sk89q/worldedit/FileSelectionAbortedException.java @@ -21,11 +21,11 @@ package com.sk89q.worldedit; public class FileSelectionAbortedException extends FilenameException { private static final long serialVersionUID = 7377072269988014886L; - + public FileSelectionAbortedException() { super(""); } - + public FileSelectionAbortedException(String msg) { super("", msg); } diff --git a/src/main/java/com/sk89q/worldedit/FilenameException.java b/src/main/java/com/sk89q/worldedit/FilenameException.java index 6892d6389..c336037c3 100644 --- a/src/main/java/com/sk89q/worldedit/FilenameException.java +++ b/src/main/java/com/sk89q/worldedit/FilenameException.java @@ -21,19 +21,19 @@ package com.sk89q.worldedit; public class FilenameException extends WorldEditException { private static final long serialVersionUID = 6072601657326106265L; - + private String filename; - + public FilenameException(String filename) { super(); this.filename = filename; } - + public FilenameException(String filename, String msg) { super(msg); this.filename = filename; } - + public String getFilename() { return filename; } diff --git a/src/main/java/com/sk89q/worldedit/FilenameResolutionException.java b/src/main/java/com/sk89q/worldedit/FilenameResolutionException.java index 2236adf07..51d325419 100644 --- a/src/main/java/com/sk89q/worldedit/FilenameResolutionException.java +++ b/src/main/java/com/sk89q/worldedit/FilenameResolutionException.java @@ -21,11 +21,11 @@ package com.sk89q.worldedit; public class FilenameResolutionException extends FilenameException { private static final long serialVersionUID = 4673670296313383121L; - + public FilenameResolutionException(String filename) { super(filename); } - + public FilenameResolutionException(String filename, String msg) { super(filename, msg); } diff --git a/src/main/java/com/sk89q/worldedit/HeightMap.java b/src/main/java/com/sk89q/worldedit/HeightMap.java index 74aeae182..49c45c1b1 100644 --- a/src/main/java/com/sk89q/worldedit/HeightMap.java +++ b/src/main/java/com/sk89q/worldedit/HeightMap.java @@ -1,4 +1,3 @@ -package com.sk89q.worldedit; // $Id$ /* * WorldEditLibrary @@ -18,6 +17,8 @@ package com.sk89q.worldedit; * along with this program. If not, see . */ +package com.sk89q.worldedit; + import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.filtering.HeightMapFilter; diff --git a/src/main/java/com/sk89q/worldedit/InvalidFilenameException.java b/src/main/java/com/sk89q/worldedit/InvalidFilenameException.java index 4431e8da3..71220265c 100644 --- a/src/main/java/com/sk89q/worldedit/InvalidFilenameException.java +++ b/src/main/java/com/sk89q/worldedit/InvalidFilenameException.java @@ -21,11 +21,11 @@ package com.sk89q.worldedit; public class InvalidFilenameException extends FilenameException { private static final long serialVersionUID = 7377072269988014886L; - + public InvalidFilenameException(String filename) { super(filename); } - + public InvalidFilenameException(String filename, String msg) { super(filename, msg); } diff --git a/src/main/java/com/sk89q/worldedit/InvalidToolBindException.java b/src/main/java/com/sk89q/worldedit/InvalidToolBindException.java index f2b958bf3..a60f4b08b 100644 --- a/src/main/java/com/sk89q/worldedit/InvalidToolBindException.java +++ b/src/main/java/com/sk89q/worldedit/InvalidToolBindException.java @@ -21,9 +21,9 @@ package com.sk89q.worldedit; public class InvalidToolBindException extends WorldEditException { private static final long serialVersionUID = -1865311004052447699L; - + private int itemId; - + public InvalidToolBindException(int itemId, String msg) { super(msg); this.itemId = itemId; diff --git a/src/main/java/com/sk89q/worldedit/LocalConfiguration.java b/src/main/java/com/sk89q/worldedit/LocalConfiguration.java index efc8dd299..9bc44e3eb 100644 --- a/src/main/java/com/sk89q/worldedit/LocalConfiguration.java +++ b/src/main/java/com/sk89q/worldedit/LocalConfiguration.java @@ -26,7 +26,6 @@ import java.io.File; import java.util.HashSet; import java.util.Set; - /** * Represents WorldEdit's configuration. * @@ -102,12 +101,12 @@ public abstract class LocalConfiguration { public String saveDir = "schematics"; public String scriptsDir = "craftscripts"; public boolean showFirstUseVersion = true; - + /** * Loads the configuration. */ public abstract void load(); - + /** * Get the working directory to work from. * diff --git a/src/main/java/com/sk89q/worldedit/LocalPlayer.java b/src/main/java/com/sk89q/worldedit/LocalPlayer.java index 26f688199..7e8971c63 100644 --- a/src/main/java/com/sk89q/worldedit/LocalPlayer.java +++ b/src/main/java/com/sk89q/worldedit/LocalPlayer.java @@ -322,6 +322,7 @@ public abstract class LocalPlayer { TargetBlock tb = new TargetBlock(this, range, 0.2); return (useLastBlock ? tb.getAnyTargetBlockFace() : tb.getTargetBlockFace()); } + /** * Get the point of the block being looked at. May return null. * @@ -556,7 +557,7 @@ public abstract class LocalPlayer { * @param pos */ public void setPosition(Vector pos) { - setPosition(pos, (float)getPitch(), (float)getYaw()); + setPosition(pos, (float) getPitch(), (float) getYaw()); } /** @@ -637,7 +638,7 @@ public abstract class LocalPlayer { if (!(other instanceof LocalPlayer)) { return false; } - LocalPlayer other2 = (LocalPlayer)other; + LocalPlayer other2 = (LocalPlayer) other; return other2.getName().equals(getName()); } @@ -652,8 +653,8 @@ public abstract class LocalPlayer { } public void checkPermission(String permission) throws WorldEditPermissionException { - if (!hasPermission(permission)) { - throw new WorldEditPermissionException(); - } + if (!hasPermission(permission)) { + throw new WorldEditPermissionException(); + } } } diff --git a/src/main/java/com/sk89q/worldedit/LocalSession.java b/src/main/java/com/sk89q/worldedit/LocalSession.java index 9a2f05fd1..cf563c984 100644 --- a/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -75,7 +75,6 @@ public class LocalSession { private boolean fastMode = false; private Mask mask; private TimeZone timezone = TimeZone.getDefault(); - //private Boolean jumptoBlock = true; /** * Construct the object. @@ -165,7 +164,7 @@ public class LocalSession { if (historyPointer < history.size()) { EditSession editSession = history.get(historyPointer); EditSession newEditSession = - new EditSession(editSession.getWorld(), -1, newBlockBag); + new EditSession(editSession.getWorld(), -1, newBlockBag); newEditSession.enableQueue(); newEditSession.setFastMode(fastMode); editSession.redo(newEditSession); @@ -465,7 +464,7 @@ public class LocalSession { setTool(item, tool); } - return (BrushTool)tool; + return (BrushTool) tool; } /** diff --git a/src/main/java/com/sk89q/worldedit/LocalWorld.java b/src/main/java/com/sk89q/worldedit/LocalWorld.java index 7a1c4a1ff..6002d2377 100644 --- a/src/main/java/com/sk89q/worldedit/LocalWorld.java +++ b/src/main/java/com/sk89q/worldedit/LocalWorld.java @@ -35,7 +35,7 @@ public abstract class LocalWorld { * Random generator. */ protected Random random = new Random(); - + /** * Get the name of the world. * @@ -129,7 +129,7 @@ public abstract class LocalWorld { * @return */ public abstract int getBlockLightLevel(Vector pt); - + /** * Regenerate an area. * @@ -248,10 +248,16 @@ public abstract class LocalWorld { */ public void simulateBlockMine(Vector pt) { BaseItemStack stack = BlockType.getBlockDrop(getBlockType(pt), (short) getBlockData(pt)); - if (stack != null) dropItem(pt, - stack.getAmount() > 1 ? new BaseItemStack(stack.getType(), - 1, stack.getDamage()) : stack, stack.getAmount()); + if (stack == null) { + return; + } + final int amount = stack.getAmount(); + if (amount > 1) { + dropItem(pt, new BaseItemStack(stack.getType(), 1, stack.getDamage()), amount); + } else { + dropItem(pt, stack, amount); + } } /** @@ -282,7 +288,7 @@ public abstract class LocalWorld { * @return */ public abstract int removeEntities(EntityType type, Vector origin, int radius); - + /** * Returns whether a block has a valid ID. * @@ -298,7 +304,8 @@ public abstract class LocalWorld { * * @param pt Position to check */ - public void checkLoadedChunk(Vector pt) {} + public void checkLoadedChunk(Vector pt) { + } /** * Compare if the other world is equal. @@ -331,7 +338,9 @@ public abstract class LocalWorld { * * @param chunks the chunks to fix */ - public void fixAfterFastMode(Iterable chunks) {} + public void fixAfterFastMode(Iterable chunks) { + } - public void fixLighting(Iterable chunks) {} + public void fixLighting(Iterable chunks) { + } } diff --git a/src/main/java/com/sk89q/worldedit/PlayerDirection.java b/src/main/java/com/sk89q/worldedit/PlayerDirection.java index 7d8205642..e7a54412d 100644 --- a/src/main/java/com/sk89q/worldedit/PlayerDirection.java +++ b/src/main/java/com/sk89q/worldedit/PlayerDirection.java @@ -33,27 +33,27 @@ public enum PlayerDirection { NORTH_WEST((new Vector(-1, 0, 1)).normalize(), (new Vector(1, 0, 1)).normalize(), false), UP(new Vector(0, 1, 0), new Vector(0, 0, 1), true), DOWN(new Vector(0, -1, 0), new Vector(0, 0, 1), true); - + private Vector dir; private Vector leftDir; private boolean isOrthogonal; - + PlayerDirection(Vector vec, Vector leftDir, boolean isOrthogonal) { this.dir = vec; this.leftDir = leftDir; this.isOrthogonal = isOrthogonal; } - + public Vector vector() { return dir; } - + @Deprecated public Vector leftVector() { return leftDir; } - + public boolean isOrthogonal() { return isOrthogonal; } -} \ No newline at end of file +} diff --git a/src/main/java/com/sk89q/worldedit/SessionCheck.java b/src/main/java/com/sk89q/worldedit/SessionCheck.java index 38ed81cbe..241724fe0 100644 --- a/src/main/java/com/sk89q/worldedit/SessionCheck.java +++ b/src/main/java/com/sk89q/worldedit/SessionCheck.java @@ -25,7 +25,7 @@ package com.sk89q.worldedit; * @author sk89q */ public interface SessionCheck { - + /** * Checks if a player is online. * @@ -33,5 +33,5 @@ public interface SessionCheck { * @return */ public boolean isOnlinePlayer(String name); - + } diff --git a/src/main/java/com/sk89q/worldedit/Vector.java b/src/main/java/com/sk89q/worldedit/Vector.java index 758de2ade..45e28c70d 100644 --- a/src/main/java/com/sk89q/worldedit/Vector.java +++ b/src/main/java/com/sk89q/worldedit/Vector.java @@ -47,9 +47,9 @@ public class Vector { * @param z */ public Vector(int x, int y, int z) { - this.x = (double)x; - this.y = (double)y; - this.z = (double)z; + this.x = (double) x; + this.y = (double) y; + this.z = (double) z; } /** @@ -60,9 +60,9 @@ public class Vector { * @param z */ public Vector(float x, float y, float z) { - this.x = (double)x; - this.y = (double)y; - this.z = (double)z; + this.x = (double) x; + this.y = (double) y; + this.z = (double) z; } /** @@ -96,7 +96,7 @@ public class Vector { * @return the x */ public int getBlockX() { - return (int)Math.round(x); + return (int) Math.round(x); } /** @@ -130,7 +130,7 @@ public class Vector { * @return the y */ public int getBlockY() { - return (int)Math.round(y); + return (int) Math.round(y); } /** @@ -164,7 +164,7 @@ public class Vector { * @return the z */ public int getBlockZ() { - return (int)Math.round(z); + return (int) Math.round(z); } /** @@ -227,7 +227,7 @@ public class Vector { * @param others * @return New point */ - public Vector add(Vector ... others) { + public Vector add(Vector... others) { double newX = x, newY = y, newZ = z; for (int i = 0; i < others.length; ++i) { @@ -278,7 +278,7 @@ public class Vector { * @param others * @return New point */ - public Vector subtract(Vector ... others) { + public Vector subtract(Vector... others) { double newX = x, newY = y, newZ = z; for (int i = 0; i < others.length; ++i) { @@ -329,7 +329,7 @@ public class Vector { * @param others * @return New point */ - public Vector multiply(Vector ... others) { + public Vector multiply(Vector... others) { double newX = x, newY = y, newZ = z; for (int i = 0; i < others.length; ++i) { @@ -546,9 +546,9 @@ public class Vector { * @return point */ public static Vector toBlockPoint(double x, double y, double z) { - return new Vector((int)Math.floor(x), - (int)Math.floor(y), - (int)Math.floor(z)); + return new Vector((int) Math.floor(x), + (int) Math.floor(y), + (int) Math.floor(z)); } /** @@ -557,9 +557,9 @@ public class Vector { * @return point */ public BlockVector toBlockPoint() { - return new BlockVector((int)Math.floor(x), - (int)Math.floor(y), - (int)Math.floor(z)); + return new BlockVector((int) Math.floor(x), + (int) Math.floor(y), + (int) Math.floor(z)); } /** diff --git a/src/main/java/com/sk89q/worldedit/Vector2D.java b/src/main/java/com/sk89q/worldedit/Vector2D.java index 88dd45bd8..78f18f72e 100644 --- a/src/main/java/com/sk89q/worldedit/Vector2D.java +++ b/src/main/java/com/sk89q/worldedit/Vector2D.java @@ -44,8 +44,8 @@ public class Vector2D { * @param z */ public Vector2D(int x, int z) { - this.x = (double)x; - this.z = (double)z; + this.x = (double) x; + this.z = (double) z; } /** @@ -55,8 +55,8 @@ public class Vector2D { * @param z */ public Vector2D(float x, float z) { - this.x = (double)x; - this.z = (double)z; + this.x = (double) x; + this.z = (double) z; } /** diff --git a/src/main/java/com/sk89q/worldedit/WorldEdit.java b/src/main/java/com/sk89q/worldedit/WorldEdit.java index ed32374d7..54b9a44f0 100644 --- a/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -53,27 +53,27 @@ public class WorldEdit { * Logger for debugging. */ public static final Logger logger = Logger.getLogger("Minecraft.WorldEdit"); - + /** * Holds WorldEdit's version. */ private static String version; - + /** * Interface to the server. */ private ServerInterface server; - + /** * Configuration. This is a subclass. */ private LocalConfiguration config; - + /** * List of commands. */ private CommandsManager commands; - + /** * Stores a list of WorldEdit sessions, keyed by players' names. Sessions * persist only for the user's session. On disconnect, the session will be @@ -81,15 +81,15 @@ public class WorldEdit { * without any WorldEdit abilities or never use WorldEdit in a session will * not have a session object generated for them. */ - private HashMap sessions = new HashMap(); - + private HashMap sessions = new HashMap(); + /** * Initialize statically. */ static { getVersion(); } - + /** * Construct an instance of the plugin * @@ -99,13 +99,13 @@ public class WorldEdit { public WorldEdit(ServerInterface server, final LocalConfiguration config) { this.server = server; this.config = config; - + commands = new CommandsManager() { @Override public boolean hasPermission(LocalPlayer player, String perm) { return player.hasPermission(perm); } - + @Override public void invokeMethod(Method parent, String[] args, LocalPlayer player, Method method, Object instance, @@ -135,20 +135,20 @@ public class WorldEdit { /* FALL-THROUGH */ case POSITION: - msg += " - Position: "+position; + msg += " - Position: " + position; break; case ALL: - msg += " - Position: "+position; + msg += " - Position: " + position; /* FALL-THROUGH */ case ORIENTATION_REGION: - msg += " - Orientation: "+player.getCardinalDirection().name(); + msg += " - Orientation: " + player.getCardinalDirection().name(); /* FALL-THROUGH */ case REGION: try { - msg += " - Region: "+session.getSelection(player.getWorld()); + msg += " - Region: " + session.getSelection(player.getWorld()); } catch (IncompleteRegionException e) { break; } @@ -194,20 +194,20 @@ public class WorldEdit { */ public LocalSession getSession(LocalPlayer player) { LocalSession session; - + synchronized (sessions) { if (sessions.containsKey(player.getName())) { return sessions.get(player.getName()); } - + session = new LocalSession(config); - + // Set the limit on the number of blocks that an operation can // change at once, or don't if the player has an override or there // is no limit. There is also a default limit if (!player.hasPermission("worldedit.limit.unrestricted") && config.maxChangeLimit > -1) { - + // If the default limit is infinite but there is a maximum // limit, make sure to not have it be overridden if (config.defaultChangeLimit < 0) { @@ -222,17 +222,17 @@ public class WorldEdit { // No change limit or override session.setBlockChangeLimit(config.defaultChangeLimit); } - + // Have the session use inventory if it's enabled and the player // doesn't have an override session.setUseInventory(config.useInventory && (!config.useInventoryOverride || !player.hasPermission("worldedit.inventory.unrestricted"))); - + // Remember the session sessions.put(player.getName(), session); } - + return session; } @@ -274,7 +274,7 @@ public class WorldEdit { String[] typeAndData = blockAndExtraData[0].split(":", 2); String testID = typeAndData[0]; int blockId = -1; - + int data = -1; // Attempt to parse the item ID or otherwise resolve an item/block @@ -295,7 +295,7 @@ public class WorldEdit { if (blockId == -1 && blockType == null) { // Maybe it's a cloth ClothColor col = ClothColor.lookup(testID); - + if (col != null) { blockType = BlockType.CLOTH; data = col.getID(); @@ -303,16 +303,16 @@ public class WorldEdit { throw new UnknownItemException(arg); } } - + // Read block ID if (blockId == -1) { blockId = blockType.getID(); } - + if (!player.getWorld().isValidBlockType(blockId)) { throw new UnknownItemException(arg); } - + if (data == -1) { // Block data not yet detected // Parse the block data (optional) try { @@ -324,7 +324,7 @@ public class WorldEdit { switch (blockType) { case CLOTH: ClothColor col = ClothColor.lookup(typeAndData[1]); - + if (col != null) { data = col.getID(); } else { @@ -335,7 +335,7 @@ public class WorldEdit { case STEP: case DOUBLE_STEP: BlockType dataType = BlockType.lookup(typeAndData[1]); - + if (dataType != null) { switch (dataType) { case STONE: @@ -374,25 +374,24 @@ public class WorldEdit { } // Check if the item is allowed - if (allAllowed || player.hasPermission("worldedit.anyblock") - || !config.disallowedBlocks.contains(blockId)) { - - // Allow special sign text syntax - if (blockType == BlockType.SIGN_POST - || blockType == BlockType.WALL_SIGN) { + if (allAllowed || player.hasPermission("worldedit.anyblock") || !config.disallowedBlocks.contains(blockId)) { + switch (blockType) { + case SIGN_POST: + case WALL_SIGN: + // Allow special sign text syntax String[] text = new String[4]; text[0] = blockAndExtraData.length > 1 ? blockAndExtraData[1] : ""; text[1] = blockAndExtraData.length > 2 ? blockAndExtraData[2] : ""; text[2] = blockAndExtraData.length > 3 ? blockAndExtraData[3] : ""; text[3] = blockAndExtraData.length > 4 ? blockAndExtraData[4] : ""; return new SignBlock(blockType.getID(), data, text); - - // Allow setting mob spawn type - } else if (blockType == BlockType.MOB_SPAWNER) { + + case MOB_SPAWNER: + // Allow setting mob spawn type if (blockAndExtraData.length > 1) { String mobName = blockAndExtraData[1]; - for (MobType mobType : MobType.values()){ - if (mobType.getName().toLowerCase().equals(mobName.toLowerCase())){ + for (MobType mobType : MobType.values()) { + if (mobType.getName().toLowerCase().equals(mobName.toLowerCase())) { mobName = mobType.getName(); break; } @@ -404,9 +403,9 @@ public class WorldEdit { } else { return new MobSpawnerBlock(data, MobType.PIG.getName()); } - - // Allow setting note - } else if (blockType == BlockType.NOTE_BLOCK) { + + case NOTE_BLOCK: + // Allow setting note if (blockAndExtraData.length > 1) { byte note = Byte.parseByte(blockAndExtraData[1]); if (note < 0 || note > 24) { @@ -415,11 +414,12 @@ public class WorldEdit { return new NoteBlock(data, note); } } else { - return new NoteBlock(data, (byte)0); + return new NoteBlock(data, (byte) 0); } - } - return new BaseBlock(blockId, data); + default: + return new BaseBlock(blockId, data); + } } throw new DisallowedItemException(arg); @@ -439,7 +439,7 @@ public class WorldEdit { return getBlock(player, id, false); } - public Set getBlocks (LocalPlayer player, String list, boolean allAllowed, boolean allowNoData) + public Set getBlocks(LocalPlayer player, String list, boolean allAllowed, boolean allowNoData) throws DisallowedItemException, UnknownItemException { String[] items = list.split(","); Set blocks = new HashSet(); @@ -473,20 +473,20 @@ public class WorldEdit { throws UnknownItemException, DisallowedItemException { String[] items = patternString.split(","); - + // Handle special block pattern types if (patternString.charAt(0) == '#') { if (patternString.equals("#clipboard") || patternString.equals("#copy")) { LocalSession session = getSession(player); CuboidClipboard clipboard; - + try { clipboard = session.getClipboard(); } catch (EmptyClipboardException e) { player.printError("Copy a selection first with //copy."); throw new UnknownItemException("#clipboard"); } - + return new ClipboardPattern(clipboard); } else { throw new UnknownItemException(patternString); @@ -502,9 +502,9 @@ public class WorldEdit { for (String s : items) { BaseBlock block; - + double chance; - + // Parse special percentage syntax if (s.matches("[0-9]+(?:\\.(?:[0-9]+)?)?%.*")) { String[] p = s.split("%"); @@ -514,22 +514,22 @@ public class WorldEdit { chance = 1; block = getBlock(player, s); } - + blockChances.add(new BlockChance(block, chance)); } return new RandomFillPattern(blockChances); } - - /** + + /** * Get a block mask. Block masks are used to determine which * blocks to include when replacing. - * + * * @param player * @param session * @param maskString * @return - * @throws WorldEditException + * @throws WorldEditException */ public Mask getBlockMask(LocalPlayer player, LocalSession session, String maskString) throws WorldEditException { @@ -622,7 +622,7 @@ public class WorldEdit { public Set getBlockIDs(LocalPlayer player, String list, boolean allBlocksAllowed) throws UnknownItemException, DisallowedItemException { - + String[] items = list.split(","); Set blocks = new HashSet(); for (String s : items) { @@ -630,7 +630,7 @@ public class WorldEdit { } return blocks; } - + /** * Gets the path to a file. This method will check to see if the filename * has valid characters and has an extension. It also prevents directory @@ -650,7 +650,7 @@ public class WorldEdit { throws FilenameException { return getSafeFile(player, dir, filename, defaultExt, extensions, true); } - + /** * Gets the path to a file. This method will check to see if the filename * has valid characters and has an extension. It also prevents directory @@ -670,7 +670,7 @@ public class WorldEdit { throws FilenameException { return getSafeFile(player, dir, filename, defaultExt, extensions, false); } - + /** * Get a safe path to a file. * @@ -687,14 +687,14 @@ public class WorldEdit { String defaultExt, String[] extensions, boolean isSave) throws FilenameException { File f; - + if (filename.equals("#")) { if (isSave) { f = player.openFileSaveDialog(extensions); } else { f = player.openFileOpenDialog(extensions); } - + if (f == null) { throw new FileSelectionAbortedException("No file selected"); } @@ -702,11 +702,11 @@ public class WorldEdit { if (defaultExt != null && filename.lastIndexOf('.') == -1) { filename += "." + defaultExt; } - + if (!filename.matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+\\.[A-Za-z0-9]+$")) { throw new InvalidFilenameException(filename, "Invalid characters or extension missing"); } - + f = new File(dir, filename); } @@ -718,7 +718,7 @@ public class WorldEdit { throw new FilenameResolutionException(filename, "Path is outside allowable root"); } - + return f; } catch (IOException e) { throw new FilenameResolutionException(filename, @@ -737,7 +737,7 @@ public class WorldEdit { throw new MaxRadiusException(); } } - + /** * Get a file relative to the defined working directory. If the specified * path is absolute, then the working directory is not used. @@ -793,7 +793,7 @@ public class WorldEdit { default: throw new UnknownDirectionException(dir.name()); } -} + } private PlayerDirection getPlayerDirection(LocalPlayer player, String dirStr) throws UnknownDirectionException { final PlayerDirection dir; @@ -859,7 +859,7 @@ public class WorldEdit { } return dir; } - + /** * Get diagonal direction vector for a player's direction. May return * null if a direction could not be found. @@ -870,7 +870,7 @@ public class WorldEdit { * @throws UnknownDirectionException */ public Vector getDiagonalDirection(LocalPlayer player, String dirStr) - throws UnknownDirectionException { + throws UnknownDirectionException { return getPlayerDirection(player, dirStr.toLowerCase()).vector(); } @@ -924,7 +924,7 @@ public class WorldEdit { sessions.clear(); } } - + /** * Flush a block bag's changes to a player. * @@ -933,35 +933,35 @@ public class WorldEdit { */ public void flushBlockBag(LocalPlayer player, EditSession editSession) { - + BlockBag blockBag = editSession.getBlockBag(); - + if (blockBag != null) { blockBag.flushChanges(); } - + Set missingBlocks = editSession.popMissingBlocks(); - + if (missingBlocks.size() > 0) { StringBuilder str = new StringBuilder(); str.append("Missing these blocks: "); int size = missingBlocks.size(); int i = 0; - + for (Integer id : missingBlocks) { BlockType type = BlockType.fromID(id); - + str.append(type != null ? type.getName() + " (" + id + ")" : id.toString()); - + ++i; - + if (i != size) { str.append(", "); } } - + player.printError(str.toString()); } } @@ -972,7 +972,7 @@ public class WorldEdit { public Map getCommands() { return commands.getCommands(); } - + /** * * @param player @@ -981,7 +981,7 @@ public class WorldEdit { public void handleDisconnect(LocalPlayer player) { forgetPlayer(player); } - + /** * * @param player @@ -994,7 +994,7 @@ public class WorldEdit { } } } - + /** * Forget a player. * @@ -1003,14 +1003,14 @@ public class WorldEdit { public void forgetPlayer(LocalPlayer player) { removeSession(player); } - + /* * Flush expired sessions. */ public void flushExpiredSessions(SessionCheck checker) { synchronized (sessions) { Iterator> it = sessions.entrySet().iterator(); - + while (it.hasNext()) { Map.Entry entry = it.next(); if (entry.getValue().hasExpired() @@ -1127,7 +1127,7 @@ public class WorldEdit { Tool tool = session.getTool(player.getItemInHand()); if (tool != null && tool instanceof BlockTool) { if (tool.canUse(player)) { - ((BlockTool)tool).actPrimary(server, config, player, session, clicked); + ((BlockTool) tool).actPrimary(server, config, player, session, clicked); return true; } } @@ -1172,7 +1172,7 @@ public class WorldEdit { Tool tool = session.getTool(player.getItemInHand()); if (tool != null && tool instanceof DoubleActionBlockTool) { if (tool.canUse(player)) { - ((DoubleActionBlockTool)tool).actSecondary(server, config, player, session, clicked); + ((DoubleActionBlockTool) tool).actSecondary(server, config, player, session, clicked); return true; } } @@ -1191,7 +1191,7 @@ public class WorldEdit { public boolean handleCommand(LocalPlayer player, String[] split) { try { split[0] = split[0].substring(1); - + // Quick script shortcut if (split[0].matches("^[^/].*\\.js$")) { String[] newSplit = new String[split.length + 1]; @@ -1200,9 +1200,9 @@ public class WorldEdit { newSplit[1] = newSplit[1]; split = newSplit; } - + String searchCmd = split[0].toLowerCase(); - + // Try to detect the command if (commands.hasCommand(searchCmd)) { } else if (config.noDoubleSlash && commands.hasCommand("/" + searchCmd)) { @@ -1211,12 +1211,12 @@ public class WorldEdit { && commands.hasCommand(searchCmd.substring(1))) { split[0] = split[0].substring(1); } - + // No command found! if (!commands.hasCommand(split[0])) { return false; } - + LocalSession session = getSession(player); EditSession editSession = session.createEditSession(player); editSession.enableQueue(); @@ -1254,14 +1254,14 @@ public class WorldEdit { player.printDebug((time / 1000.0) + "s elapsed."); } } - + flushBlockBag(player, editSession); } } catch (NumberFormatException e) { final Matcher matcher = numberFormatExceptionPattern.matcher(e.getMessage()); if (matcher.matches()) { - player.printError("Number expected; string \""+matcher.group(1)+"\" given."); + player.printError("Number expected; string \"" + matcher.group(1) + "\" given."); } else { player.printError("Number expected; string given."); } @@ -1305,7 +1305,7 @@ public class WorldEdit { return true; } - + /** * Executes a WorldEdit script. * @@ -1316,24 +1316,24 @@ public class WorldEdit { */ public void runScript(LocalPlayer player, File f, String[] args) throws WorldEditException { - String filename = f.getPath(); + String filename = f.getPath(); int index = filename.lastIndexOf("."); String ext = filename.substring(index + 1, filename.length()); - + if (!ext.equalsIgnoreCase("js")) { player.printError("Only .js scripts are currently supported"); return; } - + String script; - + try { InputStream file; - + if (!f.exists()) { file = WorldEdit.class.getResourceAsStream( "craftscripts/" + filename); - + if (file == null) { player.printError("Script does not exist: " + filename); return; @@ -1341,7 +1341,7 @@ public class WorldEdit { } else { file = new FileInputStream(f); } - + DataInputStream in = new DataInputStream(file); byte[] data = new byte[in.available()]; in.readFully(data); @@ -1351,11 +1351,11 @@ public class WorldEdit { player.printError("Script read error: " + e.getMessage()); return; } - + LocalSession session = getSession(player); CraftScriptContext scriptContext = new CraftScriptContext(this, server, config, session, player, args); - + CraftScriptEngine engine = null; try { @@ -1365,18 +1365,18 @@ public class WorldEdit { player.printError("Please see http://wiki.sk89q.com/wiki/WorldEdit/Installation"); return; } - + engine.setTimeLimit(config.scriptTimeout); - + Map vars = new HashMap(); vars.put("argv", args); vars.put("context", scriptContext); vars.put("player", player); - + try { engine.evaluate(script, filename, vars); } catch (ScriptException e) { - player.printError("Failed to execute:");; + player.printError("Failed to execute:"); player.printRaw(e.getMessage()); e.printStackTrace(); } catch (NumberFormatException e) { @@ -1394,7 +1394,7 @@ public class WorldEdit { } } } - + /** * Get Worldedit's configuration. * @@ -1403,7 +1403,7 @@ public class WorldEdit { public LocalConfiguration getConfiguration() { return config; } - + /** * Get the server interface. * @@ -1422,18 +1422,18 @@ public class WorldEdit { if (version != null) { return version; } - + Package p = WorldEdit.class.getPackage(); - + if (p == null) { p = Package.getPackage("com.sk89q.worldedit"); } - + if (p == null) { version = "(unknown)"; } else { version = p.getImplementationVersion(); - + if (version == null) { version = "(unknown)"; } diff --git a/src/main/java/com/sk89q/worldedit/WorldVector.java b/src/main/java/com/sk89q/worldedit/WorldVector.java index 97101f980..c51f4ba48 100644 --- a/src/main/java/com/sk89q/worldedit/WorldVector.java +++ b/src/main/java/com/sk89q/worldedit/WorldVector.java @@ -28,7 +28,7 @@ public class WorldVector extends Vector { /** * Represents the world. */ - private LocalWorld world; + private LocalWorld world; /** * Construct the Vector object. @@ -89,7 +89,7 @@ public class WorldVector extends Vector { super(); this.world = world; } - + /** * Get the world. * @@ -110,9 +110,9 @@ public class WorldVector extends Vector { */ public static WorldVector toBlockPoint(LocalWorld world, double x, double y, double z) { - return new WorldVector(world, (int)Math.floor(x), - (int)Math.floor(y), - (int)Math.floor(z)); + return new WorldVector(world, (int) Math.floor(x), + (int) Math.floor(y), + (int) Math.floor(z)); } /** diff --git a/src/main/java/com/sk89q/worldedit/WorldVector2D.java b/src/main/java/com/sk89q/worldedit/WorldVector2D.java index 99aa60e54..7a52fca09 100644 --- a/src/main/java/com/sk89q/worldedit/WorldVector2D.java +++ b/src/main/java/com/sk89q/worldedit/WorldVector2D.java @@ -80,7 +80,7 @@ public class WorldVector2D extends Vector2D { @Override public int hashCode() { return (world.hashCode() >> 7) ^ - ((int)(Double.doubleToLongBits(x)^(Double.doubleToLongBits(x)>>>32)) >> 13) ^ - (int)(Double.doubleToLongBits(z)^(Double.doubleToLongBits(z)>>>32)); + ((int) (Double.doubleToLongBits(x) ^ (Double.doubleToLongBits(x) >>> 32)) >> 13) ^ + (int) (Double.doubleToLongBits(z) ^ (Double.doubleToLongBits(z) >>> 32)); } } diff --git a/src/main/java/com/sk89q/worldedit/bags/BlockBag.java b/src/main/java/com/sk89q/worldedit/bags/BlockBag.java index fa9e38407..7506b92f0 100644 --- a/src/main/java/com/sk89q/worldedit/bags/BlockBag.java +++ b/src/main/java/com/sk89q/worldedit/bags/BlockBag.java @@ -40,7 +40,7 @@ public abstract class BlockBag { public void storeDroppedBlock(int id) throws BlockBagException { storeDroppedBlock(id, 0); } - + /** * Stores a block as if it was mined. * @@ -55,7 +55,7 @@ public abstract class BlockBag { storeItem(dropped); } - + /** * Sets a block as if it was placed by hand. * @@ -149,7 +149,7 @@ public abstract class BlockBag { public void storeBlock(int id) throws BlockBagException { storeItem(new BaseItem(id)); } - + /** * Store a block. * @@ -161,7 +161,7 @@ public abstract class BlockBag { public void storeItem(BaseItem item) throws BlockBagException { storeBlock(item.getType()); } - + /** * Checks to see if a block exists without removing it. * @@ -177,7 +177,7 @@ public abstract class BlockBag { return false; } } - + /** * Flush any changes. This is called at the end. */ @@ -189,6 +189,7 @@ public abstract class BlockBag { * @param pos */ public abstract void addSourcePosition(Vector pos); + /** * Adds a position to be used a source. * diff --git a/src/main/java/com/sk89q/worldedit/bags/OutOfSpaceException.java b/src/main/java/com/sk89q/worldedit/bags/OutOfSpaceException.java index 09e13ea0f..32eaf280e 100644 --- a/src/main/java/com/sk89q/worldedit/bags/OutOfSpaceException.java +++ b/src/main/java/com/sk89q/worldedit/bags/OutOfSpaceException.java @@ -25,7 +25,7 @@ package com.sk89q.worldedit.bags; */ public class OutOfSpaceException extends BlockBagException { private static final long serialVersionUID = -2962840237632916821L; - + /** * Stores the block ID. */ diff --git a/src/main/java/com/sk89q/worldedit/bags/UnplaceableBlockException.java b/src/main/java/com/sk89q/worldedit/bags/UnplaceableBlockException.java index 72f6fd597..04b271043 100644 --- a/src/main/java/com/sk89q/worldedit/bags/UnplaceableBlockException.java +++ b/src/main/java/com/sk89q/worldedit/bags/UnplaceableBlockException.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit.bags; - /** * * @author sk89q diff --git a/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java b/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java index d35db279a..9ab1b2e88 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java +++ b/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java @@ -74,7 +74,7 @@ public class BaseBlock { * @return the data */ public int getData() { - return (int)data; + return (int) data; } /** @@ -130,6 +130,7 @@ public class BaseBlock { data = (byte) BlockData.flip(type, data); return this; } + /** * Flip this block. * @param direction diff --git a/src/main/java/com/sk89q/worldedit/blocks/BaseItemStack.java b/src/main/java/com/sk89q/worldedit/blocks/BaseItemStack.java index 2215bee9d..fc28be5f8 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/BaseItemStack.java +++ b/src/main/java/com/sk89q/worldedit/blocks/BaseItemStack.java @@ -61,7 +61,7 @@ public class BaseItemStack extends BaseItem { super(id, damage); this.amount = amount; } - + /** * @return the amount */ diff --git a/src/main/java/com/sk89q/worldedit/blocks/BlockData.java b/src/main/java/com/sk89q/worldedit/blocks/BlockData.java index 68f2860cb..aff99cc8f 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/BlockData.java +++ b/src/main/java/com/sk89q/worldedit/blocks/BlockData.java @@ -721,7 +721,7 @@ public final class BlockData { case ClothColor.ID.MAGENTA: return ClothColor.ID.PINK; case ClothColor.ID.PINK: return ClothColor.ID.WHITE; } - + return ClothColor.ID.WHITE; } @@ -750,7 +750,7 @@ public final class BlockData { case ClothColor.ID.PINK: return ClothColor.ID.MAGENTA; case ClothColor.ID.WHITE: return ClothColor.ID.PINK; } - + return ClothColor.ID.WHITE; } } diff --git a/src/main/java/com/sk89q/worldedit/blocks/BlockType.java b/src/main/java/com/sk89q/worldedit/blocks/BlockType.java index 4c163e19b..0f2b2b22d 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/BlockType.java +++ b/src/main/java/com/sk89q/worldedit/blocks/BlockType.java @@ -146,7 +146,7 @@ public enum BlockType { FENCE_GATE(BlockID.FENCE_GATE, "Fence gate", "fencegate", "gate"), BRICK_STAIRS(BlockID.BRICK_STAIRS, "Brick stairs", "brickstairs", "bricksteps"), STONE_BRICK_STAIRS(BlockID.STONE_BRICK_STAIRS, "Stone brick stairs", "stonebrickstairs", "smoothstonebrickstairs"), - MYCELIUM(BlockID.MYCELIUM, "Mycelium", "fungus" ,"mycel"), + MYCELIUM(BlockID.MYCELIUM, "Mycelium", "fungus", "mycel"), LILY_PAD(BlockID.LILY_PAD, "Lily pad", "lilypad", "waterlily"), NETHER_BRICK(BlockID.NETHER_BRICK, "Nether brick", "netherbrick"), NETHER_BRICK_FENCE(BlockID.NETHER_BRICK_FENCE, "Nether brick fence", "netherbrickfence", "netherfence"), @@ -162,18 +162,18 @@ public enum BlockType { /** * Stores a map of the IDs for fast access. */ - private static final Map ids = new HashMap(); + private static final Map ids = new HashMap(); /** * Stores a map of the names for fast access. */ - private static final Map lookup = new HashMap(); + private static final Map lookup = new HashMap(); private final int id; private final String name; private final String[] lookupKeys; static { - for(BlockType type : EnumSet.allOf(BlockType.class)) { + for (BlockType type : EnumSet.allOf(BlockType.class)) { ids.put(type.id, type); for (String key : type.lookupKeys) { lookup.put(key, type); @@ -200,7 +200,7 @@ public enum BlockType { * @param id * @param name */ - BlockType(int id, String name, String ... lookupKeys) { + BlockType(int id, String name, String... lookupKeys) { this.id = id; this.name = name; this.lookupKeys = lookupKeys; @@ -947,7 +947,7 @@ public enum BlockType { addIdentity(BlockID.STONE_PRESSURE_PLATE); // rule 1 addIdentities(BlockID.IRON_DOOR, 8); // rule 2 addIdentity(BlockID.WOODEN_PRESSURE_PLATE); // rule 1 - addIdentity(BlockID.REDSTONE_ORE); // rule 4 + addIdentity(BlockID.REDSTONE_ORE); // rule 4 nonDataBlockBagItems.put(BlockID.GLOWING_REDSTONE_ORE, new BaseItem(BlockID.REDSTONE_ORE)); // rule 4 nonDataBlockBagItems.put(BlockID.REDSTONE_TORCH_OFF, new BaseItem(BlockID.REDSTONE_TORCH_ON)); // rule 3 addIdentity(BlockID.REDSTONE_TORCH_ON); // rule 1 @@ -1029,7 +1029,7 @@ public enum BlockType { private static void addIdentity(int type) { nonDataBlockBagItems.put(type, new BaseItem(type)); } - + private static void addIdentities(int type, int maxData) { for (int data = 0; data < maxData; ++data) { dataBlockBagItems.put(typeDataKey(type, data), new BaseItem(type, (short) data)); diff --git a/src/main/java/com/sk89q/worldedit/blocks/ChestBlock.java b/src/main/java/com/sk89q/worldedit/blocks/ChestBlock.java index c88e7ab07..ba7f28753 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/ChestBlock.java +++ b/src/main/java/com/sk89q/worldedit/blocks/ChestBlock.java @@ -97,22 +97,22 @@ public class ChestBlock extends BaseBlock implements TileEntityBlock, ContainerB * @return map of values * @throws DataException */ - public Map toTileEntityNBT() + public Map toTileEntityNBT() throws DataException { List itemsList = new ArrayList(); for (int i = 0; i < items.length; ++i) { BaseItemStack item = items[i]; if (item != null) { - Map data = new HashMap(); + Map data = new HashMap(); CompoundTag itemTag = new CompoundTag("Items", data); - data.put("id", new ShortTag("id", (short)item.getType())); + data.put("id", new ShortTag("id", (short) item.getType())); data.put("Damage", new ShortTag("Damage", item.getDamage())); - data.put("Count", new ByteTag("Count", (byte)item.getAmount())); - data.put("Slot", new ByteTag("Slot", (byte)i)); + data.put("Count", new ByteTag("Count", (byte) item.getAmount())); + data.put("Slot", new ByteTag("Slot", (byte) i)); itemsList.add(itemTag); } } - Map values = new HashMap(); + Map values = new HashMap(); values.put("Items", new ListTag("Items", CompoundTag.class, itemsList)); return values; } @@ -123,19 +123,18 @@ public class ChestBlock extends BaseBlock implements TileEntityBlock, ContainerB * @param values * @throws DataException */ - public void fromTileEntityNBT(Map values) - throws DataException { + public void fromTileEntityNBT(Map values) + throws DataException { if (values == null) { return; } - Tag t = values.get("id"); - if (!(t instanceof StringTag) || !((StringTag)t).getValue().equals("Chest")) { + if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Chest")) { throw new DataException("'Chest' tile entity expected"); } - ListTag items = (ListTag)Chunk.getChildTag(values, "Items", ListTag.class); + ListTag items = (ListTag) Chunk.getChildTag(values, "Items", ListTag.class); BaseItemStack[] newItems = new BaseItemStack[27]; for (Tag tag : items.getValue()) { @@ -143,16 +142,16 @@ public class ChestBlock extends BaseBlock implements TileEntityBlock, ContainerB throw new DataException("CompoundTag expected as child tag of Chest's Items"); } - CompoundTag item = (CompoundTag)tag; - Map itemValues = item.getValue(); + CompoundTag item = (CompoundTag) tag; + Map itemValues = item.getValue(); - short id = (Short)((ShortTag)Chunk.getChildTag(itemValues, "id", ShortTag.class)) + short id = (Short) ((ShortTag) Chunk.getChildTag(itemValues, "id", ShortTag.class)) .getValue(); - short damage = (Short)((ShortTag)Chunk.getChildTag(itemValues, "Damage", ShortTag.class)) + short damage = (Short) ((ShortTag) Chunk.getChildTag(itemValues, "Damage", ShortTag.class)) .getValue(); - byte count = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Count", ByteTag.class)) + byte count = (Byte) ((ByteTag) Chunk.getChildTag(itemValues, "Count", ByteTag.class)) .getValue(); - byte slot = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Slot", ByteTag.class)) + byte slot = (Byte) ((ByteTag) Chunk.getChildTag(itemValues, "Slot", ByteTag.class)) .getValue(); if (slot >= 0 && slot <= 26) { diff --git a/src/main/java/com/sk89q/worldedit/blocks/ClothColor.java b/src/main/java/com/sk89q/worldedit/blocks/ClothColor.java index 1a0e90dad..e1445429d 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/ClothColor.java +++ b/src/main/java/com/sk89q/worldedit/blocks/ClothColor.java @@ -35,14 +35,14 @@ public enum ClothColor { LIGHT_BLUE(ID.LIGHT_BLUE, "Light blue", "lightblue"), YELLOW(ID.YELLOW, "Yellow", "yellow"), LIGHT_GREEN(ID.LIGHT_GREEN, "Light green", "lightgreen"), - PINK(ID.PINK, "Pink", new String[] {"pink", "lightred"}), - GRAY(ID.GRAY, "Gray", new String[] {"grey", "gray"}), - LIGHT_GRAY(ID.LIGHT_GRAY, "Light gray", new String[] {"lightgrey", "lightgray"}), - CYAN(ID.CYAN, "Cyan", new String[] {"cyan", "turquoise"}), - PURPLE(ID.PURPLE, "Purple", new String[] {"purple", "violet"}), + PINK(ID.PINK, "Pink", new String[] { "pink", "lightred" }), + GRAY(ID.GRAY, "Gray", new String[] { "grey", "gray" }), + LIGHT_GRAY(ID.LIGHT_GRAY, "Light gray", new String[] { "lightgrey", "lightgray" }), + CYAN(ID.CYAN, "Cyan", new String[] { "cyan", "turquoise" }), + PURPLE(ID.PURPLE, "Purple", new String[] { "purple", "violet" }), BLUE(ID.BLUE, "Blue", "blue"), - BROWN(ID.BROWN, "Brown", new String[] {"brown", "cocoa", "coffee"}), - DARK_GREEN(ID.DARK_GREEN, "Dark green", new String[] {"green", "darkgreen", "cactusgreen", "cactigreen"}), + BROWN(ID.BROWN, "Brown", new String[] { "brown", "cocoa", "coffee" }), + DARK_GREEN(ID.DARK_GREEN, "Dark green", new String[] { "green", "darkgreen", "cactusgreen", "cactigreen" }), RED(ID.RED, "Red", "red"), BLACK(ID.BLACK, "Black", "black"); @@ -68,11 +68,11 @@ public enum ClothColor { /** * Stores a map of the IDs for fast access. */ - private static final Map ids = new HashMap(); + private static final Map ids = new HashMap(); /** * Stores a map of the names for fast access. */ - private static final Map lookup = new HashMap(); + private static final Map lookup = new HashMap(); private final int id; private final String name; @@ -97,7 +97,7 @@ public enum ClothColor { ClothColor(int id, String name, String lookupKey) { this.id = id; this.name = name; - this.lookupKeys = new String[]{lookupKey}; + this.lookupKeys = new String[] { lookupKey }; } /** @@ -149,4 +149,4 @@ public enum ClothColor { public String getName() { return name; } -} \ No newline at end of file +} diff --git a/src/main/java/com/sk89q/worldedit/blocks/DispenserBlock.java b/src/main/java/com/sk89q/worldedit/blocks/DispenserBlock.java index fbfd7a772..b07a28679 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/DispenserBlock.java +++ b/src/main/java/com/sk89q/worldedit/blocks/DispenserBlock.java @@ -97,22 +97,22 @@ public class DispenserBlock extends BaseBlock implements TileEntityBlock, Contai * @return map of values * @throws DataException */ - public Map toTileEntityNBT() + public Map toTileEntityNBT() throws DataException { List itemsList = new ArrayList(); for (int i = 0; i < items.length; ++i) { BaseItemStack item = items[i]; if (item != null) { - Map data = new HashMap(); + Map data = new HashMap(); CompoundTag itemTag = new CompoundTag("Items", data); - data.put("id", new ShortTag("id", (short)item.getType())); + data.put("id", new ShortTag("id", (short) item.getType())); data.put("Damage", new ShortTag("Damage", item.getDamage())); - data.put("Count", new ByteTag("Count", (byte)item.getAmount())); - data.put("Slot", new ByteTag("Slot", (byte)i)); + data.put("Count", new ByteTag("Count", (byte) item.getAmount())); + data.put("Slot", new ByteTag("Slot", (byte) i)); itemsList.add(itemTag); } } - Map values = new HashMap(); + Map values = new HashMap(); values.put("Items", new ListTag("Items", CompoundTag.class, itemsList)); return values; } @@ -123,19 +123,18 @@ public class DispenserBlock extends BaseBlock implements TileEntityBlock, Contai * @param values * @throws DataException */ - public void fromTileEntityNBT(Map values) - throws DataException { + public void fromTileEntityNBT(Map values) + throws DataException { if (values == null) { return; } - Tag t = values.get("id"); - if (!(t instanceof StringTag) || !((StringTag)t).getValue().equals("Trap")) { + if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Trap")) { throw new DataException("'Trap' tile entity expected"); } - ListTag items = (ListTag)Chunk.getChildTag(values, "Items", ListTag.class); + ListTag items = (ListTag) Chunk.getChildTag(values, "Items", ListTag.class); BaseItemStack[] newItems = new BaseItemStack[27]; for (Tag tag : items.getValue()) { @@ -143,16 +142,16 @@ public class DispenserBlock extends BaseBlock implements TileEntityBlock, Contai throw new DataException("CompoundTag expected as child tag of Trap Items"); } - CompoundTag item = (CompoundTag)tag; - Map itemValues = item.getValue(); + CompoundTag item = (CompoundTag) tag; + Map itemValues = item.getValue(); - short id = (Short)((ShortTag)Chunk.getChildTag(itemValues, "id", ShortTag.class)) + short id = (Short) ((ShortTag) Chunk.getChildTag(itemValues, "id", ShortTag.class)) .getValue(); - short damage = (Short)((ShortTag)Chunk.getChildTag(itemValues, "Damage", ShortTag.class)) + short damage = (Short) ((ShortTag) Chunk.getChildTag(itemValues, "Damage", ShortTag.class)) .getValue(); - byte count = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Count", ByteTag.class)) + byte count = (Byte) ((ByteTag) Chunk.getChildTag(itemValues, "Count", ByteTag.class)) .getValue(); - byte slot = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Slot", ByteTag.class)) + byte slot = (Byte) ((ByteTag) Chunk.getChildTag(itemValues, "Slot", ByteTag.class)) .getValue(); if (slot >= 0 && slot <= 8) { diff --git a/src/main/java/com/sk89q/worldedit/blocks/FurnaceBlock.java b/src/main/java/com/sk89q/worldedit/blocks/FurnaceBlock.java index 506ecdae2..4ca46affc 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/FurnaceBlock.java +++ b/src/main/java/com/sk89q/worldedit/blocks/FurnaceBlock.java @@ -36,7 +36,7 @@ public class FurnaceBlock extends BaseBlock implements TileEntityBlock, Containe * Store the list of items. */ private BaseItemStack[] items; - + /** * Fuel time. */ @@ -95,7 +95,7 @@ public class FurnaceBlock extends BaseBlock implements TileEntityBlock, Containe public void setItems(BaseItemStack[] items) { this.items = items; } - + /** * @return the burnTime */ @@ -139,22 +139,22 @@ public class FurnaceBlock extends BaseBlock implements TileEntityBlock, Containe * @return map of values * @throws DataException */ - public Map toTileEntityNBT() + public Map toTileEntityNBT() throws DataException { List itemsList = new ArrayList(); for (int i = 0; i < items.length; ++i) { BaseItemStack item = items[i]; if (item != null) { - Map data = new HashMap(); + Map data = new HashMap(); CompoundTag itemTag = new CompoundTag("Items", data); - data.put("id", new ShortTag("id", (short)item.getType())); + data.put("id", new ShortTag("id", (short) item.getType())); data.put("Damage", new ShortTag("Damage", item.getDamage())); - data.put("Count", new ByteTag("Count", (byte)item.getAmount())); - data.put("Slot", new ByteTag("Slot", (byte)i)); + data.put("Count", new ByteTag("Count", (byte) item.getAmount())); + data.put("Slot", new ByteTag("Slot", (byte) i)); itemsList.add(itemTag); } } - Map values = new HashMap(); + Map values = new HashMap(); values.put("Items", new ListTag("Items", CompoundTag.class, itemsList)); values.put("BurnTime", new ShortTag("BurnTime", burnTime)); values.put("CookTime", new ShortTag("CookTime", cookTime)); @@ -167,18 +167,18 @@ public class FurnaceBlock extends BaseBlock implements TileEntityBlock, Containe * @param values * @throws DataException */ - public void fromTileEntityNBT(Map values) - throws DataException { + public void fromTileEntityNBT(Map values) + throws DataException { if (values == null) { return; } Tag t = values.get("id"); - if (!(t instanceof StringTag) || !((StringTag)t).getValue().equals("Furnace")) { + if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Furnace")) { throw new DataException("'Furnace' tile entity expected"); } - ListTag items = (ListTag)Chunk.getChildTag(values, "Items", ListTag.class); + ListTag items = (ListTag) Chunk.getChildTag(values, "Items", ListTag.class); BaseItemStack[] newItems = new BaseItemStack[27]; for (Tag tag : items.getValue()) { @@ -186,16 +186,16 @@ public class FurnaceBlock extends BaseBlock implements TileEntityBlock, Containe throw new DataException("CompoundTag expected as child tag of Trap Items"); } - CompoundTag item = (CompoundTag)tag; - Map itemValues = item.getValue(); + CompoundTag item = (CompoundTag) tag; + Map itemValues = item.getValue(); - short id = (Short)((ShortTag)Chunk.getChildTag(itemValues, "id", ShortTag.class)) + short id = (Short) ((ShortTag) Chunk.getChildTag(itemValues, "id", ShortTag.class)) .getValue(); - short damage = (Short)((ShortTag)Chunk.getChildTag(itemValues, "Damage", ShortTag.class)) + short damage = (Short) ((ShortTag) Chunk.getChildTag(itemValues, "Damage", ShortTag.class)) .getValue(); - byte count = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Count", ByteTag.class)) + byte count = (Byte) ((ByteTag) Chunk.getChildTag(itemValues, "Count", ByteTag.class)) .getValue(); - byte slot = (Byte)((ByteTag)Chunk.getChildTag(itemValues, "Slot", ByteTag.class)) + byte slot = (Byte) ((ByteTag) Chunk.getChildTag(itemValues, "Slot", ByteTag.class)) .getValue(); if (slot >= 0 && slot <= 26) { @@ -207,12 +207,12 @@ public class FurnaceBlock extends BaseBlock implements TileEntityBlock, Containe t = values.get("BurnTime"); if (t instanceof ShortTag) { - burnTime = ((ShortTag)t).getValue(); + burnTime = ((ShortTag) t).getValue(); } t = values.get("CookTime"); if (t instanceof ShortTag) { - cookTime = ((ShortTag)t).getValue(); + cookTime = ((ShortTag) t).getValue(); } } } diff --git a/src/main/java/com/sk89q/worldedit/blocks/ItemID.java b/src/main/java/com/sk89q/worldedit/blocks/ItemID.java index 5218bbd79..d7301e0aa 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/ItemID.java +++ b/src/main/java/com/sk89q/worldedit/blocks/ItemID.java @@ -163,6 +163,6 @@ public final class ItemID { public static final int DISC_MELLOHI = 2262; public static final int DISC_STAL = 2263; public static final int DISC_STRAD = 2264; - public static final int DISC_WARD = 2265; + public static final int DISC_WARD = 2265; public static final int DISC_11 = 2266; } diff --git a/src/main/java/com/sk89q/worldedit/blocks/ItemType.java b/src/main/java/com/sk89q/worldedit/blocks/ItemType.java index d70c6bd69..63549b284 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/ItemType.java +++ b/src/main/java/com/sk89q/worldedit/blocks/ItemType.java @@ -146,7 +146,7 @@ public enum ItemType { FENCE_GATE(BlockID.FENCE_GATE, "Fence gate", "fencegate", "gate"), BRICK_STAIRS(BlockID.BRICK_STAIRS, "Brick stairs", "brickstairs", "bricksteps"), STONE_BRICK_STAIRS(BlockID.STONE_BRICK_STAIRS, "Stone brick stairs", "stonebrickstairs", "smoothstonebrickstairs"), - MYCELIUM(BlockID.MYCELIUM, "Mycelium", "fungus" ,"mycel"), + MYCELIUM(BlockID.MYCELIUM, "Mycelium", "fungus", "mycel"), LILY_PAD(BlockID.LILY_PAD, "Lily pad", "lilypad", "waterlily"), NETHER_BRICK(BlockID.NETHER_BRICK, "Nether brick", "netherbrick"), NETHER_BRICK_FENCE(BlockID.NETHER_BRICK_FENCE, "Nether brick fence", "netherbrickfence", "netherfence"), @@ -306,11 +306,11 @@ public enum ItemType { /** * Stores a map of the IDs for fast access. */ - private static final Map ids = new HashMap(); + private static final Map ids = new HashMap(); /** * Stores a map of the names for fast access. */ - private static final Map lookup = new LinkedHashMap(); + private static final Map lookup = new LinkedHashMap(); private final int id; private final String name; @@ -335,7 +335,7 @@ public enum ItemType { ItemType(int id, String name, String lookupKey) { this.id = id; this.name = name; - this.lookupKeys = new String[] {lookupKey}; + this.lookupKeys = new String[] { lookupKey }; } /** @@ -344,7 +344,7 @@ public enum ItemType { * @param id * @param name */ - ItemType(int id, String name, String ... lookupKeys) { + ItemType(int id, String name, String... lookupKeys) { this.id = id; this.name = name; this.lookupKeys = lookupKeys; @@ -412,32 +412,32 @@ public enum ItemType { */ public static ItemType lookup(String name, boolean fuzzy) { String testName = name.replace(" ", "").toLowerCase(); - + ItemType type = lookup.get(testName); - + if (type != null) { return type; } - + if (!fuzzy) { return null; } - + int minDist = -1; - + for (Entry entry : lookup.entrySet()) { if (entry.getKey().charAt(0) != testName.charAt(0)) { continue; } - + int dist = StringUtil.getLevenshteinDistance(entry.getKey(), testName); - + if ((dist < minDist || minDist == -1) && dist < 2) { minDist = dist; type = entry.getValue(); } } - + return type; } diff --git a/src/main/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java b/src/main/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java index 6c7f8fa43..213595ecc 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java +++ b/src/main/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java @@ -126,9 +126,9 @@ public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock { * @return map of values * @throws DataException */ - public Map toTileEntityNBT() + public Map toTileEntityNBT() throws DataException { - Map values = new HashMap(); + Map values = new HashMap(); values.put("EntityId", new StringTag("EntityId", mobType)); values.put("Delay", new ShortTag("Delay", delay)); return values; @@ -140,19 +140,19 @@ public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock { * @param values * @throws DataException */ - public void fromTileEntityNBT(Map values) - throws DataException { + public void fromTileEntityNBT(Map values) + throws DataException { if (values == null) { return; } Tag t = values.get("id"); - if (!(t instanceof StringTag) || !((StringTag)t).getValue().equals("MobSpawner")) { + if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("MobSpawner")) { throw new DataException("'MobSpawner' tile entity expected"); } - StringTag mobTypeTag = (StringTag)Chunk.getChildTag(values, "EntityId", StringTag.class); - ShortTag delayTag = (ShortTag)Chunk.getChildTag(values, "Delay", ShortTag.class); + StringTag mobTypeTag = (StringTag) Chunk.getChildTag(values, "EntityId", StringTag.class); + ShortTag delayTag = (ShortTag) Chunk.getChildTag(values, "Delay", ShortTag.class); this.mobType = mobTypeTag.getValue(); this.delay = delayTag.getValue(); diff --git a/src/main/java/com/sk89q/worldedit/blocks/NoteBlock.java b/src/main/java/com/sk89q/worldedit/blocks/NoteBlock.java index ce7574718..6182d2946 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/NoteBlock.java +++ b/src/main/java/com/sk89q/worldedit/blocks/NoteBlock.java @@ -85,16 +85,16 @@ public class NoteBlock extends BaseBlock implements TileEntityBlock { public String getTileEntityID() { return "Music"; } - + /** * Store additional tile entity data. Returns true if the data is used. * * @return map of values * @throws DataException */ - public Map toTileEntityNBT() + public Map toTileEntityNBT() throws DataException { - Map values = new HashMap(); + Map values = new HashMap(); values.put("note", new ByteTag("note", note)); return values; } @@ -105,22 +105,22 @@ public class NoteBlock extends BaseBlock implements TileEntityBlock { * @param values * @throws DataException */ - public void fromTileEntityNBT(Map values) - throws DataException { + public void fromTileEntityNBT(Map values) + throws DataException { if (values == null) { return; } - + Tag t; t = values.get("id"); - if (!(t instanceof StringTag) || !((StringTag)t).getValue().equals("Music")) { + if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Music")) { throw new DataException("'Music' tile entity expected"); } t = values.get("note"); if (t instanceof ByteTag) { - note = ((ByteTag)t).getValue(); + note = ((ByteTag) t).getValue(); } } } diff --git a/src/main/java/com/sk89q/worldedit/blocks/SignBlock.java b/src/main/java/com/sk89q/worldedit/blocks/SignBlock.java index d1406a092..a6c561a7f 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/SignBlock.java +++ b/src/main/java/com/sk89q/worldedit/blocks/SignBlock.java @@ -42,7 +42,7 @@ public class SignBlock extends BaseBlock implements TileEntityBlock { */ public SignBlock(int type, int data) { super(type, data); - this.text = new String[]{ "", "", "", "" }; + this.text = new String[] { "", "", "", "" }; } /** @@ -86,9 +86,9 @@ public class SignBlock extends BaseBlock implements TileEntityBlock { * @return map of values * @throws DataException */ - public Map toTileEntityNBT() + public Map toTileEntityNBT() throws DataException { - Map values = new HashMap(); + Map values = new HashMap(); values.put("Text1", new StringTag("Text1", text[0])); values.put("Text2", new StringTag("Text2", text[1])); values.put("Text3", new StringTag("Text3", text[2])); @@ -102,39 +102,39 @@ public class SignBlock extends BaseBlock implements TileEntityBlock { * @param values * @throws DataException */ - public void fromTileEntityNBT(Map values) - throws DataException { + public void fromTileEntityNBT(Map values) + throws DataException { if (values == null) { return; } Tag t; - text = new String[]{ "", "", "", "" }; + text = new String[] { "", "", "", "" }; t = values.get("id"); - if (!(t instanceof StringTag) || !((StringTag)t).getValue().equals("Sign")) { + if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Sign")) { throw new DataException("'Sign' tile entity expected"); } t = values.get("Text1"); if (t instanceof StringTag) { - text[0] = ((StringTag)t).getValue(); + text[0] = ((StringTag) t).getValue(); } t = values.get("Text2"); if (t instanceof StringTag) { - text[1] = ((StringTag)t).getValue(); + text[1] = ((StringTag) t).getValue(); } t = values.get("Text3"); if (t instanceof StringTag) { - text[2] = ((StringTag)t).getValue(); + text[2] = ((StringTag) t).getValue(); } t = values.get("Text4"); if (t instanceof StringTag) { - text[3] = ((StringTag)t).getValue(); + text[3] = ((StringTag) t).getValue(); } } } diff --git a/src/main/java/com/sk89q/worldedit/blocks/TileEntityBlock.java b/src/main/java/com/sk89q/worldedit/blocks/TileEntityBlock.java index 254c22dd8..f1e182123 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/TileEntityBlock.java +++ b/src/main/java/com/sk89q/worldedit/blocks/TileEntityBlock.java @@ -35,20 +35,22 @@ public interface TileEntityBlock { * @return title entity ID */ public String getTileEntityID(); + /** * Store additional tile entity data. * * @return map of values * @throws DataException */ - public Map toTileEntityNBT() + public Map toTileEntityNBT() throws DataException; + /** * Get additional information from the title entity data. * * @param values * @throws DataException */ - public void fromTileEntityNBT(Map values) + public void fromTileEntityNBT(Map values) throws DataException; } diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java index 11b0415ea..2b9c722e2 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java @@ -36,9 +36,9 @@ public class BukkitConfiguration extends LocalConfiguration { private YAMLProcessor config; private Logger logger; private FileHandler logFileHandler; - + public boolean noOpPermissions = false; - + public BukkitConfiguration(YAMLProcessor config, Logger logger) { this.config = config; this.logger = logger; @@ -53,7 +53,7 @@ public class BukkitConfiguration extends LocalConfiguration { e.printStackTrace(); } showFirstUseVersion = false; - + profile = config.getBoolean("debug", profile); wandItem = config.getInt("wand-item", wandItem); defaultChangeLimit = Math.max(-1, config.getInt( @@ -74,7 +74,7 @@ public class BukkitConfiguration extends LocalConfiguration { useInventoryOverride = config.getBoolean("use-inventory.allow-override", useInventoryOverride); maxBrushRadius = config.getInt("limits.max-brush-radius", maxBrushRadius); - + navigationWand = config.getInt("navigation-wand.item", navigationWand); navigationWandMaxDistance = config.getInt("navigation-wand.max-distance", navigationWandMaxDistance); @@ -82,18 +82,18 @@ public class BukkitConfiguration extends LocalConfiguration { scriptsDir = config.getString("scripting.dir", scriptsDir); saveDir = config.getString("saving.dir", saveDir); - + disallowedBlocks = new HashSet(config.getIntList("limits.disallowed-blocks", null)); allowedDataCycleBlocks = new HashSet(config.getIntList("limits.allowed-data-cycle-blocks", null)); noOpPermissions = config.getBoolean("no-op-permissions", false); - + LocalSession.MAX_HISTORY_SIZE = Math.max(0, config.getInt("history.size", 15)); LocalSession.EXPIRATION_GRACE = config.getInt("history.expiration", 10) * 60 * 1000; - + String snapshotsDir = config.getString("snapshots.directory", ""); - if (!snapshotsDir.isEmpty()){ + if (!snapshotsDir.isEmpty()) { snapshotRepo = new SnapshotRepository(snapshotsDir); } @@ -116,11 +116,10 @@ public class BukkitConfiguration extends LocalConfiguration { } } } - + public void unload() { if (logFileHandler != null) { logFileHandler.close(); } - } - + } } diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index 2e0ab62ed..fc4230b76 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -30,7 +30,7 @@ import com.sk89q.worldedit.cui.CUIEvent; public class BukkitPlayer extends LocalPlayer { private Player player; private WorldEditPlugin plugin; - + public BukkitPlayer(WorldEditPlugin plugin, ServerInterface server, Player player) { super(server); this.plugin = plugin; @@ -117,11 +117,11 @@ public class BukkitPlayer extends LocalPlayer { public LocalWorld getWorld() { return new BukkitWorld(player.getWorld()); } - + @Override public void dispatchCUIEvent(CUIEvent event) { String[] params = event.getParameters(); - + if (params.length > 0) { player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75" + event.getTypeId() + "|" + StringUtil.joinString(params, "|")); @@ -129,7 +129,7 @@ public class BukkitPlayer extends LocalPlayer { player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75" + event.getTypeId()); } } - + @Override public void dispatchCUIHandshake() { player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75"); diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java index 10aea6eb8..3355e6eae 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java @@ -37,7 +37,7 @@ public class BukkitPlayerBlockBag extends BlockBag { * The player's inventory; */ private ItemStack[] items; - + /** * Construct the object. * @@ -46,7 +46,7 @@ public class BukkitPlayerBlockBag extends BlockBag { public BukkitPlayerBlockBag(Player player) { this.player = player; } - + /** * Loads inventory on first use. */ @@ -55,7 +55,7 @@ public class BukkitPlayerBlockBag extends BlockBag { items = player.getInventory().getContents(); } } - + /** * Get the player. * @@ -64,7 +64,7 @@ public class BukkitPlayerBlockBag extends BlockBag { public Player getPlayer() { return player; } - + /** * Get a block. * @@ -113,7 +113,7 @@ public class BukkitPlayerBlockBag extends BlockBag { bukkitItem.setAmount(currentAmount - 1); found = true; } else { - items[slot] = null; + items[slot] = null; found = true; } @@ -196,7 +196,7 @@ public class BukkitPlayerBlockBag extends BlockBag { throw new OutOfSpaceException(id); } - + /** * Flush any changes. This is called at the end. */ @@ -216,7 +216,7 @@ public class BukkitPlayerBlockBag extends BlockBag { @Override public void addSourcePosition(Vector pos) { } - + /** * Adds a position to be used a source. * diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java index b36a770af..e5301fb02 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java @@ -26,7 +26,7 @@ import com.sk89q.worldedit.ServerInterface; public class BukkitServerInterface extends ServerInterface { public Server server; public WorldEditPlugin plugin; - + public BukkitServerInterface(WorldEditPlugin plugin, Server server) { this.plugin = plugin; this.server = server; diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java index 77deb2750..37a99dd70 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java @@ -30,10 +30,10 @@ import com.sk89q.worldedit.*; import com.sk89q.worldedit.Vector; public class BukkitUtil { - private BukkitUtil() { + private BukkitUtil() { } - - private static final Map wlw = new HashMap(); + + private static final Map wlw = new HashMap(); public static LocalWorld getLocalWorld(World w) { LocalWorld lw = wlw.get(w); @@ -43,27 +43,27 @@ public class BukkitUtil { } return lw; } - + public static BlockVector toVector(Block block) { return new BlockVector(block.getX(), block.getY(), block.getZ()); } - + public static BlockVector toVector(BlockFace face) { return new BlockVector(face.getModX(), face.getModY(), face.getModZ()); } - + public static BlockWorldVector toWorldVector(Block block) { return new BlockWorldVector(getLocalWorld(block.getWorld()), block.getX(), block.getY(), block.getZ()); } - + public static Vector toVector(Location loc) { return new Vector(loc.getX(), loc.getY(), loc.getZ()); } - + public static Vector toVector(org.bukkit.util.Vector vector) { return new Vector(vector.getX(), vector.getY(), vector.getZ()); } - + public static Location toLocation(WorldVector pt) { return new Location(toWorld(pt), pt.getX(), pt.getY(), pt.getZ()); } @@ -71,18 +71,18 @@ public class BukkitUtil { public static Location toLocation(World world, Vector pt) { return new Location(world, pt.getX(), pt.getY(), pt.getZ()); } - + public static Location center(Location loc) { return new Location( loc.getWorld(), - loc.getBlockX()+0.5, - loc.getBlockY()+0.5, - loc.getBlockZ()+0.5, + loc.getBlockX() + 0.5, + loc.getBlockY() + 0.5, + loc.getBlockZ() + 0.5, loc.getPitch(), loc.getYaw() ); } - + public static Player matchSinglePlayer(Server server, String name) { List players = server.matchPlayer(name); if (players.size() == 0) { @@ -96,18 +96,19 @@ public class BukkitUtil { } public static World toWorld(WorldVector pt) { - return ((BukkitWorld)pt.getWorld()).getWorld(); + return ((BukkitWorld) pt.getWorld()).getWorld(); } - + /** * Bukkit's Location class has serious problems with floating point * precision. */ public static boolean equals(Location a, Location b) { - if (Math.abs(a.getX()-b.getX()) > EQUALS_PRECISION) return false; - if (Math.abs(a.getY()-b.getY()) > EQUALS_PRECISION) return false; - if (Math.abs(a.getZ()-b.getZ()) > EQUALS_PRECISION) return false; + if (Math.abs(a.getX() - b.getX()) > EQUALS_PRECISION) return false; + if (Math.abs(a.getY() - b.getY()) > EQUALS_PRECISION) return false; + if (Math.abs(a.getZ() - b.getZ()) > EQUALS_PRECISION) return false; return true; } + public static final double EQUALS_PRECISION = 0.0001; } diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 96c348f10..e37ad7214 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -61,7 +61,7 @@ import com.sk89q.worldedit.regions.Region; public class BukkitWorld extends LocalWorld { private World world; - + /** * Construct the object. * @param world @@ -69,7 +69,7 @@ public class BukkitWorld extends LocalWorld { public BukkitWorld(World world) { this.world = world; } - + /** * Get the world handle. * @@ -78,7 +78,7 @@ public class BukkitWorld extends LocalWorld { public World getWorld() { return world; } - + /** * Get the name of the world * @@ -130,10 +130,10 @@ public class BukkitWorld extends LocalWorld { * @return */ @Override - public boolean setTypeIdAndData(Vector pt, int type, int data){ + public boolean setTypeIdAndData(Vector pt, int type, int data) { return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setTypeIdAndData(type, (byte) data, true); } - + /** * set block type & data * @param pt @@ -142,7 +142,7 @@ public class BukkitWorld extends LocalWorld { * @return */ @Override - public boolean setTypeIdAndDataFast(Vector pt, int type, int data){ + public boolean setTypeIdAndDataFast(Vector pt, int type, int data) { final Block block = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); if (fastLightingAvailable) { type = type & 255; @@ -175,7 +175,7 @@ public class BukkitWorld extends LocalWorld { */ @Override public void setBlockData(Vector pt, int data) { - world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setData((byte)data); + world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setData((byte) data); } /** @@ -186,7 +186,7 @@ public class BukkitWorld extends LocalWorld { */ @Override public void setBlockDataFast(Vector pt, int data) { - world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setData((byte)data, false); + world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).setData((byte) data, false); } /** @@ -221,10 +221,10 @@ public class BukkitWorld extends LocalWorld { @Override public boolean regenerate(Region region, EditSession editSession) { BaseBlock[] history = new BaseBlock[16 * 16 * 128]; - + for (Vector2D chunk : region.getChunks()) { Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16); - + // First save all the blocks inside for (int x = 0; x < 16; ++x) { for (int y = 0; y < 128; ++y) { @@ -235,20 +235,20 @@ public class BukkitWorld extends LocalWorld { } } } - + try { world.regenerateChunk(chunk.getBlockX(), chunk.getBlockZ()); } catch (Throwable t) { t.printStackTrace(); } - + // Then restore for (int x = 0; x < 16; ++x) { for (int y = 0; y < 128; ++y) { for (int z = 0; z < 16; ++z) { Vector pt = min.add(x, y, z); int index = y * 16 * 16 + z * 16 + x; - + // We have to restore the block if it was outside if (!region.contains(pt)) { editSession.smartSetBlock(pt, history[index]); @@ -260,7 +260,7 @@ public class BukkitWorld extends LocalWorld { } } } - + return true; } @@ -273,51 +273,55 @@ public class BukkitWorld extends LocalWorld { */ @Override public boolean copyToWorld(Vector pt, BaseBlock block) { - // Signs if (block instanceof SignBlock) { - setSignText(pt, ((SignBlock)block).getText()); + // Signs + setSignText(pt, ((SignBlock) block).getText()); return true; - - // Furnaces - } else if (block instanceof FurnaceBlock) { + } + + if (block instanceof FurnaceBlock) { + // Furnaces Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); if (bukkitBlock == null) return false; BlockState state = bukkitBlock.getState(); if (!(state instanceof Furnace)) return false; - Furnace bukkit = (Furnace)state; - FurnaceBlock we = (FurnaceBlock)block; + Furnace bukkit = (Furnace) state; + FurnaceBlock we = (FurnaceBlock) block; bukkit.setBurnTime(we.getBurnTime()); bukkit.setCookTime(we.getCookTime()); - return setContainerBlockContents(pt, ((ContainerBlock)block).getItems()); - - // Chests/dispenser - } else if (block instanceof ContainerBlock) { - return setContainerBlockContents(pt, ((ContainerBlock)block).getItems()); - - // Mob spawners - } else if (block instanceof MobSpawnerBlock) { + return setContainerBlockContents(pt, ((ContainerBlock) block).getItems()); + } + + if (block instanceof ContainerBlock) { + // Chests/dispenser + return setContainerBlockContents(pt, ((ContainerBlock) block).getItems()); + } + + if (block instanceof MobSpawnerBlock) { + // Mob spawners Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); if (bukkitBlock == null) return false; BlockState state = bukkitBlock.getState(); if (!(state instanceof CreatureSpawner)) return false; - CreatureSpawner bukkit = (CreatureSpawner)state; - MobSpawnerBlock we = (MobSpawnerBlock)block; + CreatureSpawner bukkit = (CreatureSpawner) state; + MobSpawnerBlock we = (MobSpawnerBlock) block; bukkit.setCreatureTypeId(we.getMobType()); bukkit.setDelay(we.getDelay()); return true; - - // Note block - } else if (block instanceof NoteBlock) { + } + + if (block instanceof NoteBlock) { + // Note block Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); if (bukkitBlock == null) return false; BlockState state = bukkitBlock.getState(); if (!(state instanceof org.bukkit.block.NoteBlock)) return false; - org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock)state; - NoteBlock we = (NoteBlock)block; + org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock) state; + NoteBlock we = (NoteBlock) block; bukkit.setRawNote(we.getNote()); return true; } - + return false; } @@ -330,13 +334,14 @@ public class BukkitWorld extends LocalWorld { */ @Override public boolean copyFromWorld(Vector pt, BaseBlock block) { - // Signs if (block instanceof SignBlock) { + // Signs ((SignBlock) block).setText(getSignText(pt)); return true; - - // Furnaces - } else if (block instanceof FurnaceBlock) { + } + + if (block instanceof FurnaceBlock) { + // Furnaces Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); if (bukkitBlock == null) return false; BlockState state = bukkitBlock.getState(); @@ -347,14 +352,16 @@ public class BukkitWorld extends LocalWorld { we.setCookTime(bukkit.getCookTime()); ((ContainerBlock) block).setItems(getContainerBlockContents(pt)); return true; + } - // Chests/dispenser - } else if (block instanceof ContainerBlock) { + if (block instanceof ContainerBlock) { + // Chests/dispenser ((ContainerBlock) block).setItems(getContainerBlockContents(pt)); return true; - - // Mob spawners - } else if (block instanceof MobSpawnerBlock) { + } + + if (block instanceof MobSpawnerBlock) { + // Mob spawners Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); if (bukkitBlock == null) return false; BlockState state = bukkitBlock.getState(); @@ -364,18 +371,19 @@ public class BukkitWorld extends LocalWorld { we.setMobType(bukkit.getCreatureTypeId()); we.setDelay((short) bukkit.getDelay()); return true; - - // Note block - } else if (block instanceof NoteBlock) { + } + + if (block instanceof NoteBlock) { + // Note block Block bukkitBlock = world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); if (bukkitBlock == null) return false; BlockState state = bukkitBlock.getState(); if (!(state instanceof org.bukkit.block.NoteBlock)) return false; - org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock)state; + org.bukkit.block.NoteBlock bukkit = (org.bukkit.block.NoteBlock) state; NoteBlock we = (NoteBlock) block; we.setNote(bukkit.getRawNote()); } - + return false; } @@ -395,7 +403,7 @@ public class BukkitWorld extends LocalWorld { return false; } - org.bukkit.block.ContainerBlock chest = (org.bukkit.block.ContainerBlock)state; + org.bukkit.block.ContainerBlock chest = (org.bukkit.block.ContainerBlock) state; Inventory inven = chest.getInventory(); inven.clear(); return true; @@ -472,7 +480,7 @@ public class BukkitWorld extends LocalWorld { ItemStack bukkitItem = new ItemStack(item.getType(), item.getAmount(), (byte) item.getDamage()); world.dropItemNaturally(toLocation(pt), bukkitItem); - + } /** @@ -499,7 +507,7 @@ public class BukkitWorld extends LocalWorld { public int killMobs(Vector origin, int radius, boolean killPets) { int num = 0; double radiusSq = Math.pow(radius, 2); - + for (LivingEntity ent : world.getLivingEntities()) { if (!killPets && ent instanceof Tameable && ((Tameable) ent).isTamed()) { continue; // tamed wolf @@ -512,10 +520,10 @@ public class BukkitWorld extends LocalWorld { } } } - + return num; } - + /** * Remove entities in an area. * @@ -527,54 +535,68 @@ public class BukkitWorld extends LocalWorld { public int removeEntities(EntityType type, Vector origin, int radius) { int num = 0; double radiusSq = Math.pow(radius, 2); - + for (Entity ent : world.getEntities()) { if (radius != -1 && origin.distanceSq(BukkitUtil.toVector(ent.getLocation())) > radiusSq) { continue; } - - if (type == EntityType.ARROWS) { + + switch (type) { + case ARROWS: if (ent instanceof Arrow) { ent.remove(); ++num; } - } else if (type == EntityType.BOATS) { + break; + + case BOATS: if (ent instanceof Boat) { ent.remove(); ++num; } - } else if (type == EntityType.ITEMS) { + break; + + case ITEMS: if (ent instanceof Item) { ent.remove(); ++num; } - } else if (type == EntityType.MINECARTS) { + break; + + case MINECARTS: if (ent instanceof Minecart) { ent.remove(); ++num; } - } else if (type == EntityType.PAINTINGS) { + break; + + case PAINTINGS: if (ent instanceof Painting) { ent.remove(); ++num; } - } else if (type == EntityType.TNT) { + break; + + case TNT: if (ent instanceof TNTPrimed) { ent.remove(); ++num; } - } else if (type == EntityType.XP_ORBS) { + break; + + case XP_ORBS: if (ent instanceof ExperienceOrb) { ent.remove(); ++num; } + break; } } - + return num; } - + private Location toLocation(Vector pt) { return new Location(world, pt.getX(), pt.getY(), pt.getZ()); } @@ -639,22 +661,22 @@ public class BukkitWorld extends LocalWorld { if (!(state instanceof org.bukkit.block.ContainerBlock)) { return new BaseItemStack[0]; } - + org.bukkit.block.ContainerBlock container = (org.bukkit.block.ContainerBlock) state; Inventory inven = container.getInventory(); int size = inven.getSize(); BaseItemStack[] contents = new BaseItemStack[size]; - + for (int i = 0; i < size; ++i) { ItemStack bukkitStack = inven.getItem(i); if (bukkitStack.getTypeId() > 0) { contents[i] = new BaseItemStack( bukkitStack.getTypeId(), - bukkitStack.getAmount(), + bukkitStack.getAmount(), bukkitStack.getDurability()); } } - + return contents; } @@ -674,11 +696,11 @@ public class BukkitWorld extends LocalWorld { if (!(state instanceof org.bukkit.block.ContainerBlock)) { return false; } - - org.bukkit.block.ContainerBlock chest = (org.bukkit.block.ContainerBlock)state; + + org.bukkit.block.ContainerBlock chest = (org.bukkit.block.ContainerBlock) state; Inventory inven = chest.getInventory(); int size = inven.getSize(); - + for (int i = 0; i < size; ++i) { if (i >= contents.length) { break; @@ -686,16 +708,16 @@ public class BukkitWorld extends LocalWorld { if (contents[i] != null) { inven.setItem(i, new ItemStack(contents[i].getType(), - contents[i].getAmount(), + contents[i].getAmount(), (byte) contents[i].getDamage())); } else { inven.setItem(i, null); } } - + return true; } - + /** * Returns whether a block has a valid ID. * @@ -719,7 +741,7 @@ public class BukkitWorld extends LocalWorld { if (!(other instanceof BukkitWorld)) { return false; } - + return ((BukkitWorld) other).world.equals(world); } @@ -761,7 +783,7 @@ public class BukkitWorld extends LocalWorld { final Object notchChunk = World_getChunkFromChunkCoords.invoke(notchWorld, chunkX, chunkZ); // Fix skylight - final byte[] blocks = (byte[])Chunk_blocks.get(notchChunk); + final byte[] blocks = (byte[]) Chunk_blocks.get(notchChunk); final int length = blocks.length; Chunk_skylightMap.set(notchChunk, NibbleArray_ctor.newInstance(length, 7)); @@ -781,7 +803,7 @@ public class BukkitWorld extends LocalWorld { for (int y = 0; y < chunkSizeY; ++y) { final int index = y + z * chunkSizeY + x * chunkSizeY * chunkSizeZ; byte blockID = blocks[index]; - if (!BlockType.emitsLight(blockID)) { + if (!BlockType.emitsLight(blockID)) { if (xBorder || zBorder && BlockType.isTranslucent(blockID)) { lightEmitters.add(chunk.getBlock(x, y, z).getState()); if (blockID == 20) { @@ -789,7 +811,7 @@ public class BukkitWorld extends LocalWorld { } else { blocks[index] = 20; } - + } continue; } diff --git a/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java b/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java index 1874b7d4a..a7a813d55 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java @@ -44,7 +44,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate { return false; } } - + public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) { try { return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId, data)); diff --git a/src/main/java/com/sk89q/worldedit/bukkit/SessionTimer.java b/src/main/java/com/sk89q/worldedit/bukkit/SessionTimer.java index 4fbeb6f3f..b51dcb47c 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/SessionTimer.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/SessionTimer.java @@ -30,10 +30,10 @@ import com.sk89q.worldedit.WorldEdit; * @author sk89q */ public class SessionTimer implements Runnable { - + private WorldEdit worldEdit; private SessionCheck checker; - + public SessionTimer(WorldEdit worldEdit, final Server server) { this.worldEdit = worldEdit; this.checker = new SessionCheck() { diff --git a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditAPI.java b/src/main/java/com/sk89q/worldedit/bukkit/WorldEditAPI.java index 41cd07fe4..8fa06a8bb 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditAPI.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/WorldEditAPI.java @@ -22,13 +22,13 @@ package com.sk89q.worldedit.bukkit; import org.bukkit.entity.Player; import com.sk89q.worldedit.LocalSession; -public class WorldEditAPI { +public class WorldEditAPI { private WorldEditPlugin plugin; - + public WorldEditAPI(WorldEditPlugin plugin) { this.plugin = plugin; } - + /** * Get the session for a player. * diff --git a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditCriticalPlayerListener.java b/src/main/java/com/sk89q/worldedit/bukkit/WorldEditCriticalPlayerListener.java index 172bbf070..d8fcb3261 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditCriticalPlayerListener.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/WorldEditCriticalPlayerListener.java @@ -32,7 +32,7 @@ public class WorldEditCriticalPlayerListener extends PlayerListener { * Plugin. */ private WorldEditPlugin plugin; - + /** * Construct the object; * diff --git a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java b/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java index 462ab6d79..dfb3e134d 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java @@ -88,7 +88,7 @@ public class WorldEditPlayerListener extends PlayerListener { } private boolean ignoreLeftClickAir = false; - + /** * Called when a player interacts * @@ -115,9 +115,11 @@ public class WorldEditPlayerListener extends PlayerListener { } if (!ignoreLeftClickAir) { - final int taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { - ignoreLeftClickAir = false; - }}, 2); + final int taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + ignoreLeftClickAir = false; + } + }, 2); if (taskId != -1) { ignoreLeftClickAir = true; diff --git a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index 7ef024b2a..989d1e683 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -53,7 +53,7 @@ public class WorldEditPlugin extends JavaPlugin { * WorldEdit messages get sent here. */ private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit"); - + /** * The server interface that all server-related API goes through. */ @@ -66,7 +66,7 @@ public class WorldEditPlugin extends JavaPlugin { * Deprecated API. */ private WorldEditAPI api; - + /** * Holds the configuration for WorldEdit. */ @@ -93,15 +93,15 @@ public class WorldEditPlugin extends JavaPlugin { // Create the default configuration file createDefaultConfiguration("config.yml"); - + // Set up configuration and such, including the permissions // resolver config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "config.yml"), true), logger); perms = new PermissionsResolverManager(this, "WorldEdit", logger); - + // Load the configuration loadConfiguration(); - + // Setup interfaces server = new BukkitServerInterface(this, getServer()); controller = new WorldEdit(server, config); @@ -109,8 +109,8 @@ public class WorldEditPlugin extends JavaPlugin { // Now we can register events! registerEvents(); - - getServer().getScheduler().scheduleAsyncRepeatingTask(this, + + getServer().getScheduler().scheduleAsyncRepeatingTask(this, new SessionTimer(controller, getServer()), 120, 120); } @@ -128,7 +128,7 @@ public class WorldEditPlugin extends JavaPlugin { config.unload(); this.getServer().getScheduler().cancelTasks(this); } - + /** * Loads and reloads all configuration. */ @@ -200,20 +200,22 @@ public class WorldEditPlugin extends JavaPlugin { while ((length = input.read(buf)) > 0) { output.write(buf, 0, length); } - + logger.info(getDescription().getName() + ": Default configuration file written: " + name); } catch (IOException e) { e.printStackTrace(); } finally { try { - if (input != null) + if (input != null) { input.close(); + } } catch (IOException e) {} try { - if (output != null) + if (output != null) { output.close(); + } } catch (IOException e) {} } } @@ -231,20 +233,20 @@ public class WorldEditPlugin extends JavaPlugin { if (!(sender instanceof Player)) { return true; } - - Player player = (Player)sender; - + + Player player = (Player) sender; + // Add the command to the array because the underlying command handling // code of WorldEdit expects it String[] split = new String[args.length + 1]; System.arraycopy(args, 0, split, 1, args.length); split[0] = "/" + cmd.getName(); - + controller.handleCommand(wrapPlayer(player), split); - + return true; } - + /** * Gets the session for the player. * @@ -254,7 +256,7 @@ public class WorldEditPlugin extends JavaPlugin { public LocalSession getSession(Player player) { return controller.getSession(wrapPlayer(player)); } - + /** * Gets the session for the player. * @@ -265,15 +267,14 @@ public class WorldEditPlugin extends JavaPlugin { LocalPlayer wePlayer = wrapPlayer(player); LocalSession session = controller.getSession(wePlayer); BlockBag blockBag = session.getBlockBag(wePlayer); - + EditSession editSession = - new EditSession(wePlayer.getWorld(), - session.getBlockChangeLimit(), blockBag); + new EditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag); editSession.enableQueue(); - + return editSession; } - + /** * Remember an edit session. * @@ -283,13 +284,13 @@ public class WorldEditPlugin extends JavaPlugin { public void remember(Player player, EditSession editSession) { LocalPlayer wePlayer = wrapPlayer(player); LocalSession session = controller.getSession(wePlayer); - + session.remember(editSession); editSession.flushQueue(); - + controller.flushBlockBag(wePlayer, editSession); } - + /** * Wrap an operation into an EditSession. * @@ -301,7 +302,7 @@ public class WorldEditPlugin extends JavaPlugin { throws Throwable { LocalPlayer wePlayer = wrapPlayer(player); LocalSession session = controller.getSession(wePlayer); - + EditSession editSession = createEditSession(player); try { op.run(session, wePlayer, editSession); @@ -309,7 +310,7 @@ public class WorldEditPlugin extends JavaPlugin { remember(player, editSession); } } - + /** * Get the API. * @@ -319,7 +320,7 @@ public class WorldEditPlugin extends JavaPlugin { public WorldEditAPI getAPI() { return api; } - + /** * Returns the configuration used by WorldEdit. * @@ -328,7 +329,7 @@ public class WorldEditPlugin extends JavaPlugin { public BukkitConfiguration getLocalConfiguration() { return config; } - + /** * Get the permissions resolver in use. * @@ -337,7 +338,7 @@ public class WorldEditPlugin extends JavaPlugin { public PermissionsResolverManager getPermissionsResolver() { return perms; } - + /** * Used to wrap a Bukkit Player as a LocalPlayer. * @@ -347,7 +348,7 @@ public class WorldEditPlugin extends JavaPlugin { public BukkitPlayer wrapPlayer(Player player) { return new BukkitPlayer(this, this.server, player); } - + /** * Get the server interface. * @@ -356,7 +357,7 @@ public class WorldEditPlugin extends JavaPlugin { public ServerInterface getServerInterface() { return server; } - + /** * Get WorldEdit. * @@ -365,7 +366,7 @@ public class WorldEditPlugin extends JavaPlugin { public WorldEdit getWorldEdit() { return controller; } - + /** * Gets the region selection for the player. * @@ -379,18 +380,18 @@ public class WorldEditPlugin extends JavaPlugin { if (!player.isOnline()) { throw new IllegalArgumentException("Offline player not allowed"); } - + LocalSession session = controller.getSession(wrapPlayer(player)); RegionSelector selector = session.getRegionSelector(); - + try { Region region = selector.getRegion(); World world = ((BukkitWorld) session.getSelectionWorld()).getWorld(); - + if (region instanceof CuboidRegion) { - return new CuboidSelection(world, selector, (CuboidRegion)region); + return new CuboidSelection(world, selector, (CuboidRegion) region); } else if (region instanceof Polygonal2DRegion) { - return new Polygonal2DSelection(world, selector, (Polygonal2DRegion)region); + return new Polygonal2DSelection(world, selector, (Polygonal2DRegion) region); } else { return null; } @@ -398,7 +399,7 @@ public class WorldEditPlugin extends JavaPlugin { return null; } } - + /** * Sets the region selection for a player. * @@ -415,8 +416,8 @@ public class WorldEditPlugin extends JavaPlugin { if (selection == null) { throw new IllegalArgumentException("Null selection not allowed"); } - - LocalSession session = controller.getSession(wrapPlayer(player)); + + LocalSession session = controller.getSession(wrapPlayer(player)); RegionSelector sel = selection.getRegionSelector(); session.setRegionSelector(new BukkitWorld(player.getWorld()), sel); session.dispatchCUISelection(wrapPlayer(player)); diff --git a/src/main/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java b/src/main/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java index 16f2b665f..f40ab3567 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java @@ -29,26 +29,26 @@ import com.sk89q.worldedit.regions.*; public class CuboidSelection extends RegionSelection { protected CuboidRegion cuboid; - - public CuboidSelection(World world, Location pt1, Location pt2) { + + public CuboidSelection(World world, Location pt1, Location pt2) { this(world, BukkitUtil.toVector(pt1), BukkitUtil.toVector(pt2)); } - - public CuboidSelection(World world, Vector pt1, Vector pt2) { + + public CuboidSelection(World world, Vector pt1, Vector pt2) { super(world); if (pt1 == null) { throw new IllegalArgumentException("Null point 1 not permitted"); } - + if (pt2 == null) { throw new IllegalArgumentException("Null point 2 not permitted"); } - + CuboidRegionSelector sel = new CuboidRegionSelector(); sel.selectPrimary(pt1); sel.selectSecondary(pt2); - + try { cuboid = sel.getRegion(); } catch (IncompleteRegionException e) { @@ -58,7 +58,7 @@ public class CuboidSelection extends RegionSelection { setRegionSelector(sel); setRegion(cuboid); } - + public CuboidSelection(World world, RegionSelector sel, CuboidRegion region) { super(world, sel, region); this.cuboid = region; diff --git a/src/main/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java b/src/main/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java index 0fd3ab260..fb5f77ef9 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java @@ -28,13 +28,13 @@ import com.sk89q.worldedit.regions.*; public class Polygonal2DSelection extends RegionSelection { protected Polygonal2DRegion poly2d; - + public Polygonal2DSelection(World world, RegionSelector sel, Polygonal2DRegion region) { super(world, sel, region); this.poly2d = region; } - - public Polygonal2DSelection(World world, List points, int minY, int maxY) { + + public Polygonal2DSelection(World world, List points, int minY, int maxY) { super(world); minY = Math.min(Math.max(0, minY), 127); @@ -48,7 +48,7 @@ public class Polygonal2DSelection extends RegionSelection { setRegionSelector(sel); setRegion(poly2d); } - + public List getNativePoints() { return Collections.unmodifiableList(poly2d.getPoints()); } diff --git a/src/main/java/com/sk89q/worldedit/bukkit/selections/RegionSelection.java b/src/main/java/com/sk89q/worldedit/bukkit/selections/RegionSelection.java index dc286bb00..6267ff394 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/selections/RegionSelection.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/selections/RegionSelection.java @@ -32,29 +32,29 @@ public abstract class RegionSelection implements Selection { private World world; private RegionSelector selector; private Region region; - + public RegionSelection(World world) { this.world = world; } - + public RegionSelection(World world, RegionSelector selector, Region region) { this.world = world; this.region = region; this.selector = selector; } - + protected Region getRegion() { return region; } - + protected void setRegion(Region region) { this.region = region; } - + public RegionSelector getRegionSelector() { return selector; } - + protected void setRegionSelector(RegionSelector selector) { this.selector = selector; } @@ -99,7 +99,7 @@ public abstract class RegionSelection implements Selection { if (!pt.getWorld().equals(world)) { return false; } - + return region.contains(toVector(pt)); } diff --git a/src/main/java/com/sk89q/worldedit/bukkit/selections/Selection.java b/src/main/java/com/sk89q/worldedit/bukkit/selections/Selection.java index a0f366182..8e9ebf31b 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/selections/Selection.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/selections/Selection.java @@ -31,70 +31,70 @@ public interface Selection { * @return min. point */ public Location getMinimumPoint(); - + /** * Get the lower point of a region. * * @return min. point */ public Vector getNativeMinimumPoint(); - + /** * Get the upper point of a region. * * @return max. point */ public Location getMaximumPoint(); - + /** * Get the upper point of a region. * * @return max. point */ public Vector getNativeMaximumPoint(); - + /** * Get the region selector. This is for internal use. * * @return */ public RegionSelector getRegionSelector(); - + /** * Get the world. * * @return */ public World getWorld(); - + /** * Get the number of blocks in the region. * * @return number of blocks */ public int getArea(); - + /** * Get X-size. * * @return width */ public int getWidth(); - + /** * Get Y-size. * * @return height */ public int getHeight(); - + /** * Get Z-size. * * @return length */ public int getLength(); - + /** * Returns true based on whether the region contains the point, * diff --git a/src/main/java/com/sk89q/worldedit/commands/BrushCommands.java b/src/main/java/com/sk89q/worldedit/commands/BrushCommands.java index bd0e55d51..4581a9e44 100644 --- a/src/main/java/com/sk89q/worldedit/commands/BrushCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/BrushCommands.java @@ -75,7 +75,7 @@ public class BrushCommands { Pattern fill = we.getBlockPattern(player, args.getString(0)); tool.setFill(fill); tool.setSize(radius); - + if (args.hasFlag('h')) { tool.setBrush(new HollowSphereBrush(), "worldedit.brush.sphere"); } else { @@ -119,13 +119,13 @@ public class BrushCommands { Pattern fill = we.getBlockPattern(player, args.getString(0)); tool.setFill(fill); tool.setSize(radius); - + if (args.hasFlag('h')) { tool.setBrush(new HollowCylinderBrush(height), "worldedit.brush.cylinder"); } else { tool.setBrush(new CylinderBrush(height), "worldedit.brush.cylinder"); } - + player.print(String.format("Cylinder brush shape equipped (%.0f by %d).", radius, height)); } @@ -144,14 +144,14 @@ public class BrushCommands { throws WorldEditException { LocalConfiguration config = we.getConfiguration(); - + CuboidClipboard clipboard = session.getClipboard(); - + if (clipboard == null) { player.printError("Copy something first."); return; } - + Vector size = clipboard.getSize(); if (size.getBlockX() > config.maxBrushRadius @@ -164,7 +164,7 @@ public class BrushCommands { BrushTool tool = session.getBrushTool(player.getItemInHand()); tool.setBrush(new ClipboardBrush(clipboard, args.hasFlag('a')), "worldedit.brush.clipboard"); - + player.print("Clipboard brush shape equipped."); } @@ -199,7 +199,7 @@ public class BrushCommands { player.print(String.format("Smooth brush equipped (%.0f x %dx, using " + (args.hasFlag('n') ? "natural blocks only" : "any block") + ").", radius, iterations)); } - + @Command( aliases = { "ex", "extinguish" }, usage = "[radius]", diff --git a/src/main/java/com/sk89q/worldedit/commands/ChunkCommands.java b/src/main/java/com/sk89q/worldedit/commands/ChunkCommands.java index 781e6735d..78f762dab 100644 --- a/src/main/java/com/sk89q/worldedit/commands/ChunkCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/ChunkCommands.java @@ -97,7 +97,7 @@ public class ChunkCommands { player.print("Note that this command does not yet support the mcregion format."); LocalConfiguration config = we.getConfiguration(); - + Set chunks = session.getSelection(player.getWorld()).getChunks(); FileOutputStream out = null; @@ -129,7 +129,9 @@ public class ChunkCommands { player.printError("Error occurred: " + e.getMessage()); } finally { if (out != null) { - try { out.close(); } catch (IOException ie) {} + try { + out.close(); + } catch (IOException ie) { } } } } else if (config.shellSaveType.equalsIgnoreCase("bash")) { diff --git a/src/main/java/com/sk89q/worldedit/commands/ClipboardCommands.java b/src/main/java/com/sk89q/worldedit/commands/ClipboardCommands.java index eebe64e6d..72bfd6a77 100644 --- a/src/main/java/com/sk89q/worldedit/commands/ClipboardCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/ClipboardCommands.java @@ -82,7 +82,7 @@ public class ClipboardCommands { if (args.argsLength() > 0) { block = we.getBlock(player, args.getString(0)); } - + Region region = session.getSelection(player.getWorld()); Vector min = region.getMinimumPoint(); Vector max = region.getMaximumPoint(); @@ -97,7 +97,7 @@ public class ClipboardCommands { editSession.setBlocks(session.getSelection(player.getWorld()), block); player.print("Block(s) cut."); } - + @Command( aliases = { "/paste" }, usage = "", @@ -114,7 +114,7 @@ public class ClipboardCommands { boolean atOrigin = args.hasFlag('o'); boolean pasteNoAir = args.hasFlag('a'); - + if (atOrigin) { Vector pos = session.getClipboard().getOrigin(); session.getClipboard().place(editSession, pos, pasteNoAir); @@ -141,7 +141,7 @@ public class ClipboardCommands { throws WorldEditException { int angle = args.getInteger(0); - + if (angle % 90 == 0) { CuboidClipboard clipboard = session.getClipboard(); clipboard.rotate2D(angle); @@ -171,7 +171,7 @@ public class ClipboardCommands { clipboard.flip(dir, args.hasFlag('p')); player.print("Clipboard flipped."); } - + @Command( aliases = { "/load" }, usage = "", @@ -189,7 +189,7 @@ public class ClipboardCommands { String filename = args.getString(0); File dir = we.getWorkingDirectoryFile(config.saveDir); File f = we.getSafeOpenFile(player, dir, filename, "schematic", - new String[] {"schematic"}); + new String[] { "schematic" }); try { String filePath = f.getCanonicalPath(); @@ -208,7 +208,7 @@ public class ClipboardCommands { player.printError("Schematic could not read or it does not exist: " + e.getMessage()); } } - + @Command( aliases = { "/save" }, usage = "", @@ -227,7 +227,7 @@ public class ClipboardCommands { File dir = we.getWorkingDirectoryFile(config.saveDir); File f = we.getSafeSaveFile(player, dir, filename, "schematic", - new String[] {"schematic"}); + new String[] { "schematic" }); if (!dir.exists()) { if (!dir.mkdir()) { @@ -252,7 +252,7 @@ public class ClipboardCommands { player.printError("Schematic could not written: " + e.getMessage()); } } - + @Command( aliases = { "clearclipboard" }, usage = "", diff --git a/src/main/java/com/sk89q/worldedit/commands/GeneralCommands.java b/src/main/java/com/sk89q/worldedit/commands/GeneralCommands.java index 653346dee..03d1338a7 100644 --- a/src/main/java/com/sk89q/worldedit/commands/GeneralCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/GeneralCommands.java @@ -56,7 +56,7 @@ public class GeneralCommands { return; } } - + session.setBlockChangeLimit(limit); player.print("Block change limit set to " + limit + "."); } @@ -147,27 +147,27 @@ public class GeneralCommands { String query = args.getString(0).trim().toLowerCase(); boolean blocksOnly = args.hasFlag('b'); boolean itemsOnly = args.hasFlag('i'); - + try { int id = Integer.parseInt(query); - + ItemType type = ItemType.fromID(id); - + if (type != null) { player.print("#" + type.getID() + " (" + type.getName() + ")"); } else { player.printError("No item found by ID " + id); } - + return; } catch (NumberFormatException e) { } - + if (query.length() <= 2) { player.printError("Enter a longer search string (len > 2)."); return; } - + if (!blocksOnly && !itemsOnly) { player.print("Searching for: " + query); } else if (blocksOnly && itemsOnly) { @@ -178,23 +178,23 @@ public class GeneralCommands { } else { player.print("Searching for items: " + query); } - + int found = 0; - + for (ItemType type : ItemType.values()) { if (found >= 15) { player.print("Too many results!"); break; } - + if (blocksOnly && type.getID() > 255) { continue; } - + if (itemsOnly && type.getID() <= 255) { continue; } - + for (String alias : type.getAliases()) { if (alias.contains(query)) { player.print("#" + type.getID() + " (" + type.getName() + ")"); @@ -203,7 +203,7 @@ public class GeneralCommands { } } } - + if (found == 0) { player.printError("No items found."); } diff --git a/src/main/java/com/sk89q/worldedit/commands/GenerationCommands.java b/src/main/java/com/sk89q/worldedit/commands/GenerationCommands.java index 9731f397d..35bc291ba 100644 --- a/src/main/java/com/sk89q/worldedit/commands/GenerationCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/GenerationCommands.java @@ -229,12 +229,12 @@ public class GenerationCommands { player.printError("Tree type '" + args.getString(1) + "' is unknown."); return; } - + int affected = editSession.makeForest(player.getPosition(), size, density, new TreeGenerator(type)); player.print(affected + " trees created."); } - + @Command( aliases = { "pumpkins" }, usage = "[size]", @@ -253,7 +253,7 @@ public class GenerationCommands { int affected = editSession.makePumpkinPatches(player.getPosition(), size); player.print(affected + " pumpkin patches created."); } - + @Command( aliases = { "/pyramid" }, usage = " ", @@ -270,13 +270,13 @@ public class GenerationCommands { Pattern block = we.getBlockPattern(player, args.getString(0)); int size = Math.max(1, args.getInteger(1)); Vector pos = session.getPlacementPosition(player); - + int affected = editSession.makePyramid(pos, block, size, true); - + player.findFreePosition(); player.print(affected + " block(s) have been created."); } - + @Command( aliases = { "/hpyramid" }, usage = " ", @@ -293,9 +293,9 @@ public class GenerationCommands { Pattern block = we.getBlockPattern(player, args.getString(0)); int size = Math.max(1, args.getInteger(1)); Vector pos = session.getPlacementPosition(player); - + int affected = editSession.makePyramid(pos, block, size, false); - + player.findFreePosition(); player.print(affected + " block(s) have been created."); } diff --git a/src/main/java/com/sk89q/worldedit/commands/HistoryCommands.java b/src/main/java/com/sk89q/worldedit/commands/HistoryCommands.java index d003cd08e..7ab3f1493 100644 --- a/src/main/java/com/sk89q/worldedit/commands/HistoryCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/HistoryCommands.java @@ -50,7 +50,7 @@ public class HistoryCommands { } else { player.checkPermission("worldedit.history.undo.other"); LocalSession sess = we.getSession(args.getString(1)); - if (sess == null){ + if (sess == null) { player.printError("Unable to find session for " + args.getString(1)); break; } @@ -65,7 +65,7 @@ public class HistoryCommands { } } } - + @Command( aliases = { "/redo", "redo" }, usage = "[times] [player]", @@ -79,7 +79,7 @@ public class HistoryCommands { throws WorldEditException { int times = Math.max(1, args.getInteger(0, 1)); - + for (int i = 0; i < times; ++i) { EditSession redone; if (args.argsLength() < 2) { @@ -87,7 +87,7 @@ public class HistoryCommands { } else { player.checkPermission("worldedit.history.redo.other"); LocalSession sess = we.getSession(args.getString(1)); - if (sess == null){ + if (sess == null) { player.printError("Unable to find session for " + args.getString(1)); break; } diff --git a/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java b/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java index a7ca0cd2b..af0a9a57f 100644 --- a/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java @@ -74,7 +74,6 @@ public class NavigationCommands { } else { player.print((ascentLevels != 1) ? "Ascended " + Integer.toString(ascentLevels) + " levels." : "Ascended a level."); } - } @Command( @@ -103,7 +102,6 @@ public class NavigationCommands { } else { player.print((descentLevels != 1) ? "Descended " + Integer.toString(descentLevels) + " levels." : "Descended a level."); } - } @Command( @@ -128,7 +126,7 @@ public class NavigationCommands { player.printError("No free spot above you found."); } } - + @Command( aliases = { "thru" }, usage = "", diff --git a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java index be47ecde2..b49ad4a60 100644 --- a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit.commands; - import java.util.Set; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; @@ -57,16 +56,16 @@ public class RegionCommands { throws WorldEditException { Pattern pattern = we.getBlockPattern(player, args.getString(0)); - + int affected; - + if (pattern instanceof SingleBlockPattern) { affected = editSession.setBlocks(session.getSelection(player.getWorld()), ((SingleBlockPattern) pattern).getBlock()); } else { affected = editSession.setBlocks(session.getSelection(player.getWorld()), pattern); } - + player.print(affected + " block(s) have been changed."); } @@ -101,10 +100,10 @@ public class RegionCommands { } else { affected = editSession.replaceBlocks(session.getSelection(player.getWorld()), from, to); } - + player.print(affected + " block(s) have been replaced."); } - + @Command( aliases = { "/overlay" }, usage = "", @@ -169,7 +168,7 @@ public class RegionCommands { } else { affected = editSession.makeCuboidWalls(session.getSelection(player.getWorld()), pattern); } - + player.print(affected + " block(s) have been changed."); } @@ -220,7 +219,7 @@ public class RegionCommands { HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0)); int affected = heightMap.applyFilter(filter, iterations); player.print("Terrain's height map smoothed. " + affected + " block(s) changed."); - + } @Command( @@ -267,7 +266,6 @@ public class RegionCommands { player.print(affected + " blocks moved."); } - @Command( aliases = { "/stack" }, diff --git a/src/main/java/com/sk89q/worldedit/commands/ScriptingCommands.java b/src/main/java/com/sk89q/worldedit/commands/ScriptingCommands.java index 143315777..d5888c04c 100644 --- a/src/main/java/com/sk89q/worldedit/commands/ScriptingCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/ScriptingCommands.java @@ -48,7 +48,7 @@ public class ScriptingCommands { String[] scriptArgs = args.getSlice(1); String name = args.getString(0); - + if (!player.hasPermission("worldedit.scripting.execute." + name)) { player.printError("You don't have permission to use that script."); return; @@ -58,8 +58,8 @@ public class ScriptingCommands { File dir = we.getWorkingDirectoryFile(we.getConfiguration().scriptsDir); File f = we.getSafeOpenFile(player, dir, name, "js", - new String[] {"js"}); - + new String[] { "js" }); + we.runScript(player, f, scriptArgs); } @@ -77,12 +77,12 @@ public class ScriptingCommands { throws WorldEditException { String lastScript = session.getLastScript(); - + if (!player.hasPermission("worldedit.scripting.execute." + lastScript)) { player.printError("You don't have permission to use that script."); return; } - + if (lastScript == null) { player.printError("Use /cs with a script name first."); return; @@ -92,8 +92,8 @@ public class ScriptingCommands { File dir = we.getWorkingDirectoryFile(we.getConfiguration().scriptsDir); File f = we.getSafeOpenFile(player, dir, lastScript, "js", - new String[] {"js"}); - + new String[] { "js" }); + we.runScript(player, f, scriptArgs); } } diff --git a/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java b/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java index 06423ae09..f48f042b4 100644 --- a/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java @@ -87,11 +87,11 @@ public class SelectionCommands { throws WorldEditException { Vector pos; - if(args.argsLength() == 1) { - if(args.getString(0).matches("-?\\d+,-?\\d+,-?\\d+")) { + if (args.argsLength() == 1) { + if (args.getString(0).matches("-?\\d+,-?\\d+,-?\\d+")) { String[] coords = args.getString(0).split(","); - pos = new Vector(Integer.parseInt(coords[0]), - Integer.parseInt(coords[1]), + pos = new Vector(Integer.parseInt(coords[0]), + Integer.parseInt(coords[1]), Integer.parseInt(coords[2])); } else { player.printError("Invalid coordinates " + args.getString(0)); @@ -106,7 +106,6 @@ public class SelectionCommands { return; } - session.getRegionSelector(player.getWorld()) .explainSecondarySelection(player, session, pos); } @@ -124,7 +123,7 @@ public class SelectionCommands { throws WorldEditException { Vector pos = player.getBlockTrace(300); - + if (pos != null) { if (!session.getRegionSelector(player.getWorld()) .selectPrimary(pos)) { @@ -152,7 +151,7 @@ public class SelectionCommands { throws WorldEditException { Vector pos = player.getBlockTrace(300); - + if (pos != null) { if (!session.getRegionSelector(player.getWorld()) .selectSecondary(pos)) { @@ -208,11 +207,11 @@ public class SelectionCommands { selector.selectPrimary(min); selector.selectSecondary(max); session.setRegionSelector(player.getWorld(), selector); - + session.dispatchCUISelection(player); } - + @Command( aliases = { "/wand" }, usage = "", @@ -228,7 +227,7 @@ public class SelectionCommands { player.giveItem(we.getConfiguration().wandItem, 1); player.print("Left click: select pos #1; Right click: select pos #2"); } - + @Command( aliases = { "toggleeditwand" }, usage = "", @@ -242,7 +241,7 @@ public class SelectionCommands { throws WorldEditException { session.setToolControl(!session.isToolControlEnabled()); - + if (session.isToolControlEnabled()) { player.print("Edit wand enabled."); } else { @@ -281,13 +280,13 @@ public class SelectionCommands { } catch (RegionOperationException e) { player.printError(e.getMessage()); } - + return; } int change = args.getInteger(0); int reverseChange = 0; - + switch (args.argsLength()) { case 2: // Either a reverse amount or a direction @@ -300,7 +299,7 @@ public class SelectionCommands { } break; - case 3: + case 3: // Both reverse amount and direction reverseChange = args.getInteger(1) * -1; dir = we.getDirection(player, @@ -313,16 +312,16 @@ public class SelectionCommands { Region region = session.getSelection(player.getWorld()); int oldSize = region.getArea(); region.expand(dir.multiply(change)); - + if (reverseChange != 0) { region.expand(dir.multiply(reverseChange)); } session.getRegionSelector().learnChanges(); int newSize = region.getArea(); - + session.getRegionSelector().explainRegionAdjust(player, session); - + player.print("Region expanded " + (newSize - oldSize) + " blocks."); } @@ -353,7 +352,7 @@ public class SelectionCommands { } break; - case 3: + case 3: // Both reverse amount and direction reverseChange = args.getInteger(1) * -1; dir = we.getDirection(player, args.getString(2).toLowerCase()); @@ -371,9 +370,9 @@ public class SelectionCommands { } session.getRegionSelector().learnChanges(); int newSize = region.getArea(); - + session.getRegionSelector().explainRegionAdjust(player, session); - + player.print("Region contracted " + (oldSize - newSize) + " blocks."); } catch (RegionOperationException e) { player.printError(e.getMessage()); @@ -392,7 +391,7 @@ public class SelectionCommands { LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { Vector dir; - + int change = args.getInteger(0); if (args.argsLength() == 2) { dir = we.getDirection(player, args.getString(1).toLowerCase()); @@ -405,9 +404,9 @@ public class SelectionCommands { region.expand(dir.multiply(change)); region.contract(dir.multiply(change)); session.getRegionSelector().learnChanges(); - + session.getRegionSelector().explainRegionAdjust(player, session); - + player.print("Region shifted."); } catch (RegionOperationException e) { player.printError(e.getMessage()); @@ -429,13 +428,13 @@ public class SelectionCommands { int change = args.getInteger(0); Region region = session.getSelection(player.getWorld()); - + try { if (!args.hasFlag('h')) { region.expand((new Vector(0, 1, 0)).multiply(change)); region.expand((new Vector(0, -1, 0)).multiply(change)); } - + if (!args.hasFlag('v')) { region.expand((new Vector(1, 0, 0)).multiply(change)); region.expand((new Vector(-1, 0, 0)).multiply(change)); @@ -444,9 +443,9 @@ public class SelectionCommands { } session.getRegionSelector().learnChanges(); - + session.getRegionSelector().explainRegionAdjust(player, session); - + player.print("Region outset."); } catch (RegionOperationException e) { player.printError(e.getMessage()); @@ -468,12 +467,12 @@ public class SelectionCommands { int change = args.getInteger(0); Region region = session.getSelection(player.getWorld()); - + if (!args.hasFlag('h')) { region.contract((new Vector(0, 1, 0)).multiply(change)); region.contract((new Vector(0, -1, 0)).multiply(change)); } - + if (!args.hasFlag('v')) { region.contract((new Vector(1, 0, 0)).multiply(change)); region.contract((new Vector(-1, 0, 0)).multiply(change)); @@ -482,9 +481,9 @@ public class SelectionCommands { } session.getRegionSelector().learnChanges(); - + session.getRegionSelector().explainRegionAdjust(player, session); - + player.print("Region inset."); } @@ -506,11 +505,11 @@ public class SelectionCommands { .add(1, 1, 1); player.print("Type: " + session.getRegionSelector().getTypeName()); - + for (String line : session.getRegionSelector().getInformationLines()) { player.print(line); } - + player.print("Size: " + size); player.print("Cuboid distance: " + region.getMaximumPoint().distance(region.getMinimumPoint())); player.print("# of blocks: " + region.getArea()); @@ -548,28 +547,28 @@ public class SelectionCommands { throws WorldEditException { List> distribution = - editSession.getBlockDistribution(session.getSelection(player.getWorld())); - + editSession.getBlockDistribution(session.getSelection(player.getWorld())); + Logger logger = Logger.getLogger("Minecraft.WorldEdit"); - + if (distribution.size() > 0) { // *Should* always be true int size = session.getSelection(player.getWorld()).getArea(); - + player.print("# total blocks: " + size); - + if (args.hasFlag('c')) { logger.info("Block distribution (req. by " + player.getName() + "):"); logger.info("# total blocks: " + size); } - + for (Countable c : distribution) { BlockType block = BlockType.fromID(c.getID()); String str = String.format("%-7s (%.3f%%) %s #%d", String.valueOf(c.getAmount()), - c.getAmount() / (double)size * 100, + c.getAmount() / (double) size * 100, block == null ? "Unknown" : block.getName(), c.getID()); player.print(str); - + if (args.hasFlag('c')) { logger.info(str); } diff --git a/src/main/java/com/sk89q/worldedit/commands/SnapshotCommands.java b/src/main/java/com/sk89q/worldedit/commands/SnapshotCommands.java index ca99a1ec0..a8d5afd9a 100644 --- a/src/main/java/com/sk89q/worldedit/commands/SnapshotCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/SnapshotCommands.java @@ -65,9 +65,9 @@ public class SnapshotCommands { List snapshots = config.snapshotRepo.getSnapshots(true, player.getWorld().getName()); if (snapshots.size() > 0) { - + int num = args.argsLength() > 0 ? Math.min(40, Math.max(5, args.getInteger(0))) : 5; - + player.print("Snapshots for world: '" + player.getWorld().getName() + "'"); for (byte i = 0; i < Math.min(num, snapshots.size()); i++) { player.print((i + 1) + ". " + snapshots.get(i).getName()); diff --git a/src/main/java/com/sk89q/worldedit/commands/SuperPickaxeCommands.java b/src/main/java/com/sk89q/worldedit/commands/SuperPickaxeCommands.java index 6e5847ee2..c7b9351a9 100644 --- a/src/main/java/com/sk89q/worldedit/commands/SuperPickaxeCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/SuperPickaxeCommands.java @@ -32,7 +32,7 @@ import com.sk89q.worldedit.tools.AreaPickaxe; import com.sk89q.worldedit.tools.RecursivePickaxe; import com.sk89q.worldedit.tools.SinglePickaxe; -public class SuperPickaxeCommands { +public class SuperPickaxeCommands { @Command( aliases = { "single" }, usage = "", @@ -49,7 +49,7 @@ public class SuperPickaxeCommands { session.enableSuperPickAxe(); player.print("Mode changed. Left click with a pickaxe. // to disable."); } - + @Command( aliases = { "area" }, usage = "", @@ -64,17 +64,17 @@ public class SuperPickaxeCommands { LocalConfiguration config = we.getConfiguration(); int range = args.getInteger(0); - + if (range > config.maxSuperPickaxeSize) { player.printError("Maximum range: " + config.maxSuperPickaxeSize); return; } - + session.setSuperPickaxe(new AreaPickaxe(range)); session.enableSuperPickAxe(); player.print("Mode changed. Left click with a pickaxe. // to disable."); } - + @Command( aliases = { "recur", "recursive" }, usage = "", @@ -89,12 +89,12 @@ public class SuperPickaxeCommands { LocalConfiguration config = we.getConfiguration(); double range = args.getDouble(0); - + if (range > config.maxSuperPickaxeSize) { player.printError("Maximum range: " + config.maxSuperPickaxeSize); return; } - + session.setSuperPickaxe(new RecursivePickaxe(range)); session.enableSuperPickAxe(); player.print("Mode changed. Left click with a pickaxe. // to disable."); diff --git a/src/main/java/com/sk89q/worldedit/commands/ToolCommands.java b/src/main/java/com/sk89q/worldedit/commands/ToolCommands.java index ad531ae1c..4bab80519 100644 --- a/src/main/java/com/sk89q/worldedit/commands/ToolCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/ToolCommands.java @@ -138,7 +138,7 @@ public class ToolCommands { LocalConfiguration config = we.getConfiguration(); int range = args.getInteger(1); - + if (range > config.maxSuperPickaxeSize) { player.printError("Maximum range: " + config.maxSuperPickaxeSize); return; @@ -159,7 +159,7 @@ public class ToolCommands { LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { } - + @Command( aliases = { "deltree" }, usage = "", diff --git a/src/main/java/com/sk89q/worldedit/commands/ToolUtilCommands.java b/src/main/java/com/sk89q/worldedit/commands/ToolUtilCommands.java index e3e209bd5..12796b251 100644 --- a/src/main/java/com/sk89q/worldedit/commands/ToolUtilCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/ToolUtilCommands.java @@ -151,14 +151,14 @@ public class ToolUtilCommands { throws WorldEditException { LocalConfiguration config = we.getConfiguration(); - + int radius = args.getInteger(0); if (radius > config.maxBrushRadius) { player.printError("Maximum allowed brush radius: " + config.maxBrushRadius); return; } - + session.getBrushTool(player.getItemInHand()).setSize(radius); player.print("Brush size set."); } diff --git a/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java b/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java index 4e6826644..1c22e0d8f 100644 --- a/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/UtilityCommands.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit.commands; - import java.util.Set; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; @@ -97,7 +96,7 @@ public class UtilityCommands { } player.print(affected + " block(s) have been created."); } - + @Command( aliases = { "/drain" }, usage = "", @@ -260,7 +259,7 @@ public class UtilityCommands { } player.print(affected + " block(s) have been replaced."); } - + @Command( aliases = { "/snow", "snow" }, usage = "[radius]", @@ -332,7 +331,7 @@ public class UtilityCommands { throws WorldEditException { LocalConfiguration config = we.getConfiguration(); - + int defaultRadius = config.maxRadius != -1 ? Math.min(40, config.maxRadius) : 40; int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : defaultRadius; @@ -378,12 +377,12 @@ public class UtilityCommands { String typeStr = args.getString(0); int radius = args.getInteger(1); - + if (radius < -1) { player.printError("Use -1 to remove all entities in loaded chunks"); return; } - + EntityType type = null; if (typeStr.matches("arrows?")) { diff --git a/src/main/java/com/sk89q/worldedit/commands/WorldEditCommands.java b/src/main/java/com/sk89q/worldedit/commands/WorldEditCommands.java index cea659686..32c9567c1 100644 --- a/src/main/java/com/sk89q/worldedit/commands/WorldEditCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/WorldEditCommands.java @@ -34,7 +34,7 @@ import com.sk89q.worldedit.WorldEditException; public class WorldEditCommands { private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); - + @Command( aliases = { "version", "ver" }, usage = "", diff --git a/src/main/java/com/sk89q/worldedit/cui/CUIEvent.java b/src/main/java/com/sk89q/worldedit/cui/CUIEvent.java index a98393570..5e0b62ec0 100644 --- a/src/main/java/com/sk89q/worldedit/cui/CUIEvent.java +++ b/src/main/java/com/sk89q/worldedit/cui/CUIEvent.java @@ -21,5 +21,6 @@ package com.sk89q.worldedit.cui; public interface CUIEvent { public String getTypeId(); + public String[] getParameters(); } diff --git a/src/main/java/com/sk89q/worldedit/cui/SelectionMinMaxEvent.java b/src/main/java/com/sk89q/worldedit/cui/SelectionMinMaxEvent.java index 92f7f765a..767f1b0a5 100644 --- a/src/main/java/com/sk89q/worldedit/cui/SelectionMinMaxEvent.java +++ b/src/main/java/com/sk89q/worldedit/cui/SelectionMinMaxEvent.java @@ -23,7 +23,7 @@ public class SelectionMinMaxEvent implements CUIEvent { protected int min; protected int max; - + public SelectionMinMaxEvent(int min, int max) { this.min = min; this.max = max; diff --git a/src/main/java/com/sk89q/worldedit/cui/SelectionPointEvent.java b/src/main/java/com/sk89q/worldedit/cui/SelectionPointEvent.java index f6d024b1d..09937ab48 100644 --- a/src/main/java/com/sk89q/worldedit/cui/SelectionPointEvent.java +++ b/src/main/java/com/sk89q/worldedit/cui/SelectionPointEvent.java @@ -26,7 +26,7 @@ public class SelectionPointEvent implements CUIEvent { protected int id; protected Vector pos; protected int area; - + public SelectionPointEvent(int id, Vector pos, int area) { this.id = id; this.pos = pos; diff --git a/src/main/java/com/sk89q/worldedit/cui/SelectionShapeEvent.java b/src/main/java/com/sk89q/worldedit/cui/SelectionShapeEvent.java index 3430fdd38..ec5e03c31 100644 --- a/src/main/java/com/sk89q/worldedit/cui/SelectionShapeEvent.java +++ b/src/main/java/com/sk89q/worldedit/cui/SelectionShapeEvent.java @@ -20,9 +20,9 @@ package com.sk89q.worldedit.cui; public class SelectionShapeEvent implements CUIEvent { - + protected String shapeName; - + public SelectionShapeEvent(String shapeName) { this.shapeName = shapeName; } diff --git a/src/main/java/com/sk89q/worldedit/data/Chunk.java b/src/main/java/com/sk89q/worldedit/data/Chunk.java index 626f13002..d2f411a58 100644 --- a/src/main/java/com/sk89q/worldedit/data/Chunk.java +++ b/src/main/java/com/sk89q/worldedit/data/Chunk.java @@ -17,7 +17,6 @@ * along with this program. If not, see . */ - package com.sk89q.worldedit.data; import java.util.List; @@ -38,7 +37,7 @@ public class Chunk { private byte[] data; private int rootX; private int rootZ; - private Map> tileEntities; + private Map> tileEntities; /** * Construct the chunk with a compound tag. @@ -49,13 +48,13 @@ public class Chunk { public Chunk(CompoundTag tag) throws DataException { rootTag = tag; - blocks = ((ByteArrayTag)getChildTag( + blocks = ((ByteArrayTag) getChildTag( rootTag.getValue(), "Blocks", ByteArrayTag.class)).getValue(); - data = ((ByteArrayTag)getChildTag( + data = ((ByteArrayTag) getChildTag( rootTag.getValue(), "Data", ByteArrayTag.class)).getValue(); - rootX = ((IntTag)getChildTag( + rootX = ((IntTag) getChildTag( rootTag.getValue(), "xPos", IntTag.class)).getValue(); - rootZ = ((IntTag)getChildTag( + rootZ = ((IntTag) getChildTag( rootTag.getValue(), "zPos", IntTag.class)).getValue(); if (blocks.length != 32768) { @@ -121,37 +120,37 @@ public class Chunk { * @throws DataException */ private void populateTileEntities() throws DataException { - List tags = (List)((ListTag)getChildTag( + List tags = (List) ((ListTag) getChildTag( rootTag.getValue(), "TileEntities", ListTag.class)) .getValue(); - tileEntities = new HashMap>(); + tileEntities = new HashMap>(); for (Tag tag : tags) { if (!(tag instanceof CompoundTag)) { throw new InvalidFormatException("CompoundTag expected in TileEntities"); } - CompoundTag t = (CompoundTag)tag; + CompoundTag t = (CompoundTag) tag; int x = 0; int y = 0; int z = 0; - Map values = new HashMap(); + Map values = new HashMap(); - for (Map.Entry entry : t.getValue().entrySet()) { + for (Map.Entry entry : t.getValue().entrySet()) { if (entry.getKey().equals("x")) { if (entry.getValue() instanceof IntTag) { - x = ((IntTag)entry.getValue()).getValue(); + x = ((IntTag) entry.getValue()).getValue(); } } else if (entry.getKey().equals("y")) { if (entry.getValue() instanceof IntTag) { - y = ((IntTag)entry.getValue()).getValue(); + y = ((IntTag) entry.getValue()).getValue(); } } else if (entry.getKey().equals("z")) { if (entry.getValue() instanceof IntTag) { - z = ((IntTag)entry.getValue()).getValue(); + z = ((IntTag) entry.getValue()).getValue(); } } @@ -172,9 +171,10 @@ public class Chunk { * @return * @throws DataException */ - private Map getBlockTileEntity(Vector pos) throws DataException { - if (tileEntities == null) + private Map getBlockTileEntity(Vector pos) throws DataException { + if (tileEntities == null) { populateTileEntities(); + } return tileEntities.get(new BlockVector(pos)); } @@ -208,8 +208,8 @@ public class Chunk { } if (block instanceof TileEntityBlock) { - Map tileEntity = getBlockTileEntity(pos); - ((TileEntityBlock)block).fromTileEntityNBT(tileEntity); + Map tileEntity = getBlockTileEntity(pos); + ((TileEntityBlock) block).fromTileEntityNBT(tileEntity); } return block; @@ -224,7 +224,7 @@ public class Chunk { * @return child tag * @throws InvalidFormatException */ - public static Tag getChildTag(Map items, String key, + public static Tag getChildTag(Map items, String key, Class expected) throws InvalidFormatException { if (!items.containsKey(key)) { @@ -232,8 +232,7 @@ public class Chunk { } Tag tag = items.get(key); if (!expected.isInstance(tag)) { - throw new InvalidFormatException( - key + " tag is not of tag type " + expected.getName()); + throw new InvalidFormatException(key + " tag is not of tag type " + expected.getName()); } return tag; } diff --git a/src/main/java/com/sk89q/worldedit/data/ChunkStore.java b/src/main/java/com/sk89q/worldedit/data/ChunkStore.java index bd2cfaa76..4c5574b27 100644 --- a/src/main/java/com/sk89q/worldedit/data/ChunkStore.java +++ b/src/main/java/com/sk89q/worldedit/data/ChunkStore.java @@ -36,8 +36,8 @@ public abstract class ChunkStore { * @return */ public static BlockVector2D toChunk(Vector pos) { - int chunkX = (int)Math.floor(pos.getBlockX() / 16.0); - int chunkZ = (int)Math.floor(pos.getBlockZ() / 16.0); + int chunkX = (int) Math.floor(pos.getBlockX() / 16.0); + int chunkZ = (int) Math.floor(pos.getBlockZ() / 16.0); return new BlockVector2D(chunkX, chunkZ); } diff --git a/src/main/java/com/sk89q/worldedit/data/FileMcRegionChunkStore.java b/src/main/java/com/sk89q/worldedit/data/FileMcRegionChunkStore.java index 21835491c..674d21f28 100644 --- a/src/main/java/com/sk89q/worldedit/data/FileMcRegionChunkStore.java +++ b/src/main/java/com/sk89q/worldedit/data/FileMcRegionChunkStore.java @@ -49,7 +49,7 @@ public class FileMcRegionChunkStore extends McRegionChunkStore { if (!file.exists()) { file = new File(path, "DIM-1" + File.separator + fileName); } - + try { return new FileInputStream(file); } catch (FileNotFoundException e) { diff --git a/src/main/java/com/sk89q/worldedit/data/ForwardSeekableInputStream.java b/src/main/java/com/sk89q/worldedit/data/ForwardSeekableInputStream.java index e0f2c00a3..48b2865e1 100644 --- a/src/main/java/com/sk89q/worldedit/data/ForwardSeekableInputStream.java +++ b/src/main/java/com/sk89q/worldedit/data/ForwardSeekableInputStream.java @@ -23,10 +23,10 @@ import java.io.IOException; import java.io.InputStream; public class ForwardSeekableInputStream extends InputStream { - + protected InputStream parent; protected long position = 0; - + public ForwardSeekableInputStream(InputStream parent) { this.parent = parent; } @@ -83,18 +83,18 @@ public class ForwardSeekableInputStream extends InputStream { position += skipped; return skipped; } - + public void seek(long n) throws IOException { long diff = n - position; - + if (diff < 0) { throw new IOException("Can't seek backwards"); } - + if (diff == 0) { return; } - + if (skip(diff) < diff) { throw new IOException("Failed to seek " + diff + " bytes"); } diff --git a/src/main/java/com/sk89q/worldedit/data/LegacyChunkStore.java b/src/main/java/com/sk89q/worldedit/data/LegacyChunkStore.java index 9e6a0684c..c10f20b53 100644 --- a/src/main/java/com/sk89q/worldedit/data/LegacyChunkStore.java +++ b/src/main/java/com/sk89q/worldedit/data/LegacyChunkStore.java @@ -96,14 +96,14 @@ public abstract class LegacyChunkStore extends ChunkStore { + tag.getClass().getName()); } - Map children = (Map)((CompoundTag)tag).getValue(); + Map children = (Map) ((CompoundTag) tag).getValue(); CompoundTag rootTag = null; // Find Level tag - for (Map.Entry entry : children.entrySet()) { + for (Map.Entry entry : children.entrySet()) { if (entry.getKey().equals("Level")) { if (entry.getValue() instanceof CompoundTag) { - rootTag = (CompoundTag)entry.getValue(); + rootTag = (CompoundTag) entry.getValue(); break; } else { throw new ChunkStoreException("CompoundTag expected for 'Level'; got " @@ -130,7 +130,7 @@ public abstract class LegacyChunkStore extends ChunkStore { * @return */ private static int divisorMod(int a, int n) { - return (int)(a - n * Math.floor(Math.floor(a) / (double)n)); + return (int) (a - n * Math.floor(Math.floor(a) / (double) n)); } /** diff --git a/src/main/java/com/sk89q/worldedit/data/McRegionChunkStore.java b/src/main/java/com/sk89q/worldedit/data/McRegionChunkStore.java index dfc958c1f..f6106cf1e 100644 --- a/src/main/java/com/sk89q/worldedit/data/McRegionChunkStore.java +++ b/src/main/java/com/sk89q/worldedit/data/McRegionChunkStore.java @@ -30,7 +30,7 @@ import com.sk89q.worldedit.Vector2D; public abstract class McRegionChunkStore extends ChunkStore { protected String curFilename = null; protected McRegionReader cachedReader = null; - + /** * Get the filename of a region file. * @@ -40,12 +40,12 @@ public abstract class McRegionChunkStore extends ChunkStore { public static String getFilename(Vector2D pos) { int x = pos.getBlockX(); int z = pos.getBlockZ(); - + String filename = "r." + (x >> 5) + "." + (z >> 5) + ".mcr"; return filename; } - + protected McRegionReader getReader(Vector2D pos, String worldname) throws DataException, IOException { String filename = getFilename(pos); if (curFilename != null) { @@ -67,7 +67,7 @@ public abstract class McRegionChunkStore extends ChunkStore { @Override public CompoundTag getChunkTag(Vector2D pos, String worldname) throws DataException, IOException { - + McRegionReader reader = getReader(pos, worldname); InputStream stream = reader.getChunkInputStream(pos); NBTInputStream nbt = new NBTInputStream(stream); @@ -80,14 +80,14 @@ public abstract class McRegionChunkStore extends ChunkStore { + tag.getClass().getName()); } - Map children = (Map)((CompoundTag)tag).getValue(); + Map children = (Map) ((CompoundTag) tag).getValue(); CompoundTag rootTag = null; // Find Level tag - for (Map.Entry entry : children.entrySet()) { + for (Map.Entry entry : children.entrySet()) { if (entry.getKey().equals("Level")) { if (entry.getValue() instanceof CompoundTag) { - rootTag = (CompoundTag)entry.getValue(); + rootTag = (CompoundTag) entry.getValue(); break; } else { throw new ChunkStoreException("CompoundTag expected for 'Level'; got " @@ -115,7 +115,6 @@ public abstract class McRegionChunkStore extends ChunkStore { */ protected abstract InputStream getInputStream(String name, String worldname) throws IOException, DataException; - /** * Close resources. diff --git a/src/main/java/com/sk89q/worldedit/data/McRegionReader.java b/src/main/java/com/sk89q/worldedit/data/McRegionReader.java index de0081f20..5339a0f03 100644 --- a/src/main/java/com/sk89q/worldedit/data/McRegionReader.java +++ b/src/main/java/com/sk89q/worldedit/data/McRegionReader.java @@ -74,7 +74,7 @@ public class McRegionReader { protected ForwardSeekableInputStream stream; protected DataInputStream dataStream; - + protected int offsets[]; /** @@ -87,10 +87,10 @@ public class McRegionReader { public McRegionReader(InputStream stream) throws DataException, IOException { this.stream = new ForwardSeekableInputStream(stream); this.dataStream = new DataInputStream(this.stream); - + readHeader(); } - + /** * Read the header. * @@ -119,13 +119,13 @@ public class McRegionReader { int x = pos.getBlockX() & 31; int z = pos.getBlockZ() & 31; - + if (x < 0 || x >= 32 || z < 0 || z >= 32) { throw new DataException("MCRegion file does not contain " + x + "," + z); } int offset = getOffset(x, z); - + // The chunk hasn't been generated if (offset == 0) { return null; @@ -143,7 +143,7 @@ public class McRegionReader { } byte version = dataStream.readByte(); - + if (version == VERSION_GZIP) { byte[] data = new byte[length - 1]; if (dataStream.read(data) < length - 1) { @@ -185,7 +185,7 @@ public class McRegionReader { public boolean hasChunk(int x, int z) { return getOffset(x, z) != 0; } - + /** * Close the stream. * @@ -194,4 +194,4 @@ public class McRegionReader { public void close() throws IOException { stream.close(); } -} \ No newline at end of file +} diff --git a/src/main/java/com/sk89q/worldedit/data/TrueZipLegacyChunkStore.java b/src/main/java/com/sk89q/worldedit/data/TrueZipLegacyChunkStore.java index 72c57c2c4..8a5ec0f7b 100644 --- a/src/main/java/com/sk89q/worldedit/data/TrueZipLegacyChunkStore.java +++ b/src/main/java/com/sk89q/worldedit/data/TrueZipLegacyChunkStore.java @@ -112,10 +112,9 @@ public class TrueZipLegacyChunkStore extends LegacyChunkStore { // So not there either... if (testEntry == null) { - for (Enumeration e = zip.entries(); - e.hasMoreElements(); ) { + for (Enumeration e = zip.entries(); e.hasMoreElements();) { - testEntry = (ZipEntry)e.nextElement(); + testEntry = (ZipEntry) e.nextElement(); // Whoo, found level.dat! if (pattern.matcher(testEntry.getName()).matches()) { diff --git a/src/main/java/com/sk89q/worldedit/data/TrueZipMcRegionChunkStore.java b/src/main/java/com/sk89q/worldedit/data/TrueZipMcRegionChunkStore.java index 8aec143d3..308d9a7c1 100644 --- a/src/main/java/com/sk89q/worldedit/data/TrueZipMcRegionChunkStore.java +++ b/src/main/java/com/sk89q/worldedit/data/TrueZipMcRegionChunkStore.java @@ -100,8 +100,7 @@ public class TrueZipMcRegionChunkStore extends McRegionChunkStore { Pattern pattern = Pattern.compile(".*\\.mcr$"); // World pattern Pattern worldPattern = Pattern.compile(worldname + "\\$"); - for (Enumeration e = zip.entries(); - e.hasMoreElements();) { + for (Enumeration e = zip.entries(); e.hasMoreElements(); ) { ZipEntry testEntry = (ZipEntry) e.nextElement(); // Check for world if (worldPattern.matcher(worldname).matches()) { @@ -158,8 +157,7 @@ public class TrueZipMcRegionChunkStore extends McRegionChunkStore { @Override @SuppressWarnings("unchecked") public boolean isValid() { - for (Enumeration e = zip.entries(); - e.hasMoreElements();) { + for (Enumeration e = zip.entries(); e.hasMoreElements(); ) { ZipEntry testEntry = e.nextElement(); diff --git a/src/main/java/com/sk89q/worldedit/data/ZippedLegacyChunkStore.java b/src/main/java/com/sk89q/worldedit/data/ZippedLegacyChunkStore.java index a960658d3..c084aef59 100644 --- a/src/main/java/com/sk89q/worldedit/data/ZippedLegacyChunkStore.java +++ b/src/main/java/com/sk89q/worldedit/data/ZippedLegacyChunkStore.java @@ -109,10 +109,9 @@ public class ZippedLegacyChunkStore extends LegacyChunkStore { // So not there either... if (testEntry == null) { - for (Enumeration e = zip.entries(); - e.hasMoreElements(); ) { + for (Enumeration e = zip.entries(); e.hasMoreElements(); ) { - testEntry = (ZipEntry)e.nextElement(); + testEntry = (ZipEntry) e.nextElement(); // Whoo, found level.dat! if (pattern.matcher(testEntry.getName()).matches()) { diff --git a/src/main/java/com/sk89q/worldedit/data/ZippedMcRegionChunkStore.java b/src/main/java/com/sk89q/worldedit/data/ZippedMcRegionChunkStore.java index 32dd1b9e0..7737ddc99 100644 --- a/src/main/java/com/sk89q/worldedit/data/ZippedMcRegionChunkStore.java +++ b/src/main/java/com/sk89q/worldedit/data/ZippedMcRegionChunkStore.java @@ -95,8 +95,7 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore { } } else { Pattern pattern = Pattern.compile(".*\\.mcr$"); - for (Enumeration e = zip.entries(); - e.hasMoreElements();) { + for (Enumeration e = zip.entries(); e.hasMoreElements(); ) { ZipEntry testEntry = (ZipEntry) e.nextElement(); // Check for world if (testEntry.getName().startsWith(worldname + "/")) { @@ -105,10 +104,10 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore { name = folder + "/" + name; break; } - + } } - + // Check if world is found if (folder == null) { throw new MissingWorldException("Target world is not present in ZIP.", worldname); @@ -152,8 +151,7 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore { @Override public boolean isValid() { - for (Enumeration e = zip.entries(); - e.hasMoreElements();) { + for (Enumeration e = zip.entries(); e.hasMoreElements(); ) { ZipEntry testEntry = e.nextElement(); diff --git a/src/main/java/com/sk89q/worldedit/dev/DocumentationPrinter.java b/src/main/java/com/sk89q/worldedit/dev/DocumentationPrinter.java index 6b57b21c6..f08f57933 100644 --- a/src/main/java/com/sk89q/worldedit/dev/DocumentationPrinter.java +++ b/src/main/java/com/sk89q/worldedit/dev/DocumentationPrinter.java @@ -45,7 +45,7 @@ import com.sk89q.worldedit.commands.UtilityCommands; public class DocumentationPrinter { public static void main(String[] args) throws IOException { File commandsDir = new File(args[0]); - + List> commandClasses = getCommandClasses(commandsDir); System.out.println("Writing permissions wiki table..."); @@ -55,7 +55,7 @@ public class DocumentationPrinter { System.out.println("Done!"); } - + private static List> getCommandClasses(File dir) { List> classes = new ArrayList>(); @@ -72,7 +72,7 @@ public class DocumentationPrinter { classes.add(ToolUtilCommands.class); classes.add(ToolCommands.class); classes.add(UtilityCommands.class); - + /*for (File f : dir.listFiles()) { if (!f.getName().matches("^.*\\.java$")) { continue; @@ -91,10 +91,10 @@ public class DocumentationPrinter { classes.add(cls); }*/ - + return classes; - } - + } + private static void writePermissionsWikiTable(List> commandClasses) throws IOException { FileOutputStream stream = null; @@ -108,26 +108,26 @@ public class DocumentationPrinter { } } } - + private static void _writePermissionsWikiTable(PrintStream stream, List> commandClasses, String prefix) { - + for (Class cls : commandClasses) { for (Method method : cls.getMethods()) { if (!method.isAnnotationPresent(Command.class)) { continue; } - + Command cmd = method.getAnnotation(Command.class); - + stream.println("|-"); stream.print("| " + prefix + cmd.aliases()[0]); stream.print(" || "); - + if (method.isAnnotationPresent(CommandPermissions.class)) { CommandPermissions perms = - method.getAnnotation(CommandPermissions.class); - + method.getAnnotation(CommandPermissions.class); + String[] permKeys = perms.value(); for (int i = 0; i < permKeys.length; ++i) { if (i > 0) { @@ -136,9 +136,9 @@ public class DocumentationPrinter { stream.print(permKeys[i]); } } - + stream.print(" || "); - + boolean firstAlias = true; if (cmd.aliases().length != 0) { for (String alias : cmd.aliases()) { @@ -164,8 +164,8 @@ public class DocumentationPrinter { if (method.isAnnotationPresent(NestedCommand.class)) { NestedCommand nested = - method.getAnnotation(NestedCommand.class); - + method.getAnnotation(NestedCommand.class); + Class[] nestedClasses = nested.value(); _writePermissionsWikiTable(stream, Arrays.asList(nestedClasses), @@ -174,7 +174,7 @@ public class DocumentationPrinter { } } } - + private static void writeBukkitYAML(List> commandClasses) throws IOException { FileOutputStream stream = null; @@ -188,7 +188,7 @@ public class DocumentationPrinter { } } } - + private static void _writeBukkitYAML(PrintStream stream, List> commandClasses) { @@ -196,7 +196,7 @@ public class DocumentationPrinter { stream.println("main: com.sk89q.worldedit.bukkit.WorldEditPlugin"); stream.println("version: ${project.version}"); stream.println("commands:"); - + for (Class cls : commandClasses) { for (Method method : cls.getMethods()) { if (!method.isAnnotationPresent(Command.class)) { diff --git a/src/main/java/com/sk89q/worldedit/expression/Expression.java b/src/main/java/com/sk89q/worldedit/expression/Expression.java index 3155067f3..fbcb3685e 100644 --- a/src/main/java/com/sk89q/worldedit/expression/Expression.java +++ b/src/main/java/com/sk89q/worldedit/expression/Expression.java @@ -100,8 +100,7 @@ public class Expression { try { return root.getValue(); - } - catch (ReturnException e) { + } catch (ReturnException e) { return e.getValue(); } } diff --git a/src/main/java/com/sk89q/worldedit/expression/lexer/Lexer.java b/src/main/java/com/sk89q/worldedit/expression/lexer/Lexer.java index 769a8a5f3..21a6b163d 100644 --- a/src/main/java/com/sk89q/worldedit/expression/lexer/Lexer.java +++ b/src/main/java/com/sk89q/worldedit/expression/lexer/Lexer.java @@ -51,50 +51,50 @@ public class Lexer { } private final DecisionTree operatorTree = new DecisionTree(null, - '+', new DecisionTree("+", - '=', new DecisionTree("+="), - '+', new DecisionTree("++") - ), - '-', new DecisionTree("-", - '=', new DecisionTree("-="), - '-', new DecisionTree("--") - ), - '*', new DecisionTree("*", - '=', new DecisionTree("*="), - '*', new DecisionTree("**") - ), - '/', new DecisionTree("/", - '=', new DecisionTree("/=") - ), - '%', new DecisionTree("%", - '=', new DecisionTree("%=") - ), - '^', new DecisionTree("^", - '=', new DecisionTree("^=") - ), - '=', new DecisionTree("=", - '=', new DecisionTree("==") - ), - '!', new DecisionTree("!", - '=', new DecisionTree("!=") - ), - '<', new DecisionTree("<", - '<', new DecisionTree("<<"), - '=', new DecisionTree("<=") - ), - '>', new DecisionTree(">", - '>', new DecisionTree(">>"), - '=', new DecisionTree(">=") - ), - '&', new DecisionTree(null, // not implemented - '&', new DecisionTree("&&") - ), - '|', new DecisionTree(null, // not implemented - '|', new DecisionTree("||") - ), - '~', new DecisionTree("~", - '=', new DecisionTree("~=") - ) + '+', new DecisionTree("+", + '=', new DecisionTree("+="), + '+', new DecisionTree("++") + ), + '-', new DecisionTree("-", + '=', new DecisionTree("-="), + '-', new DecisionTree("--") + ), + '*', new DecisionTree("*", + '=', new DecisionTree("*="), + '*', new DecisionTree("**") + ), + '/', new DecisionTree("/", + '=', new DecisionTree("/=") + ), + '%', new DecisionTree("%", + '=', new DecisionTree("%=") + ), + '^', new DecisionTree("^", + '=', new DecisionTree("^=") + ), + '=', new DecisionTree("=", + '=', new DecisionTree("==") + ), + '!', new DecisionTree("!", + '=', new DecisionTree("!=") + ), + '<', new DecisionTree("<", + '<', new DecisionTree("<<"), + '=', new DecisionTree("<=") + ), + '>', new DecisionTree(">", + '>', new DecisionTree(">>"), + '=', new DecisionTree(">=") + ), + '&', new DecisionTree(null, // not implemented + '&', new DecisionTree("&&") + ), + '|', new DecisionTree(null, // not implemented + '|', new DecisionTree("||") + ), + '~', new DecisionTree("~", + '=', new DecisionTree("~=") + ) ); private static final Set characterTokens = new HashSet(); diff --git a/src/main/java/com/sk89q/worldedit/expression/parser/Parser.java b/src/main/java/com/sk89q/worldedit/expression/parser/Parser.java index eb727b3db..af4ac9514 100644 --- a/src/main/java/com/sk89q/worldedit/expression/parser/Parser.java +++ b/src/main/java/com/sk89q/worldedit/expression/parser/Parser.java @@ -182,8 +182,7 @@ public class Parser { if (peek().id() == ';') { ++position; break; - } - else { + } else { break loop; } @@ -205,8 +204,7 @@ public class Parser { break loop; } break; - } - else { + } else { break loop; } } @@ -253,7 +251,7 @@ public class Parser { } else { RValue variable = variables.get(identifierToken.value); if (variable == null) { - if (next instanceof OperatorToken && ((OperatorToken)next).operator.equals("=")) { + if (next instanceof OperatorToken && ((OperatorToken) next).operator.equals("=")) { // Ugly hack to make temporary variables work while not sacrificing error reporting. variables.put(identifierToken.value, variable = new Variable(0)); } else { diff --git a/src/main/java/com/sk89q/worldedit/expression/parser/ParserProcessors.java b/src/main/java/com/sk89q/worldedit/expression/parser/ParserProcessors.java index 6814f985d..3c8f0d371 100644 --- a/src/main/java/com/sk89q/worldedit/expression/parser/ParserProcessors.java +++ b/src/main/java/com/sk89q/worldedit/expression/parser/ParserProcessors.java @@ -35,32 +35,32 @@ public final class ParserProcessors { final Object[][][] binaryOpsLA = { { - { "^", "pow" }, - { "**", "pow" }, + { "^", "pow" }, + { "**", "pow" }, }, { - { "*", "mul" }, - { "/", "div" }, - { "%", "mod" }, + { "*", "mul" }, + { "/", "div" }, + { "%", "mod" }, }, { - { "+", "add" }, - { "-", "sub" }, + { "+", "add" }, + { "-", "sub" }, }, { - { "<<", "shl" }, - { ">>", "shr" }, + { "<<", "shl" }, + { ">>", "shr" }, }, { - { "<", "lth" }, - { ">", "gth" }, - { "<=", "leq" }, - { ">=", "geq" }, + { "<", "lth" }, + { ">", "gth" }, + { "<=", "leq" }, + { ">=", "geq" }, }, { - { "==", "equ" }, - { "!=", "neq" }, - { "~=", "near" }, + { "==", "equ" }, + { "!=", "neq" }, + { "~=", "near" }, }, { { "&&", "and" }, @@ -71,13 +71,13 @@ public final class ParserProcessors { }; final Object[][][] binaryOpsRA = { { - { "=", "ass" }, - { "+=", "aadd" }, - { "-=", "asub" }, - { "*=", "amul" }, - { "/=", "adiv" }, - { "%=", "amod" }, - { "^=", "aexp" }, + { "=", "ass" }, + { "+=", "aadd" }, + { "-=", "asub" }, + { "*=", "amul" }, + { "/=", "adiv" }, + { "%=", "amod" }, + { "^=", "aexp" }, }, }; @@ -230,19 +230,17 @@ public final class ParserProcessors { final Identifiable last = input.removeLast(); if (last instanceof OperatorToken) { - postfixes.addLast(new UnaryOperator(last.getPosition(), "x"+((OperatorToken)last).operator)); - } - else if (last instanceof UnaryOperator) { - postfixes.addLast(new UnaryOperator(last.getPosition(), "x"+((UnaryOperator)last).operator)); - } - else { + postfixes.addLast(new UnaryOperator(last.getPosition(), "x" + ((OperatorToken) last).operator)); + } else if (last instanceof UnaryOperator) { + postfixes.addLast(new UnaryOperator(last.getPosition(), "x" + ((UnaryOperator) last).operator)); + } else { center = last; break; } } while (true); if (!(center instanceof RValue)) { - throw new ParserException(center.getPosition(), "Expected expression, found "+center); + throw new ParserException(center.getPosition(), "Expected expression, found " + center); } input.addAll(postfixes); diff --git a/src/main/java/com/sk89q/worldedit/expression/parser/UnaryOperator.java b/src/main/java/com/sk89q/worldedit/expression/parser/UnaryOperator.java index 5f03e83bd..0c3915d16 100644 --- a/src/main/java/com/sk89q/worldedit/expression/parser/UnaryOperator.java +++ b/src/main/java/com/sk89q/worldedit/expression/parser/UnaryOperator.java @@ -13,7 +13,7 @@ public class UnaryOperator extends PseudoToken { public UnaryOperator(OperatorToken operatorToken) { this(operatorToken.getPosition(), operatorToken.operator); } - + public UnaryOperator(int position, String operator) { super(position); this.operator = operator; diff --git a/src/main/java/com/sk89q/worldedit/expression/runtime/Conditional.java b/src/main/java/com/sk89q/worldedit/expression/runtime/Conditional.java index be6b263c7..1ffcbea95 100644 --- a/src/main/java/com/sk89q/worldedit/expression/runtime/Conditional.java +++ b/src/main/java/com/sk89q/worldedit/expression/runtime/Conditional.java @@ -17,8 +17,7 @@ public class Conditional extends Node { public double getValue() throws EvaluationException { if (condition.getValue() > 0.0) { return truePart.getValue(); - } - else { + } else { return falsePart == null ? 0 : falsePart.getValue(); } } @@ -31,9 +30,9 @@ public class Conditional extends Node { @Override public String toString() { if (falsePart == null) { - return "if ("+condition+") { "+truePart+" }"; + return "if (" + condition + ") { " + truePart + " }"; } else { - return "if ("+condition+") { "+truePart+" } else { "+falsePart+" }"; + return "if (" + condition + ") { " + truePart + " } else { " + falsePart + " }"; } } diff --git a/src/main/java/com/sk89q/worldedit/expression/runtime/For.java b/src/main/java/com/sk89q/worldedit/expression/runtime/For.java index d97e18248..b135ba5ee 100644 --- a/src/main/java/com/sk89q/worldedit/expression/runtime/For.java +++ b/src/main/java/com/sk89q/worldedit/expression/runtime/For.java @@ -28,8 +28,7 @@ public class For extends Node { try { ret = body.getValue(); - } - catch (BreakException e) { + } catch (BreakException e) { if (e.doContinue) { continue; } else { @@ -48,7 +47,7 @@ public class For extends Node { @Override public String toString() { - return "for ("+init+"; "+condition+"; "+increment+") { "+body+" }"; + return "for (" + init + "; " + condition + "; " + increment + ") { " + body + " }"; } //TODO: optimizer diff --git a/src/main/java/com/sk89q/worldedit/expression/runtime/Functions.java b/src/main/java/com/sk89q/worldedit/expression/runtime/Functions.java index d5817764c..4fcfa5ffa 100644 --- a/src/main/java/com/sk89q/worldedit/expression/runtime/Functions.java +++ b/src/main/java/com/sk89q/worldedit/expression/runtime/Functions.java @@ -34,7 +34,7 @@ import com.sk89q.worldedit.expression.runtime.Function.Dynamic; */ public final class Functions { private static class Overload { - private final Method method; + private final Method method; private final int mask; private final boolean isSetter; @@ -90,14 +90,12 @@ public final class Functions { } } - public static final Function getFunction(int position, String name, RValue... args) throws NoSuchMethodException { final Method getter = getMethod(name, false, args); try { Method setter = getMethod(name, true, args); return new LValueFunction(position, getter, setter, args); - } - catch (NoSuchMethodException e) { + } catch (NoSuchMethodException e) { return new Function(position, getter, args); } } diff --git a/src/main/java/com/sk89q/worldedit/expression/runtime/RValue.java b/src/main/java/com/sk89q/worldedit/expression/runtime/RValue.java index 1d84d79a1..33bf0f4df 100644 --- a/src/main/java/com/sk89q/worldedit/expression/runtime/RValue.java +++ b/src/main/java/com/sk89q/worldedit/expression/runtime/RValue.java @@ -28,5 +28,6 @@ import com.sk89q.worldedit.expression.Identifiable; */ public interface RValue extends Identifiable { public double getValue() throws EvaluationException; + public Node optimize() throws EvaluationException; } diff --git a/src/main/java/com/sk89q/worldedit/expression/runtime/Return.java b/src/main/java/com/sk89q/worldedit/expression/runtime/Return.java index 64d3d6ff4..7f3faa02b 100644 --- a/src/main/java/com/sk89q/worldedit/expression/runtime/Return.java +++ b/src/main/java/com/sk89q/worldedit/expression/runtime/Return.java @@ -21,7 +21,7 @@ public class Return extends Node { @Override public String toString() { - return "return "+value; + return "return " + value; } //TODO: optimizer diff --git a/src/main/java/com/sk89q/worldedit/expression/runtime/While.java b/src/main/java/com/sk89q/worldedit/expression/runtime/While.java index 4fb93cc22..fb5c2a279 100644 --- a/src/main/java/com/sk89q/worldedit/expression/runtime/While.java +++ b/src/main/java/com/sk89q/worldedit/expression/runtime/While.java @@ -27,8 +27,7 @@ public class While extends Node { try { ret = body.getValue(); - } - catch (BreakException e) { + } catch (BreakException e) { if (e.doContinue) { continue; } else { @@ -45,8 +44,7 @@ public class While extends Node { try { ret = body.getValue(); - } - catch (BreakException e) { + } catch (BreakException e) { if (e.doContinue) { continue; } else { @@ -67,9 +65,9 @@ public class While extends Node { @Override public String toString() { if (footChecked) { - return "do { "+body+" } while ("+condition+")"; + return "do { " + body + " } while (" + condition + ")"; } else { - return "while ("+condition+") { "+body+" }"; + return "while (" + condition + ") { " + body + " }"; } } diff --git a/src/main/java/com/sk89q/worldedit/filtering/GaussianKernel.java b/src/main/java/com/sk89q/worldedit/filtering/GaussianKernel.java index 468f159f2..cbb757636 100644 --- a/src/main/java/com/sk89q/worldedit/filtering/GaussianKernel.java +++ b/src/main/java/com/sk89q/worldedit/filtering/GaussianKernel.java @@ -28,7 +28,7 @@ import java.awt.image.Kernel; */ public class GaussianKernel extends Kernel { - + /** * Constructor of the kernel * @@ -42,13 +42,13 @@ public class GaussianKernel extends Kernel { private static float[] createKernel(int radius, double sigma) { int diameter = radius * 2 + 1; - float[] data = new float[diameter*diameter]; + float[] data = new float[diameter * diameter]; double sigma22 = 2 * sigma * sigma; double constant = Math.PI * sigma22; for (int y = -radius; y <= radius; ++y) { for (int x = -radius; x <= radius; ++x) { - data[(y+radius) * diameter + x+radius] = (float) (Math.exp(-(x * x + y * y) / sigma22) / constant); + data[(y + radius) * diameter + x + radius] = (float) (Math.exp(-(x * x + y * y) / sigma22) / constant); } } diff --git a/src/main/java/com/sk89q/worldedit/filtering/HeightMapFilter.java b/src/main/java/com/sk89q/worldedit/filtering/HeightMapFilter.java index 400408377..96eb6546f 100644 --- a/src/main/java/com/sk89q/worldedit/filtering/HeightMapFilter.java +++ b/src/main/java/com/sk89q/worldedit/filtering/HeightMapFilter.java @@ -75,7 +75,7 @@ public class HeightMapFilter { * @param height * @return the modified heightmap */ - public int[] filter(int[] inData, int width, int height ) { + public int[] filter(int[] inData, int width, int height) { int index = 0; float[] matrix = kernel.getKernelData(null); int[] outData = new int[inData.length]; @@ -84,7 +84,7 @@ public class HeightMapFilter { int kw = kernel.getWidth(); int kox = kernel.getXOrigin(); int koy = kernel.getYOrigin(); - + for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { float z = 0; @@ -92,9 +92,10 @@ public class HeightMapFilter { for (int ky = 0; ky < kh; ++ky) { int offsetY = y + ky - koy; // Clamp coordinates inside data - if (offsetY < 0 || offsetY >= height) + if (offsetY < 0 || offsetY >= height) { offsetY = y; - + } + offsetY *= width; int matrixOffset = ky * kw; @@ -104,9 +105,10 @@ public class HeightMapFilter { int offsetX = x + kx - kox; // Clamp coordinates inside data - if (offsetX < 0 || offsetX >= width) - offsetX = x; - + if (offsetX < 0 || offsetX >= width) { + offsetX = x; + } + z += f * inData[offsetY + offsetX]; } } diff --git a/src/main/java/com/sk89q/worldedit/filtering/LinearKernel.java b/src/main/java/com/sk89q/worldedit/filtering/LinearKernel.java index 77b01432d..50a46bc1f 100644 --- a/src/main/java/com/sk89q/worldedit/filtering/LinearKernel.java +++ b/src/main/java/com/sk89q/worldedit/filtering/LinearKernel.java @@ -35,9 +35,9 @@ public class LinearKernel extends Kernel { private static float[] createKernel(int radius) { int diameter = radius * 2 + 1; - float[] data = new float[diameter*diameter]; - - for (int i = 0; i < data.length; data[i++] = 1.0f/data.length) ; + float[] data = new float[diameter * diameter]; + + for (int i = 0; i < data.length; data[i++] = 1.0f / data.length) ; return data; } diff --git a/src/main/java/com/sk89q/worldedit/masks/BlockTypeMask.java b/src/main/java/com/sk89q/worldedit/masks/BlockTypeMask.java index 9ecc2ce34..57f812cd8 100644 --- a/src/main/java/com/sk89q/worldedit/masks/BlockTypeMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/BlockTypeMask.java @@ -31,24 +31,24 @@ import com.sk89q.worldedit.Vector; */ public class BlockTypeMask implements Mask { protected Set types; - + public BlockTypeMask() { types = new HashSet(); } - + public BlockTypeMask(Set types) { this.types = types; } - + public BlockTypeMask(int type) { this(); add(type); } - + public void add(int type) { types.add(type); } - + public boolean matches(EditSession editSession, Vector pos) { return types.contains(editSession.getBlockType(pos)); } diff --git a/src/main/java/com/sk89q/worldedit/masks/RegionMask.java b/src/main/java/com/sk89q/worldedit/masks/RegionMask.java index 3baf919dd..000f8eec8 100644 --- a/src/main/java/com/sk89q/worldedit/masks/RegionMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/RegionMask.java @@ -24,9 +24,9 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.regions.Region; public class RegionMask implements Mask { - + private Region region; - + public RegionMask(Region region) { this.region = region; } diff --git a/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java b/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java index c29747a3b..87a34cff7 100644 --- a/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java @@ -40,7 +40,7 @@ public class UnderOverlayMask implements Mask { this.overlay = overlay; } - public void addAll(Set ids){ + public void addAll(Set ids) { this.ids.addAll(ids); } @@ -50,4 +50,3 @@ public class UnderOverlayMask implements Mask { } } - diff --git a/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java b/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java index c8ddc1663..9f706c27e 100644 --- a/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java +++ b/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java @@ -97,7 +97,7 @@ public class CuboidRegion implements Region { Vector min = getMinimumPoint(); Vector max = getMaximumPoint(); - return (int)(max.getX() - min.getX() + 1); + return (int) (max.getX() - min.getX() + 1); } /** @@ -109,7 +109,7 @@ public class CuboidRegion implements Region { Vector min = getMinimumPoint(); Vector max = getMaximumPoint(); - return (int)(max.getY() - min.getY() + 1); + return (int) (max.getY() - min.getY() + 1); } /** @@ -121,7 +121,7 @@ public class CuboidRegion implements Region { Vector min = getMinimumPoint(); Vector max = getMaximumPoint(); - return (int)(max.getZ() - min.getZ() + 1); + return (int) (max.getZ() - min.getZ() + 1); } /** diff --git a/src/main/java/com/sk89q/worldedit/regions/CuboidRegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/CuboidRegionSelector.java index 367d2b2ca..171d13d3c 100644 --- a/src/main/java/com/sk89q/worldedit/regions/CuboidRegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/CuboidRegionSelector.java @@ -44,7 +44,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion return false; } pos1 = pos.toBlockVector(); - region.setPos1(pos1); + region.setPos1(pos1); return true; } @@ -65,7 +65,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion } else { player.print("First position set to " + pos1 + "."); } - + session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getArea())); } @@ -77,7 +77,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion } else { player.print("Second position set to " + pos2 + "."); } - + session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getArea())); } @@ -89,15 +89,15 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos2, getArea())); } } - + public BlockVector getPrimaryPosition() throws IncompleteRegionException { if (pos1 == null) { throw new IncompleteRegionException(); } - + return pos1; } - + public boolean isDefined() { return pos1 != null && pos2 != null; } @@ -106,7 +106,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion if (pos1 == null || pos2 == null) { throw new IncompleteRegionException(); } - + return region; } @@ -118,7 +118,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion pos1 = region.getPos1().toBlockVector(); pos2 = region.getPos2().toBlockVector(); } - + public void clear() { pos1 = null; pos2 = null; @@ -130,15 +130,15 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion public List getInformationLines() { List lines = new ArrayList(); - + if (pos1 != null) { lines.add("Position 1: " + pos1); } - + if (pos2 != null) { lines.add("Position 2: " + pos2); } - + return lines; } @@ -159,7 +159,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion if (pos1 != null && pos2 != null) { return region.getArea(); } - + return -1; } } diff --git a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java index 3c5656d90..9056480b5 100644 --- a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java +++ b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java @@ -43,7 +43,7 @@ public class Polygonal2DRegion implements Region { protected int minY; protected int maxY; protected boolean hasY = false; - + /** * Construct the region. */ @@ -54,7 +54,7 @@ public class Polygonal2DRegion implements Region { hasY = false; recalculate(); } - + /** * Construct the region. * @@ -69,7 +69,7 @@ public class Polygonal2DRegion implements Region { hasY = true; recalculate(); } - + /** * Get the list of points. * @@ -78,7 +78,7 @@ public class Polygonal2DRegion implements Region { public List getPoints() { return Collections.unmodifiableList(points); } - + /** * Recalculate the bounding box of this polygonal region. This should be * called after points have been changed. @@ -89,12 +89,12 @@ public class Polygonal2DRegion implements Region { max = new BlockVector(0, 0, 0); return; } - + int minX = points.get(0).getBlockX(); int minZ = points.get(0).getBlockZ(); int maxX = points.get(0).getBlockX(); int maxZ = points.get(0).getBlockZ(); - + for (BlockVector2D v : points) { int x = v.getBlockX(); int z = v.getBlockZ(); @@ -112,7 +112,7 @@ public class Polygonal2DRegion implements Region { min = new BlockVector(minX, minY, minZ); max = new BlockVector(maxX, maxY, maxZ); } - + /** * Add a point to the list. * @@ -122,7 +122,7 @@ public class Polygonal2DRegion implements Region { points.add(pt.toBlockVector2D()); recalculate(); } - + /** * Add a point to the list. * @@ -132,7 +132,7 @@ public class Polygonal2DRegion implements Region { points.add(pt); recalculate(); } - + /** * Add a point to the list. * @@ -142,7 +142,7 @@ public class Polygonal2DRegion implements Region { points.add(new BlockVector2D(pt.getBlockX(), pt.getBlockZ())); recalculate(); } - + /** * Set the minimum Y. * @@ -153,7 +153,7 @@ public class Polygonal2DRegion implements Region { minY = y; recalculate(); } - + /** * Se the maximum Y. * @@ -198,7 +198,7 @@ public class Polygonal2DRegion implements Region { j = i; } - return (int)Math.floor(Math.abs(area * 0.5) + return (int) Math.floor(Math.abs(area * 0.5) * (maxY - minY + 1)); } @@ -238,7 +238,7 @@ public class Polygonal2DRegion implements Region { if (change.getBlockX() != 0 || change.getBlockZ() != 0) { throw new RegionOperationException("Polygons can only be expanded vertically."); } - + int changeY = change.getBlockY(); if (changeY > 0) { maxY += changeY; @@ -257,7 +257,7 @@ public class Polygonal2DRegion implements Region { if (change.getBlockX() != 0 || change.getBlockZ() != 0) { throw new RegionOperationException("Polygons can only be contracted vertically."); } - + int changeY = change.getBlockY(); if (changeY > 0) { minY += changeY; @@ -291,11 +291,11 @@ public class Polygonal2DRegion implements Region { int targetX = pt.getBlockX(); //wide int targetY = pt.getBlockY(); //height int targetZ = pt.getBlockZ(); //depth - + if (targetY < minY || targetY > maxY) { return false; } - + boolean inside = false; int npoints = points.size(); int xNew, zNew; @@ -328,7 +328,7 @@ public class Polygonal2DRegion implements Region { } if (x1 <= targetX && targetX <= x2) { crossproduct = ((long) targetZ - (long) z1) * (long) (x2 - x1) - - ((long) z2 - (long) z1) * (long) (targetX - x1); + - ((long) z2 - (long) z1) * (long) (targetX - x1); if (crossproduct == 0) { if ((z1 <= targetZ) == (targetZ <= z2)) return true; //on edge } else if (crossproduct < 0 && (x1 != targetX)) { @@ -341,7 +341,7 @@ public class Polygonal2DRegion implements Region { return inside; } - + /** * Get a list of chunks. * @@ -366,7 +366,7 @@ public class Polygonal2DRegion implements Region { return chunks; } - + /** * Return the number of points. * @@ -375,7 +375,7 @@ public class Polygonal2DRegion implements Region { public int size() { return points.size(); } - + /** * Expand the height of the polygon to fit the specified Y. * @@ -395,7 +395,7 @@ public class Polygonal2DRegion implements Region { maxY = y; return true; } - + return false; } @@ -406,7 +406,7 @@ public class Polygonal2DRegion implements Region { */ public Iterator iterator() { return new Polygonal2DRegionIterator(this); - + /* Incomplete iterator. Where's my yield?! @@ -501,7 +501,7 @@ public class Polygonal2DRegion implements Region { protected int curZ; protected int curY; protected BlockVector next; - + public Polygonal2DRegionIterator(Polygonal2DRegion region) { points = new ArrayList(region.points); Vector min = region.getMinimumPoint(); @@ -520,13 +520,13 @@ public class Polygonal2DRegion implements Region { next = null; findNext(); } - + private void findNext() { if (i >= n) { next = null; return; } - + if (next != null && curY <= maxY) { ++curY; next = new BlockVector(curX, curY, curZ); @@ -536,8 +536,8 @@ public class Polygonal2DRegion implements Region { } else { return; } - } - + } + while (i < n) { curZ = i / (maxX - minX + 1) + minZ; curX = (i % (maxX - minX + 1)) + minX; @@ -548,7 +548,7 @@ public class Polygonal2DRegion implements Region { } ++i; } - + next = null; } diff --git a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegionSelector.java index 3021ee8e3..8141587f4 100644 --- a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegionSelector.java @@ -40,7 +40,7 @@ import com.sk89q.worldedit.cui.SelectionShapeEvent; public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedRegion { protected BlockVector pos1; protected Polygonal2DRegion region = new Polygonal2DRegion(); - + public boolean selectPrimary(Vector pos) { if (pos1 != null && pos1.equals(pos)) { return false; @@ -51,7 +51,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedR region.expandY(pos.getBlockY()); return true; } - + public boolean selectSecondary(Vector pos) { if (region.size() > 0) { List points = region.getPoints(); @@ -60,12 +60,12 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedR && lastPoint.getBlockZ() == pos.getBlockZ()) { return false; } - + if (points.size() >= 20) { return false; } } - + region.addPoint(pos); region.expandY(pos.getBlockY()); return true; @@ -101,7 +101,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedR if (!isDefined()) { throw new IncompleteRegionException(); } - + return region; } @@ -141,7 +141,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedR public int getArea() { return region.getArea(); } - + public int getPointCount() { return region.getPoints().size(); } diff --git a/src/main/java/com/sk89q/worldedit/regions/Region.java b/src/main/java/com/sk89q/worldedit/regions/Region.java index f1ccef15a..1f4c0d3bf 100644 --- a/src/main/java/com/sk89q/worldedit/regions/Region.java +++ b/src/main/java/com/sk89q/worldedit/regions/Region.java @@ -35,36 +35,42 @@ public interface Region extends Iterable { * @return min. point */ public Vector getMinimumPoint(); + /** * Get the upper point of a region. * * @return max. point */ public Vector getMaximumPoint(); + /** * Get the number of blocks in the region. * * @return number of blocks */ public int getArea(); + /** * Get X-size. * * @return width */ public int getWidth(); + /** * Get Y-size. * * @return height */ public int getHeight(); + /** * Get Z-size. * * @return length */ public int getLength(); + /** * Expand the region. * @@ -72,6 +78,7 @@ public interface Region extends Iterable { * @throws RegionOperationException */ public void expand(Vector change) throws RegionOperationException; + /** * Contract the region. * @@ -79,6 +86,7 @@ public interface Region extends Iterable { * @throws RegionOperationException */ public void contract(Vector change) throws RegionOperationException; + /** * Returns true based on whether the region contains the point, * @@ -86,6 +94,7 @@ public interface Region extends Iterable { * @return */ public boolean contains(Vector pt); + /** * Get a list of chunks. * diff --git a/src/main/java/com/sk89q/worldedit/regions/RegionOperationException.java b/src/main/java/com/sk89q/worldedit/regions/RegionOperationException.java index c0047f285..a64da3087 100644 --- a/src/main/java/com/sk89q/worldedit/regions/RegionOperationException.java +++ b/src/main/java/com/sk89q/worldedit/regions/RegionOperationException.java @@ -23,7 +23,7 @@ import com.sk89q.worldedit.WorldEditException; public class RegionOperationException extends WorldEditException { private static final long serialVersionUID = -6180325009115242142L; - + public RegionOperationException(String msg) { super(msg); } diff --git a/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java index 6fb6e3cec..1da9965d3 100644 --- a/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java @@ -39,7 +39,7 @@ public interface RegionSelector { * @return true if something changed */ public boolean selectPrimary(Vector pos); - + /** * Called when the second point is selected. * @@ -55,7 +55,7 @@ public interface RegionSelector { * @param session * @param pos */ - public void explainPrimarySelection(LocalPlayer player, + public void explainPrimarySelection(LocalPlayer player, LocalSession session, Vector pos); /** @@ -67,7 +67,7 @@ public interface RegionSelector { */ public void explainSecondarySelection(LocalPlayer player, LocalSession session, Vector pos); - + /** * The the player information about the region's changes. This may resend * all the defining region information if needed. @@ -76,7 +76,7 @@ public interface RegionSelector { * @param session */ public void explainRegionAdjust(LocalPlayer player, LocalSession session); - + /** * Get the primary position. * @@ -84,7 +84,7 @@ public interface RegionSelector { * @throws IncompleteRegionException */ public BlockVector getPrimaryPosition() throws IncompleteRegionException; - + /** * Get the selection. * @@ -92,52 +92,52 @@ public interface RegionSelector { * @throws IncompleteRegionException */ public Region getRegion() throws IncompleteRegionException; - + /** * Get the region even if it's not fully defined. * * @return */ public Region getIncompleteRegion(); - + /** * Returns whether the region has been fully defined. * * @return */ public boolean isDefined(); - + /** * Get the number of blocks inside the region. * * @return number of blocks or -1 if undefined */ public int getArea(); - + /** * Update the selector with changes to the region. */ public void learnChanges(); - + /** * Clear the selection. */ public void clear(); - + /** * Get a lowercase name of this region selector type. * * @return */ public String getTypeName(); - + /** * Get a lowecase space-less ID. * * @return */ public String getTypeId(); - + /** * Get lines of information about the selection. * diff --git a/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java b/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java index ab6df36e1..a4d98d603 100644 --- a/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java +++ b/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java @@ -45,14 +45,14 @@ import com.sk89q.worldedit.patterns.Pattern; public class CraftScriptContext extends CraftScriptEnvironment { private List editSessions = new ArrayList(); private String[] args; - + public CraftScriptContext(WorldEdit controller, ServerInterface server, LocalConfiguration config, LocalSession session, LocalPlayer player, String[] args) { super(controller, server, config, session, player); this.args = args; } - + /** * Get an edit session. Every subsequent call returns a new edit session. * Usually you only need to use one edit session. @@ -67,7 +67,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { editSessions.add(editSession); return editSession; } - + /** * Get the player. * @@ -76,7 +76,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { public LocalPlayer getPlayer() { return player; } - + /** * Get the player's session. * @@ -85,7 +85,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { public LocalSession getSession() { return session; } - + /** * Get the configuration for WorldEdit. * @@ -94,7 +94,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { public LocalConfiguration getConfiguration() { return config; } - + /** * Get a list of edit sessions that have been created. * @@ -103,7 +103,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { public List getEditSessions() { return Collections.unmodifiableList(editSessions); } - + /** * Print a regular message to the user. * @@ -112,7 +112,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { public void print(String msg) { player.print(msg); } - + /** * Print an error message to the user. * @@ -121,7 +121,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { public void error(String msg) { player.printError(msg); } - + /** * Print an raw message to the user. * @@ -172,7 +172,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { throws UnknownItemException, DisallowedItemException { return controller.getBlock(player, id, false); } - + /** * Get a list of blocks as a set. This returns a Pattern. * @@ -199,7 +199,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { throws UnknownItemException, DisallowedItemException { return controller.getBlockIDs(player, list, allBlocksAllowed); } - + /** * Gets the path to a file. This method will check to see if the filename * has valid characters and has an extension. It also prevents directory @@ -218,7 +218,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { File dir = controller.getWorkingDirectoryFile(folder); return controller.getSafeOpenFile(player, dir, filename, null, null); } - + /** * Gets the path to a file for opening. This method will check to see if the * filename has valid characters and has an extension. It also prevents @@ -241,7 +241,7 @@ public class CraftScriptContext extends CraftScriptEnvironment { File dir = controller.getWorkingDirectoryFile(folder); return controller.getSafeOpenFile(player, dir, filename, defaultExt, exts); } - + /** * Gets the path to a file for saving. This method will check to see if the * filename has valid characters and has an extension. It also prevents diff --git a/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEngine.java b/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEngine.java index 04d24e2ba..5c3aa1d51 100644 --- a/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEngine.java +++ b/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEngine.java @@ -24,7 +24,9 @@ import javax.script.ScriptException; public interface CraftScriptEngine { public void setTimeLimit(int milliseconds); + public int getTimeLimit(); + public Object evaluate(String script, String filename, Map args) throws ScriptException, Throwable; } diff --git a/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEnvironment.java b/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEnvironment.java index 2c98aaf39..d06b73c1c 100644 --- a/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEnvironment.java +++ b/src/main/java/com/sk89q/worldedit/scripting/CraftScriptEnvironment.java @@ -31,7 +31,7 @@ public abstract class CraftScriptEnvironment { protected LocalConfiguration config; protected LocalSession session; protected ServerInterface server; - + public CraftScriptEnvironment(WorldEdit controller, ServerInterface server, LocalConfiguration config, LocalSession session, LocalPlayer player) { this.controller = controller; diff --git a/src/main/java/com/sk89q/worldedit/scripting/RhinoContextFactory.java b/src/main/java/com/sk89q/worldedit/scripting/RhinoContextFactory.java index bbbeb36af..44e7e1f7c 100644 --- a/src/main/java/com/sk89q/worldedit/scripting/RhinoContextFactory.java +++ b/src/main/java/com/sk89q/worldedit/scripting/RhinoContextFactory.java @@ -23,11 +23,11 @@ import org.mozilla.javascript.*; public class RhinoContextFactory extends ContextFactory { protected int timeLimit; - + public RhinoContextFactory(int timeLimit) { this.timeLimit = timeLimit; } - + @Override protected Context makeContext() { RhinoContext cx = new RhinoContext(this); @@ -37,9 +37,9 @@ public class RhinoContextFactory extends ContextFactory { @Override protected void observeInstructionCount(Context cx, int instructionCount) { - RhinoContext mcx = (RhinoContext)cx; + RhinoContext mcx = (RhinoContext) cx; long currentTime = System.currentTimeMillis(); - + if (currentTime - mcx.startTime > timeLimit) { throw new Error("Script timed out (" + timeLimit + "ms)"); } @@ -48,7 +48,7 @@ public class RhinoContextFactory extends ContextFactory { @Override protected Object doTopCall(Callable callable, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { - RhinoContext mcx = (RhinoContext)cx; + RhinoContext mcx = (RhinoContext) cx; mcx.startTime = System.currentTimeMillis(); return super.doTopCall(callable, cx, scope, thisObj, args); @@ -56,9 +56,9 @@ public class RhinoContextFactory extends ContextFactory { private static class RhinoContext extends Context { long startTime; - + public RhinoContext(ContextFactory factory) { super(factory); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java b/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java index ec27bf5e1..4f907af30 100644 --- a/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java +++ b/src/main/java/com/sk89q/worldedit/scripting/RhinoCraftScriptEngine.java @@ -41,7 +41,7 @@ public class RhinoCraftScriptEngine implements CraftScriptEngine { Context cx = factory.enterContext(); ScriptableObject scriptable = new ImporterTopLevel(cx); Scriptable scope = cx.initStandardObjects(scriptable); - + for (Map.Entry entry : args.entrySet()) { ScriptableObject.putProperty(scope, entry.getKey(), Context.javaToJS(entry.getValue(), scope)); @@ -57,20 +57,20 @@ public class RhinoCraftScriptEngine implements CraftScriptEngine { throw ((WrappedException) e).getCause(); } } - + String msg; int line = (line = e.lineNumber()) == 0 ? -1 : line; - + if (e instanceof JavaScriptException) { msg = String.valueOf(((JavaScriptException) e).getValue()); } else { msg = e.getMessage(); } - + ScriptException scriptException = - new ScriptException(msg, e.sourceName(), line); + new ScriptException(msg, e.sourceName(), line); scriptException.initCause(e); - + throw scriptException; } finally { Context.exit(); diff --git a/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngine.java b/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngine.java index fc20ae163..5d227c370 100644 --- a/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngine.java +++ b/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngine.java @@ -39,28 +39,28 @@ public class RhinoScriptEngine extends AbstractScriptEngine { public Object eval(String script, ScriptContext context) throws ScriptException { - + Scriptable scope = setupScope(cx, context); - + String filename = (filename = (String) get(ScriptEngine.FILENAME)) == null ? "" : filename; - + try { return cx.evaluateString(scope, script, filename, 1, null); } catch (RhinoException e) { String msg; int line = (line = e.lineNumber()) == 0 ? -1 : line; - + if (e instanceof JavaScriptException) { msg = String.valueOf(((JavaScriptException) e).getValue()); } else { msg = e.getMessage(); } - + ScriptException scriptException = - new ScriptException(msg, e.sourceName(), line); + new ScriptException(msg, e.sourceName(), line); scriptException.initCause(e); - + throw scriptException; } finally { Context.exit(); @@ -69,28 +69,28 @@ public class RhinoScriptEngine extends AbstractScriptEngine { public Object eval(Reader reader, ScriptContext context) throws ScriptException { - + Scriptable scope = setupScope(cx, context); - + String filename = (filename = (String) get(ScriptEngine.FILENAME)) == null ? "" : filename; - + try { return cx.evaluateReader(scope, reader, filename, 1, null); } catch (RhinoException e) { String msg; int line = (line = e.lineNumber()) == 0 ? -1 : line; - + if (e instanceof JavaScriptException) { msg = String.valueOf(((JavaScriptException) e).getValue()); } else { msg = e.getMessage(); } - + ScriptException scriptException = - new ScriptException(msg, e.sourceName(), line); + new ScriptException(msg, e.sourceName(), line); scriptException.initCause(e); - + throw scriptException; } catch (IOException e) { throw new ScriptException(e); @@ -106,7 +106,7 @@ public class RhinoScriptEngine extends AbstractScriptEngine { return new RhinoScriptEngineFactory(); } } - + private Scriptable setupScope(Context cx, ScriptContext context) { ScriptableObject scriptable = new ImporterTopLevel(cx); Scriptable scope = cx.initStandardObjects(scriptable); diff --git a/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngineFactory.java b/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngineFactory.java index 8b8c795a9..aef418a65 100644 --- a/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngineFactory.java +++ b/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngineFactory.java @@ -72,22 +72,22 @@ public class RhinoScriptEngineFactory implements ScriptEngineFactory { return "1.8"; } - public String getMethodCallSyntax(String obj, String m, String ... args) { + public String getMethodCallSyntax(String obj, String m, String... args) { StringBuilder s = new StringBuilder(); s.append(obj); s.append("."); s.append(m); s.append("("); - + for (int i = 0; i < args.length; ++i) { s.append(args[i]); if (i < args.length - 1) { s.append(","); } } - + s.append(")"); - + return s.toString(); } @@ -123,7 +123,7 @@ public class RhinoScriptEngineFactory implements ScriptEngineFactory { } } - public String getProgram(String ... statements) { + public String getProgram(String... statements) { StringBuilder s = new StringBuilder(); for (String stmt : statements) { s.append(stmt); diff --git a/src/main/java/com/sk89q/worldedit/snapshots/SnapshotRestore.java b/src/main/java/com/sk89q/worldedit/snapshots/SnapshotRestore.java index dcaf33f0d..19fa972d2 100644 --- a/src/main/java/com/sk89q/worldedit/snapshots/SnapshotRestore.java +++ b/src/main/java/com/sk89q/worldedit/snapshots/SnapshotRestore.java @@ -1,4 +1,3 @@ -package com.sk89q.worldedit.snapshots; // $Id$ /* * WorldEdit @@ -18,6 +17,8 @@ package com.sk89q.worldedit.snapshots; * along with this program. If not, see . */ +package com.sk89q.worldedit.snapshots; + import com.sk89q.worldedit.*; import com.sk89q.worldedit.regions.*; import com.sk89q.worldedit.blocks.*; @@ -36,8 +37,8 @@ public class SnapshotRestore { /** * Store a list of chunks that are needed and the points in them. */ - private Map> neededChunks = - new LinkedHashMap>(); + private Map> neededChunks = + new LinkedHashMap>(); /** * Chunk store. */ @@ -141,8 +142,7 @@ public class SnapshotRestore { errorChunks = new ArrayList(); // Now let's start restoring! - for (Map.Entry> entry : - neededChunks.entrySet()) { + for (Map.Entry> entry : neededChunks.entrySet()) { BlockVector2D chunkPos = entry.getKey(); Chunk chunk; diff --git a/src/main/java/com/sk89q/worldedit/snapshots/YYMMDDHHIISSParser.java b/src/main/java/com/sk89q/worldedit/snapshots/YYMMDDHHIISSParser.java index 23e9699a8..cb8848981 100644 --- a/src/main/java/com/sk89q/worldedit/snapshots/YYMMDDHHIISSParser.java +++ b/src/main/java/com/sk89q/worldedit/snapshots/YYMMDDHHIISSParser.java @@ -26,7 +26,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class YYMMDDHHIISSParser implements SnapshotDateParser { - + protected Pattern patt = Pattern.compile("([0-9]+)[^0-9]?([0-9]+)[^0-9]?([0-9]+)[^0-9]?" + "([0-9]+)[^0-9]?([0-9]+)[^0-9]?([0-9]+)"); diff --git a/src/main/java/com/sk89q/worldedit/tools/AreaPickaxe.java b/src/main/java/com/sk89q/worldedit/tools/AreaPickaxe.java index 94c62829a..00c0f875f 100644 --- a/src/main/java/com/sk89q/worldedit/tools/AreaPickaxe.java +++ b/src/main/java/com/sk89q/worldedit/tools/AreaPickaxe.java @@ -31,15 +31,15 @@ import com.sk89q.worldedit.blocks.BlockID; public class AreaPickaxe implements BlockTool { private static final BaseBlock air = new BaseBlock(0); private int range; - + public AreaPickaxe(int range) { this.range = range; } - + public boolean canUse(LocalPlayer player) { return player.hasPermission("worldedit.superpickaxe.area"); } - + public boolean actPrimary(ServerInterface server, LocalConfiguration config, LocalPlayer player, LocalSession session, WorldVector clicked) { LocalWorld world = clicked.getWorld(); @@ -47,17 +47,17 @@ public class AreaPickaxe implements BlockTool { int oy = clicked.getBlockY(); int oz = clicked.getBlockZ(); int initialType = world.getBlockType(clicked); - + if (initialType == 0) { return true; } - + if (initialType == BlockID.BEDROCK && !player.canDestroyBedrock()) { return true; } EditSession editSession = session.createEditSession(player); - + try { for (int x = ox - range; x <= ox + range; ++x) { for (int y = oy - range; y <= oy + range; ++y) { @@ -67,7 +67,7 @@ public class AreaPickaxe implements BlockTool { if (config.superPickaxeManyDrop) { world.simulateBlockMine(pos); } - + editSession.setBlock(pos, air); } } @@ -78,7 +78,7 @@ public class AreaPickaxe implements BlockTool { } finally { session.remember(editSession); } - + return true; } } diff --git a/src/main/java/com/sk89q/worldedit/tools/BlockReplacer.java b/src/main/java/com/sk89q/worldedit/tools/BlockReplacer.java index 08bf0eb46..4cd010293 100644 --- a/src/main/java/com/sk89q/worldedit/tools/BlockReplacer.java +++ b/src/main/java/com/sk89q/worldedit/tools/BlockReplacer.java @@ -31,23 +31,23 @@ import com.sk89q.worldedit.blocks.BlockType; */ public class BlockReplacer implements DoubleActionBlockTool { private BaseBlock targetBlock; - + public BlockReplacer(BaseBlock targetBlock) { this.targetBlock = targetBlock; } - + public boolean canUse(LocalPlayer player) { return player.hasPermission("worldedit.tool.replacer"); } - + public boolean actPrimary(ServerInterface server, LocalConfiguration config, LocalPlayer player, LocalSession session, WorldVector clicked) { BlockBag bag = session.getBlockBag(player); - + LocalWorld world = clicked.getWorld(); EditSession editSession = new EditSession(world, -1, bag); - + try { editSession.setBlock(clicked, targetBlock); } catch (MaxChangedBlocksException e) { @@ -57,7 +57,7 @@ public class BlockReplacer implements DoubleActionBlockTool { } session.remember(editSession); } - + return true; } @@ -68,11 +68,11 @@ public class BlockReplacer implements DoubleActionBlockTool { LocalWorld world = clicked.getWorld(); targetBlock = (new EditSession(world, -1)).getBlock(clicked); BlockType type = BlockType.fromID(targetBlock.getType()); - + if (type != null) { player.print("Replacer tool switched to: " + type.getName()); } - + return true; } diff --git a/src/main/java/com/sk89q/worldedit/tools/BrushTool.java b/src/main/java/com/sk89q/worldedit/tools/BrushTool.java index 7a1da6d70..e8d2b3158 100644 --- a/src/main/java/com/sk89q/worldedit/tools/BrushTool.java +++ b/src/main/java/com/sk89q/worldedit/tools/BrushTool.java @@ -43,7 +43,7 @@ public class BrushTool implements TraceTool { private Pattern material = new SingleBlockPattern(new BaseBlock(BlockID.COBBLESTONE)); private double size = 1; private String permission; - + /** * Construct the tool. * @@ -52,7 +52,7 @@ public class BrushTool implements TraceTool { public BrushTool(String permission) { this.permission = permission; } - + /** * Checks to see if the player can still be using this tool (considering * permissions and such). @@ -63,7 +63,7 @@ public class BrushTool implements TraceTool { public boolean canUse(LocalPlayer player) { return player.hasPermission(permission); } - + /** * Get the filter. * @@ -92,7 +92,7 @@ public class BrushTool implements TraceTool { this.brush = brush; this.permission = perm; } - + /** * Get the current brush. * @@ -101,7 +101,7 @@ public class BrushTool implements TraceTool { public Brush getBrush() { return brush; } - + /** * Set the material. * @@ -110,7 +110,7 @@ public class BrushTool implements TraceTool { public void setFill(Pattern material) { this.material = material; } - + /** * Get the material. * @@ -137,7 +137,7 @@ public class BrushTool implements TraceTool { public void setSize(double radius) { this.size = radius; } - + /** * Get the set brush range. * @@ -168,14 +168,14 @@ public class BrushTool implements TraceTool { LocalPlayer player, LocalSession session) { WorldVector target = null; target = player.getBlockTrace(getRange(), true); - + if (target == null) { player.printError("No block in sight!"); return true; } - + BlockBag bag = session.getBlockBag(player); - + EditSession editSession = session.createEditSession(player); Mask existingMask = editSession.getMask(); if (existingMask == null) { @@ -187,7 +187,7 @@ public class BrushTool implements TraceTool { newMask.add(mask); editSession.setMask(newMask); } - + try { brush.build(editSession, target, material, size); } catch (MaxChangedBlocksException e) { @@ -198,7 +198,7 @@ public class BrushTool implements TraceTool { } session.remember(editSession); } - + return true; } diff --git a/src/main/java/com/sk89q/worldedit/tools/FloatingTreeRemover.java b/src/main/java/com/sk89q/worldedit/tools/FloatingTreeRemover.java index 374dd512a..497294907 100755 --- a/src/main/java/com/sk89q/worldedit/tools/FloatingTreeRemover.java +++ b/src/main/java/com/sk89q/worldedit/tools/FloatingTreeRemover.java @@ -35,19 +35,19 @@ import com.sk89q.worldedit.blocks.BlockID; public class FloatingTreeRemover implements BlockTool { private static final BaseBlock air = new BaseBlock(BlockID.AIR); private int range; - + public FloatingTreeRemover() { this.range = 100; } - + public boolean canUse(LocalPlayer player) { return player.hasPermission("worldedit.tool.deltree"); } - + public boolean actPrimary(ServerInterface server, LocalConfiguration config, LocalPlayer player, LocalSession session, WorldVector clicked) { LocalWorld world = clicked.getWorld(); - + int initialType = world.getBlockType(clicked); int block; @@ -60,7 +60,7 @@ public class FloatingTreeRemover implements BlockTool { player.printError("That's not a floating tree."); return true; } - + HashSet blockSet = new HashSet(); try { if (!recurse(server, editSession, world, clicked.toBlockVector(), @@ -105,7 +105,7 @@ public class FloatingTreeRemover implements BlockTool { Vector origin, int size, Set visited, int lastBlock) throws MaxChangedBlocksException { - + if (origin.distance(pos) > size || visited.contains(pos)) { return true; } @@ -113,7 +113,7 @@ public class FloatingTreeRemover implements BlockTool { visited.add(pos); int block = editSession.getBlock(pos).getType(); - if (block == BlockID.AIR || block == BlockID.SNOW){ + if (block == BlockID.AIR || block == BlockID.SNOW) { return true; } if (block != BlockID.LOG @@ -125,7 +125,7 @@ public class FloatingTreeRemover implements BlockTool { } else { return false; } - + } for (int i = -1; i <= 1; ++i) { diff --git a/src/main/java/com/sk89q/worldedit/tools/FloodFillTool.java b/src/main/java/com/sk89q/worldedit/tools/FloodFillTool.java index e9985f017..bdbcebca4 100644 --- a/src/main/java/com/sk89q/worldedit/tools/FloodFillTool.java +++ b/src/main/java/com/sk89q/worldedit/tools/FloodFillTool.java @@ -33,22 +33,22 @@ import com.sk89q.worldedit.patterns.Pattern; public class FloodFillTool implements BlockTool { private int range; private Pattern pattern; - + public FloodFillTool(int range, Pattern pattern) { this.range = range; this.pattern = pattern; } - + public boolean canUse(LocalPlayer player) { return player.hasPermission("worldedit.tool.flood-fill"); } - + public boolean actPrimary(ServerInterface server, LocalConfiguration config, LocalPlayer player, LocalSession session, WorldVector clicked) { LocalWorld world = clicked.getWorld(); - + int initialType = world.getBlockType(clicked); - + if (initialType == BlockID.AIR) { return true; } @@ -88,7 +88,7 @@ public class FloodFillTool implements BlockTool { Vector origin, int size, int initialType, Set visited) throws MaxChangedBlocksException { - + if (origin.distance(pos) > size || visited.contains(pos)) { return; } diff --git a/src/main/java/com/sk89q/worldedit/tools/QueryTool.java b/src/main/java/com/sk89q/worldedit/tools/QueryTool.java index 2355ef2c4..aebdf3adb 100644 --- a/src/main/java/com/sk89q/worldedit/tools/QueryTool.java +++ b/src/main/java/com/sk89q/worldedit/tools/QueryTool.java @@ -28,14 +28,14 @@ import com.sk89q.worldedit.blocks.*; * @author sk89q */ public class QueryTool implements BlockTool { - + public boolean canUse(LocalPlayer player) { return player.hasPermission("worldedit.tool.info"); } public boolean actPrimary(ServerInterface server, LocalConfiguration config, LocalPlayer player, LocalSession session, WorldVector clicked) { - + LocalWorld world = clicked.getWorld(); BaseBlock block = (new EditSession(world, 0)).rawGetBlock(clicked); BlockType type = BlockType.fromID(block.getType()); @@ -48,16 +48,16 @@ public class QueryTool implements BlockTool { if (block instanceof MobSpawnerBlock) { player.printRaw("\u00A7e" + "Mob Type: " - + ((MobSpawnerBlock)block).getMobType()); + + ((MobSpawnerBlock) block).getMobType()); } else if (block instanceof NoteBlock) { player.printRaw("\u00A7e" + "Note block: " - + ((NoteBlock)block).getNote()); + + ((NoteBlock) block).getNote()); } else if (block.getType() == BlockID.CLOTH) { // Should never be null player.printRaw("\u00A7e" + "Color: " + ClothColor.fromID(block.getData()).getName()); } - + return true; } diff --git a/src/main/java/com/sk89q/worldedit/tools/RecursivePickaxe.java b/src/main/java/com/sk89q/worldedit/tools/RecursivePickaxe.java index f8c2763d9..1c7b9a05e 100644 --- a/src/main/java/com/sk89q/worldedit/tools/RecursivePickaxe.java +++ b/src/main/java/com/sk89q/worldedit/tools/RecursivePickaxe.java @@ -34,21 +34,21 @@ import com.sk89q.worldedit.blocks.BlockID; public class RecursivePickaxe implements BlockTool { private static final BaseBlock air = new BaseBlock(0); private double range; - + public RecursivePickaxe(double range) { this.range = range; } - + public boolean canUse(LocalPlayer player) { return player.hasPermission("worldedit.superpickaxe.recursive"); } - + public boolean actPrimary(ServerInterface server, LocalConfiguration config, LocalPlayer player, LocalSession session, WorldVector clicked) { LocalWorld world = clicked.getWorld(); - + int initialType = world.getBlockType(clicked); - + if (initialType == BlockID.AIR) { return true; } @@ -89,7 +89,7 @@ public class RecursivePickaxe implements BlockTool { Vector origin, double size, int initialType, Set visited, boolean drop) throws MaxChangedBlocksException { - + if (origin.distance(pos) > size || visited.contains(pos)) { return; } diff --git a/src/main/java/com/sk89q/worldedit/tools/SinglePickaxe.java b/src/main/java/com/sk89q/worldedit/tools/SinglePickaxe.java index 2f0b3e9d6..2f2572d7c 100644 --- a/src/main/java/com/sk89q/worldedit/tools/SinglePickaxe.java +++ b/src/main/java/com/sk89q/worldedit/tools/SinglePickaxe.java @@ -28,15 +28,15 @@ import com.sk89q.worldedit.blocks.BlockID; * @author sk89q */ public class SinglePickaxe implements BlockTool { - + public boolean canUse(LocalPlayer player) { return player.hasPermission("worldedit.superpickaxe"); } - + public boolean actPrimary(ServerInterface server, LocalConfiguration config, LocalPlayer player, LocalSession session, WorldVector clicked) { LocalWorld world = clicked.getWorld(); - + if (world.getBlockType(clicked) == BlockID.BEDROCK && !player.canDestroyBedrock()) { return true; @@ -45,9 +45,9 @@ public class SinglePickaxe implements BlockTool { if (config.superPickaxeDrop) { world.simulateBlockMine(clicked); } - + world.setBlockType(clicked, BlockID.AIR); - + return true; } diff --git a/src/main/java/com/sk89q/worldedit/tools/Tool.java b/src/main/java/com/sk89q/worldedit/tools/Tool.java index 1cad8ddd6..f09c7f13b 100644 --- a/src/main/java/com/sk89q/worldedit/tools/Tool.java +++ b/src/main/java/com/sk89q/worldedit/tools/Tool.java @@ -28,7 +28,7 @@ import com.sk89q.worldedit.LocalPlayer; * @author sk89q */ public abstract interface Tool { - + /** * Checks to see if the player can still be using this tool (considering * permissions and such). @@ -37,5 +37,5 @@ public abstract interface Tool { * @return */ public boolean canUse(LocalPlayer player); - + } diff --git a/src/main/java/com/sk89q/worldedit/tools/TreePlanter.java b/src/main/java/com/sk89q/worldedit/tools/TreePlanter.java index 4c801aba2..9473e8610 100644 --- a/src/main/java/com/sk89q/worldedit/tools/TreePlanter.java +++ b/src/main/java/com/sk89q/worldedit/tools/TreePlanter.java @@ -29,20 +29,20 @@ import com.sk89q.worldedit.util.TreeGenerator; */ public class TreePlanter implements BlockTool { private TreeGenerator gen; - + public TreePlanter(TreeGenerator gen) { this.gen = gen; } - + public boolean canUse(LocalPlayer player) { return player.hasPermission("worldedit.tool.tree"); } - + public boolean actPrimary(ServerInterface server, LocalConfiguration config, LocalPlayer player, LocalSession session, WorldVector clicked) { - + EditSession editSession = session.createEditSession(player); - + try { if (!gen.generate(editSession, clicked.add(0, 1, 0))) { player.printError("A tree can't go there."); @@ -52,7 +52,7 @@ public class TreePlanter implements BlockTool { } finally { session.remember(editSession); } - + return true; } diff --git a/src/main/java/com/sk89q/worldedit/tools/brushes/ClipboardBrush.java b/src/main/java/com/sk89q/worldedit/tools/brushes/ClipboardBrush.java index 8ce9f0008..c7a33d903 100644 --- a/src/main/java/com/sk89q/worldedit/tools/brushes/ClipboardBrush.java +++ b/src/main/java/com/sk89q/worldedit/tools/brushes/ClipboardBrush.java @@ -28,12 +28,12 @@ import com.sk89q.worldedit.patterns.Pattern; public class ClipboardBrush implements Brush { private CuboidClipboard clipboard; private boolean noAir; - + public ClipboardBrush(CuboidClipboard clipboard, boolean noAir) { this.clipboard = clipboard; this.noAir = noAir; } - + public void build(EditSession editSession, Vector pos, Pattern mat, double size) throws MaxChangedBlocksException { clipboard.place(editSession, pos.subtract(clipboard.getSize().divide(2)), noAir); diff --git a/src/main/java/com/sk89q/worldedit/tools/brushes/CylinderBrush.java b/src/main/java/com/sk89q/worldedit/tools/brushes/CylinderBrush.java index e9c016920..0fe1b1b47 100644 --- a/src/main/java/com/sk89q/worldedit/tools/brushes/CylinderBrush.java +++ b/src/main/java/com/sk89q/worldedit/tools/brushes/CylinderBrush.java @@ -26,11 +26,11 @@ import com.sk89q.worldedit.patterns.Pattern; public class CylinderBrush implements Brush { private int height; - + public CylinderBrush(int height) { this.height = height; } - + public void build(EditSession editSession, Vector pos, Pattern mat, double size) throws MaxChangedBlocksException { editSession.makeCylinder(pos, mat, size, size, height, true); diff --git a/src/main/java/com/sk89q/worldedit/tools/brushes/HollowCylinderBrush.java b/src/main/java/com/sk89q/worldedit/tools/brushes/HollowCylinderBrush.java index 9ff0f0430..26209158a 100644 --- a/src/main/java/com/sk89q/worldedit/tools/brushes/HollowCylinderBrush.java +++ b/src/main/java/com/sk89q/worldedit/tools/brushes/HollowCylinderBrush.java @@ -26,11 +26,11 @@ import com.sk89q.worldedit.patterns.Pattern; public class HollowCylinderBrush implements Brush { private int height; - + public HollowCylinderBrush(int height) { this.height = height; } - + public void build(EditSession editSession, Vector pos, Pattern mat, double size) throws MaxChangedBlocksException { editSession.makeCylinder(pos, mat, size, size, height, false); diff --git a/src/main/java/com/sk89q/worldedit/tools/brushes/HollowSphereBrush.java b/src/main/java/com/sk89q/worldedit/tools/brushes/HollowSphereBrush.java index 3c83da1ba..822fb0968 100644 --- a/src/main/java/com/sk89q/worldedit/tools/brushes/HollowSphereBrush.java +++ b/src/main/java/com/sk89q/worldedit/tools/brushes/HollowSphereBrush.java @@ -27,7 +27,7 @@ import com.sk89q.worldedit.patterns.Pattern; public class HollowSphereBrush implements Brush { public HollowSphereBrush() { } - + public void build(EditSession editSession, Vector pos, Pattern mat, double size) throws MaxChangedBlocksException { editSession.makeSphere(pos, mat, size, size, size, false); diff --git a/src/main/java/com/sk89q/worldedit/tools/brushes/SmoothBrush.java b/src/main/java/com/sk89q/worldedit/tools/brushes/SmoothBrush.java index 9d6851dba..74dbcea0d 100644 --- a/src/main/java/com/sk89q/worldedit/tools/brushes/SmoothBrush.java +++ b/src/main/java/com/sk89q/worldedit/tools/brushes/SmoothBrush.java @@ -32,7 +32,7 @@ import com.sk89q.worldedit.regions.Region; public class SmoothBrush implements Brush { private int iterations; private boolean naturalOnly; - + public SmoothBrush(int iterations) { this(iterations, false); } @@ -41,7 +41,7 @@ public class SmoothBrush implements Brush { this.iterations = iterations; this.naturalOnly = naturalOnly; } - + public void build(EditSession editSession, Vector pos, Pattern mat, double size) throws MaxChangedBlocksException { double rad = size; diff --git a/src/main/java/com/sk89q/worldedit/tools/brushes/SphereBrush.java b/src/main/java/com/sk89q/worldedit/tools/brushes/SphereBrush.java index 4ef2582d2..bb327fd4b 100644 --- a/src/main/java/com/sk89q/worldedit/tools/brushes/SphereBrush.java +++ b/src/main/java/com/sk89q/worldedit/tools/brushes/SphereBrush.java @@ -27,7 +27,7 @@ import com.sk89q.worldedit.patterns.Pattern; public class SphereBrush implements Brush { public SphereBrush() { } - + public void build(EditSession editSession, Vector pos, Pattern mat, double size) throws MaxChangedBlocksException { editSession.makeSphere(pos, mat, size, size, size, true); diff --git a/src/main/java/com/sk89q/worldedit/util/FileDialogUtil.java b/src/main/java/com/sk89q/worldedit/util/FileDialogUtil.java index 5fa9569c5..e59e59e25 100644 --- a/src/main/java/com/sk89q/worldedit/util/FileDialogUtil.java +++ b/src/main/java/com/sk89q/worldedit/util/FileDialogUtil.java @@ -30,7 +30,7 @@ import com.sk89q.util.StringUtil; public class FileDialogUtil { public static File showSaveDialog(String[] exts) { JFileChooser dialog = new JFileChooser(); - + if (exts != null) { dialog.setFileFilter(new ExtensionFilter(exts)); } @@ -40,13 +40,13 @@ public class FileDialogUtil { if (returnVal == JFileChooser.APPROVE_OPTION) { return dialog.getSelectedFile(); } - + return null; } - + public static File showOpenDialog(String[] exts) { JFileChooser dialog = new JFileChooser(); - + if (exts != null) { dialog.setFileFilter(new ExtensionFilter(exts)); } @@ -56,20 +56,20 @@ public class FileDialogUtil { if (returnVal == JFileChooser.APPROVE_OPTION) { return dialog.getSelectedFile(); } - + return null; } - + private static class ExtensionFilter extends FileFilter { private Set exts; private String desc; - + public ExtensionFilter(String[] exts) { this.exts = new HashSet(Arrays.asList(exts)); - + desc = StringUtil.joinString(exts, ","); } - + @Override public boolean accept(File f) { if (f.isDirectory()) { diff --git a/src/main/java/com/sk89q/worldedit/util/TargetBlock.java b/src/main/java/com/sk89q/worldedit/util/TargetBlock.java index 670e09726..3fc09ba34 100644 --- a/src/main/java/com/sk89q/worldedit/util/TargetBlock.java +++ b/src/main/java/com/sk89q/worldedit/util/TargetBlock.java @@ -92,7 +92,7 @@ public class TargetBlock { yRotation = yRotation * -1; double h = (checkDistance * Math.cos(Math.toRadians(yRotation))); - + offset = new Vector((h * Math.cos(Math.toRadians(xRotation))), (checkDistance * Math.sin(Math.toRadians(yRotation))), (h * Math.sin(Math.toRadians(xRotation)))); @@ -113,7 +113,7 @@ public class TargetBlock { BlockWorldVector lastBlock = null; while (getNextBlock() != null) { if (world.getBlockType(getCurrentBlock()) == BlockID.AIR) { - if(searchForLastBlock) { + if (searchForLastBlock) { lastBlock = getCurrentBlock(); if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= 127) { searchForLastBlock = false; @@ -126,7 +126,7 @@ public class TargetBlock { BlockWorldVector currentBlock = getCurrentBlock(); return (currentBlock != null ? currentBlock : lastBlock); } - + /** * Returns the block at the sight. Returns null if out of range or if no * viable target was found @@ -134,8 +134,7 @@ public class TargetBlock { * @return Block */ public BlockWorldVector getTargetBlock() { - while ((getNextBlock() != null) - && (world.getBlockType(getCurrentBlock()) == 0)); + while (getNextBlock() != null && world.getBlockType(getCurrentBlock()) == 0) ; return getCurrentBlock(); } @@ -146,8 +145,7 @@ public class TargetBlock { * @return Block */ public BlockWorldVector getSolidTargetBlock() { - while ((getNextBlock() != null) - && BlockType.canPassThrough(world.getBlockType(getCurrentBlock()))); + while (getNextBlock() != null && BlockType.canPassThrough(world.getBlockType(getCurrentBlock()))) ; return getCurrentBlock(); } @@ -160,7 +158,7 @@ public class TargetBlock { prevPos = targetPos; do { curDistance += checkDistance; - + targetPosDouble = offset.add(targetPosDouble.getX(), targetPosDouble.getY(), targetPosDouble.getZ()); @@ -169,7 +167,7 @@ public class TargetBlock { && targetPos.getBlockX() == prevPos.getBlockX() && targetPos.getBlockY() == prevPos.getBlockY() && targetPos.getBlockZ() == prevPos.getBlockZ()); - + if (curDistance > maxDistance) { return null; } @@ -208,4 +206,4 @@ public class TargetBlock { getAnyTargetBlock(); return WorldVectorFace.getWorldVectorFace(world, getCurrentBlock(), getPreviousBlock()); } -} \ No newline at end of file +} diff --git a/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java b/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java index b11efd28c..8a8896e0f 100644 --- a/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java +++ b/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java @@ -37,19 +37,19 @@ import com.sk89q.worldedit.blocks.BlockID; */ public class TreeGenerator { public enum TreeType { - TREE("Regular tree", new String[] {"tree", "regular"}), - BIG_TREE("Big tree", new String[] {"big", "bigtree"}), - REDWOOD("Redwood", new String[] {"redwood", "sequoia", "sequoioideae"}), - TALL_REDWOOD("Tall redwood", new String[] {"tallredwood", "tallsequoia", "tallsequoioideae"}), - BIRCH("Birch", new String[] {"birch", "white", "whitebark"}), - PINE("Pine", new String[] {"pine"}), - RANDOM_REDWOOD("Random redwood", new String[] {"randredwood", "randomredwood", "anyredwood"}), - RANDOM("Random", new String[] {"rand", "random"}); + TREE("Regular tree", new String[] { "tree", "regular" }), + BIG_TREE("Big tree", new String[] { "big", "bigtree" }), + REDWOOD("Redwood", new String[] { "redwood", "sequoia", "sequoioideae" }), + TALL_REDWOOD("Tall redwood", new String[] { "tallredwood", "tallsequoia", "tallsequoioideae" }), + BIRCH("Birch", new String[] { "birch", "white", "whitebark" }), + PINE("Pine", new String[] { "pine" }), + RANDOM_REDWOOD("Random redwood", new String[] { "randredwood", "randomredwood", "anyredwood" }), + RANDOM("Random", new String[] { "rand", "random" }); /** * Stores a map of the names for fast access. */ - private static final Map lookup = new HashMap(); + private static final Map lookup = new HashMap(); private final String name; private final String[] lookupKeys; @@ -61,17 +61,17 @@ public class TreeGenerator { } } } - + TreeType(String name, String lookupKey) { this.name = name; - this.lookupKeys = new String[]{ lookupKey }; + this.lookupKeys = new String[] { lookupKey }; } - + TreeType(String name, String[] lookupKeys) { this.name = name; this.lookupKeys = lookupKeys; } - + /** * Get user-friendly tree type name. * @@ -80,7 +80,7 @@ public class TreeGenerator { public String getName() { return name; } - + /** * Return type from name. May return null. * @@ -91,11 +91,11 @@ public class TreeGenerator { return lookup.get(name.toLowerCase()); } }; - + private static Random rand = new Random(); - + private TreeType type; - + /** * Construct the tree generator with a tree type. * @@ -104,7 +104,7 @@ public class TreeGenerator { public TreeGenerator(TreeType type) { this.type = type; } - + /** * Generate a tree. * @@ -117,7 +117,7 @@ public class TreeGenerator { throws MaxChangedBlocksException { return generate(type, editSession, pos); } - + /** * Generate a tree. * @@ -130,41 +130,41 @@ public class TreeGenerator { private boolean generate(TreeType type, EditSession editSession, Vector pos) throws MaxChangedBlocksException { LocalWorld world = editSession.getWorld(); - + TreeType[] choices; TreeType realType; - + switch (type) { - case TREE: - return world.generateTree(editSession, pos); - case BIG_TREE: - return world.generateBigTree(editSession, pos); - case BIRCH: - return world.generateBirchTree(editSession, pos); - case REDWOOD: - return world.generateRedwoodTree(editSession, pos); - case TALL_REDWOOD: - return world.generateTallRedwoodTree(editSession, pos); - case PINE: - makePineTree(editSession, pos); - return true; - case RANDOM_REDWOOD: - choices = + case TREE: + return world.generateTree(editSession, pos); + case BIG_TREE: + return world.generateBigTree(editSession, pos); + case BIRCH: + return world.generateBirchTree(editSession, pos); + case REDWOOD: + return world.generateRedwoodTree(editSession, pos); + case TALL_REDWOOD: + return world.generateTallRedwoodTree(editSession, pos); + case PINE: + makePineTree(editSession, pos); + return true; + case RANDOM_REDWOOD: + choices = new TreeType[] { - TreeType.REDWOOD, TreeType.TALL_REDWOOD + TreeType.REDWOOD, TreeType.TALL_REDWOOD }; - realType = choices[rand.nextInt(choices.length)]; - return generate(realType, editSession, pos); - case RANDOM: - choices = + realType = choices[rand.nextInt(choices.length)]; + return generate(realType, editSession, pos); + case RANDOM: + choices = new TreeType[] { - TreeType.TREE, TreeType.BIG_TREE, TreeType.BIRCH, - TreeType.REDWOOD, TreeType.TALL_REDWOOD, TreeType.PINE + TreeType.TREE, TreeType.BIG_TREE, TreeType.BIRCH, + TreeType.REDWOOD, TreeType.TALL_REDWOOD, TreeType.PINE }; - realType = choices[rand.nextInt(choices.length)]; - return generate(realType, editSession, pos); + realType = choices[rand.nextInt(choices.length)]; + return generate(realType, editSession, pos); } - + return false; } @@ -226,7 +226,7 @@ public class TreeGenerator { editSession.setBlockIfAir(basePos.add(0, height, 0), leavesBlock); } - + /** * Looks up a tree type. May return null if a tree type by that * name is not found. diff --git a/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java b/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java index 0e7ed73a1..88b26aa98 100644 --- a/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java +++ b/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java @@ -32,7 +32,7 @@ public class CommandContextTest { CommandContext firstCommand; @Before - public void setUpTest(){ + public void setUpTest() { try { firstCommand = new CommandContext(firstCmdString, new HashSet(Arrays.asList('o', 'w'))); } catch (CommandException e) { diff --git a/src/test/java/com/sk89q/worldedit/blocks/BlockDataTest.java b/src/test/java/com/sk89q/worldedit/blocks/BlockDataTest.java index 196f46c33..8d2d779f9 100644 --- a/src/test/java/com/sk89q/worldedit/blocks/BlockDataTest.java +++ b/src/test/java/com/sk89q/worldedit/blocks/BlockDataTest.java @@ -35,7 +35,7 @@ public class BlockDataTest { public void testRotateFlip() { for (int type = 0; type < 256; ++type) { for (int data = 0; data < 16; ++data) { - final String message = type+"/"+data; + final String message = type + "/" + data; //Test r90(r-90(x))==x assertEquals(message, data, BlockData.rotate90(type, BlockData.rotate90Reverse(type, data))); @@ -75,11 +75,10 @@ public class BlockDataTest { public void testCycle() { // Test monotony for (int type = 0; type < 256; ++type) { - if (type == BlockID.CLOTH) - continue; + if (type == BlockID.CLOTH) continue; for (int data = 0; data < 16; ++data) { - final String message = type+"/"+data; + final String message = type + "/" + data; final int cycled = BlockData.cycle(type, data, 1); @@ -87,7 +86,7 @@ public class BlockDataTest { continue; } - assertEquals(message, data+1, cycled); + assertEquals(message, data + 1, cycled); } } @@ -104,14 +103,14 @@ public class BlockDataTest { final TreeSet datas = (TreeSet) datasTemplate.clone(); while (!datas.isEmpty()) { final int start = datas.pollFirst(); - String message = type+"/"+start; + String message = type + "/" + start; int current = start; boolean first = true; while (true) { current = BlockData.cycle(type, current, increment); if (first && current == -1) break; first = false; - message += "->"+current; + message += "->" + current; assertTrue(message, current >= 0); assertTrue(message, current < 16); if (current == start) break; diff --git a/src/test/java/com/sk89q/worldedit/expression/ExpressionTest.java b/src/test/java/com/sk89q/worldedit/expression/ExpressionTest.java index 0dac1210a..0bec185ec 100644 --- a/src/test/java/com/sk89q/worldedit/expression/ExpressionTest.java +++ b/src/test/java/com/sk89q/worldedit/expression/ExpressionTest.java @@ -12,16 +12,16 @@ public class ExpressionTest { @Test public void testEvaluate() throws ExpressionException { // check - assertEquals(1-2+3, simpleEval("1-2+3"), 0); + assertEquals(1 - 2 + 3, simpleEval("1 - 2 + 3"), 0); // check unary ops - assertEquals(2+ +4, simpleEval("2+ +4"), 0); - assertEquals(2- -4, simpleEval("2- -4"), 0); - assertEquals(2*-4, simpleEval("2*-4"), 0); + assertEquals(2 + +4, simpleEval("2 + +4"), 0); + assertEquals(2 - -4, simpleEval("2 - -4"), 0); + assertEquals(2 * -4, simpleEval("2 * -4"), 0); // check functions assertEquals(sin(5), simpleEval("sin(5)"), 0); - assertEquals(atan2(3,4), simpleEval("atan2(3,4)"), 0); + assertEquals(atan2(3, 4), simpleEval("atan2(3, 4)"), 0); // check variables assertEquals(8, Expression.compile("foo+bar", "foo", "bar").evaluate(5, 3), 0);