Refactor old sim cursor to use new cursor construct

This commit is contained in:
D4rkr34lm
2025-10-26 14:18:36 +01:00
parent 633dc67be0
commit 4c82469171
29 changed files with 1132 additions and 1263 deletions
@@ -1,20 +1,18 @@
/* /*
* 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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator; package de.steamwar.bausystem.features.simulator;
@@ -22,6 +20,7 @@ package de.steamwar.bausystem.features.simulator;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.display.SimulatorCursor;
import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor; import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor;
import de.steamwar.command.PreviousArguments; import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
@@ -49,12 +48,12 @@ public class SimulatorCommand extends SWCommand {
@Register(description = "SIMULATOR_HELP") @Register(description = "SIMULATOR_HELP")
public void genericCommand(@Validator Player p) { public void genericCommand(@Validator Player p) {
SWUtils.giveItemToPlayer(p, SimulatorStorage.getWand(p)); SWUtils.giveItemToPlayer(p, SimulatorStorage.getWand(p));
simulatorCursor.calcCursor(p); // TODO simulatorCursor.calcCursor(p);
} }
@Register(value = "change", description = "SIMULATOR_CHANGE_HELP") @Register(value = "change", description = "SIMULATOR_CHANGE_HELP")
public void change(@Validator Player p) { public void change(@Validator Player p) {
if (!SimulatorCursor.isSimulatorItem(p.getInventory().getItemInMainHand()) && !SimulatorCursor.isSimulatorItem(p.getInventory().getItemInOffHand())) { if (!SimulatorUtils.isSimulatorItem(p.getInventory().getItemInMainHand()) && !SimulatorUtils.isSimulatorItem(p.getInventory().getItemInOffHand())) {
BauSystem.MESSAGE.send("SIMULATOR_NO_SIM_IN_HAND", p); BauSystem.MESSAGE.send("SIMULATOR_NO_SIM_IN_HAND", p);
return; return;
} }
@@ -1,467 +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.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase;
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor;
import de.steamwar.bausystem.features.simulator.gui.SimulatorGroupGui;
import de.steamwar.bausystem.features.simulator.gui.SimulatorGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
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.linkage.Linked;
import de.steamwar.linkage.MinVersion;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
@Linked
@MinVersion(19)
public class SimulatorCursor implements Listener {
private final World WORLD = Bukkit.getWorlds().get(0);
private Class<?> position = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos");
private Class<?> look = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Rot");
private Class<?> positionLook = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot");
private Map<Player, CursorType> cursorType = Collections.synchronizedMap(new HashMap<>());
private Map<Player, REntityServer> cursors = Collections.synchronizedMap(new HashMap<>());
private final Set<Player> calculating = new HashSet<>();
public static boolean isSimulatorItem(ItemStack itemStack) {
return ItemUtils.isItem(itemStack, "simulator");
}
public SimulatorCursor() {
BiFunction<Player, Object, Object> function = (player, object) -> {
calcCursor(player);
return object;
};
TinyProtocol.instance.addFilter(position, function);
TinyProtocol.instance.addFilter(look, function);
TinyProtocol.instance.addFilter(positionLook, function);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
calcCursor(event.getPlayer());
}, 0);
}
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
calcCursor(event.getPlayer());
}
@EventHandler
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
calcCursor(event.getPlayer());
}, 1);
}
@EventHandler
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
event.getChanged().forEach(this::calcCursor);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
cursorType.remove(event.getPlayer());
cursors.remove(event.getPlayer());
synchronized (calculating) {
calculating.remove(event.getPlayer());
}
}
private static final Map<Player, Long> LAST_SNEAKS = new HashMap<>();
static {
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
long millis = System.currentTimeMillis();
LAST_SNEAKS.entrySet().removeIf(entry -> millis - entry.getValue() > 200);
}, 1, 1);
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
if (!event.isSneaking()) return;
Player player = event.getPlayer();
if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) {
return;
}
if (LAST_SNEAKS.containsKey(player)) {
cursorType.put(player, cursorType.getOrDefault(player, CursorType.TNT).switchType());
calcCursor(player);
} else {
LAST_SNEAKS.put(player, System.currentTimeMillis());
}
}
public void calcCursor(Player player) {
synchronized (calculating) {
if (calculating.contains(player)) return;
calculating.add(player);
}
if (!Permission.BUILD.hasPermission(player) || (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand()))) {
if (removeCursor(player) || SimulatorWatcher.show(null, player)) {
SWUtils.sendToActionbar(player, "");
}
synchronized (calculating) {
calculating.remove(player);
}
return;
}
Simulator simulator = SimulatorStorage.getSimulator(player);
if (simulator != null && simulator.getStabGenerator() != null) {
removeCursor(player);
SimulatorWatcher.show(null, player);
SWUtils.sendToActionbar(player, "§cGenerating Stab");
synchronized (calculating) {
calculating.remove(player);
}
return;
}
SimulatorWatcher.show(simulator, player);
List<REntity> entities = SimulatorWatcher.getEntitiesOfSimulator(simulator);
RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), entities);
if (rayTraceResult == null) {
removeCursor(player);
if (simulator == null) {
SWUtils.sendToActionbar(player, "§eSelect Simulator");
} else {
SWUtils.sendToActionbar(player, "§eOpen Simulator");
}
synchronized (calculating) {
calculating.remove(player);
}
return;
}
showCursor(player, rayTraceResult, simulator != null);
synchronized (calculating) {
calculating.remove(player);
}
}
private synchronized boolean removeCursor(Player player) {
REntityServer entityServer = cursors.get(player);
boolean hadCursor = entityServer != null && !entityServer.getEntities().isEmpty();
if (entityServer != null) {
entityServer.getEntities().forEach(REntity::die);
}
return hadCursor;
}
private synchronized void showCursor(Player player, RayTraceUtils.RRayTraceResult rayTraceResult, boolean hasSimulatorSelected) {
REntityServer entityServer = cursors.computeIfAbsent(player, __ -> {
REntityServer rEntityServer = new REntityServer();
rEntityServer.addPlayer(player);
return rEntityServer;
});
CursorType type = cursorType.getOrDefault(player, CursorType.TNT);
REntity hitEntity = rayTraceResult.getHitEntity();
Location location = hitEntity != null ? new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ()).toLocation(WORLD) :
type.position.apply(player, rayTraceResult).toLocation(WORLD);
Material material = hitEntity != null ? Material.GLASS : type.getMaterial();
List<RFallingBlockEntity> entities = entityServer.getEntitiesByType(RFallingBlockEntity.class);
entities.removeIf(rFallingBlockEntity -> {
if (rFallingBlockEntity.getMaterial() != material) {
rFallingBlockEntity.die();
return true;
}
rFallingBlockEntity.move(location);
return false;
});
if (entities.isEmpty()) {
RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(entityServer, location, material);
rFallingBlockEntity.setNoGravity(true);
if (material == Material.GLASS) {
rFallingBlockEntity.setGlowing(true);
}
}
if (hasSimulatorSelected) {
if (hitEntity != null) {
SWUtils.sendToActionbar(player, "§eEdit Position");
} else {
SWUtils.sendToActionbar(player, "§eAdd new " + type.name);
}
} else {
SWUtils.sendToActionbar(player, "§eCreate new Simulator");
}
}
public static Vector getPosFree(Player player, RayTraceUtils.RRayTraceResult result) {
Vector pos = result.getHitPosition();
BlockFace face = result.getHitBlockFace();
if (face != null) {
switch (face) {
case DOWN:
pos.setY(pos.getY() - 0.98);
break;
case EAST:
pos.setX(pos.getX() + 0.49);
break;
case WEST:
pos.setX(pos.getX() - 0.49);
break;
case NORTH:
pos.setZ(pos.getZ() - 0.49);
break;
case SOUTH:
pos.setZ(pos.getZ() + 0.49);
break;
default:
break;
}
if (face.getModY() == 0 && player.isSneaking()) {
pos.setY(pos.getY() - 0.49);
}
}
if (!player.isSneaking()) {
pos.setX(pos.getBlockX() + 0.5);
if (face == null || face.getModY() == 0)
pos.setY(pos.getBlockY() + 0.0);
pos.setZ(pos.getBlockZ() + 0.5);
}
return pos;
}
private static Vector getPosBlockAligned(Player player, RayTraceUtils.RRayTraceResult result) {
Vector pos = result.getHitPosition();
BlockFace face = result.getHitBlockFace();
if (face != null) {
switch (face) {
case DOWN:
pos.setY(pos.getY() - 0.98);
break;
case EAST:
pos.setX(pos.getX() + 0.49);
break;
case WEST:
pos.setX(pos.getX() - 0.49);
break;
case NORTH:
pos.setZ(pos.getZ() - 0.49);
break;
case SOUTH:
pos.setZ(pos.getZ() + 0.49);
break;
default:
break;
}
}
pos.setX(pos.getBlockX() + 0.5);
if (pos.getY() - pos.getBlockY() != 0 && face == BlockFace.UP) {
pos.setY(pos.getBlockY() + 1.0);
} else {
pos.setY(pos.getBlockY());
}
pos.setZ(pos.getBlockZ() + 0.5);
return pos;
}
@Getter
@AllArgsConstructor
public enum CursorType {
TNT(Material.TNT, SimulatorCursor::getPosFree, "TNT", vector -> new TNTElement(vector).add(new TNTPhase())),
REDSTONE_BLOCK(Material.REDSTONE_BLOCK, SimulatorCursor::getPosBlockAligned, "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase())),
OBSERVER(Material.OBSERVER, SimulatorCursor::getPosBlockAligned, "Observer", vector -> new ObserverElement(vector).add(new ObserverPhase())),
;
private Material material;
private BiFunction<Player, RayTraceUtils.RRayTraceResult, Vector> position;
private String name;
private Function<Vector, SimulatorElement<?>> elementFunction;
public CursorType switchType() {
if (this == TNT) {
return REDSTONE_BLOCK;
}
if (this == REDSTONE_BLOCK) {
return OBSERVER;
}
return TNT;
}
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
if (!ItemUtils.isItem(event.getItem(), "simulator")) {
return;
}
event.setCancelled(true);
Player player = event.getPlayer();
Simulator simulator = SimulatorStorage.getSimulator(player);
if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) {
if (simulator == null) {
return;
}
SimulatorExecutor.run(event.getPlayer(), simulator, null);
return;
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR) {
return;
}
RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), SimulatorWatcher.getEntitiesOfSimulator(simulator));
if (simulator == null) {
if (rayTraceResult == null) {
SimulatorStorage.openSimulatorSelector(player);
} else {
SWAnvilInv anvilInv = new SWAnvilInv(player, "Name");
anvilInv.setCallback(s -> {
Simulator sim = SimulatorStorage.getSimulator(s);
if (sim != null) {
BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", player);
return;
}
if (!s.matches("[a-zA-Z_0-9-]+")) {
BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", player);
return;
}
sim = new Simulator(s);
SimulatorStorage.addSimulator(s, sim);
createElement(player, rayTraceResult, sim);
SimulatorStorage.setSimulator(player, sim);
});
anvilInv.open();
}
return;
}
if (rayTraceResult == null) {
new SimulatorGui(player, simulator).open();
return;
}
if (rayTraceResult.getHitEntity() != null) {
REntity hitEntity = rayTraceResult.getHitEntity();
Vector vector = new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ());
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);
}).collect(Collectors.toList());
switch (elements.size()) {
case 0:
return;
case 1:
// Open single element present in Simulator
SimulatorElement<?> element = elements.get(0);
SimulatorGroup group1 = element.getGroup(simulator);
SimulatorBaseGui back = new SimulatorGui(player, simulator);
if (group1.getElements().size() > 1) {
back = new SimulatorGroupGui(player, simulator, group1, back);
}
element.open(player, simulator, group1, back);
break;
default:
List<SimulatorGroup> parents = elements.stream().map(e -> e.getGroup(simulator)).distinct().collect(Collectors.toList());
if (parents.size() == 1) {
// Open multi element present in Simulator in existing group
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
new SimulatorGroupGui(player, simulator, parents.get(0), simulatorGui).open();
} else {
// Open multi element present in Simulator in implicit group
SimulatorGroup group2 = new SimulatorGroup();
group2.setMaterial(null);
group2.getElements().addAll(elements);
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
new SimulatorGroupGui(player, simulator, group2, simulatorGui).open();
}
break;
}
return;
}
// 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) {
vector.subtract(new Vector(0.5, 0, 0.5));
}
SimulatorElement<?> element = type.elementFunction.apply(vector);
SimulatorGroup group = new SimulatorGroup().add(element);
simulator.getGroups().add(group);
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
element.open(player, simulator, group, simulatorGui);
SimulatorWatcher.update(simulator);
calcCursor(player);
}
}
@@ -0,0 +1,168 @@
/*
* 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.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase;
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
import de.steamwar.bausystem.features.simulator.display.SimulatorCursor;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor;
import de.steamwar.bausystem.features.simulator.gui.SimulatorGroupGui;
import de.steamwar.bausystem.features.simulator.gui.SimulatorGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
import de.steamwar.bausystem.utils.ItemUtils;
import de.steamwar.bausystem.utils.RayTraceUtils;
import de.steamwar.bausystem.utils.cursor.Cursor;
import de.steamwar.entity.REntity;
import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RFallingBlockEntity;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.MinVersion;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.var;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
@Linked
@MinVersion(19)
public class SimulatorCursorManager implements Listener {
enum SimulatorCursorMode {
TNT, REDSTONE_BLOCK, OBSERVER
}
private final Map<Player, Map<Simulator, Cursor>> activeCursorsByPlayerBySimulator = new HashMap<>();
public void onPlayerItemEquip(PlayerItemHeldEvent event) {
Player player = event.getPlayer();
// Show simulator cursor for newly held simulator item and trigger simulator display
Simulator heldSimulator = SimulatorStorage.getSimulator(player.getInventory().getItem(event.getNewSlot()));
if (heldSimulator != null) {
Map<Simulator, Cursor> cursorsBySimulator = activeCursorsByPlayerBySimulator.getOrDefault(player, new HashMap<>());
Cursor cursor = cursorsBySimulator.get(heldSimulator);
if (cursor == null) {
REntityServer simulatorServer = SimulatorRenderer.show(heldSimulator, player);
cursor = new Cursor(simulatorServer, player, Material.GLASS, Material.TNT,
Arrays.asList(Cursor.CursorMode.BLOCK_ALIGNED, Cursor.CursorMode.FREE), (clickedLocation, clickedOnEntity, clickAction) -> {
});
cursorsBySimulator.put(heldSimulator, cursor);
activeCursorsByPlayerBySimulator.put(player, cursorsBySimulator);
cursor.show();
}
cursor.show();
}
// Hide simulator cursor for previously held simulator item
Simulator previousSimulator = SimulatorStorage.getSimulator(player.getInventory().getItem(event.getPreviousSlot()));
if (previousSimulator != null) {
Map<Simulator, Cursor> cursorsBySimulator = activeCursorsByPlayerBySimulator.getOrDefault(player, new HashMap<>());
Cursor cursor = cursorsBySimulator.get(previousSimulator);
if (cursor != null) {
cursor.hide();
}
}
}
private synchronized void showCursor(Player player, RayTraceUtils.RRayTraceResult rayTraceResult, boolean hasSimulatorSelected) {
REntityServer entityServer = cursors.computeIfAbsent(player, __ -> {
REntityServer rEntityServer = new REntityServer();
rEntityServer.addPlayer(player);
return rEntityServer;
});
CursorType type = cursorType.getOrDefault(player, CursorType.TNT);
REntity hitEntity = rayTraceResult.getHitEntity();
Location location = hitEntity != null ? new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ()).toLocation(WORLD)
: type.position.apply(player, rayTraceResult).toLocation(WORLD);
Material material = hitEntity != null ? Material.GLASS : type.getMaterial();
List<RFallingBlockEntity> entities = entityServer.getEntitiesByType(RFallingBlockEntity.class);
entities.removeIf(rFallingBlockEntity -> {
if (rFallingBlockEntity.getMaterial() != material) {
rFallingBlockEntity.die();
return true;
}
rFallingBlockEntity.move(location);
return false;
});
if (entities.isEmpty()) {
RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(entityServer, location, material);
rFallingBlockEntity.setNoGravity(true);
if (material == Material.GLASS) {
rFallingBlockEntity.setGlowing(true);
}
}
if (hasSimulatorSelected) {
if (hitEntity != null) {
SWUtils.sendToActionbar(player, "§eEdit Position");
} else {
SWUtils.sendToActionbar(player, "§eAdd new " + type.name);
}
} else {
SWUtils.sendToActionbar(player, "§eCreate new Simulator");
}
}
@Getter
@AllArgsConstructor
public enum CursorType {
}
private void createElement(Player player, RayTraceUtils.RRayTraceResult rayTraceResult, Simulator simulator) {
}
}
@@ -1,20 +1,18 @@
/* /*
* 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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator; package de.steamwar.bausystem.features.simulator;
@@ -23,6 +21,7 @@ import com.google.common.io.Files;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.display.SimulatorCursor;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui;
import de.steamwar.bausystem.features.simulator.storage.SimFormatSimulatorLoader; import de.steamwar.bausystem.features.simulator.storage.SimFormatSimulatorLoader;
import de.steamwar.bausystem.features.simulator.storage.SimulatorFormatSimulatorLoader; import de.steamwar.bausystem.features.simulator.storage.SimulatorFormatSimulatorLoader;
@@ -56,12 +55,13 @@ public class SimulatorStorage implements Enable {
public static Simulator getSimulator(Player player) { public static Simulator getSimulator(Player player) {
Simulator simulator = getSimulator(player.getInventory().getItemInMainHand()); Simulator simulator = getSimulator(player.getInventory().getItemInMainHand());
if (simulator != null) return simulator; if (simulator != null)
return simulator;
return getSimulator(player.getInventory().getItemInOffHand()); return getSimulator(player.getInventory().getItemInOffHand());
} }
public static Simulator getSimulator(ItemStack itemStack) { public static Simulator getSimulator(ItemStack itemStack) {
if (!SimulatorCursor.isSimulatorItem(itemStack)) { if (!SimulatorUtils.isSimulatorItem(itemStack)) {
return null; return null;
} }
String selection = ItemUtils.getTag(itemStack, simulatorSelection); String selection = ItemUtils.getTag(itemStack, simulatorSelection);
@@ -86,11 +86,11 @@ public class SimulatorStorage implements Enable {
YAPIONFormatSimulatorLoader yapionFormatSimulatorLoader = new YAPIONFormatSimulatorLoader(); YAPIONFormatSimulatorLoader yapionFormatSimulatorLoader = new YAPIONFormatSimulatorLoader();
File[] files = simulatorsDir.listFiles(); File[] files = simulatorsDir.listFiles();
if (files == null) return; if (files == null)
return;
for (File file : files) { for (File file : files) {
try { try {
List<Simulator> simulators = simFormatSimulatorLoader.load(file) List<Simulator> simulators = simFormatSimulatorLoader.load(file).orElse(null);
.orElse(null);
if (simulators != null) { if (simulators != null) {
simulators.forEach(simulator -> { simulators.forEach(simulator -> {
simulatorMap.put(simulator.getName(), simulator); simulatorMap.put(simulator.getName(), simulator);
@@ -102,8 +102,7 @@ public class SimulatorStorage implements Enable {
} }
try { try {
List<Simulator> simulators = simulatorFormatSimulatorLoader.load(file) List<Simulator> simulators = simulatorFormatSimulatorLoader.load(file).orElse(null);
.orElse(null);
if (simulators != null) { if (simulators != null) {
simulators.forEach(simulator -> { simulators.forEach(simulator -> {
simulatorMap.put(simulator.getName(), simulator); simulatorMap.put(simulator.getName(), simulator);
@@ -116,8 +115,7 @@ public class SimulatorStorage implements Enable {
} }
try { try {
List<Simulator> simulators = yapionFormatSimulatorLoader.load(file) List<Simulator> simulators = yapionFormatSimulatorLoader.load(file).orElse(null);
.orElse(null);
if (simulators != null) { if (simulators != null) {
simulators.forEach(simulator -> { simulators.forEach(simulator -> {
simulatorMap.put(simulator.getName(), simulator); simulatorMap.put(simulator.getName(), simulator);
@@ -131,7 +129,8 @@ public class SimulatorStorage implements Enable {
} }
public static void openSimulatorSelector(Player player) { public static void openSimulatorSelector(Player player) {
SimulatorPageGui<Simulator> simulatorPageGui = new SimulatorPageGui<Simulator>(player, null, 6 * 9, simulatorMap.values().stream().sorted(Comparator.comparing(Simulator::getName)).collect(Collectors.toList())) { SimulatorPageGui<Simulator> simulatorPageGui = new SimulatorPageGui<Simulator>(player, null, 6 * 9,
simulatorMap.values().stream().sorted(Comparator.comparing(Simulator::getName)).collect(Collectors.toList())) {
@Override @Override
public String baseTitle() { public String baseTitle() {
return "Simulators"; return "Simulators";
@@ -171,7 +170,11 @@ public class SimulatorStorage implements Enable {
} }
public static ItemStack getWand(Player p) { public static ItemStack getWand(Player p) {
ItemStack itemStack = new SWItem(Material.BLAZE_ROD, BauSystem.MESSAGE.parse("SIMULATOR_WAND_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_1", p), BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_2", p), BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_3", p), BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_4", p), BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_5", p)), false, null).getItemStack(); ItemStack itemStack = new SWItem(Material.BLAZE_ROD, BauSystem.MESSAGE.parse("SIMULATOR_WAND_NAME", p),
Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_1", p), BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_2", p),
BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_3", p), BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_4", p),
BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_5", p)),
false, null).getItemStack();
ItemMeta itemMeta = itemStack.getItemMeta(); ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setCustomModelData(1); itemMeta.setCustomModelData(1);
itemStack.setItemMeta(itemMeta); itemStack.setItemMeta(itemMeta);
@@ -183,9 +186,9 @@ public class SimulatorStorage implements Enable {
ItemStack mainHand = player.getInventory().getItemInMainHand(); ItemStack mainHand = player.getInventory().getItemInMainHand();
ItemStack offHand = player.getInventory().getItemInOffHand(); ItemStack offHand = player.getInventory().getItemInOffHand();
ItemStack itemStack; ItemStack itemStack;
if (SimulatorCursor.isSimulatorItem(mainHand)) { if (SimulatorUtils.isSimulatorItem(mainHand)) {
itemStack = mainHand; itemStack = mainHand;
} else if (SimulatorCursor.isSimulatorItem(offHand)) { } else if (SimulatorUtils.isSimulatorItem(offHand)) {
itemStack = offHand; itemStack = offHand;
} else { } else {
itemStack = null; itemStack = null;
@@ -0,0 +1,12 @@
package de.steamwar.bausystem.features.simulator;
import org.bukkit.inventory.ItemStack;
import de.steamwar.bausystem.utils.ItemUtils;
import lombok.experimental.UtilityClass;
@UtilityClass
public class SimulatorUtils {
public static boolean isSimulatorItem(ItemStack itemStack) {
return ItemUtils.isItem(itemStack, "simulator");
}
}
@@ -1,129 +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.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator.storage.SimulatorSaver;
import de.steamwar.bausystem.shared.Pair;
import de.steamwar.entity.REntity;
import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RFallingBlockEntity;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.MinVersion;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.util.Vector;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
@UtilityClass
public class SimulatorWatcher {
private final World WORLD = Bukkit.getWorlds().get(0);
private Map<Simulator, REntityServer> entityServers = new HashMap<>();
private Map<Player, Pair<Simulator, Runnable>> watchers = new HashMap<>();
public void watch(Player player, Simulator simulator, Runnable watcher) {
if (simulator == null || watcher == null) {
watchers.remove(player);
} else {
watchers.put(player, new Pair<>(simulator, watcher));
}
}
public synchronized void update(Simulator simulator) {
REntityServer rEntityServer = entityServers.get(simulator);
if (rEntityServer != null) {
rEntityServer.getEntities().forEach(REntity::die);
createSim(rEntityServer, simulator);
}
new ArrayList<>(watchers.values()).forEach(simulatorRunnablePair -> {
if (simulatorRunnablePair.getKey() == simulator) {
simulatorRunnablePair.getValue().run();
}
});
SimulatorSaver.saveSimulator(SimulatorStorage.simulatorsDir, simulator);
}
@Linked
@MinVersion(19)
public static class QuitListener implements Listener {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
watchers.remove(event.getPlayer());
show(null, event.getPlayer());
}
}
private REntityServer createSim(REntityServer server, Simulator simulator) {
if (simulator == null) {
return null;
}
Map<Vector, Set<Class<?>>> positionCache = new HashMap<>();
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();
SimulatorElement<?> element = pair.getValue();
boolean wasNotPresent = positionCache.computeIfAbsent(element.getPosition(), __ -> new HashSet<>())
.add(element.getClass());
if (!wasNotPresent) return;
Material material = group.isDisabled() || element.isDisabled() ? element.getWorldDisabledMaterial() : element.getWorldMaterial();
Location location = element.getWorldPos().toLocation(WORLD);
RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(server, location, material);
rFallingBlockEntity.setNoGravity(true);
});
return server;
}
public synchronized boolean show(Simulator sim, Player player) {
AtomicBoolean removed = new AtomicBoolean();
entityServers.forEach((simulator, rEntityServer) -> {
if (rEntityServer == null) return;
if (rEntityServer.getPlayers().contains(player) && sim != simulator) {
rEntityServer.removePlayer(player);
removed.set(true);
}
});
if (sim == null) return removed.get();
entityServers.computeIfAbsent(sim, __ -> createSim(new REntityServer(), sim)).addPlayer(player);
return removed.get();
}
synchronized List<REntity> getEntitiesOfSimulator(Simulator simulator) {
REntityServer entityServer = entityServers.get(simulator);
if (entityServer == null) {
return Collections.emptyList();
}
return entityServer.getEntities();
}
}
@@ -0,0 +1,83 @@
package de.steamwar.bausystem.features.simulator.display;
import java.util.List;
import java.util.Optional;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
import de.steamwar.bausystem.utils.cursor.Cursor;
import de.steamwar.entity.REntityServer;
import de.steamwar.inventory.SWAnvilInv;
public class EmptySimulatorCursor extends Cursor implements Listener {
private final Player owner;
private SimulatorCursorMode cursorMode;
public EmptySimulatorCursor(Player owner) {
super(new REntityServer(), owner, Material.GLASS, Material.TNT, List.of(Cursor.CursorMode.FREE, Cursor.CursorMode.BLOCK_ALIGNED));
this.cursorMode = SimulatorCursorMode.TNT;
this.owner = owner;
}
public void swapCursorMode() {
cursorMode = cursorMode.switchType();
setCursorMaterial(cursorMode.getMaterial());
setAllowedCursorModes(cursorMode.getAllowedCursorModes());
}
public void hide() {
super.hide();
super.getTargetServer().removePlayer(owner);
}
public void show() {
super.show();
super.getTargetServer().addPlayer(owner);
}
@EventHandler
public void onPlayerShift(PlayerToggleSneakEvent event) {
if (event.getPlayer() != owner) {
return;
}
swapCursorMode();
}
@Override
public void onClick(Optional<Location> clickedLocation, boolean clickedOnEntity, Action clickAction) {
if (clickAction == Action.LEFT_CLICK_AIR) {
SimulatorStorage.openSimulatorSelector(owner);
} else if (clickAction == Action.LEFT_CLICK_BLOCK) {
SWAnvilInv anvilInv = new SWAnvilInv(owner, "Name");
anvilInv.setCallback(name -> {
Simulator sim = SimulatorStorage.getSimulator(name);
if (sim != null) {
BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", owner);
return;
}
if (!name.matches("[a-zA-Z_0-9-]+")) {
BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", owner);
return;
}
sim = new Simulator(name);
SimulatorStorage.addSimulator(name, sim);
SimulatorElement<?> element = cursorMode.getElementFunction().apply(clickedLocation.get().toVector());
SimulatorGroup group = new SimulatorGroup();
group.add(element);
sim.add(group);
SimulatorStorage.setSimulator(owner, sim);
});
anvilInv.open();
}
}
}
@@ -0,0 +1,104 @@
package de.steamwar.bausystem.features.simulator.display;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.util.Vector;
import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor;
import de.steamwar.bausystem.features.simulator.gui.SimulatorGroupGui;
import de.steamwar.bausystem.features.simulator.gui.SimulatorGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.utils.cursor.Cursor;
import de.steamwar.entity.REntityServer;
public class SimulatorCursor extends Cursor {
private final Simulator simulator;
private final Player owner;
private SimulatorCursorMode cursorMode;
public SimulatorCursor(Simulator simulator, Player owner, SimulatorCursorMode cursorMode) {
super(SimulatorRenderer.renderSimulator(simulator), owner, Material.LIME_STAINED_GLASS_PANE, Material.RED_STAINED_GLASS_PANE,
cursorMode.getAllowedCursorModes());
this.simulator = simulator;
this.owner = owner;
}
public void swapCursorMode() {
SimulatorCursorMode newMode = cursorMode.switchType();
setCursorMaterial(newMode.getMaterial());
setAllowedCursorModes(newMode.getAllowedCursorModes());
}
public void hide() {
super.hide();
super.getTargetServer().removePlayer(owner);
}
public void show() {
super.show();
super.getTargetServer().addPlayer(owner);
}
@EventHandler
public void onPlayerShift(PlayerToggleSneakEvent event) {
if (event.getPlayer() != owner) {
return;
}
swapCursorMode();
}
@Override
public void onClick(Optional<Location> clickedLocation, boolean clickedOnEntity, Action clickAction) {
if (clickAction == Action.RIGHT_CLICK_AIR || clickAction == Action.RIGHT_CLICK_BLOCK) {
SimulatorExecutor.run(owner, simulator, null);
} else if (!clickedOnEntity || clickedLocation.isEmpty()) {
new SimulatorGui(owner, simulator);
} else {
Vector vector = clickedLocation.get().toVector();
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);
}).collect(Collectors.toList());
switch (elements.size()) {
case 0:
return;
case 1:
// Open single element present in Simulator
SimulatorElement<?> element = elements.get(0);
SimulatorGroup group1 = element.getGroup(simulator);
SimulatorBaseGui back = new SimulatorGui(owner, simulator);
if (group1.getElements().size() > 1) {
back = new SimulatorGroupGui(owner, simulator, group1, back);
}
element.open(owner, simulator, group1, back);
break;
default:
List<SimulatorGroup> parents = elements.stream().map(e -> e.getGroup(simulator)).distinct().collect(Collectors.toList());
if (parents.size() == 1) {
// Open multi element present in Simulator in existing group
SimulatorGui simulatorGui = new SimulatorGui(owner, simulator);
new SimulatorGroupGui(owner, simulator, parents.get(0), simulatorGui).open();
} else {
// Open multi element present in Simulator in implicit group
SimulatorGroup group2 = new SimulatorGroup();
group2.setMaterial(null);
group2.getElements().addAll(elements);
SimulatorGui simulatorGui = new SimulatorGui(owner, simulator);
new SimulatorGroupGui(owner, simulator, group2, simulatorGui).open();
}
break;
}
}
}
}
@@ -0,0 +1,39 @@
package de.steamwar.bausystem.features.simulator.display;
import java.util.List;
import java.util.function.Function;
import org.bukkit.Material;
import org.bukkit.util.Vector;
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase;
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
import de.steamwar.bausystem.utils.cursor.Cursor.CursorMode;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public enum SimulatorCursorMode {
TNT(Material.TNT, "TNT", vector -> new TNTElement(vector).add(new TNTPhase()), List.of(CursorMode.FREE, CursorMode.BLOCK_ALIGNED)), REDSTONE_BLOCK(
Material.REDSTONE_BLOCK, "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase()), List.of(CursorMode.BLOCK_ALIGNED)), OBSERVER(
Material.OBSERVER, "Observer", vector -> new ObserverElement(vector).add(new ObserverPhase()), List.of(CursorMode.BLOCK_ALIGNED));
private Material material;
private String name;
private Function<Vector, SimulatorElement<?>> elementFunction;
private List<CursorMode> allowedCursorModes;
public SimulatorCursorMode switchType() {
if (this == TNT) {
return REDSTONE_BLOCK;
}
if (this == REDSTONE_BLOCK) {
return OBSERVER;
}
return TNT;
}
}
@@ -0,0 +1,78 @@
/*
* 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.display;
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator.storage.SimulatorSaver;
import de.steamwar.bausystem.shared.Pair;
import de.steamwar.entity.REntity;
import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RFallingBlockEntity;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.event.Listener;
import org.bukkit.util.Vector;
import java.util.*;
import java.util.stream.Collectors;
@UtilityClass
public class SimulatorRenderer implements Listener {
private final World WORLD = Bukkit.getWorlds().get(0);
private Map<Simulator, REntityServer> entityServers = new HashMap<>();
public synchronized void update(Simulator simulator) {
renderSimulator(simulator);
SimulatorSaver.saveSimulator(SimulatorStorage.simulatorsDir, simulator);
}
public REntityServer renderSimulator(Simulator simulator) {
if (simulator == null) {
return null;
}
REntityServer server = entityServers.computeIfAbsent(simulator, __ -> new REntityServer());
server.getEntities().forEach(REntity::die);
Map<Vector, Set<Class<?>>> positionCache = new HashMap<>();
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();
SimulatorElement<?> element = pair.getValue();
boolean wasNotPresent = positionCache.computeIfAbsent(element.getPosition(), __ -> new HashSet<>()).add(element.getClass());
if (!wasNotPresent)
return;
Material material = group.isDisabled() || element.isDisabled() ? element.getWorldDisabledMaterial() : element.getWorldMaterial();
Location location = element.getWorldPos().toLocation(WORLD);
RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(server, location, material);
rFallingBlockEntity.setNoGravity(true);
});
return server;
}
}
@@ -1,26 +1,24 @@
/* /*
* This file is a part of the SteamWar software. * This file is a part of the SteamWar software.
* *
* Copyright (C) 2020 SteamWar.de-Serverteam * Copyright (C) 2020 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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.execute; package de.steamwar.bausystem.features.simulator.execute;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher; import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar;
import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.bausystem.utils.bossbar.BossBarService;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -72,7 +70,7 @@ public abstract class StabStep {
protected final void stop() { protected final void stop() {
data.simulator.setStabGenerator(null); data.simulator.setStabGenerator(null);
SimulatorWatcher.update(data.simulator); SimulatorRenderer.update(data.simulator);
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
BauSystemBossbar bossbar = BossBarService.instance.get(player, data.region, "simulator_stab_generator"); BauSystemBossbar bossbar = BossBarService.instance.get(player, data.region, "simulator_stab_generator");
@@ -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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui; package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorElement; import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui;
import de.steamwar.inventory.InvCallback; import de.steamwar.inventory.InvCallback;
@@ -39,7 +37,8 @@ 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.getGroups().stream().filter(e -> e != parent).filter(e -> subject.canBeInGroup(e)).collect(Collectors.toList())); super(player, simulator, 6 * 9,
simulator.getGroups().stream().filter(e -> e != parent).filter(e -> subject.canBeInGroup(e)).collect(Collectors.toList()));
this.subject = subject; this.subject = subject;
this.parent = parent; this.parent = parent;
this.back = back; this.back = back;
@@ -56,7 +55,7 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui<SimulatorGroup> {
simulator.getGroups().add(newParent); simulator.getGroups().add(newParent);
parent.getElements().remove(subject); parent.getElements().remove(subject);
back.open(); back.open();
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
if (parent.getElements().size() == 1) { if (parent.getElements().size() == 1) {
parent.setDisabled(false); parent.setDisabled(false);
parent.setMaterial(Material.BARREL); parent.setMaterial(Material.BARREL);
@@ -83,7 +82,7 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui<SimulatorGroup> {
parent.setMaterial(Material.BARREL); parent.setMaterial(Material.BARREL);
} }
back.open(); back.open();
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}; };
return simulatorGroup.toItem(player, invCallback, invCallback); return simulatorGroup.toItem(player, invCallback, invCallback);
} }
@@ -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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui; package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorElement; import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui;
import de.steamwar.data.CMDs; import de.steamwar.data.CMDs;
@@ -60,7 +58,7 @@ public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
} }
if (simulatorGroup.getElements().removeIf(element -> element.getPhases().isEmpty())) { if (simulatorGroup.getElements().removeIf(element -> element.getPhases().isEmpty())) {
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
} }
if (simulatorGroup.getElements().size() < 2) { if (simulatorGroup.getElements().size() < 2) {
back.open(); back.open();
@@ -75,11 +73,12 @@ public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
simulatorGroup.getElements().clear(); simulatorGroup.getElements().clear();
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DELETE)); }).setCustomModelData(CMDs.Simulator.DELETE));
inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { inventory.setItem(4, simulatorGroup.toItem(player, clickType -> {
if (simulatorGroup.getMaterial() == null) return; if (simulatorGroup.getMaterial() == null)
return;
new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open(); new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open();
}, clickType -> { }, clickType -> {
})); }));
@@ -87,17 +86,19 @@ public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> { inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open(); new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open();
}).setCustomModelData(CMDs.Simulator.SETTINGS)); }).setCustomModelData(CMDs.Simulator.SETTINGS));
boolean disabled = simulatorGroup.getMaterial() == null ? simulatorGroup.getElements().stream().allMatch(SimulatorElement::isDisabled) : simulatorGroup.isDisabled(); boolean disabled = simulatorGroup.getMaterial() == null ? simulatorGroup.getElements().stream().allMatch(SimulatorElement::isDisabled)
inventory.setItem(50, new SWItem(disabled ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { : simulatorGroup.isDisabled();
if (simulatorGroup.getMaterial() == null) { inventory.setItem(50,
simulatorGroup.getElements().forEach(simulatorElement -> { new SWItem(disabled ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
simulatorElement.setDisabled(!disabled); if (simulatorGroup.getMaterial() == null) {
}); simulatorGroup.getElements().forEach(simulatorElement -> {
} else { simulatorElement.setDisabled(!disabled);
simulatorGroup.setDisabled(!disabled); });
} } else {
SimulatorWatcher.update(simulator); simulatorGroup.setDisabled(!disabled);
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED)); }
SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
} }
@Override @Override
@@ -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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui; package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.data.CMDs; import de.steamwar.data.CMDs;
@@ -62,7 +60,8 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
// Material Chooser // Material Chooser
inventory.setItem(4, simulatorGroup.toItem(player, clickType -> { inventory.setItem(4, simulatorGroup.toItem(player, clickType -> {
if (simulatorGroup.getMaterial() == null) return; if (simulatorGroup.getMaterial() == null)
return;
new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open(); new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open();
}, clickType -> { }, clickType -> {
})); }));
@@ -71,13 +70,14 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
int baseTicks = simulatorGroup.getBaseTick(); int baseTicks = simulatorGroup.getBaseTick();
inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? 5 : 1);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {
new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> {
if (integer < 0) return false; if (integer < 0)
return false;
simulatorGroup.changeBaseTicks(integer - baseTicks); simulatorGroup.changeBaseTicks(integer - baseTicks);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(Material.REPEATER).open(); }, this).setItem(Material.REPEATER).open();
}); });
@@ -89,7 +89,7 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
} else { } else {
simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? -5 : -1);
} }
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
boolean allTNT = simulatorGroup.getElements().stream().allMatch(TNTElement.class::isInstance); boolean allTNT = simulatorGroup.getElements().stream().allMatch(TNTElement.class::isInstance);
@@ -97,129 +97,119 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
if (allTNT) { if (allTNT) {
// Subpixel Alignment // Subpixel Alignment
inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> { inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> {
simulatorGroup.getElements().stream() simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tntElement -> {
.map(TNTElement.class::cast) tntElement.alignX(0);
.forEach(tntElement -> { tntElement.alignZ(0);
tntElement.alignX(0); });
tntElement.alignZ(0); SimulatorRenderer.update(simulator);
});
SimulatorWatcher.update(simulator);
})); }));
// Z // Z
SWItem negativZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> { SWItem negativZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> {
simulatorGroup.getElements().stream() simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tntElement -> {
.map(TNTElement.class::cast) if (tntElement.getAlignment().getZ() != -1)
.forEach(tntElement -> { tntElement.alignZ(-1);
if (tntElement.getAlignment().getZ() != -1) tntElement.alignZ(-1); });
}); SimulatorRenderer.update(simulator);
SimulatorWatcher.update(simulator);
}); });
negativZItem.setEnchanted(simulatorGroup.getElements().stream() negativZItem.setEnchanted(
.map(TNTElement.class::cast) simulatorGroup.getElements().stream().map(TNTElement.class::cast).allMatch(tntElement -> tntElement.getAlignment().getZ() == -1));
.allMatch(tntElement -> tntElement.getAlignment().getZ() == -1));
inventory.setItem(20, negativZItem); inventory.setItem(20, negativZItem);
SWItem positivZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> { SWItem positivZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> {
simulatorGroup.getElements().stream() simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tntElement -> {
.map(TNTElement.class::cast) if (tntElement.getAlignment().getZ() != 1)
.forEach(tntElement -> { tntElement.alignZ(1);
if (tntElement.getAlignment().getZ() != 1) tntElement.alignZ(1); });
}); SimulatorRenderer.update(simulator);
SimulatorWatcher.update(simulator);
}); });
positivZItem.setEnchanted(simulatorGroup.getElements().stream() positivZItem.setEnchanted(
.map(TNTElement.class::cast) simulatorGroup.getElements().stream().map(TNTElement.class::cast).allMatch(tntElement -> tntElement.getAlignment().getZ() == 1));
.allMatch(tntElement -> tntElement.getAlignment().getZ() == 1));
inventory.setItem(22, positivZItem); inventory.setItem(22, positivZItem);
// X // X
SWItem negativXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> { SWItem negativXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> {
simulatorGroup.getElements().stream() simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tntElement -> {
.map(TNTElement.class::cast) if (tntElement.getAlignment().getX() != -1)
.forEach(tntElement -> { tntElement.alignX(-1);
if (tntElement.getAlignment().getX() != -1) tntElement.alignX(-1); });
});
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}); });
negativXItem.setEnchanted(simulatorGroup.getElements().stream() negativXItem.setEnchanted(
.map(TNTElement.class::cast) simulatorGroup.getElements().stream().map(TNTElement.class::cast).allMatch(tntElement -> tntElement.getAlignment().getX() == -1));
.allMatch(tntElement -> tntElement.getAlignment().getX() == -1));
inventory.setItem(12, negativXItem); inventory.setItem(12, negativXItem);
SWItem positivXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> { SWItem positivXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> {
simulatorGroup.getElements().stream() simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tntElement -> {
.map(TNTElement.class::cast) if (tntElement.getAlignment().getX() != 1)
.forEach(tntElement -> { tntElement.alignX(1);
if (tntElement.getAlignment().getX() != 1) tntElement.alignX(1); });
}); SimulatorRenderer.update(simulator);
SimulatorWatcher.update(simulator);
}); });
positivXItem.setEnchanted(simulatorGroup.getElements().stream() positivXItem.setEnchanted(
.map(TNTElement.class::cast) simulatorGroup.getElements().stream().map(TNTElement.class::cast).allMatch(tntElement -> tntElement.getAlignment().getX() == -1));
.allMatch(tntElement -> tntElement.getAlignment().getX() == -1));
inventory.setItem(30, positivXItem); inventory.setItem(30, positivXItem);
} }
//Pos X // Pos X
inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> {
simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0, 0); simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> { inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> {
new SimulatorAnvilGui<>(player, "Relative X", "", Double::parseDouble, number -> { new SimulatorAnvilGui<>(player, "Relative X", "", Double::parseDouble, number -> {
if(!allTNT){ if (!allTNT) {
number = (double) Math.round(number); number = (double) Math.round(number);
} }
simulatorGroup.move(number, 0, 0); simulatorGroup.move(number, 0, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(Material.PAPER).open(); }, this).setItem(Material.PAPER).open();
})); }));
inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> {
simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0, 0); simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Pos Y // Pos Y
inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> {
simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0); simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> { inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> {
new SimulatorAnvilGui<>(player, "Relative Y", "", Double::parseDouble, number -> { new SimulatorAnvilGui<>(player, "Relative Y", "", Double::parseDouble, number -> {
if(!allTNT){ if (!allTNT) {
number = (double) Math.round(number); number = (double) Math.round(number);
} }
simulatorGroup.move(0, number, 0); simulatorGroup.move(0, number, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(Material.PAPER).open(); }, this).setItem(Material.PAPER).open();
})); }));
inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> {
simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0); simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
//Pos Z // Pos Z
inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> {
simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1); simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> { inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> {
new SimulatorAnvilGui<>(player, "Relative Z", "", Double::parseDouble, number -> { new SimulatorAnvilGui<>(player, "Relative Z", "", Double::parseDouble, number -> {
if(!allTNT){ if (!allTNT) {
number = (double) Math.round(number); number = (double) Math.round(number);
} }
simulatorGroup.move(0, 0, number); simulatorGroup.move(0, 0, number);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(Material.PAPER).open(); }, this).setItem(Material.PAPER).open();
})); }));
inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> {
simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1); simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
} }
} }
@@ -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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui; package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorElement; import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui;
import de.steamwar.data.CMDs; import de.steamwar.data.CMDs;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
@@ -42,8 +40,9 @@ public class SimulatorGui extends SimulatorPageGui<SimulatorGroup> {
@Override @Override
public void headerAndFooter() { public void headerAndFooter() {
if (simulator.getGroups().removeIf(element -> element.getElements().isEmpty() || element.getElements().stream().allMatch(simulatorElement -> simulatorElement.getPhases().isEmpty()))) { if (simulator.getGroups().removeIf(element -> element.getElements().isEmpty()
SimulatorWatcher.update(simulator); || element.getElements().stream().allMatch(simulatorElement -> simulatorElement.getPhases().isEmpty()))) {
SimulatorRenderer.update(simulator);
} }
inventory.setItem(4, simulator.toItem(player, clickType -> { inventory.setItem(4, simulator.toItem(player, clickType -> {
@@ -1,26 +1,24 @@
/* /*
* 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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui; package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui;
import de.steamwar.data.CMDs; import de.steamwar.data.CMDs;
@@ -36,11 +34,8 @@ import java.util.stream.Collectors;
public class SimulatorMaterialGui extends SimulatorPageGui<Material> { public class SimulatorMaterialGui extends SimulatorPageGui<Material> {
private static final List<Material> MATERIALS = Arrays.stream(Material.values()) private static final List<Material> MATERIALS = Arrays.stream(Material.values()).filter(material -> !material.isAir())
.filter(material -> !material.isAir()) .filter(material -> !material.isLegacy()).filter(Material::isItem).collect(Collectors.toList());
.filter(material -> !material.isLegacy())
.filter(Material::isItem)
.collect(Collectors.toList());
private final Supplier<Material> currentMaterial; private final Supplier<Material> currentMaterial;
private Material material; private Material material;
@@ -60,7 +55,7 @@ public class SimulatorMaterialGui extends SimulatorPageGui<Material> {
return true; return true;
} }
change.accept(player.getItemOnCursor().getType()); change.accept(player.getItemOnCursor().getType());
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return false; return false;
} }
@@ -81,9 +76,10 @@ public class SimulatorMaterialGui extends SimulatorPageGui<Material> {
@Override @Override
public SWItem convert(Material material) { public SWItem convert(Material material) {
return new SWItem(material, "§eNew Material", Arrays.asList(material == this.material ? "§eSelected" : "§eClick to select"), material == this.material, clickType -> { return new SWItem(material, "§eNew Material", Arrays.asList(material == this.material ? "§eSelected" : "§eClick to select"), material == this.material,
change.accept(material); clickType -> {
SimulatorWatcher.update(simulator); change.accept(material);
}); SimulatorRenderer.update(simulator);
});
} }
} }
@@ -1,29 +1,27 @@
/* /*
* 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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui; package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement; import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase; import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui;
import de.steamwar.data.CMDs; import de.steamwar.data.CMDs;
@@ -60,7 +58,7 @@ public class SimulatorObserverGui extends SimulatorScrollGui<ObserverPhase> {
public void headerAndFooter() { public void headerAndFooter() {
if (observer.getPhases().isEmpty()) { if (observer.getPhases().isEmpty()) {
back.open(); back.open();
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return; return;
} }
@@ -87,7 +85,7 @@ public class SimulatorObserverGui extends SimulatorScrollGui<ObserverPhase> {
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
observer.getPhases().clear(); observer.getPhases().clear();
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DELETE)); }).setCustomModelData(CMDs.Simulator.DELETE));
// Material Chooser // Material Chooser
@@ -101,10 +99,11 @@ public class SimulatorObserverGui extends SimulatorScrollGui<ObserverPhase> {
}).setCustomModelData(CMDs.Simulator.SETTINGS)); }).setCustomModelData(CMDs.Simulator.SETTINGS));
// Enable/Disable // Enable/Disable
inventory.setItem(48, new SWItem(observer.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, observer.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { inventory.setItem(48,
observer.setDisabled(!observer.isDisabled()); new SWItem(observer.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, observer.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
SimulatorWatcher.update(simulator); observer.setDisabled(!observer.isDisabled());
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED)); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
// Group chooser // Group chooser
inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> {
@@ -139,7 +138,7 @@ public class SimulatorObserverGui extends SimulatorScrollGui<ObserverPhase> {
SWItem observer = new SWItem(Material.OBSERVER, "§eObserver", lore, false, clickType -> { SWItem observer = new SWItem(Material.OBSERVER, "§eObserver", lore, false, clickType -> {
if (clickType == ClickType.MIDDLE) { if (clickType == ClickType.MIDDLE) {
this.observer.getPhases().remove(observerPhase); this.observer.getPhases().remove(observerPhase);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
} else { } else {
new SimulatorObserverPhaseSettingsGui(player, simulator, this.observer, observerPhase, this).open(); new SimulatorObserverPhaseSettingsGui(player, simulator, this.observer, observerPhase, this).open();
} }
@@ -148,42 +147,35 @@ public class SimulatorObserverGui extends SimulatorScrollGui<ObserverPhase> {
Supplier<Integer> getter = observerPhase::getTickOffset; Supplier<Integer> getter = observerPhase::getTickOffset;
Consumer<Integer> setter = observerPhase::setTickOffset; Consumer<Integer> setter = observerPhase::setTickOffset;
return new SWItem[] { return new SWItem[] {new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1)));
setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1))); SimulatorRenderer.update(simulator);
SimulatorWatcher.update(simulator); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), observer,
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED),
observer,
new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> {
setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1))); setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1)));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED), }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED), new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> {
new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> {
new SimulatorObserverPhaseSettingsGui(player, simulator, this.observer, observerPhase, this).open(); new SimulatorObserverPhaseSettingsGui(player, simulator, this.observer, observerPhase, this).open();
}).setCustomModelData(CMDs.Simulator.EDIT_ACTIVATION), }).setCustomModelData(CMDs.Simulator.EDIT_ACTIVATION),};
};
} }
@Override @Override
public SWItem[] lastColumn() { public SWItem[] lastColumn() {
return new SWItem[]{ return new SWItem[] {new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { addNewPhase(clickType.isShiftClick());
addNewPhase(clickType.isShiftClick()); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), new SWItem(Material.QUARTZ, "§eObserver§8:§a New Phase", clickType -> {
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), addNewPhase(false);
new SWItem(Material.QUARTZ, "§eObserver§8:§a New Phase", clickType -> { }).setCustomModelData(CMDs.Simulator.NEW_PHASE), new SWItem(SWItem.getDye(8), "§7", clickType -> {
addNewPhase(false); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED),};
}).setCustomModelData(CMDs.Simulator.NEW_PHASE),
new SWItem(SWItem.getDye(8), "§7", clickType -> {
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED),
};
} }
private void addNewPhase(boolean shift) { private void addNewPhase(boolean shift) {
ObserverPhase lastElement = observer.getPhases().get(observer.getPhases().size() - 1); ObserverPhase lastElement = observer.getPhases().get(observer.getPhases().size() - 1);
ObserverPhase newPhase = new ObserverPhase(lastElement.getTickOffset() + 4); ObserverPhase newPhase = new ObserverPhase(lastElement.getTickOffset() + 4);
if (shift) newPhase.setTickOffset(newPhase.getTickOffset() + 5); if (shift)
newPhase.setTickOffset(newPhase.getTickOffset() + 5);
scroll += 2; scroll += 2;
observer.add(newPhase); observer.add(newPhase);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
} }
} }
@@ -1,29 +1,27 @@
/* /*
* 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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui; package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement; import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase; import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.core.Core; import de.steamwar.core.Core;
@@ -41,7 +39,8 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui {
private final ObserverPhase observer; private final ObserverPhase observer;
private final SimulatorBaseGui back; private final SimulatorBaseGui back;
public SimulatorObserverPhaseSettingsGui(Player player, Simulator simulator, ObserverElement observerElement, ObserverPhase observer, SimulatorBaseGui back) { public SimulatorObserverPhaseSettingsGui(Player player, Simulator simulator, ObserverElement observerElement, ObserverPhase observer,
SimulatorBaseGui back) {
super(player, simulator, 5 * 9); super(player, simulator, 5 * 9);
this.observerElement = observerElement; this.observerElement = observerElement;
this.observer = observer; this.observer = observer;
@@ -74,7 +73,7 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui {
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
observerElement.getPhases().remove(observer); observerElement.getPhases().remove(observer);
back.open(); back.open();
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DELETE)); }).setCustomModelData(CMDs.Simulator.DELETE));
int index = observerElement.getPhases().indexOf(observer); int index = observerElement.getPhases().indexOf(observer);
@@ -94,18 +93,19 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui {
max = Integer.MAX_VALUE - 4; max = Integer.MAX_VALUE - 4;
} }
//Tick Offset // Tick Offset
int offset = observer.getTickOffset(); int offset = observer.getTickOffset();
inventory.setItem(10, new SWItem(SWItem.getDye(offset < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(10, new SWItem(SWItem.getDye(offset < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
observer.setTickOffset(Math.min(max, offset + (clickType.isShiftClick() ? 5 : 1))); observer.setTickOffset(Math.min(max, offset + (clickType.isShiftClick() ? 5 : 1)));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> {
new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> {
if (integer < 0) return false; if (integer < 0)
return false;
observer.setTickOffset(Math.min(Math.max(integer, min), max)); observer.setTickOffset(Math.min(Math.max(integer, min), max));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(Material.REPEATER).open(); }, this).setItem(Material.REPEATER).open();
}); });
@@ -114,60 +114,66 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui {
inventory.setItem(28, new SWItem(SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(28, new SWItem(SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
observer.setTickOffset(Math.max(min, offset - (clickType.isShiftClick() ? 5 : 1))); observer.setTickOffset(Math.max(min, offset - (clickType.isShiftClick() ? 5 : 1)));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Order // Order
int order = observer.getOrder(); int order = observer.getOrder();
inventory.setItem(13, new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(13,
observer.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
SimulatorWatcher.update(simulator); observer.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1)));
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR");
SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> { SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> {
new SimulatorAnvilGui<>(player, "Activation Order", order + "", Integer::parseInt, integer -> { new SimulatorAnvilGui<>(player, "Activation Order", order + "", Integer::parseInt, integer -> {
if (integer < -SimulatorPhase.ORDER_LIMIT) return false; if (integer < -SimulatorPhase.ORDER_LIMIT)
if (integer > SimulatorPhase.ORDER_LIMIT) return false; return false;
if (integer > SimulatorPhase.ORDER_LIMIT)
return false;
observer.setOrder(integer); observer.setOrder(integer);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(order >= 0 ? Material.COMPASS : negativeNumbers).open(); }, this).setItem(order >= 0 ? Material.COMPASS : negativeNumbers).open();
}); });
orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30))); orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30)));
inventory.setItem(22, orderItem); inventory.setItem(22, orderItem);
inventory.setItem(31, new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(31,
observer.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1))); new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
SimulatorWatcher.update(simulator); observer.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1)));
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
// Update orientation // Update orientation
inventory.setItem(25, new SWItem(Material.SUNFLOWER, "§7", clickType -> { inventory.setItem(25, new SWItem(Material.SUNFLOWER, "§7", clickType -> {
})); }));
inventory.setItem(15, new SWItem(observer.getOrientation() == BlockFace.UP ? Material.LIME_CONCRETE : Material.GRAY_CONCRETE, "§eUp", clickType -> { inventory.setItem(15, new SWItem(observer.getOrientation() == BlockFace.UP ? Material.LIME_CONCRETE : Material.GRAY_CONCRETE, "§eUp", clickType -> {
observer.setOrientation(BlockFace.UP); observer.setOrientation(BlockFace.UP);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
})); }));
inventory.setItem(33, new SWItem(observer.getOrientation() == BlockFace.DOWN ? Material.RED_CONCRETE : Material.GRAY_CONCRETE, "§eDown", clickType -> { inventory.setItem(33, new SWItem(observer.getOrientation() == BlockFace.DOWN ? Material.RED_CONCRETE : Material.GRAY_CONCRETE, "§eDown", clickType -> {
observer.setOrientation(BlockFace.DOWN); observer.setOrientation(BlockFace.DOWN);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
})); }));
inventory.setItem(16, new SWItem(observer.getOrientation() == BlockFace.NORTH ? Material.LIME_WOOL : Material.GRAY_WOOL, "§eNorth", clickType -> { inventory.setItem(16, new SWItem(observer.getOrientation() == BlockFace.NORTH ? Material.LIME_WOOL : Material.GRAY_WOOL, "§eNorth", clickType -> {
observer.setOrientation(BlockFace.NORTH); observer.setOrientation(BlockFace.NORTH);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
})); }));
inventory.setItem(34, new SWItem(observer.getOrientation() == BlockFace.SOUTH ? Material.RED_WOOL : Material.GRAY_WOOL, "§eSouth", clickType -> { inventory.setItem(34, new SWItem(observer.getOrientation() == BlockFace.SOUTH ? Material.RED_WOOL : Material.GRAY_WOOL, "§eSouth", clickType -> {
observer.setOrientation(BlockFace.SOUTH); observer.setOrientation(BlockFace.SOUTH);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}));
inventory.setItem(24, new SWItem(observer.getOrientation() == BlockFace.EAST ? Material.LIME_STAINED_GLASS : Material.GRAY_STAINED_GLASS, "§eEast", clickType -> {
observer.setOrientation(BlockFace.EAST);
SimulatorWatcher.update(simulator);
}));
inventory.setItem(26, new SWItem(observer.getOrientation() == BlockFace.WEST ? Material.RED_STAINED_GLASS : Material.GRAY_STAINED_GLASS, "§eWest", clickType -> {
observer.setOrientation(BlockFace.WEST);
SimulatorWatcher.update(simulator);
})); }));
inventory.setItem(24,
new SWItem(observer.getOrientation() == BlockFace.EAST ? Material.LIME_STAINED_GLASS : Material.GRAY_STAINED_GLASS, "§eEast", clickType -> {
observer.setOrientation(BlockFace.EAST);
SimulatorRenderer.update(simulator);
}));
inventory.setItem(26,
new SWItem(observer.getOrientation() == BlockFace.WEST ? Material.RED_STAINED_GLASS : Material.GRAY_STAINED_GLASS, "§eWest", clickType -> {
observer.setOrientation(BlockFace.WEST);
SimulatorRenderer.update(simulator);
}));
} }
} }
@@ -1,27 +1,25 @@
/* /*
* 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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui; package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement; import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.data.CMDs; import de.steamwar.data.CMDs;
@@ -68,13 +66,14 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui {
int baseTicks = observer.getBaseTick(); int baseTicks = observer.getBaseTick();
inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
observer.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); observer.changeBaseTicks(clickType.isShiftClick() ? 5 : 1);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {
new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> {
if (integer < 0) return false; if (integer < 0)
return false;
observer.changeBaseTicks(integer - baseTicks); observer.changeBaseTicks(integer - baseTicks);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(Material.REPEATER).open(); }, this).setItem(Material.REPEATER).open();
}); });
@@ -86,58 +85,58 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui {
} else { } else {
observer.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); observer.changeBaseTicks(clickType.isShiftClick() ? -5 : -1);
} }
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Pos X // Pos X
inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
observer.move(clickType.isShiftClick() ? 5 : 1, 0, 0); observer.move(clickType.isShiftClick() ? 5 : 1, 0, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + observer.getPosition().getBlockX(), clickType -> { inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + observer.getPosition().getBlockX(), clickType -> {
new SimulatorAnvilGui<>(player, "X", observer.getPosition().getBlockX() + "", Integer::parseInt, i -> { new SimulatorAnvilGui<>(player, "X", observer.getPosition().getBlockX() + "", Integer::parseInt, i -> {
observer.getPosition().setX(i); observer.getPosition().setX(i);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).open(); }, this).open();
})); }));
inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
observer.move(clickType.isShiftClick() ? -5 : -1, 0, 0); observer.move(clickType.isShiftClick() ? -5 : -1, 0, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Pos Y // Pos Y
inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
observer.move(0, clickType.isShiftClick() ? 5 : 1, 0); observer.move(0, clickType.isShiftClick() ? 5 : 1, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + observer.getPosition().getBlockY(), clickType -> { inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + observer.getPosition().getBlockY(), clickType -> {
new SimulatorAnvilGui<>(player, "Y", observer.getPosition().getBlockY() + "", Integer::parseInt, i -> { new SimulatorAnvilGui<>(player, "Y", observer.getPosition().getBlockY() + "", Integer::parseInt, i -> {
observer.getPosition().setY(i); observer.getPosition().setY(i);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).open(); }, this).open();
})); }));
inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
observer.move(0, clickType.isShiftClick() ? -5 : -1, 0); observer.move(0, clickType.isShiftClick() ? -5 : -1, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Pos Z // Pos Z
inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
observer.move(0, 0, clickType.isShiftClick() ? 5 : 1); observer.move(0, 0, clickType.isShiftClick() ? 5 : 1);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + observer.getPosition().getBlockZ(), clickType -> { inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + observer.getPosition().getBlockZ(), clickType -> {
new SimulatorAnvilGui<>(player, "Z", observer.getPosition().getBlockZ() + "", Integer::parseInt, i -> { new SimulatorAnvilGui<>(player, "Z", observer.getPosition().getBlockZ() + "", Integer::parseInt, i -> {
observer.getPosition().setZ(i); observer.getPosition().setZ(i);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).open(); }, this).open();
})); }));
inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
observer.move(0, 0, clickType.isShiftClick() ? -5 : -1); observer.move(0, 0, clickType.isShiftClick() ? -5 : -1);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
} }
} }
@@ -1,29 +1,27 @@
/* /*
* 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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui; package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui;
import de.steamwar.data.CMDs; import de.steamwar.data.CMDs;
@@ -61,7 +59,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<SimulatorRedstoneGu
public void headerAndFooter() { public void headerAndFooter() {
if (redstone.getPhases().isEmpty()) { if (redstone.getPhases().isEmpty()) {
back.open(); back.open();
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return; return;
} }
@@ -93,7 +91,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<SimulatorRedstoneGu
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
redstone.getPhases().clear(); redstone.getPhases().clear();
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DELETE)); }).setCustomModelData(CMDs.Simulator.DELETE));
// Material Chooser // Material Chooser
@@ -107,10 +105,11 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<SimulatorRedstoneGu
}).setCustomModelData(CMDs.Simulator.SETTINGS)); }).setCustomModelData(CMDs.Simulator.SETTINGS));
// Enable/Disable // Enable/Disable
inventory.setItem(48, new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { inventory.setItem(48,
redstone.setDisabled(!redstone.isDisabled()); new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
SimulatorWatcher.update(simulator); redstone.setDisabled(!redstone.isDisabled());
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED)); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
// Group chooser // Group chooser
inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> {
@@ -151,55 +150,49 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<SimulatorRedstoneGu
lore.add(""); lore.add("");
lore.add("§7Click§8:§e Edit"); lore.add("§7Click§8:§e Edit");
lore.add("§7Middle-Click§8:§e Remove"); lore.add("§7Middle-Click§8:§e Remove");
SWItem redstone = new SWItem(redstoneSubPhase.place ? Material.REDSTONE_BLOCK : Material.STONE, redstoneSubPhase.place ? "§eActivate" : "§eDeactivate", lore, false, clickType -> { SWItem redstone = new SWItem(redstoneSubPhase.place ? Material.REDSTONE_BLOCK : Material.STONE, redstoneSubPhase.place ? "§eActivate" : "§eDeactivate",
if (clickType == ClickType.MIDDLE) { lore, false, clickType -> {
this.redstone.getPhases().remove(redstoneSubPhase.phase); if (clickType == ClickType.MIDDLE) {
SimulatorWatcher.update(simulator); this.redstone.getPhases().remove(redstoneSubPhase.phase);
} else { SimulatorRenderer.update(simulator);
new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open(); } else {
} new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open();
}); }
});
redstone.getItemStack().setAmount(Math.max(1, Math.min(time, 64))); redstone.getItemStack().setAmount(Math.max(1, Math.min(time, 64)));
Supplier<Integer> getter = redstoneSubPhase.place ? redstoneSubPhase.phase::getTickOffset : redstoneSubPhase.phase::getLifetime; Supplier<Integer> getter = redstoneSubPhase.place ? redstoneSubPhase.phase::getTickOffset : redstoneSubPhase.phase::getLifetime;
Consumer<Integer> setter = redstoneSubPhase.place ? redstoneSubPhase.phase::setTickOffset : redstoneSubPhase.phase::setLifetime; Consumer<Integer> setter = redstoneSubPhase.place ? redstoneSubPhase.phase::setTickOffset : redstoneSubPhase.phase::setLifetime;
return new SWItem[] { return new SWItem[] {new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1)));
setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1))); SimulatorRenderer.update(simulator);
SimulatorWatcher.update(simulator); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), redstone,
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED),
redstone,
new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> {
setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1))); setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1)));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED), }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED), new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> {
new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> {
new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open(); new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open();
}).setCustomModelData(CMDs.Simulator.EDIT_ACTIVATION), }).setCustomModelData(CMDs.Simulator.EDIT_ACTIVATION),};
};
} }
@Override @Override
public SWItem[] lastColumn() { public SWItem[] lastColumn() {
return new SWItem[]{ return new SWItem[] {new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { addNewPhase(clickType.isShiftClick());
addNewPhase(clickType.isShiftClick()); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), new SWItem(Material.REDSTONE, "§eRedstone§8:§a New Phase", clickType -> {
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), addNewPhase(false);
new SWItem(Material.REDSTONE, "§eRedstone§8:§a New Phase", clickType -> { }).setCustomModelData(CMDs.Simulator.NEW_PHASE), new SWItem(SWItem.getDye(8), "§7", clickType -> {
addNewPhase(false); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED),};
}).setCustomModelData(CMDs.Simulator.NEW_PHASE),
new SWItem(SWItem.getDye(8), "§7", clickType -> {
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED),
};
} }
private void addNewPhase(boolean shift) { private void addNewPhase(boolean shift) {
RedstonePhase lastElement = redstone.getPhases().get(redstone.getPhases().size() - 1); RedstonePhase lastElement = redstone.getPhases().get(redstone.getPhases().size() - 1);
RedstonePhase newPhase = new RedstonePhase(lastElement.getTickOffset() + lastElement.getLifetime() + 1); RedstonePhase newPhase = new RedstonePhase(lastElement.getTickOffset() + lastElement.getLifetime() + 1);
if (shift) newPhase.setTickOffset(newPhase.getTickOffset() + 5); if (shift)
newPhase.setTickOffset(newPhase.getTickOffset() + 5);
scroll += 2; scroll += 2;
redstone.add(newPhase); redstone.add(newPhase);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
} }
@AllArgsConstructor @AllArgsConstructor
@@ -1,29 +1,27 @@
/* /*
* 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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui; package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase; import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.core.Core; import de.steamwar.core.Core;
@@ -39,7 +37,8 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui {
private final RedstonePhase redstone; private final RedstonePhase redstone;
private final SimulatorBaseGui back; private final SimulatorBaseGui back;
public SimulatorRedstonePhaseSettingsGui(Player player, Simulator simulator, RedstoneElement redstoneElement, RedstonePhase redstone, SimulatorBaseGui back) { public SimulatorRedstonePhaseSettingsGui(Player player, Simulator simulator, RedstoneElement redstoneElement, RedstonePhase redstone,
SimulatorBaseGui back) {
super(player, simulator, 5 * 9); super(player, simulator, 5 * 9);
this.redstoneElement = redstoneElement; this.redstoneElement = redstoneElement;
this.redstone = redstone; this.redstone = redstone;
@@ -72,7 +71,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui {
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
redstoneElement.getPhases().remove(redstone); redstoneElement.getPhases().remove(redstone);
back.open(); back.open();
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DELETE)); }).setCustomModelData(CMDs.Simulator.DELETE));
int index = redstoneElement.getPhases().indexOf(redstone); int index = redstoneElement.getPhases().indexOf(redstone);
@@ -95,18 +94,19 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui {
maxOffset = Integer.MAX_VALUE - 5; maxOffset = Integer.MAX_VALUE - 5;
} }
//Tick Offset // Tick Offset
int offset = redstone.getTickOffset(); int offset = redstone.getTickOffset();
inventory.setItem(10, new SWItem(SWItem.getDye(offset < maxOffset ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(10, new SWItem(SWItem.getDye(offset < maxOffset ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
redstone.setTickOffset(Math.min(maxOffset, offset + (clickType.isShiftClick() ? 5 : 1))); redstone.setTickOffset(Math.min(maxOffset, offset + (clickType.isShiftClick() ? 5 : 1)));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> {
new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> {
if (integer < 0) return false; if (integer < 0)
return false;
redstone.setTickOffset(Math.min(Math.max(integer, min), maxOffset)); redstone.setTickOffset(Math.min(Math.max(integer, min), maxOffset));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(Material.REPEATER).open(); }, this).setItem(Material.REPEATER).open();
}); });
@@ -115,21 +115,22 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui {
inventory.setItem(28, new SWItem(SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(28, new SWItem(SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
redstone.setTickOffset(Math.max(min, offset - (clickType.isShiftClick() ? 5 : 1))); redstone.setTickOffset(Math.max(min, offset - (clickType.isShiftClick() ? 5 : 1)));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Lifetime // Lifetime
int lifetime = redstone.getLifetime(); int lifetime = redstone.getLifetime();
inventory.setItem(11, new SWItem(SWItem.getDye(lifetime < maxLifetime ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(11, new SWItem(SWItem.getDye(lifetime < maxLifetime ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
redstone.setLifetime(Math.min(maxLifetime, lifetime + (clickType.isShiftClick() ? 5 : 1))); redstone.setLifetime(Math.min(maxLifetime, lifetime + (clickType.isShiftClick() ? 5 : 1)));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eActivation Time§8:§7 " + lifetime, clickType -> { SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eActivation Time§8:§7 " + lifetime, clickType -> {
new SimulatorAnvilGui<>(player, "Activation Time", lifetime + "", Integer::parseInt, integer -> { new SimulatorAnvilGui<>(player, "Activation Time", lifetime + "", Integer::parseInt, integer -> {
if (integer < 0) return false; if (integer < 0)
return false;
redstone.setLifetime(Math.min(integer, maxLifetime)); redstone.setLifetime(Math.min(integer, maxLifetime));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(Material.CLOCK).open(); }, this).setItem(Material.CLOCK).open();
}); });
@@ -138,32 +139,36 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui {
inventory.setItem(29, new SWItem(SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(29, new SWItem(SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
redstone.setLifetime(Math.max(0, lifetime - (clickType.isShiftClick() ? 5 : 1))); redstone.setLifetime(Math.max(0, lifetime - (clickType.isShiftClick() ? 5 : 1)));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Order // Order
int order = redstone.getOrder(); int order = redstone.getOrder();
inventory.setItem(13, new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(13,
redstone.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
SimulatorWatcher.update(simulator); redstone.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1)));
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR");
SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> { SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> {
new SimulatorAnvilGui<>(player, "Activation Order", order + "", Integer::parseInt, integer -> { new SimulatorAnvilGui<>(player, "Activation Order", order + "", Integer::parseInt, integer -> {
if (integer < -SimulatorPhase.ORDER_LIMIT) return false; if (integer < -SimulatorPhase.ORDER_LIMIT)
if (integer > SimulatorPhase.ORDER_LIMIT) return false; return false;
if (integer > SimulatorPhase.ORDER_LIMIT)
return false;
redstone.setOrder(integer); redstone.setOrder(integer);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(order >= 0 ? Material.COMPASS : negativeNumbers).open(); }, this).setItem(order >= 0 ? Material.COMPASS : negativeNumbers).open();
}); });
orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30))); orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30)));
inventory.setItem(22, orderItem); inventory.setItem(22, orderItem);
inventory.setItem(31, new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(31,
redstone.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1))); new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
SimulatorWatcher.update(simulator); redstone.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1)));
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
} }
} }
@@ -1,27 +1,25 @@
/* /*
* 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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui; package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement; import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.data.CMDs; import de.steamwar.data.CMDs;
@@ -67,13 +65,14 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui {
int baseTicks = redstone.getBaseTick(); int baseTicks = redstone.getBaseTick();
inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
redstone.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); redstone.changeBaseTicks(clickType.isShiftClick() ? 5 : 1);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {
new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> {
if (integer < 0) return false; if (integer < 0)
return false;
redstone.changeBaseTicks(integer - baseTicks); redstone.changeBaseTicks(integer - baseTicks);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(Material.REPEATER).open(); }, this).setItem(Material.REPEATER).open();
}); });
@@ -85,58 +84,58 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui {
} else { } else {
redstone.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); redstone.changeBaseTicks(clickType.isShiftClick() ? -5 : -1);
} }
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Pos X // Pos X
inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
redstone.move(clickType.isShiftClick() ? 5 : 1, 0, 0); redstone.move(clickType.isShiftClick() ? 5 : 1, 0, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + redstone.getPosition().getBlockX(), clickType -> { inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + redstone.getPosition().getBlockX(), clickType -> {
new SimulatorAnvilGui<>(player, "X", redstone.getPosition().getBlockX() + "", Integer::parseInt, i -> { new SimulatorAnvilGui<>(player, "X", redstone.getPosition().getBlockX() + "", Integer::parseInt, i -> {
redstone.getPosition().setX(i); redstone.getPosition().setX(i);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).open(); }, this).open();
})); }));
inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
redstone.move(clickType.isShiftClick() ? -5 : -1, 0, 0); redstone.move(clickType.isShiftClick() ? -5 : -1, 0, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Pos Y // Pos Y
inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
redstone.move(0, clickType.isShiftClick() ? 5 : 1, 0); redstone.move(0, clickType.isShiftClick() ? 5 : 1, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + redstone.getPosition().getBlockY(), clickType -> { inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + redstone.getPosition().getBlockY(), clickType -> {
new SimulatorAnvilGui<>(player, "Y", redstone.getPosition().getBlockY() + "", Integer::parseInt, i -> { new SimulatorAnvilGui<>(player, "Y", redstone.getPosition().getBlockY() + "", Integer::parseInt, i -> {
redstone.getPosition().setY(i); redstone.getPosition().setY(i);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).open(); }, this).open();
})); }));
inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
redstone.move(0, clickType.isShiftClick() ? -5 : -1, 0); redstone.move(0, clickType.isShiftClick() ? -5 : -1, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Pos Z // Pos Z
inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
redstone.move(0, 0, clickType.isShiftClick() ? 5 : 1); redstone.move(0, 0, clickType.isShiftClick() ? 5 : 1);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + redstone.getPosition().getBlockZ(), clickType -> { inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + redstone.getPosition().getBlockZ(), clickType -> {
new SimulatorAnvilGui<>(player, "Z", redstone.getPosition().getBlockZ() + "", Integer::parseInt, i -> { new SimulatorAnvilGui<>(player, "Z", redstone.getPosition().getBlockZ() + "", Integer::parseInt, i -> {
redstone.getPosition().setZ(i); redstone.getPosition().setZ(i);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).open(); }, this).open();
})); }));
inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
redstone.move(0, 0, clickType.isShiftClick() ? -5 : -1); redstone.move(0, 0, clickType.isShiftClick() ? -5 : -1);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
} }
} }
@@ -1,26 +1,24 @@
/* /*
* 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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui; package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.data.CMDs; import de.steamwar.data.CMDs;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
@@ -55,50 +53,52 @@ public class SimulatorSettingsGui extends SimulatorBaseGui {
new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open(); new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open();
})); }));
//AutoTrace // AutoTrace
inventory.setItem(19, new SWItem(simulator.isAutoTrace() ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, "§eAutoTrace§8: " + (simulator.isAutoTrace() ? "§aOn" : "§cOff"), clickType -> { inventory.setItem(19, new SWItem(simulator.isAutoTrace() ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK,
simulator.setAutoTrace(!simulator.isAutoTrace()); "§eAutoTrace§8: " + (simulator.isAutoTrace() ? "§aOn" : "§cOff"), clickType -> {
SimulatorWatcher.update(simulator); simulator.setAutoTrace(!simulator.isAutoTrace());
})); SimulatorRenderer.update(simulator);
inventory.setItem(20, new SWItem(simulator.isAutoTestblock() ? Material.END_STONE : Material.BARRIER, "§eTestblock§8: " + (simulator.isAutoTestblock() ? "§aOn" : "§cOff"), clickType -> { }));
simulator.setAutoTestblock(!simulator.isAutoTestblock()); inventory.setItem(20, new SWItem(simulator.isAutoTestblock() ? Material.END_STONE : Material.BARRIER,
SimulatorWatcher.update(simulator); "§eTestblock§8: " + (simulator.isAutoTestblock() ? "§aOn" : "§cOff"), clickType -> {
})); simulator.setAutoTestblock(!simulator.isAutoTestblock());
SimulatorRenderer.update(simulator);
}));
//Pos X // Pos X
inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
simulator.move(clickType.isShiftClick() ? 5 : 1, 0, 0); simulator.move(clickType.isShiftClick() ? 5 : 1, 0, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> { inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> {
})); }));
inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
simulator.move(clickType.isShiftClick() ? -5 : -1, 0, 0); simulator.move(clickType.isShiftClick() ? -5 : -1, 0, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Pos Y // Pos Y
inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
simulator.move(0, clickType.isShiftClick() ? 5 : 1, 0); simulator.move(0, clickType.isShiftClick() ? 5 : 1, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> { inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> {
})); }));
inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
simulator.move(0, clickType.isShiftClick() ? -5 : -1, 0); simulator.move(0, clickType.isShiftClick() ? -5 : -1, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Pos Z // Pos Z
inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
simulator.move(0, 0, clickType.isShiftClick() ? 5 : 1); simulator.move(0, 0, clickType.isShiftClick() ? 5 : 1);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> { inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> {
})); }));
inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
simulator.move(0, 0, clickType.isShiftClick() ? -5 : -1); simulator.move(0, 0, clickType.isShiftClick() ? -5 : -1);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
} }
} }
@@ -1,29 +1,27 @@
/* /*
* 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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui; package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase; import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.execute.SimulatorStabGenerator; import de.steamwar.bausystem.features.simulator.execute.SimulatorStabGenerator;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
@@ -60,7 +58,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
public void headerAndFooter() { public void headerAndFooter() {
if (tnt.getPhases().isEmpty()) { if (tnt.getPhases().isEmpty()) {
back.open(); back.open();
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return; return;
} }
@@ -87,7 +85,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
tnt.getPhases().clear(); tnt.getPhases().clear();
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DELETE)); }).setCustomModelData(CMDs.Simulator.DELETE));
// Material Chooser // Material Chooser
@@ -98,16 +96,18 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> { inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
new SimulatorTNTSettingsGui(player, simulator, tnt, this).open(); new SimulatorTNTSettingsGui(player, simulator, tnt, this).open();
}).setCustomModelData(CMDs.Simulator.SETTINGS)); }).setCustomModelData(CMDs.Simulator.SETTINGS));
inventory.setItem(48, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> { inventory.setItem(48,
tnt.setDisabled(!tnt.isDisabled()); new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
SimulatorWatcher.update(simulator); tnt.setDisabled(!tnt.isDisabled());
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED)); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
if (Core.getVersion() > 19) { if (Core.getVersion() > 19) {
inventory.setItem(49, new SWItem(Material.CALIBRATED_SCULK_SENSOR, "§eCreate Stab", click -> { inventory.setItem(49, new SWItem(Material.CALIBRATED_SCULK_SENSOR, "§eCreate Stab", click -> {
new SimulatorAnvilGui<>(player, "Depth Limit", "", Integer::parseInt, depthLimit -> { new SimulatorAnvilGui<>(player, "Depth Limit", "", Integer::parseInt, depthLimit -> {
if (depthLimit <= 0) return false; if (depthLimit <= 0)
return false;
simulator.setStabGenerator(new SimulatorStabGenerator(Region.getRegion(player.getLocation()), simulator, tnt, depthLimit)); simulator.setStabGenerator(new SimulatorStabGenerator(Region.getRegion(player.getLocation()), simulator, tnt, depthLimit));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, null).open(); }, null).open();
}).setCustomModelData(CMDs.Simulator.CREATE_STAB)); }).setCustomModelData(CMDs.Simulator.CREATE_STAB));
@@ -117,7 +117,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
tntElement.add(new TNTPhase()); tntElement.add(new TNTPhase());
parent.add(tntElement); parent.add(tntElement);
new SimulatorGroupGui(player, simulator, parent, new SimulatorGui(player, simulator)).open(); new SimulatorGroupGui(player, simulator, parent, new SimulatorGui(player, simulator)).open();
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.MAKE_GROUP)); }).setCustomModelData(CMDs.Simulator.MAKE_GROUP));
inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> { inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> {
new SimulatorGroupChooserGui(player, simulator, tnt, tnt.getGroup(simulator), this).open(); new SimulatorGroupChooserGui(player, simulator, tnt, tnt.getGroup(simulator), this).open();
@@ -126,52 +126,50 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
@Override @Override
public SWItem[] column(TNTPhase tntSetting, int index) { public SWItem[] column(TNTPhase tntSetting, int index) {
SWItem tnt = new SWItem(Material.TNT, "§eTNT§8:§7 " + tntSetting.getCount(), Arrays.asList("§7Tick§8: §e" + tntSetting.getTickOffset(), "§7Fuse§8:§e " + tntSetting.getLifetime(), "", "§7Order§8:§e " + tntSetting.getOrder(), "", "§7X-Jump§8: " + (tntSetting.isXJump() ? "§aOn" : "§cOff"), "§7Y-Jump§8: " + (tntSetting.isYJump() ? "§aOn" : "§cOff"), "§7Z-Jump§8: " + (tntSetting.isZJump() ? "§aOn" : "§cOff"), "", "§7Click§8:§e Edit", "§7Middle-Click§8:§e Remove"), false, clickType -> { SWItem tnt = new SWItem(Material.TNT, "§eTNT§8:§7 " + tntSetting.getCount(),
if (clickType == ClickType.MIDDLE) { Arrays.asList("§7Tick§8: §e" + tntSetting.getTickOffset(), "§7Fuse§8:§e " + tntSetting.getLifetime(), "",
this.tnt.getPhases().remove(tntSetting); "§7Order§8:§e " + tntSetting.getOrder(), "", "§7X-Jump§8: " + (tntSetting.isXJump() ? "§aOn" : "§cOff"),
SimulatorWatcher.update(simulator); "§7Y-Jump§8: " + (tntSetting.isYJump() ? "§aOn" : "§cOff"), "§7Z-Jump§8: " + (tntSetting.isZJump() ? "§aOn" : "§cOff"), "",
} else { "§7Click§8:§e Edit", "§7Middle-Click§8:§e Remove"),
new SimulatorTNTPhaseSettingsGui(player, simulator, this.tnt, tntSetting, this).open(); false, clickType -> {
} if (clickType == ClickType.MIDDLE) {
}); this.tnt.getPhases().remove(tntSetting);
SimulatorRenderer.update(simulator);
} else {
new SimulatorTNTPhaseSettingsGui(player, simulator, this.tnt, tntSetting, this).open();
}
});
tnt.getItemStack().setAmount(Math.min(tntSetting.getCount(), 64)); tnt.getItemStack().setAmount(Math.min(tntSetting.getCount(), 64));
return new SWItem[]{ return new SWItem[] {new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { tntSetting.setCount(tntSetting.getCount() + (clickType.isShiftClick() ? 5 : 1));
tntSetting.setCount(tntSetting.getCount() + (clickType.isShiftClick() ? 5 : 1)); SimulatorRenderer.update(simulator);
SimulatorWatcher.update(simulator); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), tnt,
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED),
tnt,
new SWItem(SWItem.getDye(tntSetting.getCount() > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> { new SWItem(SWItem.getDye(tntSetting.getCount() > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> {
tntSetting.setCount(Math.max(1, tntSetting.getCount() - (clickType.isShiftClick() ? 5 : 1))); tntSetting.setCount(Math.max(1, tntSetting.getCount() - (clickType.isShiftClick() ? 5 : 1)));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED), }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED), new SWItem(Material.ANVIL, "§eEdit Phase", clickType -> {
new SWItem(Material.ANVIL, "§eEdit Phase", clickType -> {
new SimulatorTNTPhaseSettingsGui(player, simulator, this.tnt, tntSetting, this).open(); new SimulatorTNTPhaseSettingsGui(player, simulator, this.tnt, tntSetting, this).open();
}).setCustomModelData(CMDs.Simulator.EDIT_ACTIVATION), }).setCustomModelData(CMDs.Simulator.EDIT_ACTIVATION),};
};
} }
@Override @Override
public SWItem[] lastColumn() { public SWItem[] lastColumn() {
return new SWItem[]{ return new SWItem[] {new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> { addNewPhase(clickType.isShiftClick());
addNewPhase(clickType.isShiftClick()); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), new SWItem(Material.GUNPOWDER, "§eTNT§8:§a New Phase", clickType -> {
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), addNewPhase(false);
new SWItem(Material.GUNPOWDER, "§eTNT§8:§a New Phase", clickType -> { }).setCustomModelData(CMDs.Simulator.NEW_PHASE), new SWItem(SWItem.getDye(8), "§7", clickType -> {
addNewPhase(false); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED),};
}).setCustomModelData(CMDs.Simulator.NEW_PHASE),
new SWItem(SWItem.getDye(8), "§7", clickType -> {
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED),
};
} }
private void addNewPhase(boolean shift) { private void addNewPhase(boolean shift) {
TNTPhase lastElement = tnt.getPhases().get(tnt.getPhases().size() - 1); TNTPhase lastElement = tnt.getPhases().get(tnt.getPhases().size() - 1);
TNTPhase newPhase = new TNTPhase(lastElement.getTickOffset() + 1); TNTPhase newPhase = new TNTPhase(lastElement.getTickOffset() + 1);
if (shift) newPhase.setCount(newPhase.getCount() + 5); if (shift)
newPhase.setCount(newPhase.getCount() + 5);
scroll++; scroll++;
tnt.add(newPhase); tnt.add(newPhase);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
} }
} }
@@ -1,29 +1,27 @@
/* /*
* 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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui; package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase; import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase; import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.core.Core; import de.steamwar.core.Core;
@@ -68,25 +66,26 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui {
new SimulatorMaterialGui(player, simulator, tntElement::getMaterial, tntElement::setMaterial, this).open(); new SimulatorMaterialGui(player, simulator, tntElement::getMaterial, tntElement::setMaterial, this).open();
})); }));
//Delete // Delete
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> { inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
tntElement.getPhases().remove(tnt); tntElement.getPhases().remove(tnt);
back.open(); back.open();
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DELETE)); }).setCustomModelData(CMDs.Simulator.DELETE));
//Count // Count
int count = tnt.getCount(); int count = tnt.getCount();
inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
tnt.setCount(count + (clickType.isShiftClick() ? 5 : 1)); tnt.setCount(count + (clickType.isShiftClick() ? 5 : 1));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
SWItem countItem = new SWItem(Material.TNT, "§eCount§8:§7 " + count, clickType -> { SWItem countItem = new SWItem(Material.TNT, "§eCount§8:§7 " + count, clickType -> {
new SimulatorAnvilGui<>(player, "Count", count + "", Integer::parseInt, integer -> { new SimulatorAnvilGui<>(player, "Count", count + "", Integer::parseInt, integer -> {
if (integer < 1) return false; if (integer < 1)
return false;
tnt.setCount(integer); tnt.setCount(integer);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(Material.TNT).open(); }, this).setItem(Material.TNT).open();
}); });
@@ -95,21 +94,22 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui {
inventory.setItem(27, new SWItem(SWItem.getDye(count > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(27, new SWItem(SWItem.getDye(count > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
tnt.setCount(Math.max(1, count - (clickType.isShiftClick() ? 5 : 1))); tnt.setCount(Math.max(1, count - (clickType.isShiftClick() ? 5 : 1)));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Tick Offset // Tick Offset
int offset = tnt.getTickOffset(); int offset = tnt.getTickOffset();
inventory.setItem(10, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(10, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
tnt.setTickOffset(offset + (clickType.isShiftClick() ? 5 : 1)); tnt.setTickOffset(offset + (clickType.isShiftClick() ? 5 : 1));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> { SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> {
new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> { new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> {
if (integer < 0) return false; if (integer < 0)
return false;
tnt.setTickOffset(integer); tnt.setTickOffset(integer);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(Material.REPEATER).open(); }, this).setItem(Material.REPEATER).open();
}); });
@@ -118,21 +118,22 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui {
inventory.setItem(28, new SWItem(SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(28, new SWItem(SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
tnt.setTickOffset(Math.max(0, offset - (clickType.isShiftClick() ? 5 : 1))); tnt.setTickOffset(Math.max(0, offset - (clickType.isShiftClick() ? 5 : 1)));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Lifetime // Lifetime
int lifetime = tnt.getLifetime(); int lifetime = tnt.getLifetime();
inventory.setItem(11, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(11, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
tnt.setLifetime(lifetime + (clickType.isShiftClick() ? 5 : 1)); tnt.setLifetime(lifetime + (clickType.isShiftClick() ? 5 : 1));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> { SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> {
new SimulatorAnvilGui<>(player, "Lifetime", lifetime + "", Integer::parseInt, integer -> { new SimulatorAnvilGui<>(player, "Lifetime", lifetime + "", Integer::parseInt, integer -> {
if (integer < 1) return false; if (integer < 1)
return false;
tnt.setLifetime(integer); tnt.setLifetime(integer);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(Material.CLOCK).open(); }, this).setItem(Material.CLOCK).open();
}); });
@@ -141,56 +142,63 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui {
inventory.setItem(29, new SWItem(SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(29, new SWItem(SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
tnt.setLifetime(Math.max(1, lifetime - (clickType.isShiftClick() ? 5 : 1))); tnt.setLifetime(Math.max(1, lifetime - (clickType.isShiftClick() ? 5 : 1)));
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Order // Order
int order = tnt.getOrder(); int order = tnt.getOrder();
inventory.setItem(13, new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(13,
tnt.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1))); new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
SimulatorWatcher.update(simulator); tnt.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1)));
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR"); Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR");
SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eCalculation Order§8:§7 " + order, clickType -> { SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eCalculation Order§8:§7 " + order, clickType -> {
new SimulatorAnvilGui<>(player, "Calculation Order", order + "", Integer::parseInt, integer -> { new SimulatorAnvilGui<>(player, "Calculation Order", order + "", Integer::parseInt, integer -> {
if (integer < -SimulatorPhase.ORDER_LIMIT) return false; if (integer < -SimulatorPhase.ORDER_LIMIT)
if (integer > SimulatorPhase.ORDER_LIMIT) return false; return false;
if (integer > SimulatorPhase.ORDER_LIMIT)
return false;
tnt.setOrder(integer); tnt.setOrder(integer);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(order >= 0 ? Material.COMPASS : negativeNumbers).open(); }, this).setItem(order >= 0 ? Material.COMPASS : negativeNumbers).open();
}); });
orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30))); orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30)));
inventory.setItem(22, orderItem); inventory.setItem(22, orderItem);
inventory.setItem(31, new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> { inventory.setItem(31,
tnt.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1))); new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
SimulatorWatcher.update(simulator); tnt.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1)));
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
//Jump // Jump
SWItem jumpX = new SWItem(tnt.isXJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump X§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> { SWItem jumpX =
tnt.setXJump(!tnt.isXJump()); new SWItem(tnt.isXJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump X§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> {
SimulatorWatcher.update(simulator); tnt.setXJump(!tnt.isXJump());
}); SimulatorRenderer.update(simulator);
});
inventory.setItem(33, jumpX); inventory.setItem(33, jumpX);
SWItem jumpY = new SWItem(tnt.isYJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump Y§8: " + (tnt.isYJump() ? "§aon" : "§coff"), clickType -> { SWItem jumpY =
tnt.setYJump(!tnt.isYJump()); new SWItem(tnt.isYJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump Y§8: " + (tnt.isYJump() ? "§aon" : "§coff"), clickType -> {
SimulatorWatcher.update(simulator); tnt.setYJump(!tnt.isYJump());
}); SimulatorRenderer.update(simulator);
});
inventory.setItem(16, jumpY); inventory.setItem(16, jumpY);
SWItem jumpZ = new SWItem(tnt.isZJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump Z§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> { SWItem jumpZ =
tnt.setZJump(!tnt.isZJump()); new SWItem(tnt.isZJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump Z§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> {
SimulatorWatcher.update(simulator); tnt.setZJump(!tnt.isZJump());
}); SimulatorRenderer.update(simulator);
});
inventory.setItem(35, jumpZ); inventory.setItem(35, jumpZ);
SWItem jumpAll = new SWItem(Material.TNT, "§7TNT §eJump §8: " + (tnt.hasJump() ? "§aon" : "§coff"), clickType -> { SWItem jumpAll = new SWItem(Material.TNT, "§7TNT §eJump §8: " + (tnt.hasJump() ? "§aon" : "§coff"), clickType -> {
tnt.setJump(!tnt.hasJump()); tnt.setJump(!tnt.hasJump());
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}); });
inventory.setItem(25, jumpAll); inventory.setItem(25, jumpAll);
} }
@@ -1,27 +1,25 @@
/* /*
* 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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui; package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.data.CMDs; import de.steamwar.data.CMDs;
@@ -76,13 +74,14 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui {
int baseTicks = tnt.getBaseTick(); int baseTicks = tnt.getBaseTick();
inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> { inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
tnt.changeBaseTicks(clickType.isShiftClick() ? 5 : 1); tnt.changeBaseTicks(clickType.isShiftClick() ? 5 : 1);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> { SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {
new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> { new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> {
if (integer < 0) return false; if (integer < 0)
return false;
tnt.changeBaseTicks(integer - baseTicks); tnt.changeBaseTicks(integer - baseTicks);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).setItem(Material.REPEATER).open(); }, this).setItem(Material.REPEATER).open();
}); });
@@ -94,42 +93,46 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui {
} else { } else {
tnt.changeBaseTicks(clickType.isShiftClick() ? -5 : -1); tnt.changeBaseTicks(clickType.isShiftClick() ? -5 : -1);
} }
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
// Subpixel Alignment // Subpixel Alignment
inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> { inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> {
tnt.alignX(0); tnt.alignX(0);
tnt.alignZ(0); tnt.alignZ(0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
})); }));
// Z // Z
SWItem negativZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> { SWItem negativZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> {
if (tnt.getAlignment().getZ() != -1) tnt.alignZ(-1); if (tnt.getAlignment().getZ() != -1)
SimulatorWatcher.update(simulator); tnt.alignZ(-1);
SimulatorRenderer.update(simulator);
}); });
negativZItem.setEnchanted(tnt.getAlignment().getZ() == -1); negativZItem.setEnchanted(tnt.getAlignment().getZ() == -1);
inventory.setItem(20, negativZItem); inventory.setItem(20, negativZItem);
SWItem positivZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> { SWItem positivZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> {
if (tnt.getAlignment().getZ() != 1) tnt.alignZ(1); if (tnt.getAlignment().getZ() != 1)
SimulatorWatcher.update(simulator); tnt.alignZ(1);
SimulatorRenderer.update(simulator);
}); });
positivZItem.setEnchanted(tnt.getAlignment().getZ() == 1); positivZItem.setEnchanted(tnt.getAlignment().getZ() == 1);
inventory.setItem(22, positivZItem); inventory.setItem(22, positivZItem);
// X // X
SWItem negativXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> { SWItem negativXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> {
if (tnt.getAlignment().getX() != -1) tnt.alignX(-1); if (tnt.getAlignment().getX() != -1)
SimulatorWatcher.update(simulator); tnt.alignX(-1);
SimulatorRenderer.update(simulator);
}); });
negativXItem.setEnchanted(tnt.getAlignment().getX() == -1); negativXItem.setEnchanted(tnt.getAlignment().getX() == -1);
inventory.setItem(12, negativXItem); inventory.setItem(12, negativXItem);
SWItem positivXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> { SWItem positivXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> {
if(tnt.getAlignment().getX() != 1) tnt.alignX(1); if (tnt.getAlignment().getX() != 1)
SimulatorWatcher.update(simulator); tnt.alignX(1);
SimulatorRenderer.update(simulator);
}); });
positivXItem.setEnchanted(tnt.getAlignment().getX() == 1); positivXItem.setEnchanted(tnt.getAlignment().getX() == 1);
inventory.setItem(30, positivXItem); inventory.setItem(30, positivXItem);
@@ -137,52 +140,52 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui {
// Pos X // Pos X
inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> {
tnt.move(clickType.isShiftClick() ? 0.0625 : 1, 0, 0); tnt.move(clickType.isShiftClick() ? 0.0625 : 1, 0, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + tnt.getPosition().getX(), clickType -> { inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + tnt.getPosition().getX(), clickType -> {
new SimulatorAnvilGui<>(player, "X", tnt.getPosition().getX() + "", Double::parseDouble, d -> { new SimulatorAnvilGui<>(player, "X", tnt.getPosition().getX() + "", Double::parseDouble, d -> {
tnt.getPosition().setX(d); tnt.getPosition().setX(d);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).open(); }, this).open();
})); }));
inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> {
tnt.move(clickType.isShiftClick() ? -0.0625 : -1, 0, 0); tnt.move(clickType.isShiftClick() ? -0.0625 : -1, 0, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
// Pos Y // Pos Y
inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> {
tnt.move(0, clickType.isShiftClick() ? 0.0625 : 1, 0); tnt.move(0, clickType.isShiftClick() ? 0.0625 : 1, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + tnt.getPosition().getY(), clickType -> { inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + tnt.getPosition().getY(), clickType -> {
new SimulatorAnvilGui<>(player, "Y", tnt.getPosition().getY() + "", Double::parseDouble, d -> { new SimulatorAnvilGui<>(player, "Y", tnt.getPosition().getY() + "", Double::parseDouble, d -> {
tnt.getPosition().setY(d); tnt.getPosition().setY(d);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).open(); }, this).open();
})); }));
inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> {
tnt.move(0, clickType.isShiftClick() ? -0.0625 : -1, 0); tnt.move(0, clickType.isShiftClick() ? -0.0625 : -1, 0);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
// Pos Z // Pos Z
inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> { inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> {
tnt.move(0, 0, clickType.isShiftClick() ? 0.0625 : 1); tnt.move(0, 0, clickType.isShiftClick() ? 0.0625 : 1);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + tnt.getPosition().getZ(), clickType -> { inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + tnt.getPosition().getZ(), clickType -> {
new SimulatorAnvilGui<>(player, "Z", tnt.getPosition().getZ() + "", Double::parseDouble, d -> { new SimulatorAnvilGui<>(player, "Z", tnt.getPosition().getZ() + "", Double::parseDouble, d -> {
tnt.getPosition().setZ(d); tnt.getPosition().setZ(d);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
return true; return true;
}, this).open(); }, this).open();
})); }));
inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> { inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> {
tnt.move(0, 0, clickType.isShiftClick() ? -0.0625 : -1); tnt.move(0, 0, clickType.isShiftClick() ? -0.0625 : -1);
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED)); }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
} }
} }
@@ -1,26 +1,24 @@
/* /*
* 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
* it under the terms of the GNU Affero General Public License as published by * GNU Affero General Public License as published by the Free Software Foundation, either version 3
* the Free Software Foundation, either version 3 of the License, or * 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
* but WITHOUT ANY WARRANTY; without even the implied warranty of * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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.
* along with this program. If not, see <https://www.gnu.org/licenses/>. * If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.simulator.gui.base; package de.steamwar.bausystem.features.simulator.gui.base;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
@@ -45,7 +43,8 @@ public abstract class SimulatorBaseGui {
} }
public final void open() { public final void open() {
if (!shouldOpen()) return; if (!shouldOpen())
return;
String newTitle = title(); String newTitle = title();
String originalTitle = player.getOpenInventory().getTitle(); String originalTitle = player.getOpenInventory().getTitle();
@@ -58,7 +57,6 @@ public abstract class SimulatorBaseGui {
setup(); setup();
if (player.getOpenInventory().getTopInventory() != inv) { if (player.getOpenInventory().getTopInventory() != inv) {
inventory.open(); inventory.open();
SimulatorWatcher.watch(player, simulator, this::open);
} }
if (Core.getVersion() > 19) { if (Core.getVersion() > 19) {
player.getOpenInventory().setTitle(title()); player.getOpenInventory().setTitle(title());
@@ -70,7 +68,6 @@ public abstract class SimulatorBaseGui {
} }
if (player.getOpenInventory().getTopInventory() == inv) { if (player.getOpenInventory().getTopInventory() == inv) {
inventory.open(); inventory.open();
SimulatorWatcher.watch(player, simulator, this::open);
} }
return; return;
} }
@@ -82,11 +79,7 @@ public abstract class SimulatorBaseGui {
return inv; return inv;
}); });
setup(); setup();
inventory.addCloseCallback(clickType -> {
SimulatorWatcher.watch(player, null, null);
});
SimulatorWatcher.watch(player, simulator, this::open);
if (simulator != null && simulator.getStabGenerator() != null) { if (simulator != null && simulator.getStabGenerator() != null) {
populateStabGenerator(); populateStabGenerator();
} else { } else {
@@ -98,7 +91,7 @@ public abstract class SimulatorBaseGui {
private void populateStabGenerator() { private void populateStabGenerator() {
inventory.setItem(22, new SWItem(Material.BARRIER, "§cCancel Stab Generator", click -> { inventory.setItem(22, new SWItem(Material.BARRIER, "§cCancel Stab Generator", click -> {
simulator.getStabGenerator().cancel(); simulator.getStabGenerator().cancel();
SimulatorWatcher.update(simulator); SimulatorRenderer.update(simulator);
})); }));
} }
@@ -18,11 +18,12 @@ import org.bukkit.util.Vector;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Predicate; import java.util.function.Predicate;
@Getter @Getter
public class RCursor { public abstract class Cursor {
private final World WORLD = Bukkit.getWorlds().get(0); private final World WORLD = Bukkit.getWorlds().get(0);
private final REntityServer targetServer; private final REntityServer targetServer;
@@ -30,7 +31,6 @@ public class RCursor {
private final Player owner; private final Player owner;
private final Material highlightMaterial; private final Material highlightMaterial;
private final ClickHandler onClickHandler;
private RFallingBlockEntity cursorEntity; private RFallingBlockEntity cursorEntity;
@@ -45,18 +45,17 @@ public class RCursor {
public RCursor(REntityServer targetServer, Player owner, Material highlightMaterial, Material cursorMaterial, List<CursorMode> allowedModes, ClickHandler onClickHandler) { protected Cursor(REntityServer targetServer, Player owner, Material highlightMaterial, Material cursorMaterial, List<CursorMode> allowedModes) {
this.targetServer = targetServer; this.targetServer = targetServer;
this.owner = owner; this.owner = owner;
this.highlightMaterial = highlightMaterial; this.highlightMaterial = highlightMaterial;
this.cursorMaterial = cursorMaterial; this.cursorMaterial = cursorMaterial;
this.allowedCursorModes = allowedModes; this.allowedCursorModes = allowedModes;
this.onClickHandler = onClickHandler;
cursorServer = new REntityServer(); cursorServer = new REntityServer();
cursorServer.addPlayer(owner); cursorServer.addPlayer(owner);
RCursorManager.getInstance().registerCursor(this); CursorManager.getInstance().registerCursor(this);
} }
public void render() { public void render() {
@@ -75,7 +74,8 @@ public class RCursor {
Material activeCursorMaterial = hitEntity == null ? cursorMaterial : highlightMaterial; Material activeCursorMaterial = hitEntity == null ? cursorMaterial : highlightMaterial;
CursorMode activeCursorMode = allowedCursorModes.stream().filter((mode) -> mode.isActive.test(owner)).min(Comparator.comparingInt(a -> a.priority)).orElse(CursorMode.BLOCK_ALIGNED); CursorMode activeCursorMode = allowedCursorModes.stream().filter((mode) -> mode.isActive.test(owner)).min(Comparator.comparingInt(a -> a.priority))
.orElse(CursorMode.BLOCK_ALIGNED);
Location activeCursorLocation = hitEntity == null ? activeCursorMode.positionTransform.apply(owner, rayTraceResult).toLocation(WORLD) Location activeCursorLocation = hitEntity == null ? activeCursorMode.positionTransform.apply(owner, rayTraceResult).toLocation(WORLD)
: new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ()).toLocation(WORLD); : new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ()).toLocation(WORLD);
@@ -110,16 +110,16 @@ public class RCursor {
visible = true; visible = true;
} }
void handleClick(Action action) { final void handleClick(Action action) {
if (!visible || cursorLocation == null) if (!visible)
return; return;
onClickHandler.handle(cursorLocation, isHittingEntity, action); onClick(Optional.ofNullable(this.cursorLocation), isHittingEntity, action);
} }
public void close() { public void close() {
cursorServer.close(); cursorServer.close();
RCursorManager.getInstance().unregisterCursor(this); CursorManager.getInstance().unregisterCursor(this);
} }
@AllArgsConstructor @AllArgsConstructor
@@ -155,7 +155,9 @@ public class RCursor {
} }
return pos; return pos;
}, (player) -> player.isSneaking()), BLOCK_ALIGNED(0, (player, rayTraceResult) -> { }, (player) -> player.isSneaking()),
BLOCK_ALIGNED(0, (player, rayTraceResult) -> {
Vector pos = rayTraceResult.getHitPosition(); Vector pos = rayTraceResult.getHitPosition();
BlockFace face = rayTraceResult.getHitBlockFace(); BlockFace face = rayTraceResult.getHitBlockFace();
@@ -197,7 +199,5 @@ public class RCursor {
private final Predicate<Player> isActive; private final Predicate<Player> isActive;
} }
public interface ClickHandler { public abstract void onClick(Optional<Location> cursorLocation, boolean didHitEntity, Action action);
void handle(Location cursorLocation, boolean didHitEntity, Action action);
}
} }
@@ -20,14 +20,14 @@ import java.util.Set;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@Linked @Linked
public class RCursorManager implements Listener { public class CursorManager implements Listener {
@Getter @Getter
private static RCursorManager instance; private static CursorManager instance;
private final Set<Player> calculationActive = new HashSet<>(); private final Set<Player> calculationActive = new HashSet<>();
private final Map<Player, List<RCursor>> activeCursors = new HashMap<>(); private final Map<Player, List<Cursor>> activeCursors = new HashMap<>();
public RCursorManager() { public CursorManager() {
if (instance == null) { if (instance == null) {
instance = this; instance = this;
} }
@@ -52,14 +52,14 @@ public class RCursorManager implements Listener {
TinyProtocol.instance.addFilter(positionLookPacketClass, function); TinyProtocol.instance.addFilter(positionLookPacketClass, function);
} }
void registerCursor(RCursor cursor) { void registerCursor(Cursor cursor) {
List<RCursor> cursorsOfPlayer = activeCursors.getOrDefault(cursor.getOwner(), new ArrayList<>()); List<Cursor> cursorsOfPlayer = activeCursors.getOrDefault(cursor.getOwner(), new ArrayList<>());
cursorsOfPlayer.add(cursor); cursorsOfPlayer.add(cursor);
activeCursors.put(cursor.getOwner(), cursorsOfPlayer); activeCursors.put(cursor.getOwner(), cursorsOfPlayer);
} }
void unregisterCursor(RCursor cursor) { void unregisterCursor(Cursor cursor) {
List<RCursor> cursorsOfPlayer = activeCursors.get(cursor.getOwner()); List<Cursor> cursorsOfPlayer = activeCursors.get(cursor.getOwner());
if (cursorsOfPlayer != null) { if (cursorsOfPlayer != null) {
cursorsOfPlayer.remove(cursor); cursorsOfPlayer.remove(cursor);
if (cursorsOfPlayer.isEmpty()) { if (cursorsOfPlayer.isEmpty()) {
@@ -69,9 +69,9 @@ public class RCursorManager implements Listener {
} }
private void closeCursorsOf(Player player) { private void closeCursorsOf(Player player) {
List<RCursor> cursorsOfPlayer = activeCursors.remove(player); List<Cursor> cursorsOfPlayer = activeCursors.remove(player);
if (cursorsOfPlayer != null) { if (cursorsOfPlayer != null) {
new ArrayList<>(cursorsOfPlayer).forEach(RCursor::close); new ArrayList<>(cursorsOfPlayer).forEach(Cursor::close);
} }
} }
@@ -90,10 +90,10 @@ public class RCursorManager implements Listener {
} }
} }
List<RCursor> cursors = activeCursors.get(player); List<Cursor> cursors = activeCursors.get(player);
if (cursors != null) { if (cursors != null) {
cursors.forEach(RCursor::render); cursors.forEach(Cursor::render);
} }
synchronized (calculationActive) { synchronized (calculationActive) {
@@ -105,7 +105,7 @@ public class RCursorManager implements Listener {
private void handlePlayerInteract(PlayerInteractEvent event) { private void handlePlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
List<RCursor> cursorsOfPlayer = activeCursors.get(player); List<Cursor> cursorsOfPlayer = activeCursors.get(player);
if (cursorsOfPlayer != null) { if (cursorsOfPlayer != null) {
cursorsOfPlayer.forEach(cursor -> cursor.handleClick(event.getAction())); cursorsOfPlayer.forEach(cursor -> cursor.handleClick(event.getAction()));
} }