Minecraft & PaperMC Plugin Integration
01
Load Configuration File
step-01.java
Java
private void loadAntileakConfig() { File myBestPluginDir = getDataFolder(); if (!myBestPluginDir.exists()) { myBestPluginDir.mkdirs(); } File antileakFile = new File(myBestPluginDir, "antileak.yml"); if (!antileakFile.exists()) { try { antileakFile.createNewFile(); this.antileakConfig = YamlConfiguration.loadConfiguration(antileakFile); this.antileakConfig.set("license.key", "your-license-key-here"); this.antileakConfig.save(antileakFile); } catch (IOException e) { e.printStackTrace(); } } else { this.antileakConfig = YamlConfiguration.loadConfiguration(antileakFile); }}02
License Validation with Retry Logic
step-02.java
Java
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 void validateLicense() { String productId = antileakConfig.getString("license.product-id", ""); String licenseKey = antileakConfig.getString("license.key", ""); getServer().getScheduler().runTaskAsynchronously(this, () -> { UlisesLib ulib = new UlisesLib(); int attempts = 0; while (attempts < 5) { llIIllll.I result = ulib.verifyLicense(productId, licenseKey); if (result.isSuccess() && result.getData() != null) { String discordId = result.getData().getLicense().getDiscordId(); String expiresAt = result.getData().getLicense().getExpiresAt(); Bukkit.getConsoleSender().sendMessage( ChatColor.GRAY + "[" + ChatColor.DARK_AQUA + "MyBestPlugin" + ChatColor.GRAY + "] " + ChatColor.DARK_AQUA + "✓ Authentication successful. Powering up MyBestPlugin..." ); Bukkit.getConsoleSender().sendMessage( ChatColor.GRAY + "[" + ChatColor.DARK_AQUA + "MyBestPlugin" + ChatColor.GRAY + "] " + ChatColor.GRAY + " » Discord ID: " + ChatColor.AQUA + discordId ); Bukkit.getConsoleSender().sendMessage( ChatColor.GRAY + "[" + ChatColor.DARK_AQUA + "MyBestPlugin" + ChatColor.GRAY + "] " + ChatColor.GRAY + " » Expires: " + ChatColor.AQUA + expiresAt ); getServer().getScheduler().runTask(this, () -> { loadPlugin(); startSecurityChecks(); }); return; } attempts++; String code = ulib.getLastErrorCode(); if (!isTransientError(ulib) || attempts >= 5) { Bukkit.getConsoleSender().sendMessage( ChatColor.GRAY + "[" + ChatColor.DARK_AQUA + "MyBestPlugin" + ChatColor.GRAY + "] " + ChatColor.RED + "✗ License rejected (" + code + "). Disabling." ); getServer().getScheduler().runTask(this, () -> Bukkit.getPluginManager().disablePlugin(this)); return; } Bukkit.getConsoleSender().sendMessage( ChatColor.GRAY + "[" + ChatColor.DARK_AQUA + "MyBestPlugin" + ChatColor.GRAY + "] " + ChatColor.YELLOW + "⚠ Transient error (" + code + "). Retrying..." ); try { Thread.sleep(5000L * attempts); } catch (InterruptedException e) { Thread.currentThread().interrupt(); getServer().getScheduler().runTask(this, () -> Bukkit.getPluginManager().disablePlugin(this)); return; } } });}03
Periodic Security Checks
step-03.java
Java
private final java.util.concurrent.atomic.AtomicInteger consecutiveDefinitiveFailures = new java.util.concurrent.atomic.AtomicInteger(0); private void startSecurityChecks() { ScheduledExecutorService licenseService = Executors.newSingleThreadScheduledExecutor(); licenseService.scheduleAtFixedRate(() -> { 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); Bukkit.getConsoleSender().sendMessage( ChatColor.GRAY + "[" + ChatColor.DARK_AQUA + "MyBestPlugin" + ChatColor.GRAY + "] " + ChatColor.GREEN + "✓ License check passed." ); return; } if (isTransientError(ulib)) { Bukkit.getConsoleSender().sendMessage( ChatColor.GRAY + "[" + ChatColor.DARK_AQUA + "MyBestPlugin" + ChatColor.GRAY + "] " + ChatColor.YELLOW + "⚠ Transient error (" + ulib.getLastErrorCode() + "). Will retry next cycle." ); return; } int failures = consecutiveDefinitiveFailures.incrementAndGet(); if (failures >= 3) { Bukkit.getConsoleSender().sendMessage( ChatColor.GRAY + "[" + ChatColor.DARK_AQUA + "MyBestPlugin" + ChatColor.GRAY + "] " + ChatColor.RED + "✗ License rejected (" + ulib.getLastErrorCode() + "). Disabling." ); Bukkit.getScheduler().runTask(this, () -> Bukkit.getPluginManager().disablePlugin(this)); licenseService.shutdown(); } else { Bukkit.getConsoleSender().sendMessage( ChatColor.GRAY + "[" + ChatColor.DARK_AQUA + "MyBestPlugin" + ChatColor.GRAY + "] " + ChatColor.YELLOW + "⚠ License check failed (" + ulib.getLastErrorCode() + "). Attempt " + failures + "/3." ); } }, 10L, 10L, TimeUnit.MINUTES);}Built by Ulises - Citymoon Dynamics