Guarmanda / LootChest

Plugin to reload chest with hologram, particles, and editing menu
GNU General Public License v3.0
9 stars 21 forks source link

Identified issue with respawn timers #52

Closed milan252525 closed 6 months ago

milan252525 commented 11 months ago

Hello, I have identified issue with respawn timers and updated deprecated Bucket AsyncDelayedTasks.

The issue with timers

Current State

When a chest is scheduled to respawn in Utils.copychest method, exact time to respawn X is calculated (in seconds). Then a task is scheduled to run in exactly X * 20 ticks and it runs lc.spawn(false);. One of the checks that function does is running Lootchest.checkIfTimeToRespawn method. However this check calculates time to respawn again, this time let's call it Y. The issue is that X ends up being a tiny bit smaller than Y, so the checkIfTimeToRespawn will fail most of the times. I don't exactly know what the issue is, but I suspect that it might have something to do with server ticks and the task being scheduled too early. There might possibly even be a rounding error as respawn timers are set in seconds but are calculated later with a bigger precision - milliseconds.

My fix

I have added 5 additional seconds to X, so that the scheduled task with lc.spawn(false) runs a bit later. This results in Lootchest.checkIfTimeToRespawn never failing and chests keep respawning.

Honestly, I don't think my fix of adding 5 seconds is good enough to be a proper fix. My intention is to explain the issue, so that someone more experienced with plugin development can fix it properly, without having to spend too much time identifying it.