From f236934a395acf646dc6ec5901501aa9678acfc7 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Tue, 28 Dec 2021 22:46:19 +0000 Subject: [PATCH] Add get default version min/max world height to platform - Fixes #1500 --- .../fastasyncworldedit/bukkit/FaweBukkit.java | 2 +- .../bukkit/regions/GriefPreventionFeature.java | 6 ++++-- .../bukkit/util/MinecraftVersion.java | 1 + .../bukkit/BukkitServerInterface.java | 11 +++++++++++ .../core/regions/RegionWrapper.java | 10 +++++++++- .../extension/input/ParserContext.java | 6 ++++-- .../worldedit/extension/platform/Platform.java | 11 +++++++++++ .../sk89q/worldedit/extent/OutputExtent.java | 6 +++++- .../worldedit/function/mask/OffsetMask.java | 7 ++++++- .../function/visitor/BreadthFirstSearch.java | 7 ++++++- .../function/visitor/DownwardVisitor.java | 7 ++++++- .../function/visitor/NonRisingVisitor.java | 7 ++++++- .../function/visitor/RecursiveVisitor.java | 7 ++++++- .../worldedit/regions/AbstractRegion.java | 18 ++++++++++++++---- .../com/sk89q/worldedit/regions/Region.java | 15 ++++++++++++++- .../sk89q/worldedit/world/AbstractWorld.java | 6 ++++-- 16 files changed, 108 insertions(+), 19 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/FaweBukkit.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/FaweBukkit.java index 8aff475d1..3f11d04f6 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/FaweBukkit.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/FaweBukkit.java @@ -84,7 +84,7 @@ public class FaweBukkit implements IFawe, Listener { Bukkit.getServer().shutdown(); } - chunksStretched = new MinecraftVersion().isEqualOrHigher(MinecraftVersion.NETHER); + chunksStretched = new MinecraftVersion().isEqualOrLower(MinecraftVersion.NETHER); platformAdapter = new NMSAdapter(); diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/GriefPreventionFeature.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/GriefPreventionFeature.java index 0798cf973..c75349b76 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/GriefPreventionFeature.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/GriefPreventionFeature.java @@ -1,7 +1,9 @@ package com.fastasyncworldedit.bukkit.regions; import com.fastasyncworldedit.core.regions.FaweMask; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; @@ -38,12 +40,12 @@ public class GriefPreventionFeature extends BukkitMaskManager implements Listene claim.getGreaterBoundaryCorner().getBlockX(); final BlockVector3 pos1 = BlockVector3.at( claim.getLesserBoundaryCorner().getBlockX(), - 0, + player.getWorld().getMinHeight(), claim.getLesserBoundaryCorner().getBlockZ() ); final BlockVector3 pos2 = BlockVector3.at( claim.getGreaterBoundaryCorner().getBlockX(), - 256, + player.getWorld().getMaxHeight(), claim.getGreaterBoundaryCorner().getBlockZ() ); return new FaweMask(new CuboidRegion(pos1, pos2)) { diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/MinecraftVersion.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/MinecraftVersion.java index cba863428..7715c65e2 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/MinecraftVersion.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/MinecraftVersion.java @@ -12,6 +12,7 @@ public class MinecraftVersion implements Comparable { public static final MinecraftVersion NETHER = new MinecraftVersion(1, 16); public static final MinecraftVersion CAVES_17 = new MinecraftVersion(1, 17); + public static final MinecraftVersion CAVES_18 = new MinecraftVersion(1, 18); private final int major; private final int minor; diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java index 83fc8c889..033790560 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.bukkit; +import com.fastasyncworldedit.bukkit.util.MinecraftVersion; import com.fastasyncworldedit.core.extent.processor.lighting.RelighterFactory; import com.google.common.collect.Sets; import com.sk89q.bukkit.util.CommandInfo; @@ -278,5 +279,15 @@ public class BukkitServerInterface extends AbstractPlatform implements MultiUser } return this.relighterFactory; } + + @Override + public int getVersionMinY() { + return new MinecraftVersion().isEqualOrLower(MinecraftVersion.CAVES_18) ? -64 : 0; + } + + @Override + public int getVersionMaxY() { + return new MinecraftVersion().isEqualOrLower(MinecraftVersion.CAVES_18) ? 319 : 255; + } //FAWE end } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/regions/RegionWrapper.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/regions/RegionWrapper.java index a5d38deee..55a39eb21 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/regions/RegionWrapper.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/regions/RegionWrapper.java @@ -1,5 +1,7 @@ package com.fastasyncworldedit.core.regions; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; @@ -27,7 +29,13 @@ public class RegionWrapper extends CuboidRegion { */ @Deprecated public RegionWrapper(final int minX, final int maxX, final int minZ, final int maxZ) { - this(minX, maxX, 0, 255, minZ, maxZ); + this(minX, + maxX, + WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMinY(), + WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMaxY(), + minZ, + maxZ + ); } public RegionWrapper(final int minX, final int maxX, final int minY, final int maxY, final int minZ, final int maxZ) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/ParserContext.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/ParserContext.java index e1f6cdca1..30ac850a5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/ParserContext.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/ParserContext.java @@ -21,8 +21,10 @@ package com.sk89q.worldedit.extension.input; import com.fastasyncworldedit.core.configuration.Caption; import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.factory.MaskFactory; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Locatable; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.world.World; @@ -303,8 +305,8 @@ public class ParserContext { minY = extent.getMinY(); maxY = extent.getMaxY(); } else { - minY = 0; - maxY = 255; + minY = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMinY(); + maxY = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMaxY(); } return minY; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Platform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Platform.java index abb84c3fe..dd4012ebe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Platform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Platform.java @@ -22,6 +22,7 @@ package com.sk89q.worldedit.extension.platform; import com.fastasyncworldedit.core.extent.processor.lighting.Relighter; import com.fastasyncworldedit.core.extent.processor.lighting.RelighterFactory; import com.sk89q.worldedit.LocalConfiguration; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility; import com.sk89q.worldedit.registry.Keyed; @@ -235,5 +236,15 @@ public interface Platform extends Keyed { */ @Nonnull RelighterFactory getRelighterFactory(); + + /** + * Get the default minimum Y value of worlds based on Minecraft version (inclusive). + */ + int getVersionMinY(); + + /** + * Get the default maximum Y value of worlds based on Minecraft version (inclusive). + */ + int getVersionMaxY(); //FAWE end } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java index ffe880557..df2e07723 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java @@ -22,7 +22,9 @@ package com.sk89q.worldedit.extent; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.math.MutableBlockVector3; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.internal.util.DeprecationUtil; import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility; @@ -95,7 +97,9 @@ public interface OutputExtent { @Deprecated default boolean setBiome(BlockVector2 position, BiomeType biome) { boolean result = false; - for (int y = 0; y < 256; y++) { + int minY = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMinY(); + int maxY = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMaxY(); + for (int y = minY; y < maxY; y++) { result |= setBiome(position.toBlockVector3().mutY(y), biome); } return result; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java index 91e92964f..2f83000b8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java @@ -19,6 +19,8 @@ package com.sk89q.worldedit.function.mask; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.math.BlockVector3; import javax.annotation.Nullable; @@ -47,7 +49,10 @@ public class OffsetMask extends AbstractMask { */ @Deprecated public OffsetMask(Mask mask, BlockVector3 offset) { - this(mask, offset, 0, 255); + this(mask, offset, + WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMinY(), + WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMaxY() + ); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java index 8decb381a..baab0e4c5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java @@ -28,7 +28,9 @@ import com.fastasyncworldedit.core.queue.implementation.SingleThreadQueueExtent; import com.fastasyncworldedit.core.util.ExtentTraverser; import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.operation.Operation; @@ -110,7 +112,10 @@ public abstract class BreadthFirstSearch implements Operation { */ public BreadthFirstSearch(RegionFunction function) { //FAWE start - int depth, min/max y - this(function, Integer.MAX_VALUE, 0, 255, null); + this(function, Integer.MAX_VALUE, + WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMinY(), + WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMaxY(), null + ); } //FAWE start - int depth, min/max y, preloading diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java index 7ea7f99e6..0ebeacce0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java @@ -19,6 +19,8 @@ package com.sk89q.worldedit.function.visitor; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.mask.Mask; @@ -48,7 +50,10 @@ public class DownwardVisitor extends RecursiveVisitor { @Deprecated public DownwardVisitor(Mask mask, RegionFunction function, int baseY) { //FAWE start - int depth, min/max y - this(mask, function, baseY, Integer.MAX_VALUE, 0, 255, null); + this(mask, function, baseY, Integer.MAX_VALUE, WorldEdit + .getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMinY(), + WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMaxY(), null + ); //FAWE end } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java index c4dedc1b3..d206d84fe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java @@ -19,6 +19,8 @@ package com.sk89q.worldedit.function.visitor; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.mask.Mask; @@ -39,7 +41,10 @@ public class NonRisingVisitor extends RecursiveVisitor { @Deprecated public NonRisingVisitor(Mask mask, RegionFunction function) { //FAWE start - int depth, y min/max - this(mask, function, Integer.MAX_VALUE, 0, 255, null); + this(mask, function, Integer.MAX_VALUE, WorldEdit + .getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMinY(), + WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMaxY(), null + ); //FAWE end } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java index 861210a46..c96e4b063 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java @@ -19,6 +19,8 @@ package com.sk89q.worldedit.function.visitor; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.mask.Mask; @@ -41,7 +43,10 @@ public class RecursiveVisitor extends BreadthFirstSearch { * @param function the function */ public RecursiveVisitor(Mask mask, RegionFunction function) { - this(mask, function, Integer.MAX_VALUE, 0, 255, null); + this(mask, function, Integer.MAX_VALUE, WorldEdit + .getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMinY(), + WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMaxY(), null + ); //FAWE end } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java index 2768f914b..bfcb40400 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java @@ -20,6 +20,8 @@ package com.sk89q.worldedit.regions; import com.fastasyncworldedit.core.math.BlockVectorSet; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; @@ -221,14 +223,22 @@ public abstract class AbstractRegion extends AbstractSet implement // Sub-class utilities protected final int getWorldMinY() { - //FAWE start > Integer.MIN_VALUE -> 0 (to avoid crazy for loops...) TODO: See if there's a way to find a "server default" - return world == null ? 0 : world.getMinY(); + //FAWE start > Server default based on version + return world == null ? WorldEdit + .getInstance() + .getPlatformManager() + .queryCapability(Capability.WORLD_EDITING) + .getVersionMinY() : world.getMinY(); //FAWE end } protected final int getWorldMaxY() { - //FAWE start > Integer.MAX_VALUE -> 255 (to avoid crazy for loops...) TODO: See if there's a way to find a "server default" - return world == null ? 255 : world.getMaxY(); + //FAWE start > Server default based on version + return world == null ? WorldEdit + .getInstance() + .getPlatformManager() + .queryCapability(Capability.WORLD_EDITING) + .getVersionMaxY() : world.getMaxY(); //FAWE end } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java index 8515b8952..240f039fb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java @@ -29,6 +29,8 @@ import com.fastasyncworldedit.core.queue.IBatchProcessor; import com.fastasyncworldedit.core.queue.IChunk; import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkSet; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.internal.util.DeprecationUtil; import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility; @@ -226,7 +228,18 @@ public interface Region extends Iterable, Cloneable, IBatchProcess BlockVector3 pos1 = getMinimumPoint(); BlockVector3 pos2 = getMaximumPoint(); return pos1.getBlockX() == Integer.MIN_VALUE && pos1.getBlockZ() == Integer.MIN_VALUE && pos2.getBlockX() == Integer.MAX_VALUE && pos2 - .getBlockZ() == Integer.MAX_VALUE && pos1.getBlockY() <= 0 && pos2.getBlockY() >= 255; + .getBlockZ() == Integer.MAX_VALUE + && pos1.getBlockY() <= WorldEdit + .getInstance() + .getPlatformManager() + .queryCapability( + Capability.WORLD_EDITING) + .getVersionMinY() + && pos2.getBlockY() >= WorldEdit + .getInstance() + .getPlatformManager() + .queryCapability(Capability.WORLD_EDITING) + .getVersionMaxY(); } default int getMinimumY() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java index 1f498a873..bee63181f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java @@ -20,9 +20,11 @@ package com.sk89q.worldedit.world; import com.fastasyncworldedit.core.function.mask.BlockMaskBuilder; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItemStack; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.Operation; @@ -66,12 +68,12 @@ public abstract class AbstractWorld implements World { @Override public int getMinY() { - return 0; + return WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMinY(); } @Override public int getMaxY() { - return 255; + return WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getVersionMaxY(); } @Override