SteamWar/BauSystem2.0
Archiviert
12
0

Add basic Simulator Preview
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-08-31 16:53:21 +02:00
Ursprung a83b538b04
Commit bb489fd185
18 geänderte Dateien mit 314 neuen und 188 gelöschten Zeilen

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator;
public class Simulator15 implements Simulator {
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> toCalculate) {
return null;
}
}

Datei anzeigen

@ -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 * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator; package de.steamwar.bausystem.features.simulator.preview;
import org.bukkit.Axis; import org.bukkit.Axis;
import org.bukkit.util.BoundingBox; import org.bukkit.util.BoundingBox;

Datei anzeigen

@ -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 * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator; package de.steamwar.bausystem.features.simulator.preview;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged; import org.bukkit.block.data.Waterlogged;
import org.bukkit.util.Vector;
import java.util.*; import java.util.*;

Datei anzeigen

@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator; package de.steamwar.bausystem.features.simulator.preview;
import org.bukkit.Axis; import org.bukkit.Axis;
import org.bukkit.util.BoundingBox; import org.bukkit.util.BoundingBox;

Datei anzeigen

@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator; package de.steamwar.bausystem.features.simulator.preview;
import lombok.Data; import lombok.Data;

Datei anzeigen

@ -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 * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
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.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.util.BoundingBox; import org.bukkit.util.BoundingBox;
import org.bukkit.util.Vector;
import org.bukkit.util.VoxelShape; import org.bukkit.util.VoxelShape;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
public class Simulator19 implements Simulator { public class Simulator19 implements Simulator {
@ -55,18 +57,42 @@ public class Simulator19 implements Simulator {
private static final Map<Pos, VoxelShape> COLLISION_DATA_MAP = new HashMap<>(); private static final Map<Pos, VoxelShape> COLLISION_DATA_MAP = new HashMap<>();
@Override @Override
public synchronized void run() { public synchronized PreviewRecord run(Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> toCalculate) {
PreviewRecord previewRecord = new PreviewRecord();
List<TNT> tntList = new ArrayList<>(); List<TNT> tntList = new ArrayList<>();
for (int i = 0; i < 400; i++) { int currentTick = 0;
tntList.add(new TNT(0, 120, 0));
}
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
while (!tntList.isEmpty()) { while (!tntList.isEmpty() || currentTick <= toCalculate.getKey()) {
List<List<Pair<TNTData, Integer>>> 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<TNT> remove = new ArrayList<>(); List<TNT> remove = new ArrayList<>();
for (TNT tnt : tntList) { for (TNT tnt : tntList) {
if (tnt.tick()) { if (tnt.tick()) {
remove.add(tnt); remove.add(tnt);
} }
previewRecord.add(tnt.getX(), tnt.getY(), tnt.getZ());
} }
tntList.removeAll(remove); tntList.removeAll(remove);
} }
@ -79,6 +105,7 @@ public class Simulator19 implements Simulator {
accessed = 0; accessed = 0;
cacheMisses = 0; cacheMisses = 0;
aired = 0; aired = 0;
return previewRecord;
} }
public static Material getBlockType(int x, int y, int z) { // Get BlockType of Chunk Data array? public static Material getBlockType(int x, int y, int z) { // Get BlockType of Chunk Data array?

Datei anzeigen

@ -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 * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator; package de.steamwar.bausystem.features.simulator.preview;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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() {
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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;
}

Datei anzeigen

@ -37,6 +37,7 @@ import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import yapion.hierarchy.types.YAPIONArray; import yapion.hierarchy.types.YAPIONArray;
import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONObject;
import yapion.hierarchy.types.YAPIONType; import yapion.hierarchy.types.YAPIONType;
@ -204,14 +205,37 @@ public class TNTSimulator {
TNTElementGUI.open(player, tntElement, null); TNTElementGUI.open(player, tntElement, null);
} }
public Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> locations(Player p) {
Region region = Region.getRegion(p.getLocation());
Map<Integer, Map<Integer, Set<Pair<TNTData, Integer>>>> result = new HashMap<>();
for (SimulatorElement element : tntElementList) {
if (element.locations(result, region, p.getLocation())) {
return null;
}
}
AtomicInteger maxTick = new AtomicInteger(0);
Map<Integer, List<List<Pair<TNTData, Integer>>>> toSpawn = new HashMap<>();
result.forEach((integer, integerSetMap) -> {
List<Pair<Integer, Set<Pair<TNTData, Integer>>>> 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) { public void start(Player p) {
Region region = Region.getRegion(p.getLocation()); Region region = Region.getRegion(p.getLocation());
Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result = new HashMap<>(); Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> result = locations(p);
boolean regionFrozen = false; if (result == null) {
for (SimulatorElement element : tntElementList) {
regionFrozen |= element.locations(result, region, p.getLocation());
}
if (regionFrozen) {
BauSystem.MESSAGE.send("SIMULATOR_REGION_FROZEN", p); BauSystem.MESSAGE.send("SIMULATOR_REGION_FROZEN", p);
return; return;
} }
@ -228,29 +252,13 @@ public class TNTSimulator {
Recorder.INSTANCE.set(region, new SingleTraceRecorder(region)); Recorder.INSTANCE.set(region, new SingleTraceRecorder(region));
} }
AtomicInteger maxTick = new AtomicInteger(0);
Map<Integer, List<List<Pair<Runnable, Integer>>>> toSpawn = new HashMap<>();
result.forEach((integer, integerSetMap) -> {
List<Pair<Integer, Set<Pair<Runnable, Integer>>>> 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); AtomicInteger currentTick = new AtomicInteger(0);
BauSystem.runTaskTimer(BauSystem.getInstance(), bukkitTask -> { BauSystem.runTaskTimer(BauSystem.getInstance(), bukkitTask -> {
int tick = currentTick.get(); int tick = currentTick.get();
if (tick > maxTick.get()) bukkitTask.cancel(); if (tick > result.getKey()) bukkitTask.cancel();
currentTick.incrementAndGet(); currentTick.incrementAndGet();
List<List<Pair<Runnable, Integer>>> toSpawnInTick = toSpawn.get(tick); List<List<Pair<TNTData, Integer>>> toSpawnInTick = result.getValue().get(tick);
if (toSpawnInTick == null) return; if (toSpawnInTick == null) return;
toSpawnInTick.forEach(pairs -> { toSpawnInTick.forEach(pairs -> {
AtomicBoolean hasSomeLeft = new AtomicBoolean(true); AtomicBoolean hasSomeLeft = new AtomicBoolean(true);
@ -259,7 +267,7 @@ public class TNTSimulator {
pairs.forEach(pair -> { pairs.forEach(pair -> {
if (pair.getValue() > 0) { if (pair.getValue() > 0) {
hasSomeLeft.set(true); hasSomeLeft.set(true);
pair.getKey().run(); spawn(pair.getKey());
pair.setValue(pair.getValue() - 1); pair.setValue(pair.getValue() - 1);
} }
}); });
@ -267,4 +275,13 @@ public class TNTSimulator {
}); });
}, 1, 1); }, 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));
});
}
} }

Datei anzeigen

@ -22,6 +22,9 @@ package de.steamwar.bausystem.features.simulator;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.features.simulator.gui.SimulatorSelectionGUI; 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.ItemUtils;
import de.steamwar.bausystem.utils.RayTraceUtils; import de.steamwar.bausystem.utils.RayTraceUtils;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
@ -33,6 +36,8 @@ import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import java.util.List;
import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
@Linked @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<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> toCalculate = simulator.locations(event.getPlayer());
PreviewRecord previewRecord = Simulator.impl.run(toCalculate);
previewRecord.add(event.getPlayer());
}
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (!ItemUtils.isItem(event.getItem(), "simulator")) { if (!ItemUtils.isItem(event.getItem(), "simulator")) {

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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();
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Vector> 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);
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> toCalculate);
}

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bausystem.features.simulator.tnt; package de.steamwar.bausystem.features.simulator.tnt;
import de.steamwar.bausystem.features.simulator.TNTData;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import de.steamwar.entity.REntity; import de.steamwar.entity.REntity;
@ -46,7 +47,7 @@ public interface SimulatorElement {
void remove(TNTElement tntElement); void remove(TNTElement tntElement);
SWItem menu(Player p); SWItem menu(Player p);
boolean locations(Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result, Region region, Location location); // Ticks to subtick order to spawning runnable to count of activations boolean locations(Map<Integer, Map<Integer, Set<Pair<TNTData, Integer>>>> result, Region region, Location location); // Ticks to subtick order to spawning runnable to count of activations
int tntCount(); int tntCount();
int tick(); int tick();

Datei anzeigen

@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.simulator.tnt;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.simulator.OrderUtils; import de.steamwar.bausystem.features.simulator.OrderUtils;
import de.steamwar.bausystem.features.simulator.SimulatorStorage; 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.Region;
import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode;
@ -189,7 +190,7 @@ public class TNTElement implements SimulatorElement {
} }
@Override @Override
public boolean locations(Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result, Region region, Location radius) { public boolean locations(Map<Integer, Map<Integer, Set<Pair<TNTData, Integer>>>> result, Region region, Location radius) {
if (disabled) return false; if (disabled) return false;
Location location = getPosition().toLocation(SimulatorStorage.WORLD); Location location = getPosition().toLocation(SimulatorStorage.WORLD);
if (region.isGlobal() && location.distanceSquared(radius) > 10000) { if (region.isGlobal() && location.distanceSquared(radius) > 10000) {
@ -205,14 +206,7 @@ public class TNTElement implements SimulatorElement {
result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>()) result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>())
.computeIfAbsent(OrderUtils.order(order), ignore -> new HashSet<>()) .computeIfAbsent(OrderUtils.order(order), ignore -> new HashSet<>())
.add(new Pair<>(() -> { .add(new Pair<>(new TNTData(location, fuseTicks, xVelocity, yVelocity, zVelocity), count));
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));
return false; return false;
} }

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.bausystem.features.simulator.tnt; package de.steamwar.bausystem.features.simulator.tnt;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.simulator.TNTData;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import de.steamwar.entity.REntity; import de.steamwar.entity.REntity;
@ -140,7 +141,7 @@ public class TNTGroup implements SimulatorElement {
} }
@Override @Override
public boolean locations(Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result, Region region, Location location) { public boolean locations(Map<Integer, Map<Integer, Set<Pair<TNTData, Integer>>>> result, Region region, Location location) {
if (disabled) return false; if (disabled) return false;
for (TNTElement element : elements) { for (TNTElement element : elements) {
if (element.locations(result, region, location)) { if (element.locations(result, region, location)) {