Skip to content

Stop /locate freezing the server for disabled structures (#116)#117

Merged
tastybento merged 1 commit into
developfrom
fix/structure-locate-freeze-116
Jul 9, 2026
Merged

Stop /locate freezing the server for disabled structures (#116)#117
tastybento merged 1 commit into
developfrom
fix/structure-locate-freeze-116

Conversation

@tastybento

Copy link
Copy Markdown
Member

Problem

Part of #116. Disabling a structure via world.structures cancels its AsyncStructureSpawnEvent so it is never placed — but that leaves the world's structure placement rules intact. Every structure search keeps proposing candidate positions that are then all cancelled, so the search can never succeed and scans outward to the radius cap.

This affects the whole search family, per StructuresLocateEvent's own javadoc:

  • the /locate command
  • Eyes of Ender
  • explorer / treasure maps
  • dolphins swimming to treasure
  • villager map trades (cartographer)

On a local test world, /locate structure minecraft:trial_chambers generated ~1,500 cancelled trial-chamber structure starts, scanning ~±9,000 blocks, and froze the main thread for 62 seconds, tripping the Paper Watchdog:

Locating element minecraft:trial_chambers took 62098 ms
[Paper Watchdog Thread/ERROR]: ... consider increasing timeout-time in spigot.yml ...

Fix

Handle io.papermc.paper.event.world.StructuresLocateEvent, which Paper fires before any structure search. In a CaveBlock world:

  • Remove disabled structures from the search target list.
  • If nothing enabled remains, cancel the event so the expensive scan is skipped entirely — the search returns "not found" instantly.
  • Mixed searches (e.g. a tag covering enabled + disabled structures) are narrowed to only the enabled ones.

Enabled structures, and searches in other worlds, are untouched. This sits alongside the existing AsyncStructureSpawnEvent handler:

  • AsyncStructureSpawnEvent → stops physical generation
  • StructuresLocateEvent → stops the search freeze

Testing

  • Verified on a local Paper/Purpur 1.21.11 server: /locate structure minecraft:trial_chambers now returns immediately instead of freezing for 62 s, with no flood of cancelled spawn events and no Watchdog error.
  • Added unit tests: all-disabled → cancelled; mixed → narrowed to enabled; all-enabled → untouched; outside the CaveBlock world → ignored.

Not covered here (follow-up)

The other half of #116 — a structure still generating in the initial spawn pre-gen area — stems from createWorlds() running before onEnable(), where the listener is registered, so the first chunks generate before suppression is active. That fix (register the listener before world creation) is a separate change and will follow.

🤖 Generated with Claude Code

Disabling a structure in `world.structures` cancels its
AsyncStructureSpawnEvent so it never gets placed, but leaves the world's
structure placement rules untouched. Every structure search — the
/locate command, Eyes of Ender, explorer/treasure maps, dolphins and
villager map trades — therefore keeps proposing candidate positions that
are all cancelled, so the search can never succeed and scans out to the
radius cap. On a test world, `/locate structure minecraft:trial_chambers`
generated ~1,500 cancelled structure starts and froze the main thread for
62 seconds, tripping the Watchdog.

Handle Paper's StructuresLocateEvent (fired before any structure search)
to remove disabled structures from the search list, and cancel outright
when nothing remains, so the search returns "not found" instantly instead
of scanning. Enabled structures and searches in other worlds are
untouched.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015GBGsNFUshypm5Sj8KQsEa
@sonarqubecloud

sonarqubecloud Bot commented Jul 9, 2026

Copy link
Copy Markdown

@tastybento tastybento merged commit 8b8b1a0 into develop Jul 9, 2026
3 checks passed
@tastybento tastybento deleted the fix/structure-locate-freeze-116 branch July 9, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant