mirror of
https://github.com/xoo0524tw/SynapseAnticheat.git
synced 2026-12-05 21:46:01 +02:00
80 lines
3.3 KiB
Java
80 lines
3.3 KiB
Java
package net.synapselabs.anticheat.checks.block;
|
|
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import net.synapselabs.anticheat.AiAnticheatPlugin;
|
|
import net.synapselabs.anticheat.data.PlayerProfile;
|
|
import org.bukkit.GameMode;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.EventPriority;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.block.BlockBreakEvent;
|
|
import org.bukkit.event.block.BlockDamageEvent;
|
|
import org.bukkit.potion.PotionEffectType;
|
|
|
|
public class FastBreakCheck implements Listener {
|
|
private final AiAnticheatPlugin plugin;
|
|
private final Map<UUID, Long> startDamageTime = new ConcurrentHashMap<>();
|
|
|
|
public FastBreakCheck(AiAnticheatPlugin plugin) {
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
|
public void onDamage(BlockDamageEvent event) {
|
|
if (event.getPlayer().getGameMode() != GameMode.CREATIVE) {
|
|
this.startDamageTime.put(event.getPlayer().getUniqueId(), System.currentTimeMillis());
|
|
}
|
|
}
|
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
|
public void onBreak(BlockBreakEvent event) {
|
|
if (this.plugin.isSetupCompleted()) {
|
|
if (this.plugin.getConfig().getBoolean("detection.extra_checks.fastbreak.enabled", true)) {
|
|
Player player = event.getPlayer();
|
|
if (player.getGameMode() != GameMode.CREATIVE) {
|
|
Block block = event.getBlock();
|
|
Material type = block.getType();
|
|
float hardness = type.getHardness();
|
|
if (!(hardness <= 0.05F)) {
|
|
UUID uuid = player.getUniqueId();
|
|
Long startTime = this.startDamageTime.remove(uuid);
|
|
long now = System.currentTimeMillis();
|
|
if (startTime == null) {
|
|
if (hardness > 0.8F && !player.hasPotionEffect(PotionEffectType.FAST_DIGGING)) {
|
|
event.setCancelled(true);
|
|
this.flag(player, "FastBreak (Instant: No Damage Packet)");
|
|
}
|
|
} else {
|
|
long elapsedMs = now - startTime;
|
|
long minExpectedMs = Math.round(hardness * 200.0);
|
|
if (player.hasPotionEffect(PotionEffectType.FAST_DIGGING)) {
|
|
minExpectedMs /= 2L;
|
|
}
|
|
|
|
if (elapsedMs < minExpectedMs * 0.45 && minExpectedMs > 150L) {
|
|
event.setCancelled(true);
|
|
this.flag(player, String.format("FastBreak (%dms < %dms)", elapsedMs, minExpectedMs));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void flag(Player player, String reason) {
|
|
PlayerProfile profile = this.plugin.getDataManager().getOrCreate(player);
|
|
profile.incrementHardFlags(reason);
|
|
if (this.plugin.getConfig().getBoolean("logging.console.enabled", true)) {
|
|
this.plugin
|
|
.getLogger()
|
|
.info(String.format("[Extra-Check] Player '%s' flagged for '%s' | Hard Flags: %d", player.getName(), reason, profile.getHardFlags()));
|
|
}
|
|
}
|
|
}
|