diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/BundleFilter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/BundleFilter.java new file mode 100644 index 00000000..409581bc --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/BundleFilter.java @@ -0,0 +1,63 @@ +/* + * 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.tracer2; + +import java.util.Optional; +import java.util.function.BiFunction; +import java.util.function.BiPredicate; + +public enum BundleFilter { + + + LOOSE((TNTRecord a, TNTRecord b) -> { + if(a.isExplosion() != b.isExplosion()) return Optional.of(false); + if(a.getLocation().distance(b.getLocation()) <= BundleFilter.pixelSize) return Optional.of(false); + if(a.getVelocity().distance(b.getVelocity()) <= BundleFilter.pixelSize) return Optional.of(false); + return Optional.of(true); + }), + + DEFAULT((TNTRecord a, TNTRecord b) -> { + if(a.isExplosion() != b.isExplosion()) return Optional.of(false); + if(a.getTicksSinceStart() != b.getTicksSinceStart()) return Optional.empty(); + if(a.getLocation().distance(b.getLocation()) <= BundleFilter.pixelSize) return Optional.of(false); + if(a.getVelocity().distance(b.getVelocity()) <= BundleFilter.pixelSize) return Optional.of(false); + return Optional.of(true); + }), + + STRICT((TNTRecord a, TNTRecord b) -> { + if(a.isExplosion() != b.isExplosion()) return Optional.of(false); + if(!a.getLocation().equals(b.getLocation())) return Optional.of(false); + if(!a.getVelocity().equals(b.getVelocity())) return Optional.of(false); + if(a.getTicksSinceStart() != b.getTicksSinceStart()) return Optional.empty(); + return Optional.of(true); + }), + + NONE((TNTRecord a, TNTRecord b) -> { + return Optional.empty(); + }); + + public BiFunction> apply; + + private static final double pixelSize = 0.0625; + + BundleFilter(BiFunction> apply){ + this.apply = apply; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Recorder.java index c53e6610..ff1d1607 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Recorder.java @@ -28,7 +28,6 @@ import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.TNTPrimeEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Trace.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Trace.java index 62806ce5..a2d13402 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Trace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/Trace.java @@ -78,7 +78,7 @@ public class Trace { * @param player The player the trace is rendered to * @param flags Flags modefieing the rendering */ - public void render(Player player, Collection flags){ + public void render(Player player, Collection flags, BundleFilter bundleFilter){ List workingRecords = records; //Apply filters @@ -86,7 +86,7 @@ public class Trace { workingRecords = flag.filter.apply(workingRecords); //Bundle records at unique positions - List> bundles = bundleRecords(workingRecords); + List> bundles = bundleRecords(workingRecords, bundleFilter); //Render bundled records REntityServer server = new REntityServer(); @@ -106,20 +106,27 @@ public class Trace { * @param records The TNTRecords that are supposed to be bundled * @return A list of bundles */ - private List> bundleRecords(List records){ - Map > entitiesRecords = new HashMap<>(); + private List> bundleRecords(List records, BundleFilter filter){ + ArrayList> bundles = new ArrayList<>(); + + recordsLoop : for(TNTRecord record : records) { + for(int i = bundles.size() - 1; i >= 0; i--){ + List bundle = bundles.get(i); + + Optional filterResult = filter.apply.apply(record, bundle.get(0)); + + if(filterResult.isPresent() && filterResult.get()) + bundle.add(record); + else{ + ArrayList newBundle = new ArrayList<>(); + newBundle.add(record); + continue recordsLoop; + } - for(TNTRecord record : records) { - if(entitiesRecords.containsKey(record.getLocation())) - entitiesRecords.get(record.getLocation()); - else{ - List entityRecords = new ArrayList<>(); - entityRecords.add(record); - entitiesRecords.put(record.getLocation(), entityRecords); } } - return new LinkedList<>(entitiesRecords.values()); + return bundles; } /** Hides this trail for the given player diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceCommand.java index ab82eb3e..bd70fb12 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceCommand.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.tracer2; +import de.steamwar.bausystem.region.Region; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; @@ -31,8 +32,9 @@ public class TraceCommand extends SWCommand { public Recorder recorder; public TraceCommand(){super("tracetest");} - @Register + @Register(value = "start") public void test(@Validator Player player){ - + Region region = Region.getRegion(player.getLocation()); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceManager.java index 1df3bdba..f7232e84 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer2/TraceManager.java @@ -20,10 +20,7 @@ package de.steamwar.bausystem.features.tracer2; import de.steamwar.bausystem.region.Region; -import de.steamwar.entity.REntityServer; import de.steamwar.linkage.Linked; -import org.bukkit.Location; -import org.bukkit.entity.Player; import org.bukkit.event.Listener; import java.util.*; @@ -97,12 +94,4 @@ public class TraceManager implements Listener { public Set getAll(){ return new HashSet<>(traces.values()); } - - /** Renders the given trace records - * - * @param player The player the trace is rendered to - * @param trace the trace to render - * @param flags Flags modefieing the rendering - */ - }