From 8cd46977f3fd9b544b6134e186646d33da76cd19 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Mon, 28 Dec 2015 12:05:16 -0800 Subject: [PATCH 01/14] Add paging to //schematics. -p can be used to select a page. Defaults to page 1. First implementation by @BangL. --- .../worldedit/command/SchematicCommands.java | 68 +++++++++++++++---- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index 817be6368..74e538ea9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -24,8 +24,6 @@ import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.util.io.file.FilenameException; -import com.sk89q.worldedit.util.io.file.FilenameResolutionException; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; @@ -40,8 +38,11 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.session.ClipboardHolder; -import com.sk89q.worldedit.util.io.Closer; +import com.sk89q.worldedit.util.command.binding.Switch; import com.sk89q.worldedit.util.command.parametric.Optional; +import com.sk89q.worldedit.util.io.Closer; +import com.sk89q.worldedit.util.io.file.FilenameException; +import com.sk89q.worldedit.util.io.file.FilenameResolutionException; import com.sk89q.worldedit.world.registry.WorldData; import java.io.BufferedInputStream; @@ -51,8 +52,10 @@ import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -63,6 +66,10 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class SchematicCommands { + /** + * 9 schematics per page fits in the MC chat window. + */ + private static final int SCHEMATICS_PER_PAGE = 9; private static final Logger log = Logger.getLogger(SchematicCommands.class.getCanonicalName()); private final WorldEdit worldEdit; @@ -244,14 +251,16 @@ public class SchematicCommands { @Command( aliases = {"list", "all", "ls"}, desc = "List saved schematics", - max = 0, - flags = "dn", + min = 0, + max = 1, + flags = "dnp", help = "List all schematics in the schematics directory\n" + " -d sorts by date, oldest first\n" + - " -n sorts by date, newest first\n" + " -n sorts by date, newest first\n" + + " -p prints the requested page\n" ) @CommandPermissions("worldedit.schematic.list") - public void list(Actor actor, CommandContext args) throws WorldEditException { + public void list(Actor actor, CommandContext args, @Switch('p') @Optional("1") int page) throws WorldEditException { File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().saveDir); File[] files = dir.listFiles(new FileFilter(){ @Override @@ -265,6 +274,21 @@ public class SchematicCommands { if (files == null) { throw new FilenameResolutionException(dir.getPath(), "Schematics directory invalid or not found."); } + + if (files.length == 0) { + actor.printError("No schematics found."); + return; + } + + int pageCount = files.length / SCHEMATICS_PER_PAGE + 1; + if (page < 1) { + actor.printError("Page must be at least 1"); + return; + } + if (page > pageCount) { + actor.printError("Page must be less than " + (pageCount + 1)); + return; + } final int sortType = args.hasFlag('d') ? -1 : args.hasFlag('n') ? 1 : 0; // cleanup file list @@ -283,13 +307,23 @@ public class SchematicCommands { } }); - actor.print("Available schematics (Filename (Format)):"); - actor.print(listFiles("", files)); + List schematics = listFiles("", files); + int offset = (page - 1) * SCHEMATICS_PER_PAGE; + + actor.print("Available schematics (Filename: Format) [" + page + "/" + pageCount + "]:"); + StringBuilder build = new StringBuilder(); + int limit = Math.min(offset + SCHEMATICS_PER_PAGE, schematics.size()); + for (int i = offset; i < limit; i++) { + build.append(schematics.get(i)); + } + + actor.print(build.toString()); } - private String listFiles(String prefix, File[] files) { - StringBuilder build = new StringBuilder(); + private List listFiles(String prefix, File[] files) { + List result = new ArrayList(); for (File file : files) { + StringBuilder build = new StringBuilder(); if (file.isDirectory()) { build.append(listFiles(prefix + file.getName() + "/", file.listFiles())); continue; @@ -299,10 +333,16 @@ public class SchematicCommands { continue; } - build.append("\n\u00a79"); + if (!result.isEmpty()) { // prevent an empty line + build.append('\n'); + } + build.append("\u00a79"); ClipboardFormat format = ClipboardFormat.findByFile(file); - build.append(prefix).append(file.getName()).append(": ").append(format == null ? "Unknown" : format.name()); + build.append(prefix).append(file.getName()) + .append(": ").append(format == null ? "Unknown" : format.name()); + + result.add(build.toString()); } - return build.toString(); + return result; } } From 2cd4412b5dc351ec70e4b1b49d1657ce930a98d5 Mon Sep 17 00:00:00 2001 From: wizjany Date: Wed, 13 Jan 2016 17:34:58 -0500 Subject: [PATCH 02/14] Make mask parser create world-aware expression masks. This allows things like //gmask =queryRel(...) to work. Also the query* functions now allow -1 as a wildcard for either id or data. --- .../worldedit/extension/factory/DefaultMaskParser.java | 8 +++++++- .../worldedit/internal/expression/runtime/Functions.java | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java index fa2cdf163..88d4b53ac 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java @@ -37,9 +37,11 @@ import com.sk89q.worldedit.function.mask.NoiseFilter; import com.sk89q.worldedit.function.mask.OffsetMask; import com.sk89q.worldedit.function.mask.RegionMask; import com.sk89q.worldedit.function.mask.SolidBlockMask; +import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.math.noise.RandomNoise; +import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment; import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.session.request.RequestSelection; import com.sk89q.worldedit.world.biome.BaseBiome; @@ -144,7 +146,11 @@ class DefaultMaskParser extends InputParser { case '=': try { - return new ExpressionMask(component.substring(1)); + Expression exp = Expression.compile(component.substring(1), "x", "y", "z"); + WorldEditExpressionEnvironment env = new WorldEditExpressionEnvironment( + Request.request().getEditSession(), Vector.ONE, Vector.ZERO); + exp.setEnvironment(env); + return new ExpressionMask(exp); } catch (ExpressionException e) { throw new InputParseException("Invalid expression: " + e.getMessage()); } 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 1a5981855..a9cf3b684 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 @@ -442,7 +442,9 @@ public final class Functions { private static double queryInternal(RValue type, RValue data, double typeId, double dataValue) throws EvaluationException { // Compare to input values and determine return value - final double ret = (typeId == type.getValue() && dataValue == data.getValue()) ? 1.0 : 0.0; + // -1 is a wildcard, always true + final double ret = ((type.getValue() == -1 || typeId == type.getValue()) + && (data.getValue() == -1 || dataValue == data.getValue())) ? 1.0 : 0.0; if (type instanceof LValue) { ((LValue) type).assign(typeId); From 62befe7594987d070fd7c5b5d3d9fc882d4fdd2e Mon Sep 17 00:00:00 2001 From: wizjany Date: Wed, 13 Jan 2016 18:55:49 -0500 Subject: [PATCH 03/14] Fix schematics in directories. --- .../worldedit/command/SchematicCommands.java | 84 ++++++++++--------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index 74e538ea9..9bc9de49d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -42,13 +42,11 @@ import com.sk89q.worldedit.util.command.binding.Switch; import com.sk89q.worldedit.util.command.parametric.Optional; import com.sk89q.worldedit.util.io.Closer; import com.sk89q.worldedit.util.io.file.FilenameException; -import com.sk89q.worldedit.util.io.file.FilenameResolutionException; import com.sk89q.worldedit.world.registry.WorldData; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; -import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; @@ -58,6 +56,7 @@ import java.util.Comparator; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.regex.Pattern; import static com.google.common.base.Preconditions.checkNotNull; @@ -262,19 +261,10 @@ public class SchematicCommands { @CommandPermissions("worldedit.schematic.list") public void list(Actor actor, CommandContext args, @Switch('p') @Optional("1") int page) throws WorldEditException { File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().saveDir); - File[] files = dir.listFiles(new FileFilter(){ - @Override - public boolean accept(File file) { - // sort out directories from the schematic list - // if WE supports sub-directories in the future, - // this will have to be changed - return file.isFile(); - } - }); - if (files == null) { - throw new FilenameResolutionException(dir.getPath(), "Schematics directory invalid or not found."); - } - + List fileList = allFiles(dir); + File[] files = new File[fileList.size()]; + fileList.toArray(files); + if (files.length == 0) { actor.printError("No schematics found."); return; @@ -295,52 +285,66 @@ public class SchematicCommands { Arrays.sort(files, new Comparator(){ @Override public int compare(File f1, File f2) { - // this should no longer happen, as directory-ness is checked before - // however, if a directory slips through, this will break the contract - // of comparator transitivity - if (!f1.isFile() || !f2.isFile()) return -1; // http://stackoverflow.com/questions/203030/best-way-to-list-files-in-java-sorted-by-date-modified - int result = sortType == 0 ? f1.getName().compareToIgnoreCase(f2.getName()) : // use name by default - Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); // use date if there is a flag - if (sortType == 1) result = -result; // flip date for newest first instead of oldest first - return result; + int res; + if (sortType == 0) { // use name by default + int p = f1.getParent().compareTo(f2.getParent()); + if (p == 0) { // same parent, compare names + res = f1.getName().compareTo(f2.getName()); + } else { // different parent, sort by that + res = p; + } + } else { + res = Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); // use date if there is a flag + if (sortType == 1) res = -res; // flip date for newest first instead of oldest first + } + return res; } }); - List schematics = listFiles("", files); + List schematics = listFiles(worldEdit.getConfiguration().saveDir, files); int offset = (page - 1) * SCHEMATICS_PER_PAGE; actor.print("Available schematics (Filename: Format) [" + page + "/" + pageCount + "]:"); StringBuilder build = new StringBuilder(); int limit = Math.min(offset + SCHEMATICS_PER_PAGE, schematics.size()); - for (int i = offset; i < limit; i++) { + for (int i = offset; i < limit;) { build.append(schematics.get(i)); + if (++i != limit) { + build.append("\n"); + } } actor.print(build.toString()); } + private List allFiles(File root) { + File[] files = root.listFiles(); + if (files == null) return null; + List fileList = new ArrayList(); + for (File f : files) { + if (f.isDirectory()) { + List subFiles = allFiles(f); + if (subFiles == null) continue; // empty subdir + fileList.addAll(subFiles); + } else { + fileList.add(f); + } + } + return fileList; + } + private List listFiles(String prefix, File[] files) { + if (prefix == null) prefix = ""; List result = new ArrayList(); for (File file : files) { StringBuilder build = new StringBuilder(); - if (file.isDirectory()) { - build.append(listFiles(prefix + file.getName() + "/", file.listFiles())); - continue; - } - if (!file.isFile()) { - continue; - } - - if (!result.isEmpty()) { // prevent an empty line - build.append('\n'); - } - build.append("\u00a79"); + build.append("\u00a72"); ClipboardFormat format = ClipboardFormat.findByFile(file); - build.append(prefix).append(file.getName()) - .append(": ").append(format == null ? "Unknown" : format.name()); - + boolean inRoot = file.getParentFile().getName().equals(prefix); + build.append(inRoot ? file.getName() : file.getPath().split(Pattern.quote(prefix + File.separator))[1]) + .append(": ").append(format == null ? "Unknown" : format.name()); result.add(build.toString()); } return result; From 03f8843c2021425e5279aa82f9be6177d1802eed Mon Sep 17 00:00:00 2001 From: rlf Date: Mon, 12 Oct 2015 16:15:50 +0200 Subject: [PATCH 04/14] More efficient chunk calculation of CuboidRegion --- .../sk89q/worldedit/regions/CuboidRegion.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java index 71143b3d3..258be2c6f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java @@ -300,10 +300,9 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { Vector min = getMinimumPoint(); Vector max = getMaximumPoint(); - for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) { - for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) { - chunks.add(new BlockVector2D(x >> ChunkStore.CHUNK_SHIFTS, - z >> ChunkStore.CHUNK_SHIFTS)); + for (int x = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x <= max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; ++x) { + for (int z = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z <= max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; ++z) { + chunks.add(new BlockVector2D(x, z)); } } @@ -317,11 +316,10 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { Vector min = getMinimumPoint(); Vector max = getMaximumPoint(); - for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) { - for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) { - for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) { - chunks.add(new BlockVector(x >> ChunkStore.CHUNK_SHIFTS, - y >> ChunkStore.CHUNK_SHIFTS, z >> ChunkStore.CHUNK_SHIFTS)); + for (int x = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x <= max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; ++x) { + for (int z = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z <= max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; ++z) { + for (int y = min.getBlockY() >> ChunkStore.CHUNK_SHIFTS; y <= max.getBlockY() >> ChunkStore.CHUNK_SHIFTS; ++y) { + chunks.add(new BlockVector(x, y, z)); } } } From 1952c6f91acc144f1b435bc627c0b46845c1650c Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 31 Jan 2016 21:23:51 -0800 Subject: [PATCH 05/14] Compile on JDK 6, 7, and 8 Ensure that all JDKs are supported. --- .travis.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7b43b6822..3c13ded18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,8 @@ notifications: email: false before_install: chmod +x gradlew install: ./gradlew setupCIWorkspace -S -matrix: - include: - - jdk: oraclejdk7 - script: ./gradlew build -S \ No newline at end of file +script: ./gradlew build -S +jdk: + - oraclejdk8 + - oraclejdk7 + - openjdk6 From c14a3dfbde68f3bfd1debb8f51499715340cf11c Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 31 Jan 2016 21:24:59 -0800 Subject: [PATCH 06/14] Add caching to Travis --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3c13ded18..f1f614733 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,3 +8,10 @@ jdk: - oraclejdk8 - oraclejdk7 - openjdk6 +# Caching for Gradle files, prevents hitting Maven too much. +before_cache: + - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock +cache: + directories: + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ From 53b8f08e5eb0d42895eea77e5d5fb24919b6cf29 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 31 Jan 2016 21:25:32 -0800 Subject: [PATCH 07/14] Have Travis give less verbose stack traces --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f1f614733..d7da99ae4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,8 @@ language: java notifications: email: false before_install: chmod +x gradlew -install: ./gradlew setupCIWorkspace -S -script: ./gradlew build -S +install: ./gradlew setupCIWorkspace -s +script: ./gradlew build -s jdk: - oraclejdk8 - oraclejdk7 From 9dac0b30dbde2bc0c07541f609d2c6fda180c628 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 31 Jan 2016 21:27:07 -0800 Subject: [PATCH 08/14] Speed up Travis by running on non-sudo containers See why at https://docs.travis-ci.com/user/workers/container-based-infrastructure/ --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index d7da99ae4..e526c902f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,3 +15,6 @@ cache: directories: - $HOME/.gradle/caches/ - $HOME/.gradle/wrapper/ + +# Faster builds without sudo. +sudo: false From 982420369d7709c6732261708d1f075245d99286 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 31 Jan 2016 22:26:30 -0800 Subject: [PATCH 09/14] Rewrite Closer to compile on Java 6 wrt Jar/ZipFile. --- .../com/sk89q/worldedit/util/io/Closer.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java index 2e733c6ab..6b5c37efe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java @@ -29,6 +29,7 @@ import java.util.ArrayDeque; import java.util.Deque; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.zip.ZipFile; import static com.google.common.base.Preconditions.checkNotNull; @@ -55,6 +56,7 @@ public final class Closer implements Closeable { // only need space for 2 elements in most cases, so try to use the smallest array possible private final Deque stack = new ArrayDeque(4); + private final Deque zipStack = new ArrayDeque(4); private Throwable thrown; @VisibleForTesting Closer(Suppressor suppressor) { @@ -73,6 +75,17 @@ public final class Closer implements Closeable { return closeable; } + /** + * Registers the given {@code zipFile} to be closed when this {@code Closer} is + * {@linkplain #close closed}. + * + * @return the given {@code closeable} + */ + public Z register(Z zipFile) { + zipStack.push(zipFile); + return zipFile; + } + /** * Stores the given throwable and rethrows it. It will be rethrown as is if it is an * {@code IOException}, {@code RuntimeException} or {@code Error}. Otherwise, it will be rethrown @@ -161,6 +174,18 @@ public final class Closer implements Closeable { } } } + while (!zipStack.isEmpty()) { + ZipFile zipFile = zipStack.pop(); + try { + zipFile.close(); + } catch (Throwable e) { + if (throwable == null) { + throwable = e; + } else { + suppressor.suppress(zipFile, throwable, e); + } + } + } if (thrown == null && throwable != null) { Throwables.propagateIfPossible(throwable, IOException.class); @@ -177,7 +202,7 @@ public final class Closer implements Closeable { * the given closeable. {@code thrown} is the exception that is actually being thrown from the * method. Implementations of this method should not throw under any circumstances. */ - void suppress(Closeable closeable, Throwable thrown, Throwable suppressed); + void suppress(Object closeable, Throwable thrown, Throwable suppressed); } /** @@ -188,7 +213,7 @@ public final class Closer implements Closeable { static final LoggingSuppressor INSTANCE = new LoggingSuppressor(); @Override - public void suppress(Closeable closeable, Throwable thrown, Throwable suppressed) { + public void suppress(Object closeable, Throwable thrown, Throwable suppressed) { // log to the same place as Closeables logger.log(Level.WARNING, "Suppressing exception thrown when closing " + closeable, suppressed); } @@ -217,7 +242,7 @@ public final class Closer implements Closeable { } @Override - public void suppress(Closeable closeable, Throwable thrown, Throwable suppressed) { + public void suppress(Object closeable, Throwable thrown, Throwable suppressed) { // ensure no exceptions from addSuppressed if (thrown == suppressed) { return; From d6db9a97908204c9e2b91ed077fd51c0d864ca4e Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 7 Feb 2016 09:41:29 -0800 Subject: [PATCH 10/14] Update 1.7.10 Forge version --- worldedit-forge/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldedit-forge/build.gradle b/worldedit-forge/build.gradle index f7b51a33e..6c4e6c3a4 100644 --- a/worldedit-forge/build.gradle +++ b/worldedit-forge/build.gradle @@ -19,7 +19,7 @@ dependencies { } minecraft { - ext.forgeVersion = "10.13.1.1225" + ext.forgeVersion = "10.13.4.1614-1.7.10" version = "1.7.10-$forgeVersion" replaceIn "com/sk89q/worldedit/forge/ForgeWorldEdit.java" From 6757b04d24f8920d863b0685aa76310ece3a1dc3 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 7 Feb 2016 10:14:33 -0800 Subject: [PATCH 11/14] Add FMP as a dependency at compile --- worldedit-forge/build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/worldedit-forge/build.gradle b/worldedit-forge/build.gradle index 6c4e6c3a4..015e0f88d 100644 --- a/worldedit-forge/build.gradle +++ b/worldedit-forge/build.gradle @@ -15,7 +15,8 @@ apply plugin: 'forge' dependencies { compile project(':worldedit-core') - testCompile group: 'org.mockito', name: 'mockito-core', version:'1.9.0-rc1' + compile group: 'codechicken', name: 'ForgeMultipart', version: '1.2.0.345', classifier: 'dev' + testCompile group: 'org.mockito', name: 'mockito-core', version: '1.9.0-rc1' } minecraft { From 10776f27a8c7b4840c7b02b51d5947131a693b27 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 7 Feb 2016 10:42:13 -0800 Subject: [PATCH 12/14] Fix dependency --- worldedit-forge/build.gradle | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/worldedit-forge/build.gradle b/worldedit-forge/build.gradle index 015e0f88d..a5857ecb8 100644 --- a/worldedit-forge/build.gradle +++ b/worldedit-forge/build.gradle @@ -13,9 +13,16 @@ buildscript { apply plugin: 'forge' +repositories { + maven { + name 'forge' + url 'http://files.minecraftforge.net/maven/' + } +} + dependencies { compile project(':worldedit-core') - compile group: 'codechicken', name: 'ForgeMultipart', version: '1.2.0.345', classifier: 'dev' + compile group: 'codechicken', name: 'ForgeMultipart', version: '1.7.10-1.2.0.345', classifier: 'dev' testCompile group: 'org.mockito', name: 'mockito-core', version: '1.9.0-rc1' } From 7271cca89ff5ff0621dcf4ef8d4e0ac7383045ea Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 7 Feb 2016 14:07:41 -0800 Subject: [PATCH 13/14] Implement FMP compatibility --- .../sk89q/worldedit/forge/ForgeWorldEdit.java | 13 ++++++++ .../worldedit/forge/TileEntityUtils.java | 24 +++++++++++--- .../forge/compat/ForgeMultipartCompat.java | 15 +++++++++ .../compat/ForgeMultipartExistsCompat.java | 33 +++++++++++++++++++ .../forge/compat/NoForgeMultipartCompat.java | 19 +++++++++++ worldedit-forge/src/main/resources/mcmod.info | 3 +- 6 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java create mode 100644 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java create mode 100644 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java index 7284796e6..989865815 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java @@ -26,8 +26,12 @@ import com.sk89q.worldedit.WorldVector; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.event.platform.PlatformReadyEvent; import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.forge.compat.ForgeMultipartCompat; +import com.sk89q.worldedit.forge.compat.ForgeMultipartExistsCompat; +import com.sk89q.worldedit.forge.compat.NoForgeMultipartCompat; import com.sk89q.worldedit.internal.LocalWorldAdapter; import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; @@ -76,6 +80,7 @@ public class ForgeWorldEdit { private ForgePlatform platform; private ForgeConfiguration config; private File workingDir; + private ForgeMultipartCompat compat = new NoForgeMultipartCompat(); @EventHandler public void preInit(FMLPreInitializationEvent event) { @@ -87,6 +92,10 @@ public class ForgeWorldEdit { config = new ForgeConfiguration(this); config.load(); + if (Loader.isModLoaded("ForgeMultipart")) { + compat = new ForgeMultipartExistsCompat(); + } + FMLCommonHandler.instance().bus().register(ThreadSafeCache.getInstance()); } @@ -260,6 +269,10 @@ public class ForgeWorldEdit { return this.workingDir; } + public ForgeMultipartCompat getFMPCompat() { + return compat; + } + /** * Get the version of the WorldEdit-for-Forge implementation. * diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java index fd8d6e5fe..b3706f349 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java @@ -81,9 +81,10 @@ final class TileEntityUtils { tileEntity.readFromNBT(tag); } - world.setTileEntity(position.getBlockX(), position.getBlockY(), position.getBlockZ(), tileEntity); - } + tileEntity = ForgeWorldEdit.inst.getFMPCompat().overrideTileEntity(world, tag, tileEntity); + setTileEntity(world, position, tileEntity); + } /** * Set a tile entity at the given location using the tile entity ID from * the tag. @@ -95,12 +96,26 @@ final class TileEntityUtils { static void setTileEntity(World world, Vector position, @Nullable NBTTagCompound tag) { if (tag != null) { updateForSet(tag, position); - TileEntity tileEntity = TileEntity.createAndLoadEntity(tag); + TileEntity tileEntity = makeTileEntity(world, position, tag); if (tileEntity != null) { - world.setTileEntity(position.getBlockX(), position.getBlockY(), position.getBlockZ(), tileEntity); + setTileEntity(world, position, tileEntity); } } } + + private static TileEntity makeTileEntity(World world, Vector position, + NBTTagCompound tag) { + TileEntity normal = TileEntity.createAndLoadEntity(tag); + return ForgeWorldEdit.inst.getFMPCompat().overrideTileEntity(world, tag, + normal); + } + + private static void setTileEntity(World world, Vector position, + TileEntity tileEntity) { + world.setTileEntity(position.getBlockX(), position.getBlockY(), + position.getBlockZ(), tileEntity); + ForgeWorldEdit.inst.getFMPCompat().sendDescPacket(world, tileEntity); + } /** * Construct a tile entity from the given class. @@ -139,5 +154,4 @@ final class TileEntityUtils { return genericTE; } - } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java new file mode 100644 index 000000000..a9e8bd0de --- /dev/null +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java @@ -0,0 +1,15 @@ +package com.sk89q.worldedit.forge.compat; + +import javax.annotation.Nullable; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public interface ForgeMultipartCompat { + + TileEntity overrideTileEntity(World world, @Nullable NBTTagCompound tag, + TileEntity normal); + + void sendDescPacket(World world, TileEntity entity); + +} diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java new file mode 100644 index 000000000..1f5c82f30 --- /dev/null +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java @@ -0,0 +1,33 @@ +package com.sk89q.worldedit.forge.compat; + +import codechicken.multipart.MultipartHelper; +import codechicken.multipart.TileMultipart; +import javax.annotation.Nullable; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class ForgeMultipartExistsCompat implements ForgeMultipartCompat { + + @Override + public TileEntity overrideTileEntity(World world, + @Nullable NBTTagCompound tag, TileEntity normal) { + if (tag == null) { + return normal; + } + TileEntity tile = MultipartHelper.createTileFromNBT(world, tag); + if (tile == null) { + return normal; + } + return tile; + } + + @Override + public void sendDescPacket(World world, TileEntity entity) { + if (entity instanceof TileMultipart) { + TileMultipart multi = (TileMultipart) entity; + MultipartHelper.sendDescPacket(world, multi); + } + } + +} diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java new file mode 100644 index 000000000..229a9ba40 --- /dev/null +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java @@ -0,0 +1,19 @@ +package com.sk89q.worldedit.forge.compat; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class NoForgeMultipartCompat implements ForgeMultipartCompat { + + @Override + public TileEntity overrideTileEntity(World world, NBTTagCompound tag, + TileEntity normal) { + return normal; + } + + @Override + public void sendDescPacket(World world, TileEntity entity) { + } + +} diff --git a/worldedit-forge/src/main/resources/mcmod.info b/worldedit-forge/src/main/resources/mcmod.info index df47ddfac..f3f2f5b98 100644 --- a/worldedit-forge/src/main/resources/mcmod.info +++ b/worldedit-forge/src/main/resources/mcmod.info @@ -14,7 +14,8 @@ "Forge@[${forgeVersion},)" ], "dependencies": [ - "Forge@[${forgeVersion},)" + "Forge@[${forgeVersion},)", + "ForgeMultipart" ], "dependants": [] }] From 4088f26d198ba48ed4fbdfd63748bf45455a01dc Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 7 Feb 2016 14:21:24 -0800 Subject: [PATCH 14/14] Fix checkstyle errors --- config/checkstyle/import-control.xml | 1 + .../forge/compat/ForgeMultipartCompat.java | 19 +++++++++++++++++++ .../compat/ForgeMultipartExistsCompat.java | 18 ++++++++++++++++++ .../forge/compat/NoForgeMultipartCompat.java | 19 +++++++++++++++++++ 4 files changed, 57 insertions(+) diff --git a/config/checkstyle/import-control.xml b/config/checkstyle/import-control.xml index 7a5600470..1209aa71d 100644 --- a/config/checkstyle/import-control.xml +++ b/config/checkstyle/import-control.xml @@ -48,6 +48,7 @@ + diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java index a9e8bd0de..00d1615e1 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java @@ -1,3 +1,22 @@ +/* + * 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.forge.compat; import javax.annotation.Nullable; diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java index 1f5c82f30..d1b4752e4 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java @@ -1,3 +1,21 @@ +/* + * 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.forge.compat; import codechicken.multipart.MultipartHelper; diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java index 229a9ba40..316509689 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java @@ -1,3 +1,22 @@ +/* + * 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.forge.compat; import net.minecraft.nbt.NBTTagCompound;