yoferox

in Minecraft spigot 1.21.11 and author: YoFeR0X use less tokens

📎 1 file 5,107 chars
📄
pasted-code-1777047048827.txt
txt 184 lines
▶
Create a production-ready Minecraft Paper plugin called SmartLag for Paper 1.21.x with Folia support if possible. The plugin’s purpose is to detect, diagnose, and report lag sources automatically in a simple, staff-friendly way.

Core goal

Make a plugin that continuously monitors server performance and, when lag is detected, identifies the most likely causes and presents them in a clear INVENTORY GUI and chat report. The plugin should be lightweight, efficient, configurable, and useful for real servers.

Main features

Build all of these features:

Real-time TPS / MSPT / ping / memory / chunk load monitoring
Automatic lag spike detection when TPS or MSPT crosses configurable thresholds
Detect and rank lag causes such as:
excessive entities
villager spam
hoppers
dropped items
chunk loaders
redstone activity
tile entities
mob farms
too many loaded chunks per player
suspiciously high block updates
excessive explosions
packets / movement spam
Scan chunks and produce a top lag sources list
Show which worlds, chunks, and players are contributing most
A staff INVENTORY GUI with clickable items for:
top lag chunks
top entity counts
top tile entities
top players loading chunks
recent lag spikes
server health overview
A /lagtop command that shows live lag sources
A /lagscan command that forces a full scan
A /laginfo command that shows current server health
A /lagclear command with safety confirmation to remove selected lag sources if enabled
Alerts to staff when lag is detected
Optional actionbar / title / bossbar warnings
Optional Discord webhook alerts
Optional console logs with compact summaries
Optional PlaceholderAPI support
Optional LuckPerms permission support
Optional hex color / MiniMessage support
Optional sound alerts
Optional scheduled auto-scans
Optional automatic reports every X minutes
Optional world-by-world breakdown
Optional per-player chunk load tracking
Optional heatmap-style chunk ranking
Optional teleport-to-chunk for staff
Optional click-to-run cleanup actions
Optional historical lag tracking with timestamps
Optional configurable thresholds per world
Optional filtering exclusions for protected regions, spawns, farms, etc.
Optional anti-spam protection so alerts do not flood chat
Advanced features to add

Also include many extra features so the plugin stands out:

A lag history system that stores previous spikes
A graph-like text summary or trend output for recent performance
A player impact analyzer showing who is loading the most chunks
A chunk activity profiler that scores chunks by likely cost
A mob density analyzer
A villager + hopper detector
A redstone pulse detector
A tile entity density detector
A chunk generation detector
A GC / memory pressure warning
A server startup baseline and automatic comparison
A safe mode that only reports and never clears anything
A cleanup mode for staff with confirmation
A maintenance mode that can temporarily reduce alert spam
A bypass permission for trusted players or worlds
A per-world blacklist/whitelist
A customizable INVENTORY GUI theme
A toggle for verbose vs compact output
A developer debug mode
A reload command
A fully documented config.yml
A messages.yml for all text
A permissions.yml or permission list
A no-dependency implementation unless a small dependency is truly needed
A clean plugin.yml
Proper version compatibility handling
Good performance optimization
Asynchronous scanning where safe, with main-thread access only when required
Avoid heavy loops every tick; use smart sampling and batching
Make sure it is safe on busy servers and does not create lag itself
Commands

Include at least these commands:

/lagtop
/lagscan
/laginfo
/lagclear
/lagalerts toggle
/laggui
/lagsettings
/lagreload
Permissions

Include a clean permission system like:

smartlag.admin
smartlag.view
smartlag.scan
smartlag.clear
smartlag.alerts
smartlag.INVENTORY GUI
smartlag.reload
smartlag.bypass
Configuration

Create a detailed config with options for:

TPS threshold
MSPT threshold
memory threshold
lag spike cooldown
scan interval
alert modes
INVENTORY GUI settings
sound settings
Discord webhook URL
worlds enabled
entity thresholds
hopper thresholds
villager thresholds
item thresholds
chunk limits
cleanup limits
debug mode
color settings
language text
automatic summaries
enabled detection modules
per-world overrides
Output requirements

Generate the full plugin source code with:

correct package structure
main class
listeners
managers
services
commands
INVENTORY GUI classes
config handling
utility classes
clean separation of concerns
comments where needed
ready-to-build project structure
Quality requirements

The code must be:

professional
readable
optimized
modular
easy to expand
safe for production
compatible with modern Paper APIs
not reliant on outdated APIs
not filled with placeholder code unless absolutely necessary
Final deliverables

Provide:

Full source code
File tree
plugin.yml
config.yml
messages.yml
Permission list
Build instructions
Any notes about Folia compatibility or limitations

Make the plugin feel like a real premium-quality staff tool, not a toy example.
Kodari AI
KodariApr 24 at 4:19 pm 43,237 (v2)
SmartLag
A production-ready server performance monitor for Paper 1.21.x. Continuously tracks TPS, MSPT, memory, ping, and chunk data, auto-detecting lag spikes and ranking sources by entity counts, tile entities, villagers, hoppers, dropped items, and redstone. Features a staff inventory GUI dashboard, /lagtop, /lagscan, /laginfo, /lagclear with confirmation, alert system with bossbar/actionbar/Discord webhook, lag history, chunk profiler, auto-scan scheduler, and full PlaceholderAPI support.

Planning class dependencies before writing:

  • Models (LagSpike, ChunkData, ScanResult) — no deps, written first

  • Utils (FormatUtil) — no deps

  • Config/Messages — depend on plugin instance only

  • Monitor (PerformanceMonitor, LagHistory, LagDetector) — depend on config + models

  • Scanner (ChunkScanner) — depends on models + config

  • Alerts (AlertManager, DiscordWebhook) — depends on config + messages + models

  • GUI framework → GUI implementations → depend on all managers

  • Commands — depend on all managers

  • Main class (SmartLag) — wires everything together, written last

Here’s a summary of what was built:

35 files — full production plugin:

Layer
Files
Resources
build.gradle
,
plugin.yml
,
config.yml
,
messages.yml
Models
LagSpike
,
ChunkData
,
ScanResult
Config
ConfigManager
,
MessagesManager
Monitor
PerformanceMonitor
(TPS/MSPT rolling history + trend),
LagHistory
,
LagDetector
(spike detection, auto-scan, auto-report schedulers)
Scanner
ChunkScanner
— main-thread safe, scores every chunk by entity/TE/villager/hopper/redstone/item weights
Alerts
AlertManager
(chat+actionbar+bossbar+sound),
DiscordWebhook
(async HTTP POST)
GUI Framework
InventoryGUI
,
InventoryButton
,
InventoryHandler
,
GUIManager
,
GUIListener
GUI Screens
MainDashboardGUI
,
TopChunksGUI
(teleport-to-chunk),
TopEntitiesGUI
,
LagHistoryGUI
Commands
/lagtop
,
/lagscan
,
/laginfo
(MSPT trend bar),
/lagclear
(with timed confirm),
/laggui
,
/lagalerts
,
/lagreload
,
/lagsettings
Hooks
PlaceholderHook
(9 placeholders),
PlayerConnectionListener

Build: ./gradlew jar → drop JAR into plugins/. No extra dependencies required.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
37 2,393
src/main/java/com/yofer0x/smartlag/SmartLag.java
package com.yofer0x.smartlag;

import com.yofer0x.smartlag.alert.AlertManager;
import com.yofer0x.smartlag.command.*;
import com.yofer0x.smartlag.config.ConfigManager;
import com.yofer0x.smartlag.config.MessagesManager;
import com.yofer0x.smartlag.inventory.gui.GUIListener;
import com.yofer0x.smartlag.inventory.gui.GUIManager;
import com.yofer0x.smartlag.listener.PlayerConnectionListener;
import com.yofer0x.smartlag.monitor.LagDetector;
import com.yofer0x.smartlag.monitor.LagHistory;
import com.yofer0x.smartlag.monitor.PerformanceMonitor;
import com.yofer0x.smartlag.scanner.ChunkScanner;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class SmartLag extends JavaPlugin {

    private ConfigManager configManager;
    private MessagesManager messagesManager;
    private PerformanceMonitor performanceMonitor;
    private LagHistory lagHistory;
    private LagDetector lagDetector;
    private ChunkScanner chunkScanner;
    private AlertManager alertManager;
    private GUIManager guiManager;

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

        configManager = new ConfigManager(this);
        messagesManager = new MessagesManager(this);
        lagHistory = new LagHistory(configManager);
        performanceMonitor = new PerformanceMonitor(this);
        chunkScanner = new ChunkScanner(this);
        alertManager = new AlertManager(this);
        lagDetector = new LagDetector(this);
        guiManager = new GUIManager();

        Bukkit.getPluginManager().registerEvents(new GUIListener(guiManager), this);
        Bukkit.getPluginManager().registerEvents(new PlayerConnectionListener(this), this);

        registerCommands();

        performanceMonitor.start();
        lagDetector.start();

        if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
            new com.yofer0x.smartlag.hook.PlaceholderHook(this).register();
            getLogger().info("PlaceholderAPI hooked.");
        }

        getLogger().info("SmartLag v" + getDescription().getVersion() + " by YoFeR0X enabled.");
    }

    @Override
    public void onDisable() {
        lagDetector.stop();
        performanceMonitor.stop();
        alertManager.destroy();
        getLogger().info("SmartLag disabled.");
    }

    private void registerCommands() {
        LagTopCommand lagTop = new LagTopCommand(this);
        LagInfoCommand lagInfo = new LagInfoCommand(this);
        LagClearCommand lagClear = new LagClearCommand(this);

        getCommand("lagtop").setExecutor(lagTop);
        getCommand("lagtop").setTabCompleter(lagTop);
        getCommand("laginfo").setExecutor(lagInfo);
        getCommand("laginfo").setTabCompleter(lagInfo);
        getCommand("lagclear").setExecutor(lagClear);
        getCommand("lagclear").setTabCompleter(lagClear);
        getCommand("lagscan").setExecutor(new LagScanCommand(this));
        getCommand("laggui").setExecutor(new LagGUICommand(this));
        getCommand("lagalerts").setExecutor(new LagAlertsCommand(this));
        getCommand("lagreload").setExecutor(new LagReloadCommand(this));
        getCommand("lagsettings").setExecutor(new LagSettingsCommand(this));
    }
}