SteamWar/BauSystem2.0
Archiviert
12
0

SimRework2.0 #216

Zusammengeführt
YoyoNow hat 49 Commits von SimRework2.0 nach master 2023-12-16 12:30:57 +01:00 zusammengeführt
4 geänderte Dateien mit 65 neuen und 13 gelöschten Zeilen
Nur Änderungen aus Commit 21ec66b4e2 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -34,12 +34,14 @@ import de.steamwar.bausystem.features.simulator2.execute.SimulatorExecutor;
import de.steamwar.bausystem.features.simulator2.gui.SimulatorGroupGui; import de.steamwar.bausystem.features.simulator2.gui.SimulatorGroupGui;
import de.steamwar.bausystem.features.simulator2.gui.SimulatorGui; import de.steamwar.bausystem.features.simulator2.gui.SimulatorGui;
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui;
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.entity.REntity; 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.inventory.SWAnvilInv; import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@ -137,7 +139,7 @@ public class SimulatorCursor implements Listener {
} }
} }
private void calcCursor(Player player) { private synchronized void calcCursor(Player player) {
if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) {
removeCursor(player); removeCursor(player);
SimulatorWatcher.show(null, player); SimulatorWatcher.show(null, player);
@ -151,7 +153,11 @@ public class SimulatorCursor implements Listener {
RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), entities); RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), entities);
if (rayTraceResult == null) { if (rayTraceResult == null) {
removeCursor(player); removeCursor(player);
SWUtils.sendToActionbar(player, ""); if (simulator == null) {
SWUtils.sendToActionbar(player, "§eSelect Simulator");
} else {
SWUtils.sendToActionbar(player, "§eOpen Simulator");
}
return; return;
} }
@ -324,11 +330,18 @@ public class SimulatorCursor implements Listener {
RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), SimulatorWatcher.getEntitiesOfSimulator(simulator)); RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), SimulatorWatcher.getEntitiesOfSimulator(simulator));
if (simulator == null) { if (simulator == null) {
if (rayTraceResult == null) { if (rayTraceResult == null) {
// TODO: Open Simulator Selection GUI SimulatorStorage.openSimulatorSelector(player);
} else { } else {
SWAnvilInv anvilInv = new SWAnvilInv(player, "Name"); SWAnvilInv anvilInv = new SWAnvilInv(player, "Name");
anvilInv.setCallback(s -> { anvilInv.setCallback(s -> {
// TODO: Check if Sim exists then close and message, otherwise create sim and add first tnt open that! Simulator sim = SimulatorStorage.getSimulator(s);
if (sim != null) {
player.sendMessage("§cThe simulator " + s + " already exists");
return;
}
sim = new Simulator(s);
SimulatorStorage.addSimulator(s, sim);
createElement(player, rayTraceResult, sim);
}); });
anvilInv.open(); anvilInv.open();
} }
@ -373,6 +386,10 @@ public class SimulatorCursor implements Listener {
} }
// Add new Element to current simulator // Add new Element to current simulator
createElement(player, rayTraceResult, simulator);
}
private void createElement(Player player, RayTraceUtils.RRayTraceResult rayTraceResult, Simulator simulator) {
CursorType type = cursorType.getOrDefault(player, CursorType.TNT); CursorType type = cursorType.getOrDefault(player, CursorType.TNT);
Vector vector = type.position.apply(player, rayTraceResult); Vector vector = type.position.apply(player, rayTraceResult);
if (type == CursorType.REDSTONE_BLOCK) { if (type == CursorType.REDSTONE_BLOCK) {

Datei anzeigen

@ -21,11 +21,14 @@ package de.steamwar.bausystem.features.simulator2;
import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.features.simulator2.data.Simulator; import de.steamwar.bausystem.features.simulator2.data.Simulator;
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui;
import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.bausystem.utils.ItemUtils;
import de.steamwar.inventory.SWItem;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -51,7 +54,32 @@ public class SimulatorStorage {
return simulatorMap.computeIfAbsent(selection, SimulatorStorage::loadSimulator); return simulatorMap.computeIfAbsent(selection, SimulatorStorage::loadSimulator);
} }
public static Simulator getSimulator(String name) {
return simulatorMap.computeIfAbsent(name, SimulatorStorage::loadSimulator);
}
public static void addSimulator(String name, Simulator simulator) {
simulatorMap.putIfAbsent(name, simulator);
}
private static Simulator loadSimulator(String name) { private static Simulator loadSimulator(String name) {
return SimulatorTestCommand.SIMULATOR; // TODO: Implement Loading and legacy Loading return SimulatorTestCommand.SIMULATOR; // TODO: Implement Loading and legacy Loading
} }
public static void openSimulatorSelector(Player player) {
SimulatorPageGui<Simulator> simulatorPageGui = new SimulatorPageGui<Simulator>(player, null, 6*9, new ArrayList<>(simulatorMap.values())) {
@Override
public String baseTitle() {
return "Simulators";
}
@Override
public SWItem convert(Simulator simulator) {
return simulator.toItem(player, clickType -> {
System.out.println(clickType);
});
}
};
simulatorPageGui.open();
}
} }

Datei anzeigen

@ -40,6 +40,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@UtilityClass @UtilityClass
public class SimulatorWatcher { public class SimulatorWatcher {
@ -56,7 +57,7 @@ public class SimulatorWatcher {
} }
} }
public void update(Simulator simulator) { public synchronized void update(Simulator simulator) {
REntityServer rEntityServer = entityServers.get(simulator); REntityServer rEntityServer = entityServers.get(simulator);
if (rEntityServer != null) { if (rEntityServer != null) {
rEntityServer.getEntities().forEach(REntity::die); rEntityServer.getEntities().forEach(REntity::die);
@ -85,19 +86,23 @@ 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(SimulatorGroup::getElements).flatMap(List::stream).forEach(simulatorElement -> { simulator.getElements().stream().map(group -> group.getElements().stream().map(element -> new Pair<>(group, element)).collect(Collectors.toList())).flatMap(List::stream).forEach(pair -> {
boolean wasNotPresent = positionCache.computeIfAbsent(simulatorElement.getPosition(), __ -> new HashSet<>()) SimulatorGroup group = pair.getKey();
.add(simulatorElement.getClass()); // TODO: Disabled material
SimulatorElement<?> element = pair.getValue();
boolean wasNotPresent = positionCache.computeIfAbsent(element.getPosition(), __ -> new HashSet<>())
.add(element.getClass());
if (!wasNotPresent) return; if (!wasNotPresent) return;
Material material = simulatorElement.getWorldMaterial(); Material material = element.getWorldMaterial();
Location location = simulatorElement.getWorldPos().toLocation(WORLD); Location location = element.getWorldPos().toLocation(WORLD);
RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(server, location, material); RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(server, location, material);
rFallingBlockEntity.setNoGravity(true); rFallingBlockEntity.setNoGravity(true);
}); });
return server; return server;
} }
public void show(Simulator sim, Player player) { public synchronized void show(Simulator sim, Player player) {
entityServers.forEach((simulator, rEntityServer) -> { entityServers.forEach((simulator, rEntityServer) -> {
if (rEntityServer == null) return; if (rEntityServer == null) return;
if (rEntityServer.getPlayers().contains(player) && sim != simulator) { if (rEntityServer.getPlayers().contains(player) && sim != simulator) {
@ -108,7 +113,7 @@ public class SimulatorWatcher {
entityServers.computeIfAbsent(sim, __ -> createSim(new REntityServer(), sim)).addPlayer(player); entityServers.computeIfAbsent(sim, __ -> createSim(new REntityServer(), sim)).addPlayer(player);
} }
List<REntity> getEntitiesOfSimulator(Simulator simulator) { synchronized List<REntity> getEntitiesOfSimulator(Simulator simulator) {
REntityServer entityServer = entityServers.get(simulator); REntityServer entityServer = entityServers.get(simulator);
if (entityServer == null) { if (entityServer == null) {
return Collections.emptyList(); return Collections.emptyList();

Datei anzeigen

@ -55,7 +55,9 @@ public class RedstonePhase extends SimulatorPhase {
Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
previousBlockState.set(block.getState()); previousBlockState.set(block.getState());
block.setType(Material.REDSTONE_BLOCK); block.setType(Material.REDSTONE_BLOCK);
previousBlockState.get().update(true, true); if (lifetime == 0) {
previousBlockState.get().update(true, true);
}
} }
}); });