SteamWar/BauSystem2.0
Archiviert
12
0

Fix DepthCounterListener

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-07-30 21:29:27 +02:00
Ursprung 1cfac014b6
Commit 66eb89c186

Datei anzeigen

@ -24,12 +24,15 @@ import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.region.utils.RegionType;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
@Linked(LinkageType.LISTENER) @Linked(LinkageType.LISTENER)
public class DepthCounterListener implements Listener { public class DepthCounterListener implements Listener {
@ -37,18 +40,19 @@ public class DepthCounterListener implements Listener {
@EventHandler @EventHandler
public void onEntityExplode(EntityExplodeEvent event) { public void onEntityExplode(EntityExplodeEvent event) {
Region region = Region.getRegion(event.getLocation()); Region region = Region.getRegion(event.getLocation());
boolean testblock = event.blockList().stream().anyMatch(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)); List<Block> blockList = event.blockList();
if (!testblock) { blockList = blockList.stream().filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)).collect(Collectors.toList());
if (blockList.isEmpty()) {
return; return;
} }
DepthCounter.depthMap.putIfAbsent(region, new HashSet<>()); DepthCounter.depthMap.putIfAbsent(region, new HashSet<>());
Set<Depth> depthSet = DepthCounter.depthMap.get(region); Set<Depth> depthSet = DepthCounter.depthMap.get(region);
for (Depth depth : depthSet) { for (Depth depth : depthSet) {
if (depth.update(event.blockList())) { if (depth.update(blockList)) {
return; return;
} }
} }
depthSet.add(new Depth(region, event.blockList())); depthSet.add(new Depth(region, blockList));
} }
} }