thedutchpianoman_

Develop a Minecraft plugin named "Vacuum" for Paper 26.1.2 that automatically removes dropped items from the ground after a configurable duration (default: 5 minutes), while excluding zombies. Implement a countdown feature that sends a warning message in chat when there is 1 minute left before item removal. Ensure all settings, including the item removal time, are easily adjustable in a configuration file.

Kodari AI
KodariOct 10 at 1:36 pm 1
ItemVacuum
Automatically removes dropped items from the ground after a configurable duration (default: 5 minutes) while excluding zombie-dropped items. Features a countdown warning system that notifies players in chat when items have 1 minute remaining before removal. All settings, including removal time and warning threshold, are configurable via a YAML configuration file. Uses a scheduled task system to track item age and remove expired items efficiently, with zombie-dropped items permanently exempt from cleanup.
  1. Create the Paper plugin entry point and scheduled item cleanup.

  2. Add per-item one-minute warnings while limiting cleanup to dropped items, so zombies are untouched.

  3. Put the removal time, warning time, scan interval, and message in config.yml.

Created Vacuum for Paper 26.1.2. It removes dropped item entities after the configured age, warns players once as each item enters its final minute, and leaves zombies and other mobs untouched.

Adjust the removal time, warning time, scan interval, and warning message in src/main/resources/config.yml.

thedutchpianoman_

it doesnt work, it just says in chat that it is going to remove the items but after 1 minute it doesnt remove all the items on the ground. also make it so that the plugin also removes all items on the ground in the nether and the end.

Kodari AI
KodariOct 10 at 2:13 pm 1
  1. Fix the item age/countdown cleanup so items are removed reliably after the configured duration.

  2. Ensure cleanup scans every loaded world, including the Nether and End.

Cleanup is now scheduled when an item gets its warning, so it is removed after its remaining countdown instead of relying only on later age checks. The scan includes items in every loaded world, including the Nether and End; it does not force-load unloaded chunks.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 124
src/main/java/com/kodari/vacuum/VacuumPlugin.java
package com.kodari.vacuum;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Item;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

public final class VacuumPlugin extends JavaPlugin {
    private final Set<UUID> warnedItems = new HashSet<>();
    private long removalTimeTicks;
    private long warningTimeTicks;
    private BukkitTask cleanupTask;

    @Override
    public void onEnable() {
        saveDefaultConfig();

        long removalSeconds = Math.max(1, getConfig().getLong("item-removal-time-seconds", 300));
        long warningSeconds = Math.max(0, getConfig().getLong("warning-time-seconds", 60));
        long scanIntervalTicks = Math.max(1, getConfig().getLong("scan-interval-ticks", 20));
        removalTimeTicks = removalSeconds * 20L;
        warningTimeTicks = warningSeconds * 20L;

        cleanupTask = Bukkit.getScheduler().runTaskTimer(this, this::scanItems, 20L, scanIntervalTicks);
    }

    @Override
    public void onDisable() {
        if (cleanupTask != null) {
            cleanupTask.cancel();
        }
        warnedItems.clear();
    }

    private void scanItems() {
        Set<UUID> liveItemIds = new HashSet<>();
        int warningCount = 0;
        long shortestRemainingTicks = Long.MAX_VALUE;

        for (World world : Bukkit.getWorlds()) {
            for (Item item : new ArrayList<>(world.getEntitiesByClass(Item.class))) {
                long livedTicks = item.getTicksLived();
                if (livedTicks >= removalTimeTicks) {
                    item.remove();
                    continue;
                }

                UUID itemId = item.getUniqueId();
                liveItemIds.add(itemId);
                long remainingTicks = removalTimeTicks - livedTicks;
                if (warningTimeTicks > 0 && remainingTicks <= warningTimeTicks && warnedItems.add(itemId)) {
                    warningCount++;
                    shortestRemainingTicks = Math.min(shortestRemainingTicks, remainingTicks);
                    Bukkit.getScheduler().runTaskLater(this, () -> {
                        if (item.isValid()) {
                            item.remove();
                        }
                    }, Math.max(1, remainingTicks));
                }
            }
        }

        warnedItems.retainAll(liveItemIds);
        if (warningCount > 0) {
            String warning = getConfig().getString("messages.warning", "&e%count% dropped item(s) will be removed in %time% second(s)!");
            if (warning != null) {
                warning = warning
                        .replace("%count%", String.valueOf(warningCount))
                        .replace("%time%", String.valueOf((shortestRemainingTicks + 19) / 20));
                Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', warning));
            }
        }
    }
}