From 870578dcf962ba595ef63a7f7b39b686240a8ec8 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Sat, 30 Mar 2024 16:09:06 +0100 Subject: [PATCH] Added at-Flag --- .../bausystem/features/tracer/Trace.java | 32 ++++++++++ .../tracer/rendering/dynamicFlags/AtFlag.java | 60 +++++++++++++++++++ .../rendering/dynamicFlags/IsolateFlag.java | 3 + 3 files changed, 95 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/rendering/dynamicFlags/AtFlag.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java index e679dcd0..baa263d4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/Trace.java @@ -23,12 +23,14 @@ import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tracer.rendering.BundleFilter; import de.steamwar.bausystem.features.tracer.rendering.TraceEntity; import de.steamwar.bausystem.features.tracer.rendering.ViewFlag; +import de.steamwar.bausystem.features.tracer.rendering.dynamicFlags.AtFlag; import de.steamwar.bausystem.features.tracer.rendering.dynamicFlags.IsolateFlag; import de.steamwar.bausystem.region.Region; import de.steamwar.entity.REntityServer; import lombok.Getter; import org.bukkit.entity.Player; +import java.lang.reflect.Array; import java.util.*; import java.util.stream.Stream; @@ -247,6 +249,36 @@ public class Trace { return bundles; } + + /** Modifies the render for the given player, to only show tnts at the given time interval + * + * @param player + * @param from start of time interval + * @param to end of time interval + */ + public void renderAt(Player player, int from, int to){ + ViewFlag[] viewFlags = viewFlagMap.get(player); + if(viewFlags == null) return; + + AtFlag atFlag = null; + atFlag = Stream.of(viewFlags) + .filter(AtFlag.class::isInstance) + .map(AtFlag.class::cast) + .findFirst() + .orElse(null); + + if(atFlag != null){ + atFlag.update(from, to); + } + else { + atFlag = new AtFlag(from, to); + viewFlags = Arrays.copyOf(viewFlags, viewFlags.length + 1); + viewFlags[viewFlags.length - 1] = atFlag; + } + + render(player, viewFlags, BundleFilter.STRICT); + } + /** Toggles the isolated render for the given records and player * * @param player the player the trace is shown to diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/rendering/dynamicFlags/AtFlag.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/rendering/dynamicFlags/AtFlag.java new file mode 100644 index 00000000..cb06685a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/rendering/dynamicFlags/AtFlag.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.rendering.dynamicFlags; + +import de.steamwar.bausystem.features.tracer.TNTRecord; +import de.steamwar.bausystem.features.tracer.rendering.TraceEntity; +import de.steamwar.bausystem.features.tracer.rendering.ViewFlag; +import de.steamwar.entity.REntityServer; + +import java.util.List; +import java.util.stream.Collectors; + +public class AtFlag extends ViewFlag { + private int start; + private int end; + + + public AtFlag(int start, int end){ + super(false, false, ViewFlag.IGNITE, null); + this.start = start; + this.end = end; + } + + /** Update this flag to represent another time interval + * + * @param start new interval start + * @param end new interval end + */ + public void update(int start, int end){ + this.start = start; + this.end = end; + } + + @Override + public List filter(List records) { + return records.stream() + .filter(record -> record.getTicksSinceStart() <= start && record.getTicksSinceStart() >= end) + .collect(Collectors.toList()); + } + + @Override + public void modify(REntityServer server, List entities) {} +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/rendering/dynamicFlags/IsolateFlag.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/rendering/dynamicFlags/IsolateFlag.java index 85d1f1bb..7832636f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/rendering/dynamicFlags/IsolateFlag.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/rendering/dynamicFlags/IsolateFlag.java @@ -32,6 +32,9 @@ import java.util.stream.Collectors; public class IsolateFlag extends ViewFlag { + /** + * Tnt ids that will be isolated + */ private final Set tntToIsolate = new HashSet<>(); public IsolateFlag(){