Skip to content

Commit 76787ac

Browse files
committed
final optimizations
1 parent ffaf8fb commit 76787ac

20 files changed

+39
-42
lines changed

dependency-reduced-pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@
6161
</repositories>
6262
<dependencies>
6363
<dependency>
64-
<groupId>org.spigotmc</groupId>
65-
<artifactId>spigot-api</artifactId>
66-
<version>1.21.8-R0.1-SNAPSHOT</version>
64+
<groupId>io.papermc.paper</groupId>
65+
<artifactId>paper-api</artifactId>
66+
<version>1.21-R0.1-SNAPSHOT</version>
6767
<scope>provided</scope>
6868
</dependency>
6969
<dependency>
@@ -80,7 +80,7 @@
8080
</dependency>
8181
</dependencies>
8282
<properties>
83-
<java.version>17</java.version>
83+
<java.version>21</java.version>
8484
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
8585
</properties>
8686
</project>

pom.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<description>A plugin to send below-Y0 block data to Eaglercraft clients.</description>
1414

1515
<properties>
16-
<java.version>17</java.version>
16+
<java.version>21</java.version>
1717
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1818
</properties>
1919

@@ -91,11 +91,10 @@
9191
</repositories>
9292

9393
<dependencies>
94-
<!-- Spigot API -->
9594
<dependency>
96-
<groupId>org.spigotmc</groupId>
97-
<artifactId>spigot-api</artifactId>
98-
<version>1.21.8-R0.1-SNAPSHOT</version>
95+
<groupId>io.papermc.paper</groupId>
96+
<artifactId>paper-api</artifactId>
97+
<version>1.21-R0.1-SNAPSHOT</version>
9998
<scope>provided</scope>
10099
</dependency>
101100

src/main/java/net/potato/tuff/TuffX.java

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public class TuffX extends JavaPlugin implements Listener, PluginMessageListener
6767
private final ThreadLocal<short[]> threadLocalBlockArray = ThreadLocal.withInitial(() -> new short[4096]);
6868
private final ThreadLocal<byte[]> threadLocalLightArray = ThreadLocal.withInitial(() -> new byte[4096]);
6969
private final ThreadLocal<ByteArrayOutputStream> threadLocalOutStream = ThreadLocal.withInitial(() -> new ByteArrayOutputStream(8256));
70+
private final Set<WorldChunkKey> pendingChunkLoads = ConcurrentHashMap.newKeySet();
7071

7172
private void logDebug(String message) {
7273
if (debug) getLogger().log(Level.INFO, "[TuffX-Debug] " + message);
@@ -253,42 +254,20 @@ public void run() {
253254
if (cachedData != null) {
254255
sendPayloadsToPlayer(player, cachedData);
255256
checkIfInitialLoadComplete(player);
256-
continue;
257-
}
258-
259-
if (world.isChunkLoaded(key.x(), key.z())) {
260-
processAndSendChunk(player, world.getChunkAt(key.x(), key.z()));
261257
} else {
262-
queue.add(vec);
258+
if (world.isChunkLoaded(key.x(), key.z())) {
259+
processAndSendChunk(player, world.getChunkAt(key.x(), key.z()));
260+
} else {
261+
world.loadChunk(key.x(), key.z(), true);
262+
queue.add(vec);
263+
}
263264
}
264265
}
265266
}
266267
}
267268
}.runTaskTimer(this, 0L, 1L);
268269
}
269270

270-
@EventHandler(priority = EventPriority.MONITOR)
271-
public void onPlayerChangeWorld(PlayerChangedWorldEvent event) {
272-
Player player = event.getPlayer();
273-
UUID playerId = player.getUniqueId();
274-
275-
Queue<Vector> playerQueue = requestQueue.get(playerId);
276-
if (playerQueue != null && !playerQueue.isEmpty()) {
277-
logDebug("Player " + player.getName() + " changed worlds. Clearing " + playerQueue.size() + " pending chunk requests.");
278-
playerQueue.clear();
279-
}
280-
281-
if (initialChunksToProcess.remove(playerId) != null) {
282-
logDebug("Player " + player.getName() + " was in the middle of an initial chunk load. The process has been cancelled.");
283-
awaitingInitialBatch.remove(playerId);
284-
player.sendPluginMessage(this, CHANNEL, createLoadFinishedPayload());
285-
}
286-
287-
player.sendPluginMessage(this, CHANNEL, createDimensionPayload());
288-
289-
player.sendPluginMessage(this, CHANNEL, createBelowY0StatusPayload(enabledWorlds.contains(player.getWorld().getName())));
290-
}
291-
292271
private void processAndSendChunk(final Player player, final Chunk chunk) {
293272
if (chunk == null || !player.isOnline() || chunkProcessorPool.isShutdown()) {
294273
return;
@@ -301,10 +280,9 @@ private void processAndSendChunk(final Player player, final Chunk chunk) {
301280
final ChunkSnapshot snapshot = chunk.getChunkSnapshot(true, false, false);
302281
final Map<BlockData, int[]> conversionCache = threadLocalConversionCache.get();
303282
conversionCache.clear();
304-
305283
for (int sectionY = -4; sectionY < 0; sectionY++) {
306284
if (!player.isOnline()) {
307-
return;
285+
return;
308286
}
309287
try {
310288
byte[] payload = createSectionPayload(snapshot, chunk.getX(), chunk.getZ(), sectionY, conversionCache);
@@ -322,16 +300,36 @@ private void processAndSendChunk(final Player player, final Chunk chunk) {
322300
@Override
323301
public void run() {
324302
if (player.isOnline()) {
325-
for (byte[] payload : processedPayloads) {
326-
player.sendPluginMessage(TuffX.this, CHANNEL, payload);
327-
}
303+
sendPayloadsToPlayer(player, processedPayloads);
328304
checkIfInitialLoadComplete(player);
329305
}
330306
}
331307
}.runTask(this);
332308
});
333309
}
334310

311+
@EventHandler(priority = EventPriority.MONITOR)
312+
public void onPlayerChangeWorld(PlayerChangedWorldEvent event) {
313+
Player player = event.getPlayer();
314+
UUID playerId = player.getUniqueId();
315+
316+
Queue<Vector> playerQueue = requestQueue.get(playerId);
317+
if (playerQueue != null && !playerQueue.isEmpty()) {
318+
logDebug("Player " + player.getName() + " changed worlds. Clearing " + playerQueue.size() + " pending chunk requests.");
319+
playerQueue.clear();
320+
}
321+
322+
if (initialChunksToProcess.remove(playerId) != null) {
323+
logDebug("Player " + player.getName() + " was in the middle of an initial chunk load. The process has been cancelled.");
324+
awaitingInitialBatch.remove(playerId);
325+
player.sendPluginMessage(this, CHANNEL, createLoadFinishedPayload());
326+
}
327+
328+
player.sendPluginMessage(this, CHANNEL, createDimensionPayload());
329+
330+
player.sendPluginMessage(this, CHANNEL, createBelowY0StatusPayload(enabledWorlds.contains(player.getWorld().getName())));
331+
}
332+
335333
private void sendPayloadsToPlayer(Player player, List<byte[]> payloads) {
336334
new BukkitRunnable() {
337335
@Override

target/TuffX.jar

91 Bytes
Binary file not shown.
78 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
38 Bytes
Binary file not shown.
80 Bytes
Binary file not shown.
-212 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)