Complete PaperMC Java Plugin Example
Production-ready JavaPlugin lifecycle implementation incorporating configuration loading, initial license assertion, connection retry loop, and asynchronous periodic health checks.
MyBestPluginAntiCheat.java
Java
public class MyBestPluginAntiCheat extends JavaPlugin { private FileConfiguration antileakConfig; @Override public void onEnable() { loadAntileakConfig(); String productId = antileakConfig.getString("license.product-id"); String licenseKey = antileakConfig.getString("license.key"); if (productId.equals("your-product-id-here") || licenseKey.equals("your-license-key-here")) { getLogger().severe("License details not configured. Please edit antileak.yml"); Bukkit.getPluginManager().disablePlugin(this); return; } validateLicense(productId, licenseKey); } private void validateLicense(String productId, String licenseKey) { getServer().getScheduler().runTaskAsynchronously(this, () -> { UlisesLib ulib = new UlisesLib(); int attempts = 0; while (attempts < 5) { if (ulib.isLicenseValid(productId, licenseKey)) { String discordId = ulib.getDiscordId(productId, licenseKey); String expiresAt = ulib.getExpirationDate(productId, licenseKey); getLogger().info("License validated for Discord ID: " + discordId); getLogger().info("License expires: " + expiresAt); getServer().getScheduler().runTask(this, () -> { loadFeatures(); startPeriodicChecks(); }); return; } attempts++; String code = ulib.getLastErrorCode(); if (!isTransientError(ulib) || attempts >= 5) { getLogger().severe("License rejected (" + code + "). Disabling."); getServer().getScheduler().runTask(this, () -> Bukkit.getPluginManager().disablePlugin(this) ); return; } getLogger().warning("Transient error (" + code + "). Retrying..."); try { Thread.sleep(5000L * attempts); } catch (InterruptedException e) { Thread.currentThread().interrupt(); getServer().getScheduler().runTask(this, () -> Bukkit.getPluginManager().disablePlugin(this) ); return; } } }); } private boolean isTransientError(UlisesLib ulib) { String code = ulib.getLastErrorCode(); return code != null && (code.equals("NETWORK_ERROR") || code.equals("TIMEOUT") || code.equals("SERVER_ERROR") || code.equals("MAX_RETRIES") || code.equals("RATE_LIMIT") || code.equals("RATE_LIMIT_LOCAL")); } private final java.util.concurrent.atomic.AtomicInteger consecutiveDefinitiveFailures = new java.util.concurrent.atomic.AtomicInteger(0); private void startPeriodicChecks() { Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> { UlisesLib ulib = new UlisesLib(); String productId = antileakConfig.getString("license.product-id"); String licenseKey = antileakConfig.getString("license.key"); if (ulib.isLicenseValid(productId, licenseKey)) { consecutiveDefinitiveFailures.set(0); getLogger().info("Periodic license check passed."); return; } if (isTransientError(ulib)) { getLogger().warning("Transient error (" + ulib.getLastErrorCode() + "). Will retry next cycle."); return; } int failures = consecutiveDefinitiveFailures.incrementAndGet(); if (failures >= 3) { getLogger().severe("License rejected (" + ulib.getLastErrorCode() + "). Disabling."); Bukkit.getScheduler().runTask(this, () -> Bukkit.getPluginManager().disablePlugin(this) ); } else { getLogger().warning("License check failed (" + ulib.getLastErrorCode() + "). Attempt " + failures + "/3."); } }, 20L * 60 * 10, 20L * 60 * 10); }}Built by Ulises - Citymoon Dynamics