From aaaf2d5678ee92e94533f5b0d99e13b94108171d Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Sat, 16 Jun 2018 16:36:55 +1000 Subject: [PATCH] More deprecation removal --- build.gradle | 4 +- .../sk89q/worldedit/bukkit/BukkitPlayer.java | 17 --- .../sk89q/worldedit/bukkit/BukkitWorld.java | 2 - .../worldedit/bukkit/WorldEditListener.java | 2 +- .../worldedit/bukkit/WorldEditPlugin.java | 12 +- .../main/java/com/sk89q/jnbt/CompoundTag.java | 2 +- .../com/sk89q/jnbt/CompoundTagBuilder.java | 4 +- .../java/com/sk89q/jnbt/ListTagBuilder.java | 4 +- .../java/com/sk89q/jnbt/NBTInputStream.java | 4 +- .../util/commands/CommandContext.java | 12 +- .../util/commands/CommandException.java | 2 +- .../util/commands/CommandLocals.java | 2 +- .../util/commands/CommandsManager.java | 28 ++--- .../util/commands/SimpleInjector.java | 11 +- .../java/com/sk89q/util/ReflectionUtil.java | 3 +- .../java/com/sk89q/util/yaml/YAMLNode.java | 36 +++--- .../com/sk89q/util/yaml/YAMLProcessor.java | 53 +++----- .../com/sk89q/worldedit/CuboidClipboard.java | 14 +-- .../java/com/sk89q/worldedit/EditSession.java | 117 ++++-------------- .../sk89q/worldedit/LocalConfiguration.java | 4 +- .../java/com/sk89q/worldedit/WorldEdit.java | 59 +-------- .../com/sk89q/worldedit/blocks/BlockType.java | 42 +++---- .../sk89q/worldedit/blocks/ClothColor.java | 4 +- .../com/sk89q/worldedit/blocks/ItemType.java | 8 +- .../worldedit/blocks/type/BlockTypes.java | 1 - .../worldedit/command/BiomeCommands.java | 4 +- .../worldedit/command/BrushCommands.java | 1 - .../worldedit/command/GenerationCommands.java | 1 - .../worldedit/command/HistoryCommands.java | 4 +- .../worldedit/command/SchematicCommands.java | 54 +++----- .../worldedit/command/SelectionCommands.java | 24 ++-- .../command/SnapshotUtilCommands.java | 5 +- .../sk89q/worldedit/command/ToolCommands.java | 1 - .../worldedit/command/UtilityCommands.java | 10 +- .../command/argument/PatternParser.java | 2 - .../command/argument/RegionFactoryParser.java | 19 +-- .../composition/ShapedBrushCommand.java | 4 +- .../command/tool/BlockDataCyler.java | 11 +- .../command/tool/FloatingTreeRemover.java | 10 +- .../worldedit/command/tool/FloodFillTool.java | 11 +- .../command/tool/RecursivePickaxe.java | 3 +- .../worldedit/command/tool/SinglePickaxe.java | 5 +- .../worldedit/command/tool/TreePlanter.java | 1 - .../command/tool/brush/GravityBrush.java | 3 +- .../command/util/CreatureButcher.java | 103 ++++++++------- .../worldedit/command/util/EntityRemover.java | 21 ++-- .../com/sk89q/worldedit/entity/Player.java | 28 ----- .../extension/factory/BlockFactory.java | 2 +- .../extension/factory/DefaultMaskParser.java | 4 +- .../platform/AbstractPlayerActor.java | 20 +-- .../extension/platform/PlatformManager.java | 9 +- .../extension/platform/PlayerProxy.java | 15 --- .../permission/ActorSelectorLimits.java | 9 +- .../worldedit/extent/ChangeSetExtent.java | 2 +- .../extent/buffer/ForgetfulExtentBuffer.java | 3 +- .../extent/clipboard/BlockArrayClipboard.java | 5 +- .../extent/clipboard/io/ClipboardFormat.java | 15 +-- .../extent/clipboard/io/SchematicReader.java | 32 ++--- .../extent/clipboard/io/SchematicWriter.java | 14 +-- .../SignCompatibilityHandler.java | 1 - .../extent/inventory/BlockBagExtent.java | 4 +- .../extent/reorder/MultiStageReorder.java | 12 +- .../extent/world/FastModeExtent.java | 2 +- .../extent/world/SurvivalModeExtent.java | 1 - .../function/CombinedRegionFunction.java | 2 +- .../function/generator/ForestGenerator.java | 1 - .../generator/GardenPatchGenerator.java | 31 +++-- .../worldedit/function/mask/BiomeMask2D.java | 2 +- .../worldedit/function/mask/BlockMask.java | 2 +- .../function/mask/ExistingBlockMask.java | 1 - .../function/mask/MaskIntersection.java | 4 +- .../function/mask/MaskIntersection2D.java | 2 +- .../worldedit/function/mask/MaskUnion.java | 2 +- .../sk89q/worldedit/function/mask/Masks.java | 1 - .../function/operation/OperationQueue.java | 2 +- .../function/pattern/RandomPattern.java | 2 +- .../function/visitor/BreadthFirstSearch.java | 6 +- .../history/changeset/ArrayListHistory.java | 2 +- .../changeset/BlockOptimizedHistory.java | 11 +- .../internal/ServerInterfaceAdapter.java | 1 - .../command/CommandLoggingHandler.java | 2 +- .../command/UserCommandCompleter.java | 2 +- .../internal/expression/Expression.java | 6 +- .../internal/expression/lexer/Lexer.java | 9 +- .../internal/expression/parser/Parser.java | 10 +- .../expression/parser/ParserProcessors.java | 22 ++-- .../expression/runtime/Functions.java | 32 ++--- .../internal/expression/runtime/Sequence.java | 2 +- .../internal/expression/runtime/Switch.java | 8 +- .../internal/registry/AbstractFactory.java | 2 +- .../internal/util/DocumentationPrinter.java | 18 +-- .../sk89q/worldedit/math/geom/Polygons.java | 2 +- .../ReparametrisingInterpolation.java | 2 +- .../math/transform/CombinedTransform.java | 2 +- .../sk89q/worldedit/regions/CuboidRegion.java | 55 ++++---- .../worldedit/regions/CylinderRegion.java | 7 +- .../worldedit/regions/EllipsoidRegion.java | 2 +- .../worldedit/regions/Polygonal2DRegion.java | 11 +- .../worldedit/regions/RegionIntersection.java | 2 +- .../worldedit/regions/TransformRegion.java | 2 +- .../ConvexPolyhedralRegionSelector.java | 13 +- .../selector/CuboidRegionSelector.java | 2 +- .../selector/CylinderRegionSelector.java | 2 +- .../selector/EllipsoidRegionSelector.java | 2 +- .../selector/Polygonal2DRegionSelector.java | 13 +- .../regions/selector/RegionSelectorType.java | 4 +- .../limit/PermissiveSelectorLimits.java | 6 +- .../selector/limit/SelectorLimits.java | 2 +- .../shape/WorldEditExpressionEnvironment.java | 12 +- .../schematic/MCEditSchematicFormat.java | 43 +++---- .../worldedit/schematic/SchematicFormat.java | 1 - .../java/RhinoScriptEngineFactory.java | 35 +++--- .../worldedit/session/SessionManager.java | 39 +++--- .../worldedit/session/request/Request.java | 7 +- .../session/storage/JsonFileSessionStore.java | 16 +-- .../com/sk89q/worldedit/util/Countable.java | 8 +- .../sk89q/worldedit/util/FileDialogUtil.java | 2 +- .../sk89q/worldedit/util/Java7Detector.java | 46 ------- .../util/PropertiesConfiguration.java | 28 +---- .../com/sk89q/worldedit/util/TargetBlock.java | 10 +- .../sk89q/worldedit/util/TreeGenerator.java | 59 ++++++--- .../sk89q/worldedit/util/WeightedChoice.java | 20 ++- .../worldedit/util/YAMLConfiguration.java | 4 +- .../util/collection/DoubleArrayList.java | 8 +- .../util/collection/FastListIterator.java | 6 +- .../util/collection/TupleArrayList.java | 2 +- .../util/command/SimpleDescription.java | 4 +- .../util/command/SimpleDispatcher.java | 8 +- .../util/command/composition/FlagParser.java | 2 +- .../command/composition/ProvidedValue.java | 2 +- .../command/parametric/BindingHelper.java | 8 +- .../parametric/ExceptionConverterHelper.java | 6 +- .../command/parametric/ParametricBuilder.java | 4 +- .../parametric/ParametricCallable.java | 10 +- .../util/concurrency/EvenMoreExecutors.java | 2 +- .../worldedit/util/eventbus/EventBus.java | 26 ++-- .../util/eventbus/HierarchyCache.java | 2 +- .../util/formatting/ColorCodeBuilder.java | 7 +- .../util/formatting/StyledFragment.java | 2 +- .../formatting/component/CommandUsageBox.java | 4 +- .../com/sk89q/worldedit/util/io/Closer.java | 4 +- .../worldedit/util/logging/LogFormat.java | 1 - .../sk89q/worldedit/world/AbstractWorld.java | 24 +--- .../java/com/sk89q/worldedit/world/World.java | 13 -- .../sk89q/worldedit/world/biome/Biomes.java | 11 +- .../worldedit/world/chunk/AnvilChunk.java | 32 ++--- .../sk89q/worldedit/world/chunk/OldChunk.java | 32 ++--- .../world/snapshot/SnapshotRepository.java | 15 +-- .../world/snapshot/SnapshotRestore.java | 16 +-- .../sk89q/worldedit/forge/ForgePlayer.java | 15 --- .../com/sk89q/worldedit/forge/ForgeWorld.java | 3 +- .../sk89q/worldedit/sponge/SpongePlayer.java | 16 --- 152 files changed, 701 insertions(+), 1150 deletions(-) delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/util/Java7Detector.java diff --git a/build.gradle b/build.gradle index 000fd44ee..496b8987a 100644 --- a/build.gradle +++ b/build.gradle @@ -87,8 +87,8 @@ subprojects { ext.internalVersion = version + ";" + gitCommitHash - sourceCompatibility = 1.7 - targetCompatibility = 1.7 + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 checkstyle.configFile = new File(rootProject.projectDir, "config/checkstyle/checkstyle.xml") checkstyle.toolVersion = '7.6.1' diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index 5bfba060a..d0224b154 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -71,23 +71,6 @@ public class BukkitPlayer extends AbstractPlayerActor { return player.getName(); } - @Override - public com.sk89q.worldedit.util.Location getPosition() { - Location loc = player.getLocation(); - return new com.sk89q.worldedit.util.Location(BukkitUtil.getWorld(loc.getWorld()), - loc.getX(), loc.getY(), loc.getZ()); - } - - @Override - public double getPitch() { - return player.getLocation().getPitch(); - } - - @Override - public double getYaw() { - return player.getLocation().getYaw(); - } - @Override public void giveItem(int type, int amt) { player.getInventory().addItem(new ItemStack(type, amt)); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 4c9fc09e5..7f3c11aac 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -329,7 +329,6 @@ public class BukkitWorld extends AbstractWorld { world.dropItemNaturally(BukkitUtil.toLocation(world, pt), bukkitItem); } - @SuppressWarnings("deprecation") @Override public boolean isValidBlockType(int type) { return Material.getMaterial(type) != null && Material.getMaterial(type).isBlock(); @@ -421,7 +420,6 @@ public class BukkitWorld extends AbstractWorld { } } - @SuppressWarnings("deprecation") @Override public BaseBlock getLazyBlock(Vector position) { World world = getWorld(); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java index b5ab6c75a..44dd56b44 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java @@ -66,7 +66,7 @@ public class WorldEditListener implements Listener { } // this will automatically refresh their session, we don't have to do anything - WorldEdit.getInstance().getSession(plugin.wrapPlayer(event.getPlayer())); + WorldEdit.getInstance().getSessionManager().get(plugin.wrapPlayer(event.getPlayer())); } /** diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index cb79b34c1..4910db731 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -47,7 +47,6 @@ import com.sk89q.worldedit.regions.CylinderRegion; import com.sk89q.worldedit.regions.Polygonal2DRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; -import com.sk89q.worldedit.util.Java7Detector; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -114,9 +113,6 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent()); loadAdapter(); // Need an adapter to work with special blocks with NBT data - - // Check Java version - Java7Detector.notifyIfNot8(); } private void loadConfig() { @@ -164,7 +160,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { @Override public void onDisable() { WorldEdit worldEdit = WorldEdit.getInstance(); - worldEdit.clearSessions(); + worldEdit.getSessionManager().clear(); worldEdit.getPlatformManager().unregister(server); if (config != null) { config.unload(); @@ -264,7 +260,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { * @return a session */ public LocalSession getSession(Player player) { - return WorldEdit.getInstance().getSession(wrapPlayer(player)); + return WorldEdit.getInstance().getSessionManager().get(wrapPlayer(player)); } /** @@ -364,7 +360,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { throw new IllegalArgumentException("Offline player not allowed"); } - LocalSession session = WorldEdit.getInstance().getSession(wrapPlayer(player)); + LocalSession session = WorldEdit.getInstance().getSessionManager().get(wrapPlayer(player)); RegionSelector selector = session.getRegionSelector(BukkitUtil.getWorld(player.getWorld())); try { @@ -402,7 +398,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { throw new IllegalArgumentException("Null selection not allowed"); } - LocalSession session = WorldEdit.getInstance().getSession(wrapPlayer(player)); + LocalSession session = WorldEdit.getInstance().getSessionManager().get(wrapPlayer(player)); RegionSelector sel = selection.getRegionSelector(); session.setRegionSelector(BukkitUtil.getWorld(player.getWorld()), sel); session.dispatchCUISelection(wrapPlayer(player)); diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java index 6477d2502..8f1a7793c 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java @@ -72,7 +72,7 @@ public final class CompoundTag extends Tag { * @return the builder */ public CompoundTagBuilder createBuilder() { - return new CompoundTagBuilder(new HashMap(value)); + return new CompoundTagBuilder(new HashMap<>(value)); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTagBuilder.java b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTagBuilder.java index 3d476fa40..0bd661967 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTagBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTagBuilder.java @@ -35,7 +35,7 @@ public class CompoundTagBuilder { * Create a new instance. */ CompoundTagBuilder() { - this.entries = new HashMap(); + this.entries = new HashMap<>(); } /** @@ -189,7 +189,7 @@ public class CompoundTagBuilder { * @return the new compound tag */ public CompoundTag build() { - return new CompoundTag(new HashMap(entries)); + return new CompoundTag(new HashMap<>(entries)); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/ListTagBuilder.java b/worldedit-core/src/main/java/com/sk89q/jnbt/ListTagBuilder.java index 9bcbbfd05..cd1f11e25 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/ListTagBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/ListTagBuilder.java @@ -42,7 +42,7 @@ public class ListTagBuilder { ListTagBuilder(Class type) { checkNotNull(type); this.type = type; - this.entries = new ArrayList(); + this.entries = new ArrayList<>(); } /** @@ -80,7 +80,7 @@ public class ListTagBuilder { * @return the new list tag */ public ListTag build() { - return new ListTag(type, new ArrayList(entries)); + return new ListTag(type, new ArrayList<>(entries)); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java index 223ca2248..bd6a1f9f2 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java @@ -128,7 +128,7 @@ public final class NBTInputStream implements Closeable { int childType = is.readByte(); length = is.readInt(); - List tagList = new ArrayList(); + List tagList = new ArrayList<>(); for (int i = 0; i < length; ++i) { Tag tag = readTagPayload(childType, depth + 1); if (tag instanceof EndTag) { @@ -139,7 +139,7 @@ public final class NBTInputStream implements Closeable { return new ListTag(NBTUtils.getTypeClass(childType), tagList); case NBTConstants.TYPE_COMPOUND: - Map tagMap = new HashMap(); + Map tagMap = new HashMap<>(); while (true) { NamedTag namedTag = readNamedTag(depth + 1); Tag tag = namedTag.getTag(); diff --git a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java index d1db70207..9dfc58d6f 100644 --- a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java +++ b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java @@ -34,8 +34,8 @@ public class CommandContext { protected final List originalArgIndices; protected final String[] originalArgs; - protected final Set booleanFlags = new HashSet(); - protected final Map valueFlags = new HashMap(); + protected final Set booleanFlags = new HashSet<>(); + protected final Map valueFlags = new HashMap<>(); protected final SuggestionContext suggestionContext; protected final CommandLocals locals; @@ -103,8 +103,8 @@ public class CommandContext { SuggestionContext suggestionContext = SuggestionContext.hangingValue(); // Eliminate empty args and combine multiword args first - List argIndexList = new ArrayList(args.length); - List argList = new ArrayList(args.length); + List argIndexList = new ArrayList<>(args.length); + List argList = new ArrayList<>(args.length); for (int i = 1; i < args.length; ++i) { isHanging = false; @@ -152,8 +152,8 @@ public class CommandContext { // Then flags - this.originalArgIndices = new ArrayList(argIndexList.size()); - this.parsedArgs = new ArrayList(argList.size()); + this.originalArgIndices = new ArrayList<>(argIndexList.size()); + this.parsedArgs = new ArrayList<>(argList.size()); if (parseFlags) { for (int nextArg = 0; nextArg < argList.size(); ) { diff --git a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandException.java b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandException.java index e81344e56..1dcbdde1e 100644 --- a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandException.java +++ b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandException.java @@ -28,7 +28,7 @@ import static com.google.common.base.Preconditions.checkNotNull; public class CommandException extends Exception { - private List commandStack = new ArrayList(); + private List commandStack = new ArrayList<>(); public CommandException() { super(); diff --git a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandLocals.java b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandLocals.java index e0053f0b3..0bc2992a5 100644 --- a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandLocals.java +++ b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandLocals.java @@ -24,7 +24,7 @@ import java.util.Map; public class CommandLocals { - private final Map locals = new HashMap(); + private final Map locals = new HashMap<>(); public boolean containsKey(Object key) { return locals.containsKey(key); diff --git a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java index eec7ced7c..a8f49678b 100644 --- a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java +++ b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java @@ -72,18 +72,18 @@ 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(); + protected Map instances = new HashMap<>(); /** * Mapping of commands (not including aliases) with a description. This * is only for top level commands. */ - protected Map descs = new HashMap(); + protected Map descs = new HashMap<>(); /** * Stores the injector used to getInstance. @@ -94,7 +94,7 @@ public abstract class CommandsManager { * Mapping of commands (not including aliases) with a description. This * is only for top level commands. */ - protected Map helpMessages = new HashMap(); + protected Map helpMessages = new HashMap<>(); /** * Register an class that contains commands (denoted by {@link Command}. @@ -141,11 +141,7 @@ public abstract class CommandsManager { Object obj = getInjector().getInstance(cls); return registerMethods(cls, parent, obj); } - } catch (InvocationTargetException e) { - logger.log(Level.SEVERE, "Failed to register commands", e); - } catch (IllegalAccessException e) { - logger.log(Level.SEVERE, "Failed to register commands", e); - } catch (InstantiationException e) { + } catch (InvocationTargetException | InstantiationException | IllegalAccessException e) { logger.log(Level.SEVERE, "Failed to register commands", e); } return null; @@ -161,14 +157,14 @@ public abstract class CommandsManager { */ private List registerMethods(Class cls, Method parent, Object obj) { Map map; - List registered = new ArrayList(); + 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)) { map = commands.get(parent); } else { - map = new HashMap(); + map = new HashMap<>(); commands.put(parent, map); } @@ -359,7 +355,7 @@ public abstract class CommandsManager { command.append("<"); - Set allowedCommands = new HashSet(); + Set allowedCommands = new HashSet<>(); for (Map.Entry entry : map.entrySet()) { Method childMethod = entry.getValue(); @@ -479,10 +475,10 @@ public abstract class CommandsManager { String[] newArgs = new String[args.length - level]; System.arraycopy(args, level, newArgs, 0, args.length - level); - final Set valueFlags = new HashSet(); + final Set valueFlags = new HashSet<>(); char[] flags = cmd.flags().toCharArray(); - Set newFlags = new HashSet(); + Set newFlags = new HashSet<>(); for (int i = 0; i < flags.length; ++i) { if (flags.length > i + 1 && flags[i + 1] == ':') { valueFlags.add(flags[i]); @@ -526,9 +522,7 @@ public abstract class CommandsManager { public void invokeMethod(Method parent, String[] args, T player, Method method, Object instance, Object[] methodArgs, int level) throws CommandException { try { method.invoke(instance, methodArgs); - } catch (IllegalArgumentException e) { - logger.log(Level.SEVERE, "Failed to execute command", e); - } catch (IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { logger.log(Level.SEVERE, "Failed to execute command", e); } catch (InvocationTargetException e) { if (e.getCause() instanceof CommandException) { diff --git a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java index ca3e82f92..eb6097512 100644 --- a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java +++ b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java @@ -44,16 +44,7 @@ public class SimpleInjector implements Injector { Constructor ctr = clazz.getConstructor(argClasses); ctr.setAccessible(true); return ctr.newInstance(args); - } catch (NoSuchMethodException e) { - log.log(Level.SEVERE, "Error initializing commands class " + clazz, e); - return null; - } catch (InvocationTargetException e) { - log.log(Level.SEVERE, "Error initializing commands class " + clazz, e); - return null; - } catch (InstantiationException e) { - log.log(Level.SEVERE, "Error initializing commands class " + clazz, e); - return null; - } catch (IllegalAccessException e) { + } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { log.log(Level.SEVERE, "Error initializing commands class " + clazz, e); return null; } diff --git a/worldedit-core/src/main/java/com/sk89q/util/ReflectionUtil.java b/worldedit-core/src/main/java/com/sk89q/util/ReflectionUtil.java index 0b80816f7..81388e619 100644 --- a/worldedit-core/src/main/java/com/sk89q/util/ReflectionUtil.java +++ b/worldedit-core/src/main/java/com/sk89q/util/ReflectionUtil.java @@ -34,8 +34,7 @@ public final class ReflectionUtil { Field field = checkClass.getDeclaredField(name); field.setAccessible(true); return (T) field.get(from); - } catch (NoSuchFieldException ignored) { - } catch (IllegalAccessException ignored) { + } catch (NoSuchFieldException | IllegalAccessException ignored) { } } while (checkClass.getSuperclass() != Object.class && ((checkClass = checkClass.getSuperclass()) != null)); return null; diff --git a/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLNode.java b/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLNode.java index ff0bda3a4..22b09cd48 100644 --- a/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLNode.java +++ b/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLNode.java @@ -111,7 +111,7 @@ public class YAMLNode { */ private Object prepareSerialization(Object value) { if (value instanceof Vector) { - Map out = new LinkedHashMap(); + Map out = new LinkedHashMap<>(); Vector vec = (Vector) value; out.put("x", vec.getX()); out.put("y", vec.getY()); @@ -169,7 +169,7 @@ public class YAMLNode { * @return a node for the path */ public YAMLNode addNode(String path) { - Map map = new LinkedHashMap(); + Map map = new LinkedHashMap<>(); YAMLNode node = new YAMLNode(map, writeDefaults); setProperty(path, map); return node; @@ -398,12 +398,12 @@ public class YAMLNode { */ @SuppressWarnings("unchecked") public List getKeys(String path) { - if (path == null) return new ArrayList(root.keySet()); + if (path == null) return new ArrayList<>(root.keySet()); Object o = getProperty(path); 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; } @@ -444,10 +444,10 @@ public class YAMLNode { List raw = getList(path); if (raw == null) { if (writeDefaults && def != null) setProperty(path, def); - return def != null ? def : new ArrayList(); + return def != null ? def : new ArrayList<>(); } - List list = new ArrayList(); + List list = new ArrayList<>(); for (Object o : raw) { if (o == null) { continue; @@ -474,10 +474,10 @@ public class YAMLNode { List raw = getList(path); if (raw == null) { if (writeDefaults && def != null) setProperty(path, def); - return def != null ? def : new ArrayList(); + return def != null ? def : new ArrayList<>(); } - List list = new ArrayList(); + List list = new ArrayList<>(); for (Object o : raw) { Integer i = castInt(o); if (i != null) { @@ -503,10 +503,10 @@ public class YAMLNode { List raw = getList(path); if (raw == null) { if (writeDefaults && def != null) setProperty(path, def); - return def != null ? def : new ArrayList(); + return def != null ? def : new ArrayList<>(); } - List list = new ArrayList(); + List list = new ArrayList<>(); for (Object o : raw) { Double i = castDouble(o); if (i != null) { @@ -532,10 +532,10 @@ public class YAMLNode { List raw = getList(path); if (raw == null) { if (writeDefaults && def != null) setProperty(path, def); - return def != null ? def : new ArrayList(); + return def != null ? def : new ArrayList<>(); } - List list = new ArrayList(); + List list = new ArrayList<>(); for (Object o : raw) { Boolean tetsu = castBoolean(o); if (tetsu != null) { @@ -559,7 +559,7 @@ public class YAMLNode { */ public List getVectorList(String path, List def) { List raw = getNodeList(path, null); - List list = new ArrayList(); + List list = new ArrayList<>(); for (YAMLNode o : raw) { Double x = o.getDouble("x"); @@ -590,7 +590,7 @@ public class YAMLNode { public List getVector2dList(String path, List def) { List raw = getNodeList(path, null); - List list = new ArrayList(); + List list = new ArrayList<>(); for (YAMLNode o : raw) { Double x = o.getDouble("x"); @@ -620,7 +620,7 @@ public class YAMLNode { public List getBlockVector2dList(String path, List def) { List raw = getNodeList(path, null); - List list = new ArrayList(); + List list = new ArrayList<>(); for (YAMLNode o : raw) { Double x = o.getDouble("x"); @@ -652,10 +652,10 @@ public class YAMLNode { List raw = getList(path); if (raw == null) { if (writeDefaults && def != null) setProperty(path, def); - return def != null ? def : new ArrayList(); + return def != null ? def : new ArrayList<>(); } - List list = new ArrayList(); + List list = new ArrayList<>(); for (Object o : raw) { if (o instanceof Map) { list.add(new YAMLNode((Map) o, writeDefaults)); @@ -698,7 +698,7 @@ public class YAMLNode { return null; } else if (o instanceof Map) { Map nodes = - new LinkedHashMap(); + new LinkedHashMap<>(); for (Map.Entry entry : ((Map) o).entrySet()) { if (entry.getValue() instanceof Map) { diff --git a/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java b/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java index e0ecdf33f..0d09fe64f 100644 --- a/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java +++ b/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLProcessor.java @@ -31,6 +31,7 @@ import org.yaml.snakeyaml.representer.Represent; import org.yaml.snakeyaml.representer.Representer; import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.Map.Entry; @@ -76,10 +77,10 @@ public class YAMLProcessor extends YAMLNode { * Comments support based on ZerothAngel's AnnotatedYAMLConfiguration * Comments are only supported with YAMLFormat.EXTENDED */ - private final Map comments = new HashMap(); + private final Map comments = new HashMap<>(); public YAMLProcessor(File file, boolean writeDefaults, YAMLFormat format) { - super(new LinkedHashMap(), writeDefaults); + super(new LinkedHashMap<>(), writeDefaults); this.format = format; DumperOptions options = new FancyDumperOptions(); @@ -103,21 +104,13 @@ public class YAMLProcessor extends YAMLNode { * @throws java.io.IOException on load error */ public void load() throws IOException { - InputStream stream = null; - try { - stream = getInputStream(); - if (stream == null) throw new IOException("Stream is null!"); + try (InputStream stream = getInputStream()) { + if (stream == null) + throw new IOException("Stream is null!"); read(yaml.load(new UnicodeReader(stream))); } catch (YAMLProcessorException e) { - root = new LinkedHashMap(); - } finally { - try { - if (stream != null) { - stream.close(); - } - } catch (IOException ignored) { - } + root = new LinkedHashMap<>(); } } @@ -167,18 +160,15 @@ public class YAMLProcessor extends YAMLNode { * @return true if it was successful */ public boolean save() { - OutputStream stream = null; File parent = file.getParentFile(); - if (parent != null) { parent.mkdirs(); } - - try { - stream = getOutputStream(); - if (stream == null) return false; - OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8"); + try (OutputStream stream = getOutputStream()) { + if (stream == null) + return false; + OutputStreamWriter writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8); if (header != null) { writer.append(header); writer.append(LINE_BREAK); @@ -187,7 +177,7 @@ public class YAMLProcessor extends YAMLNode { yaml.dump(root, writer); } else { // Iterate over each root-level property and dump - for (Entry entry : root.entrySet()) { + for (Entry entry: root.entrySet()) { // Output comment, if present String comment = comments.get(entry.getKey()); if (comment != null) { @@ -202,12 +192,6 @@ public class YAMLProcessor extends YAMLNode { } return true; } catch (IOException ignored) { - } finally { - try { - if (stream != null) { - stream.close(); - } - } catch (IOException ignored) {} } return false; @@ -217,9 +201,9 @@ public class YAMLProcessor extends YAMLNode { private void read(Object input) throws YAMLProcessorException { try { if (null == input) { - root = new LinkedHashMap(); + root = new LinkedHashMap<>(); } else { - root = new LinkedHashMap((Map) input); + root = new LinkedHashMap<>((Map) input); } } catch (ClassCastException e) { throw new YAMLProcessorException("Root document must be an key-value structure"); @@ -302,7 +286,7 @@ public class YAMLProcessor extends YAMLNode { * @return a node */ public static YAMLNode getEmptyNode(boolean writeDefaults) { - return new YAMLNode(new LinkedHashMap(), writeDefaults); + return new YAMLNode(new LinkedHashMap<>(), writeDefaults); } // This will be included in snakeyaml 1.10, but until then we have to do it manually. @@ -321,12 +305,7 @@ public class YAMLProcessor extends YAMLNode { private static class FancyRepresenter extends Representer { private FancyRepresenter() { - this.nullRepresenter = new Represent() { - @Override - public Node representData(Object o) { - return representScalar(Tag.NULL, ""); - } - }; + this.nullRepresenter = o -> representScalar(Tag.NULL, ""); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java index 5acdccd48..71e3cc370 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java @@ -159,7 +159,6 @@ public class CuboidClipboard { * * @param angle in degrees */ - @SuppressWarnings("deprecation") public void rotate2D(int angle) { angle = angle % 360; if (angle % 90 != 0) { // Can only rotate 90 degrees at the moment @@ -229,7 +228,6 @@ public class CuboidClipboard { * @param dir direction to flip * @param aroundPlayer flip the offset around the player */ - @SuppressWarnings("deprecation") public void flip(FlipDirection dir, boolean aroundPlayer) { checkNotNull(dir); @@ -607,8 +605,8 @@ public class CuboidClipboard { * @return a block distribution */ public List> getBlockDistribution() { - List> distribution = new ArrayList>(); - Map> map = new HashMap>(); + List> distribution = new ArrayList<>(); + Map> map = new HashMap<>(); int maxX = getWidth(); int maxY = getHeight(); @@ -627,7 +625,7 @@ public class CuboidClipboard { if (map.containsKey(id)) { map.get(id).increment(); } else { - Countable c = new Countable(id, 1); + Countable c = new Countable<>(id, 1); map.put(id, c); distribution.add(c); } @@ -648,8 +646,8 @@ public class CuboidClipboard { */ // TODO reduce code duplication public List> getBlockDistributionWithData() { - List> distribution = new ArrayList>(); - Map> map = new HashMap>(); + List> distribution = new ArrayList<>(); + Map> map = new HashMap<>(); int maxX = getWidth(); int maxY = getHeight(); @@ -669,7 +667,7 @@ public class CuboidClipboard { if (map.containsKey(bareBlock)) { map.get(bareBlock).increment(); } else { - Countable c = new Countable(bareBlock, 1); + Countable c = new Countable<>(bareBlock, 1); map.put(bareBlock, c); distribution.add(c); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index e24caa27d..0537110fd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -374,30 +374,6 @@ public class EditSession implements Extent { return world.getBlock(position); } - /** - * Get a block type at the given position. - * - * @param position the position - * @return the block type - * @deprecated Use {@link #getLazyBlock(Vector)} or {@link #getBlock(Vector)} - */ - @Deprecated - public int getBlockType(Vector position) { - return world.getBlockType(position); - } - - /** - * Get a block data at the given position. - * - * @param position the position - * @return the block data - * @deprecated Use {@link #getLazyBlock(Vector)} or {@link #getBlock(Vector)} - */ - @Deprecated - public int getBlockData(Vector position) { - return world.getBlockData(position); - } - /** * Gets the block type at a position. * @@ -436,8 +412,9 @@ public class EditSession implements Extent { public int getHighestTerrainBlock(int x, int z, int minY, int maxY, boolean naturalOnly) { for (int y = maxY; y >= minY; --y) { Vector pt = new Vector(x, y, z); - int id = getBlockType(pt); - int data = getBlockData(pt); + BaseBlock block = getLazyBlock(pt); + int id = block.getId(); + int data = block.getData(); if (naturalOnly ? BlockType.isNaturalTerrainBlock(id, data) : !BlockType.canPassThrough(id, data)) { return y; } @@ -538,35 +515,6 @@ public class EditSession implements Extent { return affected; } - /** - * Set a block (only if a previous block was not there) if {@link Math#random()} - * returns a number less than the given probability. - * - * @param position the position - * @param block the block - * @param probability a probability between 0 and 1, inclusive - * @return whether a block was changed - * @throws MaxChangedBlocksException thrown if too many blocks are changed - */ - public boolean setChanceBlockIfAir(Vector position, BaseBlock block, double probability) - throws MaxChangedBlocksException { - return Math.random() <= probability && setBlockIfAir(position, block); - } - - /** - * Set a block only if there's no block already there. - * - * @param position the position - * @param block the block to set - * @return if block was changed - * @throws MaxChangedBlocksException thrown if too many blocks are changed - * @deprecated Use your own method - */ - @Deprecated - public boolean setBlockIfAir(Vector position, BaseBlock block) throws MaxChangedBlocksException { - return getBlock(position).isAir() && setBlock(position, block); - } - @Override @Nullable public Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) { @@ -1504,8 +1452,8 @@ public class EditSession implements Extent { int oy = position.getBlockY(); int oz = position.getBlockZ(); - BaseBlock air = new BaseBlock(0); - BaseBlock water = new BaseBlock(BlockID.STATIONARY_WATER); + BaseBlock air = new BaseBlock(BlockTypes.AIR); + BaseBlock water = new BaseBlock(BlockTypes.WATER); int ceilRadius = (int) Math.ceil(radius); for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) { @@ -1516,26 +1464,18 @@ public class EditSession implements Extent { for (int y = world.getMaxY(); y >= 1; --y) { Vector pt = new Vector(x, y, z); - int id = getBlockType(pt); + com.sk89q.worldedit.blocks.type.BlockType id = getLazyBlock(pt).getType(); - switch (id) { - case BlockID.ICE: + if (id == BlockTypes.ICE) { if (setBlock(pt, water)) { ++affected; } - break; - - case BlockID.SNOW: + } else if (id == BlockTypes.SNOW) { if (setBlock(pt, air)) { ++affected; } - break; - - case BlockID.AIR: + } else if (id == BlockTypes.AIR) { continue; - - default: - break; } break; @@ -1562,8 +1502,8 @@ public class EditSession implements Extent { int oy = position.getBlockY(); int oz = position.getBlockZ(); - BaseBlock ice = new BaseBlock(BlockID.ICE); - BaseBlock snow = new BaseBlock(BlockID.SNOW); + BaseBlock ice = new BaseBlock(BlockTypes.ICE); + BaseBlock snow = new BaseBlock(BlockTypes.SNOW); int ceilRadius = (int) Math.ceil(radius); for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) { @@ -1574,7 +1514,7 @@ public class EditSession implements Extent { for (int y = world.getMaxY(); y >= 1; --y) { Vector pt = new Vector(x, y, z); - int id = getBlockType(pt); + int id = getLazyBlock(pt).getId(); if (id == BlockID.AIR) { continue; @@ -1613,20 +1553,6 @@ public class EditSession implements Extent { return affected; } - /** - * Make dirt green. - * - * @param position a position - * @param radius a radius - * @return number of blocks affected - * @throws MaxChangedBlocksException thrown if too many blocks are changed - * @deprecated Use {@link #green(Vector, double, boolean)}. - */ - @Deprecated - public int green(Vector position, double radius) throws MaxChangedBlocksException { - return green(position, radius, true); - } - /** * Make dirt green. * @@ -1656,8 +1582,9 @@ public class EditSession implements Extent { loop: for (int y = world.getMaxY(); y >= 1; --y) { final Vector pt = new Vector(x, y, z); - final int id = getBlockType(pt); - final int data = getBlockData(pt); + final BaseBlock block = getLazyBlock(pt); + final int id = block.getId(); + final int data = block.getData(); switch (id) { case BlockID.DIRT: @@ -1789,7 +1716,7 @@ public class EditSession implements Extent { for (int z = minZ; z <= maxZ; ++z) { Vector pt = new Vector(x, y, z); - int id = getBlockType(pt); + int id = getLazyBlock(pt).getId(); if (map.containsKey(id)) { map.get(id).increment(); @@ -1803,7 +1730,7 @@ public class EditSession implements Extent { } } else { for (Vector pt : region) { - int id = getBlockType(pt); + int id = getLazyBlock(pt).getId(); if (map.containsKey(id)) { map.get(id).increment(); @@ -1848,7 +1775,7 @@ public class EditSession implements Extent { for (int z = minZ; z <= maxZ; ++z) { Vector pt = new Vector(x, y, z); - BaseBlock blk = new BaseBlock(getBlockType(pt), getBlockData(pt)); + BaseBlock blk = getBlock(pt); if (map.containsKey(blk)) { map.get(blk).increment(); @@ -1862,7 +1789,7 @@ public class EditSession implements Extent { } } else { for (Vector pt : region) { - BaseBlock blk = new BaseBlock(getBlockType(pt), getBlockData(pt)); + BaseBlock blk = getBlock(pt); if (map.containsKey(blk)) { map.get(blk).increment(); @@ -1935,8 +1862,7 @@ public class EditSession implements Extent { final BlockVector sourcePosition = environment.toWorld(x.getValue(), y.getValue(), z.getValue()); // read block from world - // TODO: use getBlock here once the reflection is out of the way - final BaseBlock material = new BaseBlock(world.getBlockType(sourcePosition), world.getBlockData(sourcePosition)); + final BaseBlock material = world.getBlock(sourcePosition); // queue operation queue.put(position, material); @@ -2202,7 +2128,8 @@ public class EditSession implements Extent { while (!queue.isEmpty()) { final BlockVector current = queue.removeFirst(); - if (!BlockType.canPassThrough(getBlockType(current), getBlockData(current))) { + final BaseBlock block = getLazyBlock(current); + if (!BlockType.canPassThrough(block.getId(), block.getData())) { continue; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java index 3266671b3..613d60941 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java @@ -79,7 +79,7 @@ public abstract class LocalConfiguration { }; public boolean profile = false; - public Set disallowedBlocks = new HashSet(); + public Set disallowedBlocks = new HashSet<>(); public int defaultChangeLimit = -1; public int maxChangeLimit = -1; public int defaultMaxPolygonalPoints = -1; @@ -106,7 +106,7 @@ public abstract class LocalConfiguration { public int navigationWand = ItemID.COMPASS; public int navigationWandMaxDistance = 50; public int scriptTimeout = 3000; - public Set allowedDataCycleBlocks = new HashSet(); + public Set allowedDataCycleBlocks = new HashSet<>(); public String saveDir = "schematics"; public String scriptsDir = "craftscripts"; public boolean showHelpInfo = true; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java index 7114db65a..43471520d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -191,50 +191,9 @@ public class WorldEdit { return sessions; } - /** - * @deprecated Use {@link #getSessionManager()} - */ - @Deprecated - public LocalSession getSession(String player) { - return sessions.findByName(player); - } - - /** - * @deprecated use {@link #getSessionManager()} - */ - @Deprecated - public LocalSession getSession(Player player) { - return sessions.get(player); - } - - /** - * @deprecated use {@link #getSessionManager()} - */ - @Deprecated - public void removeSession(Player player) { - sessions.remove(player); - } - - /** - * @deprecated use {@link #getSessionManager()} - */ - @Deprecated - public void clearSessions() { - sessions.clear(); - } - - /** - * @deprecated use {@link #getSessionManager()} - */ - @Deprecated - public boolean hasSession(Player player) { - return sessions.contains(player); - } - /** * @deprecated Use {@link #getBlockFactory()} and {@link BlockFactory#parseFromInput(String, ParserContext)} */ - @SuppressWarnings("deprecation") @Deprecated public BaseBlock getBlock(Player player, String arg, boolean allAllowed) throws WorldEditException { return getBlock(player, arg, allAllowed, false); @@ -243,13 +202,12 @@ public class WorldEdit { /** * @deprecated Use {@link #getBlockFactory()} and {@link BlockFactory#parseFromInput(String, ParserContext)} */ - @SuppressWarnings("deprecation") @Deprecated public BaseBlock getBlock(Player player, String arg, boolean allAllowed, boolean allowNoData) throws WorldEditException { ParserContext context = new ParserContext(); context.setActor(player); context.setWorld(player.getWorld()); - context.setSession(getSession(player)); + context.setSession(getSessionManager().get(player)); context.setRestricted(!allAllowed); context.setPreferringWildcard(allowNoData); return getBlockFactory().parseFromInput(arg, context); @@ -258,7 +216,6 @@ public class WorldEdit { /** * @deprecated Use {@link #getBlockFactory()} and {@link BlockFactory#parseFromInput(String, ParserContext)} */ - @SuppressWarnings("deprecation") @Deprecated public BaseBlock getBlock(Player player, String id) throws WorldEditException { return getBlock(player, id, false); @@ -268,10 +225,9 @@ public class WorldEdit { * @deprecated Use {@link #getBlockFactory()} and {@link BlockFactory#parseFromListInput(String, ParserContext)} */ @Deprecated - @SuppressWarnings("deprecation") public Set getBlocks(Player player, String list, boolean allAllowed, boolean allowNoData) throws WorldEditException { String[] items = list.split(","); - Set blocks = new HashSet(); + Set blocks = new HashSet<>(); for (String id : items) { blocks.add(getBlock(player, id, allAllowed, allowNoData)); } @@ -282,7 +238,6 @@ public class WorldEdit { * @deprecated Use {@link #getBlockFactory()} and {@link BlockFactory#parseFromInput(String, ParserContext)} */ @Deprecated - @SuppressWarnings("deprecation") public Set getBlocks(Player player, String list, boolean allAllowed) throws WorldEditException { return getBlocks(player, list, allAllowed, false); } @@ -291,7 +246,6 @@ public class WorldEdit { * @deprecated Use {@link #getBlockFactory()} and {@link BlockFactory#parseFromListInput(String, ParserContext)} */ @Deprecated - @SuppressWarnings("deprecation") public Set getBlocks(Player player, String list) throws WorldEditException { return getBlocks(player, list, false); } @@ -300,10 +254,9 @@ public class WorldEdit { * @deprecated Use {@link #getBlockFactory()} and {@link BlockFactory#parseFromListInput(String, ParserContext)} */ @Deprecated - @SuppressWarnings("deprecation") public Set getBlockIDs(Player player, String list, boolean allBlocksAllowed) throws WorldEditException { String[] items = list.split(","); - Set blocks = new HashSet(); + Set blocks = new HashSet<>(); for (String s : items) { blocks.add(getBlock(player, s, allBlocksAllowed).getType().getLegacyId()); } @@ -736,7 +689,7 @@ public class WorldEdit { engine.setTimeLimit(getConfiguration().scriptTimeout); - Map vars = new HashMap(); + Map vars = new HashMap<>(); vars.put("argv", args); vars.put("context", scriptContext); vars.put("player", player); @@ -747,9 +700,7 @@ public class WorldEdit { player.printError("Failed to execute:"); player.printRaw(e.getMessage()); logger.log(Level.WARNING, "Failed to execute script", e); - } catch (NumberFormatException e) { - throw e; - } catch (WorldEditException e) { + } catch (NumberFormatException | WorldEditException e) { throw e; } catch (Throwable e) { player.printError("Failed to execute (see console):"); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockType.java index e1e162ef3..e68df4b3f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockType.java @@ -299,11 +299,11 @@ 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; @@ -383,8 +383,8 @@ public enum BlockType { } } - private static final Map itemBlockMapping = new HashMap(); - private static final Map dataItemBlockMapping = new HashMap(); + private static final Map itemBlockMapping = new HashMap<>(); + private static final Map dataItemBlockMapping = new HashMap<>(); static { for (int data = 0; data < 16; ++data) { dataItemBlockMapping.put(typeDataKey(BlockID.DIRT, data), new BaseBlock(BlockID.DIRT, data)); @@ -472,7 +472,7 @@ public enum BlockType { /** * HashSet for shouldPlaceLast. */ - private static final Set shouldPlaceLast = new HashSet(); + private static final Set shouldPlaceLast = new HashSet<>(); static { shouldPlaceLast.add(BlockID.SAPLING); shouldPlaceLast.add(BlockID.BED); @@ -551,7 +551,7 @@ public enum BlockType { /** * HashSet for shouldPlaceLast. */ - private static final Set shouldPlaceFinal = new HashSet(); + private static final Set shouldPlaceFinal = new HashSet<>(); static { shouldPlaceFinal.add(BlockID.SIGN_POST); shouldPlaceFinal.add(BlockID.WOODEN_DOOR); @@ -586,7 +586,7 @@ public enum BlockType { /** * HashSet for canPassThrough. */ - private static final Set canPassThrough = new HashSet(); + private static final Set canPassThrough = new HashSet<>(); static { canPassThrough.add(BlockID.AIR); canPassThrough.add(BlockID.WATER); @@ -688,7 +688,7 @@ public enum BlockType { /** * HashSet for centralTopLimit. */ - private static final Map centralTopLimit = new HashMap(); + private static final Map centralTopLimit = new HashMap<>(); static { centralTopLimit.put(BlockID.BED, 0.5625); centralTopLimit.put(BlockID.BREWING_STAND, 0.875); @@ -789,7 +789,7 @@ public enum BlockType { /** * HashSet for usesData. */ - private static final Set usesData = new HashSet(); + private static final Set usesData = new HashSet<>(); static { usesData.add(BlockID.STONE); usesData.add(BlockID.DIRT); @@ -934,7 +934,7 @@ public enum BlockType { /** * HashSet for isContainerBlock. */ - private static final Set isContainerBlock = new HashSet(); + private static final Set isContainerBlock = new HashSet<>(); static { isContainerBlock.add(BlockID.DISPENSER); isContainerBlock.add(BlockID.FURNACE); @@ -969,7 +969,7 @@ public enum BlockType { /** * HashSet for isRedstoneBlock. */ - private static final Set isRedstoneBlock = new HashSet(); + private static final Set isRedstoneBlock = new HashSet<>(); static { isRedstoneBlock.add(BlockID.POWERED_RAIL); isRedstoneBlock.add(BlockID.DETECTOR_RAIL); @@ -1032,7 +1032,7 @@ public enum BlockType { /** * HashSet for canTransferRedstone. */ - private static final Set canTransferRedstone = new HashSet(); + private static final Set canTransferRedstone = new HashSet<>(); static { canTransferRedstone.add(BlockID.REDSTONE_TORCH_OFF); canTransferRedstone.add(BlockID.REDSTONE_TORCH_ON); @@ -1069,7 +1069,7 @@ public enum BlockType { /** * HashSet for isRedstoneSource. */ - private static final Set isRedstoneSource = new HashSet(); + private static final Set isRedstoneSource = new HashSet<>(); static { isRedstoneSource.add(BlockID.DETECTOR_RAIL); isRedstoneSource.add(BlockID.REDSTONE_TORCH_OFF); @@ -1109,7 +1109,7 @@ public enum BlockType { /** * HashSet for isRailBlock. */ - private static final Set isRailBlock = new HashSet(); + private static final Set isRailBlock = new HashSet<>(); static { isRailBlock.add(BlockID.POWERED_RAIL); isRailBlock.add(BlockID.DETECTOR_RAIL); @@ -1139,7 +1139,7 @@ public enum BlockType { /** * HashSet for isNaturalBlock. */ - private static final Set isNaturalTerrainBlock = new HashSet(); + private static final Set isNaturalTerrainBlock = new HashSet<>(); static { isNaturalTerrainBlock.add(BlockID.STONE); isNaturalTerrainBlock.add(BlockID.GRASS); @@ -1215,7 +1215,7 @@ public enum BlockType { /** * HashSet for emitsLight. */ - private static final Set emitsLight = new HashSet(); + private static final Set emitsLight = new HashSet<>(); static { emitsLight.add(BlockID.LAVA); emitsLight.add(BlockID.STATIONARY_LAVA); @@ -1253,7 +1253,7 @@ public enum BlockType { /** * HashSet for isTranslucent. */ - private static final Set isTranslucent = new HashSet(); + private static final Set isTranslucent = new HashSet<>(); static { isTranslucent.add(BlockID.AIR); isTranslucent.add(BlockID.SAPLING); @@ -1395,8 +1395,8 @@ public enum BlockType { /** * HashMap for getBlockBagItem. */ - private static final Map dataBlockBagItems = new HashMap(); - private static final Map nonDataBlockBagItems = new HashMap(); + private static final Map dataBlockBagItems = new HashMap<>(); + private static final Map nonDataBlockBagItems = new HashMap<>(); private static final BaseItem doNotDestroy = new BaseItemStack(BlockID.AIR, 0); static { /* @@ -1886,8 +1886,8 @@ public enum BlockType { } } - private static final Map dataAttachments = new HashMap(); - private static final Map nonDataAttachments = new HashMap(); + private static final Map dataAttachments = new HashMap<>(); + private static final Map nonDataAttachments = new HashMap<>(); static { nonDataAttachments.put(BlockID.SAPLING, PlayerDirection.DOWN); nonDataAttachments.put(BlockID.LONG_GRASS, PlayerDirection.DOWN); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/ClothColor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/ClothColor.java index 76e362e7f..5cf0a5e3f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/ClothColor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/ClothColor.java @@ -73,11 +73,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; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/ItemType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/ItemType.java index 97e95e86b..809162ec6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/ItemType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/ItemType.java @@ -488,11 +488,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; @@ -636,7 +636,7 @@ public enum ItemType { return lookupKeys; } - private static final Set shouldNotStack = new HashSet(); + private static final Set shouldNotStack = new HashSet<>(); static { shouldNotStack.add(ItemID.IRON_SHOVEL); shouldNotStack.add(ItemID.IRON_PICK); @@ -735,7 +735,7 @@ public enum ItemType { return shouldNotStack.contains(id); } - private static final Set usesDamageValue = new HashSet(); + private static final Set usesDamageValue = new HashSet<>(); static { usesDamageValue.add(BlockID.DIRT); usesDamageValue.add(BlockID.WOOD); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockTypes.java index b3b237601..7b6316b01 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockTypes.java @@ -22,7 +22,6 @@ package com.sk89q.worldedit.blocks.type; import java.lang.reflect.Field; import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; import javax.annotation.Nullable; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java index 848540dd6..fdf4a39f5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java @@ -141,7 +141,7 @@ public class BiomeCommands { qualifier = "at line of sight point"; } else if (args.hasFlag('p')) { - BaseBiome biome = player.getWorld().getBiome(player.getPosition().toVector().toVector2D()); + BaseBiome biome = player.getWorld().getBiome(player.getLocation().toVector().toVector2D()); biomes.add(biome); qualifier = "at your position"; @@ -192,7 +192,7 @@ public class BiomeCommands { Mask2D mask2d = mask != null ? mask.toMask2D() : null; if (atPosition) { - region = new CuboidRegion(player.getPosition().toVector(), player.getPosition().toVector()); + region = new CuboidRegion(player.getLocation().toVector(), player.getLocation().toVector()); } else { region = session.getSelection(world); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index 631f17ae9..d0a5f6577 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -29,7 +29,6 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.command.tool.BrushTool; import com.sk89q.worldedit.command.tool.brush.ButcherBrush; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java index 5c1e47150..e9121ae39 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java @@ -195,7 +195,6 @@ public class GenerationCommands { ) @CommandPermissions("worldedit.generation.forest") @Logging(POSITION) - @SuppressWarnings("deprecation") public void forestGen(Player player, LocalSession session, EditSession editSession, @Optional("10") int size, @Optional("tree") TreeType type, @Optional("5") double density) throws WorldEditException { density = density / 100; int affected = editSession.makeForest(session.getPlacementPosition(player), size, density, new TreeGenerator(type)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java index eda112bbd..a895e183f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java @@ -60,7 +60,7 @@ public class HistoryCommands { undone = session.undo(session.getBlockBag(player), player); } else { player.checkPermission("worldedit.history.undo.other"); - LocalSession sess = worldEdit.getSession(args.getString(1)); + LocalSession sess = worldEdit.getSessionManager().findByName(args.getString(1)); if (sess == null) { player.printError("Unable to find session for " + args.getString(1)); break; @@ -95,7 +95,7 @@ public class HistoryCommands { redone = session.redo(session.getBlockBag(player), player); } else { player.checkPermission("worldedit.history.redo.other"); - LocalSession sess = worldEdit.getSession(args.getString(1)); + LocalSession sess = worldEdit.getSessionManager().findByName(args.getString(1)); if (sess == null) { player.printError("Unable to find session for " + args.getString(1)); break; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index a72e7b872..9d14467a6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -19,6 +19,8 @@ package com.sk89q.worldedit.command; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandException; @@ -52,14 +54,11 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Commands that work with schematic files. */ @@ -107,8 +106,7 @@ public class SchematicCommands { return; } - Closer closer = Closer.create(); - try { + try (Closer closer = Closer.create()) { FileInputStream fis = closer.register(new FileInputStream(f)); BufferedInputStream bis = closer.register(new BufferedInputStream(fis)); ClipboardReader reader = format.getReader(bis); @@ -122,11 +120,6 @@ public class SchematicCommands { } catch (IOException e) { player.printError("Schematic could not read or it does not exist: " + e.getMessage()); log.log(Level.WARNING, "Failed to load a saved clipboard", e); - } finally { - try { - closer.close(); - } catch (IOException ignored) { - } } } @@ -165,8 +158,7 @@ public class SchematicCommands { target = clipboard; } - Closer closer = Closer.create(); - try { + try (Closer closer = Closer.create()) { // Create parent directories File parent = f.getParentFile(); if (parent != null && !parent.exists()) { @@ -184,11 +176,6 @@ public class SchematicCommands { } catch (IOException e) { player.printError("Schematic could not written: " + e.getMessage()); log.log(Level.WARNING, "Failed to write a saved clipboard", e); - } finally { - try { - closer.close(); - } catch (IOException ignored) { - } } } @@ -283,24 +270,21 @@ public class SchematicCommands { final int sortType = args.hasFlag('d') ? -1 : args.hasFlag('n') ? 1 : 0; // cleanup file list - Arrays.sort(files, new Comparator(){ - @Override - public int compare(File f1, File f2) { - // http://stackoverflow.com/questions/203030/best-way-to-list-files-in-java-sorted-by-date-modified - int res; - if (sortType == 0) { // use name by default - int p = f1.getParent().compareTo(f2.getParent()); - if (p == 0) { // same parent, compare names - res = f1.getName().compareTo(f2.getName()); - } else { // different parent, sort by that - res = p; - } - } else { - res = Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); // use date if there is a flag - if (sortType == 1) res = -res; // flip date for newest first instead of oldest first + Arrays.sort(files, (f1, f2) -> { + // http://stackoverflow.com/questions/203030/best-way-to-list-files-in-java-sorted-by-date-modified + int res; + if (sortType == 0) { // use name by default + int p = f1.getParent().compareTo(f2.getParent()); + if (p == 0) { // same parent, compare names + res = f1.getName().compareTo(f2.getName()); + } else { // different parent, sort by that + res = p; } - return res; + } else { + res = Long.compare(f1.lastModified(), f2.lastModified()); // use date if there is a flag + if (sortType == 1) res = -res; // flip date for newest first instead of oldest first } + return res; }); List schematics = listFiles(worldEdit.getConfiguration().saveDir, files); @@ -322,7 +306,7 @@ public class SchematicCommands { private List allFiles(File root) { File[] files = root.listFiles(); if (files == null) return null; - List fileList = new ArrayList(); + List fileList = new ArrayList<>(); for (File f : files) { if (f.isDirectory()) { List subFiles = allFiles(f); @@ -337,7 +321,7 @@ public class SchematicCommands { private List listFiles(String prefix, File[] files) { if (prefix == null) prefix = ""; - List result = new ArrayList(); + List result = new ArrayList<>(); for (File file : files) { StringBuilder build = new StringBuilder(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java index 2e2be7bb4..8c83bdcac 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java @@ -19,7 +19,9 @@ package com.sk89q.worldedit.command; -import com.google.common.base.Optional; +import static com.sk89q.minecraft.util.commands.Logging.LogMode.POSITION; +import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; + import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandException; @@ -59,11 +61,9 @@ import com.sk89q.worldedit.world.storage.ChunkStore; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.Set; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.POSITION; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; - /** * Selection commands. */ @@ -332,7 +332,7 @@ public class SelectionCommands { return; } - List dirs = new ArrayList(); + List dirs = new ArrayList<>(); int change = args.getInteger(0); int reverseChange = 0; @@ -405,7 +405,7 @@ public class SelectionCommands { @CommandPermissions("worldedit.selection.contract") public void contract(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { - List dirs = new ArrayList(); + List dirs = new ArrayList<>(); int change = args.getInteger(0); int reverseChange = 0; @@ -480,7 +480,7 @@ public class SelectionCommands { @CommandPermissions("worldedit.selection.shift") public void shift(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { - List dirs = new ArrayList(); + List dirs = new ArrayList<>(); int change = args.getInteger(0); if (args.argsLength() == 2) { if (args.getString(1).contains(",")) { @@ -558,7 +558,7 @@ public class SelectionCommands { } private Vector[] getChangesForEachDir(CommandContext args) { - List changes = new ArrayList(6); + List changes = new ArrayList<>(6); int change = args.getInteger(0); if (!args.hasFlag('h')) { @@ -739,9 +739,7 @@ public class SelectionCommands { selector = new Polygonal2DRegionSelector(oldSelector); player.print("2D polygon selector: Left/right click to add a point."); Optional limit = ActorSelectorLimits.forActor(player).getPolygonVertexLimit(); - if (limit.isPresent()) { - player.print(limit.get() + " points maximum."); - } + limit.ifPresent(integer -> player.print(integer + " points maximum.")); } else if (typeName.equalsIgnoreCase("ellipsoid")) { selector = new EllipsoidRegionSelector(oldSelector); player.print("Ellipsoid selector: left click=center, right click to extend"); @@ -755,9 +753,7 @@ public class SelectionCommands { selector = new ConvexPolyhedralRegionSelector(oldSelector); player.print("Convex polyhedral selector: Left click=First vertex, right click to add more."); Optional limit = ActorSelectorLimits.forActor(player).getPolyhedronVertexLimit(); - if (limit.isPresent()) { - player.print(limit.get() + " points maximum."); - } + limit.ifPresent(integer -> player.print(integer + " points maximum.")); } else { CommandListBox box = new CommandListBox("Selection modes"); StyledFragment contents = box.getContents(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java index 9eeacf199..7dc61dba7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java @@ -115,10 +115,7 @@ public class SnapshotUtilCommands { try { chunkStore = snapshot.getChunkStore(); player.print("Snapshot '" + snapshot.getName() + "' loaded; now restoring..."); - } catch (DataException e) { - player.printError("Failed to load snapshot: " + e.getMessage()); - return; - } catch (IOException e) { + } catch (DataException | IOException e) { player.printError("Failed to load snapshot: " + e.getMessage()); return; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java index 0e4734ecf..1c3a05d23 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java @@ -74,7 +74,6 @@ public class ToolCommands { max = 1 ) @CommandPermissions("worldedit.tool.tree") - @SuppressWarnings("deprecation") public void tree(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { TreeGenerator.TreeType type = args.argsLength() > 0 ? diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index 5da53420c..08dc0dd6f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -426,7 +426,7 @@ public class UtilityCommands { CreatureButcher flags = new CreatureButcher(actor); flags.fromCommand(args); - List visitors = new ArrayList(); + List visitors = new ArrayList<>(); LocalSession session = null; EditSession editSession = null; @@ -486,7 +486,7 @@ public class UtilityCommands { EntityRemover remover = new EntityRemover(); remover.fromString(typeStr); - List visitors = new ArrayList(); + List visitors = new ArrayList<>(); LocalSession session = null; EditSession editSession = null; @@ -606,7 +606,7 @@ public class UtilityCommands { } boolean isRootLevel = true; - List visited = new ArrayList(); + List visited = new ArrayList<>(); // Drill down to the command for (int i = 0; i < effectiveLength; i++) { @@ -646,8 +646,8 @@ public class UtilityCommands { Dispatcher dispatcher = (Dispatcher) callable; // Get a list of aliases - List aliases = new ArrayList(dispatcher.getCommands()); - Collections.sort(aliases, new PrimaryAliasComparator(CommandManager.COMMAND_CLEAN_PATTERN)); + List aliases = new ArrayList<>(dispatcher.getCommands()); + aliases.sort(new PrimaryAliasComparator(CommandManager.COMMAND_CLEAN_PATTERN)); // Calculate pagination int offset = perPage * page; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PatternParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PatternParser.java index 7a5f9a928..524da7792 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PatternParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/PatternParser.java @@ -61,8 +61,6 @@ public class PatternParser extends SimpleCommand { try { return WorldEdit.getInstance().getPatternFactory().parseFromInput(patternString, parserContext); - } catch (NoMatchException e) { - throw new CommandException(e.getMessage(), e); } catch (InputParseException e) { throw new CommandException(e.getMessage(), e); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFactoryParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFactoryParser.java index 25493f363..9ec0ce101 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFactoryParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegionFactoryParser.java @@ -40,14 +40,17 @@ public class RegionFactoryParser implements CommandExecutor { try { String type = args.next(); - if (type.equals("cuboid")) { - return new CuboidRegionFactory(); - } else if (type.equals("sphere")) { - return new SphereRegionFactory(); - } else if (type.equals("cyl") || type.equals("cylinder")) { - return new CylinderRegionFactory(1); // TODO: Adjustable height - } else { - throw new CommandException("Unknown shape type: " + type + " (try one of " + getUsage() + ")"); + switch (type) { + case "cuboid": + return new CuboidRegionFactory(); + case "sphere": + return new SphereRegionFactory(); + case "cyl": + case "cylinder": + return new CylinderRegionFactory(1); // TODO: Adjustable height + + default: + throw new CommandException("Unknown shape type: " + type + " (try one of " + getUsage() + ")"); } } catch (MissingArgumentException e) { throw new CommandException("Missing shape type (try one of " + getUsage() + ")"); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java index faeb30928..f2e1beb11 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/ShapedBrushCommand.java @@ -74,9 +74,7 @@ public class ShapedBrushCommand extends SimpleCommand { BrushTool tool = session.getBrushTool(player.getItemInHand()); tool.setSize(radius); tool.setBrush(new OperationFactoryBrush(factory, regionFactory), permission); - } catch (MaxBrushRadiusException e) { - WorldEdit.getInstance().getPlatformManager().getCommandManager().getExceptionConverter().convert(e); - } catch (InvalidToolBindException e) { + } catch (MaxBrushRadiusException | InvalidToolBindException e) { WorldEdit.getInstance().getPlatformManager().getCommandManager().getExceptionConverter().convert(e); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java index ec2a05559..85e0c56b1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java @@ -46,8 +46,9 @@ public class BlockDataCyler implements DoubleActionBlockTool { World world = (World) clicked.getExtent(); - int type = world.getBlockType(clicked.toVector()); - int data = world.getBlockData(clicked.toVector()); + BaseBlock block = world.getLazyBlock(clicked.toVector()); + int type = block.getId(); + int data = block.getData(); if (!config.allowedDataCycleBlocks.isEmpty() && !player.hasPermission("worldedit.override.data-cycler") @@ -57,14 +58,14 @@ public class BlockDataCyler implements DoubleActionBlockTool { } int increment = forward ? 1 : -1; - BaseBlock block = new BaseBlock(type, BlockData.cycle(type, data, increment)); + BaseBlock newBlock = new BaseBlock(type, BlockData.cycle(type, data, increment)); EditSession editSession = session.createEditSession(player); - if (block.getData() < 0) { + if (newBlock.getData() < 0) { player.printError("That block's data cannot be cycled!"); } else { try { - editSession.setBlock(clicked.toVector(), block); + editSession.setBlock(clicked.toVector(), newBlock); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); } finally { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java index 8a375e376..7d3bc9698 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java @@ -56,7 +56,7 @@ public class FloatingTreeRemover implements BlockTool { final World world = (World) clicked.getExtent(); - switch (world.getBlockType(clicked.toVector())) { + switch (world.getLazyBlock(clicked.toVector()).getId()) { case BlockID.LOG: case BlockID.LOG2: case BlockID.LEAVES: @@ -119,8 +119,8 @@ public class FloatingTreeRemover implements BlockTool { * @return a set containing all blocks in the tree/shroom or null if this is not a floating tree/shroom. */ private Set bfs(World world, Vector origin) throws MaxChangedBlocksException { - final Set visited = new HashSet(); - final LinkedList queue = new LinkedList(); + final Set visited = new HashSet<>(); + final LinkedList queue = new LinkedList<>(); queue.addLast(origin); visited.add(origin); @@ -135,7 +135,7 @@ public class FloatingTreeRemover implements BlockTool { } if (visited.add(next)) { - switch (world.getBlockType(next)) { + switch (world.getLazyBlock(next).getId()) { case BlockID.AIR: case BlockID.SNOW: // we hit air or snow => stop walking this route @@ -154,7 +154,7 @@ public class FloatingTreeRemover implements BlockTool { default: // we hit something solid - evaluate where we came from - final int curId = world.getBlockType(current); + final int curId = world.getLazyBlock(current).getId(); if (curId == BlockID.LEAVES || curId == BlockID.LEAVES2 || curId == BlockID.VINE) { // leaves touching a wall/the ground => stop walking this route diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java index 1db0ac5e5..dd2a73d86 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java @@ -20,7 +20,8 @@ package com.sk89q.worldedit.command.tool; import com.sk89q.worldedit.*; -import com.sk89q.worldedit.blocks.BlockID; +import com.sk89q.worldedit.blocks.type.BlockType; +import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; @@ -53,13 +54,13 @@ public class FloodFillTool implements BlockTool { public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) { World world = (World) clicked.getExtent(); - int initialType = world.getBlockType(clicked.toVector()); + BlockType initialType = world.getLazyBlock(clicked.toVector()).getType(); - if (initialType == BlockID.AIR) { + if (initialType == BlockTypes.AIR) { return true; } - if (initialType == BlockID.BEDROCK && !player.canDestroyBedrock()) { + if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) { return true; } @@ -67,7 +68,7 @@ public class FloodFillTool implements BlockTool { try { recurse(server, editSession, world, clicked.toVector().toBlockVector(), - clicked.toVector(), range, initialType, new HashSet()); + clicked.toVector(), range, initialType.getLegacyId(), new HashSet<>()); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); } finally { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java index 25348565a..ee2182c68 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java @@ -21,7 +21,6 @@ package com.sk89q.worldedit.command.tool; import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.type.BlockType; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.entity.Player; @@ -69,7 +68,7 @@ public class RecursivePickaxe implements BlockTool { try { recurse(server, editSession, world, clicked.toVector().toBlockVector(), - clicked.toVector(), range, initialType, new HashSet()); + clicked.toVector(), range, initialType, new HashSet<>()); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); } finally { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java index 246a6f633..9b8bdb76d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java @@ -25,6 +25,7 @@ import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BlockID; +import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; @@ -43,7 +44,7 @@ public class SinglePickaxe implements BlockTool { @Override public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { World world = (World) clicked.getExtent(); - final int blockType = world.getBlockType(clicked.toVector()); + final int blockType = world.getLazyBlock(clicked.toVector()).getId(); if (blockType == BlockID.BEDROCK && !player.canDestroyBedrock()) { return true; @@ -53,7 +54,7 @@ public class SinglePickaxe implements BlockTool { editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop); try { - editSession.setBlock(clicked.toVector(), new BaseBlock(BlockID.AIR)); + editSession.setBlock(clicked.toVector(), new BaseBlock(BlockTypes.AIR)); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); } finally { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java index 56f4bf5ed..2f8a67463 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java @@ -24,7 +24,6 @@ import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.util.*; -import com.sk89q.worldedit.util.Location; /** * Plants a tree. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java index 904cc8b89..0e708e064 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java @@ -23,7 +23,6 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.function.pattern.Pattern; @@ -44,7 +43,7 @@ public class GravityBrush implements Brush { for (double x = position.getBlockX() + size; x > position.getBlockX() - size; --x) { for (double z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) { double y = startY; - final List blockTypes = new ArrayList(); + final List blockTypes = new ArrayList<>(); for (; y > position.getBlockY() - size; --y) { final Vector pt = new Vector(x, y, z); final BaseBlock block = editSession.getBlock(pt); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java index 7623d338e..96545811a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java @@ -81,62 +81,59 @@ public class CreatureButcher { } public EntityFunction createFunction(final EntityRegistry entityRegistry) { - return new EntityFunction() { - @Override - public boolean apply(Entity entity) throws WorldEditException { - boolean killPets = (flags & Flags.PETS) != 0; - boolean killNPCs = (flags & Flags.NPCS) != 0; - boolean killAnimals = (flags & Flags.ANIMALS) != 0; - boolean killGolems = (flags & Flags.GOLEMS) != 0; - boolean killAmbient = (flags & Flags.AMBIENT) != 0; - boolean killTagged = (flags & Flags.TAGGED) != 0; - boolean killArmorStands = (flags & Flags.ARMOR_STAND) != 0; + return entity -> { + boolean killPets = (flags & Flags.PETS) != 0; + boolean killNPCs = (flags & Flags.NPCS) != 0; + boolean killAnimals = (flags & Flags.ANIMALS) != 0; + boolean killGolems = (flags & Flags.GOLEMS) != 0; + boolean killAmbient = (flags & Flags.AMBIENT) != 0; + boolean killTagged = (flags & Flags.TAGGED) != 0; + boolean killArmorStands = (flags & Flags.ARMOR_STAND) != 0; - EntityType type = entity.getFacet(EntityType.class); + EntityType type = entity.getFacet(EntityType.class); - if (type == null) { - return false; - } - - if (type.isPlayerDerived()) { - return false; - } - - if (!type.isLiving()) { - return false; - } - - if (!killAnimals && type.isAnimal()) { - return false; - } - - if (!killPets && type.isTamed()) { - return false; - } - - if (!killGolems && type.isGolem()) { - return false; - } - - if (!killNPCs && type.isNPC()) { - return false; - } - - if (!killAmbient && type.isAmbient()) { - return false; - } - - if (!killTagged && type.isTagged()) { - return false; - } - - if (!killArmorStands && type.isArmorStand()) { - return false; - } - - entity.remove(); - return true; + if (type == null) { + return false; } + + if (type.isPlayerDerived()) { + return false; + } + + if (!type.isLiving()) { + return false; + } + + if (!killAnimals && type.isAnimal()) { + return false; + } + + if (!killPets && type.isTamed()) { + return false; + } + + if (!killGolems && type.isGolem()) { + return false; + } + + if (!killNPCs && type.isNPC()) { + return false; + } + + if (!killAmbient && type.isAmbient()) { + return false; + } + + if (!killTagged && type.isTagged()) { + return false; + } + + if (!killArmorStands && type.isArmorStand()) { + return false; + } + + entity.remove(); + return true; }; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/EntityRemover.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/EntityRemover.java index b6459b186..d336eda71 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/EntityRemover.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/EntityRemover.java @@ -140,20 +140,17 @@ public class EntityRemover { public EntityFunction createFunction(final EntityRegistry entityRegistry) { final Type type = this.type; - checkNotNull("type can't be null", type); - return new EntityFunction() { - @Override - public boolean apply(Entity entity) throws WorldEditException { - EntityType registryType = entity.getFacet(EntityType.class); - if (registryType != null) { - if (type.matches(registryType)) { - entity.remove(); - return true; - } + checkNotNull(type, "type can't be null"); + return entity -> { + EntityType registryType = entity.getFacet(EntityType.class); + if (registryType != null) { + if (type.matches(registryType)) { + entity.remove(); + return true; } - - return false; } + + return false; }; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java index e60160bbc..d626b73f4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java @@ -229,34 +229,6 @@ public interface Player extends Entity, Actor { */ PlayerDirection getCardinalDirection(); - /** - * Get the actor's position. - * - *

If the actor has no permission, then a dummy location is returned.

- * - * @return the actor's position - * @deprecated use {@link #getLocation()} - */ - Location getPosition(); - - /** - * Get the player's view pitch in degrees. - * - * @return pitch - * @deprecated use {@link #getLocation()} - */ - @Deprecated - double getPitch(); - - /** - * Get the player's view yaw in degrees. - * - * @return yaw - * @deprecated use {@link #getLocation()} - */ - @Deprecated - double getYaw(); - /** * Pass through the wall that you are looking at. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/BlockFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/BlockFactory.java index 43037ccf5..2cb35aab1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/BlockFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/BlockFactory.java @@ -57,7 +57,7 @@ public class BlockFactory extends AbstractFactory { * @throws InputParseException thrown in error with the input */ public Set parseFromListInput(String input, ParserContext context) throws InputParseException { - Set blocks = new HashSet(); + Set blocks = new HashSet<>(); for (String token : input.split(",")) { blocks.add(parseFromInput(token, context)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java index 88d4b53ac..bdba0c924 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java @@ -64,7 +64,7 @@ class DefaultMaskParser extends InputParser { @Override public Mask parseFromInput(String input, ParserContext context) throws InputParseException { - List masks = new ArrayList(); + List masks = new ArrayList<>(); for (String component : input.split(" ")) { if (component.isEmpty()) { @@ -126,7 +126,7 @@ class DefaultMaskParser extends InputParser { return new MaskIntersection(offsetMask, Masks.negate(submask)); case '$': - Set biomes = new HashSet(); + Set biomes = new HashSet<>(); String[] biomesList = component.substring(1).split(","); BiomeRegistry biomeRegistry = context.requireWorld().getWorldData().getBiomeRegistry(); List knownBiomes = biomeRegistry.getBiomes(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java index e7dd15fce..e9ea78519 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java @@ -244,7 +244,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { int initialY = Math.max(0, pos.getBlockY()); int y = Math.max(0, pos.getBlockY() + 2); int z = pos.getBlockZ(); - Extent world = getPosition().getExtent(); + Extent world = getLocation().getExtent(); // No free space above if (world.getBlock(new Vector(x, y, z)).getId() != 0) { @@ -278,7 +278,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { int y = Math.max(0, pos.getBlockY() + 1); final int z = pos.getBlockZ(); final int maxY = Math.min(getWorld().getMaxY() + 1, initialY + distance); - final Extent world = getPosition().getExtent(); + final Extent world = getLocation().getExtent(); while (y <= world.getMaximumPoint().getY() + 2) { if (!BlockType.canPassThrough(world.getBlock(new Vector(x, y, z)))) { @@ -299,7 +299,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { @Override public void floatAt(int x, int y, int z, boolean alwaysGlass) { try { - getPosition().getExtent().setBlock(new Vector(x, y - 1, z), new BaseBlock(BlockTypes.GLASS)); + getLocation().getExtent().setBlock(new Vector(x, y - 1, z), new BaseBlock(BlockTypes.GLASS)); } catch (WorldEditException e) { e.printStackTrace(); } @@ -308,12 +308,12 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { @Override public Location getBlockIn() { - return getPosition(); + return getLocation(); } @Override public Location getBlockOn() { - return getPosition().setY(getPosition().getY() - 1); + return getLocation().setY(getLocation().getY() - 1); } @Override @@ -346,15 +346,15 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { @Override public PlayerDirection getCardinalDirection(int yawOffset) { - if (getPitch() > 67.5) { + if (getLocation().getPitch() > 67.5) { return PlayerDirection.DOWN; } - if (getPitch() < -67.5) { + if (getLocation().getPitch() < -67.5) { return PlayerDirection.UP; } // From hey0's code - double rot = (getYaw() + yawOffset) % 360; //let's use real yaw now + double rot = (getLocation().getYaw() + yawOffset) % 360; //let's use real yaw now if (rot < 0) { rot += 360.0; } @@ -380,7 +380,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { public boolean passThroughForwardWall(int range) { int searchDist = 0; TargetBlock hitBlox = new TargetBlock(this, range, 0.2); - Extent world = getPosition().getExtent(); + Extent world = getLocation().getExtent(); Location block; boolean firstBlock = true; int freeToFind = 2; @@ -422,7 +422,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { @Override public void setPosition(Vector pos) { - setPosition(pos, (float) getPitch(), (float) getYaw()); + setPosition(pos, getLocation().getPitch(), getLocation().getYaw()); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java index 4335afe66..c4ba1c6d0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java @@ -69,8 +69,8 @@ public class PlatformManager { private final WorldEdit worldEdit; private final CommandManager commandManager; - private final List platforms = new ArrayList(); - private final Map preferences = new EnumMap(Capability.class); + private final List platforms = new ArrayList<>(); + private final Map preferences = new EnumMap<>(Capability.class); private @Nullable String firstSeenVersion; private final AtomicBoolean initialized = new AtomicBoolean(); private final AtomicBoolean configured = new AtomicBoolean(); @@ -218,7 +218,7 @@ public class PlatformManager { * @return a list of platforms */ public synchronized List getPlatforms() { - return new ArrayList(platforms); + return new ArrayList<>(platforms); } /** @@ -291,7 +291,6 @@ public class PlatformManager { * @return a {@link ServerInterface} * @throws IllegalStateException if no platform has been registered */ - @SuppressWarnings("deprecation") public ServerInterface getServerInterface() throws IllegalStateException { return ServerInterfaceAdapter.adapt(queryCapability(Capability.USER_COMMANDS)); } @@ -304,7 +303,6 @@ public class PlatformManager { } } - @SuppressWarnings("deprecation") @Subscribe public void handleBlockInteract(BlockInteractEvent event) { // Create a proxy actor with a potentially different world for @@ -385,7 +383,6 @@ public class PlatformManager { } } - @SuppressWarnings("deprecation") @Subscribe public void handlePlayerInput(PlayerInputEvent event) { // Create a proxy actor with a potentially different world for diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java index be4adabb9..64278310d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java @@ -87,21 +87,6 @@ class PlayerProxy extends AbstractPlayerActor { return basePlayer.getLocation(); } - @Override - public Location getPosition() { - return basePlayer.getPosition(); - } - - @Override - public double getPitch() { - return basePlayer.getPitch(); - } - - @Override - public double getYaw() { - return basePlayer.getYaw(); - } - @Override public void setPosition(Vector pos, float pitch, float yaw) { basePlayer.setPosition(pos, pitch, yaw); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/permission/ActorSelectorLimits.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/permission/ActorSelectorLimits.java index 255dbb406..5712fcb4e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/permission/ActorSelectorLimits.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/permission/ActorSelectorLimits.java @@ -19,13 +19,14 @@ package com.sk89q.worldedit.extension.platform.permission; -import com.google.common.base.Optional; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; -import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Optional; public class ActorSelectorLimits implements SelectorLimits { @@ -55,7 +56,7 @@ public class ActorSelectorLimits implements SelectorLimits { if (limit > 0) { return Optional.of(limit); } else { - return Optional.absent(); + return Optional.empty(); } } @@ -74,7 +75,7 @@ public class ActorSelectorLimits implements SelectorLimits { if (limit > 0) { return Optional.of(limit); } else { - return Optional.absent(); + return Optional.empty(); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java index 794183355..e76fa285f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java @@ -85,7 +85,7 @@ public class ChangeSetExtent extends AbstractDelegateExtent { } private List wrapEntities(List entities) { - List newList = new ArrayList(entities.size()); + List newList = new ArrayList<>(entities.size()); for (Entity entity : entities) { newList.add(new TrackedEntity(entity)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java index aed9e356d..eca710dd3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java @@ -23,7 +23,6 @@ import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; @@ -51,7 +50,7 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat private static final BaseBlock AIR = new BaseBlock(BlockTypes.AIR); - private final Map buffer = new LinkedHashMap(); + private final Map buffer = new LinkedHashMap<>(); private final Mask mask; private Vector min = null; private Vector max = null; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index a48d8499f..dd79786f7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -23,7 +23,6 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -48,7 +47,7 @@ public class BlockArrayClipboard implements Clipboard { private final Region region; private Vector origin = new Vector(); private final BaseBlock[][][] blocks; - private final List entities = new ArrayList(); + private final List entities = new ArrayList<>(); /** * Create a new instance. @@ -98,7 +97,7 @@ public class BlockArrayClipboard implements Clipboard { @Override public List getEntities(Region region) { - List filtered = new ArrayList(); + List filtered = new ArrayList<>(); for (Entity entity : entities) { if (region.contains(entity.getLocation().toVector())) { filtered.add(entity); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormat.java index 460d23662..f170db83d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormat.java @@ -65,9 +65,7 @@ public enum ClipboardFormat { @Override public boolean isFormat(File file) { - DataInputStream str = null; - try { - str = new DataInputStream(new GZIPInputStream(new FileInputStream(file))); + try (DataInputStream str = new DataInputStream(new GZIPInputStream(new FileInputStream(file)))) { if ((str.readByte() & 0xFF) != NBTConstants.TYPE_COMPOUND) { return false; } @@ -77,18 +75,11 @@ public enum ClipboardFormat { return name.equals("Schematic"); } catch (IOException e) { return false; - } finally { - if (str != null) { - try { - str.close(); - } catch (IOException ignored) { - } - } } } }; - private static final Map aliasMap = new HashMap(); + private static final Map aliasMap = new HashMap<>(); private final String[] aliases; @@ -107,7 +98,7 @@ public enum ClipboardFormat { * @return a set of aliases */ public Set getAliases() { - return Collections.unmodifiableSet(new HashSet(Arrays.asList(aliases))); + return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(aliases))); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java index a4f4fbaa6..92f05f9d9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java @@ -160,7 +160,7 @@ public class SchematicReader implements ClipboardReader { // Need to pull out tile entities List tileEntities = requireTag(schematic, "TileEntities", ListTag.class).getValue(); - Map> tileEntitiesMap = new HashMap>(); + Map> tileEntitiesMap = new HashMap<>(); for (Tag tag : tileEntities) { if (!(tag instanceof CompoundTag)) continue; @@ -170,21 +170,25 @@ public class SchematicReader implements ClipboardReader { int y = 0; int z = 0; - Map values = new HashMap(); + Map values = new HashMap<>(); for (Map.Entry entry : t.getValue().entrySet()) { - if (entry.getKey().equals("x")) { - if (entry.getValue() instanceof IntTag) { - x = ((IntTag) entry.getValue()).getValue(); - } - } else if (entry.getKey().equals("y")) { - if (entry.getValue() instanceof IntTag) { - y = ((IntTag) entry.getValue()).getValue(); - } - } else if (entry.getKey().equals("z")) { - if (entry.getValue() instanceof IntTag) { - z = ((IntTag) entry.getValue()).getValue(); - } + switch (entry.getKey()) { + case "x": + if (entry.getValue() instanceof IntTag) { + x = ((IntTag) entry.getValue()).getValue(); + } + break; + case "y": + if (entry.getValue() instanceof IntTag) { + y = ((IntTag) entry.getValue()).getValue(); + } + break; + case "z": + if (entry.getValue() instanceof IntTag) { + z = ((IntTag) entry.getValue()).getValue(); + } + break; } values.put(entry.getKey(), entry.getValue()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java index 7ab751992..98a0324ea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java @@ -89,7 +89,7 @@ public class SchematicWriter implements ClipboardWriter { // Metadata // ==================================================================== - HashMap schematic = new HashMap(); + HashMap schematic = new HashMap<>(); schematic.put("Width", new ShortTag((short) width)); schematic.put("Length", new ShortTag((short) length)); schematic.put("Height", new ShortTag((short) height)); @@ -108,7 +108,7 @@ public class SchematicWriter implements ClipboardWriter { byte[] blocks = new byte[width * height * length]; byte[] addBlocks = null; byte[] blockData = new byte[width * height * length]; - List tileEntities = new ArrayList(); + List tileEntities = new ArrayList<>(); for (Vector point : region) { Vector relative = point.subtract(min); @@ -136,7 +136,7 @@ public class SchematicWriter implements ClipboardWriter { // Store TileEntity data CompoundTag rawTag = block.getNbtData(); if (rawTag != null) { - Map values = new HashMap(); + Map values = new HashMap<>(); for (Entry entry : rawTag.getValue().entrySet()) { values.put(entry.getKey(), entry.getValue()); } @@ -163,12 +163,12 @@ public class SchematicWriter implements ClipboardWriter { // Entities // ==================================================================== - List entities = new ArrayList(); + List entities = new ArrayList<>(); for (Entity entity : clipboard.getEntities()) { BaseEntity state = entity.getState(); if (state != null) { - Map values = new HashMap(); + Map values = new HashMap<>(); // Put NBT provided data CompoundTag rawTag = state.getNbtData(); @@ -197,7 +197,7 @@ public class SchematicWriter implements ClipboardWriter { } private Tag writeVector(Vector vector, String name) { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(new DoubleTag(vector.getX())); list.add(new DoubleTag(vector.getY())); list.add(new DoubleTag(vector.getZ())); @@ -205,7 +205,7 @@ public class SchematicWriter implements ClipboardWriter { } private Tag writeRotation(Location location, String name) { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(new FloatTag(location.getYaw())); list.add(new FloatTag(location.getPitch())); return new ListTag(FloatTag.class, list); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/SignCompatibilityHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/SignCompatibilityHandler.java index 410059aba..11c08c183 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/SignCompatibilityHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/SignCompatibilityHandler.java @@ -27,7 +27,6 @@ import com.google.gson.JsonSyntaxException; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.type.BlockTypes; import java.util.Map; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java index 71355570b..6063ade33 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java @@ -34,7 +34,7 @@ import java.util.Map; */ public class BlockBagExtent extends AbstractDelegateExtent { - private Map missingBlocks = new HashMap(); + private Map missingBlocks = new HashMap<>(); private BlockBag blockBag; /** @@ -74,7 +74,7 @@ public class BlockBagExtent extends AbstractDelegateExtent { */ public Map popMissing() { Map missingBlocks = this.missingBlocks; - this.missingBlocks = new HashMap(); + this.missingBlocks = new HashMap<>(); return missingBlocks; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java index 86595f3df..7b3b93391 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java @@ -43,9 +43,9 @@ import java.util.*; */ public class MultiStageReorder extends AbstractDelegateExtent implements ReorderingExtent { - private TupleArrayList stage1 = new TupleArrayList(); - private TupleArrayList stage2 = new TupleArrayList(); - private TupleArrayList stage3 = new TupleArrayList(); + private TupleArrayList stage1 = new TupleArrayList<>(); + private TupleArrayList stage2 = new TupleArrayList<>(); + private TupleArrayList stage3 = new TupleArrayList<>(); private boolean enabled; /** @@ -127,8 +127,8 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder public Operation resume(RunContext run) throws WorldEditException { Extent extent = getExtent(); - final Set blocks = new HashSet(); - final Map blockTypes = new HashMap(); + final Set blocks = new HashSet<>(); + final Map blockTypes = new HashMap<>(); for (Map.Entry entry : stage3) { final BlockVector pt = entry.getKey(); blocks.add(pt); @@ -141,7 +141,7 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder continue; } - final Deque walked = new LinkedList(); + final Deque walked = new LinkedList<>(); while (true) { walked.addFirst(current); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java index 42306a99d..a64b140b8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java @@ -40,7 +40,7 @@ import static com.google.common.base.Preconditions.checkNotNull; public class FastModeExtent extends AbstractDelegateExtent { private final World world; - private final Set dirtyChunks = new HashSet(); + private final Set dirtyChunks = new HashSet<>(); private boolean enabled = true; /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java index aaed000d3..a5ceb03c2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java @@ -22,7 +22,6 @@ package com.sk89q.worldedit.extent.world; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.world.World; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/CombinedRegionFunction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/CombinedRegionFunction.java index 4f6957c5a..2a0a4f992 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/CombinedRegionFunction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/CombinedRegionFunction.java @@ -31,7 +31,7 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class CombinedRegionFunction implements RegionFunction { - private final List functions = new ArrayList(); + private final List functions = new ArrayList<>(); /** * Create a combined region function. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java index b5fdc60a7..d0ab03f0a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java @@ -23,7 +23,6 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.type.BlockType; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.function.RegionFunction; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java index c9b1294a1..ce973c195 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java @@ -24,7 +24,6 @@ import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.pattern.BlockPattern; @@ -98,7 +97,7 @@ public class GardenPatchGenerator implements RegionFunction { } } - editSession.setBlockIfAir(pos, new BaseBlock(BlockTypes.OAK_LEAVES)); + setBlockIfAir(editSession, pos, new BaseBlock(BlockTypes.OAK_LEAVES)); affected++; int t = random.nextInt(4); @@ -113,10 +112,10 @@ public class GardenPatchGenerator implements RegionFunction { placeVine(basePos, pos.add(1, 0, 0)); } if (random.nextBoolean()) { - editSession.setBlockIfAir(pos.add(1, h, -1), log); + setBlockIfAir(editSession, pos.add(1, h, -1), log); affected++; } - editSession.setBlockIfAir(p = pos.add(0, 0, -1), plant.apply(p)); + setBlockIfAir(editSession, p = pos.add(0, 0, -1), plant.apply(p)); affected++; break; @@ -125,10 +124,10 @@ public class GardenPatchGenerator implements RegionFunction { placeVine(basePos, pos.add(0, 0, 1)); } if (random.nextBoolean()) { - editSession.setBlockIfAir(pos.add(1, h, 0), log); + setBlockIfAir(editSession, pos.add(1, h, 0), log); affected++; } - editSession.setBlockIfAir(p = pos.add(1, 0, 1), plant.apply(p)); + setBlockIfAir(editSession, p = pos.add(1, 0, 1), plant.apply(p)); affected++; break; @@ -137,10 +136,10 @@ public class GardenPatchGenerator implements RegionFunction { placeVine(basePos, pos.add(0, 0, -1)); } if (random.nextBoolean()) { - editSession.setBlockIfAir(pos.add(-1, h, 0), log); + setBlockIfAir(editSession, pos.add(-1, h, 0), log); affected++; } - editSession.setBlockIfAir(p = pos.add(-1, 0, 1), plant.apply(p)); + setBlockIfAir(editSession, p = pos.add(-1, 0, 1), plant.apply(p)); affected++; break; @@ -149,10 +148,10 @@ public class GardenPatchGenerator implements RegionFunction { placeVine(basePos, pos.add(-1, 0, 0)); } if (random.nextBoolean()) { - editSession.setBlockIfAir(pos.add(-1, h, -1), log); + setBlockIfAir(editSession, pos.add(-1, h, -1), log); affected++; } - editSession.setBlockIfAir(p = pos.add(-1, 0, -1), plant.apply(p)); + setBlockIfAir(editSession, p = pos.add(-1, 0, -1), plant.apply(p)); affected++; break; } @@ -195,6 +194,18 @@ public class GardenPatchGenerator implements RegionFunction { return pattern; } + /** + * Set a block only if there's no block already there. + * + * @param position the position + * @param block the block to set + * @return if block was changed + * @throws MaxChangedBlocksException thrown if too many blocks are changed + */ + private static boolean setBlockIfAir(EditSession session, Vector position, BaseBlock block) throws MaxChangedBlocksException { + return session.getBlock(position).isAir() && session.setBlock(position, block); + } + /** * Get a pattern that creates melons. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BiomeMask2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BiomeMask2D.java index 75240db18..b1d8be833 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BiomeMask2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BiomeMask2D.java @@ -36,7 +36,7 @@ import static com.google.common.base.Preconditions.checkNotNull; public class BiomeMask2D extends AbstractMask2D { private final Extent extent; - private final Set biomes = new HashSet(); + private final Set biomes = new HashSet<>(); /** * Create a new biome mask. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java index 15fe2705e..4ffbea7bf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java @@ -40,7 +40,7 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class BlockMask extends AbstractExtentMask { - private final Set blocks = new HashSet(); + private final Set blocks = new HashSet<>(); /** * Create a new block mask. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java index fd98c1a64..20c417ca1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java @@ -21,7 +21,6 @@ package com.sk89q.worldedit.function.mask; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.blocks.BlockID; import javax.annotation.Nullable; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java index d98fdadac..2d1fadaaa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java @@ -38,7 +38,7 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class MaskIntersection extends AbstractMask { - private final Set masks = new HashSet(); + private final Set masks = new HashSet<>(); /** * Create a new intersection. @@ -105,7 +105,7 @@ public class MaskIntersection extends AbstractMask { @Nullable @Override public Mask2D toMask2D() { - List mask2dList = new ArrayList(); + List mask2dList = new ArrayList<>(); for (Mask mask : masks) { Mask2D mask2d = mask.toMask2D(); if (mask2d != null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection2D.java index 02e605ff9..75905f49f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection2D.java @@ -33,7 +33,7 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class MaskIntersection2D implements Mask2D { - private final Set masks = new HashSet(); + private final Set masks = new HashSet<>(); /** * Create a new intersection. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java index 955ab779e..941cf0c14 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java @@ -67,7 +67,7 @@ public class MaskUnion extends MaskIntersection { @Nullable @Override public Mask2D toMask2D() { - List mask2dList = new ArrayList(); + List mask2dList = new ArrayList<>(); for (Mask mask : getMasks()) { Mask2D mask2d = mask.toMask2D(); if (mask2d != null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java index 7c0a8f53f..82b5a5176 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java @@ -20,7 +20,6 @@ package com.sk89q.worldedit.function.mask; import com.sk89q.worldedit.*; -import com.sk89q.worldedit.session.request.Request; import javax.annotation.Nullable; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/OperationQueue.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/OperationQueue.java index 49aa9d637..f4b2a95d7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/OperationQueue.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/OperationQueue.java @@ -35,7 +35,7 @@ import static com.google.common.base.Preconditions.checkNotNull; public class OperationQueue implements Operation { private final List operations = Lists.newArrayList(); - private final Deque queue = new ArrayDeque(); + private final Deque queue = new ArrayDeque<>(); private Operation current; /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java index 992eda5c5..31f58fc31 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java @@ -34,7 +34,7 @@ import static com.google.common.base.Preconditions.checkNotNull; public class RandomPattern extends AbstractPattern { private final Random random = new Random(); - private List patterns = new ArrayList(); + private List patterns = new ArrayList<>(); private double max = 0; /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java index b935e0cf6..84d8ab366 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java @@ -44,9 +44,9 @@ import static com.google.common.base.Preconditions.checkNotNull; public abstract class BreadthFirstSearch implements Operation { private final RegionFunction function; - private final Queue queue = new ArrayDeque(); - private final Set visited = new HashSet(); - private final List directions = new ArrayList(); + private final Queue queue = new ArrayDeque<>(); + private final Set visited = new HashSet<>(); + private final List directions = new ArrayList<>(); private int affected = 0; /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java index 7e980cdd1..fb871a214 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java @@ -33,7 +33,7 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class ArrayListHistory implements ChangeSet { - private final List changes = new ArrayList(); + private final List changes = new ArrayList<>(); @Override public void add(Change change) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java index d8286ffb5..f6e921263 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java @@ -43,8 +43,8 @@ import static java.util.Map.Entry; */ public class BlockOptimizedHistory extends ArrayListHistory { - private final TupleArrayList previous = new TupleArrayList(); - private final TupleArrayList current = new TupleArrayList(); + private final TupleArrayList previous = new TupleArrayList<>(); + private final TupleArrayList current = new TupleArrayList<>(); @Override public void add(Change change) { @@ -86,12 +86,7 @@ public class BlockOptimizedHistory extends ArrayListHistory { * @return a function */ private Function, Change> createTransform() { - return new Function, Change>() { - @Override - public Change apply(Entry entry) { - return new BlockChange(entry.getKey(), entry.getValue(), entry.getValue()); - } - }; + return entry -> new BlockChange(entry.getKey(), entry.getValue(), entry.getValue()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/ServerInterfaceAdapter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/ServerInterfaceAdapter.java index af49c16f4..32d0922cc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/ServerInterfaceAdapter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/ServerInterfaceAdapter.java @@ -37,7 +37,6 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * Adapts {@link Platform}s into the legacy {@link ServerInterface}. */ -@SuppressWarnings("ALL") public class ServerInterfaceAdapter extends ServerInterface { private final Platform platform; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java index 9f650bee8..71c9751e7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java @@ -99,7 +99,7 @@ public class CommandLoggingHandler extends AbstractInvokeListener implements Inv } if (logMode != null && sender.isPlayer()) { - Vector position = player.getPosition().toVector(); + Vector position = player.getLocation().toVector(); LocalSession session = worldEdit.getSessionManager().get(player); switch (logMode) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/UserCommandCompleter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/UserCommandCompleter.java index 63957cbca..5e0bbdbb7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/UserCommandCompleter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/UserCommandCompleter.java @@ -56,7 +56,7 @@ public class UserCommandCompleter implements CommandCompleter { public List getSuggestions(String arguments, CommandLocals locals) throws CommandException { Platform platform = platformManager.queryCapability(Capability.USER_COMMANDS); if (platform instanceof MultiUserPlatform) { - List suggestions = new ArrayList(); + List suggestions = new ArrayList<>(); Collection users = ((MultiUserPlatform) platform).getConnectedUsers(); for (Actor user : users) { if (user.getName().toLowerCase().startsWith(arguments.toLowerCase().trim())) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java index 5a61709f3..12190d532 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java @@ -68,9 +68,9 @@ import java.util.Stack; */ public class Expression { - private static final ThreadLocal> instance = new ThreadLocal>(); + private static final ThreadLocal> instance = new ThreadLocal<>(); - private final Map variables = new HashMap(); + private final Map variables = new HashMap<>(); private final String[] variableNames; private RValue root; private final Functions functions = new Functions(); @@ -148,7 +148,7 @@ public class Expression { private void pushInstance() { Stack foo = instance.get(); if (foo == null) { - instance.set(foo = new Stack()); + instance.set(foo = new Stack<>()); } foo.push(this); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/lexer/Lexer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/lexer/Lexer.java index 8a3aa4d05..8e5b3bbec 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/lexer/Lexer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/lexer/Lexer.java @@ -102,7 +102,7 @@ public class Lexer { ) ); - private static final Set characterTokens = new HashSet(); + private static final Set characterTokens = new HashSet<>(); static { characterTokens.add(','); characterTokens.add('('); @@ -114,13 +114,14 @@ public class Lexer { characterTokens.add(':'); } - private static final Set keywords = new HashSet(Arrays.asList("if", "else", "while", "do", "for", "break", "continue", "return", "switch", "case", "default")); + private static final Set keywords = + new HashSet<>(Arrays.asList("if", "else", "while", "do", "for", "break", "continue", "return", "switch", "case", "default")); private static final Pattern numberPattern = Pattern.compile("^([0-9]*(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?)"); private static final Pattern identifierPattern = Pattern.compile("^([A-Za-z][0-9A-Za-z_]*)"); private List tokenize() throws LexerException { - List tokens = new ArrayList(); + List tokens = new ArrayList<>(); do { skipWhitespace(); @@ -189,7 +190,7 @@ public class Lexer { public class DecisionTree { private final String tokenName; - private final Map subTrees = new HashMap(); + private final Map subTrees = new HashMap<>(); private DecisionTree(String tokenName, Object... args) { this.tokenName = tokenName; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/parser/Parser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/parser/Parser.java index 3d6b7c30f..24f3dafa9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/parser/Parser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/parser/Parser.java @@ -92,7 +92,7 @@ public class Parser { } private RValue parseStatements(boolean singleStatement) throws ParserException { - List statements = new ArrayList(); + List statements = new ArrayList<>(); loop: while (position < tokens.size()) { boolean expectSemicolon = false; @@ -227,8 +227,8 @@ public class Parser { case 's': // switch ++position; final RValue parameter = parseBracket(); - final List values = new ArrayList(); - final List caseStatements = new ArrayList(); + final List values = new ArrayList<>(); + final List caseStatements = new ArrayList<>(); RValue defaultCase = null; consumeCharacter('{'); @@ -310,7 +310,7 @@ public class Parser { } private RValue parseExpression(boolean canBeEmpty) throws ParserException { - LinkedList halfProcessed = new LinkedList(); + LinkedList halfProcessed = new LinkedList<>(); // process brackets, numbers, functions, variables and detect prefix operators boolean expressionStart = true; @@ -397,7 +397,7 @@ public class Parser { return Functions.getFunction(identifierToken.getPosition(), identifierToken.value); } - List args = new ArrayList(); + List args = new ArrayList<>(); loop: while (true) { args.add(parseExpression(false)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/parser/ParserProcessors.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/parser/ParserProcessors.java index fc29e37d5..d1810bc9f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/parser/ParserProcessors.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/parser/ParserProcessors.java @@ -33,7 +33,7 @@ import java.util.*; */ public final class ParserProcessors { - private static final Map unaryOpMap = new HashMap(); + private static final Map unaryOpMap = new HashMap<>(); private static final Map[] binaryOpMapsLA; private static final Map[] binaryOpMapsRA; @@ -111,7 +111,7 @@ public final class ParserProcessors { break; default: - Map m = lBinaryOpMapsLA[i] = new HashMap(); + Map m = lBinaryOpMapsLA[i] = new HashMap<>(); for (final Object[] element : a) { m.put((String) element[0], (String) element[1]); } @@ -133,7 +133,7 @@ public final class ParserProcessors { break; default: - Map m = lBinaryOpMapsRA[i] = new HashMap(); + Map m = lBinaryOpMapsRA[i] = new HashMap<>(); for (final Object[] element : a) { m.put((String) element[0], (String) element[1]); } @@ -153,8 +153,8 @@ public final class ParserProcessors { return processUnaryOps(input); } - LinkedList lhs = new LinkedList(); - LinkedList rhs = new LinkedList(); + LinkedList lhs = new LinkedList<>(); + LinkedList rhs = new LinkedList<>(); String operator = null; for (Iterator it = input.descendingIterator(); it.hasNext();) { @@ -195,8 +195,8 @@ public final class ParserProcessors { return processTernaryOps(input); } - LinkedList lhs = new LinkedList(); - LinkedList rhs = new LinkedList(); + LinkedList lhs = new LinkedList<>(); + LinkedList rhs = new LinkedList<>(); String operator = null; for (Identifiable identifiable : input) { @@ -232,9 +232,9 @@ public final class ParserProcessors { } private static RValue processTernaryOps(LinkedList input) throws ParserException { - LinkedList lhs = new LinkedList(); - LinkedList mhs = new LinkedList(); - LinkedList rhs = new LinkedList(); + LinkedList lhs = new LinkedList<>(); + LinkedList mhs = new LinkedList<>(); + LinkedList rhs = new LinkedList<>(); int partsFound = 0; int conditionalsFound = 0; @@ -290,7 +290,7 @@ public final class ParserProcessors { private static RValue processUnaryOps(LinkedList input) throws ParserException { // Preprocess postfix operators into unary operators final Identifiable center; - LinkedList postfixes = new LinkedList(); + LinkedList postfixes = new LinkedList<>(); do { if (input.isEmpty()) { throw new ParserException(-1, "Expression missing."); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java index a9cf3b684..4b4cbad13 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java @@ -123,7 +123,7 @@ public final class Functions { throw new NoSuchMethodException(); // TODO: return null (check for side-effects first) } - private static final Map> functions = new HashMap>(); + private static final Map> functions = new HashMap<>(); static { for (Method method : Functions.class.getMethods()) { try { @@ -138,10 +138,7 @@ public final class Functions { Overload overload = new Overload(method); - List overloads = functions.get(methodName); - if (overloads == null) { - functions.put(methodName, overloads = new ArrayList()); - } + List overloads = functions.computeIfAbsent(methodName, k -> new ArrayList<>()); overloads.add(overload); } @@ -279,8 +276,8 @@ public final class Functions { } - private static final Map gmegabuf = new HashMap(); - private final Map megabuf = new HashMap(); + private static final Map gmegabuf = new HashMap<>(); + private final Map megabuf = new HashMap<>(); public Map getMegabuf() { return megabuf; @@ -383,12 +380,7 @@ public final class Functions { return random.nextInt((int) Math.floor(max.getValue())); } - private static final ThreadLocal localPerlin = new ThreadLocal() { - @Override - protected PerlinNoise initialValue() { - return new PerlinNoise(); - } - }; + private static final ThreadLocal localPerlin = ThreadLocal.withInitial(PerlinNoise::new); public static double perlin(RValue seed, RValue x, RValue y, RValue z, RValue frequency, RValue octaves, RValue persistence) throws EvaluationException { PerlinNoise perlin = localPerlin.get(); @@ -403,12 +395,7 @@ public final class Functions { return perlin.noise(new Vector(x.getValue(), y.getValue(), z.getValue())); } - private static final ThreadLocal localVoronoi = new ThreadLocal() { - @Override - protected VoronoiNoise initialValue() { - return new VoronoiNoise(); - } - }; + private static final ThreadLocal localVoronoi = ThreadLocal.withInitial(VoronoiNoise::new); public static double voronoi(RValue seed, RValue x, RValue y, RValue z, RValue frequency) throws EvaluationException { VoronoiNoise voronoi = localVoronoi.get(); @@ -421,12 +408,7 @@ public final class Functions { return voronoi.noise(new Vector(x.getValue(), y.getValue(), z.getValue())); } - private static final ThreadLocal localRidgedMulti = new ThreadLocal() { - @Override - protected RidgedMultiFractalNoise initialValue() { - return new RidgedMultiFractalNoise(); - } - }; + private static final ThreadLocal localRidgedMulti = ThreadLocal.withInitial(RidgedMultiFractalNoise::new); public static double ridgedmulti(RValue seed, RValue x, RValue y, RValue z, RValue frequency, RValue octaves) throws EvaluationException { RidgedMultiFractalNoise ridgedMulti = localRidgedMulti.get(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Sequence.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Sequence.java index 0cdd92c51..f6458acce 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Sequence.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Sequence.java @@ -71,7 +71,7 @@ public class Sequence extends Node { @Override public RValue optimize() throws EvaluationException { - final List newSequence = new ArrayList(); + final List newSequence = new ArrayList<>(); RValue droppedLast = null; for (RValue invokable : sequence) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Switch.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Switch.java index 164293ff4..9f2f35764 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Switch.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Switch.java @@ -45,7 +45,7 @@ public class Switch extends Node implements RValue { } private static Map invertList(List values) { - Map valueMap = new HashMap(); + Map valueMap = new HashMap<>(); for (int i = 0; i < values.size(); ++i) { valueMap.put(values.get(i), i); } @@ -124,7 +124,7 @@ public class Switch extends Node implements RValue { @Override public RValue optimize() throws EvaluationException { final RValue optimizedParameter = parameter.optimize(); - final List newSequence = new ArrayList(); + final List newSequence = new ArrayList<>(); if (optimizedParameter instanceof Constant) { final double parameter = optimizedParameter.getValue(); @@ -165,9 +165,9 @@ public class Switch extends Node implements RValue { return new Switch(getPosition(), optimizedParameter, Collections.singletonMap(parameter, 0), newSequence, null); } - final Map newValueMap = new HashMap(); + final Map newValueMap = new HashMap<>(); - Map backMap = new HashMap(); + Map backMap = new HashMap<>(); for (Entry entry : valueMap.entrySet()) { backMap.put(entry.getValue(), entry.getKey()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/registry/AbstractFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/registry/AbstractFactory.java index 95563fcc0..4f4f36ea6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/registry/AbstractFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/registry/AbstractFactory.java @@ -38,7 +38,7 @@ import static com.google.common.base.Preconditions.checkNotNull; public abstract class AbstractFactory { protected final WorldEdit worldEdit; - protected final List> parsers = new ArrayList>(); + protected final List> parsers = new ArrayList<>(); /** * Create a new factory. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/DocumentationPrinter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/DocumentationPrinter.java index d4e38e34d..c82570597 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/DocumentationPrinter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/DocumentationPrinter.java @@ -59,7 +59,7 @@ public final class DocumentationPrinter { } private static List> getCommandClasses(File dir) { - List> classes = new ArrayList>(); + List> classes = new ArrayList<>(); classes.add(BiomeCommands.class); classes.add(ChunkCommands.class); @@ -100,15 +100,9 @@ public final class DocumentationPrinter { private static void writePermissionsWikiTable(List> commandClasses) throws IOException { - FileOutputStream stream = null; - try { - stream = new FileOutputStream("wiki_permissions.txt"); + try (FileOutputStream stream = new FileOutputStream("wiki_permissions.txt")) { PrintStream print = new PrintStream(stream); writePermissionsWikiTable(print, commandClasses, "/"); - } finally { - if (stream != null) { - stream.close(); - } } } @@ -180,15 +174,9 @@ public final class DocumentationPrinter { private static void writeBukkitYAML() throws IOException { - FileOutputStream stream = null; - try { - stream = new FileOutputStream("plugin.yml"); + try (FileOutputStream stream = new FileOutputStream("plugin.yml")) { PrintStream print = new PrintStream(stream); writeBukkitYAML(print); - } finally { - if (stream != null) { - stream.close(); - } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/geom/Polygons.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/geom/Polygons.java index c6f011243..007977d58 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/geom/Polygons.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/geom/Polygons.java @@ -50,7 +50,7 @@ public final class Polygons { nPoints = maxPoints - 1; } - final List points = new ArrayList(nPoints); + final List points = new ArrayList<>(nPoints); for (int i = 0; i < nPoints; ++i) { double angle = i * (2.0 * Math.PI) / nPoints; final Vector2D pos = new Vector2D(Math.cos(angle), Math.sin(angle)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java index 8a0df7b9f..7b67c6a86 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java @@ -42,7 +42,7 @@ public class ReparametrisingInterpolation implements Interpolation { private final Interpolation baseInterpolation; private double totalArcLength; - private final TreeMap cache = new TreeMap(); + private final TreeMap cache = new TreeMap<>(); public ReparametrisingInterpolation(Interpolation baseInterpolation) { checkNotNull(baseInterpolation); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java index eab410b99..46cd72177 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java @@ -75,7 +75,7 @@ public class CombinedTransform implements Transform { @Override public Transform inverse() { - List list = new ArrayList(); + List list = new ArrayList<>(); for (int i = transforms.length - 1; i >= 0; i--) { list.add(transforms[i].inverse()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java index 7777517c2..711d729d8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java @@ -287,7 +287,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { @Override public Set getChunks() { - Set chunks = new HashSet(); + Set chunks = new HashSet<>(); Vector min = getMinimumPoint(); Vector max = getMaximumPoint(); @@ -303,7 +303,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { @Override public Set getChunkCubes() { - Set chunks = new HashSet(); + Set chunks = new HashSet<>(); Vector min = getMinimumPoint(); Vector max = getMaximumPoint(); @@ -372,38 +372,33 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { @Override public Iterable asFlatRegion() { - return new Iterable() { + return () -> new Iterator() { + private Vector min = getMinimumPoint(); + private Vector max = getMaximumPoint(); + private int nextX = min.getBlockX(); + private int nextZ = min.getBlockZ(); + @Override - public Iterator iterator() { - return new Iterator() { - private Vector min = getMinimumPoint(); - private Vector max = getMaximumPoint(); - private int nextX = min.getBlockX(); - private int nextZ = min.getBlockZ(); + public boolean hasNext() { + return (nextX != Integer.MIN_VALUE); + } - @Override - public boolean hasNext() { - return (nextX != Integer.MIN_VALUE); + @Override + public Vector2D next() { + if (!hasNext()) throw new java.util.NoSuchElementException(); + Vector2D answer = new Vector2D(nextX, nextZ); + if (++nextX > max.getBlockX()) { + nextX = min.getBlockX(); + if (++nextZ > max.getBlockZ()) { + nextX = Integer.MIN_VALUE; } + } + return answer; + } - @Override - public Vector2D next() { - if (!hasNext()) throw new java.util.NoSuchElementException(); - Vector2D answer = new Vector2D(nextX, nextZ); - if (++nextX > max.getBlockX()) { - nextX = min.getBlockX(); - if (++nextZ > max.getBlockZ()) { - nextX = Integer.MIN_VALUE; - } - } - return answer; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; + @Override + public void remove() { + throw new UnsupportedOperationException(); } }; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java index 37bd1a21d..fd09c57b4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java @@ -331,12 +331,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { @Override public Iterable asFlatRegion() { - return new Iterable() { - @Override - public Iterator iterator() { - return new FlatRegionIterator(CylinderRegion.this); - } - }; + return () -> new FlatRegionIterator(CylinderRegion.this); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java index dc429beb5..069cdaff3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java @@ -178,7 +178,7 @@ public class EllipsoidRegion extends AbstractRegion { @Override public Set getChunks() { - final Set chunks = new HashSet(); + final Set chunks = new HashSet<>(); final Vector min = getMinimumPoint(); final Vector max = getMaximumPoint(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java index 9d7146ed9..62361548e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java @@ -71,7 +71,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { */ public Polygonal2DRegion(World world, List points, int minY, int maxY) { super(world); - this.points = new ArrayList(points); + this.points = new ArrayList<>(points); this.minY = minY; this.maxY = maxY; hasY = true; @@ -409,12 +409,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { @Override public Iterable asFlatRegion() { - return new Iterable() { - @Override - public Iterator iterator() { - return new FlatRegionIterator(Polygonal2DRegion.this); - } - }; + return () -> new FlatRegionIterator(Polygonal2DRegion.this); } /** @@ -440,7 +435,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { @Override public Polygonal2DRegion clone() { Polygonal2DRegion clone = (Polygonal2DRegion) super.clone(); - clone.points = new ArrayList(points); + clone.points = new ArrayList<>(points); return clone; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java index dcdcee2cf..ad93903ee 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java @@ -43,7 +43,7 @@ import java.util.List; */ public class RegionIntersection extends AbstractRegion { - private final List regions = new ArrayList(); + private final List regions = new ArrayList<>(); /** * Create a new instance with the included list of regions. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java index 3ffb59a03..cff94d8cd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java @@ -154,7 +154,7 @@ public class TransformRegion extends AbstractRegion { @Override public List polygonize(int maxPoints) { List origPoints = region.polygonize(maxPoints); - List transformedPoints = new ArrayList(); + List transformedPoints = new ArrayList<>(); for (BlockVector2D vector : origPoints) { transformedPoints.add(transform.apply(vector.toVector(0)).toVector2D().toBlockVector2D()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java index f7cac803e..afbcb1ae1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java @@ -19,7 +19,8 @@ package com.sk89q.worldedit.regions.selector; -import com.google.common.base.Optional; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.IncompleteRegionException; @@ -36,14 +37,14 @@ import com.sk89q.worldedit.regions.polyhedron.Triangle; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; import com.sk89q.worldedit.world.World; -import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; -import static com.google.common.base.Preconditions.checkNotNull; +import javax.annotation.Nullable; /** * Creates a {@code ConvexPolyhedralRegion} from a user's selections. @@ -96,7 +97,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion region = new ConvexPolyhedralRegion(oldRegion.getWorld()); - for (final BlockVector2D pt : new ArrayList(oldRegion.polygonize(Integer.MAX_VALUE))) { + for (final BlockVector2D pt : new ArrayList<>(oldRegion.polygonize(Integer.MAX_VALUE))) { region.addVertex(pt.toVector(minY)); region.addVertex(pt.toVector(maxY)); } @@ -183,7 +184,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion @Override public List getInformationLines() { - List ret = new ArrayList(); + List ret = new ArrayList<>(); ret.add("Vertices: "+region.getVertices().size()); ret.add("Triangles: "+region.getTriangles().size()); @@ -239,7 +240,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion Collection vertices = region.getVertices(); Collection triangles = region.getTriangles(); - Map vertexIds = new HashMap(vertices.size()); + Map vertexIds = new HashMap<>(vertices.size()); int lastVertexId = -1; for (Vector vertex : vertices) { vertexIds.put(vertex, ++lastVertexId); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java index 4b2f89705..fdafcd41b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java @@ -234,7 +234,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { @Override public List getInformationLines() { - final List lines = new ArrayList(); + final List lines = new ArrayList<>(); if (position1 != null) { lines.add("Position 1: " + position1); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java index 2ff239b93..592d05f15 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java @@ -225,7 +225,7 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion { @Override public List getInformationLines() { - final List lines = new ArrayList(); + final List lines = new ArrayList<>(); if (!region.getCenter().equals(Vector.ZERO)) { lines.add("Center: " + region.getCenter()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java index ce330cb6b..e01e667da 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java @@ -201,7 +201,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion { @Override public List getInformationLines() { - final List lines = new ArrayList(); + final List lines = new ArrayList<>(); final Vector center = region.getCenter(); if (center.lengthSq() > 0) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java index 4089be208..2cf8682b8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java @@ -19,8 +19,13 @@ package com.sk89q.worldedit.regions.selector; -import com.google.common.base.Optional; -import com.sk89q.worldedit.*; +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.BlockVector; +import com.sk89q.worldedit.BlockVector2D; +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.internal.cui.CUIRegion; import com.sk89q.worldedit.internal.cui.SelectionMinMaxEvent; @@ -32,11 +37,11 @@ import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; import com.sk89q.worldedit.world.World; -import javax.annotation.Nullable; import java.util.Collections; import java.util.List; +import java.util.Optional; -import static com.google.common.base.Preconditions.checkNotNull; +import javax.annotation.Nullable; /** * Creates a {@code Polygonal2DRegion} from a user's selections. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/RegionSelectorType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/RegionSelectorType.java index c522ed532..9ce56af45 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/RegionSelectorType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/RegionSelectorType.java @@ -57,9 +57,7 @@ public enum RegionSelectorType { public RegionSelector createSelector() { try { return getSelectorClass().newInstance(); - } catch (InstantiationException e) { - throw new RuntimeException("Could not create selector", e); - } catch (IllegalAccessException e) { + } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException("Could not create selector", e); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/limit/PermissiveSelectorLimits.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/limit/PermissiveSelectorLimits.java index 17d965840..ff68702d5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/limit/PermissiveSelectorLimits.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/limit/PermissiveSelectorLimits.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.regions.selector.limit; -import com.google.common.base.Optional; +import java.util.Optional; /** * No limits at all. @@ -33,12 +33,12 @@ public class PermissiveSelectorLimits implements SelectorLimits { @Override public Optional getPolygonVertexLimit() { - return Optional.absent(); + return Optional.empty(); } @Override public Optional getPolyhedronVertexLimit() { - return Optional.absent(); + return Optional.empty(); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/limit/SelectorLimits.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/limit/SelectorLimits.java index 143efb49d..1f66c055b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/limit/SelectorLimits.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/limit/SelectorLimits.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.regions.selector.limit; -import com.google.common.base.Optional; +import java.util.Optional; /** * Defines limits for selections. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java index 744d53609..8dffdba77 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java @@ -48,32 +48,32 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment { @Override public int getBlockType(double x, double y, double z) { - return editSession.getBlockType(toWorld(x, y, z)); + return editSession.getLazyBlock(toWorld(x, y, z)).getId(); } @Override public int getBlockData(double x, double y, double z) { - return editSession.getBlockData(toWorld(x, y, z)); + return editSession.getLazyBlock(new Vector(x, y, z)).getData(); } @Override public int getBlockTypeAbs(double x, double y, double z) { - return editSession.getBlockType(new Vector(x, y, z)); + return editSession.getLazyBlock(new Vector(x, y, z)).getId(); } @Override public int getBlockDataAbs(double x, double y, double z) { - return editSession.getBlockData(new Vector(x, y, z)); + return editSession.getLazyBlock(new Vector(x, y, z)).getData(); } @Override public int getBlockTypeRel(double x, double y, double z) { - return editSession.getBlockType(toWorldRel(x, y, z)); + return editSession.getLazyBlock(toWorldRel(x, y, z)).getId(); } @Override public int getBlockDataRel(double x, double y, double z) { - return editSession.getBlockData(toWorldRel(x, y, z)); + return editSession.getLazyBlock(new Vector(x, y, z)).getData(); } public void setCurrentBlock(Vector current) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/schematic/MCEditSchematicFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/schematic/MCEditSchematicFormat.java index 613f13a6c..20170d615 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/schematic/MCEditSchematicFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/schematic/MCEditSchematicFormat.java @@ -151,18 +151,22 @@ public class MCEditSchematicFormat extends SchematicFormat { Map values = new HashMap<>(); for (Map.Entry entry : t.getValue().entrySet()) { - if (entry.getKey().equals("x")) { - if (entry.getValue() instanceof IntTag) { - x = ((IntTag) entry.getValue()).getValue(); - } - } else if (entry.getKey().equals("y")) { - if (entry.getValue() instanceof IntTag) { - y = ((IntTag) entry.getValue()).getValue(); - } - } else if (entry.getKey().equals("z")) { - if (entry.getValue() instanceof IntTag) { - z = ((IntTag) entry.getValue()).getValue(); - } + switch (entry.getKey()) { + case "x": + if (entry.getValue() instanceof IntTag) { + x = ((IntTag) entry.getValue()).getValue(); + } + break; + case "y": + if (entry.getValue() instanceof IntTag) { + y = ((IntTag) entry.getValue()).getValue(); + } + break; + case "z": + if (entry.getValue() instanceof IntTag) { + z = ((IntTag) entry.getValue()).getValue(); + } + break; } values.put(entry.getKey(), entry.getValue()); @@ -276,7 +280,7 @@ public class MCEditSchematicFormat extends SchematicFormat { schematic.put("Blocks", new ByteArrayTag(blocks)); schematic.put("Data", new ByteArrayTag(blockData)); - schematic.put("Entities", new ListTag(CompoundTag.class, new ArrayList())); + schematic.put("Entities", new ListTag(CompoundTag.class, new ArrayList<>())); schematic.put("TileEntities", new ListTag(CompoundTag.class, tileEntities)); if (addBlocks != null) { schematic.put("AddBlocks", new ByteArrayTag(addBlocks)); @@ -291,9 +295,7 @@ public class MCEditSchematicFormat extends SchematicFormat { @Override public boolean isOfFormat(File file) { - DataInputStream str = null; - try { - str = new DataInputStream(new GZIPInputStream(new FileInputStream(file))); + try (DataInputStream str = new DataInputStream(new GZIPInputStream(new FileInputStream(file)))) { if ((str.readByte() & 0xFF) != NBTConstants.TYPE_COMPOUND) { return false; } @@ -303,15 +305,8 @@ public class MCEditSchematicFormat extends SchematicFormat { return name.equals("Schematic"); } catch (IOException e) { return false; - } finally { - if (str != null) { - try { - str.close(); - } catch (IOException ignore) { - // blargh - } - } } + // blargh } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/schematic/SchematicFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/schematic/SchematicFormat.java index 7ecbe0181..1f87a0da9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/schematic/SchematicFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/schematic/SchematicFormat.java @@ -21,7 +21,6 @@ package com.sk89q.worldedit.schematic; import com.sk89q.worldedit.CuboidClipboard; import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.world.DataException; import java.io.File; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngineFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngineFactory.java index 0e3c4be1d..89cca721e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngineFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/java/RhinoScriptEngineFactory.java @@ -31,7 +31,7 @@ public class RhinoScriptEngineFactory implements ScriptEngineFactory { private static List extensions; static { - names = new ArrayList(5); + names = new ArrayList<>(5); names.add("ECMAScript"); names.add("ecmascript"); names.add("JavaScript"); @@ -39,14 +39,14 @@ public class RhinoScriptEngineFactory implements ScriptEngineFactory { names.add("js"); names = Collections.unmodifiableList(names); - mimeTypes = new ArrayList(4); + mimeTypes = new ArrayList<>(4); mimeTypes.add("application/ecmascript"); mimeTypes.add("text/ecmascript"); mimeTypes.add("application/javascript"); mimeTypes.add("text/javascript"); mimeTypes = Collections.unmodifiableList(mimeTypes); - extensions = new ArrayList(2); + extensions = new ArrayList<>(2); extensions.add("emcascript"); extensions.add("js"); extensions = Collections.unmodifiableList(extensions); @@ -116,20 +116,21 @@ public class RhinoScriptEngineFactory implements ScriptEngineFactory { @Override public Object getParameter(String key) { - if (key.equals(ScriptEngine.ENGINE)) { - return getEngineName(); - } else if (key.equals(ScriptEngine.ENGINE_VERSION)) { - return getEngineVersion(); - } else if (key.equals(ScriptEngine.NAME)) { - return getEngineName(); - } else if (key.equals(ScriptEngine.LANGUAGE)) { - return getLanguageName(); - } else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) { - return getLanguageVersion(); - } else if (key.equals("THREADING")) { - return "MULTITHREADED"; - } else { - throw new IllegalArgumentException("Invalid key"); + switch (key) { + case ScriptEngine.ENGINE: + return getEngineName(); + case ScriptEngine.ENGINE_VERSION: + return getEngineVersion(); + case ScriptEngine.NAME: + return getEngineName(); + case ScriptEngine.LANGUAGE: + return getLanguageName(); + case ScriptEngine.LANGUAGE_VERSION: + return getLanguageVersion(); + case "THREADING": + return "MULTITHREADED"; + default: + throw new IllegalArgumentException("Invalid key"); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java index 60c788ca9..887f45a3f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java @@ -64,7 +64,7 @@ public class SessionManager { private static final Logger log = Logger.getLogger(SessionManager.class.getCanonicalName()); private final Timer timer = new Timer(); private final WorldEdit worldEdit; - private final Map sessions = new HashMap(); + private final Map sessions = new HashMap<>(); private SessionStore store = new VoidStore(); /** @@ -204,30 +204,27 @@ public class SessionManager { return Futures.immediateFuture(sessions); } - return executorService.submit(new Callable() { - @Override - public Object call() throws Exception { - Exception exception = null; + return executorService.submit((Callable) () -> { + Exception exception = null; - for (Map.Entry entry : sessions.entrySet()) { - SessionKey key = entry.getKey(); + for (Map.Entry entry : sessions.entrySet()) { + SessionKey key = entry.getKey(); - if (key.isPersistent()) { - try { - store.save(getKey(key), entry.getValue()); - } catch (IOException e) { - log.log(Level.WARNING, "Failed to write session for UUID " + getKey(key), e); - exception = e; - } + if (key.isPersistent()) { + try { + store.save(getKey(key), entry.getValue()); + } catch (IOException e) { + log.log(Level.WARNING, "Failed to write session for UUID " + getKey(key), e); + exception = e; } } - - if (exception != null) { - throw exception; - } - - return sessions; } + + if (exception != null) { + throw exception; + } + + return sessions; }); } @@ -305,7 +302,7 @@ public class SessionManager { synchronized (SessionManager.this) { long now = System.currentTimeMillis(); Iterator it = sessions.values().iterator(); - Map saveQueue = new HashMap(); + Map saveQueue = new HashMap<>(); while (it.hasNext()) { SessionHolder stored = it.next(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/request/Request.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/request/Request.java index 99993ffa3..fd7cd2dde 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/request/Request.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/request/Request.java @@ -30,12 +30,7 @@ import javax.annotation.Nullable; */ public final class Request { - private static final ThreadLocal threadLocal = - new ThreadLocal() { - @Override protected Request initialValue() { - return new Request(); - } - }; + private static final ThreadLocal threadLocal = ThreadLocal.withInitial(Request::new); private @Nullable World world; private @Nullable LocalSession session; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/storage/JsonFileSessionStore.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/storage/JsonFileSessionStore.java index 7247a52cd..962ae4426 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/storage/JsonFileSessionStore.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/storage/JsonFileSessionStore.java @@ -85,8 +85,7 @@ public class JsonFileSessionStore implements SessionStore { @Override public LocalSession load(UUID id) throws IOException { File file = getPath(id); - Closer closer = Closer.create(); - try { + try (Closer closer = Closer.create()) { FileReader fr = closer.register(new FileReader(file)); BufferedReader br = closer.register(new BufferedReader(fr)); return gson.fromJson(br, LocalSession.class); @@ -94,11 +93,6 @@ public class JsonFileSessionStore implements SessionStore { throw new IOException(e); } catch (FileNotFoundException e) { return new LocalSession(); - } finally { - try { - closer.close(); - } catch (IOException ignored) { - } } } @@ -106,19 +100,13 @@ public class JsonFileSessionStore implements SessionStore { public void save(UUID id, LocalSession session) throws IOException { File finalFile = getPath(id); File tempFile = new File(finalFile.getParentFile(), finalFile.getName() + ".tmp"); - Closer closer = Closer.create(); - try { + try (Closer closer = Closer.create()) { FileWriter fr = closer.register(new FileWriter(tempFile)); BufferedWriter bw = closer.register(new BufferedWriter(fr)); gson.toJson(session, bw); } catch (JsonIOException e) { throw new IOException(e); - } finally { - try { - closer.close(); - } catch (IOException ignored) { - } } if (finalFile.exists()) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Countable.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Countable.java index e1f48d135..e522c3ae6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Countable.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Countable.java @@ -67,12 +67,6 @@ public class Countable implements Comparable> { @Override public int compareTo(Countable other) { - if (amount > other.amount) { - return 1; - } else if (amount == other.amount) { - return 0; - } else { - return -1; - } + return Integer.compare(amount, other.amount); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/FileDialogUtil.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/FileDialogUtil.java index 47659b036..927692140 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/FileDialogUtil.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/FileDialogUtil.java @@ -69,7 +69,7 @@ public final class FileDialogUtil { private String desc; private ExtensionFilter(String[] exts) { - this.exts = new HashSet(Arrays.asList(exts)); + this.exts = new HashSet<>(Arrays.asList(exts)); desc = StringUtil.joinString(exts, ","); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Java7Detector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Java7Detector.java deleted file mode 100644 index d825073a2..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Java7Detector.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ -package com.sk89q.worldedit.util; - -import com.sk89q.worldedit.WorldEdit; - -public final class Java7Detector { - - public static void notifyIfNot8() { - int major = -1; - try { - String[] ver = System.getProperty("java.version").split("\\."); - major = Integer.parseInt(ver[1]); - } catch (Exception ignored) { - } - - if (major == 7) { - WorldEdit.logger.warning( - "WorldEdit has detected you are using Java 7."); - WorldEdit.logger.warning( - "WorldEdit will stop supporting Java less than version 8 in the future," - + " due to Java 7 being EOL since April 2015." - + " Please update your server to Java 8."); - } - } - - private Java7Detector() { - } - -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java index 75674ffe1..703910959 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java @@ -63,20 +63,11 @@ public class PropertiesConfiguration extends LocalConfiguration { @Override public void load() { - InputStream stream = null; - try { - stream = new FileInputStream(path); + try (InputStream stream = new FileInputStream(path)) { properties.load(stream); } catch (FileNotFoundException ignored) { } catch (IOException e) { log.log(Level.WARNING, "Failed to read configuration", e); - } finally { - if (stream != null) { - try { - stream.close(); - } catch (IOException ignored) { - } - } } loadExtra(); @@ -121,22 +112,11 @@ public class PropertiesConfiguration extends LocalConfiguration { snapshotRepo = new SnapshotRepository(snapshotsDir); } - OutputStream output = null; path.getParentFile().mkdirs(); - try { - output = new FileOutputStream(path); + try (OutputStream output = new FileOutputStream(path)) { properties.store(output, "Don't put comments; they get removed"); - } catch (FileNotFoundException e) { - log.log(Level.WARNING, "Failed to write configuration", e); } catch (IOException e) { log.log(Level.WARNING, "Failed to write configuration", e); - } finally { - if (output != null) { - try { - output.close(); - } catch (IOException ignored) { - } - } } } @@ -239,13 +219,13 @@ public class PropertiesConfiguration extends LocalConfiguration { String val = properties.getProperty(key); if (val == null) { properties.setProperty(key, StringUtil.joinString(def, ",", 0)); - Set set = new HashSet(); + Set set = new HashSet<>(); for (int i : def) { set.add(i); } return set; } else { - Set set = new HashSet(); + Set set = new HashSet<>(); String[] parts = val.split(","); for (String part : parts) { try { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java index 72541f9d8..eb95be7eb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java @@ -20,8 +20,8 @@ package com.sk89q.worldedit.util; import com.sk89q.worldedit.*; -import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.BlockType; +import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.world.World; @@ -49,7 +49,7 @@ public class TargetBlock { */ public TargetBlock(Player player) { this.world = player.getWorld(); - this.setValues(player.getPosition().toVector(), player.getYaw(), player.getPitch(), + this.setValues(player.getLocation().toVector(), player.getLocation().getYaw(), player.getLocation().getPitch(), 300, 1.65, 0.2); } @@ -62,7 +62,7 @@ public class TargetBlock { */ public TargetBlock(Player player, int maxDistance, double checkDistance) { this.world = player.getWorld(); - this.setValues(player.getPosition().toVector(), player.getYaw(), player.getPitch(), maxDistance, 1.65, checkDistance); + this.setValues(player.getLocation().toVector(), player.getLocation().getYaw(), player.getLocation().getPitch(), maxDistance, 1.65, checkDistance); } /** @@ -103,7 +103,7 @@ public class TargetBlock { boolean searchForLastBlock = true; Location lastBlock = null; while (getNextBlock() != null) { - if (world.getBlockType(getCurrentBlock().toVector()) == BlockID.AIR) { + if (world.getLazyBlock(getCurrentBlock().toVector()).getType() == BlockTypes.AIR) { if (searchForLastBlock) { lastBlock = getCurrentBlock(); if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) { @@ -125,7 +125,7 @@ public class TargetBlock { * @return Block */ public Location getTargetBlock() { - while (getNextBlock() != null && world.getBlockType(getCurrentBlock().toVector()) == 0) ; + while (getNextBlock() != null && world.getLazyBlock(getCurrentBlock().toVector()).getType() == BlockTypes.AIR) ; return getCurrentBlock(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java index 504d02b77..c88b47b66 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java @@ -24,7 +24,6 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.type.BlockTypes; import javax.annotation.Nullable; @@ -108,7 +107,7 @@ public class TreeGenerator { /** * Stores a map of the names for fast access. */ - private static final Map lookup = new HashMap(); + private static final Map lookup = new HashMap<>(); private static final Set primaryAliases = Sets.newHashSet(); private final String name; @@ -204,7 +203,7 @@ public class TreeGenerator { // Create trunk for (int i = 0; i < trunkHeight; ++i) { - if (!editSession.setBlockIfAir(basePosition.add(0, i, 0), logBlock)) { + if (!setBlockIfAir(editSession, basePosition.add(0, i, 0), logBlock)) { return; } } @@ -214,38 +213,38 @@ public class TreeGenerator { // Create tree + leaves for (int i = 0; i < height; ++i) { - editSession.setBlockIfAir(basePosition.add(0, i, 0), logBlock); + setBlockIfAir(editSession, basePosition.add(0, i, 0), logBlock); // Less leaves at these levels double chance = ((i == 0 || i == height - 1) ? 0.6 : 1); // Inner leaves - editSession.setChanceBlockIfAir(basePosition.add(-1, i, 0), leavesBlock, chance); - editSession.setChanceBlockIfAir(basePosition.add(1, i, 0), leavesBlock, chance); - editSession.setChanceBlockIfAir(basePosition.add(0, i, -1), leavesBlock, chance); - editSession.setChanceBlockIfAir(basePosition.add(0, i, 1), leavesBlock, chance); - editSession.setChanceBlockIfAir(basePosition.add(1, i, 1), leavesBlock, chance); - editSession.setChanceBlockIfAir(basePosition.add(-1, i, 1), leavesBlock, chance); - editSession.setChanceBlockIfAir(basePosition.add(1, i, -1), leavesBlock, chance); - editSession.setChanceBlockIfAir(basePosition.add(-1, i, -1), leavesBlock, chance); + setChanceBlockIfAir(editSession, basePosition.add(-1, i, 0), leavesBlock, chance); + setChanceBlockIfAir(editSession, basePosition.add(1, i, 0), leavesBlock, chance); + setChanceBlockIfAir(editSession, basePosition.add(0, i, -1), leavesBlock, chance); + setChanceBlockIfAir(editSession, basePosition.add(0, i, 1), leavesBlock, chance); + setChanceBlockIfAir(editSession, basePosition.add(1, i, 1), leavesBlock, chance); + setChanceBlockIfAir(editSession, basePosition.add(-1, i, 1), leavesBlock, chance); + setChanceBlockIfAir(editSession, basePosition.add(1, i, -1), leavesBlock, chance); + setChanceBlockIfAir(editSession, basePosition.add(-1, i, -1), leavesBlock, chance); if (!(i == 0 || i == height - 1)) { for (int j = -2; j <= 2; ++j) { - editSession.setChanceBlockIfAir(basePosition.add(-2, i, j), leavesBlock, 0.6); + setChanceBlockIfAir(editSession, basePosition.add(-2, i, j), leavesBlock, 0.6); } for (int j = -2; j <= 2; ++j) { - editSession.setChanceBlockIfAir(basePosition.add(2, i, j), leavesBlock, 0.6); + setChanceBlockIfAir(editSession, basePosition.add(2, i, j), leavesBlock, 0.6); } for (int j = -2; j <= 2; ++j) { - editSession.setChanceBlockIfAir(basePosition.add(j, i, -2), leavesBlock, 0.6); + setChanceBlockIfAir(editSession, basePosition.add(j, i, -2), leavesBlock, 0.6); } for (int j = -2; j <= 2; ++j) { - editSession.setChanceBlockIfAir(basePosition.add(j, i, 2), leavesBlock, 0.6); + setChanceBlockIfAir(editSession, basePosition.add(j, i, 2), leavesBlock, 0.6); } } } - editSession.setBlockIfAir(basePosition.add(0, height, 0), leavesBlock); + setBlockIfAir(editSession, basePosition.add(0, height, 0), leavesBlock); } /** @@ -260,4 +259,30 @@ public class TreeGenerator { return TreeType.lookup(type); } + /** + * Set a block (only if a previous block was not there) if {@link Math#random()} + * returns a number less than the given probability. + * + * @param position the position + * @param block the block + * @param probability a probability between 0 and 1, inclusive + * @return whether a block was changed + * @throws MaxChangedBlocksException thrown if too many blocks are changed + */ + private static boolean setChanceBlockIfAir(EditSession session, Vector position, BaseBlock block, double probability) + throws MaxChangedBlocksException { + return Math.random() <= probability && setBlockIfAir(session, position, block); + } + + /** + * Set a block only if there's no block already there. + * + * @param position the position + * @param block the block to set + * @return if block was changed + * @throws MaxChangedBlocksException thrown if too many blocks are changed + */ + private static boolean setBlockIfAir(EditSession session, Vector position, BaseBlock block) throws MaxChangedBlocksException { + return session.getBlock(position).isAir() && session.setBlock(position, block); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/WeightedChoice.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/WeightedChoice.java index 3e5d5d440..e384ecf73 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/WeightedChoice.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/WeightedChoice.java @@ -19,11 +19,11 @@ package com.sk89q.worldedit.util; -import com.google.common.base.Function; -import com.google.common.base.Optional; - import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Optional; +import java.util.function.Function; + /** * Returns the best choice given a weighting function and a target weight. * @@ -60,12 +60,10 @@ public class WeightedChoice { public void consider(T object) { checkNotNull(object); Number value = checkNotNull(function.apply(object)); - if (value != null) { - double distance = Math.abs(target - value.doubleValue()); - if (current == null || distance <= best) { - best = distance; - current = object; - } + double distance = Math.abs(target - value.doubleValue()); + if (current == null || distance <= best) { + best = distance; + current = object; } } @@ -76,9 +74,9 @@ public class WeightedChoice { */ public Optional> getChoice() { if (current != null) { - return Optional.of(new Choice(current, best)); + return Optional.of(new Choice<>(current, best)); } else { - return Optional.absent(); + return Optional.empty(); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java index 974313c50..909dfe4f1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java @@ -76,8 +76,8 @@ public class YAMLConfiguration extends LocalConfiguration { butcherDefaultRadius = Math.max(-1, config.getInt("limits.butcher-radius.default", butcherDefaultRadius)); butcherMaxRadius = Math.max(-1, config.getInt("limits.butcher-radius.maximum", butcherMaxRadius)); - disallowedBlocks = new HashSet(config.getIntList("limits.disallowed-blocks", null)); - allowedDataCycleBlocks = new HashSet(config.getIntList("limits.allowed-data-cycle-blocks", null)); + disallowedBlocks = new HashSet<>(config.getIntList("limits.disallowed-blocks", null)); + allowedDataCycleBlocks = new HashSet<>(config.getIntList("limits.allowed-data-cycle-blocks", null)); registerHelp = config.getBoolean("register-help", true); logCommands = config.getBoolean("logging.log-commands", logCommands); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/DoubleArrayList.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/DoubleArrayList.java index f2b0a2539..d3bf38793 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/DoubleArrayList.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/DoubleArrayList.java @@ -33,8 +33,8 @@ import java.util.NoSuchElementException; */ public class DoubleArrayList implements Iterable> { - private List listA = new ArrayList(); - private List listB = new ArrayList(); + private List listA = new ArrayList<>(); + private List listB = new ArrayList<>(); private boolean isReversed = false; /** @@ -81,11 +81,11 @@ public class DoubleArrayList implements Iterable> { */ public Iterator> iterator(boolean reversed) { if (reversed) { - 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()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/FastListIterator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/FastListIterator.java index 638de0194..75aea6b29 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/FastListIterator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/FastListIterator.java @@ -93,7 +93,7 @@ public class FastListIterator implements Iterator { * @return an iterator */ public static Iterator forwardIterator(List list) { - return new FastListIterator(list, 0, list.size(), 1); + return new FastListIterator<>(list, 0, list.size(), 1); } /** @@ -105,9 +105,9 @@ public class FastListIterator implements Iterator { */ public static Iterator reverseIterator(List list) { if (!list.isEmpty()) { - return new FastListIterator(list, list.size() - 1, list.size(), -1); + return new FastListIterator<>(list, list.size() - 1, list.size(), -1); } else { - return new FastListIterator(list, 0, 0, -1); + return new FastListIterator<>(list, 0, 0, -1); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/TupleArrayList.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/TupleArrayList.java index f4d9b1f4b..8247607f1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/TupleArrayList.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/TupleArrayList.java @@ -39,7 +39,7 @@ public class TupleArrayList extends ArrayList> { * @param b the 'value' */ public void put(A a, B b) { - add(new Tuple(a, b)); + add(new Tuple<>(a, b)); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDescription.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDescription.java index ad3047117..4bea65d91 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDescription.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDescription.java @@ -28,8 +28,8 @@ import java.util.List; */ public class SimpleDescription implements Description { - private List parameters = new ArrayList(); - private List permissions = new ArrayList(); + private List parameters = new ArrayList<>(); + private List permissions = new ArrayList<>(); private String description; private String help; private String overrideUsage; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java index 8478c76e9..1f67fe51c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java @@ -40,7 +40,7 @@ import java.util.Set; */ public class SimpleDispatcher implements Dispatcher { - private final Map commands = new HashMap(); + private final Map commands = new HashMap<>(); private final SimpleDescription description = new SimpleDescription(); /** @@ -74,7 +74,7 @@ public class SimpleDispatcher implements Dispatcher { @Override public Set getCommands() { - return Collections.unmodifiableSet(new HashSet(commands.values())); + return Collections.unmodifiableSet(new HashSet<>(commands.values())); } @Override @@ -84,7 +84,7 @@ public class SimpleDispatcher implements Dispatcher { @Override public Set getPrimaryAliases() { - Set aliases = new HashSet(); + Set aliases = new HashSet<>(); for (CommandMapping mapping : getCommands()) { aliases.add(mapping.getPrimaryAlias()); } @@ -143,7 +143,7 @@ public class SimpleDispatcher implements Dispatcher { if (split.length <= 1) { String prefix = split.length > 0 ? split[0] : ""; - List suggestions = new ArrayList(); + List suggestions = new ArrayList<>(); for (CommandMapping mapping : getCommands()) { if (mapping.getCallable().testPermission(locals)) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/FlagParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/FlagParser.java index 2868a3ba8..2309adb53 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/FlagParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/FlagParser.java @@ -39,7 +39,7 @@ public class FlagParser implements CommandExecutor { private final Map> flags = Maps.newHashMap(); public Flag registerFlag(char flag, CommandExecutor executor) { - Flag ret = new Flag(flag); + Flag ret = new Flag<>(flag); flags.put(flag, executor); return ret; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/ProvidedValue.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/ProvidedValue.java index 7620bc7c3..5528728b7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/ProvidedValue.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/ProvidedValue.java @@ -63,7 +63,7 @@ public class ProvidedValue implements CommandExecutor { } public static ProvidedValue create(T value, String description) { - return new ProvidedValue(value, description); + return new ProvidedValue<>(value, description); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingHelper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingHelper.java index a29d6ddd3..73b59f087 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingHelper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingHelper.java @@ -54,8 +54,8 @@ public class BindingHelper implements Binding { * Create a new instance. */ public BindingHelper() { - List bindings = new ArrayList(); - List types = new ArrayList(); + List bindings = new ArrayList<>(); + List types = new ArrayList<>(); for (Method method : this.getClass().getMethods()) { BindingMatch info = method.getAnnotation(BindingMatch.class); @@ -145,7 +145,7 @@ public class BindingHelper implements Binding { public Object bind(ParameterData parameter, ArgumentStack scoped, boolean onlyConsume) throws ParameterException, CommandException, InvocationTargetException { BoundMethod binding = match(parameter); - List args = new ArrayList(); + List args = new ArrayList<>(); args.add(scoped); if (binding.classifier != null) { @@ -184,7 +184,7 @@ public class BindingHelper implements Binding { @Override public List getSuggestions(ParameterData parameter, String prefix) { - return new ArrayList(); + return new ArrayList<>(); } private static class BoundMethod implements Comparable { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ExceptionConverterHelper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ExceptionConverterHelper.java index 2341e5816..5b2d9fd5d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ExceptionConverterHelper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ExceptionConverterHelper.java @@ -42,7 +42,7 @@ public abstract class ExceptionConverterHelper implements ExceptionConverter { @SuppressWarnings("unchecked") public ExceptionConverterHelper() { - List handlers = new ArrayList(); + List handlers = new ArrayList<>(); for (Method method : this.getClass().getMethods()) { if (method.getAnnotation(ExceptionMatch.class) == null) { @@ -76,9 +76,7 @@ public abstract class ExceptionConverterHelper implements ExceptionConverter { throw (CommandException) e.getCause(); } throw new WrappedCommandException(e); - } catch (IllegalArgumentException e) { - throw new WrappedCommandException(e); - } catch (IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException e) { throw new WrappedCommandException(e); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricBuilder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricBuilder.java index b02178874..6204422b4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricBuilder.java @@ -54,9 +54,9 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class ParametricBuilder { - private final Map bindings = new HashMap(); + private final Map bindings = new HashMap<>(); private final Paranamer paranamer = new CachingParanamer(); - private final List invokeListeners = new ArrayList(); + private final List invokeListeners = new ArrayList<>(); private Authorizer authorizer = new NullAuthorizer(); private CommandCompleter defaultCompleter = new NullCompleter(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java index 5492a2e81..d24ebbb8f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java @@ -39,9 +39,9 @@ class ParametricCallable implements CommandCallable { private final Object object; private final Method method; private final ParameterData[] parameters; - private final Set valueFlags = new HashSet(); + private final Set valueFlags = new HashSet<>(); private final boolean anyFlags; - private final Set legacyFlags = new HashSet(); + private final Set legacyFlags = new HashSet<>(); private final SimpleDescription description = new SimpleDescription(); private final CommandPermissions commandPermissions; @@ -63,7 +63,7 @@ class ParametricCallable implements CommandCallable { String[] names = builder.getParanamer().lookupParameterNames(method, false); Type[] types = method.getGenericParameterTypes(); parameters = new ParameterData[types.length]; - List userParameters = new ArrayList(); + List userParameters = new ArrayList<>(); // This helps keep tracks of @Nullables that appear in the middle of a list // of parameters @@ -186,7 +186,7 @@ class ParametricCallable implements CommandCallable { try { // preProcess handlers - List handlers = new ArrayList(); + List handlers = new ArrayList<>(); for (InvokeListener listener : builder.getInvokeListeners()) { InvokeHandler handler = listener.createInvokeHandler(); handlers.add(handler); @@ -422,7 +422,7 @@ class ParametricCallable implements CommandCallable { if (!found) { if (unusedFlags == null) { - unusedFlags = new HashSet(); + unusedFlags = new HashSet<>(); } unusedFlags.add(flag); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/concurrency/EvenMoreExecutors.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/concurrency/EvenMoreExecutors.java index 6a5ee3430..5272039a1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/concurrency/EvenMoreExecutors.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/concurrency/EvenMoreExecutors.java @@ -46,7 +46,7 @@ public final class EvenMoreExecutors { ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor( minThreads, maxThreads, 60L, TimeUnit.SECONDS, - new ArrayBlockingQueue(queueSize)); + new ArrayBlockingQueue<>(queueSize)); threadPoolExecutor.allowCoreThreadTimeOut(true); return threadPoolExecutor; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/eventbus/EventBus.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/eventbus/EventBus.java index 0ee7b7d65..d8cbe8b20 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/eventbus/EventBus.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/eventbus/EventBus.java @@ -19,7 +19,8 @@ package com.sk89q.worldedit.util.eventbus; -import com.google.common.base.Supplier; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import com.google.common.collect.SetMultimap; @@ -27,12 +28,17 @@ import com.google.common.eventbus.DeadEvent; import com.sk89q.worldedit.internal.annotation.RequiresNewerGuava; import java.lang.reflect.InvocationTargetException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Dispatches events to listeners, and provides ways for listeners to register * themselves. @@ -50,13 +56,7 @@ public class EventBus { private final Logger logger = Logger.getLogger(EventBus.class.getCanonicalName()); private final SetMultimap, EventHandler> handlersByType = - Multimaps.newSetMultimap(new HashMap, Collection>(), - new Supplier>() { - @Override - public Set get() { - return newHandlerSet(); - } - }); + Multimaps.newSetMultimap(new HashMap<>(), this::newHandlerSet); /** * Strategy for finding handler methods in registered objects. Currently, @@ -153,7 +153,7 @@ public class EventBus { * @param event event to post. */ public void post(Object event) { - List dispatching = new ArrayList(); + List dispatching = new ArrayList<>(); synchronized (this) { Set> dispatchTypes = flattenHierarchy(event.getClass()); @@ -211,7 +211,7 @@ public class EventBus { * @return a new, mutable set for handlers. */ protected synchronized Set newHandlerSet() { - return new HashSet(); + return new HashSet<>(); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/eventbus/HierarchyCache.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/eventbus/HierarchyCache.java index 31aeb1f53..5644e2aa3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/eventbus/HierarchyCache.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/eventbus/HierarchyCache.java @@ -34,7 +34,7 @@ import java.util.*; @RequiresNewerGuava class HierarchyCache { - private final Map, Set>> cache = new WeakHashMap, Set>>(); + private final Map, Set>> cache = new WeakHashMap<>(); public Set> get(Class concreteClass) { Set> ret = cache.get(concreteClass); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java index 08cf70e18..0134827f5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java @@ -126,11 +126,8 @@ public class ColorCodeBuilder { return builder.toString(); } else if (!resetFrom.hasEqualFormatting(resetTo) || (resetFrom.getColor() != null && resetTo.getColor() == null)) { - StringBuilder builder = new StringBuilder(); // Have to set reset code and add back all the formatting codes - builder.append(Style.RESET); - builder.append(getCode(resetTo)); - return builder.toString(); + return String.valueOf(Style.RESET) + getCode(resetTo); } else { if (resetFrom.getColor() != resetTo.getColor()) { return String.valueOf(resetTo.getColor()); @@ -163,7 +160,7 @@ public class ColorCodeBuilder { char[] rawChars = (rawString + ' ').toCharArray(); // add a trailing space to trigger pagination StringBuilder word = new StringBuilder(); StringBuilder line = new StringBuilder(); - List lines = new LinkedList(); + List lines = new LinkedList<>(); int lineColorChars = 0; for (int i = 0; i < rawChars.length; i++) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyledFragment.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyledFragment.java index eaa4293cc..9ef38446b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyledFragment.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyledFragment.java @@ -27,7 +27,7 @@ import java.util.List; */ public class StyledFragment extends Fragment { - private final List children = new ArrayList(); + private final List children = new ArrayList<>(); private StyleSet style; private Fragment lastText; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java index 4f27aa6c1..adfbc1ec5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java @@ -71,8 +71,8 @@ public class CommandUsageBox extends StyledFragment { CommandListBox box = new CommandListBox("Subcommands"); String prefix = !commandString.isEmpty() ? commandString + " " : ""; - List list = new ArrayList(dispatcher.getCommands()); - Collections.sort(list, new PrimaryAliasComparator(CommandManager.COMMAND_CLEAN_PATTERN)); + List list = new ArrayList<>(dispatcher.getCommands()); + list.sort(new PrimaryAliasComparator(CommandManager.COMMAND_CLEAN_PATTERN)); for (CommandMapping mapping : list) { if (locals == null || mapping.getCallable().testPermission(locals)) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java index 6b5c37efe..ff1793082 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java @@ -55,8 +55,8 @@ public final class Closer implements Closeable { final Suppressor suppressor; // only need space for 2 elements in most cases, so try to use the smallest array possible - private final Deque stack = new ArrayDeque(4); - private final Deque zipStack = new ArrayDeque(4); + private final Deque stack = new ArrayDeque<>(4); + private final Deque zipStack = new ArrayDeque<>(4); private Throwable thrown; @VisibleForTesting Closer(Suppressor suppressor) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/logging/LogFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/logging/LogFormat.java index 7b0b8e9e5..05a4c8378 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/logging/LogFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/logging/LogFormat.java @@ -22,7 +22,6 @@ package com.sk89q.worldedit.util.logging; import java.util.Date; import java.util.logging.Formatter; import java.util.logging.LogRecord; -import java.util.logging.Level; import java.io.PrintWriter; import java.io.StringWriter; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java index 3f2d0e9b7..a3b248570 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java @@ -109,16 +109,6 @@ public abstract class AbstractWorld implements World { new BaseBlock(BlockTypes.FLOWING_WATER)); } - @Override - public int getBlockType(Vector pt) { - return getLazyBlock(pt).getType().getLegacyId(); - } - - @Override - public int getBlockData(Vector pt) { - return getLazyBlock(pt).getData(); - } - @Override public void dropItem(Vector pt, BaseItemStack item, int times) { for (int i = 0; i < times; ++i) { @@ -189,19 +179,15 @@ public abstract class AbstractWorld implements World { return false; } - @SuppressWarnings("deprecation") @Override public boolean queueBlockBreakEffect(Platform server, Vector position, int blockId, double priority) { if (taskId == -1) { - taskId = server.schedule(0, 1, new Runnable() { - @Override - public void run() { - int max = Math.max(1, Math.min(30, effectQueue.size() / 3)); - for (int i = 0; i < max; ++i) { - if (effectQueue.isEmpty()) return; + taskId = server.schedule(0, 1, () -> { + int max = Math.max(1, Math.min(30, effectQueue.size() / 3)); + for (int i = 0; i < max; ++i) { + if (effectQueue.isEmpty()) return; - effectQueue.poll().play(); - } + effectQueue.poll().play(); } }); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java index 882356350..f92126eb0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java @@ -27,7 +27,6 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItemStack; -import com.sk89q.worldedit.blocks.type.BlockType; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; @@ -92,18 +91,6 @@ public interface World extends Extent { */ boolean useItem(Vector position, BaseItem item, Direction face); - /** - * @deprecated Use {@link #getLazyBlock(Vector)} - */ - @Deprecated - int getBlockType(Vector pt); - - /** - * @deprecated Use {@link #getLazyBlock(Vector)} - */ - @Deprecated - int getBlockData(Vector pt); - /** * Similar to {@link Extent#setBlock(Vector, BaseBlock)} but a * {@code notifyAndLight} parameter indicates whether adjacent blocks diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/Biomes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/Biomes.java index c19c2ac93..0282227db 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/Biomes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/Biomes.java @@ -19,18 +19,19 @@ package com.sk89q.worldedit.world.biome; -import com.google.common.base.Function; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.base.Functions; -import com.google.common.base.Optional; import com.sk89q.worldedit.util.WeightedChoice; import com.sk89q.worldedit.util.WeightedChoice.Choice; import com.sk89q.worldedit.util.function.LevenshteinDistance; import com.sk89q.worldedit.world.registry.BiomeRegistry; -import javax.annotation.Nullable; import java.util.Collection; +import java.util.Optional; +import java.util.function.Function; -import static com.google.common.base.Preconditions.checkNotNull; +import javax.annotation.Nullable; /** * Utility methods related to biomes. @@ -55,7 +56,7 @@ public final class Biomes { checkNotNull(registry); Function compare = new LevenshteinDistance(name, false, LevenshteinDistance.STANDARD_CHARS); - WeightedChoice chooser = new WeightedChoice(Functions.compose(compare, new BiomeName(registry)), 0); + WeightedChoice chooser = new WeightedChoice<>(Functions.compose(compare::apply, new BiomeName(registry)), 0); for (BaseBiome biome : biomes) { chooser.consider(biome); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java index f52f6d969..87ec424aa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java @@ -196,7 +196,7 @@ public class AnvilChunk implements Chunk { List tags = NBTUtils.getChildTag(rootTag.getValue(), "TileEntities", ListTag.class).getValue(); - tileEntities = new HashMap>(); + tileEntities = new HashMap<>(); for (Tag tag : tags) { if (!(tag instanceof CompoundTag)) { @@ -210,21 +210,25 @@ public class AnvilChunk implements Chunk { int y = 0; int z = 0; - Map values = new HashMap(); + Map values = new HashMap<>(); for (Map.Entry entry : t.getValue().entrySet()) { - if (entry.getKey().equals("x")) { - if (entry.getValue() instanceof IntTag) { - x = ((IntTag) entry.getValue()).getValue(); - } - } else if (entry.getKey().equals("y")) { - if (entry.getValue() instanceof IntTag) { - y = ((IntTag) entry.getValue()).getValue(); - } - } else if (entry.getKey().equals("z")) { - if (entry.getValue() instanceof IntTag) { - z = ((IntTag) entry.getValue()).getValue(); - } + switch (entry.getKey()) { + case "x": + if (entry.getValue() instanceof IntTag) { + x = ((IntTag) entry.getValue()).getValue(); + } + break; + case "y": + if (entry.getValue() instanceof IntTag) { + y = ((IntTag) entry.getValue()).getValue(); + } + break; + case "z": + if (entry.getValue() instanceof IntTag) { + z = ((IntTag) entry.getValue()).getValue(); + } + break; } values.put(entry.getKey(), entry.getValue()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java index 98849cdcb..b2e35d3bc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java @@ -123,7 +123,7 @@ public class OldChunk implements Chunk { rootTag.getValue(), "TileEntities", ListTag.class) .getValue(); - tileEntities = new HashMap>(); + tileEntities = new HashMap<>(); for (Tag tag : tags) { if (!(tag instanceof CompoundTag)) { @@ -136,21 +136,25 @@ public class OldChunk implements Chunk { int y = 0; int z = 0; - Map values = new HashMap(); + Map values = new HashMap<>(); for (Map.Entry entry : t.getValue().entrySet()) { - if (entry.getKey().equals("x")) { - if (entry.getValue() instanceof IntTag) { - x = ((IntTag) entry.getValue()).getValue(); - } - } else if (entry.getKey().equals("y")) { - if (entry.getValue() instanceof IntTag) { - y = ((IntTag) entry.getValue()).getValue(); - } - } else if (entry.getKey().equals("z")) { - if (entry.getValue() instanceof IntTag) { - z = ((IntTag) entry.getValue()).getValue(); - } + switch (entry.getKey()) { + case "x": + if (entry.getValue() instanceof IntTag) { + x = ((IntTag) entry.getValue()).getValue(); + } + break; + case "y": + if (entry.getValue() instanceof IntTag) { + y = ((IntTag) entry.getValue()).getValue(); + } + break; + case "z": + if (entry.getValue() instanceof IntTag) { + z = ((IntTag) entry.getValue()).getValue(); + } + break; } values.put(entry.getKey(), entry.getValue()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRepository.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRepository.java index 0b6ede080..2add97ec8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRepository.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRepository.java @@ -37,7 +37,7 @@ import java.util.List; public class SnapshotRepository { protected File dir; - protected List dateParsers = new ArrayList(); + protected List dateParsers = new ArrayList<>(); /** * Create a new instance of a repository. @@ -71,19 +71,16 @@ public class SnapshotRepository { * @return a list of snapshots */ public List getSnapshots(boolean newestFirst, String worldName) throws MissingWorldException { - FilenameFilter filter = new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - File f = new File(dir, name); - return isValidSnapshot(f); - } + FilenameFilter filter = (dir, name) -> { + File f = new File(dir, name); + return isValidSnapshot(f); }; File[] snapshotFiles = dir.listFiles(); if (snapshotFiles == null) { throw new MissingWorldException(worldName); } - List list = new ArrayList(snapshotFiles.length); + List list = new ArrayList<>(snapshotFiles.length); for (File file : snapshotFiles) { if (isValidSnapshot(file)) { @@ -102,7 +99,7 @@ public class SnapshotRepository { } if (newestFirst) { - Collections.sort(list, Collections.reverseOrder()); + list.sort(Collections.reverseOrder()); } else { Collections.sort(list); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRestore.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRestore.java index ca636e007..1ccfef753 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRestore.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRestore.java @@ -44,7 +44,7 @@ import java.util.Map; */ public class SnapshotRestore { - private final Map> neededChunks = new LinkedHashMap>(); + private final Map> neededChunks = new LinkedHashMap<>(); private final ChunkStore chunkStore; private final EditSession editSession; private ArrayList missingChunks; @@ -111,7 +111,7 @@ public class SnapshotRestore { // Unidentified chunk if (!neededChunks.containsKey(chunkPos)) { - neededChunks.put(chunkPos, new ArrayList()); + neededChunks.put(chunkPos, new ArrayList<>()); } neededChunks.get(chunkPos).add(pos); @@ -133,8 +133,8 @@ public class SnapshotRestore { */ public void restore() throws MaxChangedBlocksException { - missingChunks = new ArrayList(); - errorChunks = new ArrayList(); + missingChunks = new ArrayList<>(); + errorChunks = new ArrayList<>(); // Now let's start restoring! for (Map.Entry> entry : neededChunks.entrySet()) { @@ -156,15 +156,9 @@ public class SnapshotRestore { } } catch (MissingChunkException me) { missingChunks.add(chunkPos); - } catch (MissingWorldException me) { + } catch (IOException | DataException me) { errorChunks.add(chunkPos); lastErrorMessage = me.getMessage(); - } catch (DataException de) { - errorChunks.add(chunkPos); - lastErrorMessage = de.getMessage(); - } catch (IOException ioe) { - errorChunks.add(chunkPos); - lastErrorMessage = ioe.getMessage(); } } } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java index b68cbc3e4..eaa034d28 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java @@ -81,26 +81,11 @@ public class ForgePlayer extends AbstractPlayerActor { this.player.rotationPitch); } - @Override - public Location getPosition() { - return new Location(ForgeWorldEdit.inst.getWorld(this.player.world), this.player.posX, this.player.posY, this.player.posZ); - } - @Override public com.sk89q.worldedit.world.World getWorld() { return ForgeWorldEdit.inst.getWorld(this.player.world); } - @Override - public double getPitch() { - return this.player.rotationPitch; - } - - @Override - public double getYaw() { - return this.player.rotationYaw; - } - @Override public void giveItem(int type, int amt) { this.player.inventory.addItemStackToInventory(new ItemStack(Item.getItemById(type), amt, 0)); diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java index ec6541ce9..64d7fd37c 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java @@ -167,8 +167,7 @@ public class ForgeWorld extends AbstractWorld { Chunk chunk = world.getChunkFromChunkCoords(x >> 4, z >> 4); BlockPos pos = new BlockPos(x, y, z); IBlockState old = chunk.getBlockState(pos); - @SuppressWarnings("deprecation") - IBlockState newState = Block.getBlockById(block.getId()).getStateFromMeta(block.getData()); + IBlockState newState = Block.getBlockById(block.getId()).getStateFromMeta(block.getData()); IBlockState successState = chunk.setBlockState(pos, newState); boolean successful = successState != null; diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java index b8f57edda..5024d56c0 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java @@ -81,27 +81,11 @@ public class SpongePlayer extends AbstractPlayerActor { return SpongeWorldEdit.inst().getAdapter().adapt(entityLoc, entityRot); } - @Override - public Location getPosition() { - Vector3d pos = this.player.getLocation().getPosition(); - return new Location(SpongeWorldEdit.inst().getAdapter().getWorld(this.player.getWorld()), pos.getX(), pos.getY(), pos.getZ()); - } - @Override public com.sk89q.worldedit.world.World getWorld() { return SpongeWorldEdit.inst().getAdapter().getWorld(player.getWorld()); } - @Override - public double getPitch() { - return getLocation().getPitch(); - } - - @Override - public double getYaw() { - return getLocation().getYaw(); - } - @Override public void giveItem(int type, int amt) { this.player.getInventory().offer(ItemStack.of(SpongeWorldEdit.inst().getAdapter().resolveItem(type), amt));