Reimplemented trace rendering
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
D4rkr34lm 2023-12-19 16:17:14 +01:00
Ursprung f94aeeda01
Commit 2bf3cfbb1d
6 geänderte Dateien mit 200 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -51,11 +51,6 @@ public class BauSystem extends JavaPlugin implements Listener {
// This should be treated as final!
public static Message MESSAGE;
/*
* Plugin wide availeble data
*/
public static final TraceManager TRACES = new TraceManager();
@Getter
private static BauSystem instance;

Datei anzeigen

@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.bausystem.region.Region;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -35,6 +36,13 @@ import java.util.*;
@Linked
public class Recorder implements Listener {
/**
* Linked instance of TraceManager
*/
@LinkedInstance
TraceManager manager;
/**
* Map for all traces beeing activly recorded
*/
@ -68,7 +76,7 @@ public class Recorder implements Listener {
public void startRecording(Region region){
Trace trace = new Trace(region);
activeTraces.put(region, trace);
BauSystem.TRACES.add(trace);
manager.add(trace);
}
/** Stops the recording at the given region
@ -76,9 +84,16 @@ public class Recorder implements Listener {
* @param region region to stop recording
*/
public void stopRecording(Region region){
Trace trace = activeTraces.get(region);
trace.setRecords(Collections.unmodifiableList(trace.getRecords()));
activeTraces.remove(region);
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())) lastRecordMap.remove(tnt);
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList()))
lastRecordMap.remove(tnt);
trackedTNT.put(region, new ArrayList<>());
}
/** Internal methode to record all tracked TNT Entities
@ -102,7 +117,9 @@ public class Recorder implements Listener {
TNTRecord lastRecord = lastRecordMap.getOrDefault(tntPrimed, null);
TNTRecord record = new TNTRecord(tntPrimed, tntPrimed.getFuseTicks() == 0, TPSUtils.currentTick.get() - trace.getStartTime(), lastRecord);
if(lastRecord != null) lastRecord.setNext(record);
if(lastRecord != null)
lastRecord.setNext(record);
lastRecordMap.put(tntPrimed, record);
trace.add(record);
}
@ -114,10 +131,12 @@ public class Recorder implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTNTSpawn(EntitySpawnEvent event){
if(!(event.getEntity() instanceof TNTPrimed)) return;
Region region = Region.getRegion(event.getLocation());
if(activeTraces.containsKey(region)){
//Check whether set for tracking already exists. Creating it if necessary
if(!trackedTNT.containsKey(region)) trackedTNT.put(region, new ArrayList<>());
if(!trackedTNT.containsKey(region))
trackedTNT.put(region, new ArrayList<>());
trackedTNT.get(region).add((TNTPrimed) event.getEntity());
tntSpawnRegion.put((TNTPrimed) event.getEntity(), region);
@ -131,6 +150,7 @@ public class Recorder implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTNTExplode(EntityExplodeEvent event){
if(!(event.getEntity() instanceof TNTPrimed)) return;
Region region = tntSpawnRegion.getOrDefault((TNTPrimed) event.getEntity(), null);
if(region == null) return;
trackedTNT.get(region).remove((TNTPrimed) event.getEntity());

Datei anzeigen

@ -21,12 +21,12 @@ package de.steamwar.bausystem.features.tracer2;
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.bausystem.region.Region;
import de.steamwar.entity.REntityServer;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
public class Trace {
/**
@ -44,7 +44,13 @@ public class Trace {
/**
* Records of TNTs, making up the trace
*/
private final List<TNTRecord> records = new ArrayList<>();
@Getter
private List<TNTRecord> records = new ArrayList<>();
/**
* A map of players -> REntityServers for rendering traces to a player
*/
private Map<Player, REntityServer> serverMap = new HashMap<>();
public Trace (Region region){
this.region = region;
@ -57,4 +63,64 @@ public class Trace {
protected void add (TNTRecord record){
records.add(record);
}
/** Internal methode to make records immutable after recording is finished
*
* @param records immutable records list
*/
protected void setRecords(List<TNTRecord> records){
this.records = records;
}
/** Renders this traces
*
* @param player The player the trace is rendered to
* @param flags Flags modefieing the rendering
*/
public void render(Player player, Collection<ViewFlag> flags){
List<TNTRecord> workingRecords = records;
//Apply filters
for(ViewFlag flag : flags)
workingRecords = flag.filter.apply(workingRecords);
//Bundle records at unique positions
List<List<TNTRecord>> bundles = bundleRecords(workingRecords);
//Render bundled records
REntityServer server = new REntityServer();
serverMap.put(player, server);
List<TraceEntity> entities = new LinkedList<>();
for(List<TNTRecord> bundle : bundles)
entities.add(new TraceEntity(server, bundle.get(0).getLocation(), bundle.get(0).isExplosion(), bundle));
//Apply modifiers
for(ViewFlag flag : flags)
flag.modify.accept(server, entities);
}
/** Bundles the passed TNTRecords based on whether they are at the same location
*
* @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<>();
for(TNTRecord record : records) {
if(entitiesRecords.containsKey(record.getLocation()))
entitiesRecords.get(record.getLocation());
else{
List <TNTRecord> entityRecords = new ArrayList<>();
entityRecords.add(record);
entitiesRecords.put(record.getLocation(), entityRecords);
}
}
return new LinkedList<>(entitiesRecords.values());
}
}

Datei anzeigen

@ -0,0 +1,42 @@
/*
* 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 de.steamwar.entity.REntityServer;
import de.steamwar.entity.RFallingBlockEntity;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.Material;
import java.util.List;
public class TraceEntity extends RFallingBlockEntity {
/**
* The records represented by this REntity
*/
@Getter
private final List<TNTRecord> records;
public TraceEntity(REntityServer server, Location location, boolean isExplosion, List<TNTRecord> records) {
super(server, location, isExplosion ? Material.RED_STAINED_GLASS : Material.TNT);
this.records = records;
}
}

Datei anzeigen

@ -22,11 +22,9 @@ 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.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.*;
import java.util.stream.Collectors;
@ -43,8 +41,6 @@ public class TraceManager implements Listener {
*/
private int currOpenId = 0;
/** Adds a new trace to the global record
*
* @param trace Trace to be added
@ -70,7 +66,7 @@ public class TraceManager implements Listener {
*/
public void clear(){
traces.clear();
currOpenId = 1;
currOpenId = 0;
}
/** Methode to get all traces in a certain region
@ -101,4 +97,12 @@ 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
*/
}

Datei anzeigen

@ -0,0 +1,53 @@
/*
* 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 de.steamwar.entity.REntityServer;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.UnaryOperator;
public enum ViewFlag {
EXPLOSION((List<TNTRecord> records) ->{
List<TNTRecord> ret = new ArrayList<>();
for(TNTRecord record : records)
if(record.isExplosion())
ret.add(record);
return ret;
}, (REntityServer server , List<TraceEntity> entities) -> {});
/**
* The filtering part of the flag
*/
public final UnaryOperator<List<TNTRecord>> filter;
/**
* The modifieng part of the flag
*/
public final BiConsumer<REntityServer, List<TraceEntity>> modify;
ViewFlag(UnaryOperator<List<TNTRecord>> filter, BiConsumer<REntityServer,List<TraceEntity>> modify) {
this.filter = filter;
this.modify = modify;
}
}