From 4f2a6a70c484606e08ad618f732b932adc4afa99 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Oct 2022 18:12:51 +0200 Subject: [PATCH] Possible optimization of trace recorder Signed-off-by: yoyosource --- .../bausystem/features/tracer/record/Recorder.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java index faabcc62..06a84e46 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -36,9 +36,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; -import java.util.HashMap; -import java.util.Map; -import java.util.ArrayList; +import java.util.*; import java.util.stream.Collectors; @Linked @@ -135,12 +133,19 @@ public class Recorder implements Listener { } } + private Set activeTNTs = new HashSet<>(); + + { + activeTNTs.addAll(world.getEntitiesByClass(TNTPrimed.class)); + } + @EventHandler public void onEntitySpawn(EntitySpawnEvent event) { Entity entity = event.getEntity(); if (!(entity instanceof TNTPrimed)) { return; } + activeTNTs.add((TNTPrimed) entity); get((TNTPrimed) entity).spawn((TNTPrimed) entity); } @@ -157,7 +162,7 @@ public class Recorder implements Listener { } private void tick() { - world.getEntitiesByClass(TNTPrimed.class).forEach(tntPrimed -> { + activeTNTs.forEach(tntPrimed -> { get(tntPrimed).tick(tntPrimed); }); } @@ -172,6 +177,7 @@ public class Recorder implements Listener { Region region = tntTraceRecorderMap.get((TNTPrimed) entity); traceRecorder.explode((TNTPrimed) entity, !event.blockList().isEmpty() && region.inRegion(event.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)); tntTraceRecorderMap.remove(entity); + activeTNTs.remove(entity); tick(); } }