ThrottleManager

class ThrottleManager(settingsSupplier: () -> ThrottleSettings, onlineLookup: (UUID) -> Player? = { null }, clock: () -> Long = System::currentTimeMillis)

Per-actor throttling of the despawn pipeline.

The global io.fairyfox.papermc.despawneditems.config.PerformanceSettings budget answers "how much relocation work may the server do this tick". This answers the different question the owner asked for: "how much of that budget may this player take" — so a single player dumping a double chest of junk cannot consume the whole pipeline while everyone else's items quietly expire.

Three composable strategies, selected by throttle.strategy:

StrategyWhat it boundsOwner's phrasing
ThrottleStrategy.RATErelocations per actor per time window (token bucket)"max per chunk of time"
ThrottleStrategy.CONCURRENTrelocations in flight per actor at once"max per each one"
ThrottleStrategy.FAIR_SHAREdrain order across actors, weighted"some users get more than others"
ThrottleStrategy.COMBINEDall three at once

State is per-actor and lazily created; purgeIdle evicts actors whose budgets are full and who have nothing in flight, so a long-running server does not accumulate a map entry per player who ever dropped an item.

Parameters

settingsSupplier

read fresh each call so /despi reload takes effect immediately.

onlineLookup

injected player lookup — tests pass a stub and need no server.

clock

injected time source in milliseconds — tests drive it deterministically.

Constructors

Link copied to clipboard
constructor(settingsSupplier: () -> ThrottleSettings, onlineLookup: (UUID) -> Player? = { null }, clock: () -> Long = System::currentTimeMillis)

Properties

Link copied to clipboard

Number of actors currently holding throttle state (diagnostics + tests).

Functions

Link copied to clipboard

Classifies one despawning item belonging to actor (null = ownerless drop).

Link copied to clipboard
fun inFlightFor(actor: UUID?): Int

Relocations currently in flight for actor.

Link copied to clipboard
fun onFinish(actor: UUID?)

Records that a relocation finished for actor. Never goes negative.

Link copied to clipboard
fun onStart(actor: UUID?)

Records that a relocation started for actor (concurrency accounting).

Link copied to clipboard
fun purgeIdle()

Drops per-actor state that is fully refilled and idle, bounding memory.

Link copied to clipboard
fun reset()

Clears all throttle state — used on reload and plugin disable.

Link copied to clipboard
fun shareFor(actor: UUID?): Int

Weighted round-robin ordering hint: how many items may be drained for actor in a single drain pass. Weight 3 drains three times as fast as weight 1 — the mechanism behind "some users get more despawned items than others".