diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 48049b645..e7d6c8e52 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/crowdin-distributor.sh b/crowdin-distributor.sh index 564dfe011..deba5dbf0 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 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 f2815405e..a0a8672a9 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-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index a4167c0bb..e1ae9079c 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(""); @@ -327,6 +324,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 2818876c6..3d2f2c6c2 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 @@ -213,6 +213,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-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 64b52f6d8..b44216319 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -2433,9 +2433,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); @@ -2446,7 +2449,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; 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 17a1ce642..27042c23e 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; } /** 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 577579f65..609f7c7e2 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 00bc78895..690081c7b 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 8e2e640b8..877a379da 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(); 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 fb4c48277..32066cf0d 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 9f3d0beb7..6492442a8 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 9134274ee..6acb68823 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