From f69cbd2724837ed8018c4fd938c1225a884f8ab9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 21 Apr 2024 13:17:28 +0200 Subject: [PATCH] Add TraceScoreboardElement --- BauSystem_Main/src/BauSystem.properties | 3 +- BauSystem_Main/src/BauSystem_de.properties | 3 - .../features/tracer/TraceRecorder.java | 8 +++ .../tracer/TraceRecordingWrapper.java | 4 ++ .../tracer/TraceScoreboardElement.java | 60 +++++++++++++++++++ 5 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index af866f4a..6b52862b 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -479,8 +479,7 @@ TPSLIMIT_FROZEN = §eTPS frozen # Trace TRACE_RECORD=§aon TRACE_HAS_TRACES=§ehas Traces -TRACE_IDLE_SINGLE=§esingle -TRACE_IDLE_AUTO_IGNITE=§eauto +TRACE_IDLE_AUTO=§eauto TRACE_MESSAGE_START = §aTNT-Tracer started TRACE_MESSAGE_STOP = §cTNT-Tracer stopped TRACE_MESSAGE_CLEAR=§cAll TNT-positions deleted diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index d73906be..0c33a977 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -448,9 +448,6 @@ TPSLIMIT_FROZEN = §eTPS eingefroren. # Trace TRACE_RECORD=§aan TRACE_HAS_TRACES=§ehat Traces -TRACE_IDLE_SINGLE=§esingle -TRACE_IDLE_AUTO_EXPLODE=§eauto §8(§7explode§8) -TRACE_IDLE_AUTO_IGNITE=§eauto §8(§7ignite§8) 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 diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java index 23fae040..a706433b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecorder.java @@ -176,6 +176,14 @@ public class TraceRecorder implements Listener { return record; } + public boolean isAutoTraceEnabledInRegion(Region region) { + return autoTraceRegions.contains(region); + } + + public boolean isTraceActiveInRegion(Region region) { + return activeTraces.containsKey(region); + } + /** * Event for TNTs beeing spawn. * Registers newly spawned TNT to be traced if reqired diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecordingWrapper.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecordingWrapper.java index c68a3a75..48f00569 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecordingWrapper.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceRecordingWrapper.java @@ -91,5 +91,9 @@ public class TraceRecordingWrapper { protected void finalizeRecording() { recordsOutputStream.flush(); recordsOutputStream.close(); + + if (trace.getRecords().isEmpty()) { + TraceManager.instance.remove(trace); + } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java new file mode 100644 index 00000000..7a34f29a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java @@ -0,0 +1,60 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +import java.util.Collection; + +@Linked +public class TraceScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.OTHER; + } + + @Override + public int order() { + return 1; + } + + @Override + public String get(Region region, Player p) { + if (!Permission.BUILD.hasPermission(p)) return null; + if (TraceRecorder.instance.isTraceActiveInRegion(region)) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_RECORD", p); + } else if (TraceRecorder.instance.isAutoTraceEnabledInRegion(region)) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_IDLE_AUTO", p); + } + + Collection traces = TraceManager.instance.get(region); + if (traces.isEmpty()) { + return null; + } else { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_HAS_TRACES", p); + } + } +}