From ab4809985e8a622bc23c143b6566cbfd50d5def6 Mon Sep 17 00:00:00 2001 From: Maddy Miller Date: Sat, 6 Jul 2024 20:28:30 +1000 Subject: [PATCH 1/8] Lazily compute BlockState#getAsString (#2566) * Lazily compute BlockState#getAsString * Implement in BaseBlock --- .../sk89q/worldedit/bukkit/BukkitAdapter.java | 2 +- .../sk89q/worldedit/world/block/BaseBlock.java | 17 ++++++++++++++++- .../sk89q/worldedit/world/block/BlockState.java | 7 +++++++ .../worldedit/world/block/BlockStateHolder.java | 5 +++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java index f2815405e4..a0a8672a92 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java @@ -491,7 +491,7 @@ public static > BlockData adapt(B block) { if (cacheKey == BlockStateIdAccess.invalidId()) { cacheKey = block.hashCode(); } - return blockDataCache.computeIfAbsent(cacheKey, input -> Bukkit.createBlockData(block.getAsString())).clone(); + return blockDataCache.computeIfAbsent(cacheKey, input -> Bukkit.createBlockData(block.toImmutableState().getAsString())).clone(); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java index 577579f652..609f7c7e26 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java @@ -192,8 +192,18 @@ public int hashCode() { return ret; } + /** + * Gets a string representation of this BaseBlock, in the format expected by WorldEdit's block parsers. + * + *

+ * If NBT data is present, it will be included in the string. If you only want the underlying block state, call + * this method on the return value from {@link #toImmutableState()} instead. + *

+ * + * @return The string representation + */ @Override - public String toString() { + public String getAsString() { String nbtString = ""; if (nbtData != null) { nbtString = LinStringIO.writeToString(nbtData.getValue()); @@ -202,4 +212,9 @@ public String toString() { return blockState.getAsString() + nbtString; } + @Override + public String toString() { + return getAsString(); + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index 00bc788957..690081c7ba 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -66,6 +66,7 @@ public void setInternalId(BlockState blockState, int internalId) { private final Map, Object> values; private final BaseBlock emptyBaseBlock; + private final LazyReference lazyStringRepresentation; // Neighbouring state table. private Table, Object, BlockState> states; @@ -79,6 +80,7 @@ public void setInternalId(BlockState blockState, int internalId) { this.blockType = blockType; this.values = new LinkedHashMap<>(); this.emptyBaseBlock = new BaseBlock(this); + this.lazyStringRepresentation = LazyReference.from(BlockStateHolder.super::getAsString); } /** @@ -270,6 +272,11 @@ BlockState setState(final Property property, final Object value) { return this; } + @Override + public String getAsString() { + return lazyStringRepresentation.getValue(); + } + @Override public String toString() { return getAsString(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java index 8e2e640b8b..877a379dad 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java @@ -133,6 +133,11 @@ default BaseBlock applyBlock(BlockVector3 position) { return toBaseBlock(); } + /** + * Gets a String representation of this BlockStateHolder, in the format expected by WorldEdit's block parsers. + * + * @return a string representation + */ default String getAsString() { if (getStates().isEmpty()) { return this.getBlockType().id(); From 62632448b4fedaf9dc4b543c664c476ff906ba36 Mon Sep 17 00:00:00 2001 From: Madeline Miller Date: Sat, 6 Jul 2024 20:51:29 +1000 Subject: [PATCH 2/8] Release 7.3.4 --- CHANGELOG.txt | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 48049b6456..e7d6c8e527 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,7 @@ 7.3.4 - Added support for 1.21 +- Fixed an issue where //drawsel can prevent using //world overrides in some situation +- Improved performance of repeatedly getting string representations of a block 7.3.3 - [Sponge] Re-add Sponge support diff --git a/gradle.properties b/gradle.properties index 487a94ddd5..5291e96232 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=com.sk89q.worldedit -version=7.3.4-SNAPSHOT +version=7.3.4 org.gradle.jvmargs=-Xmx1500M org.gradle.parallel=true From 43b3b0308be78b87dc2d617692b1d53e7535d6db Mon Sep 17 00:00:00 2001 From: Madeline Miller Date: Sat, 6 Jul 2024 20:52:50 +1000 Subject: [PATCH 3/8] Back to SNAPSHOT for continued development --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 5291e96232..51078e9ed9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=com.sk89q.worldedit -version=7.3.4 +version=7.3.5-SNAPSHOT org.gradle.jvmargs=-Xmx1500M org.gradle.parallel=true From 27bd26607f497650c4bc295f0eb090cdac14f4df Mon Sep 17 00:00:00 2001 From: Octavia Togami Date: Sat, 6 Jul 2024 04:08:42 -0700 Subject: [PATCH 4/8] Update crowdin-distributor --- crowdin-distributor.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crowdin-distributor.sh b/crowdin-distributor.sh index 564dfe011c..deba5dbf08 100755 --- a/crowdin-distributor.sh +++ b/crowdin-distributor.sh @@ -2,7 +2,7 @@ set -e # For snapshots, please specify the full version (with date and time) -cdist_version="0.1.0-20210612.072458-9" +cdist_version="0.1.0-20240706.110724-10" cdist_path_version="$cdist_version" if [ -n "${cdist_version#*-}" ]; then From 84ad34c36f404498f8cc07ac744f1af22d12cf59 Mon Sep 17 00:00:00 2001 From: Maddy Miller Date: Sun, 7 Jul 2024 16:16:15 +1000 Subject: [PATCH 5/8] Shutdown executor service on disable (#2570) * Shutdown executor service on disable * also do CLI --- .../main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java | 1 + .../src/main/java/com/sk89q/worldedit/cli/CLIWorldEdit.java | 1 + .../main/java/com/sk89q/worldedit/fabric/FabricWorldEdit.java | 1 + .../java/com/sk89q/worldedit/neoforge/NeoForgeWorldEdit.java | 1 + .../main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java | 1 + 5 files changed, 5 insertions(+) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index a4167c0bb7..a84370da7c 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -327,6 +327,7 @@ public void onDisable() { config.unload(); } this.getServer().getScheduler().cancelTasks(this); + worldEdit.getExecutorService().shutdown(); } /** diff --git a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIWorldEdit.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIWorldEdit.java index d527790157..3a75d8f023 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIWorldEdit.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIWorldEdit.java @@ -205,6 +205,7 @@ public void onStopped() { WorldEdit worldEdit = WorldEdit.getInstance(); worldEdit.getSessionManager().unload(); worldEdit.getPlatformManager().unregister(platform); + WorldEdit.getInstance().getExecutorService().shutdown(); } public FileRegistries getFileRegistries() { diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorldEdit.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorldEdit.java index fb4c48277d..32066cf0d5 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorldEdit.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorldEdit.java @@ -299,6 +299,7 @@ private void onStopServer(MinecraftServer minecraftServer) { WorldEdit worldEdit = WorldEdit.getInstance(); worldEdit.getSessionManager().unload(); WorldEdit.getInstance().getEventBus().post(new PlatformUnreadyEvent(platform)); + WorldEdit.getInstance().getExecutorService().shutdown(); } private boolean skipEvents() { diff --git a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorldEdit.java b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorldEdit.java index 9f3d0beb77..6492442a80 100644 --- a/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorldEdit.java +++ b/worldedit-neoforge/src/main/java/com/sk89q/worldedit/neoforge/NeoForgeWorldEdit.java @@ -257,6 +257,7 @@ public void serverStopping(ServerStoppingEvent event) { WorldEdit worldEdit = WorldEdit.getInstance(); worldEdit.getSessionManager().unload(); WorldEdit.getInstance().getEventBus().post(new PlatformUnreadyEvent(platform)); + WorldEdit.getInstance().getExecutorService().shutdown(); } @SubscribeEvent diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java index 9134274ee6..6acb688238 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java @@ -244,6 +244,7 @@ public void serverStopping(StoppingEngineEvent event) { WorldEdit worldEdit = WorldEdit.getInstance(); worldEdit.getSessionManager().unload(); WorldEdit.getInstance().getEventBus().post(new PlatformUnreadyEvent(platform)); + WorldEdit.getInstance().getExecutorService().shutdown(); } @Listener From f31c2e65ea7429b8812c0aca5297e2b575740119 Mon Sep 17 00:00:00 2001 From: Maddy Miller Date: Sun, 7 Jul 2024 16:31:13 +1000 Subject: [PATCH 6/8] Remove <1.16 //drawsel max size handling (#2572) --- .../com/sk89q/worldedit/internal/cui/ServerCUIHandler.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java index 17a1ce642b..27042c23e4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java @@ -23,7 +23,6 @@ import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.entity.Player; -import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.RegionSelector; @@ -47,10 +46,7 @@ private ServerCUIHandler() { } public static int getMaxServerCuiSize() { - int dataVersion = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getDataVersion(); - - // 1.16 increased maxSize to 48. - return dataVersion >= 2566 ? 48 : 32; + return 48; } /** From 292dae65cb01929dc2158f09bdb19fdc82b3669f Mon Sep 17 00:00:00 2001 From: Maddy Miller Date: Fri, 12 Jul 2024 12:02:09 +1000 Subject: [PATCH 7/8] Use Bukkit Registry API where possible (#2573) --- .../worldedit/bukkit/WorldEditPlugin.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index a84370da7c..e1ae9079c3 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -63,8 +63,8 @@ import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.Registry; import org.bukkit.Tag; -import org.bukkit.block.Biome; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -208,14 +208,14 @@ private void setupWorldData() { @SuppressWarnings({ "unchecked" }) private void initializeRegistries() { // Biome - for (Biome biome : Biome.values()) { + Registry.BIOME.forEach(biome -> { if (!biome.name().equals("CUSTOM")) { String key = biome.getKey().toString(); BiomeType.REGISTRY.register(key, new BiomeType(key)); } - } + }); // Block & Item - for (Material material : Material.values()) { + Registry.MATERIAL.forEach(material -> { if (material.isBlock()) { BlockType.REGISTRY.register(material.getKey().toString(), new BlockType(material.getKey().toString(), blockState -> { // TODO Use something way less hacky than this. @@ -242,16 +242,13 @@ private void initializeRegistries() { if (material.isItem()) { ItemType.REGISTRY.register(material.getKey().toString(), new ItemType(material.getKey().toString())); } - } + }); // Entity - for (org.bukkit.entity.EntityType entityType : org.bukkit.entity.EntityType.values()) { - if (entityType == org.bukkit.entity.EntityType.UNKNOWN) { - // This doesn't have a key - skip it - continue; - } + Registry.ENTITY_TYPE.forEach(entityType -> { String key = entityType.getKey().toString(); EntityType.REGISTRY.register(key, new EntityType(key)); - } + }); + // ... :| GameModes.get(""); WeatherTypes.get(""); From 570ec87790f8d153bf1bf0aaa475dca5c5058e8b Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Fri, 19 Jul 2024 02:21:37 +0200 Subject: [PATCH 8/8] Fix queryRel for //deform and //brush deform --- .../src/main/java/com/sk89q/worldedit/EditSession.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 f39025cef4..6ec06f36a1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -2440,9 +2440,12 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u final DoubleArrayList queue = new DoubleArrayList<>(false); - for (BlockVector3 position : region) { + for (BlockVector3 targetBlockPosition : region) { + final Vector3 targetPosition = targetBlockPosition.toVector3(); + environment.setCurrentBlock(targetPosition); + // offset, scale - final Vector3 scaled = position.toVector3().subtract(zero).divide(unit); + final Vector3 scaled = targetPosition.subtract(zero).divide(unit); // transform expression.evaluate(new double[]{ scaled.x(), scaled.y(), scaled.z() }, timeout); @@ -2453,7 +2456,7 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u final BaseBlock material = world.getFullBlock(sourcePosition); // queue operation - queue.put(position, material); + queue.put(targetBlockPosition, material); } int affected = 0;