Stop tree-cache scans from crashing worker ticks and log the real stacktrace.
Co-authored-by: Cursor <cursoragent@cursor.com>
@@ -48,6 +48,7 @@ import java.util.Map;
48
48
import java.util.Set;
49
49
import java.util.UUID;
50
50
import java.util.concurrent.ThreadLocalRandom;
51
import java.util.logging.Level;
51
52
52
53
final class FarmerManager {
53
54
private static final BlockFace[] HORIZONTAL = {
@@ -110,7 +111,11 @@ final class FarmerManager {
110
111
111
112
void tick(long elapsedTicks) {
112
113
clock += elapsedTicks;
113
treeIndex.tick();
114
try {
115
treeIndex.tick();
116
} catch (RuntimeException ex) {
117
plugin.getLogger().log(Level.WARNING, "Tree scan tick failed", ex);
118
}
114
119
// Snapshot: register/unregister can run mid-tick (chunk entity load/unload).
115
120
for (Brain brain : List.copyOf(brains.values())) {
116
121
if (!brain.golem.isValid() || brain.golem.isDead()) {
@@ -120,7 +125,10 @@ final class FarmerManager {
120
125
try {
121
126
brain.tick();
122
127
} catch (RuntimeException ex) {
123
plugin.getLogger().warning("Farmer " + brain.golem.getUniqueId() + " tick failed: " + ex.getMessage());
128
plugin.getLogger().log(Level.WARNING,
129
"Worker " + brain.golem.getUniqueId() + " (" + brain.role + ") tick failed",
130
ex);
131
brain.nextScanTick = clock + scanInterval;
124
132
}
125
133
}
126
134
}
@@ -48,6 +48,7 @@ import java.util.Map;48
import java.util.Set;48
import java.util.Set;49
import java.util.UUID;49
import java.util.UUID;50
import java.util.concurrent.ThreadLocalRandom;50
import java.util.concurrent.ThreadLocalRandom;51
import java.util.logging.Level;51
52
52
final class FarmerManager {53
final class FarmerManager {53
private static final BlockFace[] HORIZONTAL = {54
private static final BlockFace[] HORIZONTAL = {@@ -110,7 +111,11 @@ final class FarmerManager {110
111
111
void tick(long elapsedTicks) {112
void tick(long elapsedTicks) {112
clock += elapsedTicks;113
clock += elapsedTicks;113
treeIndex.tick();114
try {115
treeIndex.tick();116
} catch (RuntimeException ex) {117
plugin.getLogger().log(Level.WARNING, "Tree scan tick failed", ex);118
}114
// Snapshot: register/unregister can run mid-tick (chunk entity load/unload).119
// Snapshot: register/unregister can run mid-tick (chunk entity load/unload).115
for (Brain brain : List.copyOf(brains.values())) {120
for (Brain brain : List.copyOf(brains.values())) {116
if (!brain.golem.isValid() || brain.golem.isDead()) {121
if (!brain.golem.isValid() || brain.golem.isDead()) {@@ -120,7 +125,10 @@ final class FarmerManager {120
try {125
try {121
brain.tick();126
brain.tick();122
} catch (RuntimeException ex) {127
} catch (RuntimeException ex) {123
plugin.getLogger().warning("Farmer " + brain.golem.getUniqueId() + " tick failed: " + ex.getMessage());128
plugin.getLogger().log(Level.WARNING,129
"Worker " + brain.golem.getUniqueId() + " (" + brain.role + ") tick failed",130
ex);131
brain.nextScanTick = clock + scanInterval;124
}132
}125
}133
}126
}134
}@@ -122,12 +122,13 @@ final class TreeIndex {
122
122
if (origin == null) return null;
123
123
DetectedTree best = null;
124
124
double bestDistance = Double.MAX_VALUE;
125
for (DetectedTree tree : trees.values()) {
125
List<DetectedTree> stale = new ArrayList<>();
126
for (DetectedTree tree : List.copyOf(trees.values())) {
126
127
if (!tree.isAvailableFor(golemId)) continue;
127
128
if (unreachable.contains(tree.id())) continue;
128
129
if (!tree.hasLogWithin(origin, radius)) continue;
129
if (!tree.stillPresent(origin.getWorld())) {
130
invalidateTree(tree);
130
if (tree.logs().isEmpty() || !tree.stillPresent(origin.getWorld())) {
131
stale.add(tree);
131
132
continue;
132
133
}
133
134
BlockRef first = tree.standOrder().getFirst();
@@ -139,6 +140,7 @@ final class TreeIndex {
139
140
best = tree;
140
141
}
141
142
}
143
for (DetectedTree tree : stale) invalidateTree(tree);
142
144
return best;
143
145
}
144
146
@@ -147,6 +149,7 @@ final class TreeIndex {
147
149
}
148
150
149
151
void invalidateExpectedLog(BlockRef ref) {
152
if (ref == null) return;
150
153
UUID treeId = logToTree.get(ref);
151
154
if (treeId == null) {
152
155
invalidateChunk(ref.worldId(), ref.chunkX(), ref.chunkZ());
@@ -122,12 +122,13 @@ final class TreeIndex {122
if (origin == null) return null;122
if (origin == null) return null;123
DetectedTree best = null;123
DetectedTree best = null;124
double bestDistance = Double.MAX_VALUE;124
double bestDistance = Double.MAX_VALUE;125
for (DetectedTree tree : trees.values()) {125
List<DetectedTree> stale = new ArrayList<>();126
for (DetectedTree tree : List.copyOf(trees.values())) {126
if (!tree.isAvailableFor(golemId)) continue;127
if (!tree.isAvailableFor(golemId)) continue;127
if (unreachable.contains(tree.id())) continue;128
if (unreachable.contains(tree.id())) continue;128
if (!tree.hasLogWithin(origin, radius)) continue;129
if (!tree.hasLogWithin(origin, radius)) continue;129
if (!tree.stillPresent(origin.getWorld())) {130
if (tree.logs().isEmpty() || !tree.stillPresent(origin.getWorld())) {130
invalidateTree(tree);131
stale.add(tree);131
continue;132
continue;132
}133
}133
BlockRef first = tree.standOrder().getFirst();134
BlockRef first = tree.standOrder().getFirst();@@ -139,6 +140,7 @@ final class TreeIndex {139
best = tree;140
best = tree;140
}141
}141
}142
}143
for (DetectedTree tree : stale) invalidateTree(tree);142
return best;144
return best;143
}145
}144
146
@@ -147,6 +149,7 @@ final class TreeIndex {147
}149
}148
150
149
void invalidateExpectedLog(BlockRef ref) {151
void invalidateExpectedLog(BlockRef ref) {152
if (ref == null) return;150
UUID treeId = logToTree.get(ref);153
UUID treeId = logToTree.get(ref);151
if (treeId == null) {154
if (treeId == null) {152
invalidateChunk(ref.worldId(), ref.chunkX(), ref.chunkZ());155
invalidateChunk(ref.worldId(), ref.chunkX(), ref.chunkZ());