S

I want you to create a Clean System where it clear all items on the ground and clear all hostile mobs but exclude those hostile mobs that has a nametag which is everything willbe configuranble at config.yml and also it has message.yml. This will work every 5 minutes with a modernize warning messages. I also wanted you to add a view distance limit for each world that will be configurable on config.yml. I also wanted you to name this plugin CloudClean with a author Velrion/Kryzi (one person). I also wanted you to add /clean reload, /clean hostile, and /clean items commands.

Kodari AI
KodariNov 6 at 3:49 am 3
CloudClean
CloudClean is a Minecraft server maintenance plugin that automatically clears all ground items and hostile mobs every 5 minutes, with configurable exceptions for named hostile mobs. It features modernized warning messages before each clean, fully customizable through config.yml and message.yml. The plugin includes a configurable view distance limit per world, and provides three commands: /clean reload to reload configuration files, /clean hostile to manually clear hostile mobs, and /clean items to manually clear ground items. All settings, including cleanup intervals, world-specific view distances, and mob exceptions, are easily adjustable in the configuration files. Developed by Velrion/Kryzi, this plugin ensures optimal server performance by regularly removing entities and items that can cause lag.
  1. Add scheduled item and hostile-mob cleanup with configurable warnings and named-mob protection.

  2. Add per-world view-distance limits and configurable messages.

  3. Add /clean reload, /clean hostile, and /clean items with permissions.

Created CloudClean for Paper, with five-minute cleanup, configurable warnings and named-mob protection. Per-world view distances and messages are configurable in config.yml and message.yml.

Commands: /clean reload, /clean hostile, and /clean items. Manual cleanup also respects world exclusions and named-mob protection.

S

I want you to make that it clears hostile mobs on a unloaded chunks across on every worlds that available on the server. I also wanted you to exclude the clearing of Warden, Wither, Elder Guardian, and Wandering Trader.

Kodari AI
KodariNov 7 at 7:38 am 2
  1. Extend hostile cleanup to unloaded chunks across all worlds.

  2. Exclude Wardens, Withers, Elder Guardians, and Wandering Traders.

  • Unloaded chunks will be cleaned when their entities load, avoiding mass chunk loading and server lag.

  • The four requested entity types will be protected alongside configured exclusions.

Updated CloudClean to protect Wardens, Withers, Elder Guardians, and Wandering Traders.

Hostile mobs in unloaded chunks are cleaned when their entities next load, rather than by force-loading chunks. Deferred removals aren’t included in the immediate cleanup count.

S

I want you to make it really clears every hostile mobs on a unloaded chunk because some of them making the server so lag.

Kodari AI
KodariNov 7 at 7:42 am 2

I’ll scan saved entity-region files and load affected chunks gradually, rather than waiting for players to visit them. Cleanup will run in the background; completion counts will still reflect the immediately loaded entities.

CloudClean now scans saved entity regions and gradually loads unloaded chunks to clear eligible hostile mobs. Named mobs and the requested protected types remain excluded.

The scan runs in the background, so immediate cleanup counts don’t include those removals. Unloaded mobs normally don’t tick; loading chunks to clean them can itself add server load.

S

I want you to add exclude villagers on the cleaning.

Kodari AI
KodariNov 8 at 11:26 pm 1

Villagers are already excluded because cleanup targets hostile mobs. I’ll add an explicit safeguard for them too.

Villagers now have an explicit cleanup exclusion, including in unloaded chunks. They were already protected because they aren’t hostile mobs.

S

Change the name of this plugin into NyraClean

Kodari AI
KodariWed at 1:17 pm 1
  • Rename the plugin and default message prefix to NyraClean.

  • Keep existing permission nodes so permissions don’t break.

Renamed the plugin to NyraClean. Existing cloudclean.* permission nodes remain unchanged.

After upgrading, copy your existing configuration and messages from plugins/CloudClean to plugins/NyraClean. Update the prefix in message.yml if you want existing messages to show the new name.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
6 450
src/main/java/com/velrion/cloudclean/CloudClean.java
package com.velrion.cloudclean;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Queue;
import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Enemy;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.EntitiesLoadEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.scheduler.BukkitTask;

public final class CloudClean extends JavaPlugin implements Listener, TabExecutor {
    private FileConfiguration messages;
    private BukkitTask cleanupTask;
    private final Map<UUID, Integer> originalViewDistances = new HashMap<>();
    private File cleanupStateFile;
    private FileConfiguration cleanupState;
    private NamespacedKey hostileGenerationKey;
    private final Queue<ChunkTarget> chunksToClean = new ArrayDeque<>();
    private boolean scanningChunks;
    private boolean loadingChunk;
    private BukkitTask chunkCleanupTask;

    private record ChunkTarget(UUID world, int x, int z) {}
    private record WorldRegion(UUID world, File directory) {}

    @Override
    public void onEnable() {
        saveDefaultConfig();
        saveResource("message.yml", false);
        cleanupStateFile = new File(getDataFolder(), "cleanup-state.yml");
        cleanupState = YamlConfiguration.loadConfiguration(cleanupStateFile);
        hostileGenerationKey = new NamespacedKey(this, "hostile-cleanup-generation");
        loadMessages();
        getServer().getPluginManager().registerEvents(this, this);
        getCommand("clean").setExecutor(this);
        getCommand("clean").setTabCompleter(this);
        applyViewDistances();
        startCleanup();
    }

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

    private void loadMessages() {
        messages = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "message.yml"));
    }

    private String message(String key, String... replacements) {
        String text = messages.getString(key, "");
        text = text.replace("%prefix%", messages.getString("prefix", ""));
        for (int i = 0; i + 1 < replacements.length; i += 2) {
            text = text.replace(replacements[i], replacements[i + 1]);
        }
        return ChatColor.translateAlternateColorCodes('&', text);
    }

    private void broadcast(String key, String... replacements) {
        String text = message(key, replacements);
        if (!text.isEmpty()) {
            Bukkit.broadcastMessage(text);
        }
    }

    private void startCleanup() {
        if (cleanupTask != null) {
            cleanupTask.cancel();
            cleanupTask = null;
        }
        if (!getConfig().getBoolean("cleanup.enabled", true)) {
            return;
        }
        final int interval = Math.max(1, getConfig().getInt("cleanup.interval-seconds", 300));
        cleanupTask = Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
            private int remaining = interval;

            @Override
            public void run() {
                remaining--;
                if (remaining <= 0) {
                    int[] counts = clean(getConfig().getBoolean("cleanup.items", true),
                            getConfig().getBoolean("cleanup.hostile-mobs", true));
                    if (getConfig().getBoolean("cleanup.broadcast-completion", true)) {
                        broadcast("complete", "%items%", String.valueOf(counts[0]),
                                "%hostile%", String.valueOf(counts[1]));
                    }
                    remaining = interval;
                } else if (getConfig().getBoolean("cleanup.warnings.enabled", true)
                        && getConfig().getIntegerList("cleanup.warnings.seconds").contains(remaining)) {
                    broadcast("warning", "%seconds%", String.valueOf(remaining));
                }
            }
        }, 20L, 20L);
    }

    private int[] clean(boolean items, boolean hostile) {
        int[] counts = new int[2];
        List<String> excludedWorlds = getConfig().getStringList("cleanup.excluded-worlds");
        List<String> excludedTypes = getConfig().getStringList("cleanup.excluded-hostile-types").stream()
                .map(type -> type.toUpperCase(Locale.ROOT)).collect(Collectors.toList());
        boolean protectNamed = getConfig().getBoolean("cleanup.protect-named-mobs", true);
        for (World world : Bukkit.getWorlds()) {
            if (excludedWorlds.contains(world.getName())) {
                continue;
            }
            if (hostile) {
                String key = world.getUID().toString();
                cleanupState.set(key, cleanupState.getLong(key, 0L) + 1L);
            }
            for (Entity entity : world.getEntities()) {
                if (items && entity instanceof Item) {
                    entity.remove();
                    counts[0]++;
                } else if (hostile && shouldRemoveHostile(entity, protectNamed, excludedTypes)) {
                    entity.remove();
                    counts[1]++;
                }
            }
        }
        if (hostile) {
            try {
                cleanupState.save(cleanupStateFile);
            } catch (IOException e) {
                getLogger().severe("Could not save hostile cleanup state: " + e.getMessage());
            }
            scanUnloadedChunks(excludedWorlds);
        }
        return counts;
    }

    private void scanUnloadedChunks(List<String> excludedWorlds) {
        if (scanningChunks || loadingChunk || !chunksToClean.isEmpty()) {
            return;
        }
        List<WorldRegion> regions = new ArrayList<>();
        for (World world : Bukkit.getWorlds()) {
            if (!excludedWorlds.contains(world.getName())) {
                regions.add(new WorldRegion(world.getUID(), new File(world.getWorldFolder(), "entities")));
            }
        }
        scanningChunks = true;
        Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
            List<ChunkTarget> found = new ArrayList<>();
            for (WorldRegion region : regions) {
                File[] files = region.directory().listFiles((dir, name) -> name.matches("r\\.-?\\d+\\.-?\\d+\\.mca"));
                if (files == null) {
                    continue;
                }
                for (File file : files) {
                    String[] parts = file.getName().split("\\.");
                    try (RandomAccessFile input = new RandomAccessFile(file, "r")) {
                        int regionX = Integer.parseInt(parts[1]);
                        int regionZ = Integer.parseInt(parts[2]);
                        for (int i = 0; i < 1024; i++) {
                            if (input.readInt() != 0) {
                                found.add(new ChunkTarget(region.world(), regionX * 32 + i % 32,
                                        regionZ * 32 + i / 32));
                            }
                        }
                    } catch (IOException | NumberFormatException e) {
                        getLogger().warning("Could not scan entity region " + file + ": " + e.getMessage());
                    }
                }
            }
            Bukkit.getScheduler().runTask(this, () -> {
                scanningChunks = false;
                chunksToClean.addAll(found);