Files
src
pom.xml
Code
10 980
src/main/java/com/anticlient/antimoddetect/AntiModDetect.java
package com.anticlient.antimoddetect;
import com.anticlient.antimoddetect.command.DetectCommand;
import com.anticlient.antimoddetect.detection.DetectionManager;
import com.anticlient.antimoddetect.detection.DetectionListener;
import com.anticlient.antimoddetect.config.ConfigManager;
import com.anticlient.antimoddetect.punishment.PunishmentManager;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
@Getter
public class AntiModDetect extends JavaPlugin {
@Getter
private static AntiModDetect instance;
private ConfigManager configManager;
private DetectionManager detectionManager;
private PunishmentManager punishmentManager;
private ProtocolManager protocolManager;
private BukkitTask scanTask;
@Override
public void onEnable() {
instance = this;
saveDefaultConfig();
this.configManager = new ConfigManager(this);
this.protocolManager = ProtocolLibrary.getProtocolManager();
this.punishmentManager = new PunishmentManager(this);
this.detectionManager = new DetectionManager(this);
getServer().getPluginManager().registerEvents(new DetectionListener(this), this);
new DetectCommand(this).register();
scheduleScanTask();
getLogger().info("AntiModDetect enabled. Monitoring " + configManager.getModKeys().size() + " mod(s).");
}
@Override
public void onDisable() {
if (scanTask != null) {
scanTask.cancel();
}
if (detectionManager != null) {
detectionManager.cleanup();
}
getLogger().info("AntiModDetect disabled.");
}
public void reload() {
reloadConfig();
configManager.reload();
if (scanTask != null) {
scanTask.cancel();
scanTask = null;
}
scheduleScanTask();
}
private void scheduleScanTask() {
int intervalSeconds = configManager.getScanInterval();
if (intervalSeconds <= 0) return;
long intervalTicks = intervalSeconds * 20L;
scanTask = Bukkit.getScheduler().runTaskTimer(this, () -> {
for (org.bukkit.entity.Player player : Bukkit.getOnlinePlayers()) {
if (!player.hasPermission("antimoddetect.bypass")) {
detectionManager.startCheck(player);
}
}
}, intervalTicks, intervalTicks);
}
}