Skip to content

Commit 8e2cee1

Browse files
committed
Add debug info for chunks loading during deletion
1 parent 7434e55 commit 8e2cee1

File tree

4 files changed

+82
-4
lines changed

4 files changed

+82
-4
lines changed

src/main/java/com/github/jikoo/regionerator/DebugLevel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public enum DebugLevel {
1010
OFF,
1111
LOW,
1212
MEDIUM,
13-
HIGH
13+
HIGH,
14+
EXTREME
1415

1516
}

src/main/java/com/github/jikoo/regionerator/DeletionRunnable.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,30 @@ private boolean isDeleteEligible(ChunkInfo chunkInfo) {
148148
} catch (InterruptedException ignored) {}
149149
}
150150

151+
if (plugin.debug(DebugLevel.HIGH)) {
152+
plugin.getDebugListener().monitorChunk(chunkInfo.getChunkX(), chunkInfo.getChunkZ());
153+
}
154+
155+
VisitStatus visitStatus;
151156
try {
152-
return chunkInfo.getVisitStatus().ordinal() < VisitStatus.VISITED.ordinal();
157+
// Calculate VisitStatus including protection hooks.
158+
visitStatus = chunkInfo.getVisitStatus();
153159
} catch (RuntimeException e) {
160+
// Interruption is not due to plugin shutdown, log.
154161
if (!this.isCancelled() && plugin.isEnabled()) {
155-
// Interruption is not due to plugin shutdown, log.
156162
plugin.debug(() -> String.format("Caught an exception getting VisitStatus: %s", e.getMessage()), e);
157163
}
164+
158165
// If an exception occurred, do not delete chunk.
159-
return false;
166+
visitStatus = VisitStatus.UNKNOWN;
160167
}
168+
169+
if (plugin.debug(DebugLevel.HIGH)) {
170+
plugin.getDebugListener().ignoreChunk(chunkInfo.getChunkX(), chunkInfo.getChunkZ());
171+
}
172+
173+
return visitStatus.ordinal() < VisitStatus.VISITED.ordinal();
174+
161175
}
162176

163177
public String getRunStats() {

src/main/java/com/github/jikoo/regionerator/Regionerator.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.github.jikoo.regionerator.commands.RegioneratorExecutor;
44
import com.github.jikoo.regionerator.hooks.Hook;
55
import com.github.jikoo.regionerator.hooks.PluginHook;
6+
import com.github.jikoo.regionerator.listeners.DebugListener;
67
import com.github.jikoo.regionerator.listeners.FlaggingListener;
78
import com.github.jikoo.regionerator.listeners.HookListener;
89
import com.github.jikoo.regionerator.util.yaml.Config;
@@ -44,6 +45,7 @@ public class Regionerator extends JavaPlugin {
4445
private Config config;
4546
private MiscData miscData;
4647
private BukkitTask flagging;
48+
private DebugListener debugListener;
4749

4850
@Override
4951
public void onEnable() {
@@ -68,6 +70,7 @@ public void onEnable() {
6870
miscData.checkWorldValidity();
6971

7072
chunkFlagger = new ChunkFlagger(this);
73+
debugListener = new DebugListener(this);
7174

7275
PluginCommand command = getCommand("regionerator");
7376
RegioneratorExecutor executor = new RegioneratorExecutor(this, deletionRunnables);
@@ -176,6 +179,10 @@ public void run() {
176179
}
177180
}.runTaskTimer(this, 0L, 1200L);
178181
}
182+
183+
if (debug(DebugLevel.HIGH)) {
184+
getServer().getPluginManager().registerEvents(debugListener, this);
185+
}
179186
}
180187

181188
public Config config() {
@@ -277,6 +284,10 @@ public ChunkFlagger getFlagger() {
277284
return this.chunkFlagger;
278285
}
279286

287+
DebugListener getDebugListener() {
288+
return debugListener;
289+
}
290+
280291
public boolean isPaused() {
281292
return this.paused.get();
282293
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.github.jikoo.regionerator.listeners;
2+
3+
import com.github.jikoo.regionerator.DebugLevel;
4+
import com.github.jikoo.regionerator.Regionerator;
5+
import java.util.HashSet;
6+
import java.util.Set;
7+
import java.util.logging.Level;
8+
import org.bukkit.Chunk;
9+
import org.bukkit.event.EventHandler;
10+
import org.bukkit.event.Listener;
11+
import org.bukkit.event.world.ChunkLoadEvent;
12+
13+
/**
14+
* Listener used for additional debugging info.
15+
*
16+
* @author Jikoo
17+
*/
18+
public class DebugListener implements Listener {
19+
20+
private final Regionerator plugin;
21+
private final Set<Long> badChunkHashes;
22+
23+
public DebugListener(Regionerator plugin) {
24+
this.plugin = plugin;
25+
this.badChunkHashes = new HashSet<>();
26+
}
27+
28+
@EventHandler
29+
public void onChunkLoad(ChunkLoadEvent event) {
30+
if (badChunkHashes.contains(getHash(event.getChunk()))) {
31+
plugin.debug(DebugLevel.HIGH, () -> String.format("Chunk loaded while being checked at %s, %s", event.getChunk().getX(), event.getChunk().getZ()));
32+
plugin.debug(DebugLevel.EXTREME, () -> plugin.getLogger().log(Level.INFO, "Chunk load trace", new Throwable()));
33+
}
34+
}
35+
36+
public void monitorChunk(int chunkX, int chunkZ) {
37+
badChunkHashes.add(getHash(chunkX, chunkZ));
38+
}
39+
40+
public void ignoreChunk(int chunkX, int chunkZ) {
41+
badChunkHashes.remove(getHash(chunkX, chunkZ));
42+
}
43+
44+
private long getHash(Chunk chunk) {
45+
return getHash(chunk.getX(), chunk.getZ());
46+
}
47+
48+
private long getHash(long x, long z) {
49+
return z ^ (x << 32);
50+
}
51+
52+
}

0 commit comments

Comments
 (0)