diff --git a/BauSystem_15/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator15.java b/BauSystem_15/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator15.java new file mode 100644 index 00000000..36c53f40 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator15.java @@ -0,0 +1,39 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.tracer.record; + +import net.minecraft.server.v1_15_R1.EntityTNTPrimed; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; +import org.bukkit.entity.TNTPrimed; + +import java.util.stream.Stream; + +public class TNTPrimedIterator15 implements TNTPrimedIterator { + + private static final CraftWorld WORLD = (CraftWorld) Bukkit.getWorlds().get(0); + + @Override + public Stream iterator() { + return WORLD.getHandle().entitiesById.values().stream() + .filter(EntityTNTPrimed.class::isInstance) + .map(entity -> (TNTPrimed) entity.getBukkitEntity()); + } +} diff --git a/BauSystem_18/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator18.java b/BauSystem_18/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator18.java new file mode 100644 index 00000000..e6771471 --- /dev/null +++ b/BauSystem_18/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator18.java @@ -0,0 +1,41 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.tracer.record; + +import net.minecraft.world.entity.item.EntityTNTPrimed; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; +import org.bukkit.entity.TNTPrimed; + +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + +public class TNTPrimedIterator18 implements TNTPrimedIterator { + + private static final CraftWorld WORLD = (CraftWorld) Bukkit.getWorlds().get(0); + + @Override + public Stream iterator() { + return StreamSupport.stream(WORLD.getHandle().H().a().spliterator(), false) + .filter(EntityTNTPrimed.class::isInstance) + .map(entity -> (TNTPrimed) entity.getBukkitEntity()); + } +} + diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator19.java b/BauSystem_19/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator19.java new file mode 100644 index 00000000..b56e04b3 --- /dev/null +++ b/BauSystem_19/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator19.java @@ -0,0 +1,41 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.tracer.record; + +import net.minecraft.world.entity.item.EntityTNTPrimed; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; +import org.bukkit.entity.TNTPrimed; + +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + +public class TNTPrimedIterator19 implements TNTPrimedIterator { + + private static final CraftWorld WORLD = (CraftWorld) Bukkit.getWorlds().get(0); + + @Override + public Stream iterator() { + return StreamSupport.stream(WORLD.getHandle().F().a().spliterator(), false) + .filter(EntityTNTPrimed.class::isInstance) + .map(entity -> (TNTPrimed) entity.getBukkitEntity()); + } +} + 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 06a84e46..d24d8a1c 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 @@ -133,19 +133,12 @@ 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); } @@ -162,7 +155,7 @@ public class Recorder implements Listener { } private void tick() { - activeTNTs.forEach(tntPrimed -> { + TNTPrimedIterator.impl.iterator().forEach(tntPrimed -> { get(tntPrimed).tick(tntPrimed); }); } @@ -177,7 +170,6 @@ 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(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator.java new file mode 100644 index 00000000..a6f05b5e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator.java @@ -0,0 +1,32 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.tracer.record; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.core.VersionDependent; +import org.bukkit.entity.TNTPrimed; + +import java.util.stream.Stream; + +public interface TNTPrimedIterator { + TNTPrimedIterator impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); + + Stream iterator(); +}