From 451c47d3ed3e123bb6ba5153576cbfa553e50b80 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 20 Sep 2023 17:14:34 +0200 Subject: [PATCH] Add TraceRecordAutoDeletion Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 8 +++ BauSystem_Main/src/BauSystem_de.properties | 8 +++ .../features/tracer/TraceCommand.java | 35 ++++++++++ .../tracer/record/AutoTraceRecorder.java | 20 +++++- .../features/tracer/record/Recorder.java | 9 +-- .../tracer/record/SimpleTraceRecorder.java | 3 +- .../record/TraceRecordAutoDeletion.java | 65 +++++++++++++++++++ .../features/tracer/record/TraceRecorder.java | 3 +- 8 files changed, 140 insertions(+), 11 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecordAutoDeletion.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 87df791c..3f7c25f1 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -489,6 +489,13 @@ TRACE_IDLE_AUTO_EXPLODE=§eauto §8(§7explode§8) TRACE_IDLE_AUTO_IGNITE=§eauto §8(§7ignite§8) TRACE_MESSAGE_AUTO_IDLE_EXPLODE = §aAuto-Tracer explode started TRACE_MESSAGE_AUTO_IDLE_IGNITE = §aAuto-Tracer ignite started +TRACE_MESSAGE_AUTO_DELETE_INVALID = §cAuto delete cannot be used currently +TRACE_MESSAGE_AUTO_DELETE_ALWAYS = §7Last Shot will §ealways §7be deleted +TRACE_MESSAGE_AUTO_DELETE_NEVER = §7Last Shot will §enever §7be deleted +TRACE_MESSAGE_AUTO_DELETE_NO_BUILD_DESTROY = §7Last Shot will be deleted if §eno build §7block was destroyed +TRACE_MESSAGE_AUTO_DELETE_BUILD_DESTROY = §7Last Shot will be deleted if §ea build §7block was destroyed +TRACE_MESSAGE_AUTO_DELETE_NO_TESTBLOCK_DESTROY = §7Last Shot will be deleted if §eno testblock §7block was destroyed +TRACE_MESSAGE_AUTO_DELETE_TESTBLOCK_DESTROY = §7Last Shot will be deleted if §ea testlblock §7block was destroyed TRACE_MESSAGE_START = §aTNT-Tracer started TRACE_MESSAGE_SINGLE = §aSingle-Tracer started TRACE_MESSAGE_STOP = §cTNT-Tracer stopped @@ -502,6 +509,7 @@ TRACE_COMMAND_HELP_START = §8/§etrace start §8- §7Starts recording of all TN TRACE_COMMAND_HELP_SINGLE = §8/§etrace single §8- §7Starts a single recording of all TNT-positions TRACE_COMMAND_HELP_STOP = §8/§etrace stop §8- §7Stops the TNT-Tracer TRACE_COMMAND_HELP_AUTO = §8/§etrace toggleauto §8- §7Automatic start of recording +TRACE_COMMAND_HELP_AUTO_REMOVE = §8/§etrace autoremove §8<§eParameter§8> §8- §7Remove last Trace Record automatically TRACE_COMMAND_HELP_SHOW = §8/§etrace show §8<§eParameter§8> - §7Shows all TNT-positions TRACE_COMMAND_HELP_HIDE = §8/§etrace hide §8- §7Hides all TNT-positions TRACE_COMMAND_HELP_DELETE = §8/§etrace delete §8- §7Deletes all TNT-positions diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 18b742b6..9cc9c1d5 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -458,6 +458,13 @@ TRACE_IDLE_AUTO_EXPLODE=§eauto §8(§7explode§8) TRACE_IDLE_AUTO_IGNITE=§eauto §8(§7ignite§8) TRACE_MESSAGE_AUTO_IDLE_EXPLODE = §aAuto-Tracer explode gestartet TRACE_MESSAGE_AUTO_IDLE_IGNITE = §aAuto-Tracer ignite gestartet +TRACE_MESSAGE_AUTO_DELETE_INVALID = §cAuto delete kann aktuell nicht genutzt werden +TRACE_MESSAGE_AUTO_DELETE_ALWAYS = §7Der letzte Schuss wird §eimmer§7 gelöscht +TRACE_MESSAGE_AUTO_DELETE_NEVER = §7Der letzte Schuss wird §enie§7 gelöscht +TRACE_MESSAGE_AUTO_DELETE_NO_BUILD_DESTROY = §7Der letzte Schuss wird gelöscht, wenn §ekein§7 Block aus dem §eBaubereich§7 zerstört wurde +TRACE_MESSAGE_AUTO_DELETE_BUILD_DESTROY = §7Der letzte Schuss wird gelöscht, wenn §eein§7 Block aus dem §eBaubereich§7 zerstört wurde +TRACE_MESSAGE_AUTO_DELETE_NO_TESTBLOCK_DESTROY = §7Der letzte Schuss wird gelöscht, wenn §ekein§7 Block aus dem §eTestblock§7 zerstört wurde +TRACE_MESSAGE_AUTO_DELETE_TESTBLOCK_DESTROY = §7Der letzte Schuss wird gelöscht, wenn §eein§7 Block aus dem §eTestblock§7 zerstört wurde TRACE_MESSAGE_START = §aTNT-Tracer gestartet TRACE_MESSAGE_SINGLE = §aSingle-Tracer gestartet TRACE_MESSAGE_STOP = §cTNT-Tracer gestoppt @@ -471,6 +478,7 @@ TRACE_COMMAND_HELP_START = §8/§etrace start §8- §7Startet die Aufnahme aller TRACE_COMMAND_HELP_SINGLE = §8/§etrace single §8- §7Startet eine einzelne Aufnahme aller TNT-Positionen TRACE_COMMAND_HELP_STOP = §8/§etrace stop §8- §7Stoppt den TNT-Tracer TRACE_COMMAND_HELP_AUTO = §8/§etrace toggleauto §8- §7Automatischer Aufnahmenstart +TRACE_COMMAND_HELP_AUTO_REMOVE = §8/§etrace autoremove §8<§eParameter§8> §8- §7Löscht den letzten Trace automatisch TRACE_COMMAND_HELP_SHOW = §8/§etrace show §8<§eParameter§8> - §7Zeigt alle TNT-Positionen TRACE_COMMAND_HELP_HIDE = §8/§etrace hide §8- §7Versteckt alle TNT-Positionen TRACE_COMMAND_HELP_DELETE = §8/§etrace delete §8- §7Löscht alle TNT-Positionen diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index 122529d6..958b4574 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -89,6 +89,41 @@ public class TraceCommand extends SWCommand { } } + @Register(value = {"autoremove"}, description = "TRACE_COMMAND_HELP_AUTO_REMOVE") + @Register(value = {"autodelete"}) + public void setAutoDeleteMode(@Validator Player p, @StaticValue({"-always", "-never", "-no_build_destroy", "-build_destroy", "-no_testblock_destroy", "-testblock_destroy"}) String destroyMode) { + Region region = Region.getRegion(p.getLocation()); + TraceRecorder recorder = this.recorder.get(region); + if (!(recorder instanceof AutoTraceRecorder) || recorder instanceof SingleTraceRecorder) { + BauSystem.MESSAGE.send("TRACE_MESSAGE_AUTO_DELETE_INVALID", p); + return; + } + AutoTraceRecorder autoTraceRecorder = (AutoTraceRecorder) recorder; + switch (destroyMode) { + case "-always": + autoTraceRecorder.setTraceRecordAutoDeletion(TraceRecordAutoDeletion.ALWAYS); + break; + case "-never": + autoTraceRecorder.setTraceRecordAutoDeletion(TraceRecordAutoDeletion.NEVER); + break; + case "-no_build_destroy": + autoTraceRecorder.setTraceRecordAutoDeletion(TraceRecordAutoDeletion.NO_BUILD_DESTROY); + break; + case "-build_destroy": + autoTraceRecorder.setTraceRecordAutoDeletion(TraceRecordAutoDeletion.BUILD_DESTROY); + break; + case "-no_testblock_destroy": + autoTraceRecorder.setTraceRecordAutoDeletion(TraceRecordAutoDeletion.NO_TESTBLOCK_DESTROY); + break; + case "-testblock_destroy": + autoTraceRecorder.setTraceRecordAutoDeletion(TraceRecordAutoDeletion.TESTBLOCK_DESTROY); + break; + default: + return; + } + BauSystem.MESSAGE.send("TRACE_MESSAGE_AUTO_DELETE_" + autoTraceRecorder.getTraceRecordAutoDeletion().name(), p); + } + @Register(value = {"show"}, description = "TRACE_COMMAND_HELP_SHOW") public void showCommand(@Validator Player p, @OptionalValue("entity") ShowModeType showModeType, ShowModeParameterType... showModeParameterTypes) { ShowModeParameter showModeParameter = new ShowModeParameter(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java index 35c6c497..ea08ec15 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java @@ -22,6 +22,11 @@ package de.steamwar.bausystem.features.tracer.record; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tracer.show.Record; +import de.steamwar.bausystem.features.tracer.show.StoredRecords; +import de.steamwar.bausystem.features.tracer.show.TraceShowManager; +import de.steamwar.bausystem.region.Region; +import lombok.Getter; +import lombok.Setter; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; @@ -37,8 +42,15 @@ public abstract class AutoTraceRecorder implements TraceRecorder { private final Map recordMap = new HashMap<>(); private Record record; + + private Region region; private Supplier recordSupplier; + @Setter + @Getter + private TraceRecordAutoDeletion traceRecordAutoDeletion = TraceRecordAutoDeletion.NEVER; + private Record lastRecord; + private Record.TNTRecord getRecord(TNTPrimed tntPrimed) { return recordMap.computeIfAbsent(tntPrimed, __ -> record.spawn(TPSUtils.currentRealTick.get() - startTime)); } @@ -58,6 +70,10 @@ public abstract class AutoTraceRecorder implements TraceRecorder { } private void startRecording() { + if (lastRecord != null && traceRecordAutoDeletion.test(lastRecord)) { + StoredRecords.remove(region, lastRecord); + TraceShowManager.reshow(region); + } lastExplosion = 0; startTime = TPSUtils.currentRealTick.get(); record = recordSupplier.get(); @@ -65,7 +81,8 @@ public abstract class AutoTraceRecorder implements TraceRecorder { } @Override - public void recordSupplier(Supplier recordSupplier) { + public void init(Region region, Supplier recordSupplier) { + this.region = region; this.recordSupplier = recordSupplier; } @@ -112,6 +129,7 @@ public abstract class AutoTraceRecorder implements TraceRecorder { if (recording && lastExplosion > 80) { recording = false; recordMap.clear(); + lastRecord = record; record = null; stoppedRecording(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java index ec1d5e48..1bd04377 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -26,7 +26,6 @@ import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.linkage.Linked; -import org.bukkit.Bukkit; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; @@ -80,12 +79,6 @@ public class Recorder implements Listener { } private static final DisabledTracerRecorder DISABLED = new DisabledTracerRecorder(); - static Recorder instance; - - { - instance = this; - } - private Map regionTraceRecorderMap = new HashMap<>(); private Map tntTraceRecorderMap = new HashMap<>(); @@ -99,7 +92,7 @@ public class Recorder implements Listener { public void set(Region region, TraceRecorder traceRecorder) { regionTraceRecorderMap.put(region, traceRecorder); - traceRecorder.recordSupplier(() -> { + traceRecorder.init(region, () -> { Record record = new Record(region); StoredRecords.add(region, record); return record; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java index a5b7b77e..213299ad 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.tracer.record; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tracer.show.Record; +import de.steamwar.bausystem.region.Region; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; @@ -41,7 +42,7 @@ public class SimpleTraceRecorder implements TraceRecorder, ActiveTracer { } @Override - public void recordSupplier(Supplier recordSupplier) { + public void init(Region region, Supplier recordSupplier) { record = recordSupplier.get(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecordAutoDeletion.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecordAutoDeletion.java new file mode 100644 index 00000000..a99eff0e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecordAutoDeletion.java @@ -0,0 +1,65 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.tracer.record; + +import de.steamwar.bausystem.features.tracer.show.Record; + +public enum TraceRecordAutoDeletion { + + ALWAYS { + @Override + public boolean test(Record record) { + return true; + } + }, + NEVER { + @Override + public boolean test(Record record) { + return false; + } + }, + NO_BUILD_DESTROY { + @Override + public boolean test(Record record) { + return record.getTnt().stream().noneMatch(Record.TNTRecord::isInBuildArea); + } + }, + BUILD_DESTROY { + @Override + public boolean test(Record record) { + return record.getTnt().stream().anyMatch(Record.TNTRecord::isInBuildArea); + } + }, + NO_TESTBLOCK_DESTROY { + @Override + public boolean test(Record record) { + return record.getTnt().stream().noneMatch(Record.TNTRecord::isInTestblockArea); + } + }, + TESTBLOCK_DESTROY { + @Override + public boolean test(Record record) { + return record.getTnt().stream().anyMatch(Record.TNTRecord::isInTestblockArea); + } + }, + ; + + public abstract boolean test(Record record); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java index 20279fa7..c667f4e0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.tracer.record; import de.steamwar.bausystem.features.tracer.show.Record; +import de.steamwar.bausystem.region.Region; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; @@ -28,7 +29,7 @@ import java.util.function.Supplier; public interface TraceRecorder { String scoreboard(Player player); - default void recordSupplier(Supplier recordSupplier) { + default void init(Region region, Supplier recordSupplier) { } default void postClear() { }