SimRework2.0 #216
23
BauSystem_15/src/de/steamwar/bausystem/utils/TickListener15.java
Normale Datei
23
BauSystem_15/src/de/steamwar/bausystem/utils/TickListener15.java
Normale Datei
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* 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.utils;
|
||||||
|
|
||||||
|
public class TickListener15 implements TickListener {
|
||||||
|
}
|
@ -51,6 +51,7 @@ dependencies {
|
|||||||
implementation project(":BauSystem_Main")
|
implementation project(":BauSystem_Main")
|
||||||
|
|
||||||
compileOnly 'org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT'
|
compileOnly 'org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT'
|
||||||
|
compileOnly 'io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT'
|
||||||
compileOnly 'it.unimi.dsi:fastutil:8.5.6'
|
compileOnly 'it.unimi.dsi:fastutil:8.5.6'
|
||||||
compileOnly 'com.mojang:datafixerupper:4.0.26'
|
compileOnly 'com.mojang:datafixerupper:4.0.26'
|
||||||
compileOnly 'io.netty:netty-all:4.1.68.Final'
|
compileOnly 'io.netty:netty-all:4.1.68.Final'
|
||||||
|
51
BauSystem_19/src/de/steamwar/bausystem/utils/TickListener19.java
Normale Datei
51
BauSystem_19/src/de/steamwar/bausystem/utils/TickListener19.java
Normale Datei
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* 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.utils;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.event.server.ServerTickEndEvent;
|
||||||
|
import com.destroystokyo.paper.event.server.ServerTickStartEvent;
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.features.tpslimit.TPSFreezeUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class TickListener19 implements TickListener, Listener {
|
||||||
|
|
||||||
|
private boolean tickStartRan = false;
|
||||||
|
|
||||||
|
public TickListener19() {
|
||||||
|
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onServerTickStart(ServerTickStartEvent event) {
|
||||||
|
if (TPSFreezeUtils.isFrozen()) return;
|
||||||
|
Bukkit.getPluginManager().callEvent(new TickStartEvent());
|
||||||
|
tickStartRan = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onServerTickEnd(ServerTickEndEvent event) {
|
||||||
|
if (!tickStartRan) return;
|
||||||
|
Bukkit.getPluginManager().callEvent(new TickEndEvent());
|
||||||
|
tickStartRan = false;
|
||||||
|
}
|
||||||
|
}
|
@ -27,6 +27,7 @@ import de.steamwar.bausystem.linkage.LinkageUtils;
|
|||||||
import de.steamwar.bausystem.region.loader.PrototypeLoader;
|
import de.steamwar.bausystem.region.loader.PrototypeLoader;
|
||||||
import de.steamwar.bausystem.region.loader.RegionLoader;
|
import de.steamwar.bausystem.region.loader.RegionLoader;
|
||||||
import de.steamwar.bausystem.region.loader.Updater;
|
import de.steamwar.bausystem.region.loader.Updater;
|
||||||
|
import de.steamwar.bausystem.utils.TickListener;
|
||||||
import de.steamwar.bausystem.worlddata.WorldData;
|
import de.steamwar.bausystem.worlddata.WorldData;
|
||||||
import de.steamwar.message.Message;
|
import de.steamwar.message.Message;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -76,6 +77,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
LinkageUtils.link();
|
LinkageUtils.link();
|
||||||
RamUsage.init();
|
RamUsage.init();
|
||||||
|
TickListener.impl.init();
|
||||||
|
|
||||||
// This could disable any watchdog stuff. We need to investigate if this is a problem.
|
// This could disable any watchdog stuff. We need to investigate if this is a problem.
|
||||||
/*
|
/*
|
||||||
|
@ -30,12 +30,14 @@ import de.steamwar.command.TypeMapper;
|
|||||||
import de.steamwar.command.TypeValidator;
|
import de.steamwar.command.TypeValidator;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import de.steamwar.linkage.LinkedInstance;
|
import de.steamwar.linkage.LinkedInstance;
|
||||||
|
import de.steamwar.linkage.MinVersion;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
|
@MinVersion(19)
|
||||||
public class SimulatorCommand extends SWCommand {
|
public class SimulatorCommand extends SWCommand {
|
||||||
|
|
||||||
@LinkedInstance
|
@LinkedInstance
|
||||||
|
@ -41,6 +41,7 @@ import de.steamwar.entity.REntityServer;
|
|||||||
import de.steamwar.entity.RFallingBlockEntity;
|
import de.steamwar.entity.RFallingBlockEntity;
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
import de.steamwar.inventory.SWAnvilInv;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
|
import de.steamwar.linkage.MinVersion;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -66,6 +67,7 @@ import java.util.function.Function;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
|
@MinVersion(19)
|
||||||
public class SimulatorCursor implements Listener {
|
public class SimulatorCursor implements Listener {
|
||||||
|
|
||||||
private final World WORLD = Bukkit.getWorlds().get(0);
|
private final World WORLD = Bukkit.getWorlds().get(0);
|
||||||
@ -366,7 +368,7 @@ public class SimulatorCursor implements Listener {
|
|||||||
if (rayTraceResult.getHitEntity() != null) {
|
if (rayTraceResult.getHitEntity() != null) {
|
||||||
REntity hitEntity = rayTraceResult.getHitEntity();
|
REntity hitEntity = rayTraceResult.getHitEntity();
|
||||||
Vector vector = new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ());
|
Vector vector = new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ());
|
||||||
List<SimulatorElement<?>> elements = simulator.getElements().stream().map(SimulatorGroup::getElements).flatMap(List::stream).filter(element -> {
|
List<SimulatorElement<?>> elements = simulator.getGroups().stream().map(SimulatorGroup::getElements).flatMap(List::stream).filter(element -> {
|
||||||
return element.getWorldPos().distanceSquared(vector) < (1 / 16.0) * (1 / 16.0);
|
return element.getWorldPos().distanceSquared(vector) < (1 / 16.0) * (1 / 16.0);
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
@ -414,7 +416,7 @@ public class SimulatorCursor implements Listener {
|
|||||||
}
|
}
|
||||||
SimulatorElement<?> element = type.elementFunction.apply(vector);
|
SimulatorElement<?> element = type.elementFunction.apply(vector);
|
||||||
SimulatorGroup group = new SimulatorGroup().add(element);
|
SimulatorGroup group = new SimulatorGroup().add(element);
|
||||||
simulator.getElements().add(group);
|
simulator.getGroups().add(group);
|
||||||
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
|
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
|
||||||
element.open(player, simulator, group, simulatorGui);
|
element.open(player, simulator, group, simulatorGui);
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
|
@ -31,6 +31,7 @@ import de.steamwar.bausystem.features.simulator.storage.YAPIONFormatSimulatorLoa
|
|||||||
import de.steamwar.bausystem.utils.ItemUtils;
|
import de.steamwar.bausystem.utils.ItemUtils;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
|
import de.steamwar.linkage.MinVersion;
|
||||||
import de.steamwar.linkage.api.Enable;
|
import de.steamwar.linkage.api.Enable;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -44,6 +45,7 @@ import java.io.IOException;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
|
@MinVersion(19)
|
||||||
public class SimulatorStorage implements Enable {
|
public class SimulatorStorage implements Enable {
|
||||||
|
|
||||||
public static final File simulatorsDir = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "simulators");
|
public static final File simulatorsDir = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "simulators");
|
||||||
|
@ -28,6 +28,7 @@ import de.steamwar.entity.REntity;
|
|||||||
import de.steamwar.entity.REntityServer;
|
import de.steamwar.entity.REntityServer;
|
||||||
import de.steamwar.entity.RFallingBlockEntity;
|
import de.steamwar.entity.RFallingBlockEntity;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
|
import de.steamwar.linkage.MinVersion;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -73,6 +74,7 @@ public class SimulatorWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
|
@MinVersion(19)
|
||||||
public static class QuitListener implements Listener {
|
public static class QuitListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -87,7 +89,7 @@ public class SimulatorWatcher {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Map<Vector, Set<Class<?>>> positionCache = new HashMap<>();
|
Map<Vector, Set<Class<?>>> positionCache = new HashMap<>();
|
||||||
simulator.getElements().stream().map(group -> group.getElements().stream().map(element -> new Pair<>(group, element)).collect(Collectors.toList())).flatMap(List::stream).forEach(pair -> {
|
simulator.getGroups().stream().map(group -> group.getElements().stream().map(element -> new Pair<>(group, element)).collect(Collectors.toList())).flatMap(List::stream).forEach(pair -> {
|
||||||
SimulatorGroup group = pair.getKey();
|
SimulatorGroup group = pair.getKey();
|
||||||
SimulatorElement<?> element = pair.getValue();
|
SimulatorElement<?> element = pair.getValue();
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ import org.bukkit.entity.Player;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ -39,10 +40,10 @@ public final class Simulator {
|
|||||||
private Material material = Material.BARREL;
|
private Material material = Material.BARREL;
|
||||||
private final String name;
|
private final String name;
|
||||||
private boolean autoTrace = false;
|
private boolean autoTrace = false;
|
||||||
private final List<SimulatorGroup> elements = new ArrayList<>();
|
private final List<SimulatorGroup> groups = new ArrayList<>();
|
||||||
|
|
||||||
public void move(int x, int y, int z) {
|
public void move(int x, int y, int z) {
|
||||||
elements.forEach(simulatorGroup -> {
|
groups.forEach(simulatorGroup -> {
|
||||||
simulatorGroup.move(x, y, z);
|
simulatorGroup.move(x, y, z);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -51,14 +52,14 @@ public final class Simulator {
|
|||||||
return new SWItem(material, "§e" + name, invCallback);
|
return new SWItem(material, "§e" + name, invCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toSimulatorActions(Map<Integer, List<SimulatorAction>> actions) {
|
public void toSimulatorActions(BiConsumer<Integer, SimulatorAction> tickStart, BiConsumer<Integer, SimulatorAction> tickEnd) {
|
||||||
elements.forEach(simulatorGroup -> {
|
groups.forEach(simulatorGroup -> {
|
||||||
simulatorGroup.toSimulatorActions(actions);
|
simulatorGroup.toSimulatorActions(tickStart, tickEnd);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Simulator add(SimulatorGroup group) {
|
public Simulator add(SimulatorGroup group) {
|
||||||
elements.add(group);
|
groups.add(group);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ -101,17 +102,17 @@ public abstract class SimulatorElement<T extends SimulatorPhase> {
|
|||||||
return new SWItem(material, "§e" + getName(player), lore, disabled, invCallback);
|
return new SWItem(material, "§e" + getName(player), lore, disabled, invCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toSimulatorActions(Map<Integer, List<SimulatorAction>> actions) {
|
public void toSimulatorActions(BiConsumer<Integer, SimulatorAction> tickStart, BiConsumer<Integer, SimulatorAction> tickEnd) {
|
||||||
if (disabled) return;
|
if (disabled) return;
|
||||||
phases.forEach(phase -> {
|
phases.forEach(phase -> {
|
||||||
phase.toSimulatorActions(actions, position.clone());
|
phase.toSimulatorActions(position.clone(), tickStart, tickEnd);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back);
|
public abstract void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back);
|
||||||
|
|
||||||
public SimulatorGroup getGroup(Simulator simulator) {
|
public SimulatorGroup getGroup(Simulator simulator) {
|
||||||
return simulator.getElements().stream()
|
return simulator.getGroups().stream()
|
||||||
.filter(simulatorGroup -> simulatorGroup.getElements().contains(this))
|
.filter(simulatorGroup -> simulatorGroup.getElements().contains(this))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
@ -31,6 +31,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ -40,7 +41,9 @@ public final class SimulatorGroup {
|
|||||||
private final List<SimulatorElement<?>> elements = new ArrayList<>();
|
private final List<SimulatorElement<?>> elements = new ArrayList<>();
|
||||||
|
|
||||||
public SimulatorGroup add(SimulatorElement<?> element) {
|
public SimulatorGroup add(SimulatorElement<?> element) {
|
||||||
elements.add(element);
|
if (!elements.contains(element)) {
|
||||||
|
elements.add(element);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,10 +85,10 @@ public final class SimulatorGroup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toSimulatorActions(Map<Integer, List<SimulatorAction>> actions) {
|
public void toSimulatorActions(BiConsumer<Integer, SimulatorAction> tickStart, BiConsumer<Integer, SimulatorAction> tickEnd) {
|
||||||
if (disabled) return;
|
if (disabled) return;
|
||||||
elements.forEach(simulatorElement -> {
|
elements.forEach(simulatorElement -> {
|
||||||
simulatorElement.toSimulatorActions(actions);
|
simulatorElement.toSimulatorActions(tickStart, tickEnd);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import yapion.hierarchy.types.YAPIONObject;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ -37,7 +38,7 @@ public abstract class SimulatorPhase {
|
|||||||
protected int lifetime = 80;
|
protected int lifetime = 80;
|
||||||
protected int order = 0;
|
protected int order = 0;
|
||||||
|
|
||||||
public abstract void toSimulatorActions(Map<Integer, List<SimulatorAction>> actions, Vector position);
|
public abstract void toSimulatorActions(Vector position, BiConsumer<Integer, SimulatorAction> tickStart, BiConsumer<Integer, SimulatorAction> tickEnd);
|
||||||
public void saveExtra(YAPIONObject phaseObject) {}
|
public void saveExtra(YAPIONObject phaseObject) {}
|
||||||
public void loadExtra(YAPIONObject phaseObject) {}
|
public void loadExtra(YAPIONObject phaseObject) {}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator.data.redstone;
|
package de.steamwar.bausystem.features.simulator.data.redstone;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||||
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@ -33,6 +34,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public final class RedstonePhase extends SimulatorPhase {
|
public final class RedstonePhase extends SimulatorPhase {
|
||||||
@ -46,31 +48,27 @@ public final class RedstonePhase extends SimulatorPhase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toSimulatorActions(Map<Integer, List<SimulatorAction>> actions, Vector position) {
|
public void toSimulatorActions(Vector position, BiConsumer<Integer, SimulatorAction> tickStart, BiConsumer<Integer, SimulatorAction> tickEnd) {
|
||||||
AtomicReference<BlockState> previousBlockState = new AtomicReference<>();
|
AtomicReference<BlockState> blockState = new AtomicReference<>();
|
||||||
actions.computeIfAbsent(tickOffset, __ -> new ArrayList<>())
|
tickStart.accept(tickOffset, new SimulatorAction(order, 1) {
|
||||||
.add(new SimulatorAction(0, 1) {
|
@Override
|
||||||
@Override
|
public void accept(World world) {
|
||||||
public void accept(World world) {
|
Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||||
// TODO: 0 Tick Pistons not working
|
blockState.set(block.getState());
|
||||||
Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
block.setType(Material.REDSTONE_BLOCK);
|
||||||
previousBlockState.set(block.getState());
|
}
|
||||||
block.setType(Material.REDSTONE_BLOCK);
|
});
|
||||||
if (lifetime == 0) {
|
tickEnd.accept(tickOffset + lifetime, new SimulatorAction(0, 1) {
|
||||||
previousBlockState.get().update(true, true);
|
@Override
|
||||||
}
|
public void accept(World world) {
|
||||||
}
|
BlockState state = blockState.get();
|
||||||
});
|
if (state != null) {
|
||||||
|
state.update(true, true);
|
||||||
if (lifetime == 0) {
|
} else {
|
||||||
return;
|
Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||||
}
|
block.setType(Material.AIR);
|
||||||
actions.computeIfAbsent(tickOffset + lifetime, __ -> new ArrayList<>())
|
}
|
||||||
.add(new SimulatorAction(0, 1) {
|
}
|
||||||
@Override
|
});
|
||||||
public void accept(World world) {
|
|
||||||
previousBlockState.get().update(true, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import yapion.hierarchy.types.YAPIONObject;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ -57,8 +58,8 @@ public final class TNTPhase extends SimulatorPhase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toSimulatorActions(Map<Integer, List<SimulatorAction>> actions, Vector position) {
|
public void toSimulatorActions(Vector position, BiConsumer<Integer, SimulatorAction> tickStart, BiConsumer<Integer, SimulatorAction> tickEnd) {
|
||||||
actions.computeIfAbsent(tickOffset, __ -> new ArrayList<>()).add(new SimulatorAction(order, count) {
|
tickStart.accept(tickOffset, new SimulatorAction(order, count) {
|
||||||
@Override
|
@Override
|
||||||
public void accept(World world) {
|
public void accept(World world) {
|
||||||
TNTPrimed tnt = world.spawn(position.toLocation(world), TNTPrimed.class);
|
TNTPrimed tnt = world.spawn(position.toLocation(world), TNTPrimed.class);
|
||||||
|
@ -19,63 +19,88 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator.execute;
|
package de.steamwar.bausystem.features.simulator.execute;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import lombok.experimental.UtilityClass;
|
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
||||||
|
import de.steamwar.bausystem.utils.TickEndEvent;
|
||||||
|
import de.steamwar.bausystem.utils.TickStartEvent;
|
||||||
|
import de.steamwar.linkage.Linked;
|
||||||
|
import de.steamwar.linkage.MinVersion;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
@UtilityClass
|
@Linked
|
||||||
public class SimulatorExecutor {
|
@MinVersion(19)
|
||||||
|
public class SimulatorExecutor implements Listener {
|
||||||
|
|
||||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||||
private static Set<Simulator> currentlyRunning = new HashSet<>();
|
private static Set<Simulator> currentlyRunning = new HashSet<>();
|
||||||
|
private static Map<Long, Map<Integer, List<SimulatorAction>>> tickStartActions = new HashMap<>();
|
||||||
|
private static Map<Long, List<SimulatorAction>> tickEndActions = new HashMap<>();
|
||||||
|
|
||||||
public boolean run(Simulator simulator) {
|
public static boolean run(Simulator simulator) {
|
||||||
if (currentlyRunning.contains(simulator)) return false;
|
if (currentlyRunning.contains(simulator)) return false;
|
||||||
|
currentlyRunning.add(simulator);
|
||||||
|
|
||||||
Map<Integer, List<SimulatorAction>> map = new HashMap<>();
|
long currentTick = TPSUtils.currentRealTick.get();
|
||||||
simulator.toSimulatorActions(map);
|
AtomicLong lastTick = new AtomicLong();
|
||||||
|
simulator.toSimulatorActions((tickOffset, simulatorAction) -> {
|
||||||
Map<Integer, Map<Integer, List<SimulatorAction>>> actions = new HashMap<>();
|
lastTick.set(Math.max(lastTick.get(), tickOffset));
|
||||||
map.forEach((integer, simulatorActions) -> {
|
tickStartActions.computeIfAbsent(currentTick + tickOffset, __ -> new HashMap<>())
|
||||||
simulatorActions.forEach(simulatorAction -> {
|
.computeIfAbsent(simulatorAction.getOrder(), __ -> new ArrayList<>())
|
||||||
actions.computeIfAbsent(integer, __ -> new HashMap<>()).computeIfAbsent(simulatorAction.getOrder(), __ -> new ArrayList<>()).add(simulatorAction);
|
.add(simulatorAction);
|
||||||
});
|
}, (tickOffset, simulatorAction) -> {
|
||||||
|
lastTick.set(Math.max(lastTick.get(), tickOffset));
|
||||||
|
tickEndActions.computeIfAbsent(currentTick + tickOffset, __ -> new ArrayList<>())
|
||||||
|
.add(simulatorAction);
|
||||||
});
|
});
|
||||||
|
|
||||||
AtomicInteger tick = new AtomicInteger();
|
tickEndActions.computeIfAbsent(currentTick + lastTick.get() + 4, __ -> new ArrayList<>())
|
||||||
BauSystem.runTaskTimer(BauSystem.getInstance(), bukkitTask -> {
|
.add(new SimulatorAction(0, 1) {
|
||||||
if (actions.isEmpty()) {
|
@Override
|
||||||
bukkitTask.cancel();
|
public void accept(World world) {
|
||||||
currentlyRunning.remove(simulator);
|
currentlyRunning.remove(simulator);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int currentTick = tick.getAndIncrement();
|
|
||||||
Map<Integer, List<SimulatorAction>> actionsToRun = actions.remove(currentTick);
|
|
||||||
if (actionsToRun == null) return;
|
|
||||||
List<Integer> keys = new ArrayList<>(actionsToRun.keySet());
|
|
||||||
keys.sort(null);
|
|
||||||
|
|
||||||
for (int actionKey : keys) {
|
|
||||||
List<SimulatorAction> keyedActions = actionsToRun.get(actionKey);
|
|
||||||
while (!keyedActions.isEmpty()) {
|
|
||||||
Collections.shuffle(keyedActions);
|
|
||||||
for (int i = keyedActions.size() - 1 ; i >= 0; i--) {
|
|
||||||
SimulatorAction action = keyedActions.get(i);
|
|
||||||
action.accept(WORLD);
|
|
||||||
action.setCount(action.getCount() - 1);
|
|
||||||
if (action.getCount() == 0) {
|
|
||||||
keyedActions.remove(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}, 0, 1);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onTickStart(TickStartEvent event) {
|
||||||
|
long currentTick = TPSUtils.currentRealTick.get();
|
||||||
|
Map<Integer, List<SimulatorAction>> actionsToRun = tickStartActions.remove(currentTick);
|
||||||
|
if (actionsToRun == null) return;
|
||||||
|
|
||||||
|
List<Integer> keys = new ArrayList<>(actionsToRun.keySet());
|
||||||
|
keys.sort(null);
|
||||||
|
for (int actionKey : keys) {
|
||||||
|
runActions(actionsToRun.get(actionKey));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onTickEnd(TickEndEvent event) {
|
||||||
|
long currentTick = TPSUtils.currentRealTick.get() - 1;
|
||||||
|
List<SimulatorAction> actionsToRun = tickEndActions.remove(currentTick);
|
||||||
|
if (actionsToRun == null) return;
|
||||||
|
runActions(actionsToRun);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runActions(List<SimulatorAction> actionsToRun) {
|
||||||
|
while (!actionsToRun.isEmpty()) {
|
||||||
|
Collections.shuffle(actionsToRun);
|
||||||
|
for (int i = actionsToRun.size() - 1 ; i >= 0; i--) {
|
||||||
|
SimulatorAction action = actionsToRun.get(i);
|
||||||
|
action.accept(WORLD);
|
||||||
|
action.setCount(action.getCount() - 1);
|
||||||
|
if (action.getCount() == 0) {
|
||||||
|
actionsToRun.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui<SimulatorGroup> {
|
|||||||
private final SimulatorBaseGui back;
|
private final SimulatorBaseGui back;
|
||||||
|
|
||||||
public SimulatorGroupChooserGui(Player player, Simulator simulator, SimulatorElement<?> subject, SimulatorGroup parent, SimulatorBaseGui back) {
|
public SimulatorGroupChooserGui(Player player, Simulator simulator, SimulatorElement<?> subject, SimulatorGroup parent, SimulatorBaseGui back) {
|
||||||
super(player, simulator, 6 * 9, simulator.getElements().stream().filter(e -> e != parent).collect(Collectors.toList()));
|
super(player, simulator, 6 * 9, simulator.getGroups().stream().filter(e -> e != parent).collect(Collectors.toList()));
|
||||||
this.subject = subject;
|
this.subject = subject;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.back = back;
|
this.back = back;
|
||||||
@ -53,7 +53,7 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui<SimulatorGroup> {
|
|||||||
inventory.setItem(49, new SWItem(Material.BARRIER, "§cRemove from Group", clickType -> {
|
inventory.setItem(49, new SWItem(Material.BARRIER, "§cRemove from Group", clickType -> {
|
||||||
SimulatorGroup newParent = new SimulatorGroup();
|
SimulatorGroup newParent = new SimulatorGroup();
|
||||||
newParent.add(subject);
|
newParent.add(subject);
|
||||||
simulator.getElements().add(newParent);
|
simulator.getGroups().add(newParent);
|
||||||
parent.getElements().remove(subject);
|
parent.getElements().remove(subject);
|
||||||
back.open();
|
back.open();
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
|
@ -31,7 +31,7 @@ import org.bukkit.entity.Player;
|
|||||||
public class SimulatorGui extends SimulatorPageGui<SimulatorGroup> {
|
public class SimulatorGui extends SimulatorPageGui<SimulatorGroup> {
|
||||||
|
|
||||||
public SimulatorGui(Player player, Simulator simulator) {
|
public SimulatorGui(Player player, Simulator simulator) {
|
||||||
super(player, simulator, 6 * 9, simulator.getElements());
|
super(player, simulator, 6 * 9, simulator.getGroups());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -41,7 +41,7 @@ public class SimulatorGui extends SimulatorPageGui<SimulatorGroup> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void headerAndFooter() {
|
public void headerAndFooter() {
|
||||||
if (simulator.getElements().removeIf(element -> element.getElements().isEmpty() || element.getElements().stream().allMatch(simulatorElement -> simulatorElement.getPhases().isEmpty()))) {
|
if (simulator.getGroups().removeIf(element -> element.getElements().isEmpty() || element.getElements().stream().allMatch(simulatorElement -> simulatorElement.getPhases().isEmpty()))) {
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SimulatorTNTSettingsGui extends SimulatorBaseGui {
|
public class SimulatorTNTSettingsGui extends SimulatorBaseGui { // TODO: Anvil GUI's!
|
||||||
private final TNTElement tnt;
|
private final TNTElement tnt;
|
||||||
private final SimulatorBaseGui back;
|
private final SimulatorBaseGui back;
|
||||||
|
|
||||||
|
@ -83,8 +83,8 @@ public class SimFormatSimulatorLoader implements SimulatorLoader {
|
|||||||
elements.streamObject().forEach(elementObject -> {
|
elements.streamObject().forEach(elementObject -> {
|
||||||
SimulatorElement<?> element;
|
SimulatorElement<?> element;
|
||||||
Supplier<SimulatorPhase> phaseConstructor;
|
Supplier<SimulatorPhase> phaseConstructor;
|
||||||
Vector position = new Vector(groupObject.getDouble("x"), groupObject.getDouble("y"), groupObject.getDouble("z"));
|
Vector position = new Vector(elementObject.getDouble("x"), elementObject.getDouble("y"), elementObject.getDouble("z"));
|
||||||
String type = groupObject.getPlainValue("type");
|
String type = elementObject.getPlainValue("type");
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "TNT":
|
case "TNT":
|
||||||
element = new TNTElement(position);
|
element = new TNTElement(position);
|
||||||
|
@ -37,7 +37,7 @@ public class SimulatorSaver {
|
|||||||
simulatorObject.add("autoTrace", simulator.isAutoTrace());
|
simulatorObject.add("autoTrace", simulator.isAutoTrace());
|
||||||
|
|
||||||
YAPIONArray groups = new YAPIONArray();
|
YAPIONArray groups = new YAPIONArray();
|
||||||
simulator.getElements().forEach(group -> {
|
simulator.getGroups().forEach(group -> {
|
||||||
YAPIONObject groupObject = new YAPIONObject();
|
YAPIONObject groupObject = new YAPIONObject();
|
||||||
groupObject.add("material", group.getMaterial().name());
|
groupObject.add("material", group.getMaterial().name());
|
||||||
groupObject.add("disabled", group.isDisabled());
|
groupObject.add("disabled", group.isDisabled());
|
||||||
|
36
BauSystem_Main/src/de/steamwar/bausystem/utils/TickEndEvent.java
Normale Datei
36
BauSystem_Main/src/de/steamwar/bausystem/utils/TickEndEvent.java
Normale Datei
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* 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.utils;
|
||||||
|
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class TickEndEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
31
BauSystem_Main/src/de/steamwar/bausystem/utils/TickListener.java
Normale Datei
31
BauSystem_Main/src/de/steamwar/bausystem/utils/TickListener.java
Normale Datei
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* 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.utils;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.core.VersionDependent;
|
||||||
|
|
||||||
|
public interface TickListener {
|
||||||
|
|
||||||
|
TickListener impl = VersionDependent.getVersionImpl(BauSystem.getInstance());
|
||||||
|
|
||||||
|
default void init() {
|
||||||
|
}
|
||||||
|
}
|
36
BauSystem_Main/src/de/steamwar/bausystem/utils/TickStartEvent.java
Normale Datei
36
BauSystem_Main/src/de/steamwar/bausystem/utils/TickStartEvent.java
Normale Datei
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* 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.utils;
|
||||||
|
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class TickStartEvent extends Event {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
@ -61,6 +61,10 @@ allprojects {
|
|||||||
maven {
|
maven {
|
||||||
url = uri('https://libraries.minecraft.net')
|
url = uri('https://libraries.minecraft.net')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maven {
|
||||||
|
url = uri("https://repo.papermc.io/repository/maven-public/")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren