SteamWar/BauSystem2.0
Archiviert
12
0

Trace Refactor #233

Zusammengeführt
YoyoNow hat 121 Commits von TracerGUI nach master 2024-04-21 16:03:26 +02:00 zusammengeführt
4 geänderte Dateien mit 60 neuen und 12 gelöschten Zeilen
Nur Änderungen aus Commit f94aeeda01 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -45,6 +45,11 @@ public class Recorder implements Listener {
*/
private final Map<Region, List<TNTPrimed>> trackedTNT = new HashMap<>();
/** Map from TNT to Region the TNT spawned in
*
*/
private final Map<TNTPrimed, Region> tntSpawnRegion = new HashMap<>();
/**
* Maps a tracked tnt entity to the last record taken of it
*/
@ -83,9 +88,7 @@ public class Recorder implements Listener {
for(Region region : activeTraces.keySet()){
Trace trace = activeTraces.get(region);
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())){
TNTRecord record = new TNTRecord(tnt, false, TPSUtils.currentTick.get() - trace.getStartTime(), lastRecordMap.getOrDefault(tnt, null));
lastRecordMap.put(tnt, record);
trace.add(record);
record(tnt, trace);
}
}
}
@ -93,16 +96,18 @@ public class Recorder implements Listener {
/** Internal methode to record exploded tnt
*
* @param tntPrimed tnt exploding
* @param trace trace to record the tnt for
*/
private void record(TNTPrimed tntPrimed){
Region region = Region.getRegion(tntPrimed.getLocation());
Trace trace = activeTraces.get(region);
private void record(TNTPrimed tntPrimed, Trace trace){
TNTRecord lastRecord = lastRecordMap.getOrDefault(tntPrimed, null);
TNTRecord record = new TNTRecord(tntPrimed, true, TPSUtils.currentTick.get() - trace.getStartTime(), lastRecordMap.getOrDefault(tntPrimed, null));
TNTRecord record = new TNTRecord(tntPrimed, tntPrimed.getFuseTicks() == 0, TPSUtils.currentTick.get() - trace.getStartTime(), lastRecord);
if(lastRecord != null) lastRecord.setNext(record);
lastRecordMap.put(tntPrimed, record);
trace.add(record);
}
/** Eventhandler for TNTs beeing spawn.
/** Event for TNTs beeing spawn.
* Registers newly spawned TNT to be traced if reqired
* @param event
*/
@ -115,6 +120,7 @@ public class Recorder implements Listener {
if(!trackedTNT.containsKey(region)) trackedTNT.put(region, new ArrayList<>());
trackedTNT.get(region).add((TNTPrimed) event.getEntity());
tntSpawnRegion.put((TNTPrimed) event.getEntity(), region);
}
}
@ -125,8 +131,11 @@ public class Recorder implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTNTExplode(EntityExplodeEvent event){
if(!(event.getEntity() instanceof TNTPrimed)) return;
Region region = Region.getRegion(event.getLocation());
Region region = tntSpawnRegion.getOrDefault((TNTPrimed) event.getEntity(), null);
if(region == null) return;
trackedTNT.get(region).remove((TNTPrimed) event.getEntity());
record((TNTPrimed) event.getEntity());
tntSpawnRegion.remove((TNTPrimed) event.getEntity());
record((TNTPrimed) event.getEntity(), activeTraces.get(region));
}
}

Datei anzeigen

@ -56,6 +56,11 @@ public class TNTRecord {
*/
private final TNTRecord previous;
/**
* Reference to the next record of the tnt represented by this record
*/
private TNTRecord next;
public TNTRecord(TNTPrimed tnt, boolean explosion, long ticksSinceStart, TNTRecord previous){
this.explosion = explosion;
this.ticksSinceStart = ticksSinceStart;
@ -64,4 +69,13 @@ public class TNTRecord {
velocity = tnt.getVelocity();
this.previous = previous;
}
/**
* One call only function to set next
* @param next
*/
protected void setNext(TNTRecord next){
if(this.next == null) this.next = next;
}
}

Datei anzeigen

@ -19,5 +19,20 @@
package de.steamwar.bausystem.features.tracer2;
public class TraceCommand {
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance;
import org.bukkit.entity.Player;
@Linked
public class TraceCommand extends SWCommand {
@LinkedInstance
public Recorder recorder;
public TraceCommand(){super("tracetest");}
@Register
public void test(@Validator Player player){
}
}

Datei anzeigen

@ -20,11 +20,19 @@
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.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;
public class TraceManager {
@Linked
public class TraceManager implements Listener {
/**
* Map of all current traces
*/
@ -35,6 +43,8 @@ public class TraceManager {
*/
private int currOpenId = 0;
/** Adds a new trace to the global record
*
* @param trace Trace to be added