From 85bfd16d7c16613e79f49d3acaa17007c09baa3e Mon Sep 17 00:00:00 2001 From: matt <4009945+MattBDev@users.noreply.github.com> Date: Fri, 15 Feb 2019 21:46:10 -0500 Subject: [PATCH] Code cleaning Most notable change: Remove redundant type parameters and replaced with <>. This is a small step to bring us closer to upstream parity. --- .../com/thevoxelbox/voxelsniper/Brushes.java | 2 +- .../voxelsniper/VoxelSniperListener.java | 2 +- .../voxelsniper/brush/BlockResetBrush.java | 2 +- .../voxelsniper/brush/DomeBrush.java | 2 +- .../voxelsniper/brush/EntityRemovalBrush.java | 4 +- .../voxelsniper/brush/ErodeBrush.java | 8 +- .../voxelsniper/brush/GenerateTreeBrush.java | 2 +- .../voxelsniper/brush/HeatRayBrush.java | 2 +- .../voxelsniper/brush/MoveBrush.java | 4 +- .../voxelsniper/brush/PullBrush.java | 2 +- .../voxelsniper/brush/ShellSetBrush.java | 3 +- .../voxelsniper/brush/SplineBrush.java | 6 +- .../voxelsniper/brush/StampBrush.java | 8 +- .../voxelsniper/brush/StencilListBrush.java | 2 +- .../voxelsniper/brush/perform/PerformerE.java | 4 +- .../voxelsniper/jsap/HelpJSAP.java | 2 +- gradle/wrapper/gradle-wrapper.properties | 3 +- worldedit-bukkit/build.gradle | 176 +- .../java/com/boydti/fawe/bukkit/Metrics.java | 4 +- .../boydti/fawe/bukkit/chat/JsonString.java | 2 +- .../boydti/fawe/bukkit/chat/Reflection.java | 4 +- .../bukkit/listener/BukkitImageListener.java | 4 +- .../com/boydti/fawe/bukkit/util/ItemUtil.java | 2 +- .../fawe/bukkit/v0/BukkitQueue_All.java | 2 +- .../worldedit/blocks/MobSpawnerBlock.java | 2 +- .../com/sk89q/worldedit/blocks/SignBlock.java | 2 +- .../main/java/com/boydti/fawe/FaweAPI.java | 2 +- .../main/java/com/boydti/fawe/FaweCache.java | 2 +- .../fawe/configuration/TypeDescription.java | 6 +- .../com/boydti/fawe/configuration/Yaml.java | 8 +- .../ConfigurationSerialization.java | 2 +- .../com/boydti/fawe/example/IntFaweChunk.java | 4 +- .../boydti/fawe/example/WeakFaweQueueMap.java | 2 +- .../java/com/boydti/fawe/jnbt/JSON2NBT.java | 2 +- .../com/boydti/fawe/jnbt/anvil/MCAChunk.java | 17 +- .../com/boydti/fawe/object/FaweChunk.java | 2 +- .../com/boydti/fawe/object/HistoryExtent.java | 2 +- .../boydti/fawe/object/brush/SplineBrush.java | 2 +- .../object/changeset/DiskStorageHistory.java | 2 +- .../collection/IterableThreadLocal.java | 2 +- .../collection/SimpleRandomCollection.java | 2 +- .../fawe/object/collection/SoftHashMap.java | 14 +- .../fawe/object/io/PGZIPOutputStream.java | 6 +- .../fawe/object/regions/PolyhedralRegion.java | 16 +- .../regions/selector/FuzzyRegionSelector.java | 2 +- .../selector/PolyhedralRegionSelector.java | 4 +- .../java/com/boydti/fawe/util/SetQueue.java | 2 +- .../boydti/fawe/util/ShapeInterpolator.java | 4 +- .../java/com/boydti/fawe/util/StringMan.java | 2 +- .../com/boydti/fawe/util/TextureUtil.java | 2 +- .../boydti/fawe/util/chat/UsageMessage.java | 2 +- .../boydti/fawe/util/task/TaskBuilder.java | 4 +- .../main/java/com/sk89q/jnbt/CompoundTag.java | 894 +++++----- .../com/sk89q/jnbt/CompoundTagBuilder.java | 6 +- .../java/com/sk89q/jnbt/NBTInputStream.java | 8 +- .../java/com/sk89q/worldedit/EditSession.java | 4 +- .../java/com/sk89q/worldedit/WorldEdit.java | 1433 +++++++++-------- .../worldedit/command/BiomeCommands.java | 2 +- .../sk89q/worldedit/command/HelpBuilder.java | 6 +- .../worldedit/command/ScriptingCommands.java | 2 +- .../worldedit/command/UtilityCommands.java | 4 +- .../extension/platform/PlatformManager.java | 8 +- .../extent/clipboard/io/ClipboardFormat.java | 4 +- .../function/mask/MaskIntersection.java | 2 +- .../worldedit/function/mask/MaskUnion.java | 2 +- .../internal/expression/Expression.java | 2 +- .../expression/runtime/Functions.java | 8 +- .../ConvexPolyhedralRegionSelector.java | 2 +- .../selector/CuboidRegionSelector.java | 4 +- .../selector/CylinderRegionSelector.java | 2 +- .../selector/EllipsoidRegionSelector.java | 2 +- .../util/command/SimpleDispatcher.java | 10 +- .../parametric/AParametricCallable.java | 2 +- .../FunctionParametricCallable.java | 8 +- .../command/parametric/ParametricBuilder.java | 6 +- .../parametric/ParametricCallable.java | 10 +- .../formatting/component/CommandUsageBox.java | 2 +- .../util/task/progress/ProgressIterator.java | 2 +- .../worldedit/world/block/BlockType.java | 3 +- .../worldedit/world/block/BlockTypes.java | 8 +- .../sk89q/worldedit/world/item/ItemTypes.java | 2 +- .../util/commands/CommandContextTest.java | 4 +- 82 files changed, 1417 insertions(+), 1406 deletions(-) diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/Brushes.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/Brushes.java index 77fcc072b..3517a1d05 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/Brushes.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/Brushes.java @@ -79,7 +79,7 @@ public class Brushes */ public Set getSniperBrushHandles(Class clazz) { - return new HashSet(brushes.get(clazz)); + return new HashSet<>(brushes.get(clazz)); } /** diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperListener.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperListener.java index 0c7d26c4c..f0ee3a73e 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperListener.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperListener.java @@ -26,7 +26,7 @@ public class VoxelSniperListener implements Listener private static final String SNIPER_PERMISSION = "voxelsniper.sniper"; private final VoxelSniper plugin; - private Map commands = new HashMap(); + private Map commands = new HashMap<>(); /** * @param plugin diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlockResetBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlockResetBrush.java index 6738b696a..180939755 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlockResetBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/BlockResetBrush.java @@ -13,7 +13,7 @@ import org.bukkit.block.Block; */ public class BlockResetBrush extends Brush { - private static final ArrayList DENIED_UPDATES = new ArrayList(); + private static final ArrayList DENIED_UPDATES = new ArrayList<>(); static { diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/DomeBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/DomeBrush.java index 19e1322a8..4983bf52a 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/DomeBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/DomeBrush.java @@ -54,7 +54,7 @@ public class DomeBrush extends Brush final int absoluteHeight = Math.abs(v.getVoxelHeight()); final boolean negative = v.getVoxelHeight() < 0; - final Set changeablePositions = new HashSet(); + final Set changeablePositions = new HashSet<>(); final Undo undo = new Undo(); diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/EntityRemovalBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/EntityRemovalBrush.java index 0d6871621..727a6a58c 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/EntityRemovalBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/EntityRemovalBrush.java @@ -16,7 +16,7 @@ import java.util.regex.PatternSyntaxException; */ public class EntityRemovalBrush extends Brush { - private final List exemptions = new ArrayList(3); + private final List exemptions = new ArrayList<>(3); /** * @@ -82,7 +82,7 @@ public class EntityRemovalBrush extends Brush private boolean isClassInExemptionList(Class entityClass) throws PatternSyntaxException { // Create a list of superclasses and interfaces implemented by the current entity type - final List entityClassHierarchy = new ArrayList(); + final List entityClassHierarchy = new ArrayList<>(); Class currentClass = entityClass; while (currentClass != null && !currentClass.equals(Object.class)) diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ErodeBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ErodeBrush.java index 0f678c88b..6d2b5e12e 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ErodeBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ErodeBrush.java @@ -133,7 +133,7 @@ public class ErodeBrush extends Brush int count = 0; - final Map blockCount = new HashMap(); + final Map blockCount = new HashMap<>(); for (final Vector vector : ErodeBrush.FACES_TO_CHECK) { @@ -363,8 +363,8 @@ public class ErodeBrush extends Brush public BlockChangeTracker(final AsyncWorld world) { - this.blockChanges = new HashMap>(); - this.flatChanges = new HashMap(); + this.blockChanges = new HashMap<>(); + this.flatChanges = new HashMap<>(); this.world = world; } @@ -400,7 +400,7 @@ public class ErodeBrush extends Brush { if (!this.blockChanges.containsKey(iteration)) { - this.blockChanges.put(iteration, new HashMap()); + this.blockChanges.put(iteration, new HashMap<>()); } this.blockChanges.get(iteration).put(position, changedBlock); diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/GenerateTreeBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/GenerateTreeBrush.java index 4a9067442..e38d8e277 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/GenerateTreeBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/GenerateTreeBrush.java @@ -24,7 +24,7 @@ public class GenerateTreeBrush extends Brush { // Tree Variables. private Random randGenerator = new Random(); - private ArrayList branchBlocks = new ArrayList(); + private ArrayList branchBlocks = new ArrayList<>(); private Undo undo; // If these default values are edited. Remember to change default values in the default preset. private Material leafType = Material.OAK_LEAVES; diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/HeatRayBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/HeatRayBrush.java index 1ac689d24..b50611818 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/HeatRayBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/HeatRayBrush.java @@ -44,7 +44,7 @@ public class HeatRayBrush extends Brush private static final double REQUIRED_FIRE_DENSITY = -0.25; private static final double REQUIRED_AIR_DENSITY = 0; - private static final ArrayList FLAMABLE_BLOCKS = new ArrayList(); + private static final ArrayList FLAMABLE_BLOCKS = new ArrayList<>(); private int octaves = 5; private double frequency = 1; diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/MoveBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/MoveBrush.java index b59d0ece1..9329fbf5f 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/MoveBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/MoveBrush.java @@ -58,7 +58,7 @@ public class MoveBrush extends Brush final AsyncWorld world = selection.getBlockStates().get(0).getWorld(); final Undo undo = new Undo(); - final HashSet undoSet = new HashSet(); + final HashSet undoSet = new HashSet<>(); final Selection newSelection = new Selection(); final Location movedLocation1 = selection.getLocation1(); @@ -214,7 +214,7 @@ public class MoveBrush extends Brush /** * Calculated BlockStates of the selection. */ - private final ArrayList blockStates = new ArrayList(); + private final ArrayList blockStates = new ArrayList<>(); /** * */ diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/PullBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/PullBrush.java index 7ec40bfe4..83c4a21bb 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/PullBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/PullBrush.java @@ -14,7 +14,7 @@ import java.util.HashSet; */ public class PullBrush extends Brush { - private final HashSet surface = new HashSet(); + private final HashSet surface = new HashSet<>(); private int vh; private double c1 = 1; private double c2 = 0; diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellSetBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellSetBrush.java index 9e7fa81d8..b4037a11f 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellSetBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/ShellSetBrush.java @@ -57,7 +57,8 @@ public class ShellSetBrush extends Brush } else { - final ArrayList blocks = new ArrayList(((Math.abs(highX - lowX) * Math.abs(highZ - lowZ) * Math.abs(highY - lowY)) / 2)); + final ArrayList blocks = new ArrayList<>( + ((Math.abs(highX - lowX) * Math.abs(highZ - lowZ) * Math.abs(highY - lowY)) / 2)); for (int y = lowY; y <= highY; y++) { for (int x = lowX; x <= highX; x++) diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplineBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplineBrush.java index 707a8c7ab..b2a0bdb47 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplineBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/SplineBrush.java @@ -16,9 +16,9 @@ import java.util.ArrayList; */ public class SplineBrush extends PerformBrush { - private final ArrayList endPts = new ArrayList(); - private final ArrayList ctrlPts = new ArrayList(); - protected ArrayList spline = new ArrayList(); + private final ArrayList endPts = new ArrayList<>(); + private final ArrayList ctrlPts = new ArrayList<>(); + protected ArrayList spline = new ArrayList<>(); protected boolean set; protected boolean ctrl; protected String[] sparams = {"ss", "sc", "clear"}; diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/StampBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/StampBrush.java index 43b884c28..c19e0f4e1 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/StampBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/StampBrush.java @@ -52,10 +52,10 @@ public class StampBrush extends Brush NO_AIR, FILL, DEFAULT } - protected HashSet clone = new HashSet(); - protected HashSet fall = new HashSet(); - protected HashSet drop = new HashSet(); - protected HashSet solid = new HashSet(); + protected HashSet clone = new HashSet<>(); + protected HashSet fall = new HashSet<>(); + protected HashSet drop = new HashSet<>(); + protected HashSet solid = new HashSet<>(); protected Undo undo; protected boolean sorted = false; diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/StencilListBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/StencilListBrush.java index a90f80569..b96a78a21 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/StencilListBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/StencilListBrush.java @@ -26,7 +26,7 @@ public class StencilListBrush extends Brush private short zRef; private short yRef; private byte pasteParam = 0; - private HashMap stencilList = new HashMap(); + private HashMap stencilList = new HashMap<>(); /** * diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/PerformerE.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/PerformerE.java index ef0ff7e5a..eafae4f82 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/PerformerE.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/perform/PerformerE.java @@ -163,8 +163,8 @@ public enum PerformerE static { - performers = new TreeMap(); - long_names = new TreeMap(); + performers = new TreeMap<>(); + long_names = new TreeMap<>(); for (PerformerE pe : values()) { diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/jsap/HelpJSAP.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/jsap/HelpJSAP.java index 17a01b81c..89870aa21 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/jsap/HelpJSAP.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/jsap/HelpJSAP.java @@ -165,7 +165,7 @@ public class HelpJSAP extends JSAP { if (!(jsapResult.success()) || jsapResult.getBoolean("help")) { - List returnValue = new LinkedList(); + List returnValue = new LinkedList<>(); // To avoid spurious missing argument errors we never print errors if help is required. if (!jsapResult.getBoolean("help")) { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e0b3fb8d7..db93606ed 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Mon Mar 25 18:59:14 EDT 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip diff --git a/worldedit-bukkit/build.gradle b/worldedit-bukkit/build.gradle index 43077f21e..acefe8c9b 100644 --- a/worldedit-bukkit/build.gradle +++ b/worldedit-bukkit/build.gradle @@ -1,88 +1,88 @@ -apply plugin: 'eclipse' -apply plugin: 'idea' -apply plugin: 'maven' - -repositories { - maven { url "https://hub.spigotmc.org/nexus/content/groups/public" } -} - -dependencies { - compile project(':worldedit-core') - compile 'net.milkbowl.vault:VaultAPI:1.7' - compile 'com.sk89q:dummypermscompat:1.8' - compile 'com.destroystokyo.paper:paper-api:1.13.2-R0.1-SNAPSHOT' - compile 'org.spigotmc:spigot:1.13.2-R0.1-SNAPSHOT' - testCompile 'org.mockito:mockito-core:1.9.0-rc1' - compile 'com.massivecraft:factions:2.8.0' - compile 'com.drtshock:factions:1.6.9.5' - compile 'com.factionsone:FactionsOne:1.2.2' - compile 'me.ryanhamshire:GriefPrevention:11.5.2' - compile 'com.massivecraft:mcore:7.0.1' - compile 'net.sacredlabyrinth.Phaed:PreciousStones:10.0.4-SNAPSHOT' - compile 'net.jzx7:regios:5.9.9' - compile 'com.bekvon.bukkit.residence:Residence:4.5._13.1' - compile 'com.palmergames.bukkit:towny:0.84.0.9' - compile 'com.thevoxelbox.voxelsniper:voxelsniper:5.171.0' - compile 'com.comphenix.protocol:ProtocolLib-API:4.4.0-SNAPSHOT' - compile 'com.wasteofplastic:askyblock:3.0.8.2' - compileOnly 'com.sk89q.worldguard:worldguard-core:7.0.0-20190215.210421-39' - compileOnly 'com.sk89q.worldguard:worldguard-legacy:7.0.0-20190215.210421-39' -} - -processResources { - from (sourceSets.main.resources.srcDirs) { - expand 'internalVersion': project.internalVersion - include 'plugin.yml' - } - - from (sourceSets.main.resources.srcDirs) { - exclude 'plugin.yml' - } -} - -jar.archiveName="fawe-bukkit-${project.parent.version}.jar" -jar.destinationDir = file '../mvn/com/boydti/fawe-bukkit/' + project.parent.version -task createPom << { - pom { - project { - groupId 'com.boydti' - artifactId 'fawe-bukkit' - version project.parent.version - } - } - .getEffectivePom() - .setDependencies(new ArrayList<>()) - .writeTo("../mvn/com/boydti/fawe-bukkit/${project.parent.version}/fawe-bukkit-${project.parent.version}.pom") - pom { - project { - groupId 'com.boydti' - artifactId 'fawe-bukkit' - version 'latest' - } - } - .getEffectivePom() - .setDependencies(new ArrayList<>()) - .writeTo("../mvn/com/boydti/fawe-bukkit/latest/fawe-bukkit-latest.pom") -} -task copyFiles { - doLast { - copy { - from "../mvn/com/boydti/fawe-bukkit/${project.parent.version}/" - into '../mvn/com/boydti/fawe-bukkit/latest/' - include('*.jar') - rename ("fawe-bukkit-${project.parent.version}.jar", 'fawe-bukkit-latest.jar') - } - } -} - -shadowJar { - dependencies { - include(dependency(':worldedit-core')) - } - archiveName = "${parent.name}-${project.name.replaceAll("worldedit-", "")}-${parent.version}.jar" - destinationDir = file '../target' -} - -build.dependsOn(shadowJar) -build.finalizedBy(copyFiles) -copyFiles.dependsOn(createPom) +apply plugin: 'eclipse' +apply plugin: 'idea' +apply plugin: 'maven' + +repositories { + maven { url "https://hub.spigotmc.org/nexus/content/groups/public" } +} + +dependencies { + compile project(':worldedit-core') + compile 'net.milkbowl.vault:VaultAPI:1.7' + compile 'com.sk89q:dummypermscompat:1.10' + compile 'com.destroystokyo.paper:paper-api:1.13.2-R0.1-SNAPSHOT' + compile 'org.spigotmc:spigot:1.13.2-R0.1-SNAPSHOT' + testCompile 'org.mockito:mockito-core:1.9.0-rc1' + compile 'com.massivecraft:factions:2.8.0' + compile 'com.drtshock:factions:1.6.9.5' + compile 'com.factionsone:FactionsOne:1.2.2' + compile 'me.ryanhamshire:GriefPrevention:11.5.2' + compile 'com.massivecraft:mcore:7.0.1' + compile 'net.sacredlabyrinth.Phaed:PreciousStones:10.0.4-SNAPSHOT' + compile 'net.jzx7:regios:5.9.9' + compile 'com.bekvon.bukkit.residence:Residence:4.5._13.1' + compile 'com.palmergames.bukkit:towny:0.84.0.9' + compile 'com.thevoxelbox.voxelsniper:voxelsniper:5.171.0' + compile 'com.comphenix.protocol:ProtocolLib-API:4.4.0-SNAPSHOT' + compile 'com.wasteofplastic:askyblock:3.0.8.2' + compileOnly 'com.sk89q.worldguard:worldguard-core:7.0.0-20190215.210421-39' + compileOnly 'com.sk89q.worldguard:worldguard-legacy:7.0.0-20190215.210421-39' +} + +processResources { + from (sourceSets.main.resources.srcDirs) { + expand 'internalVersion': project.internalVersion + include 'plugin.yml' + } + + from (sourceSets.main.resources.srcDirs) { + exclude 'plugin.yml' + } +} + +jar.archiveName="fawe-bukkit-${project.parent.version}.jar" +jar.destinationDir = file '../mvn/com/boydti/fawe-bukkit/' + project.parent.version +task createPom << { + pom { + project { + groupId 'com.boydti' + artifactId 'fawe-bukkit' + version project.parent.version + } + } + .getEffectivePom() + .setDependencies(new ArrayList<>()) + .writeTo("../mvn/com/boydti/fawe-bukkit/${project.parent.version}/fawe-bukkit-${project.parent.version}.pom") + pom { + project { + groupId 'com.boydti' + artifactId 'fawe-bukkit' + version 'latest' + } + } + .getEffectivePom() + .setDependencies(new ArrayList<>()) + .writeTo("../mvn/com/boydti/fawe-bukkit/latest/fawe-bukkit-latest.pom") +} +task copyFiles { + doLast { + copy { + from "../mvn/com/boydti/fawe-bukkit/${project.parent.version}/" + into '../mvn/com/boydti/fawe-bukkit/latest/' + include('*.jar') + rename ("fawe-bukkit-${project.parent.version}.jar", 'fawe-bukkit-latest.jar') + } + } +} + +shadowJar { + dependencies { + include(dependency(':worldedit-core')) + } + archiveName = "${parent.name}-${project.name.replaceAll("worldedit-", "")}-${parent.version}.jar" + destinationDir = file '../target' +} + +build.dependsOn(shadowJar) +build.finalizedBy(copyFiles) +copyFiles.dependsOn(createPom) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/Metrics.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/Metrics.java index ff1deca39..cd3269238 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/Metrics.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/Metrics.java @@ -43,7 +43,7 @@ public class Metrics { /** * All of the custom graphs to submit to metrics. */ - private final Set graphs = Collections.synchronizedSet(new HashSet()); + private final Set graphs = Collections.synchronizedSet(new HashSet<>()); /** * Unique server id. */ @@ -581,4 +581,4 @@ public class Metrics { return plotter.name.equals(this.name) && plotter.getValue() == getValue(); } } -} \ No newline at end of file +} diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/JsonString.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/JsonString.java index e59fb2e70..115bdf66e 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/JsonString.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/JsonString.java @@ -29,7 +29,7 @@ final class JsonString implements JsonRepresentedObject, ConfigurationSerializab } public Map serialize() { - HashMap theSingleValue = new HashMap(); + HashMap theSingleValue = new HashMap<>(); theSingleValue.put("stringValue", _value); return theSingleValue; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/Reflection.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/Reflection.java index d0e7b60c7..17e5e4280 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/Reflection.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/Reflection.java @@ -177,12 +177,12 @@ public final class Reflection { */ public synchronized static Method getMethod(Class clazz, String name, Class... args) { if (!_loadedMethods.containsKey(clazz)) { - _loadedMethods.put(clazz, new HashMap>, Method>>()); + _loadedMethods.put(clazz, new HashMap<>()); } Map>, Method>> loadedMethodNames = _loadedMethods.get(clazz); if (!loadedMethodNames.containsKey(name)) { - loadedMethodNames.put(name, new HashMap>, Method>()); + loadedMethodNames.put(name, new HashMap<>()); } Map>, Method> loadedSignatures = loadedMethodNames.get(name); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java index 00ed97f2d..efd8dbb3d 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java @@ -72,7 +72,7 @@ public class BukkitImageListener implements Listener { String name = player.getName().toLowerCase(); if (!event.getMessage().toLowerCase().contains(name)) { ArrayDeque buffered = fp.getMeta("CFIBufferedMessages"); - if (buffered == null) fp.setMeta("CFIBufferedMessaged", buffered = new ArrayDeque()); + if (buffered == null) fp.setMeta("CFIBufferedMessaged", buffered = new ArrayDeque<>()); String full = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage()); buffered.add(full); iter.remove(); @@ -280,4 +280,4 @@ public class BukkitImageListener implements Listener { } } } -} \ No newline at end of file +} diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/ItemUtil.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/ItemUtil.java index df5f92f87..28015ebb0 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/ItemUtil.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/ItemUtil.java @@ -69,7 +69,7 @@ public class ItemUtil { if (nativeTag != null) return (CompoundTag) nativeTag; } Tag nativeTag = BukkitQueue_0.toNative(nmsTag); - map.put(nmsTag.hashCode(), new WeakReference(nativeTag)); + map.put(nmsTag.hashCode(), new WeakReference<>(nativeTag)); return null; } } catch (Throwable e) { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java index dea95cace..77ea732fc 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java @@ -154,7 +154,7 @@ public class BukkitQueue_All extends BukkitQueue_0(); + if (unloaded == null) unloaded = new ArrayDeque<>(); unloaded.add(chunk); } } diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java index 6bc58a39c..c74c8f382 100644 --- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java +++ b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java @@ -118,7 +118,7 @@ public class MobSpawnerBlock extends BaseBlock { @Override public CompoundTag getNbtData() { - Map values = new HashMap(); + Map values = new HashMap<>(); values.put("EntityId", new StringTag(mobType)); values.put("Delay", new ShortTag(delay)); values.put("SpawnCount", new ShortTag(spawnCount)); diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java index 49ba23e27..60dabd6c7 100644 --- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java +++ b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java @@ -92,7 +92,7 @@ public class SignBlock extends BaseBlock { @Override public CompoundTag getNbtData() { - Map values = new HashMap(); + Map values = new HashMap<>(); values.put("Text1", new StringTag(text[0])); values.put("Text2", new StringTag(text[1])); values.put("Text3", new StringTag(text[2])); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java b/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java index f40085442..efcb66b5c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java @@ -378,7 +378,7 @@ public class FaweAPI { }); RegionWrapper bounds = new RegionWrapper(origin.x - radius, origin.x + radius, origin.z - radius, origin.z + radius); RegionWrapper boundsPlus = new RegionWrapper(bounds.minX - 64, bounds.maxX + 512, bounds.minZ - 64, bounds.maxZ + 512); - HashSet regionSet = new HashSet(Arrays.asList(bounds)); + HashSet regionSet = new HashSet<>(Arrays.asList(bounds)); ArrayList result = new ArrayList<>(); for (File file : files) { UUID uuid = UUID.fromString(file.getParentFile().getName()); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java index 41c0c23ce..a6d9394c9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java @@ -76,7 +76,7 @@ public class FaweCache { } public static Map asMap(Object... pairs) { - HashMap map = new HashMap(pairs.length >> 1); + HashMap map = new HashMap<>(pairs.length >> 1); for (int i = 0; i < pairs.length; i += 2) { String key = (String) pairs[i]; Object value = pairs[i + 1]; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/configuration/TypeDescription.java b/worldedit-core/src/main/java/com/boydti/fawe/configuration/TypeDescription.java index b4d115097..1f0b1474c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/configuration/TypeDescription.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/configuration/TypeDescription.java @@ -33,9 +33,9 @@ public final class TypeDescription { public TypeDescription(Class clazz, Tag tag) { this.type = clazz; this.tag = tag; - listProperties = new HashMap>(); - keyProperties = new HashMap>(); - valueProperties = new HashMap>(); + listProperties = new HashMap<>(); + keyProperties = new HashMap<>(); + valueProperties = new HashMap<>(); } public TypeDescription(Class clazz, String tag) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/configuration/Yaml.java b/worldedit-core/src/main/java/com/boydti/fawe/configuration/Yaml.java index 470c3090d..400d19c24 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/configuration/Yaml.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/configuration/Yaml.java @@ -175,7 +175,7 @@ public class Yaml { * @return YAML String */ public String dump(Object data) { - List list = new ArrayList(1); + List list = new ArrayList<>(1); list.add(data); return dumpAll(list.iterator()); } @@ -215,7 +215,7 @@ public class Yaml { * stream to write to */ public void dump(Object data, Writer output) { - List list = new ArrayList(1); + List list = new ArrayList<>(1); list.add(data); dumpAll(list.iterator(), output, null); } @@ -292,7 +292,7 @@ public class Yaml { if (flowStyle != null) { representer.setDefaultFlowStyle(flowStyle); } - List list = new ArrayList(1); + List list = new ArrayList<>(1); list.add(data); StringWriter buffer = new StringWriter(); dumpAll(list.iterator(), buffer, rootTag); @@ -345,7 +345,7 @@ public class Yaml { } private static class SilentEmitter implements Emitable { - private List events = new ArrayList(100); + private List events = new ArrayList<>(100); public List getEvents() { return events; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/configuration/serialization/ConfigurationSerialization.java b/worldedit-core/src/main/java/com/boydti/fawe/configuration/serialization/ConfigurationSerialization.java index 05f6464a6..445702c6f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/configuration/serialization/ConfigurationSerialization.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/configuration/serialization/ConfigurationSerialization.java @@ -16,7 +16,7 @@ public class ConfigurationSerialization { public static final String SERIALIZED_TYPE_KEY = "=="; private static final Map> aliases = - new HashMap>(); + new HashMap<>(); private final Class clazz; protected ConfigurationSerialization(Class clazz) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/example/IntFaweChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/example/IntFaweChunk.java index df1b1aa8a..2d6c7f7b9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/example/IntFaweChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/example/IntFaweChunk.java @@ -163,7 +163,7 @@ public abstract class IntFaweChunk extends FaweChunk @Override public Map getTiles() { - return tiles == null ? new HashMap() : tiles; + return tiles == null ? new HashMap<>() : tiles; } @Override @@ -189,7 +189,7 @@ public abstract class IntFaweChunk extends FaweChunk @Override public HashSet getEntityRemoves() { - return entityRemoves == null ? new HashSet() : entityRemoves; + return entityRemoves == null ? new HashSet<>() : entityRemoves; } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/example/WeakFaweQueueMap.java b/worldedit-core/src/main/java/com/boydti/fawe/example/WeakFaweQueueMap.java index e5c5a87ae..681745ec4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/example/WeakFaweQueueMap.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/example/WeakFaweQueueMap.java @@ -123,7 +123,7 @@ public class WeakFaweQueueMap implements IFaweQueueMap { @Override public void add(FaweChunk chunk) { long pair = MathMan.pairInt(chunk.getX(), chunk.getZ()); - Reference previous = this.blocks.put(pair, new SoftReference(chunk)); + Reference previous = this.blocks.put(pair, new SoftReference<>(chunk)); if (previous != null) { FaweChunk previousChunk = previous.get(); if (previousChunk != null) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/JSON2NBT.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/JSON2NBT.java index 97eadc54d..9d53caec8 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/JSON2NBT.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/JSON2NBT.java @@ -406,7 +406,7 @@ public class JSON2NBT { } public Tag parse() throws NBTException { - HashMap map = new HashMap(); + HashMap map = new HashMap<>(); Iterator var2 = this.tagList.iterator(); while (var2.hasNext()) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java index 84a856d11..801f5707e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java @@ -102,12 +102,13 @@ public class MCAChunk extends FaweChunk { if (entities.isEmpty()) { out.writeNamedEmptyList("Entities"); } else { - out.writeNamedTag("Entities", new ListTag(CompoundTag.class, new ArrayList(entities.values()))); + out.writeNamedTag("Entities", new ListTag(CompoundTag.class, new ArrayList<>(entities.values()))); } if (tiles.isEmpty()) { out.writeNamedEmptyList("TileEntities"); } else { - out.writeNamedTag("TileEntities", new ListTag(CompoundTag.class, new ArrayList(tiles.values()))); + out.writeNamedTag("TileEntities", new ListTag(CompoundTag.class, + new ArrayList<>(tiles.values()))); } out.writeNamedTag("InhabitedTime", inhabitedTime); out.writeNamedTag("LastUpdate", lastUpdate); @@ -422,9 +423,9 @@ public class MCAChunk extends FaweChunk { return null; } // e.g. by precalculating the length - HashMap level = new HashMap(); - level.put("Entities", new ListTag(CompoundTag.class, new ArrayList(entities.values()))); - level.put("TileEntities", new ListTag(CompoundTag.class, new ArrayList(tiles.values()))); + HashMap level = new HashMap<>(); + level.put("Entities", new ListTag(CompoundTag.class, new ArrayList<>(entities.values()))); + level.put("TileEntities", new ListTag(CompoundTag.class, new ArrayList<>(tiles.values()))); level.put("InhabitedTime", inhabitedTime); level.put("LastUpdate", lastUpdate); level.put("LightPopulated", (byte) 0); @@ -442,7 +443,7 @@ public class MCAChunk extends FaweChunk { if (idLayer == null) { continue; } - HashMap map = new HashMap(); + HashMap map = new HashMap<>(); map.put("Y", (byte) layer); map.put("BlockLight", blockLight[layer]); map.put("SkyLight", skyLight[layer]); @@ -499,7 +500,7 @@ public class MCAChunk extends FaweChunk { @Override public void accept(Integer index, CompoundTag entityTag) { if (entities == null) { - entities = new HashMap(); + entities = new HashMap<>(); } long least = entityTag.getLong("UUIDLeast"); long most = entityTag.getLong("UUIDMost"); @@ -635,7 +636,7 @@ public class MCAChunk extends FaweChunk { @Override public Map getTiles() { - return tiles == null ? new HashMap() : tiles; + return tiles == null ? new HashMap<>() : tiles; } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweChunk.java index 50ca1f4cc..91339926a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweChunk.java @@ -21,7 +21,7 @@ public abstract class FaweChunk implements Callable { private int x, z; public static int HEIGHT = 256; - private final ArrayDeque tasks = new ArrayDeque(0); + private final ArrayDeque tasks = new ArrayDeque<>(0); /** * A FaweSections object represents a chunk and the blocks that you wish to change in it. diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java index 75c88b73d..bbc6510b3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java @@ -97,7 +97,7 @@ public class HistoryExtent extends AbstractDelegateExtent { } private List wrapEntities(final List entities) { - final List newList = new ArrayList(entities.size()); + final List newList = new ArrayList<>(entities.size()); for (final Entity entity : entities) { newList.add(new TrackedEntity(entity)); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java index 7ea44b6da..685725ac3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java @@ -121,7 +121,7 @@ public class SplineBrush implements Brush, ResettableTool { double continuity = 0; double quality = 10; - final List nodes = new ArrayList(centroids.size()); + final List nodes = new ArrayList<>(centroids.size()); for (final Vector3 nodevector : centroids) { final Node n = new Node(nodevector); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index 455d03d6f..742aeb3be 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -491,7 +491,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet { public Map getPercents() { Map map = getBlocks(); int count = getSize(); - Int2ObjectOpenHashMap newMap = new Int2ObjectOpenHashMap(); + Int2ObjectOpenHashMap newMap = new Int2ObjectOpenHashMap<>(); for (Map.Entry entry : map.entrySet()) { int id = entry.getKey(); int changes = entry.getValue(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/IterableThreadLocal.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/IterableThreadLocal.java index 031f903ce..c31704c8d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/IterableThreadLocal.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/IterableThreadLocal.java @@ -12,7 +12,7 @@ import java.util.concurrent.ConcurrentLinkedDeque; public abstract class IterableThreadLocal extends ThreadLocal implements Iterable { private ThreadLocal flag; - private ConcurrentLinkedDeque allValues = new ConcurrentLinkedDeque(); + private ConcurrentLinkedDeque allValues = new ConcurrentLinkedDeque<>(); public IterableThreadLocal() { } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SimpleRandomCollection.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SimpleRandomCollection.java index 55e15b63c..aaa450f49 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SimpleRandomCollection.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SimpleRandomCollection.java @@ -7,7 +7,7 @@ import java.util.TreeMap; public class SimpleRandomCollection extends RandomCollection { - private final NavigableMap map = new TreeMap(); + private final NavigableMap map = new TreeMap<>(); private double total = 0; public SimpleRandomCollection(Map weights, SimpleRandom random) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SoftHashMap.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SoftHashMap.java index 4bc0875dd..883d4d235 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SoftHashMap.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/SoftHashMap.java @@ -93,10 +93,10 @@ public class SoftHashMap implements Map { public SoftHashMap(int retentionSize) { super(); RETENTION_SIZE = Math.max(0, retentionSize); - queue = new ReferenceQueue(); + queue = new ReferenceQueue<>(); strongReferencesLock = new ReentrantLock(); - map = new ConcurrentHashMap>(); - strongReferences = new ConcurrentLinkedQueue(); + map = new ConcurrentHashMap<>(); + strongReferences = new ConcurrentLinkedQueue<>(); } /** @@ -223,7 +223,7 @@ public class SoftHashMap implements Map { //noinspection unchecked return Collections.EMPTY_SET; } - Collection values = new ArrayList(keys.size()); + Collection values = new ArrayList<>(keys.size()); for (K key : keys) { V v = get(key); if (v != null) { @@ -238,7 +238,7 @@ public class SoftHashMap implements Map { */ public V put(K key, V value) { processQueue(); // throw out garbage collected values first - SoftValue sv = new SoftValue(value, key, queue); + SoftValue sv = new SoftValue<>(value, key, queue); SoftValue previous = map.put(key, sv); addToStrongReferences(value); return previous != null ? previous.get() : null; @@ -274,7 +274,7 @@ public class SoftHashMap implements Map { return Collections.EMPTY_SET; } - Map kvPairs = new HashMap(keys.size()); + Map kvPairs = new HashMap<>(keys.size()); for (K key : keys) { V v = get(key); if (v != null) { @@ -307,4 +307,4 @@ public class SoftHashMap implements Map { } } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/io/PGZIPOutputStream.java b/worldedit-core/src/main/java/com/boydti/fawe/object/io/PGZIPOutputStream.java index 2eedcd140..89eaea7ea 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/io/PGZIPOutputStream.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/io/PGZIPOutputStream.java @@ -39,7 +39,7 @@ public class PGZIPOutputStream extends FilterOutputStream { // todo: remove after block guessing is implemented // array list that contains the block sizes - ArrayList blockSizes = new ArrayList(); + ArrayList blockSizes = new ArrayList<>(); private int level = Deflater.DEFAULT_COMPRESSION; private int strategy = Deflater.DEFAULT_STRATEGY; @@ -80,7 +80,7 @@ public class PGZIPOutputStream extends FilterOutputStream { super(out); this.executor = executor; this.nthreads = nthreads; - this.emitQueue = new ArrayBlockingQueue>(nthreads); + this.emitQueue = new ArrayBlockingQueue<>(nthreads); writeHeader(); } @@ -246,4 +246,4 @@ public class PGZIPOutputStream extends FilterOutputStream { // LOG.warn("Already closed."); } } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/PolyhedralRegion.java b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/PolyhedralRegion.java index 654fdd9d3..a05e91ce9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/PolyhedralRegion.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/PolyhedralRegion.java @@ -38,17 +38,17 @@ public class PolyhedralRegion extends AbstractRegion { /** * Vertices that are contained in the convex hull. */ - private final Set vertices = new LinkedHashSet(); + private final Set vertices = new LinkedHashSet<>(); /** * Triangles that form the convex hull. */ - private final List triangles = new ArrayList(); + private final List triangles = new ArrayList<>(); /** * Vertices that are coplanar to the first 3 vertices. */ - private final Set vertexBacklog = new LinkedHashSet(); + private final Set vertexBacklog = new LinkedHashSet<>(); /** * Minimum point of the axis-aligned bounding box. @@ -165,7 +165,7 @@ public class PolyhedralRegion extends AbstractRegion { triangles.add((new Triangle(v[0], v[size - 1], v[size - 2]))); return true; } - final Set borderEdges = new LinkedHashSet(); + final Set borderEdges = new LinkedHashSet<>(); for (Iterator it = triangles.iterator(); it.hasNext(); ) { final Triangle triangle = it.next(); @@ -200,7 +200,7 @@ public class PolyhedralRegion extends AbstractRegion { vertices.remove(vertex); // Clone, clear and work through the backlog - final List vertexBacklog2 = new ArrayList(vertexBacklog); + final List vertexBacklog2 = new ArrayList<>(vertexBacklog); vertexBacklog.clear(); for (BlockVector3 vertex2 : vertexBacklog2) { addVertex(vertex2); @@ -261,7 +261,7 @@ public class PolyhedralRegion extends AbstractRegion { } private static void shiftCollection(Collection collection, BlockVector3 change) { - final List tmp = new ArrayList(collection); + final List tmp = new ArrayList<>(collection); collection.clear(); for (BlockVector3 vertex : tmp) { collection.add(change.add(vertex)); @@ -308,7 +308,7 @@ public class PolyhedralRegion extends AbstractRegion { return vertices; } - final List ret = new ArrayList(vertices); + final List ret = new ArrayList<>(vertices); ret.addAll(vertexBacklog); return ret; @@ -322,4 +322,4 @@ public class PolyhedralRegion extends AbstractRegion { public AbstractRegion clone() { return new PolyhedralRegion(this); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/FuzzyRegionSelector.java b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/FuzzyRegionSelector.java index 96402196e..ff398e776 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/FuzzyRegionSelector.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/FuzzyRegionSelector.java @@ -152,7 +152,7 @@ public class FuzzyRegionSelector extends AbstractDelegateExtent implements Regio @Override public List getInformationLines() { - final List lines = new ArrayList(); + final List lines = new ArrayList<>(); for (int i = 0; i < positions.size(); i++) { lines.add("Position " + i + ": " + positions.get(i)); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/PolyhedralRegionSelector.java b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/PolyhedralRegionSelector.java index c9a68d2a8..b8815126a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/PolyhedralRegionSelector.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/selector/PolyhedralRegionSelector.java @@ -146,7 +146,7 @@ public class PolyhedralRegionSelector 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()); @@ -202,7 +202,7 @@ public class PolyhedralRegionSelector 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 (BlockVector3 vertex : vertices) { vertexIds.put(vertex, ++lastVertexId); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/SetQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/util/SetQueue.java index 536f3202a..191bed5b0 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/SetQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/SetQueue.java @@ -228,7 +228,7 @@ public class SetQueue { } public Collection getAllQueues() { - ArrayList list = new ArrayList(activeQueues.size() + inactiveQueues.size()); + ArrayList list = new ArrayList<>(activeQueues.size() + inactiveQueues.size()); list.addAll(inactiveQueues); list.addAll(activeQueues); return list; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/ShapeInterpolator.java b/worldedit-core/src/main/java/com/boydti/fawe/util/ShapeInterpolator.java index 6dc9ba418..9d23d38d4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/ShapeInterpolator.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/ShapeInterpolator.java @@ -167,7 +167,7 @@ public class ShapeInterpolator { bezierCoordinates[0] = curX = movX = coordinates[0]; bezierCoordinates[1] = curY = movY = coordinates[1]; float newX, newY; - final Vector savedPathEndPoints = new Vector(); + final Vector savedPathEndPoints = new Vector<>(); numCoordinates = 2; while (!pi.isDone()) { switch (pi.currentSegment(coordinates)) { @@ -735,4 +735,4 @@ public class ShapeInterpolator { return res; } } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/StringMan.java b/worldedit-core/src/main/java/com/boydti/fawe/util/StringMan.java index b02de918d..1622629f9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/StringMan.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/StringMan.java @@ -148,7 +148,7 @@ public class StringMan { } public static List split(String input, char delim) { - List result = new ArrayList(); + List result = new ArrayList<>(); int start = 0; int bracket = 0; boolean inQuotes = false; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java b/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java index d7216c891..b7d037ffd 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java @@ -583,7 +583,7 @@ public class TextureUtil implements TextureHolder{ // Get all the groups in the current jar // The vanilla textures are in `assets/minecraft` // A jar may contain textures for multiple mods - Set mods = new HashSet(); + Set mods = new HashSet<>(); { Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/chat/UsageMessage.java b/worldedit-core/src/main/java/com/boydti/fawe/util/chat/UsageMessage.java index ea33a753d..3c187360d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/chat/UsageMessage.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/chat/UsageMessage.java @@ -57,7 +57,7 @@ public class UsageMessage extends Message { text(BBC.HELP_HEADER_SUBCOMMANDS.f()); String prefix = !commandString.isEmpty() ? commandString + " " : ""; - List list = new ArrayList(dispatcher.getCommands()); + List list = new ArrayList<>(dispatcher.getCommands()); Collections.sort(list, new PrimaryAliasComparator(CommandManager.COMMAND_CLEAN_PATTERN)); for (CommandMapping mapping : list) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java b/worldedit-core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java index 402b79f21..adc56e908 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/task/TaskBuilder.java @@ -308,7 +308,7 @@ public class TaskBuilder extends Metadatable { continue; case SYNC_PARALLEL: case ASYNC_PARALLEL: - final ArrayList parallel = new ArrayList(); + final ArrayList parallel = new ArrayList<>(); parallel.add(task); RunnableTask next = tasks.peek(); while (next != null && next.type == task.type) { @@ -571,4 +571,4 @@ public class TaskBuilder extends Metadatable { DELAY, ABORT } -} \ No newline at end of file +} 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 da642d4db..7b75a4642 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java @@ -1,447 +1,447 @@ -/* - * 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.jnbt; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * The {@code TAG_Compound} tag. - */ -public final class CompoundTag extends Tag { - - private final Map value; - - /** - * Creates the tag with an empty name. - * - * @param value the value of the tag - */ - public CompoundTag(Map value) { - super(); - this.value = value; - } - - @Override - public Map getRaw() { - HashMap raw = new HashMap<>(); - for (Map.Entry entry : value.entrySet()) { - raw.put(entry.getKey(), entry.getValue().getRaw()); - } - return raw; - } - - /** - * Returns whether this compound tag contains the given key. - * - * @param key the given key - * @return true if the tag contains the given key - */ - public boolean containsKey(String key) { - return value.containsKey(key); - } - - @Override - public Map getValue() { - return value; - } - - /** - * Return a new compound tag with the given values. - * - * @param value the value - * @return the new compound tag - */ - public CompoundTag setValue(Map value) { - return new CompoundTag(value); - } - - /** - * Create a compound tag builder. - * - * @return the builder - */ - public CompoundTagBuilder createBuilder() { - return new CompoundTagBuilder(new HashMap(value)); - } - - /** - * Get a byte array named with the given key. - * - *

If the key does not exist or its value is not a byte array tag, - * then an empty byte array will be returned.

- * - * @param key the key - * @return a byte array - */ - public byte[] getByteArray(String key) { - Tag tag = value.get(key); - if (tag instanceof ByteArrayTag) { - return ((ByteArrayTag) tag).getValue(); - } else { - return new byte[0]; - } - } - - /** - * Get a byte named with the given key. - * - *

If the key does not exist or its value is not a byte tag, - * then {@code 0} will be returned.

- * - * @param key the key - * @return a byte - */ - public byte getByte(String key) { - Tag tag = value.get(key); - if (tag instanceof ByteTag) { - return ((ByteTag) tag).getValue(); - } else { - return (byte) 0; - } - } - - /** - * Get a double named with the given key. - * - *

If the key does not exist or its value is not a double tag, - * then {@code 0} will be returned.

- * - * @param key the key - * @return a double - */ - public double getDouble(String key) { - Tag tag = value.get(key); - if (tag instanceof DoubleTag) { - return ((DoubleTag) tag).getValue(); - } else { - return 0; - } - } - - /** - * Get a double named with the given key, even if it's another - * type of number. - * - *

If the key does not exist or its value is not a number, - * then {@code 0} will be returned.

- * - * @param key the key - * @return a double - */ - public double asDouble(String key) { - Tag tag = value.get(key); - if (tag instanceof ByteTag) { - return ((ByteTag) tag).getValue(); - - } else if (tag instanceof ShortTag) { - return ((ShortTag) tag).getValue(); - - } else if (tag instanceof IntTag) { - return ((IntTag) tag).getValue(); - - } else if (tag instanceof LongTag) { - return ((LongTag) tag).getValue(); - - } else if (tag instanceof FloatTag) { - return ((FloatTag) tag).getValue(); - - } else if (tag instanceof DoubleTag) { - return ((DoubleTag) tag).getValue(); - - } else { - return 0; - } - } - - /** - * Get a float named with the given key. - * - *

If the key does not exist or its value is not a float tag, - * then {@code 0} will be returned.

- * - * @param key the key - * @return a float - */ - public float getFloat(String key) { - Tag tag = value.get(key); - if (tag instanceof FloatTag) { - return ((FloatTag) tag).getValue(); - } else { - return 0; - } - } - - /** - * Get a {@code int[]} named with the given key. - * - *

If the key does not exist or its value is not an int array tag, - * then an empty array will be returned.

- * - * @param key the key - * @return an int array - */ - public int[] getIntArray(String key) { - Tag tag = value.get(key); - if (tag instanceof IntArrayTag) { - return ((IntArrayTag) tag).getValue(); - } else { - return new int[0]; - } - } - - /** - * Get an int named with the given key. - * - *

If the key does not exist or its value is not an int tag, - * then {@code 0} will be returned.

- * - * @param key the key - * @return an int - */ - public int getInt(String key) { - Tag tag = value.get(key); - if (tag instanceof IntTag) { - return ((IntTag) tag).getValue(); - } else { - return 0; - } - } - - /** - * Get an int named with the given key, even if it's another - * type of number. - * - *

If the key does not exist or its value is not a number, - * then {@code 0} will be returned.

- * - * @param key the key - * @return an int - */ - public int asInt(String key) { - Tag tag = value.get(key); - if (tag instanceof ByteTag) { - return ((ByteTag) tag).getValue(); - - } else if (tag instanceof ShortTag) { - return ((ShortTag) tag).getValue(); - - } else if (tag instanceof IntTag) { - return ((IntTag) tag).getValue(); - - } else if (tag instanceof LongTag) { - return ((LongTag) tag).getValue().intValue(); - - } else if (tag instanceof FloatTag) { - return ((FloatTag) tag).getValue().intValue(); - - } else if (tag instanceof DoubleTag) { - return ((DoubleTag) tag).getValue().intValue(); - - } else { - return 0; - } - } - - /** - * Get a list of tags named with the given key. - * - *

If the key does not exist or its value is not a list tag, - * then an empty list will be returned.

- * - * @param key the key - * @return a list of tags - */ - public List getList(String key) { - Tag tag = value.get(key); - if (tag instanceof ListTag) { - return ((ListTag) tag).getValue(); - } else { - return Collections.emptyList(); - } - } - - /** - * Get a {@code TagList} named with the given key. - * - *

If the key does not exist or its value is not a list tag, - * then an empty tag list will be returned.

- * - * @param key the key - * @return a tag list instance - */ - public ListTag getListTag(String key) { - Tag tag = value.get(key); - if (tag instanceof ListTag) { - return (ListTag) tag; - } else { - return new ListTag(StringTag.class, Collections.emptyList()); - } - } - - /** - * Get a list of tags named with the given key. - * - *

If the key does not exist or its value is not a list tag, - * then an empty list will be returned. If the given key references - * a list but the list of of a different type, then an empty - * list will also be returned.

- * - * @param key the key - * @param listType the class of the contained type - * @return a list of tags - * @param the type of list - */ - @SuppressWarnings("unchecked") - public List getList(String key, Class listType) { - Tag tag = value.get(key); - if (tag instanceof ListTag) { - ListTag listTag = (ListTag) tag; - if (listTag.getType().equals(listType)) { - return (List) listTag.getValue(); - } else { - return Collections.emptyList(); - } - } else { - return Collections.emptyList(); - } - } - - /** - * Get a {@code long[]} named with the given key. - * - *

If the key does not exist or its value is not an long array tag, - * then an empty array will be returned.

- * - * @param key the key - * @return an int array - */ - public long[] getLongArray(String key) { - Tag tag = value.get(key); - if (tag instanceof LongArrayTag) { - return ((LongArrayTag) tag).getValue(); - } else { - return new long[0]; - } - } - - /** - * Get a long named with the given key. - * - *

If the key does not exist or its value is not a long tag, - * then {@code 0} will be returned.

- * - * @param key the key - * @return a long - */ - public long getLong(String key) { - Tag tag = value.get(key); - if (tag instanceof LongTag) { - return ((LongTag) tag).getValue(); - } else { - return 0L; - } - } - - /** - * Get a long named with the given key, even if it's another - * type of number. - * - *

If the key does not exist or its value is not a number, - * then {@code 0} will be returned.

- * - * @param key the key - * @return a long - */ - public long asLong(String key) { - Tag tag = value.get(key); - if (tag instanceof ByteTag) { - return ((ByteTag) tag).getValue(); - - } else if (tag instanceof ShortTag) { - return ((ShortTag) tag).getValue(); - - } else if (tag instanceof IntTag) { - return ((IntTag) tag).getValue(); - - } else if (tag instanceof LongTag) { - return ((LongTag) tag).getValue(); - - } else if (tag instanceof FloatTag) { - return ((FloatTag) tag).getValue().longValue(); - - } else if (tag instanceof DoubleTag) { - return ((DoubleTag) tag).getValue().longValue(); - - } else { - return 0L; - } - } - - /** - * Get a short named with the given key. - * - *

If the key does not exist or its value is not a short tag, - * then {@code 0} will be returned.

- * - * @param key the key - * @return a short - */ - public short getShort(String key) { - Tag tag = value.get(key); - if (tag instanceof ShortTag) { - return ((ShortTag) tag).getValue(); - } else { - return 0; - } - } - - /** - * Get a string named with the given key. - * - *

If the key does not exist or its value is not a string tag, - * then {@code ""} will be returned.

- * - * @param key the key - * @return a string - */ - public String getString(String key) { - Tag tag = value.get(key); - if (tag instanceof StringTag) { - return ((StringTag) tag).getValue(); - } else { - return ""; - } - } - - @Override - public String toString() { - StringBuilder bldr = new StringBuilder(); - bldr.append("TAG_Compound").append(": ").append(value.size()).append(" entries\r\n{\r\n"); - for (Map.Entry entry : value.entrySet()) { - bldr.append(" ").append(entry.getValue().toString().replaceAll("\r\n", "\r\n ")).append("\r\n"); - } - bldr.append("}"); - return bldr.toString(); - } - -} \ No newline at end of file +/* + * 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.jnbt; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * The {@code TAG_Compound} tag. + */ +public final class CompoundTag extends Tag { + + private final Map value; + + /** + * Creates the tag with an empty name. + * + * @param value the value of the tag + */ + public CompoundTag(Map value) { + super(); + this.value = value; + } + + @Override + public Map getRaw() { + HashMap raw = new HashMap<>(); + for (Map.Entry entry : value.entrySet()) { + raw.put(entry.getKey(), entry.getValue().getRaw()); + } + return raw; + } + + /** + * Returns whether this compound tag contains the given key. + * + * @param key the given key + * @return true if the tag contains the given key + */ + public boolean containsKey(String key) { + return value.containsKey(key); + } + + @Override + public Map getValue() { + return value; + } + + /** + * Return a new compound tag with the given values. + * + * @param value the value + * @return the new compound tag + */ + public CompoundTag setValue(Map value) { + return new CompoundTag(value); + } + + /** + * Create a compound tag builder. + * + * @return the builder + */ + public CompoundTagBuilder createBuilder() { + return new CompoundTagBuilder(new HashMap<>(value)); + } + + /** + * Get a byte array named with the given key. + * + *

If the key does not exist or its value is not a byte array tag, + * then an empty byte array will be returned.

+ * + * @param key the key + * @return a byte array + */ + public byte[] getByteArray(String key) { + Tag tag = value.get(key); + if (tag instanceof ByteArrayTag) { + return ((ByteArrayTag) tag).getValue(); + } else { + return new byte[0]; + } + } + + /** + * Get a byte named with the given key. + * + *

If the key does not exist or its value is not a byte tag, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return a byte + */ + public byte getByte(String key) { + Tag tag = value.get(key); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + } else { + return (byte) 0; + } + } + + /** + * Get a double named with the given key. + * + *

If the key does not exist or its value is not a double tag, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return a double + */ + public double getDouble(String key) { + Tag tag = value.get(key); + if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get a double named with the given key, even if it's another + * type of number. + * + *

If the key does not exist or its value is not a number, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return a double + */ + public double asDouble(String key) { + Tag tag = value.get(key); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + + } else if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + + } else if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + + } else if (tag instanceof LongTag) { + return ((LongTag) tag).getValue(); + + } else if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue(); + + } else if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue(); + + } else { + return 0; + } + } + + /** + * Get a float named with the given key. + * + *

If the key does not exist or its value is not a float tag, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return a float + */ + public float getFloat(String key) { + Tag tag = value.get(key); + if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get a {@code int[]} named with the given key. + * + *

If the key does not exist or its value is not an int array tag, + * then an empty array will be returned.

+ * + * @param key the key + * @return an int array + */ + public int[] getIntArray(String key) { + Tag tag = value.get(key); + if (tag instanceof IntArrayTag) { + return ((IntArrayTag) tag).getValue(); + } else { + return new int[0]; + } + } + + /** + * Get an int named with the given key. + * + *

If the key does not exist or its value is not an int tag, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return an int + */ + public int getInt(String key) { + Tag tag = value.get(key); + if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get an int named with the given key, even if it's another + * type of number. + * + *

If the key does not exist or its value is not a number, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return an int + */ + public int asInt(String key) { + Tag tag = value.get(key); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + + } else if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + + } else if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + + } else if (tag instanceof LongTag) { + return ((LongTag) tag).getValue().intValue(); + + } else if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue().intValue(); + + } else if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue().intValue(); + + } else { + return 0; + } + } + + /** + * Get a list of tags named with the given key. + * + *

If the key does not exist or its value is not a list tag, + * then an empty list will be returned.

+ * + * @param key the key + * @return a list of tags + */ + public List getList(String key) { + Tag tag = value.get(key); + if (tag instanceof ListTag) { + return ((ListTag) tag).getValue(); + } else { + return Collections.emptyList(); + } + } + + /** + * Get a {@code TagList} named with the given key. + * + *

If the key does not exist or its value is not a list tag, + * then an empty tag list will be returned.

+ * + * @param key the key + * @return a tag list instance + */ + public ListTag getListTag(String key) { + Tag tag = value.get(key); + if (tag instanceof ListTag) { + return (ListTag) tag; + } else { + return new ListTag(StringTag.class, Collections.emptyList()); + } + } + + /** + * Get a list of tags named with the given key. + * + *

If the key does not exist or its value is not a list tag, + * then an empty list will be returned. If the given key references + * a list but the list of of a different type, then an empty + * list will also be returned.

+ * + * @param key the key + * @param listType the class of the contained type + * @return a list of tags + * @param the type of list + */ + @SuppressWarnings("unchecked") + public List getList(String key, Class listType) { + Tag tag = value.get(key); + if (tag instanceof ListTag) { + ListTag listTag = (ListTag) tag; + if (listTag.getType().equals(listType)) { + return (List) listTag.getValue(); + } else { + return Collections.emptyList(); + } + } else { + return Collections.emptyList(); + } + } + + /** + * Get a {@code long[]} named with the given key. + * + *

If the key does not exist or its value is not an long array tag, + * then an empty array will be returned.

+ * + * @param key the key + * @return an int array + */ + public long[] getLongArray(String key) { + Tag tag = value.get(key); + if (tag instanceof LongArrayTag) { + return ((LongArrayTag) tag).getValue(); + } else { + return new long[0]; + } + } + + /** + * Get a long named with the given key. + * + *

If the key does not exist or its value is not a long tag, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return a long + */ + public long getLong(String key) { + Tag tag = value.get(key); + if (tag instanceof LongTag) { + return ((LongTag) tag).getValue(); + } else { + return 0L; + } + } + + /** + * Get a long named with the given key, even if it's another + * type of number. + * + *

If the key does not exist or its value is not a number, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return a long + */ + public long asLong(String key) { + Tag tag = value.get(key); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + + } else if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + + } else if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + + } else if (tag instanceof LongTag) { + return ((LongTag) tag).getValue(); + + } else if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue().longValue(); + + } else if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue().longValue(); + + } else { + return 0L; + } + } + + /** + * Get a short named with the given key. + * + *

If the key does not exist or its value is not a short tag, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return a short + */ + public short getShort(String key) { + Tag tag = value.get(key); + if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get a string named with the given key. + * + *

If the key does not exist or its value is not a string tag, + * then {@code ""} will be returned.

+ * + * @param key the key + * @return a string + */ + public String getString(String key) { + Tag tag = value.get(key); + if (tag instanceof StringTag) { + return ((StringTag) tag).getValue(); + } else { + return ""; + } + } + + @Override + public String toString() { + StringBuilder bldr = new StringBuilder(); + bldr.append("TAG_Compound").append(": ").append(value.size()).append(" entries\r\n{\r\n"); + for (Map.Entry entry : value.entrySet()) { + bldr.append(" ").append(entry.getValue().toString().replaceAll("\r\n", "\r\n ")).append("\r\n"); + } + bldr.append("}"); + return bldr.toString(); + } + +} 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 1799993bb..2e701ddf3 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. */ public CompoundTagBuilder() { - this.entries = new HashMap(); + this.entries = new HashMap<>(); } /** @@ -201,7 +201,7 @@ public class CompoundTagBuilder { * @return the new compound tag */ public CompoundTag build() { - return new CompoundTag(new HashMap(entries)); + return new CompoundTag(new HashMap<>(entries)); } /** @@ -213,4 +213,4 @@ public class CompoundTagBuilder { return new CompoundTagBuilder(); } -} \ No newline at end of file +} 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 5788e0b8a..78b9998a8 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java @@ -375,7 +375,7 @@ public final class NBTInputStream implements Closeable { childType = NBTConstants.TYPE_COMPOUND; } 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) { @@ -385,7 +385,7 @@ public final class NBTInputStream implements Closeable { } return (tagList); case NBTConstants.TYPE_COMPOUND: - Map tagMap = new HashMap(); + Map tagMap = new HashMap<>(); while (true) { NamedTag namedTag = readNamedTag(depth + 1); Tag tag = namedTag.getTag(); @@ -562,7 +562,7 @@ public final class NBTInputStream implements Closeable { childType = NBTConstants.TYPE_COMPOUND; } 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) { @@ -573,7 +573,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/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index df587294d..2b2343408 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -3172,7 +3172,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, */ public int drawSpline(final Pattern pattern, final List nodevectors, final double tension, final double bias, final double continuity, final double quality, final double radius, final boolean filled) throws WorldEditException { LocalBlockVectorSet vset = new LocalBlockVectorSet(); - final List nodes = new ArrayList(nodevectors.size()); + final List nodes = new ArrayList<>(nodevectors.size()); final KochanekBartelsInterpolation interpol = new KochanekBartelsInterpolation(); for (BlockVector3 nodevector : nodevectors) { @@ -3278,7 +3278,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, public void recurseHollow(final Region region, final BlockVector3 origin, final Set outside) { //TODO FIXME Optimize - avoid vector creation - final ArrayDeque queue = new ArrayDeque(); + final ArrayDeque queue = new ArrayDeque<>(); queue.addLast(origin); while (!queue.isEmpty()) { 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 4ccc9fdb3..3ec352d07 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -1,158 +1,161 @@ -/* - * 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; - -import static com.sk89q.worldedit.event.platform.Interaction.HIT; -import static com.sk89q.worldedit.event.platform.Interaction.OPEN; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.blocks.BaseItem; -import com.sk89q.worldedit.entity.Player; -import com.sk89q.worldedit.event.platform.BlockInteractEvent; -import com.sk89q.worldedit.event.platform.InputType; -import com.sk89q.worldedit.event.platform.PlayerInputEvent; -import com.sk89q.worldedit.extension.factory.BlockFactory; -import com.sk89q.worldedit.extension.factory.ItemFactory; -import com.sk89q.worldedit.extension.factory.MaskFactory; -import com.sk89q.worldedit.extension.factory.PatternFactory; -import com.sk89q.worldedit.extension.platform.Actor; -import com.sk89q.worldedit.extension.platform.Capability; -import com.sk89q.worldedit.extension.platform.Platform; -import com.sk89q.worldedit.extension.platform.PlatformManager; -import com.sk89q.worldedit.extent.inventory.BlockBag; -import com.sk89q.worldedit.internal.expression.Expression; -import com.sk89q.worldedit.internal.expression.runtime.Constant; -import com.sk89q.worldedit.internal.expression.runtime.RValue; -import com.sk89q.worldedit.function.pattern.Pattern; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.scripting.CraftScriptContext; -import com.sk89q.worldedit.scripting.CraftScriptEngine; -import com.sk89q.worldedit.scripting.RhinoCraftScriptEngine; -import com.sk89q.worldedit.session.SessionManager; -import com.sk89q.worldedit.session.request.Request; -import com.sk89q.worldedit.util.Direction; -import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.eventbus.EventBus; -import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException; -import com.sk89q.worldedit.util.io.file.FilenameException; -import com.sk89q.worldedit.util.io.file.FilenameResolutionException; -import com.sk89q.worldedit.util.io.file.InvalidFilenameException; +/* + * 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; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import com.sk89q.worldedit.blocks.BaseItem; +import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.event.platform.BlockInteractEvent; +import com.sk89q.worldedit.event.platform.InputType; +import com.sk89q.worldedit.event.platform.PlayerInputEvent; +import com.sk89q.worldedit.extension.factory.BlockFactory; +import com.sk89q.worldedit.extension.factory.ItemFactory; +import com.sk89q.worldedit.extension.factory.MaskFactory; +import com.sk89q.worldedit.extension.factory.PatternFactory; +import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.extension.platform.Capability; +import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.extension.platform.PlatformManager; +import com.sk89q.worldedit.extent.inventory.BlockBag; +import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.internal.expression.Expression; +import com.sk89q.worldedit.internal.expression.runtime.Constant; +import com.sk89q.worldedit.internal.expression.runtime.RValue; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.scripting.CraftScriptContext; +import com.sk89q.worldedit.scripting.CraftScriptEngine; +import com.sk89q.worldedit.scripting.RhinoCraftScriptEngine; +import com.sk89q.worldedit.session.SessionManager; +import com.sk89q.worldedit.session.request.Request; +import com.sk89q.worldedit.util.Direction; +import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.util.eventbus.EventBus; +import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException; +import com.sk89q.worldedit.util.io.file.FilenameException; +import com.sk89q.worldedit.util.io.file.FilenameResolutionException; +import com.sk89q.worldedit.util.io.file.InvalidFilenameException; import com.sk89q.worldedit.util.logging.WorldEditPrefixHandler; import com.sk89q.worldedit.util.task.SimpleSupervisor; import com.sk89q.worldedit.util.task.Supervisor; -import com.sk89q.worldedit.world.block.BlockStateHolder; -import com.sk89q.worldedit.world.block.BlockType; -import com.sk89q.worldedit.world.registry.BundledBlockData; -import com.sk89q.worldedit.world.registry.BundledItemData; -import com.sk89q.worldedit.world.registry.LegacyMapper; - -import java.io.DataInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.script.ScriptException; - -/** - * The entry point and container for a working implementation of WorldEdit. - * - *

An instance handles event handling; block, mask, pattern, etc. registration; - * the management of sessions; the creation of {@link EditSession}s; and more. - * In order to use WorldEdit, at least one {@link Platform} must be registered - * with WorldEdit using {@link PlatformManager#register(Platform)} on the - * manager retrieved using {@link WorldEdit#getPlatformManager()}.

- * - *

An instance of WorldEdit can be retrieved using the static - * method {@link WorldEdit#getInstance()}, which is shared among all - * platforms within the same classloader hierarchy.

- */ -public class WorldEdit { - - public static final Logger logger = Logger.getLogger(WorldEdit.class.getCanonicalName()); - - private final static WorldEdit instance = new WorldEdit(); - private static String version; - - private final EventBus eventBus = new EventBus(); - private final PlatformManager platformManager = new PlatformManager(this); - private final EditSessionFactory editSessionFactory = new EditSessionFactory.EditSessionFactoryImpl(eventBus); +import com.sk89q.worldedit.world.block.BlockStateHolder; +import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.registry.BundledBlockData; +import com.sk89q.worldedit.world.registry.BundledItemData; +import com.sk89q.worldedit.world.registry.LegacyMapper; + +import javax.annotation.Nullable; +import javax.script.ScriptException; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import static com.sk89q.worldedit.event.platform.Interaction.HIT; +import static com.sk89q.worldedit.event.platform.Interaction.OPEN; + +/** + * The entry point and container for a working implementation of WorldEdit. + * + *

An instance handles event handling; block, mask, pattern, etc. registration; + * the management of sessions; the creation of {@link EditSession}s; and more. + * In order to use WorldEdit, at least one {@link Platform} must be registered + * with WorldEdit using {@link PlatformManager#register(Platform)} on the + * manager retrieved using {@link WorldEdit#getPlatformManager()}.

+ * + *

An instance of WorldEdit can be retrieved using the static + * method {@link WorldEdit#getInstance()}, which is shared among all + * platforms within the same classloader hierarchy.

+ */ +public final class WorldEdit { + + public static final Logger logger = Logger.getLogger(WorldEdit.class.getCanonicalName()); + + private final static WorldEdit instance = new WorldEdit(); + private static String version; + + private final EventBus eventBus = new EventBus(); + private final PlatformManager platformManager = new PlatformManager(this); + private final EditSessionFactory editSessionFactory = new EditSessionFactory.EditSessionFactoryImpl(eventBus); private final SessionManager sessions = new SessionManager(this); - private final Supervisor supervisor = new SimpleSupervisor(); - - private final BlockFactory blockFactory = new BlockFactory(this); - private final ItemFactory itemFactory = new ItemFactory(this); - private final MaskFactory maskFactory = new MaskFactory(this); - private final PatternFactory patternFactory = new PatternFactory(this); - - static { - WorldEditPrefixHandler.register("com.sk89q.worldedit"); - getVersion(); - } - - private WorldEdit() { - } - - /** - * Gets the current instance of this class. - * - *

An instance will always be available, but no platform may yet be - * registered with WorldEdit, meaning that a number of operations - * may fail. However, event handlers can be registered.

- * - * @return an instance of WorldEdit. - */ - public static WorldEdit getInstance() { - return instance; - } - - /** - * Get the platform manager, where platforms (that implement WorldEdit) - * can be registered and information about registered platforms can - * be queried. - * - * @return the platform manager - */ - public PlatformManager getPlatformManager() { - return platformManager; - } - - /** - * Get the event bus for WorldEdit. - * - *

Event handlers can be registered on the event bus.

- * - * @return the event bus - */ - public EventBus getEventBus() { - return eventBus; + private final Supervisor supervisor = new SimpleSupervisor(); + + private final BlockFactory blockFactory = new BlockFactory(this); + private final ItemFactory itemFactory = new ItemFactory(this); + private final MaskFactory maskFactory = new MaskFactory(this); + private final PatternFactory patternFactory = new PatternFactory(this); + + static { + WorldEditPrefixHandler.register("com.sk89q.worldedit"); + getVersion(); } - + + private WorldEdit() { + } + + /** + * Gets the current instance of this class. + * + *

An instance will always be available, but no platform may yet be + * registered with WorldEdit, meaning that a number of operations + * may fail. However, event handlers can be registered.

+ * + * @return an instance of WorldEdit. + */ + public static WorldEdit getInstance() { + return instance; + } + + /** + * Get the platform manager, where platforms (that implement WorldEdit) + * can be registered and information about registered platforms can + * be queried. + * + * @return the platform manager + */ + public PlatformManager getPlatformManager() { + return platformManager; + } + + /** + * Get the event bus for WorldEdit. + * + *

Event handlers can be registered on the event bus.

+ * + * @return the event bus + */ + public EventBus getEventBus() { + return eventBus; + } + /** * Get the supervisor. * @@ -161,566 +164,570 @@ public class WorldEdit { public Supervisor getSupervisor() { return supervisor; } - - - /** - * Get the block factory from which new {@link BlockStateHolder}s can be - * constructed. - * - * @return the block factory - */ - public BlockFactory getBlockFactory() { - return blockFactory; - } - - /** - * Get the item factory from which new {@link BaseItem}s can be - * constructed. - * - * @return the item factory - */ - public ItemFactory getItemFactory() { - return itemFactory; - } - - /** - * Get the mask factory from which new {@link com.sk89q.worldedit.function.mask.Mask}s - * can be constructed. - * - * @return the mask factory - */ - public MaskFactory getMaskFactory() { - return maskFactory; - } - - /** - * Get the pattern factory from which new {@link com.sk89q.worldedit.function.pattern.Pattern}s - * can be constructed. - * - * @return the pattern factory - */ - public PatternFactory getPatternFactory() { - return patternFactory; - } - - /** - * Return the session manager. - * - * @return the session manager - */ - public SessionManager getSessionManager() { - return sessions; - } - - /** - * Gets the path to a file. This method will check to see if the filename - * has valid characters and has an extension. It also prevents directory - * traversal exploits by checking the root directory and the file directory. - * On success, a {@code java.io.File} object will be returned. - * - * @param player the player - * @param dir sub-directory to look in - * @param filename filename (user-submitted) - * @param defaultExt append an extension if missing one, null to not use - * @param extensions list of extensions, null for any - * @return a file - * @throws FilenameException thrown if the filename is invalid - */ - public File getSafeSaveFile(Player player, File dir, String filename, String defaultExt, String... extensions) throws FilenameException { - return getSafeFile(player, dir, filename, defaultExt, extensions, true); - } - - /** - * Gets the path to a file. This method will check to see if the filename - * has valid characters and has an extension. It also prevents directory - * traversal exploits by checking the root directory and the file directory. - * On success, a {@code java.io.File} object will be returned. - * - * @param player the player - * @param dir sub-directory to look in - * @param filename filename (user-submitted) - * @param defaultExt append an extension if missing one, null to not use - * @param extensions list of extensions, null for any - * @return a file - * @throws FilenameException thrown if the filename is invalid - */ - public File getSafeOpenFile(Player player, File dir, String filename, String defaultExt, String... extensions) throws FilenameException { - return getSafeFile(player, dir, filename, defaultExt, extensions, false); - } - - /** - * Get a safe path to a file. - * - * @param player the player - * @param dir sub-directory to look in - * @param filename filename (user-submitted) - * @param defaultExt append an extension if missing one, null to not use - * @param extensions list of extensions, null for any - * @param isSave true if the purpose is for saving - * @return a file - * @throws FilenameException thrown if the filename is invalid - */ - private File getSafeFile(Player player, File dir, String filename, String defaultExt, String[] extensions, boolean isSave) throws FilenameException { - if (extensions != null && (extensions.length == 1 && extensions[0] == null)) extensions = null; - - File f; - - if (filename.equals("#")) { - if (isSave) { - f = player.openFileSaveDialog(extensions); - } else { - f = player.openFileOpenDialog(extensions); - } - - if (f == null) { - throw new FileSelectionAbortedException("No file selected"); - } - } else { - List exts = extensions == null ? ImmutableList.of(defaultExt) : Lists.asList(defaultExt, extensions); - return getSafeFileWithExtensions(dir, filename, exts, isSave); - } - - try { - String filePath = f.getCanonicalPath(); - String dirPath = dir.getCanonicalPath(); - - if (!filePath.substring(0, dirPath.length()).equals(dirPath) && !getConfiguration().allowSymlinks) { - throw new FilenameResolutionException(filename, - "Path is outside allowable root"); - } - - return f; - } catch (IOException e) { - throw new FilenameResolutionException(filename, - "Failed to resolve path"); - } - } - - private File getSafeFileWithExtensions(File dir, String filename, List exts, boolean isSave) throws InvalidFilenameException { - if (isSave) { - // First is default, only use that. - if (exts.size() != 1) { - exts = exts.subList(0, 1); - } - } - File result = null; - for (Iterator iter = exts.iterator(); iter.hasNext() && (result == null || !result.exists());) { - result = getSafeFileWithExtension(dir, filename, iter.next()); - } - if (result == null) { - throw new InvalidFilenameException(filename, "Invalid characters or extension missing"); - } - return result; - } - - private File getSafeFileWithExtension(File dir, String filename, String extension) { - if (extension != null && filename.lastIndexOf('.') == -1) { - filename += "." + extension; - } - - if (!checkFilename(filename)) { - return null; - } - - return new File(dir, filename); - } - - private boolean checkFilename(String filename) { - return filename.matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+\\.[A-Za-z0-9]+$"); - } - - /** - * Load the bundled mappings. - */ - public void loadMappings() { - BundledBlockData.getInstance(); // Load block registry - BundledItemData.getInstance(); // Load item registry - LegacyMapper.getInstance(); // Load item registry - } - - /** - * Checks to see if the specified radius is within bounds. - * - * @param radius the radius - * @throws MaxRadiusException - */ - public void checkMaxRadius(double radius) throws MaxRadiusException { - if (getConfiguration().maxRadius > 0 && radius > getConfiguration().maxRadius) { - throw new MaxRadiusException(); - } - } - - /** - * Checks to see if the specified brush radius is within bounds. - * - * @param radius the radius - * @throws MaxBrushRadiusException - */ - public void checkMaxBrushRadius(double radius) throws MaxBrushRadiusException { - if (getConfiguration().maxBrushRadius > 0 && radius > getConfiguration().maxBrushRadius) { - throw new MaxBrushRadiusException(); - } - } - - public void checkMaxBrushRadius(Expression radius) throws MaxBrushRadiusException { - if (getConfiguration().maxBrushRadius > 0) { - RValue r = radius.getRoot(); - if (r instanceof Constant && ((Constant) r).getValue() > getConfiguration().maxBrushRadius) { - throw new MaxBrushRadiusException(); - } - } - } - - /** - * Get a file relative to the defined working directory. If the specified - * path is absolute, then the working directory is not used. - * - * @param path the subpath under the working directory - * @return a working directory - */ - public File getWorkingDirectoryFile(String path) { - File f = new File(path); - if (f.isAbsolute()) { - return f; - } - - return new File(getConfiguration().getWorkingDirectory(), path); - } - - /** - * Get the direction vector for a player's direction. May return - * null if a direction could not be found. - * - * @param player the player - * @param dirStr the direction string - * @return a direction vector - * @throws UnknownDirectionException thrown if the direction is not known - */ - public BlockVector3 getDirection(Player player, String dirStr) throws UnknownDirectionException { - dirStr = dirStr.toLowerCase(); - - final Direction dir = getPlayerDirection(player, dirStr); - - if (dir.isUpright() || dir.isCardinal()) { - return dir.toBlockVector(); - } else { - throw new UnknownDirectionException(dir.name()); - } - } - - /** - * Get the direction vector for a player's direction. May return - * null if a direction could not be found. - * - * @param player the player - * @param dirStr the direction string - * @return a direction vector - * @throws UnknownDirectionException thrown if the direction is not known - */ - public BlockVector3 getDiagonalDirection(Player player, String dirStr) throws UnknownDirectionException { - dirStr = dirStr.toLowerCase(); - - final Direction dir = getPlayerDirection(player, dirStr); - - if (dir.isCardinal() || dir.isOrdinal() || dir.isUpright()) { - return dir.toBlockVector(); - } - - throw new UnknownDirectionException(dir.name()); - } - - /** - * Get the direction vector for a player's direction. May return - * null if a direction could not be found. - * - * @param player the player - * @param dirStr the direction string - * @return a direction enum value - * @throws UnknownDirectionException thrown if the direction is not known - */ - private Direction getPlayerDirection(Player player, String dirStr) throws UnknownDirectionException { - final Direction dir; - - switch (dirStr.charAt(0)) { - case 'w': - dir = Direction.WEST; - break; - - case 'e': - dir = Direction.EAST; - break; - - case 's': - if (dirStr.indexOf('w') > 0) { - return Direction.SOUTHWEST; - } - - if (dirStr.indexOf('e') > 0) { - return Direction.SOUTHEAST; - } - dir = Direction.SOUTH; - break; - - case 'n': - if (dirStr.indexOf('w') > 0) { - return Direction.NORTHWEST; - } - - if (dirStr.indexOf('e') > 0) { - return Direction.NORTHEAST; - } - dir = Direction.NORTH; - break; - - case 'u': - dir = Direction.UP; - break; - - case 'd': - dir = Direction.DOWN; - break; - - case 'm': // me - case 'f': // forward - dir = player.getCardinalDirection(0); - break; - - case 'b': // back - dir = player.getCardinalDirection(180); - break; - - case 'l': // left - dir = player.getCardinalDirection(-90); - break; - - case 'r': // right - dir = player.getCardinalDirection(90); - break; - - default: - throw new UnknownDirectionException(dirStr); - } - return dir; - } - - - /** - * Flush a block bag's changes to a player. - * - * @param actor the actor - * @param editSession the edit session - */ - public void flushBlockBag(Actor actor, EditSession editSession) { - BlockBag blockBag = editSession.getBlockBag(); - - if (blockBag != null) { - blockBag.flushChanges(); - } - - Map missingBlocks = editSession.popMissingBlocks(); - - if (!missingBlocks.isEmpty()) { - StringBuilder str = new StringBuilder(); - str.append("Missing these blocks: "); - int size = missingBlocks.size(); - int i = 0; - - for (Map.Entry blockTypeIntegerEntry : missingBlocks.entrySet()) { - str.append((blockTypeIntegerEntry.getKey()).getName()); - - str.append(" [Amt: ").append(blockTypeIntegerEntry.getValue()).append("]"); - - ++i; - - if (i != size) { - str.append(", "); - } - } - - actor.printError(str.toString()); - } - } - - /** - * Called on arm swing. - * - * @param player the player - * @return true if the swing was handled - */ - public boolean handleArmSwing(Player player) { - PlayerInputEvent event = new PlayerInputEvent(player, InputType.PRIMARY); - getEventBus().post(event); - return event.isCancelled(); - } - - /** - * Called on right click (not on a block). - * - * @param player the player - * @return true if the right click was handled - */ - public boolean handleRightClick(Player player) { - PlayerInputEvent event = new PlayerInputEvent(player, InputType.SECONDARY); - getEventBus().post(event); - return event.isCancelled(); - } - - /** - * Called on right click. - * - * @param player the player - * @param clicked the clicked block - * @return false if you want the action to go through - */ - public boolean handleBlockRightClick(Player player, Location clicked) { - BlockInteractEvent event = new BlockInteractEvent(player, clicked, OPEN); - getEventBus().post(event); - return event.isCancelled(); - } - - /** - * Called on left click. - * - * @param player the player - * @param clicked the clicked block - * @return false if you want the action to go through - */ - public boolean handleBlockLeftClick(Player player, Location clicked) { - BlockInteractEvent event = new BlockInteractEvent(player, clicked, HIT); - getEventBus().post(event); - return event.isCancelled(); - } - - /** - * Executes a WorldEdit script. - * - * @param player the player - * @param f the script file to execute - * @param args arguments for the script - * @throws WorldEditException - */ - public void runScript(Player player, File f, String[] args) throws WorldEditException { - Request.reset(); - - String filename = f.getPath(); - int index = filename.lastIndexOf('.'); - String ext = filename.substring(index + 1); - - if (!ext.equalsIgnoreCase("js")) { - player.printError("Only .js scripts are currently supported"); - return; - } - - String script; - - try { - InputStream file; - - if (!f.exists()) { - file = WorldEdit.class.getResourceAsStream("craftscripts/" + filename); - - if (file == null) { - player.printError("Script does not exist: " + filename); - return; - } - } else { - file = new FileInputStream(f); - } - - DataInputStream in = new DataInputStream(file); - byte[] data = new byte[in.available()]; - in.readFully(data); - in.close(); - script = new String(data, 0, data.length, "utf-8"); - } catch (IOException e) { - player.printError("Script read error: " + e.getMessage()); - return; - } - - LocalSession session = getSessionManager().get(player); - CraftScriptContext scriptContext = new CraftScriptContext(this, getPlatformManager().queryCapability(Capability.USER_COMMANDS), - getConfiguration(), session, player, args); - - CraftScriptEngine engine; - - try { - engine = new RhinoCraftScriptEngine(); - } catch (NoClassDefFoundError e) { - player.printError("Failed to find an installed script engine."); - player.printError("Please see http://wiki.sk89q.com/wiki/WorldEdit/Installation"); - return; - } - - engine.setTimeLimit(getConfiguration().scriptTimeout); - - Map vars = new HashMap<>(); - vars.put("argv", args); - vars.put("context", scriptContext); - vars.put("player", player); - - try { - engine.evaluate(script, filename, vars); - } catch (ScriptException e) { - player.printError("Failed to execute:"); - player.printRaw(e.getMessage()); - logger.log(Level.WARNING, "Failed to execute script", e); - } catch (NumberFormatException | WorldEditException e) { - throw e; - } catch (Throwable e) { - player.printError("Failed to execute (see console):"); - player.printRaw(e.getClass().getCanonicalName()); - logger.log(Level.WARNING, "Failed to execute script", e); - } finally { - for (EditSession editSession : scriptContext.getEditSessions()) { - editSession.flushQueue(); - session.remember(editSession); - } - } - } - - /** - * Get Worldedit's configuration. - * - * @return a configuration - */ - public LocalConfiguration getConfiguration() { - return getPlatformManager().getConfiguration(); - } - - /** - * Get a factory for {@link EditSession}s. - */ - public EditSessionFactory getEditSessionFactory() { - return editSessionFactory; - } - - /** - * Get the version. - * - * @return the version of WorldEdit - */ - public static String getVersion() { - if (version != null) { - return version; - } - - Package p = WorldEdit.class.getPackage(); - - if (p == null) { - p = Package.getPackage("com.sk89q.worldedit"); - } - - if (p == null) { - version = "(unknown)"; - } else { - version = p.getImplementationVersion(); - - if (version == null) { - version = "(unknown)"; - } - } - - return version; - } - -} \ No newline at end of file + + /** + * Get the block factory from which new {@link BlockStateHolder}s can be + * constructed. + * + * @return the block factory + */ + public BlockFactory getBlockFactory() { + return blockFactory; + } + + /** + * Get the item factory from which new {@link BaseItem}s can be + * constructed. + * + * @return the item factory + */ + public ItemFactory getItemFactory() { + return itemFactory; + } + + /** + * Get the mask factory from which new {@link Mask}s + * can be constructed. + * + * @return the mask factory + */ + public MaskFactory getMaskFactory() { + return maskFactory; + } + + /** + * Get the pattern factory from which new {@link Pattern}s + * can be constructed. + * + * @return the pattern factory + */ + public PatternFactory getPatternFactory() { + return patternFactory; + } + + /** + * Return the session manager. + * + * @return the session manager + */ + public SessionManager getSessionManager() { + return sessions; + } + + /** + * Gets the path to a file. This method will check to see if the filename + * has valid characters and has an extension. It also prevents directory + * traversal exploits by checking the root directory and the file directory. + * On success, a {@code java.io.File} object will be returned. + * + * @param player the player + * @param dir sub-directory to look in + * @param filename filename (user-submitted) + * @param defaultExt append an extension if missing one, null to not use + * @param extensions list of extensions, null for any + * @return a file + * @throws FilenameException thrown if the filename is invalid + */ + public File getSafeSaveFile(Player player, File dir, String filename, String defaultExt, String... extensions) throws FilenameException { + return getSafeFile(player, dir, filename, defaultExt, extensions, true); + } + + /** + * Gets the path to a file. This method will check to see if the filename + * has valid characters and has an extension. It also prevents directory + * traversal exploits by checking the root directory and the file directory. + * On success, a {@code java.io.File} object will be returned. + * + * @param player the player + * @param dir sub-directory to look in + * @param filename filename (user-submitted) + * @param defaultExt append an extension if missing one, null to not use + * @param extensions list of extensions, null for any + * @return a file + * @throws FilenameException thrown if the filename is invalid + */ + public File getSafeOpenFile(Player player, File dir, String filename, String defaultExt, String... extensions) throws FilenameException { + return getSafeFile(player, dir, filename, defaultExt, extensions, false); + } + + /** + * Get a safe path to a file. + * + * @param player the player + * @param dir sub-directory to look in + * @param filename filename (user-submitted) + * @param defaultExt append an extension if missing one, null to not use + * @param extensions list of extensions, null for any + * @param isSave true if the purpose is for saving + * @return a file + * @throws FilenameException thrown if the filename is invalid + */ + private File getSafeFile(@Nullable Player player, File dir, String filename, String defaultExt, String[] extensions, boolean isSave) throws FilenameException { + if (extensions != null && (extensions.length == 1 && extensions[0] == null)) extensions = null; + + File f; + + if (filename.equals("#") && player != null) { + if (isSave) { + f = player.openFileSaveDialog(extensions); + } else { + f = player.openFileOpenDialog(extensions); + } + + if (f == null) { + throw new FileSelectionAbortedException("No file selected"); + } + } else { + List exts = extensions == null ? ImmutableList.of(defaultExt) : Lists.asList(defaultExt, extensions); + f = getSafeFileWithExtensions(dir, filename, exts, isSave); + } + + try { + Path filePath = Paths.get(f.toURI()).normalize(); + Path dirPath = Paths.get(dir.toURI()).normalize(); + + boolean inDir = filePath.startsWith(dirPath); + Path existingParent = filePath; + do { + existingParent = existingParent.getParent(); + } while (existingParent != null && !existingParent.toFile().exists()); + + boolean isSym = existingParent != null && !existingParent.toRealPath().equals(existingParent); + if (!inDir || (!getConfiguration().allowSymlinks && isSym)) { + throw new FilenameResolutionException(filename, "Path is outside allowable root"); + } + + return filePath.toFile(); + } catch (IOException e) { + throw new FilenameResolutionException(filename, "Failed to resolve path"); + } + } + + private File getSafeFileWithExtensions(File dir, String filename, List exts, boolean isSave) throws InvalidFilenameException { + if (isSave) { + // First is default, only use that. + if (exts.size() != 1) { + exts = exts.subList(0, 1); + } + } + File result = null; + for (Iterator iter = exts.iterator(); iter.hasNext() && (result == null || (!isSave && !result.exists()));) { + result = getSafeFileWithExtension(dir, filename, iter.next()); + } + if (result == null) { + throw new InvalidFilenameException(filename, "Invalid characters or extension missing"); + } + return result; + } + + private File getSafeFileWithExtension(File dir, String filename, String extension) { + if (extension != null) { + int dot = filename.lastIndexOf('.'); + if (dot < 0 || !filename.substring(dot).equalsIgnoreCase(extension)) { + filename += "." + extension; + } + } + + if (!checkFilename(filename)) { + return null; + } + + return new File(dir, filename); + } + + private boolean checkFilename(String filename) { + return filename.matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+\\.[A-Za-z0-9]+$"); + } + + /** + * Load the bundled mappings. + */ + public void loadMappings() { + BundledBlockData.getInstance(); // Load block registry + BundledItemData.getInstance(); // Load item registry + LegacyMapper.getInstance(); // Load item registry + } + + /** + * Checks to see if the specified radius is within bounds. + * + * @param radius the radius + * @throws MaxRadiusException + */ + public void checkMaxRadius(double radius) throws MaxRadiusException { + if (getConfiguration().maxRadius > 0 && radius > getConfiguration().maxRadius) { + throw new MaxRadiusException(); + } + } + + /** + * Checks to see if the specified brush radius is within bounds. + * + * @param radius the radius + * @throws MaxBrushRadiusException + */ + public void checkMaxBrushRadius(double radius) throws MaxBrushRadiusException { + if (getConfiguration().maxBrushRadius > 0 && radius > getConfiguration().maxBrushRadius) { + throw new MaxBrushRadiusException(); + } + } + + public void checkMaxBrushRadius(Expression radius) throws MaxBrushRadiusException { + if (getConfiguration().maxBrushRadius > 0) { + RValue r = radius.getRoot(); + if (r instanceof Constant && ((Constant) r).getValue() > getConfiguration().maxBrushRadius) { + throw new MaxBrushRadiusException(); + } + } + } + + /** + * Get a file relative to the defined working directory. If the specified + * path is absolute, then the working directory is not used. + * + * @param path the subpath under the working directory + * @return a working directory + */ + public File getWorkingDirectoryFile(String path) { + File f = new File(path); + if (f.isAbsolute()) { + return f; + } + + return new File(getConfiguration().getWorkingDirectory(), path); + } + + /** + * Get the direction vector for a player's direction. May return + * null if a direction could not be found. + * + * @param player the player + * @param dirStr the direction string + * @return a direction vector + * @throws UnknownDirectionException thrown if the direction is not known + */ + public BlockVector3 getDirection(Player player, String dirStr) throws UnknownDirectionException { + dirStr = dirStr.toLowerCase(); + + final Direction dir = getPlayerDirection(player, dirStr); + + if (dir.isUpright() || dir.isCardinal()) { + return dir.toBlockVector(); + } else { + throw new UnknownDirectionException(dir.name()); + } + } + + /** + * Get the direction vector for a player's direction. May return + * null if a direction could not be found. + * + * @param player the player + * @param dirStr the direction string + * @return a direction vector + * @throws UnknownDirectionException thrown if the direction is not known + */ + public BlockVector3 getDiagonalDirection(Player player, String dirStr) throws UnknownDirectionException { + dirStr = dirStr.toLowerCase(); + + final Direction dir = getPlayerDirection(player, dirStr); + + if (dir.isCardinal() || dir.isOrdinal() || dir.isUpright()) { + return dir.toBlockVector(); + } + + throw new UnknownDirectionException(dir.name()); + } + + /** + * Get the direction vector for a player's direction. May return + * null if a direction could not be found. + * + * @param player the player + * @param dirStr the direction string + * @return a direction enum value + * @throws UnknownDirectionException thrown if the direction is not known + */ + private Direction getPlayerDirection(Player player, String dirStr) throws UnknownDirectionException { + final Direction dir; + + switch (dirStr.charAt(0)) { + case 'w': + dir = Direction.WEST; + break; + + case 'e': + dir = Direction.EAST; + break; + + case 's': + if (dirStr.indexOf('w') > 0) { + return Direction.SOUTHWEST; + } + + if (dirStr.indexOf('e') > 0) { + return Direction.SOUTHEAST; + } + dir = Direction.SOUTH; + break; + + case 'n': + if (dirStr.indexOf('w') > 0) { + return Direction.NORTHWEST; + } + + if (dirStr.indexOf('e') > 0) { + return Direction.NORTHEAST; + } + dir = Direction.NORTH; + break; + + case 'u': + dir = Direction.UP; + break; + + case 'd': + dir = Direction.DOWN; + break; + + case 'm': // me + case 'f': // forward + dir = player.getCardinalDirection(0); + break; + + case 'b': // back + dir = player.getCardinalDirection(180); + break; + + case 'l': // left + dir = player.getCardinalDirection(-90); + break; + + case 'r': // right + dir = player.getCardinalDirection(90); + break; + + default: + throw new UnknownDirectionException(dirStr); + } + return dir; + } + + /** + * Flush a block bag's changes to a player. + * + * @param actor the actor + * @param editSession the edit session + */ + public void flushBlockBag(Actor actor, EditSession editSession) { + BlockBag blockBag = editSession.getBlockBag(); + + if (blockBag != null) { + blockBag.flushChanges(); + } + + Map missingBlocks = editSession.popMissingBlocks(); + + if (!missingBlocks.isEmpty()) { + StringBuilder str = new StringBuilder(); + str.append("Missing these blocks: "); + int size = missingBlocks.size(); + int i = 0; + + for (Map.Entry blockTypeIntegerEntry : missingBlocks.entrySet()) { + str.append((blockTypeIntegerEntry.getKey()).getName()); + + str.append(" [Amt: ").append(blockTypeIntegerEntry.getValue()).append("]"); + + ++i; + + if (i != size) { + str.append(", "); + } + } + + actor.printError(str.toString()); + } + } + + /** + * Called on arm swing. + * + * @param player the player + * @return true if the swing was handled + */ + public boolean handleArmSwing(Player player) { + PlayerInputEvent event = new PlayerInputEvent(player, InputType.PRIMARY); + getEventBus().post(event); + return event.isCancelled(); + } + + /** + * Called on right click (not on a block). + * + * @param player the player + * @return true if the right click was handled + */ + public boolean handleRightClick(Player player) { + PlayerInputEvent event = new PlayerInputEvent(player, InputType.SECONDARY); + getEventBus().post(event); + return event.isCancelled(); + } + + /** + * Called on right click. + * + * @param player the player + * @param clicked the clicked block + * @return false if you want the action to go through + */ + public boolean handleBlockRightClick(Player player, Location clicked) { + BlockInteractEvent event = new BlockInteractEvent(player, clicked, OPEN); + getEventBus().post(event); + return event.isCancelled(); + } + + /** + * Called on left click. + * + * @param player the player + * @param clicked the clicked block + * @return false if you want the action to go through + */ + public boolean handleBlockLeftClick(Player player, Location clicked) { + BlockInteractEvent event = new BlockInteractEvent(player, clicked, HIT); + getEventBus().post(event); + return event.isCancelled(); + } + + /** + * Executes a WorldEdit script. + * + * @param player the player + * @param f the script file to execute + * @param args arguments for the script + * @throws WorldEditException + */ + public void runScript(Player player, File f, String[] args) throws WorldEditException { + String filename = f.getPath(); + int index = filename.lastIndexOf('.'); + String ext = filename.substring(index + 1); + + if (!ext.equalsIgnoreCase("js")) { + player.printError("Only .js scripts are currently supported"); + return; + } + + String script; + + try { + InputStream file; + + if (!f.exists()) { + file = WorldEdit.class.getResourceAsStream("craftscripts/" + filename); + + if (file == null) { + player.printError("Script does not exist: " + filename); + return; + } + } else { + file = new FileInputStream(f); + } + + DataInputStream in = new DataInputStream(file); + byte[] data = new byte[in.available()]; + in.readFully(data); + in.close(); + script = new String(data, 0, data.length, StandardCharsets.UTF_8); + } catch (IOException e) { + player.printError("Script read error: " + e.getMessage()); + return; + } + + LocalSession session = getSessionManager().get(player); + CraftScriptContext scriptContext = new CraftScriptContext(this, getPlatformManager().queryCapability(Capability.USER_COMMANDS), + getConfiguration(), session, player, args); + + CraftScriptEngine engine; + + try { + engine = new RhinoCraftScriptEngine(); + } catch (NoClassDefFoundError e) { + player.printError("Failed to find an installed script engine."); + player.printError("Please see http://wiki.sk89q.com/wiki/WorldEdit/Installation"); + return; + } + + engine.setTimeLimit(getConfiguration().scriptTimeout); + + Map vars = new HashMap<>(); + vars.put("argv", args); + vars.put("context", scriptContext); + vars.put("player", player); + + try { + engine.evaluate(script, filename, vars); + } catch (ScriptException e) { + player.printError("Failed to execute:"); + player.printRaw(e.getMessage()); + logger.log(Level.WARNING, "Failed to execute script", e); + } catch (NumberFormatException | WorldEditException e) { + throw e; + } catch (Throwable e) { + player.printError("Failed to execute (see console):"); + player.printRaw(e.getClass().getCanonicalName()); + logger.log(Level.WARNING, "Failed to execute script", e); + } finally { + for (EditSession editSession : scriptContext.getEditSessions()) { + editSession.flushQueue(); + session.remember(editSession); + } + } + } + + /** + * Get Worldedit's configuration. + * + * @return a configuration + */ + public LocalConfiguration getConfiguration() { + return getPlatformManager().getConfiguration(); + } + + /** + * Get a factory for {@link EditSession}s. + */ + public EditSessionFactory getEditSessionFactory() { + return editSessionFactory; + } + + /** + * Get the version. + * + * @return the version of WorldEdit + */ + public static String getVersion() { + if (version != null) { + return version; + } + + Package p = WorldEdit.class.getPackage(); + + if (p == null) { + p = Package.getPackage("com.sk89q.worldedit"); + } + + if (p == null) { + version = "(unknown)"; + } else { + version = p.getImplementationVersion(); + + if (version == null) { + version = "(unknown)"; + } + } + + return version; + } + +} 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 cee597288..9e952c00b 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 @@ -185,7 +185,7 @@ public class BiomeCommands extends MethodCommands { for (int i = 0; i < biomes.length; i++) { int count = biomes[i]; if (count != 0) { - distribution.add(new Countable(new BaseBiome(i), count)); + distribution.add(new Countable<>(new BaseBiome(i), count)); } } Collections.sort(distribution); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HelpBuilder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HelpBuilder.java index 11f87e904..0947bcb3b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HelpBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HelpBuilder.java @@ -51,14 +51,14 @@ public abstract class HelpBuilder implements Runnable { } boolean isRootLevel = true; - List visited = new ArrayList(); + List visited = new ArrayList<>(); // Create the message if (callable instanceof Dispatcher) { Dispatcher dispatcher = (Dispatcher) callable; // Get a list of aliases - List aliases = new ArrayList(dispatcher.getCommands()); + List aliases = new ArrayList<>(dispatcher.getCommands()); List prefixes = Collections.nCopies(aliases.size(), ""); // Group by callable @@ -174,7 +174,7 @@ public abstract class HelpBuilder implements Runnable { return; } dispatcher = (Dispatcher) callable; - aliases = new ArrayList(dispatcher.getCommands()); + aliases = new ArrayList<>(dispatcher.getCommands()); prefixes = Collections.nCopies(aliases.size(), ""); } else { aliases = new ArrayList<>(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java index a4ad5779b..29fb1b916 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java @@ -139,7 +139,7 @@ public class ScriptingCommands { engine.setTimeLimit(worldEdit.getConfiguration().scriptTimeout); - Map vars = new HashMap(); + Map vars = new HashMap<>(); vars.put("argv", args); vars.put("actor", actor); 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 a3a76808a..61f007404 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 @@ -556,7 +556,7 @@ public class UtilityCommands extends MethodCommands { CreatureButcher flags = new CreatureButcher(actor); flags.fromCommand(args); - List visitors = new ArrayList(); + List visitors = new ArrayList<>(); LocalSession session = null; EditSession editSession = null; @@ -616,7 +616,7 @@ public class UtilityCommands extends MethodCommands { EntityRemover remover = new EntityRemover(); remover.fromString(typeStr); - List visitors = new ArrayList(); + List visitors = new ArrayList<>(); LocalSession session = null; EditSession editSession = null; 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 e89d5c4ac..3387a107a 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 @@ -73,8 +73,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(); @@ -230,7 +230,7 @@ public class PlatformManager { * @return a list of platforms */ public synchronized List getPlatforms() { - return new ArrayList(platforms); + return new ArrayList<>(platforms); } /** @@ -566,4 +566,4 @@ public class PlatformManager { -} \ No newline at end of file +} 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 4b735c7b5..c6213806f 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 @@ -143,7 +143,7 @@ public interface ClipboardFormat { default URL uploadPublic(final Clipboard clipboard, String category, String user) { // summary // blocks - HashMap map = new HashMap(); + HashMap map = new HashMap<>(); BlockVector3 dimensions = clipboard.getDimensions(); map.put("width", dimensions.getX()); map.put("height", dimensions.getY()); @@ -179,4 +179,4 @@ public interface ClipboardFormat { e.printStackTrace(); } } -} \ No newline at end of file +} 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 b998aaceb..9321ec5cd 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 @@ -185,7 +185,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/MaskUnion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java index 5d4fe065b..a3ac57a03 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 @@ -72,7 +72,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/internal/expression/Expression.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Expression.java index 41cb27134..17460fc1f 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 @@ -69,7 +69,7 @@ public class Expression { private static final ThreadLocal> instance = ThreadLocal.withInitial(ArrayDeque::new); - private final Map variables = new HashMap(); + private final Map variables = new HashMap<>(); private final String[] variableNames; private Variable[] variableArray; private RValue root; 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 ed9b6ef82..088cef4c2 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 @@ -124,7 +124,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()) { @@ -143,7 +143,7 @@ public final class Functions { List overloads = functions.get(methodName); if (overloads == null) { - functions.put(methodName, overloads = new ArrayList()); + functions.put(methodName, overloads = new ArrayList<>()); } overloads.add(overload); @@ -281,8 +281,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; 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 68791a33b..92242baa0 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 @@ -191,7 +191,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()); 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 14adfc8e7..c98a118c0 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 @@ -260,7 +260,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); @@ -318,4 +318,4 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { } -} \ No newline at end of file +} 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 3dfd75738..afe54c996 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 @@ -241,7 +241,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(Vector3.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 3019f7c6b..31b7d5077 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 @@ -199,7 +199,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion { @Override public List getInformationLines() { - final List lines = new ArrayList(); + final List lines = new ArrayList<>(); final Vector3 center = region.getCenter(); if (center.lengthSq() > 0) { 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 421602563..ee89574d9 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(); /** @@ -82,7 +82,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 @@ -92,7 +92,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()); } @@ -151,7 +151,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)) { @@ -188,4 +188,4 @@ public class SimpleDispatcher implements Dispatcher { // Checking every perm in the class here was unnecessarily stupid return true; } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/AParametricCallable.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/AParametricCallable.java index a8c9a408e..3d6e13013 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/AParametricCallable.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/AParametricCallable.java @@ -171,7 +171,7 @@ public abstract class AParametricCallable 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/command/parametric/FunctionParametricCallable.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/FunctionParametricCallable.java index 4ab9de23f..2e77631ff 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/FunctionParametricCallable.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/FunctionParametricCallable.java @@ -15,9 +15,9 @@ public class FunctionParametricCallable extends AParametricCallable { private final ParametricBuilder builder; 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 String permission; private final Command command; @@ -81,7 +81,7 @@ public class FunctionParametricCallable extends AParametricCallable { } parameters = new ParameterData[paramParsables.size()]; - List userParameters = new ArrayList(); + List userParameters = new ArrayList<>(); // This helps keep tracks of @Nullables that appear in the middle of a list // of parameters @@ -325,4 +325,4 @@ public class FunctionParametricCallable extends AParametricCallable { public String toString() { return command.aliases()[0]; } -} \ No newline at end of file +} 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 918bff40d..1bc62aa31 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 @@ -65,10 +65,10 @@ 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 FaweParanamer(); - private final List invokeListeners = new ArrayList(); - private final List exceptionConverters = new ArrayList(); + private final List invokeListeners = new ArrayList<>(); + private final List exceptionConverters = 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 a8ad5ab1b..e2b90f6c0 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 @@ -55,9 +55,9 @@ public class ParametricCallable extends AParametricCallable { 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; private final Command definition; @@ -81,7 +81,7 @@ public class ParametricCallable extends AParametricCallable { 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 @@ -221,7 +221,7 @@ public class ParametricCallable extends AParametricCallable { try { // preProcess handlers - List handlers = new ArrayList(); + List handlers = new ArrayList<>(); for (InvokeListener listener : builder.getInvokeListeners()) { InvokeHandler handler = listener.createInvokeHandler(); handlers.add(handler); @@ -361,4 +361,4 @@ public class ParametricCallable extends AParametricCallable { } -} \ No newline at end of file +} 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 80747ab15..e4935cb16 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 @@ -73,7 +73,7 @@ public class CommandUsageBox extends StyledFragment { CommandListBox box = new CommandListBox(BBC.HELP_HEADER_SUBCOMMANDS.f()); String prefix = !commandString.isEmpty() ? commandString + " " : ""; - List list = new ArrayList(dispatcher.getCommands()); + List list = new ArrayList<>(dispatcher.getCommands()); Collections.sort(list, new PrimaryAliasComparator(CommandManager.COMMAND_CLEAN_PATTERN)); for (CommandMapping mapping : list) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/task/progress/ProgressIterator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/task/progress/ProgressIterator.java index 11eb34f32..447838922 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/task/progress/ProgressIterator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/task/progress/ProgressIterator.java @@ -83,7 +83,7 @@ public class ProgressIterator implements Iterator, ProgressObservable { * @return an instance */ public static ProgressIterator create(Iterator iterator, int count) { - return new ProgressIterator(iterator, count); + return new ProgressIterator<>(iterator, count); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java index 2a27cb699..b87acf092 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java @@ -81,7 +81,8 @@ public class BlockType implements FawePattern { public ArrayList updateStates(){ if(settings != null) { - return settings.localStates = new ArrayList(settings.localStates.stream().map(state -> new BlockStateImpl(this, state.getInternalId(), state.getOrdinal())).collect(Collectors.toList())); + return settings.localStates = new ArrayList<>(settings.localStates.stream() + .map(state -> new BlockStateImpl(this, state.getInternalId(), state.getOrdinal())).collect(Collectors.toList())); }else { return null; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java index adf5dcaf1..03027b552 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java @@ -676,9 +676,9 @@ public class BlockTypes{ public static BlockType register(BlockType type) { if(sortedRegistry == null) { - sortedRegistry = new ArrayList(); - stateList = new ArrayList(); - $NAMESPACES = new LinkedHashSet(); + sortedRegistry = new ArrayList<>(); + stateList = new ArrayList<>(); + $NAMESPACES = new LinkedHashSet<>(); BIT_OFFSET = MathMan.log2nlz(WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().registerBlocks().size()); BIT_MASK = ((1 << BIT_OFFSET) - 1); } @@ -775,7 +775,7 @@ public class BlockTypes{ this.propertiesSet = Collections.emptySet(); } this.permutations = maxInternalStateId; - this.localStates = new ArrayList(); + this.localStates = new ArrayList<>(); this.blockMaterial = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getMaterial(type); this.itemType = ItemTypes.get(type); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java index c35e95541..3f90c6cc3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java @@ -838,7 +838,7 @@ public final class ItemTypes { public static ItemType register(final ItemType item) { if(sortedRegistry == null) - sortedRegistry = new ArrayList(); + sortedRegistry = new ArrayList<>(); if(!sortedRegistry.contains(item))sortedRegistry.add(item); // return ItemType.REGISTRY.register(item.getId(), item); return internalRegister(item); diff --git a/worldedit-core/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java b/worldedit-core/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java index bcdf19dd2..025981e6e 100644 --- a/worldedit-core/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java +++ b/worldedit-core/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java @@ -38,7 +38,7 @@ public class CommandContextTest { @Before public void setUpTest() { try { - firstCommand = new CommandContext(firstCmdString, new HashSet(Arrays.asList('o', 'w'))); + firstCommand = new CommandContext(firstCmdString, new HashSet<>(Arrays.asList('o', 'w'))); } catch (CommandException e) { log.log(Level.WARNING, "Error", e); fail("Unexpected exception when creating CommandContext"); @@ -48,7 +48,7 @@ public class CommandContextTest { @Test(expected = CommandException.class) public void testInvalidFlags() throws CommandException { final String failingCommand = "herpderp -opw testers"; - new CommandContext(failingCommand, new HashSet(Arrays.asList('o', 'w'))); + new CommandContext(failingCommand, new HashSet<>(Arrays.asList('o', 'w'))); } @Test