diff --git a/src/main/java/de/lasertec/camp/AntiCampManager.java b/src/main/java/de/lasertec/camp/AntiCampManager.java deleted file mode 100644 index f5b75f5..0000000 --- a/src/main/java/de/lasertec/camp/AntiCampManager.java +++ /dev/null @@ -1,149 +0,0 @@ -package de.lasertec.camp; - -import de.lasertec.LasertecPlugin; -import de.lasertec.game.Game; -import de.lasertec.player.LaserPlayer; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -/** - * Anti-Camp System. - * - * Erkennt Spieler die sich zu lange nicht bewegen und bestraft sie. - * - * Ablauf: - * 1. Position wird jede Sekunde geprüft - * 2. Hat sich der Spieler < camp-idle-radius Blöcke bewegt → idle-Zeit erhöhen - * 3. Nach warn-duration Sekunden → Warnung - * 4. Nach max-idle-seconds Sekunden → Strafe (Punkte-Abzug) - * - * Ausnahmen: - * - Spieler nahe der eigenen Basis (heilen) - * - Spieler die getroffen wurden (müssen zur Basis) - */ -public class AntiCampManager { - - private final LasertecPlugin plugin; - - /** UUID → letzte bekannte Position */ - private final Map lastPosition = new HashMap<>(); - /** UUID → Sekunden an gleicher Stelle */ - private final Map idleSeconds = new HashMap<>(); - /** UUID → wurde bereits gewarnt (true = Warnung lief, false = noch nicht) */ - private final Map warned = new HashMap<>(); - - public AntiCampManager(LasertecPlugin plugin) { - this.plugin = plugin; - } - - /** - * Wird vom Game-Task jede Sekunde aufgerufen. - * Prüft alle Spieler des Spiels auf Camping-Verhalten. - */ - public void tick(Game game) { - if (!plugin.getConfigManager().isAntiCampEnabled()) return; - - double idleRadius = plugin.getConfigManager().getCampIdleRadius(); - double excludeRadius = plugin.getConfigManager().getCampExcludeRadius(); - int maxIdle = plugin.getConfigManager().getCampMaxIdleSecs(); - int warnDuration = plugin.getConfigManager().getCampWarnDuration(); - String action = plugin.getConfigManager().getCampAction(); - int penalty = plugin.getConfigManager().getCampScorePenalty(); - - for (Player player : game.getOnline()) { - UUID uid = player.getUniqueId(); - LaserPlayer lp = game.getLP(uid); - if (lp == null) continue; - - // Getroffene Spieler vom Camp-Check ausnehmen - if (lp.isHit()) { - reset(uid); - continue; - } - - // Spieler nahe eigener Basis: ausschließen (Heilzone) - Location base = game.getArena().getBase(lp.getTeam()); - if (base != null && player.getLocation().distanceSquared(base) <= excludeRadius * excludeRadius) { - reset(uid); - continue; - } - - Location prev = lastPosition.get(uid); - Location curr = player.getLocation(); - - if (prev == null) { - lastPosition.put(uid, curr.clone()); - idleSeconds.put(uid, 0); - warned.put(uid, false); - continue; - } - - // Hat sich der Spieler bewegt? - double moved = prev.distanceSquared(curr); - if (moved > idleRadius * idleRadius) { - // Bewegt → Reset - lastPosition.put(uid, curr.clone()); - idleSeconds.put(uid, 0); - warned.put(uid, false); - continue; - } - - // Still gestanden - int idle = idleSeconds.merge(uid, 1, Integer::sum); - - // Warnphase - if (action.contains("WARN") && idle == warnDuration && !warned.getOrDefault(uid, false)) { - warned.put(uid, true); - player.sendMessage(plugin.getConfigManager().getPrefix() - + plugin.getConfigManager().getCampWarnMsg()); - player.playSound(player.getLocation(), - plugin.getConfigManager().getCampWarnSound(), 1f, - plugin.getConfigManager().getCampWarnSoundPitch()); - } - - // Strafphase - if (action.contains("PUNISH") && idle >= maxIdle) { - lp.addScore(-penalty); - // Score darf nicht unter 0 fallen - if (lp.getScore() < 0) lp.addScore(-lp.getScore()); - - player.sendMessage(plugin.getConfigManager().getPrefix() - + "§c⛔ Camp-Strafe: §7-" + penalty + " Punkte (Bewege dich!)"); - player.playSound(player.getLocation(), - plugin.getConfigManager().getCampWarnSound(), 1f, - plugin.getConfigManager().getCampWarnSoundPitch()); - - // Idle-Zähler auf maxIdle halten (weiter bestrafen jede Sekunde) - idleSeconds.put(uid, maxIdle); - } - } - } - - /** Spieler aus dem Camp-Tracking entfernen (bei Leave/End). */ - public void remove(UUID uuid) { - lastPosition.remove(uuid); - idleSeconds.remove(uuid); - warned.remove(uuid); - } - - /** Alle Daten zurücksetzen (bei Spiel-Reset). */ - public void reset() { - lastPosition.clear(); - idleSeconds.clear(); - warned.clear(); - } - - private void reset(UUID uid) { - lastPosition.remove(uid); - idleSeconds.put(uid, 0); - warned.put(uid, false); - } - - public int getIdleSeconds(UUID uuid) { - return idleSeconds.getOrDefault(uuid, 0); - } -}