Skip to content

Fix CraftLegacy warning and hopper task stopping on stack size change#90

Merged
ptthanh02 merged 3 commits into
mainfrom
copilot/fix-craftlegacy-warning
Nov 1, 2025
Merged

Fix CraftLegacy warning and hopper task stopping on stack size change#90
ptthanh02 merged 3 commits into
mainfrom
copilot/fix-craftlegacy-warning

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 1, 2025

Addresses two issues: (1) CraftLegacy initialization warning appearing in logs, and (2) hoppers stopping item transfer when spawner stack size changes.

Changes

Remove legacy material support trigger

  • Remove DynamicMaterialDetector class that was iterating through Material.values() in static initializer, which triggers CraftLegacy initialization
  • Replace dynamic material detection with static set of known spawner info materials in SpawnerMenuAction (PLAYER_HEAD, SPAWNER, ZOMBIE_HEAD, SKELETON_SKULL, WITHER_SKELETON_SKULL, CREEPER_HEAD, PIGLIN_HEAD, DRAGON_HEAD)
  • Add EntityType validation in EntityLootRegistry to skip entity types not available in current server version
  • Keep getState(false) as it's not the source of the warning

Fix hopper task continuity on stack size changes

  • Add HopperHandler.restartHopperForSpawner() to stop and restart hopper tasks when spawner virtual inventory is recreated
  • Call from SpawnerData.updateStackSize() after inventory recreation to maintain hopper task with fresh references
// SpawnerData.updateStackSize()
VirtualInventory newInventory = new VirtualInventory(this.maxSpawnerLootSlots);
transferItemsToNewInventory(currentItems, newInventory);
this.virtualInventory = newInventory;

// Restart hopper task with new inventory reference
if (plugin.getHopperHandler() != null) {
    plugin.getHopperHandler().restartHopperForSpawner(this.spawnerLocation);
}

The hopper task was holding a stale inventory reference after stack size modification, causing transfer operations to fail silently.

Version compatibility improvements

  • EntityLootRegistry now validates both entity types and materials, logging warnings and skipping entries not available in the current Minecraft version
  • Prevents loading incompatible mob configurations or items from newer/older versions
Original prompt

[09:19:37 INFO]: [SmartSpawner] Enabling SmartSpawner v1.5.5
[09:19:38 INFO]: [SmartSpawner] Running on standard Paper server.
[09:19:38 INFO]: [SmartSpawner] Successfully connected to Vault & Economy provider: EssentialsX Economy
[09:19:39 INFO]: [SmartSpawner] No compatible shop plugins found. Shop integration is disabled.
[09:19:39 INFO]: [SmartSpawner] Loaded storage GUI layout: default
[09:19:39 INFO]: [SmartSpawner] Loaded main GUI layout: default
[09:19:40 WARN]: [org.bukkit.craftbukkit.legacy.CraftLegacy] Initializing Legacy Material Support. Unless you have legacy plugins and/or data this is a bug!
[09:20:01 INFO]: [SmartSpawner] Initial spawner load complete. Loaded: 8357, Pending (missing worlds): 0
[09:20:01 INFO]: [SmartSpawner] SmartSpawner has been enabled! (Loaded in 23952ms)

Find and remove the source of the CraftLegacy Warning
When spawner and hopper were use changing the stacksize causing the hopper to stop working (stop sucking items from spawner inv)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@ptthanh02 ptthanh02 marked this pull request as ready for review November 1, 2025 02:30
Co-authored-by: ptthanh02 <73684260+ptthanh02@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CraftLegacy warning related to SmartSpawner Fix CraftLegacy warning and hopper task stopping on stack size change Nov 1, 2025
Copilot AI requested a review from ptthanh02 November 1, 2025 02:39
@ptthanh02
Copy link
Copy Markdown
Contributor

@copilot reverse to getState(false). I found the problem it is because in the code there is DynamicMaterialDetector looping through material, can we remove it since we have SpawnerMobHeadTexture & MobHeadConfig which taking care of the texture already, also can check if EntityLootRegistry have smart mob version loading to avoid older version load mob and item from later version

…ntity type validation

Co-authored-by: ptthanh02 <73684260+ptthanh02@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 1, 2025

@copilot reverse to getState(false). I found the problem it is because in the code there is DynamicMaterialDetector looping through material, can we remove it since we have SpawnerMobHeadTexture & Mob...

Done in commit fcd536d.

Changes:

  1. Reverted to getState(false) - kept as requested
  2. Removed DynamicMaterialDetector class - this was causing CraftLegacy warning via Material.values() iteration in static initializer
  3. Replaced with static Set.of() containing known spawner info materials in SpawnerMenuAction
  4. Added EntityType validation in EntityLootRegistry to skip entities not available in current version (logs warning and continues)
  5. Existing Material validation already handles items from incompatible versions

The CraftLegacy warning was triggered by Material.values() loop, not getState(false). SpawnerMobHeadTexture & MobHeadConfig continue to handle textures, and EntityLootRegistry now has smart version loading for both entity types and materials.

@ptthanh02 ptthanh02 merged commit 9596430 into main Nov 1, 2025
2 checks passed
@ptthanh02 ptthanh02 deleted the copilot/fix-craftlegacy-warning branch November 1, 2025 03:20
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.

2 participants