Dieser Commit ist enthalten in:
Ursprung
20b116f228
Commit
21ec66b4e2
@ -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.SimulatorGui;
|
||||
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.RayTraceUtils;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RFallingBlockEntity;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import lombok.AllArgsConstructor;
|
||||
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())) {
|
||||
removeCursor(player);
|
||||
SimulatorWatcher.show(null, player);
|
||||
@ -151,7 +153,11 @@ public class SimulatorCursor implements Listener {
|
||||
RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), entities);
|
||||
if (rayTraceResult == null) {
|
||||
removeCursor(player);
|
||||
SWUtils.sendToActionbar(player, "");
|
||||
if (simulator == null) {
|
||||
SWUtils.sendToActionbar(player, "§eSelect Simulator");
|
||||
} else {
|
||||
SWUtils.sendToActionbar(player, "§eOpen Simulator");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -324,11 +330,18 @@ public class SimulatorCursor implements Listener {
|
||||
RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), SimulatorWatcher.getEntitiesOfSimulator(simulator));
|
||||
if (simulator == null) {
|
||||
if (rayTraceResult == null) {
|
||||
// TODO: Open Simulator Selection GUI
|
||||
SimulatorStorage.openSimulatorSelector(player);
|
||||
} else {
|
||||
SWAnvilInv anvilInv = new SWAnvilInv(player, "Name");
|
||||
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();
|
||||
}
|
||||
@ -373,6 +386,10 @@ public class SimulatorCursor implements Listener {
|
||||
}
|
||||
|
||||
// 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);
|
||||
Vector vector = type.position.apply(player, rayTraceResult);
|
||||
if (type == CursorType.REDSTONE_BLOCK) {
|
||||
|
@ -21,11 +21,14 @@ package de.steamwar.bausystem.features.simulator2;
|
||||
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
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.inventory.SWItem;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -51,7 +54,32 @@ public class SimulatorStorage {
|
||||
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) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@UtilityClass
|
||||
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);
|
||||
if (rEntityServer != null) {
|
||||
rEntityServer.getEntities().forEach(REntity::die);
|
||||
@ -85,19 +86,23 @@ public class SimulatorWatcher {
|
||||
return null;
|
||||
}
|
||||
Map<Vector, Set<Class<?>>> positionCache = new HashMap<>();
|
||||
simulator.getElements().stream().map(SimulatorGroup::getElements).flatMap(List::stream).forEach(simulatorElement -> {
|
||||
boolean wasNotPresent = positionCache.computeIfAbsent(simulatorElement.getPosition(), __ -> new HashSet<>())
|
||||
.add(simulatorElement.getClass());
|
||||
simulator.getElements().stream().map(group -> group.getElements().stream().map(element -> new Pair<>(group, element)).collect(Collectors.toList())).flatMap(List::stream).forEach(pair -> {
|
||||
SimulatorGroup group = pair.getKey();
|
||||
// TODO: Disabled material
|
||||
SimulatorElement<?> element = pair.getValue();
|
||||
|
||||
boolean wasNotPresent = positionCache.computeIfAbsent(element.getPosition(), __ -> new HashSet<>())
|
||||
.add(element.getClass());
|
||||
if (!wasNotPresent) return;
|
||||
Material material = simulatorElement.getWorldMaterial();
|
||||
Location location = simulatorElement.getWorldPos().toLocation(WORLD);
|
||||
Material material = element.getWorldMaterial();
|
||||
Location location = element.getWorldPos().toLocation(WORLD);
|
||||
RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(server, location, material);
|
||||
rFallingBlockEntity.setNoGravity(true);
|
||||
});
|
||||
return server;
|
||||
}
|
||||
|
||||
public void show(Simulator sim, Player player) {
|
||||
public synchronized void show(Simulator sim, Player player) {
|
||||
entityServers.forEach((simulator, rEntityServer) -> {
|
||||
if (rEntityServer == null) return;
|
||||
if (rEntityServer.getPlayers().contains(player) && sim != simulator) {
|
||||
@ -108,7 +113,7 @@ public class SimulatorWatcher {
|
||||
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);
|
||||
if (entityServer == null) {
|
||||
return Collections.emptyList();
|
||||
|
@ -55,7 +55,9 @@ public class RedstonePhase extends SimulatorPhase {
|
||||
Block block = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
previousBlockState.set(block.getState());
|
||||
block.setType(Material.REDSTONE_BLOCK);
|
||||
previousBlockState.get().update(true, true);
|
||||
if (lifetime == 0) {
|
||||
previousBlockState.get().update(true, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren