Skip to content

Commit 47e1e6c

Browse files
committed
some bug fixes
1 parent 2ece7b0 commit 47e1e6c

File tree

10 files changed

+42
-2
lines changed

10 files changed

+42
-2
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.bukkit.util.Vector;
2525
import org.bukkit.event.block.BlockPhysicsEvent;
2626
import org.bukkit.event.player.PlayerTeleportEvent;
27+
import org.bukkit.event.player.PlayerChangedWorldEvent;
2728

2829
import java.io.*;
2930
import java.nio.charset.StandardCharsets;
@@ -45,6 +46,7 @@ public class TuffX extends JavaPlugin implements Listener, PluginMessageListener
4546

4647
private final Set<UUID> awaitingInitialBatch = ConcurrentHashMap.newKeySet();
4748
private final Map<UUID, AtomicInteger> initialChunksToProcess = new ConcurrentHashMap<>();
49+
private Set<String> enabledWorlds;
4850

4951
private BukkitTask processorTask;
5052

@@ -59,6 +61,9 @@ public void onEnable() {
5961
saveDefaultConfig();
6062
this.CHUNKS_PER_TICK = getConfig().getInt("chunks-per-tick", 6);
6163
this.debug = getConfig().getBoolean("debug-mode", false);
64+
this.enabledWorlds = new HashSet<>(getConfig().getStringList("enabled-worlds"));
65+
66+
logDebug("TuffX will be active in the following worlds: " + String.join(", ", this.enabledWorlds));
6267

6368
getServer().getMessenger().registerOutgoingPluginChannel(this, CHANNEL);
6469
getServer().getMessenger().registerIncomingPluginChannel(this, CHANNEL, this);
@@ -100,6 +105,12 @@ private void handleSingleChunkRequest(Player player, int chunkX, int chunkZ, UUI
100105

101106
private void handleIncomingPacket(Player player, Location loc, String action, int chunkX, int chunkZ, DataInputStream in) throws IOException {
102107
UUID playerId = player.getUniqueId();
108+
109+
if (!enabledWorlds.contains(player.getWorld().getName())) {
110+
if (awaitingInitialBatch.contains(playerId)) player.sendPluginMessage(this, CHANNEL, createLoadFinishedPayload());
111+
return;
112+
}
113+
103114
switch (action.toLowerCase()) {
104115
case "request_chunk":
105116
handleSingleChunkRequest(player,chunkX,chunkZ,playerId);
@@ -183,6 +194,25 @@ public void run() {
183194
}.runTaskTimer(this, 0L, 1L);
184195
}
185196

197+
@EventHandler(priority = EventPriority.MONITOR)
198+
public void onPlayerChangeWorld(PlayerChangedWorldEvent event) {
199+
Player player = event.getPlayer();
200+
UUID playerId = player.getUniqueId();
201+
202+
Queue<Vector> playerQueue = requestQueue.get(playerId);
203+
204+
if (playerQueue != null && !playerQueue.isEmpty()) {
205+
logDebug("Player " + player.getName() + " changed worlds. Clearing " + playerQueue.size() + " pending chunk requests from their old world.");
206+
playerQueue.clear();
207+
}
208+
209+
if (awaitingInitialBatch.remove(playerId)) {
210+
logDebug("Player " + player.getName() + " changed worlds during initial load. Cancelling.");
211+
player.sendPluginMessage(this, CHANNEL, createLoadFinishedPayload());
212+
initialChunksToProcess.remove(playerId);
213+
}
214+
}
215+
186216
private void processAndSendChunk(final Player player, final Chunk chunk) {
187217
if (chunk == null || !player.isOnline()) return;
188218

src/main/resources/config.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#debug mode
22
debug-mode: false
3+
34
#amount of chunks to send per tick to players
4-
chunks-per-tick: 6
5+
chunks-per-tick: 6
6+
7+
#worlds for y0 to be enabled in (experimental)
8+
enabled-worlds:
9+
- 'world'

target/TuffX.jar

645 Bytes
Binary file not shown.

target/classes/config.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#debug mode
22
debug-mode: false
3+
34
#amount of chunks to send per tick to players
4-
chunks-per-tick: 6
5+
chunks-per-tick: 6
6+
7+
#worlds for y0 to be enabled in (experimental)
8+
enabled-worlds:
9+
- 'world'
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
1.21 KB
Binary file not shown.

target/original-TuffX.jar

645 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)