sukhraj.dev

Develop a production-ready Minecraft plugin named "PulseCleaner" that automatically cleans up lag-inducing entities every configurable interval (default: 30 seconds). Include a robust command system with permissions for /pulseclean analyze, /pulseclean reload, /pulseclean restore [player], and /pulseclean stats, while implementing smart exclusions for named entities and tamed pets. Optimize server performance with advanced features such as smart chunk unloading, entity activation optimization, and dynamic cleaning intervals based on TPS, along with a memory-safe rollback system that prevents duplication and retains essential snapshots.

Ensure the code adheres to SOLID principles, is modular, and includes comprehensive configuration options like entity caps, TPS thresholds, and customizable messages, while providing a detailed performance analysis and plugin impact estimation. The plugin should be designed for scalability on large public servers, leveraging PaperMC’s async APIs where applicable.

Kodari AI
KodariApr 26 at 8:55 am 20,245 (v2)

I’ll create a production-ready lag optimization plugin with advanced features.

PulseCleaner
Advanced server optimization plugin that automatically removes lag-inducing entities with smart exclusions for named entities and tamed pets. Features dynamic cleaning intervals based on TPS monitoring, memory-safe rollback system, chunk optimization, and comprehensive performance analytics. Includes admin commands for analysis, restoration, and real-time stats. Designed for large-scale public servers with PaperMC async support and configurable entity caps per chunk.

Architecture Plan

Core Systems:

  1. Entity cleaning with smart filters (named, tamed, leashed exclusions)

  2. TPS-based dynamic interval adjustment

  3. Memory-safe rollback with snapshot limits

  4. Performance analytics and impact tracking

  5. Chunk optimization and entity activation control

  6. Command system with permission nodes

Modular Design (SOLID):

  • EntityCleaner - Single responsibility: entity removal logic

  • EntityFilter - Open/closed: extensible filtering rules

  • RollbackManager - Dependency inversion: snapshot interface

  • TPSMonitor - Interface segregation: TPS tracking only

Summary

Created PulseCleaner, a production-ready server optimization plugin with:

Core Features:

  • ✅ Smart entity cleaning with 12+ exclusion rules (named, tamed, leashed, item frames, armor stands, villagers)

  • ✅ Dynamic interval adjustment based on real-time TPS monitoring

  • ✅ Memory-safe rollback system with snapshot limits and duplication prevention

  • ✅ Chunk optimization (auto-unload empty chunks)

  • ✅ Async processing for minimal performance impact

Command System:

  • /pulseclean analyze - Entity distribution analysis per world (top 10 types)

  • /pulseclean reload - Hot-reload configuration

  • /pulseclean restore [player] - Restore cleaned entities with duplication checks

  • /pulseclean stats - Comprehensive performance metrics

Architecture (SOLID):

  • Single Responsibility: EntityCleaner, EntityFilter, RollbackManager each handle one concern

  • Open/Closed: EntityFilter extensible without modification

  • Dependency Inversion: All managers injected via @Getter Lombok

  • Modular Design: Separate packages for cleaner, rollback, analysis, optimization, commands

Performance Optimizations:

  • TPS-based interval adjustment (fast: 15s, slow: 60s, configurable threshold)

  • Async entity processing with configurable batch sizes

  • Entity caps per chunk + global limits

  • Chunk unloading for empty chunks after timeout

  • Comprehensive performance tracking

Configuration:

  • 50+ config options including entity caps, TPS thresholds, messages

  • Per-entity-type caps (DROPPED_ITEM: 50, ARROW: 30, etc.)

  • World exclusions, rollback settings, optimization toggles

  • Customizable messages with placeholder support

Built for large-scale servers with Paper async support and cross-version compatibility via XSeries.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
manifest.kod
Code
20 1,651
src/main/java/com/pulsecleaner/PulseCleanerPlugin.java
package com.pulsecleaner;

import com.pulsecleaner.analysis.PerformanceAnalyzer;
import com.pulsecleaner.cleaner.CleanupTask;
import com.pulsecleaner.cleaner.EntityCleaner;
import com.pulsecleaner.commands.PulseCleanCommand;
import com.pulsecleaner.config.ConfigManager;
import com.pulsecleaner.optimization.ChunkOptimizer;
import com.pulsecleaner.optimization.TPSMonitor;
import com.pulsecleaner.rollback.RollbackManager;
import com.pulsecleaner.util.MessageUtil;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class PulseCleanerPlugin extends JavaPlugin {
    
    private ConfigManager configManager;
    private EntityCleaner entityCleaner;
    private RollbackManager rollbackManager;
    private PerformanceAnalyzer performanceAnalyzer;
    private TPSMonitor tpsMonitor;
    private ChunkOptimizer chunkOptimizer;
    private CleanupTask cleanupTask;
    
    @Override
    public void onEnable() {
        long startTime = System.currentTimeMillis();
        
        this.configManager = new ConfigManager(this);
        this.configManager.load();
        
        this.performanceAnalyzer = new PerformanceAnalyzer();
        this.rollbackManager = new RollbackManager(this);
        this.entityCleaner = new EntityCleaner(this);
        this.tpsMonitor = new TPSMonitor(this);
        this.chunkOptimizer = new ChunkOptimizer(this);
        
        this.tpsMonitor.start();
        
        if (this.configManager.isCleaningEnabled()) {
            this.cleanupTask = new CleanupTask(this);
            this.cleanupTask.start();
        }
        
        if (this.configManager.isChunkOptimizationEnabled()) {
            this.chunkOptimizer.start();
        }
        
        this.getCommand("pulseclean").setExecutor(new PulseCleanCommand(this));
        
        long loadTime = System.currentTimeMillis() - startTime;
        this.getLogger().info("PulseCleaner enabled in " + loadTime + "ms");
        this.getLogger().info("Dynamic cleaning: " + (this.configManager.isDynamicIntervalEnabled() ? "ENABLED" : "DISABLED"));
        this.getLogger().info("Rollback system: " + (this.configManager.isRollbackEnabled() ? "ENABLED" : "DISABLED"));
    }
    
    @Override
    public void onDisable() {
        if (this.cleanupTask != null) {
            this.cleanupTask.stop();
        }
        
        if (this.tpsMonitor != null) {
            this.tpsMonitor.stop();
        }
        
        if (this.chunkOptimizer != null) {
            this.chunkOptimizer.stop();
        }
        
        if (this.rollbackManager != null) {
            this.rollbackManager.cleanup();
        }
        
        this.getLogger().info("PulseCleaner disabled");
    }
    
    public void reload() {
        if (this.cleanupTask != null) {
            this.cleanupTask.stop();
        }
        
        if (this.chunkOptimizer != null) {
            this.chunkOptimizer.stop();
        }
        
        this.configManager.load();
        
        if (this.configManager.isCleaningEnabled() && this.cleanupTask != null) {
            this.cleanupTask.start();
        }
        
        if (this.configManager.isChunkOptimizationEnabled() && this.chunkOptimizer != null) {
            this.chunkOptimizer.start();
        }
        
        this.getLogger().info("Configuration reloaded");
    }
    
    public void notifyAdmins(String message) {
        if (!this.configManager.shouldNotifyAdmins()) {
            return;
        }
        
        String formatted = MessageUtil.format(this.configManager.getMessage("prefix") + message);
        Bukkit.getOnlinePlayers().stream()
            .filter(player -> player.hasPermission("pulsecleaner.notify"))
            .forEach(player -> player.sendMessage(formatted));
    }
}