Dieser Commit ist enthalten in:
Ursprung
b58e418ea4
Commit
f94aeeda01
@ -45,6 +45,11 @@ public class Recorder implements Listener {
|
|||||||
*/
|
*/
|
||||||
private final Map<Region, List<TNTPrimed>> trackedTNT = new HashMap<>();
|
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
|
* 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()){
|
for(Region region : activeTraces.keySet()){
|
||||||
Trace trace = activeTraces.get(region);
|
Trace trace = activeTraces.get(region);
|
||||||
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())){
|
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptyList())){
|
||||||
TNTRecord record = new TNTRecord(tnt, false, TPSUtils.currentTick.get() - trace.getStartTime(), lastRecordMap.getOrDefault(tnt, null));
|
record(tnt, trace);
|
||||||
lastRecordMap.put(tnt, record);
|
|
||||||
trace.add(record);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,16 +96,18 @@ public class Recorder implements Listener {
|
|||||||
/** Internal methode to record exploded tnt
|
/** Internal methode to record exploded tnt
|
||||||
*
|
*
|
||||||
* @param tntPrimed tnt exploding
|
* @param tntPrimed tnt exploding
|
||||||
|
* @param trace trace to record the tnt for
|
||||||
*/
|
*/
|
||||||
private void record(TNTPrimed tntPrimed){
|
private void record(TNTPrimed tntPrimed, Trace trace){
|
||||||
Region region = Region.getRegion(tntPrimed.getLocation());
|
TNTRecord lastRecord = lastRecordMap.getOrDefault(tntPrimed, null);
|
||||||
Trace trace = activeTraces.get(region);
|
|
||||||
|
|
||||||
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);
|
trace.add(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Eventhandler for TNTs beeing spawn.
|
/** Event for TNTs beeing spawn.
|
||||||
* Registers newly spawned TNT to be traced if reqired
|
* Registers newly spawned TNT to be traced if reqired
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
@ -115,6 +120,7 @@ public class Recorder implements Listener {
|
|||||||
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());
|
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)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onTNTExplode(EntityExplodeEvent event){
|
public void onTNTExplode(EntityExplodeEvent event){
|
||||||
if(!(event.getEntity() instanceof TNTPrimed)) return;
|
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());
|
trackedTNT.get(region).remove((TNTPrimed) event.getEntity());
|
||||||
record((TNTPrimed) event.getEntity());
|
tntSpawnRegion.remove((TNTPrimed) event.getEntity());
|
||||||
|
|
||||||
|
record((TNTPrimed) event.getEntity(), activeTraces.get(region));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,11 @@ public class TNTRecord {
|
|||||||
*/
|
*/
|
||||||
private final TNTRecord previous;
|
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){
|
public TNTRecord(TNTPrimed tnt, boolean explosion, long ticksSinceStart, TNTRecord previous){
|
||||||
this.explosion = explosion;
|
this.explosion = explosion;
|
||||||
this.ticksSinceStart = ticksSinceStart;
|
this.ticksSinceStart = ticksSinceStart;
|
||||||
@ -64,4 +69,13 @@ public class TNTRecord {
|
|||||||
velocity = tnt.getVelocity();
|
velocity = tnt.getVelocity();
|
||||||
this.previous = previous;
|
this.previous = previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One call only function to set next
|
||||||
|
* @param next
|
||||||
|
*/
|
||||||
|
protected void setNext(TNTRecord next){
|
||||||
|
if(this.next == null) this.next = next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,5 +19,20 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.tracer2;
|
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){
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,19 @@
|
|||||||
package de.steamwar.bausystem.features.tracer2;
|
package de.steamwar.bausystem.features.tracer2;
|
||||||
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
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.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TraceManager {
|
@Linked
|
||||||
|
public class TraceManager implements Listener {
|
||||||
/**
|
/**
|
||||||
* Map of all current traces
|
* Map of all current traces
|
||||||
*/
|
*/
|
||||||
@ -35,6 +43,8 @@ public class TraceManager {
|
|||||||
*/
|
*/
|
||||||
private int currOpenId = 0;
|
private int currOpenId = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Adds a new trace to the global record
|
/** Adds a new trace to the global record
|
||||||
*
|
*
|
||||||
* @param trace Trace to be added
|
* @param trace Trace to be added
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren