🧹 X-ClearLagπŸ”Œ Developer API

X-Clearlag API Documentation v1.6

Welcome to the X-Clearlag developer API. This documentation will help you integrate your own plugins with our cleanup engine, or even extend its functionality using our custom Event API.

πŸ“¦ Getting Started

To use the API, ensure you have X-Clearlag installed on your server. You can access the API entry point via the XClearlagAPI class.

import com.fabian.xclearlag.api.XClearlagAPI;
 
XClearlagAPI api = XClearlagAPI.getInstance();

πŸš€ Common Operations

1. Trigger a Cleanup Programmatically

You can trigger any task defined in the config.yml manually via the API.

api.triggerCleanup("items-task", player, (removed) -> {
    player.sendMessage("Cleanup finished! Removed " + removed + " entities.");
});

2. Get Real-time TPS

Get the server’s current Ticks Per Second (TPS) as measured by our high-precision monitor.

double tps = api.getTPS();
System.out.println("Current Server Load: " + tps);

πŸ”” Custom Event API

X-Clearlag fires custom events through the standard Bukkit Event Bus. You can listen to them like any other event.

XPreClearEvent

Fired before the discovery phase begins.

[!TIP] This event is Cancellable. You can use it to prevent a cleanup from running under specific conditions.

@EventHandler
public void onPreClear(XPreClearEvent event) {
    String taskName = event.getTaskName();
    if (taskName.equals("critical-mobs")) {
        event.setCancelled(true); // Stop this specific cleanup
    }
}

XPostClearEvent

Fired after the entities have been removed from the world.

@EventHandler
public void onPostClear(XPostClearEvent event) {
    int removed = event.getEntitiesRemoved();
    Bukkit.broadcastMessage("X-Clearlag cleared " + removed + " entities!");
}

🧩 PlaceholderAPI Support

If you have PlaceholderAPI installed, you can use these tags anywhere:

  • %xclearlag_tps% β€” Current server TPS.
  • %xclearlag_total_removed% β€” Historical total of removed entities.
  • %xclearlag_next_clear_<task>% β€” Seconds until the next run of a specific task.

πŸ› οΈ Maven / Dependency

Currently, you should just depend on the JAR or the project’s artifact if you are building in the same workspace.

[!IMPORTANT] X-Clearlag v1.6 is Universal and Folia-Ready. The API works exactly the same on Spigot, Paper, and Folia.