Added option for bundeling to trace rendering
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
Dieser Commit ist enthalten in:
Ursprung
85512be3a8
Commit
beb49cdcd1
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<TNTRecord, TNTRecord, Optional<Boolean>> apply;
|
||||
|
||||
private static final double pixelSize = 0.0625;
|
||||
|
||||
BundleFilter(BiFunction<TNTRecord, TNTRecord, Optional<Boolean>> apply){
|
||||
this.apply = apply;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
|
@ -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<ViewFlag> flags){
|
||||
public void render(Player player, Collection<ViewFlag> flags, BundleFilter bundleFilter){
|
||||
List<TNTRecord> workingRecords = records;
|
||||
|
||||
//Apply filters
|
||||
@ -86,7 +86,7 @@ public class Trace {
|
||||
workingRecords = flag.filter.apply(workingRecords);
|
||||
|
||||
//Bundle records at unique positions
|
||||
List<List<TNTRecord>> bundles = bundleRecords(workingRecords);
|
||||
List<List<TNTRecord>> 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<List<TNTRecord>> bundleRecords(List<TNTRecord> records){
|
||||
Map <Location, List<TNTRecord>> entitiesRecords = new HashMap<>();
|
||||
private List<List<TNTRecord>> bundleRecords(List<TNTRecord> records, BundleFilter filter){
|
||||
ArrayList<List<TNTRecord>> bundles = new ArrayList<>();
|
||||
|
||||
for(TNTRecord record : records) {
|
||||
if(entitiesRecords.containsKey(record.getLocation()))
|
||||
entitiesRecords.get(record.getLocation());
|
||||
recordsLoop : for(TNTRecord record : records) {
|
||||
for(int i = bundles.size() - 1; i >= 0; i--){
|
||||
List<TNTRecord> bundle = bundles.get(i);
|
||||
|
||||
Optional<Boolean> filterResult = filter.apply.apply(record, bundle.get(0));
|
||||
|
||||
if(filterResult.isPresent() && filterResult.get())
|
||||
bundle.add(record);
|
||||
else{
|
||||
List <TNTRecord> entityRecords = new ArrayList<>();
|
||||
entityRecords.add(record);
|
||||
entitiesRecords.put(record.getLocation(), entityRecords);
|
||||
ArrayList<TNTRecord> newBundle = new ArrayList<>();
|
||||
newBundle.add(record);
|
||||
continue recordsLoop;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return new LinkedList<>(entitiesRecords.values());
|
||||
return bundles;
|
||||
}
|
||||
|
||||
/** Hides this trail for the given player
|
||||
|
@ -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());
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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<Trace> 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
|
||||
*/
|
||||
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren