PHP: /** * @param ItemSpawnEvent $event */ public function itemSpawn ( ItemSpawnEvent $event ) { $entity = $event->getEntity(); $this->plugin->getScheduler()->scheduleDelayedTask(new ClosureTask(function (?int $currentTick) use($entity): void{ $entity->flagForDespawn(); }), 3 * 20); } I despawn items 3 seconds after they were thrown by a player by using a delayed task but what if multiple players throw a lot of items? It'd create a lot of delayed tasks and would probably cause lag as well. How should approach this instead?
I dont think running a lot of task that only runs one line of code would do any harm, the items probably would cause more lag than the tasks
Technically you can extend ItemEntity, change the part where it checks for the time to despawn and register with override