Skip to content

Commit 4726327

Browse files
authored
Merge pull request #2730 from EngineHub/ot/merge/7.3.x-into-master-mar-08-2025
Merge 7.3.x into master
2 parents 5311195 + 2be1150 commit 4726327

File tree

13 files changed

+115
-62
lines changed

13 files changed

+115
-62
lines changed

verification/src/changes/accepted-core-public-api-changes.json

+37
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,42 @@
2828
"CONSTRUCTOR_REMOVED"
2929
]
3030
}
31+
],
32+
"No one should be using these fields outside the class anyways": [
33+
{
34+
"type": "com.sk89q.worldedit.world.storage.FileMcRegionChunkStore",
35+
"member": "Class com.sk89q.worldedit.world.storage.FileMcRegionChunkStore",
36+
"changes": [
37+
"FIELD_REMOVED_IN_SUPERCLASS"
38+
]
39+
},
40+
{
41+
"type": "com.sk89q.worldedit.world.storage.McRegionChunkStore",
42+
"member": "Field cachedReader",
43+
"changes": [
44+
"FIELD_REMOVED"
45+
]
46+
},
47+
{
48+
"type": "com.sk89q.worldedit.world.storage.McRegionChunkStore",
49+
"member": "Field curFilename",
50+
"changes": [
51+
"FIELD_REMOVED"
52+
]
53+
},
54+
{
55+
"type": "com.sk89q.worldedit.world.storage.TrueZipMcRegionChunkStore",
56+
"member": "Class com.sk89q.worldedit.world.storage.TrueZipMcRegionChunkStore",
57+
"changes": [
58+
"FIELD_REMOVED_IN_SUPERCLASS"
59+
]
60+
},
61+
{
62+
"type": "com.sk89q.worldedit.world.storage.ZippedMcRegionChunkStore",
63+
"member": "Class com.sk89q.worldedit.world.storage.ZippedMcRegionChunkStore",
64+
"changes": [
65+
"FIELD_REMOVED_IN_SUPERCLASS"
66+
]
67+
}
3168
]
3269
}

worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -1825,9 +1825,10 @@ public int makeCone(BlockVector3 pos, Pattern block, double radiusX, double radi
18251825
final double radiusXPow = Math.pow(radiusX, 2);
18261826
final double radiusZPow = Math.pow(radiusZ, 2);
18271827
final double heightPow = Math.pow(height, 2);
1828+
final int layers = Math.abs(height);
18281829

1829-
for (int y = 0; y < height; ++y) {
1830-
double ySquaredMinusHeightOverHeightSquared = Math.pow(y - height, 2) / heightPow;
1830+
for (int y = 0; y < layers; ++y) {
1831+
double ySquaredMinusHeightOverHeightSquared = Math.pow(y - layers, 2) / heightPow;
18311832

18321833
forX:
18331834
for (int x = 0; x <= ceilRadiusX; ++x) {
@@ -1849,25 +1850,26 @@ public int makeCone(BlockVector3 pos, Pattern block, double radiusX, double radi
18491850
double xNext = Math.pow(x + thickness, 2) / radiusXPow
18501851
+ zSquaredOverRadiusZ - ySquaredMinusHeightOverHeightSquared;
18511852
double yNext = xSquaredOverRadiusX + zSquaredOverRadiusZ
1852-
- Math.pow(y + thickness - height, 2) / heightPow;
1853+
- Math.pow(y + thickness - layers, 2) / heightPow;
18531854
double zNext = xSquaredOverRadiusX + Math.pow(z + thickness, 2)
18541855
/ radiusZPow - ySquaredMinusHeightOverHeightSquared;
1855-
if (xNext <= 0 && zNext <= 0 && (yNext <= 0 && y + thickness != height)) {
1856+
if (xNext <= 0 && zNext <= 0 && (yNext <= 0 && y + thickness != layers)) {
18561857
continue;
18571858
}
18581859
}
18591860

18601861
if (distanceFromOriginMinusHeightSquared <= 0) {
1861-
if (setBlock(pos.add(x, y, z), block)) {
1862+
int yOffset = height < 0 ? -y : y;
1863+
if (setBlock(pos.add(x, yOffset, z), block)) {
18621864
++affected;
18631865
}
1864-
if (setBlock(pos.add(-x, y, z), block)) {
1866+
if (setBlock(pos.add(-x, yOffset, z), block)) {
18651867
++affected;
18661868
}
1867-
if (setBlock(pos.add(x, y, -z), block)) {
1869+
if (setBlock(pos.add(x, yOffset, -z), block)) {
18681870
++affected;
18691871
}
1870-
if (setBlock(pos.add(-x, y, -z), block)) {
1872+
if (setBlock(pos.add(-x, yOffset, -z), block)) {
18711873
++affected;
18721874
}
18731875
}

worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,10 @@ public void dispatchCUISetup(Actor actor) {
957957
public void dispatchCUISelection(Actor actor) {
958958
checkNotNull(actor);
959959

960-
if (!hasCUISupport && useServerCUI) {
961-
updateServerCUI(actor);
960+
if (!hasCUISupport) {
961+
if (useServerCUI) {
962+
updateServerCUI(actor);
963+
}
962964
return;
963965
}
964966

worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.google.common.collect.Lists;
2727
import com.google.common.collect.SetMultimap;
2828
import com.google.common.util.concurrent.ListeningExecutorService;
29-
import com.google.common.util.concurrent.MoreExecutors;
3029
import com.sk89q.worldedit.blocks.BaseItem;
3130
import com.sk89q.worldedit.entity.Player;
3231
import com.sk89q.worldedit.event.platform.BlockInteractEvent;
@@ -56,7 +55,6 @@
5655
import com.sk89q.worldedit.util.Direction;
5756
import com.sk89q.worldedit.util.Location;
5857
import com.sk89q.worldedit.util.asset.AssetLoaders;
59-
import com.sk89q.worldedit.util.concurrency.EvenMoreExecutors;
6058
import com.sk89q.worldedit.util.eventbus.EventBus;
6159
import com.sk89q.worldedit.util.formatting.text.TextComponent;
6260
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
@@ -123,8 +121,6 @@ public final class WorldEdit {
123121
@Deprecated
124122
private final EditSessionFactory editSessionFactory = new EditSessionFactory.EditSessionFactoryImpl();
125123
private final SessionManager sessions = new SessionManager(this);
126-
private final ListeningExecutorService executorService = MoreExecutors.listeningDecorator(
127-
EvenMoreExecutors.newBoundedCachedThreadPool(0, 1, 20, "WorldEdit Task Executor - %s"));
128124
private final Supervisor supervisor = new SimpleSupervisor();
129125
private final AssetLoaders assetLoaders = new AssetLoaders(this);
130126
private final SchematicsManager schematicsManager = new SchematicsManager(this);
@@ -192,7 +188,7 @@ public Supervisor getSupervisor() {
192188
* @return the executor service
193189
*/
194190
public ListeningExecutorService getExecutorService() {
195-
return executorService;
191+
return platformManager.getExecutorService();
196192
}
197193

198194
/**

worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java

+1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ public void rotate(Actor actor, LocalSession session,
242242

243243
@Command(
244244
name = "/flip",
245+
aliases = { "/mirror" },
245246
desc = "Flip the contents of the clipboard across the origin"
246247
)
247248
@CommandPermissions("worldedit.clipboard.flip")

worldedit-core/src/main/java/com/sk89q/worldedit/event/platform/PlatformInitializeEvent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/**
2525
* Fired when configuration has been loaded and the platform is in the
26-
* intialization stage.
26+
* initialization stage.
2727
*
2828
* <p>This event is fired once.</p>
2929
*/

worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java

+36-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
package com.sk89q.worldedit.extension.platform;
2121

22+
import com.google.common.collect.Maps;
23+
import com.google.common.util.concurrent.ListeningExecutorService;
24+
import com.google.common.util.concurrent.MoreExecutors;
2225
import com.sk89q.worldedit.LocalConfiguration;
2326
import com.sk89q.worldedit.LocalSession;
2427
import com.sk89q.worldedit.WorldEdit;
@@ -41,7 +44,9 @@
4144
import com.sk89q.worldedit.util.HandSide;
4245
import com.sk89q.worldedit.util.Location;
4346
import com.sk89q.worldedit.util.SideEffect;
47+
import com.sk89q.worldedit.util.concurrency.EvenMoreExecutors;
4448
import com.sk89q.worldedit.util.eventbus.Subscribe;
49+
import com.sk89q.worldedit.util.lifecycle.SimpleLifecycled;
4550
import com.sk89q.worldedit.world.World;
4651
import org.apache.logging.log4j.Logger;
4752

@@ -69,7 +74,8 @@ public class PlatformManager {
6974

7075
private final WorldEdit worldEdit;
7176
private final PlatformCommandManager platformCommandManager;
72-
private final List<Platform> platforms = new ArrayList<>();
77+
private final SimpleLifecycled<ListeningExecutorService> executorService;
78+
private final Map<Platform, Boolean> platforms = Maps.newHashMap();
7379
private final Map<Capability, Platform> preferences = new EnumMap<>(Capability.class);
7480
private @Nullable String firstSeenVersion;
7581
private final AtomicBoolean initialized = new AtomicBoolean();
@@ -84,6 +90,7 @@ public PlatformManager(WorldEdit worldEdit) {
8490
checkNotNull(worldEdit);
8591
this.worldEdit = worldEdit;
8692
this.platformCommandManager = new PlatformCommandManager(worldEdit, this);
93+
this.executorService = SimpleLifecycled.invalid();
8794

8895
// Register this instance for events
8996
worldEdit.getEventBus().register(this);
@@ -101,7 +108,7 @@ public synchronized void register(Platform platform) {
101108

102109
// Just add the platform to the list of platforms: we'll pick favorites
103110
// once all the platforms have been loaded
104-
platforms.add(platform);
111+
platforms.put(platform, false);
105112

106113
// Make sure that versions are in sync
107114
if (firstSeenVersion != null) {
@@ -126,7 +133,7 @@ public synchronized void register(Platform platform) {
126133
public synchronized boolean unregister(Platform platform) {
127134
checkNotNull(platform);
128135

129-
boolean removed = platforms.remove(platform);
136+
boolean removed = platforms.remove(platform) != null;
130137

131138
if (removed) {
132139
LOGGER.info("Unregistering " + platform.getClass().getCanonicalName() + " from WorldEdit");
@@ -212,7 +219,7 @@ private synchronized void choosePreferred() {
212219
Platform preferred = null;
213220
Preference highest = null;
214221

215-
for (Platform platform : platforms) {
222+
for (Platform platform : platforms.keySet()) {
216223
Preference preference = platform.getCapabilities().get(capability);
217224
if (preference != null && (highest == null || preference.isPreferredOver(highest))) {
218225
preferred = platform;
@@ -231,7 +238,7 @@ private synchronized void choosePreferred() {
231238
* @return a list of platforms
232239
*/
233240
public synchronized List<Platform> getPlatforms() {
234-
return new ArrayList<>(platforms);
241+
return new ArrayList<>(platforms.keySet());
235242
}
236243

237244
/**
@@ -284,6 +291,21 @@ public PlatformCommandManager getPlatformCommandManager() {
284291
return platformCommandManager;
285292
}
286293

294+
/**
295+
* Get the executor service. Internal, not for API use.
296+
*
297+
* @return the executor service
298+
*/
299+
public ListeningExecutorService getExecutorService() {
300+
return executorService.valueOrThrow();
301+
}
302+
303+
private static ListeningExecutorService createExecutor() {
304+
return MoreExecutors.listeningDecorator(
305+
EvenMoreExecutors.newBoundedCachedThreadPool(
306+
0, 1, 20, "WorldEdit Task Executor - %s"));
307+
}
308+
287309
/**
288310
* Get the current configuration.
289311
*
@@ -340,6 +362,10 @@ public void handlePlatformsRegistered(PlatformsRegisteredEvent event) {
340362
@Subscribe
341363
public void handleNewPlatformReady(PlatformReadyEvent event) {
342364
preferences.forEach((cap, platform) -> cap.ready(this, platform));
365+
platforms.put(event.getPlatform(), true);
366+
if (!executorService.isValid()) {
367+
executorService.newValue(createExecutor());
368+
}
343369
}
344370

345371
/**
@@ -348,6 +374,11 @@ public void handleNewPlatformReady(PlatformReadyEvent event) {
348374
@Subscribe
349375
public void handleNewPlatformUnready(PlatformUnreadyEvent event) {
350376
preferences.forEach((cap, platform) -> cap.unready(this, platform));
377+
platforms.put(event.getPlatform(), false);
378+
if (!platforms.containsValue(true)) {
379+
executorService.value().ifPresent(ListeningExecutorService::shutdownNow);
380+
executorService.invalidate();
381+
}
351382
}
352383

353384
@Subscribe

worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRestore.java

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.sk89q.worldedit.world.chunk.Chunk;
3030
import com.sk89q.worldedit.world.storage.ChunkStore;
3131
import com.sk89q.worldedit.world.storage.MissingChunkException;
32+
import org.apache.logging.log4j.LogManager;
33+
import org.apache.logging.log4j.Logger;
3234

3335
import java.io.IOException;
3436
import java.util.ArrayList;
@@ -41,6 +43,8 @@
4143
*/
4244
public class SnapshotRestore {
4345

46+
private static final Logger LOGGER = LogManager.getLogger();
47+
4448
private final Map<BlockVector2, ArrayList<BlockVector3>> neededChunks = new LinkedHashMap<>();
4549
private final ChunkStore chunkStore;
4650
private final EditSession editSession;
@@ -154,6 +158,7 @@ public void restore() throws MaxChangedBlocksException {
154158
} catch (MissingChunkException me) {
155159
missingChunks.add(chunkPos);
156160
} catch (IOException | DataException me) {
161+
LOGGER.info(() -> "Failed to load chunk at " + chunkPos, me);
157162
errorChunks.add(chunkPos);
158163
lastErrorMessage = me.getMessage();
159164
}

worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/McRegionChunkStore.java

+3-25
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232

3333
public abstract class McRegionChunkStore extends ChunkStore {
3434

35-
protected String curFilename = null;
36-
protected McRegionReader cachedReader = null;
37-
3835
/**
3936
* Get the filename of a region file.
4037
*
@@ -50,26 +47,14 @@ public static String getFilename(BlockVector2 position) {
5047

5148
protected McRegionReader getReader(BlockVector2 pos, String worldname) throws DataException, IOException {
5249
String filename = getFilename(pos);
53-
if (curFilename != null) {
54-
if (curFilename.equals(filename)) {
55-
return cachedReader;
56-
} else {
57-
try {
58-
cachedReader.close();
59-
} catch (IOException ignored) {
60-
}
61-
}
62-
}
6350
InputStream stream = getInputStream(filename, worldname);
64-
cachedReader = new McRegionReader(stream);
65-
//curFilename = filename;
66-
return cachedReader;
51+
return new McRegionReader(stream);
6752
}
6853

6954
@Override
7055
public LinCompoundTag getChunkData(BlockVector2 position, World world) throws DataException, IOException {
71-
McRegionReader reader = getReader(position, world.getName());
72-
try (var chunkStream = new DataInputStream(reader.getChunkInputStream(position))) {
56+
try (McRegionReader reader = getReader(position, world.getName());
57+
var chunkStream = new DataInputStream(reader.getChunkInputStream(position))) {
7358
return LinBinaryIO.readUsing(chunkStream, LinRootEntry::readFrom).value();
7459
}
7560
}
@@ -84,11 +69,4 @@ public LinCompoundTag getChunkData(BlockVector2 position, World world) throws Da
8469
*/
8570
protected abstract InputStream getInputStream(String name, String worldName) throws IOException, DataException;
8671

87-
@Override
88-
public void close() throws IOException {
89-
if (cachedReader != null) {
90-
cachedReader.close();
91-
}
92-
}
93-
9472
}

0 commit comments

Comments
 (0)