From 3d4468ef8cbeb070be1de2252870c759b25ad4c0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 14 Jun 2023 17:03:29 +0200 Subject: [PATCH] Add Tracer to global Region Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 - BauSystem_Main/src/BauSystem_de.properties | 1 - .../features/tracer/TraceCommand.java | 6 --- .../tracer/TraceScoreboardElement.java | 14 +++++-- .../features/tracer/record/Recorder.java | 39 ++----------------- 5 files changed, 15 insertions(+), 46 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 44fd1772..6b641c33 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -763,7 +763,6 @@ TRACE_MESSAGE_ISOLATE = §aTNT-positions isolated TRACE_MESSAGE_UNISOLATE = §cTNT-positions hidden TRACE_MESSAGE_CLICK_ISOLATE = §eClick to §aisolate§8/§cunisolate TRACE_MESSAGE_DISALLOWED = §cYou are not allowed to use the TNT-Tracer here -TRACE_MESSAGE_NO_REGION = §cYou are not in a region TRACE_COMMAND_HELP_START = §8/§etrace start §8- §7Starts recording of all TNT-positions TRACE_COMMAND_HELP_SINGLE = §8/§etrace single §8- §7Starts a single recording of all TNT-positions diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 9730a04b..3e788236 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -735,7 +735,6 @@ TRACE_MESSAGE_ISOLATE = §aTNT-Positionen isoliert TRACE_MESSAGE_UNISOLATE = §cTNT-Positionen ausgeblendet TRACE_MESSAGE_CLICK_ISOLATE = §eKlicken zum §aisolieren§8/§causblenden TRACE_MESSAGE_DISALLOWED = §cDu darfst hier nicht den TNT-Tracer nutzen -TRACE_MESSAGE_NO_REGION = §cDu bist in keiner Region TRACE_COMMAND_HELP_START = §8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen TRACE_COMMAND_HELP_SINGLE = §8/§etrace single §8- §7Startet eine einzelne Aufnahme aller 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 b79d08f0..f18147f3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -25,7 +25,6 @@ import de.steamwar.bausystem.features.tracer.gui.TraceGui; import de.steamwar.bausystem.features.tracer.record.*; import de.steamwar.bausystem.features.tracer.show.Record; import de.steamwar.bausystem.features.tracer.show.*; -import de.steamwar.bausystem.features.tracer.show.EntityShowMode; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.ShowMode; import de.steamwar.command.PreviousArguments; @@ -262,11 +261,6 @@ public class TraceCommand extends SWCommand { messageSender.send("TRACE_MESSAGE_DISALLOWED", player); return false; } - Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - messageSender.send("TRACE_MESSAGE_NO_REGION", player); - return false; - } return true; }; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java index 5e955824..87ae3876 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java @@ -21,12 +21,15 @@ package de.steamwar.bausystem.features.tracer; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tracer.record.Recorder; +import de.steamwar.bausystem.features.tracer.show.Record; import de.steamwar.bausystem.features.tracer.show.StoredRecords; 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.List; + @Linked public class TraceScoreboardElement implements ScoreboardElement { @@ -45,9 +48,14 @@ public class TraceScoreboardElement implements ScoreboardElement { String traceScore = Recorder.INSTANCE.get(region).scoreboard(p); if (traceScore != null) { return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + traceScore; - } else if (!(Recorder.INSTANCE.get(region) instanceof Recorder.NoopTraceRecorder) && !StoredRecords.getRecords(region).isEmpty()) { - return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_HAS_TRACES", p); } - return null; + List records = StoredRecords.getRecords(region); + if (records.isEmpty()) { + return null; + } + if (records.stream().allMatch(record -> record.getTnt().isEmpty())) { + return null; + } + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_HAS_TRACES", p); } } 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 85d2ef2a..3a0bfe7b 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 @@ -27,7 +27,6 @@ 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.World; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; @@ -37,7 +36,9 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.stream.Collectors; @Linked @@ -49,36 +50,6 @@ public class Recorder implements Listener { INSTANCE = this; } - public static class NoopTraceRecorder implements TraceRecorder { - @Override - public String scoreboard(Player player) { - return null; - } - - @Override - public void spawn(TNTPrimed tntPrimed) { - } - - @Override - public void tick(TNTPrimed tntPrimed) { - } - - @Override - public void explode(TNTPrimed tntPrimed, boolean b) { - } - - @Override - public String scriptState() { - return "OFF"; - } - - @Override - public long scriptTime() { - return 0; - } - } - private static final NoopTraceRecorder NOOP = new NoopTraceRecorder(); - private static class DisabledTracerRecorder implements TraceRecorder { @Override public String scoreboard(Player player) { @@ -115,8 +86,6 @@ public class Recorder implements Listener { instance = this; } - private final World world = Bukkit.getWorlds().get(0); - private Map regionTraceRecorderMap = new HashMap<>(); private Map tntTraceRecorderMap = new HashMap<>(); @@ -125,7 +94,7 @@ public class Recorder implements Listener { } public TraceRecorder get(Region region) { - return regionTraceRecorderMap.getOrDefault(region, region.isGlobal() ? NOOP : DISABLED); + return regionTraceRecorderMap.getOrDefault(region, DISABLED); } public void set(Region region, TraceRecorder traceRecorder) {