|
|
|
@ -20,22 +20,21 @@
|
|
|
|
|
package de.steamwar.bausystem.features.tracer2;
|
|
|
|
|
|
|
|
|
|
import de.steamwar.bausystem.BauSystem;
|
|
|
|
|
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
|
|
|
|
import de.steamwar.bausystem.region.Region;
|
|
|
|
|
import de.steamwar.linkage.Linked;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
@Linked
|
|
|
|
|
public class Recorder {
|
|
|
|
|
public class Recorder implements Listener {
|
|
|
|
|
/**
|
|
|
|
|
* Map for all traces beeing activly recorded
|
|
|
|
|
*/
|
|
|
|
@ -67,22 +66,50 @@ public class Recorder {
|
|
|
|
|
*/
|
|
|
|
|
public void stopRecording(Region region){
|
|
|
|
|
activeTraces.remove(region);
|
|
|
|
|
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptySet())) lastRecordMap.remove(tnt);
|
|
|
|
|
trackedTNT.put(region, new HashSet<>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Internal methode to record all tracked TNT Entities
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
private void record(){
|
|
|
|
|
for(Region region : activeTraces.keySet()){
|
|
|
|
|
Trace trace = activeTraces.get(region);
|
|
|
|
|
for(TNTPrimed tnt : trackedTNT.getOrDefault(region, Collections.emptySet())){
|
|
|
|
|
TNTRecord record = new TNTRecord(tnt, false, TPSUtils.currentTick.get() - trace.getStartTime(), lastRecordMap.getOrDefault(tnt, null));
|
|
|
|
|
lastRecordMap.put(tnt, record);
|
|
|
|
|
trace.add(record);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Internal methode to record exploded tnt
|
|
|
|
|
*
|
|
|
|
|
* @param tntPrimed tnt exploding
|
|
|
|
|
*/
|
|
|
|
|
private void record(TNTPrimed tntPrimed){
|
|
|
|
|
Region region = Region.getRegion(tntPrimed.getLocation());
|
|
|
|
|
Trace trace = activeTraces.get(region);
|
|
|
|
|
|
|
|
|
|
TNTRecord record = new TNTRecord(tntPrimed, true, TPSUtils.currentTick.get() - trace.getStartTime(), lastRecordMap.getOrDefault(tntPrimed, null));
|
|
|
|
|
trace.add(record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Eventhandler for TNTs beeing spawn.
|
|
|
|
|
* Registers newly spawn to be traced if reqired
|
|
|
|
|
* Registers newly spawned TNT to be traced if reqired
|
|
|
|
|
* @param event
|
|
|
|
|
*/
|
|
|
|
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
|
|
|
|
public void onTNTPrimed(EntitySpawnEvent event){
|
|
|
|
|
public void onTNTSpawn(EntitySpawnEvent event){
|
|
|
|
|
if(!(event.getEntity() instanceof TNTPrimed)) return;
|
|
|
|
|
Region region = Region.getRegion(event.getLocation());
|
|
|
|
|
if(activeTraces.keySet().contains(region)){
|
|
|
|
|
//Check whether set for tracking already exists. Creating it if necessary
|
|
|
|
|
if(!trackedTNT.keySet().contains(region)) trackedTNT.put(region, new HashSet<>());
|
|
|
|
|
|
|
|
|
|
trackedTNT.get(region).add((TNTPrimed) event.getEntity());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Event for TNTs exploding
|
|
|
|
@ -91,6 +118,9 @@ public class Recorder {
|
|
|
|
|
*/
|
|
|
|
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
|
|
|
|
public void onTNTExplode(EntityExplodeEvent event){
|
|
|
|
|
|
|
|
|
|
if(!(event.getEntity() instanceof TNTPrimed)) return;
|
|
|
|
|
Region region = Region.getRegion(event.getLocation());
|
|
|
|
|
trackedTNT.get(region).remove((TNTPrimed) event.getEntity());
|
|
|
|
|
record((TNTPrimed) event.getEntity());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|