toxic_991

Develop a comprehensive Minecraft server optimization plugin designed for Paper, Purpur, and Spigot versions 1.21.11, ensuring compatibility for both Java and Bedrock players through Geyser and Floodgate. The plugin should focus on enhancing server performance with features like automatic lag reduction, smart mob limiting, dynamic view distance adjustments, and an easy-to-navigate INVENTORY GUI for Java players, while also providing a dedicated interface for Bedrock users. Include a clean configuration file with adjustable presets, permission support, and a suite of commands for monitoring and managing server performance, all built with modular Java code to minimize memory usage and prevent conflicts.

Kodari AI
KodariApr 25 at 8:45 am 20,443 (v2)

I’ll create a comprehensive server optimization plugin with GUI support for both Java and Bedrock players.

ServerOptimizer
A comprehensive server optimization plugin for Paper, Purpur, and Spigot 1.21+ with cross-platform support for Java and Bedrock players. Features automatic lag reduction, smart mob limiting, dynamic view distance adjustments, chunk management, and real-time TPS monitoring. Includes an intuitive inventory GUI for Java players and Bedrock-friendly interfaces. Offers configurable performance presets (low, balanced, aggressive), permission-based controls, and comprehensive commands for monitoring server health.

Perfect! I’ve created ServerOptimizer - a comprehensive server optimization plugin with all the requested features:

🎯 Key Features Implemented:

Performance Optimization

  • Real-time TPS monitoring with color-coded status indicators

  • Automatic lag reduction triggered when TPS drops below threshold

  • Smart mob limiting per chunk with configurable limits

  • Dynamic view distance adjustment based on server performance

  • Entity management with automatic item merging and excess entity removal

  • Memory management with automatic garbage collection

Cross-Platform Support

  • Bedrock detection via Floodgate integration

  • Action bar stats for Bedrock players instead of GUIs

  • Simplified interfaces option for Bedrock users

  • Full Java player support with interactive GUIs

Interactive GUI System (Java Players)

  • Main Menu - Central hub for all features

  • Performance Monitor - Live TPS, memory, and entity statistics

  • Mob Limiter - Configure and manage mob spawning

  • All GUIs use the lazy initialization pattern from documentation

Configuration Presets

  • Low - Minimal optimization for small servers

  • Balanced - Recommended for most servers (default)

  • Aggressive - Maximum optimization for high-load servers

Commands & Permissions

  • /optimize - Open GUI or manage settings

  • /performance (aliases: /tps, /lag) - View server stats

  • Full permission system with bypass support

Advanced Features

  • Chunk management with fast unloading

  • Redstone optimization with clock limiting

  • Hopper optimization with adjustable cooldowns

  • Automatic mob clearing with smart filtering

  • Multi-world support with per-world statistics

The plugin is built with modular architecture, uses XSeries for cross-version compatibility (1.21+), and includes Lombok for clean code. All features are configurable through the comprehensive config.yml with sensible defaults.

toxic_991

Errors

1 image attached
Kodari AI
KodariApr 25 at 8:52 am 4,014 (v2)

I can see the error is occurring in PerformanceMonitor.updateStats() at line 51. Let me examine the file to fix the issue.

The issue is that updateStats() is being called from an async task (line 33), but it’s accessing world.getEntities() which is NOT thread-safe and must be called on the main thread. This causes the crash you’re seeing.

Fixed! The crash was caused by accessing Bukkit’s world entities from an async thread. Changed runTaskTimerAsynchronously to runTaskTimer so all Bukkit API calls run safely on the main thread.

The plugin should now start without errors. Rebuild and restart your server.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
22 1,669
src/main/java/com/serveroptimizer/ServerOptimizer.java
package com.serveroptimizer;

import com.serveroptimizer.commands.OptimizeCommand;
import com.serveroptimizer.commands.PerformanceCommand;
import com.serveroptimizer.config.ConfigManager;
import com.serveroptimizer.inventory.gui.GUIListener;
import com.serveroptimizer.inventory.gui.GUIManager;
import com.serveroptimizer.performance.LagReducer;
import com.serveroptimizer.performance.MobLimiter;
import com.serveroptimizer.performance.PerformanceMonitor;
import com.serveroptimizer.performance.ViewDistanceManager;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class ServerOptimizer extends JavaPlugin {
    
    private ConfigManager configManager;
    private PerformanceMonitor performanceMonitor;
    private GUIManager guiManager;
    private MobLimiter mobLimiter;
    private ViewDistanceManager viewDistanceManager;
    private LagReducer lagReducer;
    
    @Override
    public void onEnable() {
        this.saveDefaultConfig();
        
        this.configManager = new ConfigManager(this);
        this.performanceMonitor = new PerformanceMonitor(this);
        this.guiManager = new GUIManager();
        this.mobLimiter = new MobLimiter(this);
        this.viewDistanceManager = new ViewDistanceManager(this);
        this.lagReducer = new LagReducer(this);
        
        this.registerEvents();
        this.registerCommands();
        this.startTasks();
        
        this.getLogger().info("ServerOptimizer has been enabled!");
        this.getLogger().info("Performance preset: " + this.configManager.getCurrentPreset());
        this.getLogger().info("Cross-platform support: " + (Bukkit.getPluginManager().getPlugin("floodgate") != null ? "Enabled" : "Disabled"));
    }
    
    @Override
    public void onDisable() {
        if (this.performanceMonitor != null) {
            this.performanceMonitor.shutdown();
        }
        this.getLogger().info("ServerOptimizer has been disabled!");
    }
    
    private void registerEvents() {
        GUIListener guiListener = new GUIListener(this.guiManager);
        Bukkit.getPluginManager().registerEvents(guiListener, this);
        Bukkit.getPluginManager().registerEvents(this.mobLimiter, this);
    }
    
    private void registerCommands() {
        this.getCommand("optimize").setExecutor(new OptimizeCommand(this));
        this.getCommand("performance").setExecutor(new PerformanceCommand(this));
    }
    
    private void startTasks() {
        this.performanceMonitor.startMonitoring();
        
        if (this.getConfig().getBoolean("view-distance.dynamic")) {
            this.viewDistanceManager.startDynamicAdjustment();
        }
        
        if (this.getConfig().getBoolean("auto-optimize.enabled")) {
            this.lagReducer.startAutoOptimization();
        }
        
        if (this.getConfig().getBoolean("auto-mob-clear.enabled")) {
            int interval = this.getConfig().getInt("auto-mob-clear.interval", 600) * 20;
            Bukkit.getScheduler().runTaskTimer(this, () -> {
                this.mobLimiter.clearMobs();
            }, interval, interval);
        }
    }
    
    public void reload() {
        this.reloadConfig();
        this.configManager = new ConfigManager(this);
        this.performanceMonitor.shutdown();
        this.performanceMonitor = new PerformanceMonitor(this);
        this.startTasks();
    }
}