From b7b11cc4786bb0b72d86268e0d2114886ffe17ab Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Mon, 2 Mar 2020 17:43:27 -0500 Subject: [PATCH] Gradle Upgrades and Clipboard Refactoring --- buildSrc/build.gradle.kts | 1 - buildSrc/src/main/kotlin/ArtifactoryConfig.kt | 40 ------------------- buildSrc/src/main/kotlin/PlatformConfig.kt | 4 +- gradle/wrapper/gradle-wrapper.properties | 2 +- worldedit-core/build.gradle.kts | 13 ++++-- .../boydti/fawe/object/brush/ErodeBrush.java | 39 +++++++++--------- .../clipboard/CPUOptimizedClipboard.java | 10 ++--- .../clipboard/DiskOptimizedClipboard.java | 10 ++--- .../com/boydti/fawe/util/TaskManager.java | 30 +++++++------- .../sk89q/worldedit/entity/Metadatable.java | 1 - .../clipboard/io/FastSchematicReader.java | 1 + .../sk89q/worldedit/regions/CuboidRegion.java | 26 +++--------- 12 files changed, 61 insertions(+), 116 deletions(-) delete mode 100644 buildSrc/src/main/kotlin/ArtifactoryConfig.kt diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index ad4989477..17800ae54 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -35,6 +35,5 @@ dependencies { implementation("com.github.jengelman.gradle.plugins:shadow:5.1.0") implementation("net.ltgt.apt-eclipse:net.ltgt.apt-eclipse.gradle.plugin:0.21") implementation("net.ltgt.apt-idea:net.ltgt.apt-idea.gradle.plugin:0.21") - implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.9.7") implementation("gradle.plugin.com.mendhak.gradlecrowdin:plugin:0.1.0") } diff --git a/buildSrc/src/main/kotlin/ArtifactoryConfig.kt b/buildSrc/src/main/kotlin/ArtifactoryConfig.kt deleted file mode 100644 index d19f35238..000000000 --- a/buildSrc/src/main/kotlin/ArtifactoryConfig.kt +++ /dev/null @@ -1,40 +0,0 @@ -import org.gradle.api.Project -import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.named -import org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention -import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask - -private const val ARTIFACTORY_CONTEXT_URL = "artifactory_contextUrl" -private const val ARTIFACTORY_USER = "artifactory_user" -private const val ARTIFACTORY_PASSWORD = "artifactory_password" - -fun Project.applyRootArtifactoryConfig() { - if (!project.hasProperty(ARTIFACTORY_CONTEXT_URL)) ext[ARTIFACTORY_CONTEXT_URL] = "http://localhost" - if (!project.hasProperty(ARTIFACTORY_USER)) ext[ARTIFACTORY_USER] = "guest" - if (!project.hasProperty(ARTIFACTORY_PASSWORD)) ext[ARTIFACTORY_PASSWORD] = "" - - apply(plugin = "com.jfrog.artifactory") - configure { - setContextUrl("${project.property(ARTIFACTORY_CONTEXT_URL)}") - clientConfig.publisher.run { - repoKey = when { - "${project.version}".contains("SNAPSHOT") -> "libs-snapshot-local" - else -> "libs-release-local" - } - username = "${project.property(ARTIFACTORY_USER)}" - password = "${project.property(ARTIFACTORY_PASSWORD)}" - isMaven = true - isIvy = false - } - } - tasks.named("artifactoryPublish") { - isSkip = true - } -} - -fun Project.applyCommonArtifactoryConfig() { - tasks.named("artifactoryPublish") { - publishConfigs("archives") - } -} diff --git a/buildSrc/src/main/kotlin/PlatformConfig.kt b/buildSrc/src/main/kotlin/PlatformConfig.kt index 2856c62e0..0c573871c 100644 --- a/buildSrc/src/main/kotlin/PlatformConfig.kt +++ b/buildSrc/src/main/kotlin/PlatformConfig.kt @@ -20,12 +20,10 @@ import org.gradle.kotlin.dsl.withType fun Project.applyPlatformAndCoreConfiguration() { applyCommonConfiguration() apply(plugin = "java") - apply(plugin = "eclipse") apply(plugin = "idea") apply(plugin = "maven") //apply(plugin = "checkstyle") apply(plugin = "com.github.johnrengelman.shadow") - //apply(plugin = "com.jfrog.artifactory") ext["internalVersion"] = "$version;${rootProject.ext["gitCommitHash"]}" @@ -44,7 +42,7 @@ fun Project.applyPlatformAndCoreConfiguration() { } dependencies { - "compileOnly"("org.jetbrains:annotations:18.0.0") + "compileOnly"("org.jetbrains:annotations:19.0.0") "testImplementation"("org.junit.jupiter:junit-jupiter-api:${Versions.JUNIT}") "testImplementation"("org.junit.jupiter:junit-jupiter-params:${Versions.JUNIT}") "testImplementation"("org.mockito:mockito-core:${Versions.MOCKITO}") diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ca9d62814..5028f28f8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/worldedit-core/build.gradle.kts b/worldedit-core/build.gradle.kts index a58e758eb..25ed1cefa 100644 --- a/worldedit-core/build.gradle.kts +++ b/worldedit-core/build.gradle.kts @@ -114,7 +114,7 @@ tasks.named("shadowJar") { val crowdinApiKey = "crowdin_apikey" -if (project.hasProperty(crowdinApiKey)) { +if (project.hasProperty(crowdinApiKey) && !gradle.startParameter.isOffline) { tasks.named("crowdinUpload") { apiKey = "${project.property(crowdinApiKey)}" projectId = "worldedit-core" @@ -126,12 +126,19 @@ if (project.hasProperty(crowdinApiKey)) { ) } - tasks.named("crowdinDownload") { + val dlTranslationsTask = tasks.named("crowdinDownload") { apiKey = "${project.property(crowdinApiKey)}" - destination = "${file("build/resources/main/lang")}" + destination = "${buildDir.resolve("crowdin-i18n")}" projectId = "worldedit-core" } + tasks.named("processResources") { + dependsOn(dlTranslationsTask) + from(dlTranslationsTask.get().destination) { + into("lang") + } + } + tasks.named("classes").configure { dependsOn("crowdinDownload") } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java index cb23bef94..bb1e932e2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java @@ -1,47 +1,50 @@ package com.boydti.fawe.object.brush; import com.boydti.fawe.object.clipboard.CPUOptimizedClipboard; -import com.boydti.fawe.object.clipboard.LinearClipboard; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Direction; +import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; import java.util.Arrays; public class ErodeBrush implements Brush { private static final BlockVector3[] FACES_TO_CHECK = Direction.valuesOf(Direction.Flag.CARDINAL).stream().map(Direction::toBlockVector).toArray(BlockVector3[]::new); - private final int erodeFaces, erodeRec, fillFaces, fillRec; + private final int erodeFaces, erodeRecursion, fillFaces, fillRecursion; public ErodeBrush() { this(2, 1, 5, 1); } - public ErodeBrush(int erodeFaces, int erodeRec, int fillFaces, int fillRec) { + public ErodeBrush(int erodeFaces, int erodeRecursion, int fillFaces, int fillRecursion) { this.erodeFaces = erodeFaces; - this.erodeRec = erodeRec; + this.erodeRecursion = erodeRecursion; this.fillFaces = fillFaces; - this.fillRec = fillRec; + this.fillRecursion = fillRecursion; } @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { - this.erosion(editSession, erodeFaces, erodeRec, fillFaces, fillRec, position, size); + this.erosion(editSession, erodeFaces, erodeRecursion, fillFaces, fillRecursion, position, size); } - public void erosion(final EditSession es, int erodeFaces, int erodeRec, int fillFaces, int fillRec, BlockVector3 target, double size) { - int brushSize = (int) size + 1; + public void erosion(final EditSession es, int erodeFaces, int erodeRecursion, int fillFaces, int fillRecursion, BlockVector3 target, double size) { + int brushSize = (int) size; int brushSizeSquared = (int) (size * size); - BlockVector3 dimension = BlockVector3.ONE.multiply(brushSize * 2 + 1); - Clipboard buffer1 = new CPUOptimizedClipboard(dimension); - Clipboard buffer2 = new CPUOptimizedClipboard(dimension); + Location min = new Location(es.getWorld(), target.toVector3().subtract(size, size, size)); + Location max = new Location(es.getWorld(), target.toVector3().add(size, size, size)); + Region region = new CuboidRegion(es.getWorld(), min.toBlockPoint(), max.toBlockPoint()); + Clipboard buffer1 = new CPUOptimizedClipboard(region); + Clipboard buffer2 = new CPUOptimizedClipboard(region); final int bx = target.getBlockX(); final int by = target.getBlockY(); @@ -61,12 +64,12 @@ public class ErodeBrush implements Brush { } int swap = 0; - for (int i = 0; i < erodeRec; ++i) { + for (int i = 0; i < erodeRecursion; ++i) { erosionIteration(brushSize, brushSizeSquared, erodeFaces, swap % 2 == 0 ? buffer1 : buffer2, swap % 2 == 1 ? buffer1 : buffer2); swap++; } - for (int i = 0; i < fillRec; ++i) { + for (int i = 0; i < fillRecursion; ++i) { fillIteration(brushSize, brushSizeSquared, fillFaces, swap % 2 == 0 ? buffer1 : buffer2, swap % 2 == 1 ? buffer1 : buffer2); swap++; } @@ -95,14 +98,14 @@ public class ErodeBrush implements Brush { if (state.getBlockType().getMaterial().isMovementBlocker()) { continue; } - int total = 0; - int highest = 1; BaseBlock highestState = state; if (frequency == null) { frequency = new int[BlockTypes.size()]; } else { Arrays.fill(frequency, 0); } + int total = 0; + int highest = 1; for (BlockVector3 offs : FACES_TO_CHECK) { BaseBlock next = current.getFullBlock(relx + offs.getBlockX(), rely + offs.getBlockY(), relz + offs.getBlockZ()); if (!next.getBlockType().getMaterial().isMovementBlocker()) { @@ -140,14 +143,14 @@ public class ErodeBrush implements Brush { if (!state.getMaterial().isMovementBlocker()) { continue; } - int total = 0; - int highest = 1; BaseBlock highestState = state; if (frequency == null) { frequency = new int[BlockTypes.size()]; } else { Arrays.fill(frequency, 0); } + int highest = 1; + int total = 0; for (BlockVector3 offs : FACES_TO_CHECK) { BaseBlock next = current.getFullBlock(relx + offs.getBlockX(), rely + offs.getBlockY(), relz + offs.getBlockZ()); if (next.getMaterial().isMovementBlocker()) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java index f72b94f1c..bbf8788af 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java @@ -37,17 +37,13 @@ public class CPUOptimizedClipboard extends LinearClipboard { private final HashMap nbtMapIndex; - public CPUOptimizedClipboard(BlockVector3 dimensions) { - super(dimensions); + public CPUOptimizedClipboard(Region region) { + super(region.getDimensions()); this.states = new char[getVolume()]; nbtMapLoc = new HashMap<>(); nbtMapIndex = new HashMap<>(); } - - public CPUOptimizedClipboard(Region region) { - this(region.getDimensions()); - } - + @Override public boolean hasBiomes() { return biomes != null; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java index 9809ed736..ace476311 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java @@ -62,8 +62,8 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable private FileChannel fileChannel; private boolean hasBiomes; - public DiskOptimizedClipboard(BlockVector3 dimensions, UUID uuid) { - this(dimensions, MainUtil.getFile(Fawe.get() != null ? Fawe.imp().getDirectory() : new File("."), Settings.IMP.PATHS.CLIPBOARD + File.separator + uuid + ".bd")); + public DiskOptimizedClipboard(Region region, UUID uuid) { + this(region.getDimensions(), MainUtil.getFile(Fawe.get() != null ? Fawe.imp().getDirectory() : new File("."), Settings.IMP.PATHS.CLIPBOARD + File.separator + uuid + ".bd")); } public DiskOptimizedClipboard(BlockVector3 dimensions) { @@ -108,11 +108,7 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable throw new RuntimeException(e); } } - - public DiskOptimizedClipboard(Region region, UUID uuid) { - this(region.getDimensions(), uuid); - } - + @Override public URI getURI() { return file.toURI(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/TaskManager.java b/worldedit-core/src/main/java/com/boydti/fawe/util/TaskManager.java index a5edd67c9..3c7d1703a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/TaskManager.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/TaskManager.java @@ -36,23 +36,23 @@ public abstract class TaskManager { /** * Run a repeating task asynchronously * - * @param runnable + * @param runnable the task to run * @param interval in ticks - * @return + * @return the task id number */ public abstract int repeatAsync(@NotNull final Runnable runnable, final int interval); /** * Run a task asynchronously * - * @param runnable + * @param runnable the task to run */ public abstract void async(@NotNull final Runnable runnable); /** * Run a task on the main thread * - * @param runnable + * @param runnable the task to run */ public abstract void task(@NotNull final Runnable runnable); @@ -153,10 +153,10 @@ public abstract class TaskManager { /** * Run a task on the current thread or asynchronously - * - If it's already the main thread, it will jst call run() + * - If it's already the main thread, it will just call run() * - * @param runnable - * @param async + * @param runnable the task to run + * @param async whether the task should run on the main thread */ public void taskNow(@NotNull final Runnable runnable, boolean async) { if (async) { @@ -170,7 +170,7 @@ public abstract class TaskManager { * Run a task as soon as possible on the main thread * - Non blocking if not calling from the main thread * - * @param runnable + * @param runnable the task to run */ public void taskNowMain(@NotNull final Runnable runnable) { if (Fawe.isMainThread()) { @@ -183,8 +183,8 @@ public abstract class TaskManager { /** * Run a task as soon as possible not on the main thread * - * @param runnable - * @see com.boydti.fawe.Fawe#isMainThread() + * @param runnable the task to run + * @see Fawe#isMainThread() */ public void taskNowAsync(@NotNull final Runnable runnable) { taskNow(runnable, Fawe.isMainThread()); @@ -193,8 +193,8 @@ public abstract class TaskManager { /** * Run a task on the main thread at the next tick or now async * - * @param runnable - * @param async + * @param runnable the task to run. + * @param async whether the task should run on the main thread */ public void taskSoonMain(@NotNull final Runnable runnable, boolean async) { if (async) { @@ -208,7 +208,7 @@ public abstract class TaskManager { /** * Run a task later on the main thread * - * @param runnable + * @param runnable the task to run * @param delay in ticks */ public abstract void later(@NotNull final Runnable runnable, final int delay); @@ -216,7 +216,7 @@ public abstract class TaskManager { /** * Run a task later asynchronously * - * @param runnable + * @param runnable the task to run * @param delay in ticks */ public abstract void laterAsync(@NotNull final Runnable runnable, final int delay); @@ -224,7 +224,7 @@ public abstract class TaskManager { /** * Cancel a task * - * @param task + * @param task the id of the task to cancel */ public abstract void cancel(final int task); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Metadatable.java b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Metadatable.java index 5e2e61126..1062a3f39 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Metadatable.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Metadatable.java @@ -10,7 +10,6 @@ public interface Metadatable { * * @param key * @param value - * @return previous value */ void setMeta(String key, Object value); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/FastSchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/FastSchematicReader.java index a3957ada3..80a4613df 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/FastSchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/FastSchematicReader.java @@ -38,6 +38,7 @@ import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.DataFixer; import com.sk89q.worldedit.world.biome.BiomeType; 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 03b6fdc6c..8b328bb95 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 @@ -124,8 +124,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { if (pos1 == null || pos2 == null) { return; } - pos1 = pos1.clampY(world == null ? 0 : 0, world == null ? FaweCache.IMP.WORLD_MAX_Y : world.getMaxY()); - pos2 = pos2.clampY(world == null ? 0 : 0, world == null ? FaweCache.IMP.WORLD_MAX_Y : world.getMaxY()); + pos1 = pos1.clampY(0, world == null ? 255 : world.getMaxY()); + pos2 = pos2.clampY(0, world == null ? 255 : world.getMaxY()); minX = Math.min(pos1.getX(), pos2.getX()); minY = Math.min(pos1.getY(), pos2.getY()); minZ = Math.min(pos1.getZ(), pos2.getZ()); @@ -397,9 +397,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { if (o instanceof BlockVector2) { BlockVector2 cv = (BlockVector2) o; return cv.getX() >= minX && cv.getX() <= maxX && cv.getZ() >= minZ && cv.getZ() <= maxZ; - } else { - return false; } + return false; } }; } @@ -422,15 +421,11 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { return chunks; } - /* Slow and unnecessary + @Override public boolean contains(BlockVector3 position) { - BlockVector3 min = getMinimumPoint(); - BlockVector3 max = getMaximumPoint(); - - return position.containedWithin(min, max); + return contains(position.getX(), position.getY(), position.getZ()); } - */ @Override public boolean contains(int x, int y, int z) { @@ -442,11 +437,6 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ; } - @Override - public boolean contains(BlockVector3 position) { - return contains(position.getX(), position.getY(), position.getZ()); - } - @Override public Iterator iterator() { if (Settings.IMP.HISTORY.COMPRESSION_LEVEL >= 9) { @@ -543,7 +533,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { @Override public boolean hasNext() { - return hasNext; + return (hasNext); } @Override @@ -596,10 +586,6 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { return answer; } - @Override - public void remove() { - throw new UnsupportedOperationException(); - } }; }