Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
a83b538b04
Commit
bb489fd185
@ -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 {
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
* 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;
|
||||
package de.steamwar.bausystem.features.simulator.preview;
|
||||
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.util.BoundingBox;
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
* 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;
|
||||
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.*;
|
||||
|
@ -17,7 +17,7 @@
|
||||
* 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.util.BoundingBox;
|
@ -17,7 +17,7 @@
|
||||
* 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;
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
* 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;
|
||||
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<Pos, VoxelShape> COLLISION_DATA_MAP = new HashMap<>();
|
||||
|
||||
@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<>();
|
||||
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<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<>();
|
||||
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?
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
* 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;
|
||||
package de.steamwar.bausystem.features.simulator.preview;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
@ -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() {
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
@ -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<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) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result = new HashMap<>();
|
||||
boolean regionFrozen = false;
|
||||
for (SimulatorElement element : tntElementList) {
|
||||
regionFrozen |= element.locations(result, region, p.getLocation());
|
||||
}
|
||||
if (regionFrozen) {
|
||||
Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> 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<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);
|
||||
BauSystem.runTaskTimer(BauSystem.getInstance(), bukkitTask -> {
|
||||
int tick = currentTick.get();
|
||||
if (tick > maxTick.get()) bukkitTask.cancel();
|
||||
if (tick > result.getKey()) bukkitTask.cancel();
|
||||
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;
|
||||
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));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> 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")) {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
@ -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<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 tick();
|
||||
|
||||
|
@ -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<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;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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<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;
|
||||
for (TNTElement element : elements) {
|
||||
if (element.locations(result, region, location)) {
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren