@@ -41,26 +41,21 @@ public void spawnLootToSpawner(SpawnerData spawner) {
4141 try {
4242 // Acquire dataLock to safely read spawn timing and configuration values
4343 // Use tryLock with short timeout to avoid blocking
44- boolean dataLockAcquired = false ;
4544 try {
46- dataLockAcquired = spawner .getDataLock ().tryLock (50 , java .util .concurrent .TimeUnit .MILLISECONDS );
45+ if (!spawner .getDataLock ().tryLock (50 , java .util .concurrent .TimeUnit .MILLISECONDS )) {
46+ // dataLock is held (likely stack size change), skip this cycle
47+ return ;
48+ }
4749 } catch (InterruptedException e ) {
4850 Thread .currentThread ().interrupt ();
4951 return ;
5052 }
51-
52- if (!dataLockAcquired ) {
53- // dataLock is held (likely stack size change), skip this cycle
54- return ;
55- }
56-
53+
5754 // Declare variables outside the try block so they're accessible in the async lambda
5855 final long currentTime = System .currentTimeMillis ();
5956 final long spawnTime ;
60- final EntityType entityType ;
6157 final int minMobs ;
6258 final int maxMobs ;
63- final String spawnerId ;
6459 final AtomicInteger usedSlots ;
6560 final AtomicInteger maxSlots ;
6661
@@ -81,10 +76,8 @@ public void spawnLootToSpawner(SpawnerData spawner) {
8176 }
8277
8378 // Important: Store the current values we need for async processing
84- entityType = spawner .getEntityType ();
8579 minMobs = spawner .getMinMobs ();
8680 maxMobs = spawner .getMaxMobs ();
87- spawnerId = spawner .getSpawnerId ();
8881 // Store currentTime to update lastSpawnTime after successful loot addition
8982 spawnTime = currentTime ;
9083 } finally {
@@ -289,7 +282,7 @@ private List<ItemStack> limitItemsToAvailableSlots(List<ItemStack> items, Spawne
289282 int remainingSlots = maxSlots - calculateSlots (simulatedInventory );
290283 if (remainingSlots > 0 ) {
291284 // Maximum items we can add in the remaining slots
292- long maxAddAmount = remainingSlots * maxStackSize - (currentAmount % maxStackSize );
285+ long maxAddAmount = ( long ) remainingSlots * maxStackSize - (currentAmount % maxStackSize );
293286 if (maxAddAmount > 0 ) {
294287 // Create a partial item
295288 ItemStack partialItem = item .clone ();
@@ -348,11 +341,9 @@ private void handleGuiUpdates(SpawnerData spawner) {
348341 Location loc = spawner .getSpawnerLocation ();
349342 World world = loc .getWorld ();
350343 if (world != null ) {
351- Scheduler .runLocationTask (loc , () -> {
352- world .spawnParticle (Particle .HAPPY_VILLAGER ,
353- loc .clone ().add (0.5 , 0.5 , 0.5 ),
354- 10 , 0.3 , 0.3 , 0.3 , 0 );
355- });
344+ Scheduler .runLocationTask (loc , () -> world .spawnParticle (Particle .HAPPY_VILLAGER ,
345+ loc .clone ().add (0.5 , 0.5 , 0.5 ),
346+ 10 , 0.3 , 0.3 , 0.3 , 0 ));
356347 }
357348 }
358349
@@ -385,19 +376,16 @@ public void preGenerateLoot(SpawnerData spawner, LootGenerationCallback callback
385376 }
386377
387378 try {
388- boolean dataLockAcquired = false ;
389379 try {
390- dataLockAcquired = spawner .getDataLock ().tryLock (50 , java .util .concurrent .TimeUnit .MILLISECONDS );
380+ if (!spawner .getDataLock ().tryLock (50 , java .util .concurrent .TimeUnit .MILLISECONDS )) {
381+ callback .onLootGenerated (Collections .emptyList (), 0 );
382+ return ;
383+ }
391384 } catch (InterruptedException e ) {
392385 Thread .currentThread ().interrupt ();
393386 callback .onLootGenerated (Collections .emptyList (), 0 );
394387 return ;
395388 }
396-
397- if (!dataLockAcquired ) {
398- callback .onLootGenerated (Collections .emptyList (), 0 );
399- return ;
400- }
401389
402390 final int minMobs ;
403391 final int maxMobs ;
@@ -465,17 +453,14 @@ public void addPreGeneratedLoot(SpawnerData spawner, List<ItemStack> items, int
465453 }
466454
467455 try {
468- boolean dataLockAcquired = false ;
469456 try {
470- dataLockAcquired = spawner .getDataLock ().tryLock (50 , java .util .concurrent .TimeUnit .MILLISECONDS );
457+ if (!spawner .getDataLock ().tryLock (50 , java .util .concurrent .TimeUnit .MILLISECONDS )) {
458+ return ;
459+ }
471460 } catch (InterruptedException e ) {
472461 Thread .currentThread ().interrupt ();
473462 return ;
474463 }
475-
476- if (!dataLockAcquired ) {
477- return ;
478- }
479464
480465 final long spawnTime = System .currentTimeMillis ();
481466 final boolean capacityCheck ;
0 commit comments