diff --git a/BauSystem_15/src/de/steamwar/bausystem/features/simulator/Simulator15.java b/BauSystem_15/src/de/steamwar/bausystem/features/simulator/Simulator15.java deleted file mode 100644 index 5576ff45..00000000 --- a/BauSystem_15/src/de/steamwar/bausystem/features/simulator/Simulator15.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2023 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.simulator; - -public class Simulator15 implements Simulator { -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/features/simulator/preview/Simulator15.java b/BauSystem_15/src/de/steamwar/bausystem/features/simulator/preview/Simulator15.java new file mode 100644 index 00000000..0c33b6d8 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/features/simulator/preview/Simulator15.java @@ -0,0 +1,35 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator.preview; + +import de.steamwar.bausystem.features.simulator.TNTData; +import de.steamwar.bausystem.features.simulator.preview.Simulator; +import de.steamwar.bausystem.shared.Pair; + +import java.util.List; +import java.util.Map; + +public class Simulator15 implements Simulator { + + @Override + public PreviewRecord run(Pair>>>> toCalculate) { + return null; + } +} diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/AxisMovementLimiter.java b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/AxisMovementLimiter.java similarity index 84% rename from BauSystem_19/src/de/steamwar/bausystem/features/simulator/AxisMovementLimiter.java rename to BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/AxisMovementLimiter.java index 41eec617..49841c17 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/AxisMovementLimiter.java +++ b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/AxisMovementLimiter.java @@ -1,23 +1,23 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2023 SteamWar.de-Serverteam + * Copyright (C) 2023 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 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. + * 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 . + * 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.simulator; +package de.steamwar.bausystem.features.simulator.preview; import org.bukkit.Axis; import org.bukkit.util.BoundingBox; diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/Explosion.java b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/Explosion.java similarity index 88% rename from BauSystem_19/src/de/steamwar/bausystem/features/simulator/Explosion.java rename to BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/Explosion.java index 468d3c73..6caffe0e 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/Explosion.java +++ b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/Explosion.java @@ -1,28 +1,26 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2023 SteamWar.de-Serverteam + * Copyright (C) 2023 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 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. + * 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 . + * 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.simulator; +package de.steamwar.bausystem.features.simulator.preview; import org.bukkit.Material; -import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Waterlogged; -import org.bukkit.util.Vector; import java.util.*; diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/OptimizedAxisMovementLimiter.java b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/OptimizedAxisMovementLimiter.java similarity index 99% rename from BauSystem_19/src/de/steamwar/bausystem/features/simulator/OptimizedAxisMovementLimiter.java rename to BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/OptimizedAxisMovementLimiter.java index 3ecbf8bd..2f9da376 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/OptimizedAxisMovementLimiter.java +++ b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/OptimizedAxisMovementLimiter.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator; +package de.steamwar.bausystem.features.simulator.preview; import org.bukkit.Axis; import org.bukkit.util.BoundingBox; diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/Pos.java b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/Pos.java similarity index 94% rename from BauSystem_19/src/de/steamwar/bausystem/features/simulator/Pos.java rename to BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/Pos.java index 831c09f5..82a94b9a 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/Pos.java +++ b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/Pos.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.simulator; +package de.steamwar.bausystem.features.simulator.preview; import lombok.Data; diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/Simulator19.java b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/Simulator19.java similarity index 54% rename from BauSystem_19/src/de/steamwar/bausystem/features/simulator/Simulator19.java rename to BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/Simulator19.java index 1f499509..eefa7e10 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/Simulator19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/Simulator19.java @@ -1,33 +1,35 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2023 SteamWar.de-Serverteam + * Copyright (C) 2023 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 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. + * 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 . + * 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.simulator; +package de.steamwar.bausystem.features.simulator.preview; +import de.steamwar.bausystem.features.simulator.TNTData; +import de.steamwar.bausystem.shared.Pair; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.data.BlockData; import org.bukkit.util.BoundingBox; -import org.bukkit.util.Vector; import org.bukkit.util.VoxelShape; import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; public class Simulator19 implements Simulator { @@ -55,18 +57,42 @@ public class Simulator19 implements Simulator { private static final Map COLLISION_DATA_MAP = new HashMap<>(); @Override - public synchronized void run() { + public synchronized PreviewRecord run(Pair>>>> toCalculate) { + PreviewRecord previewRecord = new PreviewRecord(); List tntList = new ArrayList<>(); - for (int i = 0; i < 400; i++) { - tntList.add(new TNT(0, 120, 0)); - } + int currentTick = 0; + long time = System.currentTimeMillis(); - while (!tntList.isEmpty()) { + while (!tntList.isEmpty() || currentTick <= toCalculate.getKey()) { + List>> toSpawnInTick = toCalculate.getValue().get(currentTick); + if (toSpawnInTick != null) { + toSpawnInTick.forEach(pairs -> { + AtomicBoolean hasSomeLeft = new AtomicBoolean(true); + while(hasSomeLeft.get()) { + hasSomeLeft.set(false); + pairs.forEach(pair -> { + if (pair.getValue() > 0) { + hasSomeLeft.set(true); + TNT tnt = new TNT(pair.getKey().location.getX(), pair.getKey().location.getY(), pair.getKey().location.getZ()); + if (!pair.getKey().xVelocity) tnt.setVx(0.0); + if (!pair.getKey().yVelocity) tnt.setVy(0.0); + if (!pair.getKey().zVelocity) tnt.setVz(0.0); + tnt.setFuse(tnt.getFuse()); + tntList.add(tnt); + pair.setValue(pair.getValue() - 1); + } + }); + } + }); + } + currentTick++; + List remove = new ArrayList<>(); for (TNT tnt : tntList) { if (tnt.tick()) { remove.add(tnt); } + previewRecord.add(tnt.getX(), tnt.getY(), tnt.getZ()); } tntList.removeAll(remove); } @@ -79,6 +105,7 @@ public class Simulator19 implements Simulator { accessed = 0; cacheMisses = 0; aired = 0; + return previewRecord; } public static Material getBlockType(int x, int y, int z) { // Get BlockType of Chunk Data array? diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/TNT.java b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/TNT.java similarity index 92% rename from BauSystem_19/src/de/steamwar/bausystem/features/simulator/TNT.java rename to BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/TNT.java index cbc71ab7..0cecafe3 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/TNT.java +++ b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/preview/TNT.java @@ -1,23 +1,23 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2023 SteamWar.de-Serverteam + * Copyright (C) 2023 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 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. + * 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 . + * 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.simulator; +package de.steamwar.bausystem.features.simulator.preview; import lombok.Getter; import lombok.Setter; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/Simulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/Simulator.java deleted file mode 100644 index 6e1a8ab6..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/Simulator.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2023 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.simulator; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.core.VersionDependent; - -public interface Simulator { - Simulator impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); - - default void run() { - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTData.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTData.java new file mode 100644 index 00000000..0bdfdb71 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTData.java @@ -0,0 +1,32 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator; + +import lombok.RequiredArgsConstructor; +import org.bukkit.Location; + +@RequiredArgsConstructor +public class TNTData { + public final Location location; + public final int fuse; + public final boolean xVelocity; + public final boolean yVelocity; + public final boolean zVelocity; +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index d1a71b95..e936fa0b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -37,6 +37,7 @@ import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; import yapion.hierarchy.types.YAPIONArray; import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONType; @@ -204,14 +205,37 @@ public class TNTSimulator { TNTElementGUI.open(player, tntElement, null); } + public Pair>>>> locations(Player p) { + Region region = Region.getRegion(p.getLocation()); + Map>>> result = new HashMap<>(); + for (SimulatorElement element : tntElementList) { + if (element.locations(result, region, p.getLocation())) { + return null; + } + } + + AtomicInteger maxTick = new AtomicInteger(0); + Map>>> toSpawn = new HashMap<>(); + result.forEach((integer, integerSetMap) -> { + List>>> internal = new ArrayList<>(); + integerSetMap.forEach((integer1, pairs) -> { + internal.add(new Pair<>(integer1, pairs)); + }); + internal.sort(Comparator.comparingInt(Pair::getKey)); + + toSpawn.put(integer, internal.stream().map(Pair::getValue).map(ArrayList::new).peek(Collections::shuffle).collect(Collectors.toList())); + + if (maxTick.get() < integer) { + maxTick.set(integer); + } + }); + return new Pair<>(maxTick.get(), toSpawn); + } + public void start(Player p) { Region region = Region.getRegion(p.getLocation()); - Map>>> result = new HashMap<>(); - boolean regionFrozen = false; - for (SimulatorElement element : tntElementList) { - regionFrozen |= element.locations(result, region, p.getLocation()); - } - if (regionFrozen) { + Pair>>>> result = locations(p); + if (result == null) { BauSystem.MESSAGE.send("SIMULATOR_REGION_FROZEN", p); return; } @@ -228,29 +252,13 @@ public class TNTSimulator { Recorder.INSTANCE.set(region, new SingleTraceRecorder(region)); } - AtomicInteger maxTick = new AtomicInteger(0); - Map>>> toSpawn = new HashMap<>(); - result.forEach((integer, integerSetMap) -> { - List>>> internal = new ArrayList<>(); - integerSetMap.forEach((integer1, pairs) -> { - internal.add(new Pair<>(integer1, pairs)); - }); - internal.sort(Comparator.comparingInt(Pair::getKey)); - - toSpawn.put(integer, internal.stream().map(Pair::getValue).map(ArrayList::new).peek(Collections::shuffle).collect(Collectors.toList())); - - if (maxTick.get() < integer) { - maxTick.set(integer); - } - }); - AtomicInteger currentTick = new AtomicInteger(0); BauSystem.runTaskTimer(BauSystem.getInstance(), bukkitTask -> { int tick = currentTick.get(); - if (tick > maxTick.get()) bukkitTask.cancel(); + if (tick > result.getKey()) bukkitTask.cancel(); currentTick.incrementAndGet(); - List>> toSpawnInTick = toSpawn.get(tick); + List>> toSpawnInTick = result.getValue().get(tick); if (toSpawnInTick == null) return; toSpawnInTick.forEach(pairs -> { AtomicBoolean hasSomeLeft = new AtomicBoolean(true); @@ -259,7 +267,7 @@ public class TNTSimulator { pairs.forEach(pair -> { if (pair.getValue() > 0) { hasSomeLeft.set(true); - pair.getKey().run(); + spawn(pair.getKey()); pair.setValue(pair.getValue() - 1); } }); @@ -267,4 +275,13 @@ public class TNTSimulator { }); }, 1, 1); } + + private void spawn(TNTData tntData) { + SimulatorStorage.WORLD.spawn(tntData.location, TNTPrimed.class, tntPrimed -> { + tntPrimed.setFuseTicks(tntData.fuse); + if (!tntData.xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); + if (!tntData.yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); + if (!tntData.zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); + }); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java index a3862c9f..374d1192 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java @@ -22,6 +22,9 @@ package de.steamwar.bausystem.features.simulator; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.simulator.gui.SimulatorSelectionGUI; +import de.steamwar.bausystem.features.simulator.preview.PreviewRecord; +import de.steamwar.bausystem.features.simulator.preview.Simulator; +import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.bausystem.utils.RayTraceUtils; import de.steamwar.linkage.Linked; @@ -33,6 +36,8 @@ import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import java.util.List; +import java.util.Map; import java.util.function.Function; @Linked @@ -95,6 +100,25 @@ public class TNTSimulatorListener implements Listener { }); } + @EventHandler + public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { + if (!ItemUtils.isItem(event.getOffHandItem(), "simulator")) { + return; + } + if (ItemUtils.isItem(event.getMainHandItem(), "simulator")) { + return; + } + if (!permissionCheck(event.getPlayer())) { + return; + } + + TNTSimulator simulator = SimulatorStorage.getSimulator(event.getOffHandItem()); + if (simulator == null) return; + Pair>>>> toCalculate = simulator.locations(event.getPlayer()); + PreviewRecord previewRecord = Simulator.impl.run(toCalculate); + previewRecord.add(event.getPlayer()); + } + @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (!ItemUtils.isItem(event.getItem(), "simulator")) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TestCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TestCommand.java deleted file mode 100644 index c0869fd6..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TestCommand.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2023 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.simulator; - -import de.steamwar.command.SWCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.entity.Player; - -@Linked -public class TestCommand extends SWCommand { - - public TestCommand() { - super("test"); - } - - @Register - public void genericCommand(Player player) { - Simulator.impl.run(); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/PreviewRecord.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/PreviewRecord.java new file mode 100644 index 00000000..b59db64e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/PreviewRecord.java @@ -0,0 +1,53 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator.preview; + +import de.steamwar.entity.REntityServer; +import de.steamwar.entity.RFallingBlockEntity; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class PreviewRecord { + + private Set vectorList = new HashSet<>(); + private REntityServer rEntityServer; + + public void add(double x, double y, double z) { + vectorList.add(new Vector(x, y, z)); + } + + public void add(Player player) { + if (rEntityServer == null) { + rEntityServer = new REntityServer(); + + vectorList.forEach(vector -> { + RFallingBlockEntity entity = new RFallingBlockEntity(rEntityServer, vector.toLocation(player.getWorld()), Material.RED_STAINED_GLASS); + entity.setNoGravity(true); + }); + } + rEntityServer.addPlayer(player); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/Simulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/Simulator.java new file mode 100644 index 00000000..ca3fa2c8 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/preview/Simulator.java @@ -0,0 +1,34 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.simulator.preview; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.simulator.TNTData; +import de.steamwar.bausystem.shared.Pair; +import de.steamwar.core.VersionDependent; + +import java.util.List; +import java.util.Map; + +public interface Simulator { + Simulator impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); + + PreviewRecord run(Pair>>>> toCalculate); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java index 181e3389..c0c67067 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.simulator.tnt; +import de.steamwar.bausystem.features.simulator.TNTData; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.Pair; import de.steamwar.entity.REntity; @@ -46,7 +47,7 @@ public interface SimulatorElement { void remove(TNTElement tntElement); SWItem menu(Player p); - boolean locations(Map>>> result, Region region, Location location); // Ticks to subtick order to spawning runnable to count of activations + boolean locations(Map>>> result, Region region, Location location); // Ticks to subtick order to spawning runnable to count of activations int tntCount(); int tick(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java index 666c3359..6828566b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.simulator.tnt; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.simulator.OrderUtils; import de.steamwar.bausystem.features.simulator.SimulatorStorage; +import de.steamwar.bausystem.features.simulator.TNTData; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; @@ -189,7 +190,7 @@ public class TNTElement implements SimulatorElement { } @Override - public boolean locations(Map>>> result, Region region, Location radius) { + public boolean locations(Map>>> result, Region region, Location radius) { if (disabled) return false; Location location = getPosition().toLocation(SimulatorStorage.WORLD); if (region.isGlobal() && location.distanceSquared(radius) > 10000) { @@ -205,14 +206,7 @@ public class TNTElement implements SimulatorElement { result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>()) .computeIfAbsent(OrderUtils.order(order), ignore -> new HashSet<>()) - .add(new Pair<>(() -> { - SimulatorStorage.WORLD.spawn(location, TNTPrimed.class, tntPrimed -> { - tntPrimed.setFuseTicks(fuseTicks); - if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); - if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); - if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); - }); - }, count)); + .add(new Pair<>(new TNTData(location, fuseTicks, xVelocity, yVelocity, zVelocity), count)); return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java index f3327578..2e4e85b9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.simulator.tnt; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.simulator.TNTData; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.Pair; import de.steamwar.entity.REntity; @@ -140,7 +141,7 @@ public class TNTGroup implements SimulatorElement { } @Override - public boolean locations(Map>>> result, Region region, Location location) { + public boolean locations(Map>>> result, Region region, Location location) { if (disabled) return false; for (TNTElement element : elements) { if (element.locations(result, region, location)) {