Dieser Commit ist enthalten in:
Ursprung
b49c75d6bd
Commit
c050046820
@ -313,6 +313,7 @@ SIMULATOR_GUI_CREATE_SIM = §eCreate simulator
|
|||||||
SIMULATOR_GUI_CREATE_SIM_GUI = Create simulator
|
SIMULATOR_GUI_CREATE_SIM_GUI = Create simulator
|
||||||
SIMULATOR_NAME_ALREADY_EXISTS = §cSimulator already exists
|
SIMULATOR_NAME_ALREADY_EXISTS = §cSimulator already exists
|
||||||
SIMULATOR_NAME_INVALID = §cInvalid name
|
SIMULATOR_NAME_INVALID = §cInvalid name
|
||||||
|
SIMULATOR_ERROR_COPY = §cCopy failed
|
||||||
SIMULATOR_NOT_EXISTS = §cSimulator does not exist
|
SIMULATOR_NOT_EXISTS = §cSimulator does not exist
|
||||||
SIMULATOR_CREATE = §aSimulator created
|
SIMULATOR_CREATE = §aSimulator created
|
||||||
SIMULATOR_EDIT_LOCATION = §7Edit position
|
SIMULATOR_EDIT_LOCATION = §7Edit position
|
||||||
|
@ -305,6 +305,7 @@ SIMULATOR_GUI_CREATE_SIM = §eSimulator erstellen
|
|||||||
SIMULATOR_GUI_CREATE_SIM_GUI = Simulator erstellen
|
SIMULATOR_GUI_CREATE_SIM_GUI = Simulator erstellen
|
||||||
SIMULATOR_NAME_ALREADY_EXISTS = §cSimulator existiert bereits
|
SIMULATOR_NAME_ALREADY_EXISTS = §cSimulator existiert bereits
|
||||||
SIMULATOR_NAME_INVALID = §cUngültiger Name
|
SIMULATOR_NAME_INVALID = §cUngültiger Name
|
||||||
|
SIMULATOR_ERROR_COPY = §cFehler beim kopieren
|
||||||
SIMULATOR_NOT_EXISTS = §cSimulator existiert nicht
|
SIMULATOR_NOT_EXISTS = §cSimulator existiert nicht
|
||||||
SIMULATOR_CREATE = §aSimulator erstellt
|
SIMULATOR_CREATE = §aSimulator erstellt
|
||||||
SIMULATOR_EDIT_LOCATION = §7Editiere Positionen
|
SIMULATOR_EDIT_LOCATION = §7Editiere Positionen
|
||||||
|
@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class OrderUtils {
|
|
||||||
|
|
||||||
private final List<Material> activationOrder = new ArrayList<>();
|
|
||||||
|
|
||||||
private final Map<Material, String> nameMap = new HashMap<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
add(Material.REPEATER, "SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_REPEATER");
|
|
||||||
add(Material.OBSERVER, "SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_OBSERVER");
|
|
||||||
add(Material.COMPARATOR, "SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_COMPARATOR");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material next(Material material) {
|
|
||||||
int index = activationOrder.indexOf(material);
|
|
||||||
if (index == -1) {
|
|
||||||
return activationOrder.get(0);
|
|
||||||
}
|
|
||||||
if (index + 1 >= activationOrder.size()) {
|
|
||||||
return activationOrder.get(0);
|
|
||||||
}
|
|
||||||
return activationOrder.get(index + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material previous(Material material) {
|
|
||||||
int index = activationOrder.indexOf(material);
|
|
||||||
if (index == -1) {
|
|
||||||
return activationOrder.get(0);
|
|
||||||
}
|
|
||||||
if (index - 1 < 0) {
|
|
||||||
return activationOrder.get(activationOrder.size() - 1);
|
|
||||||
}
|
|
||||||
return activationOrder.get(index - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> orderList(Material material, Player player) {
|
|
||||||
List<String> lore = new ArrayList<>();
|
|
||||||
for (Material m : activationOrder) {
|
|
||||||
String element = BauSystem.MESSAGE.parse(name(m), player);
|
|
||||||
if (m == material) {
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ACTIVE", player, element));
|
|
||||||
} else {
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_INACTIVE", player, element));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int order(Material material) {
|
|
||||||
return activationOrder.indexOf(material);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String name(Material material) {
|
|
||||||
return nameMap.getOrDefault(material, "SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_UNKNOWN");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void add(Material material, String name) {
|
|
||||||
activationOrder.add(material);
|
|
||||||
nameMap.put(material, name);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2021 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.Permission;
|
|
||||||
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.inventory.ClickType;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class SimulatorBauGuiItem extends BauGuiItem {
|
|
||||||
|
|
||||||
public SimulatorBauGuiItem() {
|
|
||||||
super(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getItem(Player player) {
|
|
||||||
ItemStack itemStack = new SWItem(Material.BLAZE_ROD, BauSystem.MESSAGE.parse("SIMULATOR_GUI_ITEM_NAME", player)).getItemStack();
|
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
|
||||||
itemMeta.setCustomModelData(1);
|
|
||||||
itemStack.setItemMeta(itemMeta);
|
|
||||||
return itemStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean click(ClickType click, Player p) {
|
|
||||||
p.closeInventory();
|
|
||||||
p.performCommand("sim");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Permission permission() {
|
|
||||||
return Permission.WORLD;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of the SteamWar software.
|
* This file is a part of the SteamWar software.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2022 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 GNU Affero General Public License as published by
|
* 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
|
* the Free Software Foundation, either version 3 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 even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU 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. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator;
|
package de.steamwar.bausystem.features.simulator;
|
||||||
@ -22,105 +22,76 @@ package de.steamwar.bausystem.features.simulator;
|
|||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.SWUtils;
|
import de.steamwar.bausystem.SWUtils;
|
||||||
import de.steamwar.bausystem.features.simulator.gui.SimulatorSelectionGUI;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.utils.ItemUtils;
|
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;
|
||||||
import de.steamwar.command.TypeMapper;
|
import de.steamwar.command.TypeMapper;
|
||||||
import de.steamwar.command.TypeValidator;
|
import de.steamwar.command.TypeValidator;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
|
import de.steamwar.linkage.LinkedInstance;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class SimulatorCommand extends SWCommand {
|
public class SimulatorCommand extends SWCommand {
|
||||||
|
|
||||||
|
@LinkedInstance
|
||||||
|
public SimulatorCursor simulatorCursor;
|
||||||
|
|
||||||
public SimulatorCommand() {
|
public SimulatorCommand() {
|
||||||
super("simulator", "sim");
|
super("sim", "simulator");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(description = "SIMULATOR_HELP")
|
@Register(description = "SIMULATOR_HELP")
|
||||||
public void genericCommand(@Validator Player p) {
|
public void genericCommand(@Validator Player p) {
|
||||||
SimulatorCursor.hide(p, null);
|
|
||||||
SWUtils.giveItemToPlayer(p, SimulatorStorage.getWand(p));
|
SWUtils.giveItemToPlayer(p, SimulatorStorage.getWand(p));
|
||||||
|
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) {
|
||||||
ItemStack itemStack = p.getInventory().getItemInMainHand();
|
if (!SimulatorCursor.isSimulatorItem(p.getInventory().getItemInMainHand()) && !SimulatorCursor.isSimulatorItem(p.getInventory().getItemInOffHand())) {
|
||||||
if (!ItemUtils.isItem(itemStack, "simulator")) {
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_NO_SIM_IN_HAND", p);
|
BauSystem.MESSAGE.send("SIMULATOR_NO_SIM_IN_HAND", p);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SimulatorSelectionGUI.open(p, itemStack);
|
SimulatorStorage.openSimulatorSelector(p);
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "create", description = "SIMULATOR_CREATE_HELP")
|
|
||||||
public void create(@Validator Player p, String name) {
|
|
||||||
createSimulator(p, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean createSimulator(Player p, String name) {
|
|
||||||
if (SimulatorStorage.getSimulatorNames().contains(name)) {
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", p);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!name.matches("[a-zA-Z_0-9-]+")) {
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", p);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
SimulatorStorage.createNewSimulator(name);
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_CREATE", p);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "delete", description = "SIMULATOR_DELETE_HELP")
|
|
||||||
public void delete(@Validator Player p, @Mapper("simulators") String name) {
|
|
||||||
if (!SimulatorStorage.getSimulatorNames().contains(name)) {
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_NOT_EXISTS", p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SimulatorStorage.delete(name);
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_DELETED", p);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "start", description = "SIMULATOR_START_HELP")
|
|
||||||
public void start(@Validator Player p, @Mapper("simulators") String name) {
|
|
||||||
TNTSimulator tntSimulator = SimulatorStorage.getSimulator(name);
|
|
||||||
if (tntSimulator == null) {
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_NOT_EXISTS", p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tntSimulator.start(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "copy", description = "SIMULATOR_COPY_HELP")
|
@Register(value = "copy", description = "SIMULATOR_COPY_HELP")
|
||||||
public void copy(@Validator Player p, @Mapper("simulators") String toCopy, String name) {
|
public void copy(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator, String name) {
|
||||||
TNTSimulator tntSimulator = SimulatorStorage.getSimulator(toCopy);
|
|
||||||
if (tntSimulator == null) {
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_NOT_EXISTS", p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (SimulatorStorage.getSimulator(name) != null) {
|
if (SimulatorStorage.getSimulator(name) != null) {
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", p);
|
BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", p);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SimulatorStorage.copySimulator(tntSimulator, name);
|
if (!name.matches("[a-zA-Z_0-9-]+")) {
|
||||||
|
BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!SimulatorStorage.copy(simulator, name)) {
|
||||||
|
BauSystem.MESSAGE.send("SIMULATOR_ERROR_COPY", p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mapper("simulators")
|
@Register(value = "delete", description = "SIMULATOR_DELETE_HELP")
|
||||||
public TypeMapper<String> allSimulators() {
|
public void delete(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator) {
|
||||||
return new TypeMapper<String>() {
|
SimulatorStorage.delete(simulator);
|
||||||
|
BauSystem.MESSAGE.send("SIMULATOR_DELETED", p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register(value = "start", description = "SIMULATOR_START_HELP")
|
||||||
|
public void start(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator) {
|
||||||
|
SimulatorExecutor.run(simulator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ClassMapper(value = Simulator.class, local = true)
|
||||||
|
public TypeMapper<Simulator> allSimulators() {
|
||||||
|
return new TypeMapper<>() {
|
||||||
@Override
|
@Override
|
||||||
public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
public Simulator map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
||||||
if (SimulatorStorage.getSimulatorNames().contains(s)) {
|
return SimulatorStorage.getSimulator(s);
|
||||||
return s;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,108 +1,219 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of the SteamWar software.
|
* This file is a part of the SteamWar software.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2022 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 GNU Affero General Public License as published by
|
* 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
|
* the Free Software Foundation, either version 3 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 even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU 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. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator;
|
package de.steamwar.bausystem.features.simulator;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement;
|
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.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.ItemUtils;
|
||||||
import de.steamwar.bausystem.utils.RayTraceUtils;
|
import de.steamwar.bausystem.utils.RayTraceUtils;
|
||||||
|
import de.steamwar.entity.REntity;
|
||||||
import de.steamwar.entity.REntityServer;
|
import de.steamwar.entity.REntityServer;
|
||||||
import de.steamwar.entity.RFallingBlockEntity;
|
import de.steamwar.entity.RFallingBlockEntity;
|
||||||
import lombok.experimental.UtilityClass;
|
import de.steamwar.inventory.SWAnvilInv;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import de.steamwar.linkage.Linked;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.Player;
|
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 org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@UtilityClass
|
@Linked
|
||||||
public class SimulatorCursor {
|
public class SimulatorCursor implements Listener {
|
||||||
|
|
||||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
private final World WORLD = Bukkit.getWorlds().get(0);
|
||||||
private Map<Player, REntityServer> rEntityServerMap = new HashMap<>();
|
private Class<?> position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition");
|
||||||
|
private Class<?> look = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInLook");
|
||||||
|
private Class<?> positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook");
|
||||||
|
|
||||||
public void show(Player player, TNTSimulator tntSimulator, RayTraceUtils.RRayTraceResult result) {
|
private Map<Player, CursorType> cursorType = Collections.synchronizedMap(new HashMap<>());
|
||||||
if (true) return;
|
private Map<Player, REntityServer> cursors = Collections.synchronizedMap(new HashMap<>());
|
||||||
REntityServer cursor = rEntityServerMap.get(player);
|
|
||||||
|
|
||||||
if (cursor != null)
|
public static boolean isSimulatorItem(ItemStack itemStack) {
|
||||||
cursor.close();
|
return ItemUtils.isItem(itemStack, "simulator");
|
||||||
|
|
||||||
tntSimulator.show(player);
|
|
||||||
|
|
||||||
if (result == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (result.getHitEntity() != null) {
|
|
||||||
List<SimulatorElement> elements = tntSimulator.getEntity(result.getHitEntity());
|
|
||||||
|
|
||||||
cursor = new REntityServer();
|
|
||||||
RFallingBlockEntity entity = new RFallingBlockEntity(cursor, (elements.isEmpty() ? getPos(player, result) : elements.get(0).getPosition()).toLocation(WORLD), Material.TNT);
|
|
||||||
entity.setNoGravity(true);
|
|
||||||
entity.setGlowing(true);
|
|
||||||
cursor.addPlayer(player);
|
|
||||||
rEntityServerMap.put(player, cursor);
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("SIMULATOR_POSITION_EDIT", player, ChatMessageType.ACTION_BAR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SimulatorStorage.getSimulator(player.getInventory().getItemInOffHand()) != null && result.getHitPosition().distanceSquared(player.getLocation().toVector()) < 25) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor = new REntityServer();
|
|
||||||
RFallingBlockEntity entity = new RFallingBlockEntity(cursor, getPos(player, result).toLocation(WORLD), Material.TNT);
|
|
||||||
entity.setNoGravity(true);
|
|
||||||
cursor.addPlayer(player);
|
|
||||||
rEntityServerMap.put(player, cursor);
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("SIMULATOR_POSITION_ADD", player, ChatMessageType.ACTION_BAR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hide(Player player) {
|
public SimulatorCursor() {
|
||||||
REntityServer cursor = rEntityServerMap.get(player);
|
BiFunction<Player, Object, Object> function = (player, object) -> {
|
||||||
if (cursor == null) return;
|
calcCursor(player);
|
||||||
|
return object;
|
||||||
|
};
|
||||||
|
TinyProtocol.instance.addFilter(position, function);
|
||||||
|
TinyProtocol.instance.addFilter(look, function);
|
||||||
|
TinyProtocol.instance.addFilter(positionLook, function);
|
||||||
|
}
|
||||||
|
|
||||||
cursor.close();
|
@EventHandler
|
||||||
SimulatorStorage.getSimulatorNames().forEach(s -> {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
SimulatorStorage.getSimulator(s).hide(player);
|
calcCursor(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||||
|
calcCursor(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||||
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
|
calcCursor(event.getPlayer());
|
||||||
|
}, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
cursorType.remove(event.getPlayer());
|
||||||
|
cursors.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 synchronized void calcCursor(Player player) {
|
||||||
|
if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) {
|
||||||
|
if (removeCursor(player)) {
|
||||||
|
SimulatorWatcher.show(null, player);
|
||||||
|
SWUtils.sendToActionbar(player, "");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Simulator simulator = SimulatorStorage.getSimulator(player);
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
showCursor(player, rayTraceResult, simulator != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
public void hide(Player player, TNTSimulator tntSimulator) {
|
CursorType type = cursorType.getOrDefault(player, CursorType.TNT);
|
||||||
REntityServer cursor = rEntityServerMap.get(player);
|
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);
|
||||||
|
|
||||||
if (cursor != null)
|
Material material = hitEntity != null ? Material.GLASS : type.getMaterial();
|
||||||
cursor.close();
|
List<RFallingBlockEntity> entities = entityServer.getEntitiesByType(RFallingBlockEntity.class);
|
||||||
|
entities.removeIf(rFallingBlockEntity -> {
|
||||||
if (tntSimulator != null) {
|
if (rFallingBlockEntity.getMaterial() != material) {
|
||||||
tntSimulator.hide(player);
|
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");
|
||||||
}
|
}
|
||||||
rEntityServerMap.remove(player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector getPos(Player player, RayTraceUtils.RRayTraceResult result) {
|
public static Vector getPosTNT(Player player, RayTraceUtils.RRayTraceResult result) {
|
||||||
Vector pos = result.getHitPosition();
|
Vector pos = result.getHitPosition();
|
||||||
|
|
||||||
BlockFace face = result.getHitBlockFace();
|
BlockFace face = result.getHitBlockFace();
|
||||||
@ -141,4 +252,172 @@ public class SimulatorCursor {
|
|||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Vector getPosRedstoneBlock(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::getPosTNT, "TNT", vector -> new TNTElement(vector).add(new TNTPhase())),
|
||||||
|
REDSTONE_BLOCK(Material.REDSTONE_BLOCK, SimulatorCursor::getPosRedstoneBlock, "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase())),
|
||||||
|
;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
return TNT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
|
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(simulator);
|
||||||
|
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.getElements().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.getElements().add(group);
|
||||||
|
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
|
||||||
|
element.open(player, simulator, group, simulatorGui);
|
||||||
|
SimulatorWatcher.update(simulator);
|
||||||
|
calcCursor(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,124 +1,145 @@
|
|||||||
/*
|
/*
|
||||||
* This file is a part of the SteamWar software.
|
* This file is a part of the SteamWar software.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2022 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 GNU Affero General Public License as published by
|
* 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
|
* the Free Software Foundation, either version 3 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 even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU 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. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator;
|
package de.steamwar.bausystem.features.simulator;
|
||||||
|
|
||||||
|
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.tnt.TNTElement;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui;
|
||||||
|
import de.steamwar.bausystem.features.simulator.storage.SimFormatSimulatorLoader;
|
||||||
|
import de.steamwar.bausystem.features.simulator.storage.SimulatorFormatSimulatorLoader;
|
||||||
|
import de.steamwar.bausystem.features.simulator.storage.SimulatorSaver;
|
||||||
|
import de.steamwar.bausystem.features.simulator.storage.YAPIONFormatSimulatorLoader;
|
||||||
import de.steamwar.bausystem.utils.ItemUtils;
|
import de.steamwar.bausystem.utils.ItemUtils;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import de.steamwar.linkage.api.Disable;
|
|
||||||
import de.steamwar.linkage.api.Enable;
|
import de.steamwar.linkage.api.Enable;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import yapion.exceptions.YAPIONException;
|
|
||||||
import yapion.hierarchy.types.YAPIONArray;
|
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
|
||||||
import yapion.parser.YAPIONParser;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
// @Linked
|
@Linked
|
||||||
public class SimulatorStorage implements Enable, Disable {
|
public class SimulatorStorage implements Enable {
|
||||||
|
|
||||||
public static final World WORLD = Bukkit.getWorlds().get(0);
|
|
||||||
private static final File simulatorsDir = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "simulators");
|
|
||||||
|
|
||||||
|
public static final File simulatorsDir = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "simulators");
|
||||||
|
private static Map<String, Simulator> simulatorMap = new HashMap<>();
|
||||||
private static NamespacedKey simulatorSelection = SWUtils.getNamespaceKey("simulator_selection");
|
private static NamespacedKey simulatorSelection = SWUtils.getNamespaceKey("simulator_selection");
|
||||||
|
|
||||||
private static Map<String, TNTSimulator> tntSimulators = new HashMap<>();
|
public static Simulator getSimulator(Player player) {
|
||||||
|
Simulator simulator = getSimulator(player.getInventory().getItemInMainHand());
|
||||||
public static void createNewSimulator(String name) {
|
if (simulator != null) return simulator;
|
||||||
tntSimulators.put(name, new TNTSimulator());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<String> getSimulatorNames() {
|
|
||||||
return tntSimulators.keySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TNTSimulator getSimulator(String name) {
|
|
||||||
return tntSimulators.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TNTSimulator getSimulator(Player player) {
|
|
||||||
TNTSimulator current = getSimulator(player.getInventory().getItemInMainHand());
|
|
||||||
if (current != null) return current;
|
|
||||||
return getSimulator(player.getInventory().getItemInOffHand());
|
return getSimulator(player.getInventory().getItemInOffHand());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TNTSimulator getSimulator(ItemStack itemStack) {
|
public static Simulator getSimulator(ItemStack itemStack) {
|
||||||
if (itemStack == null) {
|
if (!SimulatorCursor.isSimulatorItem(itemStack)) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!ItemUtils.isItem(itemStack, "simulator")) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String selection = ItemUtils.getTag(itemStack, simulatorSelection);
|
String selection = ItemUtils.getTag(itemStack, simulatorSelection);
|
||||||
if (selection == null) {
|
if (selection == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return tntSimulators.get(selection);
|
return simulatorMap.get(selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setSimulator(Player player, ItemStack itemStack, TNTSimulator simulator) {
|
public static Simulator getSimulator(String name) {
|
||||||
for (Map.Entry<String, TNTSimulator> entry : tntSimulators.entrySet()) {
|
return simulatorMap.get(name);
|
||||||
if (entry.getValue() == simulator) {
|
}
|
||||||
ItemUtils.setTag(itemStack, simulatorSelection, entry.getKey());
|
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
public static void addSimulator(String name, Simulator simulator) {
|
||||||
itemMeta.setDisplayName(BauSystem.MESSAGE.parse("SIMULATOR_WAND_NAME_SELECTED", player, entry.getKey()));
|
simulatorMap.putIfAbsent(name, simulator);
|
||||||
itemStack.setItemMeta(itemMeta);
|
}
|
||||||
return;
|
|
||||||
|
@Override
|
||||||
|
public void enable() {
|
||||||
|
SimFormatSimulatorLoader simFormatSimulatorLoader = new SimFormatSimulatorLoader();
|
||||||
|
SimulatorFormatSimulatorLoader simulatorFormatSimulatorLoader = new SimulatorFormatSimulatorLoader();
|
||||||
|
YAPIONFormatSimulatorLoader yapionFormatSimulatorLoader = new YAPIONFormatSimulatorLoader();
|
||||||
|
|
||||||
|
for (File file : simulatorsDir.listFiles()) {
|
||||||
|
try {
|
||||||
|
List<Simulator> simulators = simFormatSimulatorLoader.load(file)
|
||||||
|
.orElse(null);
|
||||||
|
if (simulators != null) {
|
||||||
|
simulators.forEach(simulator -> {
|
||||||
|
simulatorMap.put(simulator.getName(), simulator);
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
List<Simulator> simulators = simulatorFormatSimulatorLoader.load(file)
|
||||||
|
.orElse(null);
|
||||||
|
if (simulators != null) {
|
||||||
|
simulators.forEach(simulator -> {
|
||||||
|
simulatorMap.put(simulator.getName(), simulator);
|
||||||
|
SimulatorSaver.saveSimulator(simulatorsDir, simulator);
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
List<Simulator> simulators = yapionFormatSimulatorLoader.load(file)
|
||||||
|
.orElse(null);
|
||||||
|
if (simulators != null) {
|
||||||
|
simulators.forEach(simulator -> {
|
||||||
|
simulatorMap.put(simulator.getName(), simulator);
|
||||||
|
SimulatorSaver.saveSimulator(simulatorsDir, simulator);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void delete(String name) {
|
public static void openSimulatorSelector(Player player) {
|
||||||
TNTSimulator tntSimulator = tntSimulators.remove(name);
|
SimulatorPageGui<Simulator> simulatorPageGui = new SimulatorPageGui<Simulator>(player, null, 6 * 9, new ArrayList<>(simulatorMap.values())) {
|
||||||
if (tntSimulator != null) {
|
@Override
|
||||||
tntSimulator.close();
|
public String baseTitle() {
|
||||||
}
|
return "Simulators";
|
||||||
new File(simulatorsDir, name + ".simulator").delete();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static void copySimulator(TNTSimulator tntSimulator, String name) {
|
@Override
|
||||||
tntSimulators.put(name, new TNTSimulator(tntSimulator.toYAPION()));
|
public SWItem convert(Simulator simulator) {
|
||||||
}
|
return simulator.toItem(player, clickType -> {
|
||||||
|
setSimulator(player, simulator);
|
||||||
public static void removeSimulator(ItemStack itemStack) {
|
player.closeInventory();
|
||||||
if (!ItemUtils.isItem(itemStack, "simulator")) {
|
});
|
||||||
return;
|
}
|
||||||
}
|
};
|
||||||
ItemUtils.setTag(itemStack, simulatorSelection, null);
|
simulatorPageGui.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack getWand(Player p) {
|
public static ItemStack getWand(Player p) {
|
||||||
@ -130,68 +151,48 @@ public class SimulatorStorage implements Enable, Disable {
|
|||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static void setSimulator(Player player, Simulator simulator) {
|
||||||
public void enable() {
|
ItemStack mainHand = player.getInventory().getItemInMainHand();
|
||||||
if (!simulatorsDir.exists()) {
|
ItemStack offHand = player.getInventory().getItemInOffHand();
|
||||||
simulatorsDir.mkdir();
|
ItemStack itemStack;
|
||||||
|
if (SimulatorCursor.isSimulatorItem(mainHand)) {
|
||||||
|
itemStack = mainHand;
|
||||||
|
} else if (SimulatorCursor.isSimulatorItem(offHand)) {
|
||||||
|
itemStack = offHand;
|
||||||
|
} else {
|
||||||
|
itemStack = null;
|
||||||
}
|
}
|
||||||
File[] files = simulatorsDir.listFiles();
|
if (itemStack == null) {
|
||||||
if (files == null) return;
|
|
||||||
|
|
||||||
for (File file : files) {
|
|
||||||
YAPIONObject yapionObject;
|
|
||||||
try {
|
|
||||||
yapionObject = YAPIONParser.parse(file);
|
|
||||||
} catch (YAPIONException | IOException e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (file.getName().endsWith(".yapion")) {
|
|
||||||
String name = file.getName().substring(0, file.getName().length() - 7);
|
|
||||||
try {
|
|
||||||
SteamwarUser steamwarUser = SteamwarUser.get(Integer.parseInt(name));
|
|
||||||
convert(file, steamwarUser);
|
|
||||||
} catch (Exception e) {
|
|
||||||
file.delete();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
String name = file.getName().substring(0, file.getName().length() - ".simulator".length());
|
|
||||||
tntSimulators.put(name, new TNTSimulator(yapionObject));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void convert(File file, SteamwarUser steamwarUser) {
|
|
||||||
YAPIONObject yapionObject;
|
|
||||||
try {
|
|
||||||
yapionObject = YAPIONParser.parse(file);
|
|
||||||
} catch (YAPIONException | IOException e) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
file.delete();
|
ItemUtils.setTag(itemStack, simulatorSelection, simulator.getName());
|
||||||
} catch (Exception e) {
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
e.printStackTrace();
|
itemMeta.setDisplayName(BauSystem.MESSAGE.parse("SIMULATOR_WAND_NAME_SELECTED", player, simulator.getName()));
|
||||||
}
|
itemStack.setItemMeta(itemMeta);
|
||||||
for (String s : yapionObject.getKeys()) {
|
|
||||||
String newName = steamwarUser.getUserName() + (s.isEmpty() ? "" : "_" + s);
|
|
||||||
YAPIONArray content = yapionObject.getArray(s);
|
|
||||||
if (content.isEmpty()) continue;
|
|
||||||
TNTSimulator tntSimulator = new TNTSimulator();
|
|
||||||
for (YAPIONObject element : content.streamObject().collect(Collectors.toList())) {
|
|
||||||
tntSimulator.getTntElementList().add(new TNTElement(element, null, tntSimulator.getEntityServer()));
|
|
||||||
}
|
|
||||||
tntSimulators.put(newName, tntSimulator);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static List<String> getSimulatorNames() {
|
||||||
public void disable() {
|
return new ArrayList<>(simulatorMap.keySet());
|
||||||
for (Map.Entry<String, TNTSimulator> entry : tntSimulators.entrySet()) {
|
}
|
||||||
try {
|
|
||||||
entry.getValue().toYAPION().toFile(new File(simulatorsDir, entry.getKey() + ".simulator"));
|
public static void delete(Simulator simulator) {
|
||||||
} catch (Exception e) {
|
simulatorMap.remove(simulator.getName());
|
||||||
e.printStackTrace();
|
new File(simulatorsDir, simulator.getName() + ".sim").delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean copy(Simulator simulator, String name) {
|
||||||
|
try {
|
||||||
|
File file = new File(simulatorsDir, name + ".sim");
|
||||||
|
Files.copy(new File(simulatorsDir, simulator.getName() + ".sim"), file);
|
||||||
|
new SimFormatSimulatorLoader().load(file).ifPresent(simulators -> {
|
||||||
|
simulators.forEach(sim -> {
|
||||||
|
simulatorMap.put(sim.getName(), sim);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,12 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2;
|
package de.steamwar.bausystem.features.simulator;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorElement;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement;
|
import de.steamwar.bausystem.features.simulator.storage.SimulatorSaver;
|
||||||
import de.steamwar.bausystem.features.simulator2.storage.SimulatorSaver;
|
|
||||||
import de.steamwar.bausystem.shared.Pair;
|
import de.steamwar.bausystem.shared.Pair;
|
||||||
import de.steamwar.entity.REntity;
|
import de.steamwar.entity.REntity;
|
||||||
import de.steamwar.entity.REntityServer;
|
import de.steamwar.entity.REntityServer;
|
@ -1,270 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.configplayer.Config;
|
|
||||||
import de.steamwar.bausystem.features.simulator.gui.TNTElementGUI;
|
|
||||||
import de.steamwar.bausystem.features.simulator.gui.TNTSimulatorGui;
|
|
||||||
import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement;
|
|
||||||
import de.steamwar.bausystem.features.simulator.tnt.TNTElement;
|
|
||||||
import de.steamwar.bausystem.features.simulator.tnt.TNTGroup;
|
|
||||||
import de.steamwar.bausystem.features.tracer.record.Recorder;
|
|
||||||
import de.steamwar.bausystem.features.tracer.record.SingleTraceRecorder;
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
|
||||||
import de.steamwar.bausystem.shared.Pair;
|
|
||||||
import de.steamwar.bausystem.utils.RayTraceUtils;
|
|
||||||
import de.steamwar.entity.REntity;
|
|
||||||
import de.steamwar.entity.REntityServer;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import yapion.hierarchy.types.YAPIONArray;
|
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
|
||||||
import yapion.hierarchy.types.YAPIONType;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class TNTSimulator {
|
|
||||||
|
|
||||||
private Set<Player> players = new HashSet<>();
|
|
||||||
private REntityServer entityServer = new REntityServer();
|
|
||||||
|
|
||||||
private Material material = Material.TNT;
|
|
||||||
|
|
||||||
private List<SimulatorElement> tntElementList = new ArrayList<>();
|
|
||||||
|
|
||||||
public TNTSimulator() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public TNTSimulator(YAPIONObject yapionObject) {
|
|
||||||
material = Material.valueOf(yapionObject.getStringOrDefault("material", Material.TNT.name()));
|
|
||||||
YAPIONArray yapionArray = yapionObject.getArrayOrDefault("tntElements", new YAPIONArray());
|
|
||||||
for (YAPIONObject element : yapionArray.streamObject().collect(Collectors.toList())) {
|
|
||||||
if (element.containsKey("elements", YAPIONType.ARRAY)) {
|
|
||||||
tntElementList.add(new TNTGroup(element, entityServer));
|
|
||||||
} else {
|
|
||||||
tntElementList.add(new TNTElement(element, null, entityServer));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public YAPIONObject toYAPION() {
|
|
||||||
YAPIONObject yapionObject = new YAPIONObject();
|
|
||||||
yapionObject.add("material", material.name());
|
|
||||||
YAPIONArray yapionArray = new YAPIONArray();
|
|
||||||
for (SimulatorElement element : tntElementList) {
|
|
||||||
yapionArray.add(element.toYAPION());
|
|
||||||
}
|
|
||||||
yapionObject.add("tntElements", yapionArray);
|
|
||||||
return yapionObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() {
|
|
||||||
entityServer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void show(Player player) {
|
|
||||||
if (!players.contains(player)) {
|
|
||||||
entityServer.addPlayer(player);
|
|
||||||
players.add(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hide(Player player) {
|
|
||||||
if (players.contains(player)) {
|
|
||||||
entityServer.removePlayer(player);
|
|
||||||
players.remove(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _hide(Player player) {
|
|
||||||
players.remove(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<REntity> getEntities() {
|
|
||||||
return tntElementList.stream().flatMap(element -> element.getEntities().stream()).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SimulatorElement> getEntity(REntity entity) {
|
|
||||||
List<SimulatorElement> tntSpawns = new ArrayList<>();
|
|
||||||
for (SimulatorElement spawn : tntElementList) {
|
|
||||||
spawn.getEntity(tntSpawns, entity);
|
|
||||||
}
|
|
||||||
return tntSpawns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
new ArrayList<>(tntElementList).forEach(this::remove);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(SimulatorElement element) {
|
|
||||||
if (element instanceof TNTElement) {
|
|
||||||
TNTElement tntElement = (TNTElement) element;
|
|
||||||
if (tntElement.hasParent()) {
|
|
||||||
tntElement.getParent().remove(tntElement);
|
|
||||||
if (tntElement.getParent().getElements().isEmpty()) {
|
|
||||||
remove(tntElement.getParent());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
element.remove(tntElement);
|
|
||||||
}
|
|
||||||
} else if (element instanceof TNTGroup) {
|
|
||||||
TNTGroup tntGroup = (TNTGroup) element;
|
|
||||||
tntGroup.getElements().forEach(tntElement -> {
|
|
||||||
tntElement.remove(tntElement);
|
|
||||||
});
|
|
||||||
tntGroup.getElements().clear();
|
|
||||||
}
|
|
||||||
element.close();
|
|
||||||
tntElementList.remove(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void change() {
|
|
||||||
tntElementList.forEach(simulatorElement -> {
|
|
||||||
simulatorElement.change();
|
|
||||||
if (simulatorElement instanceof TNTGroup) {
|
|
||||||
((TNTGroup) simulatorElement).getElements().forEach(SimulatorElement::change);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void edit(Player player, RayTraceUtils.RRayTraceResult result) {
|
|
||||||
if (result == null) {
|
|
||||||
TNTSimulatorGui.open(player, this, null, this::getTntElementList, null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SimulatorCursor.show(player, this, result);
|
|
||||||
|
|
||||||
if (result.getHitEntity() != null) {
|
|
||||||
List<SimulatorElement> elements = getEntity(result.getHitEntity());
|
|
||||||
if (elements.isEmpty()) return;
|
|
||||||
|
|
||||||
if (elements.size() == 1) {
|
|
||||||
TNTElementGUI.open(player, (TNTElement) elements.get(0), null);
|
|
||||||
} else {
|
|
||||||
List<TNTGroup> tntGroups = tntElementList.stream().filter(TNTGroup.class::isInstance).map(TNTGroup.class::cast).collect(Collectors.toList());
|
|
||||||
List<SimulatorElement> newElementList = new ArrayList<>();
|
|
||||||
for (TNTGroup tntGroup : tntGroups) {
|
|
||||||
if (new HashSet<>(elements).containsAll(tntGroup.getElements())) {
|
|
||||||
newElementList.add(tntGroup);
|
|
||||||
elements.removeAll(tntGroup.getElements());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
newElementList.addAll(elements);
|
|
||||||
if (newElementList.size() == 1) {
|
|
||||||
SimulatorElement element = newElementList.get(0);
|
|
||||||
if (element instanceof TNTGroup) {
|
|
||||||
TNTGroup tntGroup = (TNTGroup) element;
|
|
||||||
TNTSimulatorGui.open(player, null, tntGroup, () -> {
|
|
||||||
List<SimulatorElement> elementList = new ArrayList<>();
|
|
||||||
elementList.addAll(tntGroup.getElements());
|
|
||||||
return elementList;
|
|
||||||
}, null);
|
|
||||||
} else {
|
|
||||||
TNTElementGUI.open(player, (TNTElement) elements.get(0), null);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
TNTSimulatorGui.open(player, null, null, () -> newElementList, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SimulatorStorage.getSimulator(player.getInventory().getItemInOffHand()) != null && result.getHitPosition().distanceSquared(player.getLocation().toVector()) < 25) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
TNTElement tntElement = new TNTElement(SimulatorCursor.getPos(player, result), null, entityServer);
|
|
||||||
tntElementList.add(tntElement);
|
|
||||||
TNTElementGUI.open(player, tntElement, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start(Player p) {
|
|
||||||
Region region = Region.getRegion(p.getLocation());
|
|
||||||
Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result = new HashMap<>();
|
|
||||||
boolean regionFrozen = false;
|
|
||||||
for (SimulatorElement element : tntElementList) {
|
|
||||||
regionFrozen |= element.locations(result, region, p.getLocation());
|
|
||||||
}
|
|
||||||
if (regionFrozen) {
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_REGION_FROZEN", p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AtomicBoolean needsAutoTrace = new AtomicBoolean();
|
|
||||||
players.forEach(player -> {
|
|
||||||
boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false);
|
|
||||||
if (simulatorAutoTrace) {
|
|
||||||
needsAutoTrace.set(true);
|
|
||||||
player.performCommand("trace show");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (needsAutoTrace.get()) {
|
|
||||||
Recorder.INSTANCE.set(region, new SingleTraceRecorder(region));
|
|
||||||
}
|
|
||||||
|
|
||||||
AtomicInteger maxTick = new AtomicInteger(0);
|
|
||||||
Map<Integer, List<List<Pair<Runnable, Integer>>>> toSpawn = new HashMap<>();
|
|
||||||
result.forEach((integer, integerSetMap) -> {
|
|
||||||
List<Pair<Integer, Set<Pair<Runnable, Integer>>>> internal = new ArrayList<>();
|
|
||||||
integerSetMap.forEach((integer1, pairs) -> {
|
|
||||||
internal.add(new Pair<>(integer1, pairs));
|
|
||||||
});
|
|
||||||
internal.sort(Comparator.comparingInt(Pair::getKey));
|
|
||||||
|
|
||||||
toSpawn.put(integer, internal.stream().map(Pair::getValue).map(ArrayList::new).peek(Collections::shuffle).collect(Collectors.toList()));
|
|
||||||
|
|
||||||
if (maxTick.get() < integer) {
|
|
||||||
maxTick.set(integer);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
AtomicInteger currentTick = new AtomicInteger(0);
|
|
||||||
BauSystem.runTaskTimer(BauSystem.getInstance(), bukkitTask -> {
|
|
||||||
int tick = currentTick.get();
|
|
||||||
if (tick > maxTick.get()) bukkitTask.cancel();
|
|
||||||
currentTick.incrementAndGet();
|
|
||||||
|
|
||||||
List<List<Pair<Runnable, Integer>>> toSpawnInTick = toSpawn.get(tick);
|
|
||||||
if (toSpawnInTick == null) return;
|
|
||||||
toSpawnInTick.forEach(pairs -> {
|
|
||||||
AtomicBoolean hasSomeLeft = new AtomicBoolean(true);
|
|
||||||
while(hasSomeLeft.get()) {
|
|
||||||
hasSomeLeft.set(false);
|
|
||||||
pairs.forEach(pair -> {
|
|
||||||
if (pair.getValue() > 0) {
|
|
||||||
hasSomeLeft.set(true);
|
|
||||||
pair.getKey().run();
|
|
||||||
pair.setValue(pair.getValue() - 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, 1, 1);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,130 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.Permission;
|
|
||||||
import de.steamwar.bausystem.features.simulator.gui.SimulatorSelectionGUI;
|
|
||||||
import de.steamwar.bausystem.utils.ItemUtils;
|
|
||||||
import de.steamwar.bausystem.utils.RayTraceUtils;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.*;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
// @Linked
|
|
||||||
public class TNTSimulatorListener implements Listener {
|
|
||||||
|
|
||||||
private boolean permissionCheck(Player player) {
|
|
||||||
if (!Permission.hasPermission(player, Permission.WORLD)) {
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_NO_PERMS", player);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static RayTraceUtils.RRayTraceResult trace(Player player, Location to, TNTSimulator simulator) {
|
|
||||||
return RayTraceUtils.traceREntity(player, to, simulator.getEntities());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerMove(PlayerMoveEvent e) {
|
|
||||||
if (ItemUtils.isItem(e.getPlayer().getInventory().getItemInMainHand(), "simulator")) {
|
|
||||||
simulatorShowHide(e.getPlayer(), i -> null, PlayerInventory::getItemInMainHand, e.getTo());
|
|
||||||
} else {
|
|
||||||
SimulatorCursor.hide(e.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerItemHeld(PlayerItemHeldEvent e) {
|
|
||||||
simulatorShowHide(e.getPlayer(), i -> i.getItem(e.getPreviousSlot()), i -> i.getItem(e.getNewSlot()), e.getPlayer().getLocation());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerDropItem(PlayerDropItemEvent e) {
|
|
||||||
simulatorShowHide(e.getPlayer(), i -> e.getItemDrop().getItemStack(), i -> null, e.getPlayer().getLocation());
|
|
||||||
}
|
|
||||||
|
|
||||||
private TNTSimulator simulatorShowHide(Player player, Function<PlayerInventory, ItemStack> oldItemFunction, Function<PlayerInventory, ItemStack> newItemFunction, Location location) {
|
|
||||||
TNTSimulator oldSimulator = SimulatorStorage.getSimulator(oldItemFunction.apply(player.getInventory()));
|
|
||||||
SimulatorCursor.hide(player, oldSimulator);
|
|
||||||
|
|
||||||
TNTSimulator simulator = SimulatorStorage.getSimulator(newItemFunction.apply(player.getInventory()));
|
|
||||||
if (simulator == null) return null;
|
|
||||||
|
|
||||||
SimulatorCursor.show(player, simulator, trace(player, location, simulator));
|
|
||||||
return simulator;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
|
||||||
if (ItemUtils.isItem(e.getPlayer().getInventory().getItemInMainHand(), "simulator")) {
|
|
||||||
simulatorShowHide(e.getPlayer(), i -> null, PlayerInventory::getItemInMainHand, e.getPlayer().getLocation());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
||||||
SimulatorCursor.hide(event.getPlayer(), null);
|
|
||||||
SimulatorStorage.getSimulatorNames().forEach(s -> {
|
|
||||||
SimulatorStorage.getSimulator(s)._hide(event.getPlayer());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
|
||||||
if (!ItemUtils.isItem(event.getItem(), "simulator")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
if (!permissionCheck(event.getPlayer())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
TNTSimulator simulator = SimulatorStorage.getSimulator(event.getItem());
|
|
||||||
|
|
||||||
switch (event.getAction()) {
|
|
||||||
case LEFT_CLICK_BLOCK:
|
|
||||||
case LEFT_CLICK_AIR:
|
|
||||||
if (simulator == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
simulator.start(event.getPlayer());
|
|
||||||
break;
|
|
||||||
case RIGHT_CLICK_BLOCK:
|
|
||||||
case RIGHT_CLICK_AIR:
|
|
||||||
if (simulator == null) {
|
|
||||||
SimulatorSelectionGUI.open(event.getPlayer(), event.getItem());
|
|
||||||
} else {
|
|
||||||
simulator.edit(event.getPlayer(), trace(event.getPlayer(), event.getPlayer().getLocation(), simulator));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,9 +17,9 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.data;
|
package de.steamwar.bausystem.features.simulator.data;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction;
|
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
||||||
import de.steamwar.inventory.InvCallback;
|
import de.steamwar.inventory.InvCallback;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
@ -17,10 +17,10 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.data;
|
package de.steamwar.bausystem.features.simulator.data;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction;
|
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.inventory.InvCallback;
|
import de.steamwar.inventory.InvCallback;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
@ -17,9 +17,9 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.data;
|
package de.steamwar.bausystem.features.simulator.data;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction;
|
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
||||||
import de.steamwar.inventory.InvCallback;
|
import de.steamwar.inventory.InvCallback;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
@ -17,9 +17,9 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.data;
|
package de.steamwar.bausystem.features.simulator.data;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction;
|
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
@ -17,13 +17,13 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.data.redstone;
|
package de.steamwar.bausystem.features.simulator.data.redstone;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorElement;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.SimulatorRedstoneGui;
|
import de.steamwar.bausystem.features.simulator.gui.SimulatorRedstoneGui;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
@ -18,10 +18,10 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.data.redstone;
|
package de.steamwar.bausystem.features.simulator.data.redstone;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||||
import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction;
|
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
@ -17,13 +17,13 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.data.tnt;
|
package de.steamwar.bausystem.features.simulator.data.tnt;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorElement;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.SimulatorTNTGui;
|
import de.steamwar.bausystem.features.simulator.gui.SimulatorTNTGui;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.inventory.InvCallback;
|
import de.steamwar.inventory.InvCallback;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
@ -17,10 +17,10 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.data.tnt;
|
package de.steamwar.bausystem.features.simulator.data.tnt;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||||
import de.steamwar.bausystem.features.simulator2.execute.SimulatorAction;
|
import de.steamwar.bausystem.features.simulator.execute.SimulatorAction;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
@ -17,7 +17,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.execute;
|
package de.steamwar.bausystem.features.simulator.execute;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
@ -17,10 +17,10 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.execute;
|
package de.steamwar.bausystem.features.simulator.execute;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.gui;
|
|
||||||
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class ItemUtils {
|
|
||||||
|
|
||||||
public static SWItem unique(SWItem swItem) {
|
|
||||||
ItemMeta itemMeta = swItem.getItemMeta();
|
|
||||||
itemMeta.getPersistentDataContainer().set(NamespacedKey.minecraft(UUID.randomUUID().toString()), PersistentDataType.INTEGER, 0);
|
|
||||||
swItem.setItemMeta(itemMeta);
|
|
||||||
return swItem;
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,14 +17,14 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.gui;
|
package de.steamwar.bausystem.features.simulator.gui;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
|
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorElement;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui;
|
||||||
import de.steamwar.inventory.InvCallback;
|
import de.steamwar.inventory.InvCallback;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
@ -17,14 +17,14 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.gui;
|
package de.steamwar.bausystem.features.simulator.gui;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
|
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorElement;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -17,12 +17,12 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.gui;
|
package de.steamwar.bausystem.features.simulator.gui;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
|
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -17,15 +17,13 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.gui;
|
package de.steamwar.bausystem.features.simulator.gui;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
|
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorElement;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -17,12 +17,12 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.gui;
|
package de.steamwar.bausystem.features.simulator.gui;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
|
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -17,15 +17,15 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.gui;
|
package de.steamwar.bausystem.features.simulator.gui;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
|
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement;
|
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase;
|
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorScrollGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -17,13 +17,13 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.gui;
|
package de.steamwar.bausystem.features.simulator.gui;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
|
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement;
|
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase;
|
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -17,12 +17,12 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.gui;
|
package de.steamwar.bausystem.features.simulator.gui;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
|
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement;
|
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.gui;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.features.simulator.SimulatorCommand;
|
|
||||||
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
|
|
||||||
import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import de.steamwar.inventory.SWListInv;
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class SimulatorSelectionGUI {
|
|
||||||
|
|
||||||
public void open(Player player, ItemStack hand) {
|
|
||||||
List<SWListInv.SWListEntry<TNTSimulator>> swListEntryList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (String name : SimulatorStorage.getSimulatorNames()) {
|
|
||||||
TNTSimulator simulator = SimulatorStorage.getSimulator(name);
|
|
||||||
SWItem swItem = new SWItem(simulator.getMaterial(), "§f" + name, new ArrayList<>(), false, null);
|
|
||||||
swListEntryList.add(new SWListInv.SWListEntry<>(swItem, simulator));
|
|
||||||
}
|
|
||||||
|
|
||||||
SWListInv<TNTSimulator> inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_GUI_SELECT_SIM", player), false, swListEntryList, (clickType, tntSimulator) -> {
|
|
||||||
TNTSimulator current = SimulatorStorage.getSimulator(hand);
|
|
||||||
if (current != null) {
|
|
||||||
current.hide(player);
|
|
||||||
}
|
|
||||||
SimulatorStorage.setSimulator(player, hand, tntSimulator);
|
|
||||||
player.getInventory().setItemInMainHand(hand);
|
|
||||||
player.closeInventory();
|
|
||||||
});
|
|
||||||
|
|
||||||
inv.setItem(49, new SWItem(Material.NAME_TAG, BauSystem.MESSAGE.parse("SIMULATOR_GUI_CREATE_SIM", player), clickType -> {
|
|
||||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("SIMULATOR_GUI_CREATE_SIM_GUI", player), "");
|
|
||||||
swAnvilInv.setItem(Material.PAPER);
|
|
||||||
swAnvilInv.setCallback(s -> {
|
|
||||||
player.closeInventory();
|
|
||||||
if (SimulatorCommand.createSimulator(player, s)) {
|
|
||||||
TNTSimulator current = SimulatorStorage.getSimulator(hand);
|
|
||||||
if (current != null) {
|
|
||||||
current.hide(player);
|
|
||||||
}
|
|
||||||
TNTSimulator tntSimulator = SimulatorStorage.getSimulator(s);
|
|
||||||
SimulatorStorage.setSimulator(player, hand, tntSimulator);
|
|
||||||
player.getInventory().setItemInMainHand(hand);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
swAnvilInv.open();
|
|
||||||
}));
|
|
||||||
|
|
||||||
inv.open();
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,11 +17,11 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.gui;
|
package de.steamwar.bausystem.features.simulator.gui;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
|
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -17,15 +17,15 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.gui;
|
package de.steamwar.bausystem.features.simulator.gui;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
|
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorScrollGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -17,14 +17,14 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.gui;
|
package de.steamwar.bausystem.features.simulator.gui;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
|
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
@ -17,12 +17,12 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.gui;
|
package de.steamwar.bausystem.features.simulator.gui;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
|
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -1,390 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.gui;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.features.simulator.OrderUtils;
|
|
||||||
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
|
|
||||||
import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
|
||||||
import de.steamwar.bausystem.features.simulator.gui.components.ChangeMaterial;
|
|
||||||
import de.steamwar.bausystem.features.simulator.gui.components.ChangePosition;
|
|
||||||
import de.steamwar.bausystem.features.simulator.gui.components.Disabled;
|
|
||||||
import de.steamwar.bausystem.features.simulator.tnt.TNTElement;
|
|
||||||
import de.steamwar.bausystem.features.simulator.tnt.TNTGroup;
|
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
|
||||||
import de.steamwar.inventory.SWInventory;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.inventory.ClickType;
|
|
||||||
import org.bukkit.util.Consumer;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static de.steamwar.bausystem.features.simulator.gui.ItemUtils.unique;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class TNTElementGUI {
|
|
||||||
|
|
||||||
private SWInventory open(Player player, String name) {
|
|
||||||
SWInventory inv = new SWInventory(player, 45, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_GUI_NAME", player, name));
|
|
||||||
SWItem gray = new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§f", clickType -> {});
|
|
||||||
for (int i = 0; i < 9; i++) {
|
|
||||||
inv.setItem(i, gray);
|
|
||||||
inv.setItem(i + 36, gray);
|
|
||||||
}
|
|
||||||
return inv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void open(Player player, TNTElement tntElement, Runnable back) {
|
|
||||||
SWInventory inv = open(player, "");
|
|
||||||
if (back != null) {
|
|
||||||
inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run()));
|
|
||||||
}
|
|
||||||
|
|
||||||
TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player);
|
|
||||||
Runnable editObserver = () -> {
|
|
||||||
List<String> locationLore = new ArrayList<>();
|
|
||||||
locationLore.add("");
|
|
||||||
locationLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, tntElement.getPosition().getX()));
|
|
||||||
locationLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, tntElement.getPosition().getY()));
|
|
||||||
locationLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, tntElement.getPosition().getZ()));
|
|
||||||
inv.setItem(20, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_LOCATION", player), locationLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
editLocation(player, tntElement, () -> open(player, tntElement, back));
|
|
||||||
}));
|
|
||||||
|
|
||||||
List<String> propertiesLore = new ArrayList<>();
|
|
||||||
propertiesLore.add("");
|
|
||||||
propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_COUNT", player, tntElement.getCount()));
|
|
||||||
propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, tntElement.getTickOffset()));
|
|
||||||
propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_FUSE", player, tntElement.getFuseTicks()));
|
|
||||||
propertiesLore.add("");
|
|
||||||
propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_X", player, active(player, tntElement.isXVelocity())));
|
|
||||||
propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Y", player, active(player, tntElement.isYVelocity())));
|
|
||||||
propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Z", player, active(player, tntElement.isZVelocity())));
|
|
||||||
inv.setItem(22, new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_PROPERTIES", player), propertiesLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
editProperties(player, tntElement, () -> open(player, tntElement, back));
|
|
||||||
}));
|
|
||||||
|
|
||||||
List<String> otherLore = new ArrayList<>();
|
|
||||||
otherLore.add("");
|
|
||||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ACTIVATED_WITH", player, BauSystem.MESSAGE.parse(OrderUtils.name(tntElement.getOrder()), player)));
|
|
||||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME_LORE", player, tntElement.getMaterial().name()));
|
|
||||||
if (tntElement.isDisabled()) {
|
|
||||||
otherLore.add("");
|
|
||||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", player));
|
|
||||||
}
|
|
||||||
inv.setItem(24, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_OTHER", player), otherLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
editOther(player, tntElement, () -> open(player, tntElement, back));
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Delete tnt
|
|
||||||
inv.setItem(44, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_REMOVE_TNT", player), clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntSimulator.remove(tntElement);
|
|
||||||
player.closeInventory();
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
editObserver.run();
|
|
||||||
tntElement.register(editObserver, player::closeInventory);
|
|
||||||
inv.addCloseRunnable(() -> {
|
|
||||||
tntElement.unregister(editObserver);
|
|
||||||
});
|
|
||||||
|
|
||||||
inv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void editLocation(Player player, TNTElement tntElement, Runnable back) {
|
|
||||||
SWInventory inv = open(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_EDIT_LOCATION", player));
|
|
||||||
if (back != null) {
|
|
||||||
inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run()));
|
|
||||||
}
|
|
||||||
|
|
||||||
Runnable editObserver = () -> {
|
|
||||||
ChangePosition.show(inv, player, tntElement, vectorUnaryOperator -> {
|
|
||||||
if (tntElement.getParent() == null) {
|
|
||||||
tntElement.setPosition(vectorUnaryOperator.apply(tntElement.getPosition()));
|
|
||||||
} else {
|
|
||||||
tntElement.setPosition(vectorUnaryOperator.apply(tntElement.getPosition()).subtract(tntElement.getParent().getPosition()));
|
|
||||||
}
|
|
||||||
}, () -> editLocation(player, tntElement, back));
|
|
||||||
|
|
||||||
// Alignment
|
|
||||||
inv.setItem(23, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_NEGATIVE_Z", player), clickType -> { // Z negative
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.align(new Vector(0, 0, 0.49));
|
|
||||||
tntElement.change();
|
|
||||||
}));
|
|
||||||
inv.setItem(25, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_POSITIVE_Z", player), clickType -> { // Z positive
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.align(new Vector(0, 0, 0.51));
|
|
||||||
tntElement.change();
|
|
||||||
}));
|
|
||||||
inv.setItem(15, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_POSITIVE_X", player), clickType -> { // X positive
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.align(new Vector(0.51, 0, 0));
|
|
||||||
tntElement.change();
|
|
||||||
}));
|
|
||||||
inv.setItem(33, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_NEGATIVE_X", player), clickType -> { // X negative
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.align(new Vector(0.49, 0, 0));
|
|
||||||
tntElement.change();
|
|
||||||
}));
|
|
||||||
inv.setItem(24, new SWItem(Material.SUNFLOWER, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_CENTER", player), clickType -> { // CENTER
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.align(new Vector(0.5, 0, 0.5));
|
|
||||||
tntElement.change();
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
editObserver.run();
|
|
||||||
tntElement.register(editObserver, player::closeInventory);
|
|
||||||
inv.addCloseRunnable(() -> {
|
|
||||||
tntElement.unregister(editObserver);
|
|
||||||
});
|
|
||||||
|
|
||||||
inv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void editProperties(Player player, TNTElement tntElement, Runnable back) {
|
|
||||||
SWInventory inv = open(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_EDIT_PROPERTIES", player));
|
|
||||||
if (back != null) {
|
|
||||||
inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run()));
|
|
||||||
}
|
|
||||||
|
|
||||||
String plusOneName = BauSystem.MESSAGE.parse("SIMULATOR_PLUS_ONE", player);
|
|
||||||
String minusOneName = BauSystem.MESSAGE.parse("SIMULATOR_MINUS_ONE", player);
|
|
||||||
List<String> plusOneFiveShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_FIVE_SHIFT", player));
|
|
||||||
List<String> minusOneFiveShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_FIVE_SHIFT", player));
|
|
||||||
List<String> lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player));
|
|
||||||
|
|
||||||
TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player);
|
|
||||||
Runnable editObserver = () -> {
|
|
||||||
// Change Count of spawned TNT
|
|
||||||
inv.setItem(10, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.setCount(tntElement.getCount() + ((clickType.isShiftClick()) ? 5 : 1));
|
|
||||||
tntElement.change();
|
|
||||||
})));
|
|
||||||
SWItem countItem = new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_COUNT", player, tntElement.getCount()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_COUNT_ANVIL_GUI_NAME", player), tntElement.getCount(), c -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.setCount(c);
|
|
||||||
tntElement.change();
|
|
||||||
editProperties(player, tntElement, back);
|
|
||||||
}, () -> editProperties(player, tntElement, back)));
|
|
||||||
countItem.getItemStack().setAmount(tntElement.getCount());
|
|
||||||
inv.setItem(19, countItem);
|
|
||||||
inv.setItem(28, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.setCount(tntElement.getCount() - ((clickType.isShiftClick()) ? 5 : 1));
|
|
||||||
tntElement.change();
|
|
||||||
})));
|
|
||||||
|
|
||||||
// Change TickOffset
|
|
||||||
inv.setItem(11, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.setTickOffset(tntElement.getOwnTickOffset() + (clickType.isShiftClick() ? 5 : 1));
|
|
||||||
tntElement.change();
|
|
||||||
})));
|
|
||||||
SWItem tickItem = new SWItem(SWItem.getMaterial("DIODE"), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, tntElement.getTickOffset()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK_ANVIL_GUI_NAME", player), tntElement.getTickOffset(), tick -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.setTickOffset(tick - tntElement.getParentTickOffset());
|
|
||||||
tntElement.change();
|
|
||||||
editProperties(player, tntElement, back);
|
|
||||||
}, () -> editProperties(player, tntElement, back)));
|
|
||||||
tickItem.getItemStack().setAmount(Math.max(tntElement.getTickOffset(), 1));
|
|
||||||
inv.setItem(20, tickItem);
|
|
||||||
inv.setItem(29, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.setTickOffset(tntElement.getOwnTickOffset() - (clickType.isShiftClick() ? 5 : 1));
|
|
||||||
tntElement.change();
|
|
||||||
})));
|
|
||||||
|
|
||||||
// Change FuseTicks
|
|
||||||
inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.setFuseTicks(tntElement.getFuseTicks() + (clickType.isShiftClick() ? 5 : 1));
|
|
||||||
tntElement.change();
|
|
||||||
})));
|
|
||||||
SWItem fuseTickItem = new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_FUSE", player, tntElement.getFuseTicks()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_FUSE_ANVIL_GUI_NAME", player), tntElement.getFuseTicks(), tick -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.setFuseTicks(tick);
|
|
||||||
tntElement.change();
|
|
||||||
editProperties(player, tntElement, back);
|
|
||||||
}, () -> editProperties(player, tntElement, back)));
|
|
||||||
fuseTickItem.getItemStack().setAmount(Math.max(tntElement.getFuseTicks(), 1));
|
|
||||||
inv.setItem(21, fuseTickItem);
|
|
||||||
inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.setFuseTicks(tntElement.getFuseTicks() - (clickType.isShiftClick() ? 5 : 1));
|
|
||||||
tntElement.change();
|
|
||||||
})));
|
|
||||||
|
|
||||||
// Velocity Settings
|
|
||||||
inv.setItem(24, Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_NAME", player), clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
if (tntElement.isXVelocity() || tntElement.isYVelocity() || tntElement.isZVelocity()) {
|
|
||||||
tntElement.setXVelocity(false);
|
|
||||||
tntElement.setYVelocity(false);
|
|
||||||
tntElement.setZVelocity(false);
|
|
||||||
} else {
|
|
||||||
tntElement.setXVelocity(true);
|
|
||||||
tntElement.setYVelocity(true);
|
|
||||||
tntElement.setZVelocity(true);
|
|
||||||
}
|
|
||||||
tntElement.change();
|
|
||||||
});
|
|
||||||
inv.setItem(32, new SWItem(getWool(tntElement.isXVelocity()), getColor(tntElement.isXVelocity()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_X", player, active(player, tntElement.isXVelocity())), clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.setXVelocity(!tntElement.isXVelocity());
|
|
||||||
tntElement.change();
|
|
||||||
}));
|
|
||||||
inv.setItem(15, new SWItem(getWool(tntElement.isYVelocity()), getColor(tntElement.isYVelocity()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Y", player, active(player, tntElement.isYVelocity())), clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.setYVelocity(!tntElement.isYVelocity());
|
|
||||||
tntElement.change();
|
|
||||||
}));
|
|
||||||
inv.setItem(34, new SWItem(getWool(tntElement.isZVelocity()), getColor(tntElement.isZVelocity()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Z", player, active(player, tntElement.isZVelocity())), clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntElement.setZVelocity(!tntElement.isZVelocity());
|
|
||||||
tntElement.change();
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
editObserver.run();
|
|
||||||
tntElement.register(editObserver, player::closeInventory);
|
|
||||||
inv.addCloseRunnable(() -> {
|
|
||||||
tntElement.unregister(editObserver);
|
|
||||||
});
|
|
||||||
|
|
||||||
inv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void editOther(Player player, TNTElement tntElement, Runnable back) {
|
|
||||||
SWInventory inv = open(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_EDIT_OTHER", player));
|
|
||||||
if (back != null) {
|
|
||||||
inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run()));
|
|
||||||
}
|
|
||||||
|
|
||||||
TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player);
|
|
||||||
Runnable editObserver = () -> {
|
|
||||||
inv.setItem(19, new SWItem(tntElement.getOrder(), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ACTIVATED_NAME", player), OrderUtils.orderList(tntElement.getOrder(), player), false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
if (clickType.isShiftClick()) {
|
|
||||||
tntElement.setOrder(OrderUtils.previous(tntElement.getOrder()));
|
|
||||||
} else {
|
|
||||||
tntElement.setOrder(OrderUtils.next(tntElement.getOrder()));
|
|
||||||
}
|
|
||||||
tntElement.change();
|
|
||||||
}));
|
|
||||||
|
|
||||||
ChangeMaterial.show(inv, player, 21, tntElement, Material.BARREL, () -> editOther(player, tntElement, back));
|
|
||||||
Disabled.show(inv, player, 22, tntSimulator, tntElement);
|
|
||||||
|
|
||||||
if (!tntElement.hasParent()) {
|
|
||||||
inv.setItem(24, new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ADD_IGNITION_PHASE", player), Arrays.asList(), false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
// Create TNTGroup
|
|
||||||
tntSimulator.getTntElementList().remove(tntElement);
|
|
||||||
Vector vector = tntElement.getOwnPosition().clone();
|
|
||||||
int tickOffset = tntElement.getOwnTickOffset();
|
|
||||||
TNTGroup tntGroup = new TNTGroup(vector);
|
|
||||||
tntGroup.setTickOffset(tickOffset);
|
|
||||||
tntGroup.add(tntElement);
|
|
||||||
tntElement.setTickOffset(0);
|
|
||||||
tntElement.setPosition(new Vector(0, 0, 0));
|
|
||||||
tntSimulator.getTntElementList().add(tntGroup);
|
|
||||||
|
|
||||||
// Add new TNT
|
|
||||||
TNTElement newElement = new TNTElement(new Vector(0, 0, 0), tntGroup, tntSimulator.getEntityServer());
|
|
||||||
newElement.setTickOffset(1);
|
|
||||||
tntGroup.add(newElement);
|
|
||||||
|
|
||||||
tntElement.change();
|
|
||||||
open(player, newElement, () -> TNTSimulatorGui.open(player, null, tntGroup, () -> new ArrayList<>(tntGroup.getElements()), () -> {
|
|
||||||
TNTSimulatorGui.open(player, tntSimulator, null, () -> new ArrayList<>(tntSimulator.getTntElementList()), null);
|
|
||||||
}));
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
inv.setItem(24, new SWItem());
|
|
||||||
}
|
|
||||||
|
|
||||||
inv.setItem(25, new SWItem(Material.DISPENSER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ADD_TNT", player), clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
Vector vector = tntElement.getOwnPosition().clone();
|
|
||||||
TNTElement newElement = new TNTElement(vector, null, tntSimulator.getEntityServer());
|
|
||||||
if (tntElement.hasParent()) {
|
|
||||||
newElement.setTickOffset(tntElement.getOwnTickOffset() + 1);
|
|
||||||
tntElement.getParent().add(newElement);
|
|
||||||
open(player, newElement, () -> TNTSimulatorGui.open(player, null, tntElement.getParent(), () -> new ArrayList<>(tntElement.getParent().getElements()), () -> {
|
|
||||||
TNTSimulatorGui.open(player, tntSimulator, null, () -> new ArrayList<>(tntSimulator.getTntElementList()), null);
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
tntSimulator.getTntElementList().add(newElement);
|
|
||||||
open(player, newElement, () -> TNTSimulatorGui.open(player, tntSimulator, null, tntSimulator::getTntElementList, null));
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Delete tnt
|
|
||||||
inv.setItem(44, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_REMOVE_TNT", player), clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntSimulator.remove(tntElement);
|
|
||||||
player.closeInventory();
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
editObserver.run();
|
|
||||||
tntElement.register(editObserver, player::closeInventory);
|
|
||||||
inv.addCloseRunnable(() -> {
|
|
||||||
tntElement.unregister(editObserver);
|
|
||||||
});
|
|
||||||
|
|
||||||
inv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String active(Player p, boolean active) {
|
|
||||||
return active ? BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_ON", p) : BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_OFF", p);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Material getWool(boolean b) {
|
|
||||||
return b ? Material.LIME_WOOL : Material.RED_WOOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte getColor(boolean b) {
|
|
||||||
return (byte) (b ? 10 : 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void changeCount(Player player, String name, int defaultValue, Consumer<Integer> result, Runnable failure) {
|
|
||||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, name, defaultValue + "");
|
|
||||||
swAnvilInv.setItem(Material.PAPER);
|
|
||||||
swAnvilInv.setCallback(s -> {
|
|
||||||
try {
|
|
||||||
result.accept(Integer.parseInt(s));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
failure.run();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
swAnvilInv.open();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,198 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.gui;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
|
|
||||||
import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
|
||||||
import de.steamwar.bausystem.features.simulator.gui.components.ChangeMaterial;
|
|
||||||
import de.steamwar.bausystem.features.simulator.gui.components.ChangePosition;
|
|
||||||
import de.steamwar.bausystem.features.simulator.gui.components.Disabled;
|
|
||||||
import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement;
|
|
||||||
import de.steamwar.bausystem.features.simulator.tnt.TNTElement;
|
|
||||||
import de.steamwar.bausystem.features.simulator.tnt.TNTGroup;
|
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
|
||||||
import de.steamwar.inventory.SWInventory;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.inventory.ClickType;
|
|
||||||
import org.bukkit.util.Consumer;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.UnaryOperator;
|
|
||||||
|
|
||||||
import static de.steamwar.bausystem.features.simulator.gui.ItemUtils.unique;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class TNTGroupEditGUI {
|
|
||||||
|
|
||||||
private static final Vector X_VECTOR = new Vector(0.0625, 0, 0);
|
|
||||||
private static final Vector Y_VECTOR = new Vector(0, 0.0625, 0);
|
|
||||||
private static final Vector Z_VECTOR = new Vector(0, 0, 0.0625);
|
|
||||||
|
|
||||||
private static final Vector FX_VECTOR = new Vector(1, 0, 0);
|
|
||||||
private static final Vector FY_VECTOR = new Vector(0, 1, 0);
|
|
||||||
private static final Vector FZ_VECTOR = new Vector(0, 0, 1);
|
|
||||||
|
|
||||||
public void open(Player player, TNTSimulator tntSimulator, List<SimulatorElement> simulatorElements, Runnable back) {
|
|
||||||
SWInventory inv = new SWInventory(player, 45, BauSystem.MESSAGE.parse("SIMULATOR_MOVE_ALL_GUI_NAME", player));
|
|
||||||
SWItem gray = new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§f", clickType -> {});
|
|
||||||
for (int i = 0; i < 9; i++) {
|
|
||||||
inv.setItem(i, gray);
|
|
||||||
inv.setItem(i + 36, gray);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (back != null) {
|
|
||||||
inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run()));
|
|
||||||
}
|
|
||||||
|
|
||||||
String plusOneName = BauSystem.MESSAGE.parse("SIMULATOR_PLUS_ONE", player);
|
|
||||||
String minusOneName = BauSystem.MESSAGE.parse("SIMULATOR_MINUS_ONE", player);
|
|
||||||
List<String> plusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_PIXEL_SHIFT", player));
|
|
||||||
List<String> minusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_PIXEL_SHIFT", player));
|
|
||||||
List<String> lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player));
|
|
||||||
|
|
||||||
Vector vector = simulatorElements.get(0).getPosition();
|
|
||||||
|
|
||||||
// X Position
|
|
||||||
inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
moveAll(simulatorElements, clickType.isShiftClick() ? X_VECTOR : FX_VECTOR);
|
|
||||||
tntSimulator.change();
|
|
||||||
})));
|
|
||||||
inv.setItem(21, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, vector.getX()), lore, false, clickType -> {}));
|
|
||||||
inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
moveAll(simulatorElements, (clickType.isShiftClick() ? X_VECTOR : FX_VECTOR).clone().multiply(-1));
|
|
||||||
tntSimulator.change();
|
|
||||||
})));
|
|
||||||
|
|
||||||
// Y Position
|
|
||||||
inv.setItem(13, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
moveAll(simulatorElements, clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR);
|
|
||||||
tntSimulator.change();
|
|
||||||
})));
|
|
||||||
inv.setItem(22, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, vector.getY()), lore, false, clickType -> {}));
|
|
||||||
inv.setItem(31, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
moveAll(simulatorElements, (clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR).clone().multiply(-1));
|
|
||||||
tntSimulator.change();
|
|
||||||
})));
|
|
||||||
|
|
||||||
// Z Position
|
|
||||||
inv.setItem(14, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
moveAll(simulatorElements, clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR);
|
|
||||||
tntSimulator.change();
|
|
||||||
})));
|
|
||||||
inv.setItem(23, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, vector.getZ()), lore, false, clickType -> {}));
|
|
||||||
inv.setItem(32, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
moveAll(simulatorElements, (clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR).clone().multiply(-1));
|
|
||||||
})));
|
|
||||||
|
|
||||||
inv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void moveAll(List<SimulatorElement> simulatorElements, Vector vector) {
|
|
||||||
for (SimulatorElement element : simulatorElements) {
|
|
||||||
if (element instanceof TNTGroup) {
|
|
||||||
TNTGroup group = (TNTGroup) element;
|
|
||||||
group.setPosition(group.getPosition().add(vector));
|
|
||||||
} else if (element instanceof TNTElement) {
|
|
||||||
TNTElement tntElement = (TNTElement) element;
|
|
||||||
tntElement.setPosition(tntElement.getOwnPosition().add(vector));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void open(Player player, TNTGroup tntGroup, Runnable back) {
|
|
||||||
SWInventory inv = new SWInventory(player, 45, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_GROUP_MENU", player));
|
|
||||||
SWItem gray = new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§f", clickType -> {});
|
|
||||||
for (int i = 0; i < 9; i++) {
|
|
||||||
inv.setItem(i, gray);
|
|
||||||
inv.setItem(i + 36, gray);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (back != null) {
|
|
||||||
inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run()));
|
|
||||||
}
|
|
||||||
|
|
||||||
String plusOneName = BauSystem.MESSAGE.parse("SIMULATOR_PLUS_ONE", player);
|
|
||||||
String minusOneName = BauSystem.MESSAGE.parse("SIMULATOR_MINUS_ONE", player);
|
|
||||||
List<String> plusOneFiveShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_FIVE_SHIFT", player));
|
|
||||||
List<String> minusOneFiveShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_FIVE_SHIFT", player));
|
|
||||||
List<String> lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player));
|
|
||||||
|
|
||||||
TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player);
|
|
||||||
Runnable editObserver = () -> {
|
|
||||||
ChangePosition.show(inv, player, tntGroup, vectorUnaryOperator -> {
|
|
||||||
tntGroup.setPosition(vectorUnaryOperator.apply(tntGroup.getPosition()));
|
|
||||||
}, () -> open(player, tntGroup, back));
|
|
||||||
ChangeMaterial.show(inv, player, 14, tntGroup, Material.BARREL, () -> open(player, tntGroup, back));
|
|
||||||
Disabled.show(inv, player, 32, tntSimulator, tntGroup);
|
|
||||||
|
|
||||||
// Change TickOffset
|
|
||||||
inv.setItem(16, new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntGroup.setTickOffset(tntGroup.getTickOffset() + (clickType.isShiftClick() ? 5 : 1));
|
|
||||||
tntGroup.change();
|
|
||||||
}));
|
|
||||||
SWItem tickItem = new SWItem(SWItem.getMaterial("DIODE"), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, tntGroup.getTickOffset()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK_ANVIL_GUI_NAME", player), tntGroup.getTickOffset(), tick -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntGroup.setTickOffset(tick);
|
|
||||||
tntGroup.change();
|
|
||||||
open(player, tntGroup, back);
|
|
||||||
}, () -> open(player, tntGroup, back)));
|
|
||||||
tickItem.getItemStack().setAmount(Math.max(tntGroup.getTickOffset(), 1));
|
|
||||||
inv.setItem(25, tickItem);
|
|
||||||
inv.setItem(34, new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
tntGroup.setTickOffset(tntGroup.getTickOffset() - (clickType.isShiftClick() ? 5 : 1));
|
|
||||||
tntGroup.change();
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
editObserver.run();
|
|
||||||
tntGroup.register(editObserver, player::closeInventory);
|
|
||||||
inv.addCloseRunnable(() -> {
|
|
||||||
tntGroup.unregister(editObserver);
|
|
||||||
});
|
|
||||||
|
|
||||||
inv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void changeCount(Player player, String name, int defaultValue, Consumer<Integer> result, Runnable failure) {
|
|
||||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, name, defaultValue + "");
|
|
||||||
swAnvilInv.setItem(Material.PAPER);
|
|
||||||
swAnvilInv.setCallback(s -> {
|
|
||||||
try {
|
|
||||||
result.accept(Integer.parseInt(s));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
failure.run();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
swAnvilInv.open();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,216 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.gui;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.configplayer.Config;
|
|
||||||
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
|
|
||||||
import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
|
||||||
import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement;
|
|
||||||
import de.steamwar.bausystem.features.simulator.tnt.TNTElement;
|
|
||||||
import de.steamwar.bausystem.features.simulator.tnt.TNTGroup;
|
|
||||||
import de.steamwar.inventory.SWInventory;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import de.steamwar.inventory.SWListInv;
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.inventory.ClickType;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import static de.steamwar.bausystem.features.simulator.gui.ItemUtils.unique;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class TNTSimulatorGui {
|
|
||||||
|
|
||||||
private static final Vector X_VECTOR = new Vector(0.0625, 0, 0);
|
|
||||||
private static final Vector Y_VECTOR = new Vector(0, 0.0625, 0);
|
|
||||||
private static final Vector Z_VECTOR = new Vector(0, 0, 0.0625);
|
|
||||||
|
|
||||||
private static final Vector FX_VECTOR = new Vector(1, 0, 0);
|
|
||||||
private static final Vector FY_VECTOR = new Vector(0, 1, 0);
|
|
||||||
private static final Vector FZ_VECTOR = new Vector(0, 0, 1);
|
|
||||||
|
|
||||||
public void open(Player player, TNTSimulator currentTntSimulator, TNTGroup currentTntGroup, Supplier<List<SimulatorElement>> simulatorElements, Runnable back) {
|
|
||||||
List<SWListInv.SWListEntry<SimulatorElement>> swListEntryList = new ArrayList<>();
|
|
||||||
|
|
||||||
int totalTNTCount = 0;
|
|
||||||
for (SimulatorElement element : simulatorElements.get()) {
|
|
||||||
swListEntryList.add(new SWListInv.SWListEntry<>(element.menu(player), element));
|
|
||||||
totalTNTCount += element.tntCount();
|
|
||||||
}
|
|
||||||
swListEntryList.sort(Comparator.comparing(o -> o.getObject().tick()));
|
|
||||||
|
|
||||||
SWListInv<SimulatorElement> inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_GUI_NAME", player), false, swListEntryList, (clickType, simulatorElement) -> {
|
|
||||||
if (simulatorElement instanceof TNTGroup) {
|
|
||||||
TNTGroup tntGroup = (TNTGroup) simulatorElement;
|
|
||||||
open(player, null, tntGroup, () -> new ArrayList<>(tntGroup.getElements()), () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back));
|
|
||||||
} else {
|
|
||||||
TNTElementGUI.open(player, (TNTElement) simulatorElement, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (back != null) {
|
|
||||||
inv.setItem(47, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run()));
|
|
||||||
}
|
|
||||||
SWItem swItem = new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TOTAL_TNT", player, totalTNTCount), clickType -> {
|
|
||||||
});
|
|
||||||
swItem.getItemStack().setAmount(totalTNTCount);
|
|
||||||
List<SimulatorElement> elements = simulatorElements.get();
|
|
||||||
inv.setItem(elements.isEmpty() ? 49 : 50, swItem);
|
|
||||||
if (currentTntGroup != null) {
|
|
||||||
Runnable editObserver = () -> {
|
|
||||||
List<String> otherLore = new ArrayList<>();
|
|
||||||
otherLore.add("");
|
|
||||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, currentTntGroup.getPosition().getX()));
|
|
||||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, currentTntGroup.getPosition().getY()));
|
|
||||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, currentTntGroup.getPosition().getZ()));
|
|
||||||
otherLore.add("");
|
|
||||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME_LORE", player, currentTntGroup.getMaterial().name()));
|
|
||||||
otherLore.add("");
|
|
||||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, currentTntGroup.getTickOffset()));
|
|
||||||
if (currentTntGroup.isDisabled()) {
|
|
||||||
otherLore.add("");
|
|
||||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", player));
|
|
||||||
}
|
|
||||||
inv.setItem(48, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_GROUP", player), otherLore, false, clickType -> {
|
|
||||||
TNTGroupEditGUI.open(player, currentTntGroup, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back));
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
editObserver.run();
|
|
||||||
currentTntGroup.register(editObserver, player::closeInventory);
|
|
||||||
inv.addCloseRunnable(() -> {
|
|
||||||
currentTntGroup.unregister(editObserver);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (!elements.isEmpty()) {
|
|
||||||
TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player);
|
|
||||||
inv.setItem(48, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_GROUP", player), new ArrayList<>(), false, clickType -> {
|
|
||||||
TNTGroupEditGUI.open(player, tntSimulator, elements, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back));
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (currentTntSimulator != null) {
|
|
||||||
if (totalTNTCount > 0) {
|
|
||||||
inv.setItem(48, new SWItem(Material.MAGENTA_GLAZED_TERRACOTTA, BauSystem.MESSAGE.parse("SIMULATOR_GUI_MOVE_ALL", player), clickType -> {
|
|
||||||
moveAll(player, currentTntSimulator, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back));
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false);
|
|
||||||
inv.setItem(47, new SWItem(simulatorAutoTrace ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, BauSystem.MESSAGE.parse("SIMULATOR_GUI_AUTO_TRACE", player, simulatorAutoTrace), clickType -> {
|
|
||||||
Config.getInstance().get(player).put("simulatorAutoTrace", !simulatorAutoTrace);
|
|
||||||
open(player, currentTntSimulator, currentTntGroup, simulatorElements, back);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentTntSimulator != null || currentTntGroup != null) {
|
|
||||||
inv.setItem(51, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("SIMULATOR_GUI_DELETE", player), clickType -> {
|
|
||||||
if (currentTntSimulator != null) {
|
|
||||||
currentTntSimulator.getTntElementList().forEach(SimulatorElement::close);
|
|
||||||
currentTntSimulator.clear();
|
|
||||||
player.closeInventory();
|
|
||||||
} else {
|
|
||||||
TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player);
|
|
||||||
tntSimulator.remove(currentTntGroup);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
inv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void moveAll(Player player, TNTSimulator tntSimulator, Runnable back) {
|
|
||||||
SWInventory inv = new SWInventory(player, 45, BauSystem.MESSAGE.parse("SIMULATOR_MOVE_ALL_GUI_NAME", player));
|
|
||||||
SWItem gray = new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§f", clickType -> {});
|
|
||||||
for (int i = 0; i < 9; i++) {
|
|
||||||
inv.setItem(i, gray);
|
|
||||||
inv.setItem(i + 36, gray);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (back != null) {
|
|
||||||
inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run()));
|
|
||||||
}
|
|
||||||
|
|
||||||
String plusOneName = BauSystem.MESSAGE.parse("SIMULATOR_PLUS_ONE", player);
|
|
||||||
String minusOneName = BauSystem.MESSAGE.parse("SIMULATOR_MINUS_ONE", player);
|
|
||||||
List<String> plusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_PIXEL_SHIFT", player));
|
|
||||||
List<String> minusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_PIXEL_SHIFT", player));
|
|
||||||
List<String> lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player));
|
|
||||||
|
|
||||||
// X Position
|
|
||||||
inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
moveAll(tntSimulator, clickType.isShiftClick() ? X_VECTOR : FX_VECTOR);
|
|
||||||
tntSimulator.change();
|
|
||||||
})));
|
|
||||||
inv.setItem(21, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_X", player), lore, false, clickType -> {}));
|
|
||||||
inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
moveAll(tntSimulator, (clickType.isShiftClick() ? X_VECTOR : FX_VECTOR).clone().multiply(-1));
|
|
||||||
tntSimulator.change();
|
|
||||||
})));
|
|
||||||
|
|
||||||
// Y Position
|
|
||||||
inv.setItem(13, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
moveAll(tntSimulator, clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR);
|
|
||||||
tntSimulator.change();
|
|
||||||
})));
|
|
||||||
inv.setItem(22, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_Y", player), lore, false, clickType -> {}));
|
|
||||||
inv.setItem(31, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
moveAll(tntSimulator, (clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR).clone().multiply(-1));
|
|
||||||
tntSimulator.change();
|
|
||||||
})));
|
|
||||||
|
|
||||||
// Z Position
|
|
||||||
inv.setItem(14, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
moveAll(tntSimulator, clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR);
|
|
||||||
tntSimulator.change();
|
|
||||||
})));
|
|
||||||
inv.setItem(23, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_Z", player), lore, false, clickType -> {}));
|
|
||||||
inv.setItem(32, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
moveAll(tntSimulator, (clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR).clone().multiply(-1));
|
|
||||||
tntSimulator.change();
|
|
||||||
})));
|
|
||||||
|
|
||||||
inv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void moveAll(TNTSimulator tntSimulator, Vector vector) {
|
|
||||||
for (SimulatorElement element : tntSimulator.getTntElementList()) {
|
|
||||||
if (element instanceof TNTGroup) {
|
|
||||||
TNTGroup group = (TNTGroup) element;
|
|
||||||
group.setPosition(group.getPosition().add(vector));
|
|
||||||
} else if (element instanceof TNTElement) {
|
|
||||||
TNTElement tntElement = (TNTElement) element;
|
|
||||||
tntElement.setPosition(tntElement.getOwnPosition().add(vector));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,10 +17,10 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.gui.base;
|
package de.steamwar.bausystem.features.simulator.gui.base;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
|
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
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;
|
@ -17,9 +17,9 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.gui.base;
|
package de.steamwar.bausystem.features.simulator.gui.base;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -17,10 +17,10 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.gui.base;
|
package de.steamwar.bausystem.features.simulator.gui.base;
|
||||||
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.gui.components;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement;
|
|
||||||
import de.steamwar.inventory.SWInventory;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import de.steamwar.inventory.SWListInv;
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class ChangeMaterial {
|
|
||||||
|
|
||||||
private static final List<Material> MATERIALS = new ArrayList<>();
|
|
||||||
static {
|
|
||||||
Arrays.stream(Material.values())
|
|
||||||
.filter(Material::isItem)
|
|
||||||
.filter(material -> !material.isLegacy())
|
|
||||||
.forEach(MATERIALS::add);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void show(SWInventory inv, Player player, int position, SimulatorElement simulatorElement, Material defaultMaterial, Runnable back) {
|
|
||||||
inv.setItem(position, new SWItem(simulatorElement.getMaterial(), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL", player), Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL_LORE_1", player, simulatorElement.getMaterial().name().toLowerCase()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL_LORE_2", player), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL_LORE_3", player)), false, clickType -> {
|
|
||||||
if (clickType.isLeftClick()) {
|
|
||||||
List<SWListInv.SWListEntry<Material>> swListEntries = new ArrayList<>();
|
|
||||||
MATERIALS.forEach(current -> {
|
|
||||||
swListEntries.add(new SWListInv.SWListEntry<>(new SWItem(current, BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME", player, current.name().toLowerCase()), Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_CLICK", player)), false, ignored -> {
|
|
||||||
}), current));
|
|
||||||
});
|
|
||||||
SWListInv<Material> swListInv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_GUI_NAME", player), false, swListEntries, (invClickType, material) -> {
|
|
||||||
simulatorElement.setMaterial(material);
|
|
||||||
simulatorElement.change();
|
|
||||||
back.run();
|
|
||||||
});
|
|
||||||
swListInv.open();
|
|
||||||
} else {
|
|
||||||
simulatorElement.setMaterial(defaultMaterial);
|
|
||||||
simulatorElement.change();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,163 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.gui.components;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
|
||||||
import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement;
|
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
|
||||||
import de.steamwar.inventory.SWInventory;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.inventory.ClickType;
|
|
||||||
import org.bukkit.util.Consumer;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.function.UnaryOperator;
|
|
||||||
|
|
||||||
import static de.steamwar.bausystem.features.simulator.gui.ItemUtils.unique;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class ChangePosition {
|
|
||||||
|
|
||||||
private static final Vector X_VECTOR = new Vector(0.0625, 0, 0);
|
|
||||||
private static final Vector Y_VECTOR = new Vector(0, 0.0625, 0);
|
|
||||||
private static final Vector Z_VECTOR = new Vector(0, 0, 0.0625);
|
|
||||||
|
|
||||||
private static final Vector FX_VECTOR = new Vector(1, 0, 0);
|
|
||||||
private static final Vector FY_VECTOR = new Vector(0, 1, 0);
|
|
||||||
private static final Vector FZ_VECTOR = new Vector(0, 0, 1);
|
|
||||||
|
|
||||||
public void show(SWInventory inv, Player player, SimulatorElement simulatorElement, Consumer<UnaryOperator<Vector>> toChangeVector, Runnable back) {
|
|
||||||
String plusOneName = BauSystem.MESSAGE.parse("SIMULATOR_PLUS_ONE", player);
|
|
||||||
String minusOneName = BauSystem.MESSAGE.parse("SIMULATOR_MINUS_ONE", player);
|
|
||||||
List<String> plusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_PIXEL_SHIFT", player));
|
|
||||||
List<String> minusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_PIXEL_SHIFT", player));
|
|
||||||
List<String> lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player));
|
|
||||||
|
|
||||||
// X Position
|
|
||||||
inv.setItem(10, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
toChangeVector.accept(vector -> {
|
|
||||||
vector.add(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR);
|
|
||||||
return vector;
|
|
||||||
});
|
|
||||||
simulatorElement.change();
|
|
||||||
})));
|
|
||||||
inv.setItem(19, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, simulatorElement.getPosition().getX()), lore, false, clickType -> {
|
|
||||||
changePosition(player, simulatorElement.getPosition().getX(), x -> {
|
|
||||||
toChangeVector.accept(vector -> {
|
|
||||||
vector.setX(clamp(x));
|
|
||||||
return vector;
|
|
||||||
});
|
|
||||||
simulatorElement.change();
|
|
||||||
back.run();
|
|
||||||
}, back);
|
|
||||||
}));
|
|
||||||
inv.setItem(28, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
toChangeVector.accept(vector -> {
|
|
||||||
vector.subtract(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR);
|
|
||||||
return vector;
|
|
||||||
});
|
|
||||||
simulatorElement.change();
|
|
||||||
})));
|
|
||||||
|
|
||||||
// Y Position
|
|
||||||
inv.setItem(11, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
toChangeVector.accept(vector -> {
|
|
||||||
vector.add(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR);
|
|
||||||
return vector;
|
|
||||||
});
|
|
||||||
simulatorElement.change();
|
|
||||||
})));
|
|
||||||
inv.setItem(20, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, simulatorElement.getPosition().getY()), lore, false, clickType -> {
|
|
||||||
changePosition(player, simulatorElement.getPosition().getY(), y -> {
|
|
||||||
toChangeVector.accept(vector -> {
|
|
||||||
vector.setY(clamp(y));
|
|
||||||
return vector;
|
|
||||||
});
|
|
||||||
simulatorElement.change();
|
|
||||||
back.run();
|
|
||||||
}, back);
|
|
||||||
}));
|
|
||||||
inv.setItem(29, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
toChangeVector.accept(vector -> {
|
|
||||||
vector.subtract(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR);
|
|
||||||
return vector;
|
|
||||||
});
|
|
||||||
simulatorElement.change();
|
|
||||||
})));
|
|
||||||
|
|
||||||
// Z Position
|
|
||||||
inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
toChangeVector.accept(vector -> {
|
|
||||||
vector.add(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR);
|
|
||||||
return vector;
|
|
||||||
});
|
|
||||||
simulatorElement.change();
|
|
||||||
})));
|
|
||||||
inv.setItem(21, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, simulatorElement.getPosition().getZ()), lore, false, clickType -> {
|
|
||||||
changePosition(player, simulatorElement.getPosition().getZ(), z -> {
|
|
||||||
toChangeVector.accept(vector -> {
|
|
||||||
vector.setZ(clamp(z));
|
|
||||||
return vector;
|
|
||||||
});
|
|
||||||
simulatorElement.change();
|
|
||||||
back.run();
|
|
||||||
}, back);
|
|
||||||
}));
|
|
||||||
inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
|
||||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
|
||||||
toChangeVector.accept(vector -> {
|
|
||||||
vector.subtract(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR);
|
|
||||||
return vector;
|
|
||||||
});
|
|
||||||
simulatorElement.change();
|
|
||||||
})));
|
|
||||||
}
|
|
||||||
|
|
||||||
private double clamp(double d) {
|
|
||||||
return (int) (d * 10000) * 0.0001;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void changePosition(Player player, double defaultValue, Consumer<Double> result, Runnable failure) {
|
|
||||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_ANVIL_GUI_NAME", player), defaultValue + "");
|
|
||||||
swAnvilInv.setItem(Material.PAPER);
|
|
||||||
swAnvilInv.setCallback(s -> {
|
|
||||||
try {
|
|
||||||
result.accept(Double.parseDouble(s.replace(',', '.')));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
failure.run();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
swAnvilInv.open();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.gui.components;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
|
||||||
import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement;
|
|
||||||
import de.steamwar.inventory.SWInventory;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class Disabled {
|
|
||||||
|
|
||||||
public void show(SWInventory inv, Player player, int position, TNTSimulator tntSimulator, SimulatorElement simulatorElement) {
|
|
||||||
inv.setItem(position, new SWItem(simulatorElement.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, BauSystem.MESSAGE.parse(simulatorElement.isDisabled() ? "SIMULATOR_TNT_SPAWN_DISABLED" : "SIMULATOR_TNT_SPAWN_ENABLED", player), new ArrayList<>(), !simulatorElement.isDisabled(), clickType -> {
|
|
||||||
simulatorElement.setDisabled(!simulatorElement.isDisabled());
|
|
||||||
simulatorElement.change();
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,16 +17,16 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.storage;
|
package de.steamwar.bausystem.features.simulator.storage;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorElement;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorPhase;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement;
|
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase;
|
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import yapion.exceptions.YAPIONException;
|
import yapion.exceptions.YAPIONException;
|
||||||
@ -40,7 +40,6 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class SimFormatSimulatorLoader implements SimulatorLoader {
|
public class SimFormatSimulatorLoader implements SimulatorLoader {
|
||||||
|
|
@ -17,12 +17,12 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.storage;
|
package de.steamwar.bausystem.features.simulator.storage;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import yapion.exceptions.YAPIONException;
|
import yapion.exceptions.YAPIONException;
|
||||||
@ -66,7 +66,7 @@ public class SimulatorFormatSimulatorLoader implements SimulatorLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// file.delete();
|
file.delete();
|
||||||
return Optional.of(Collections.singletonList(simulator));
|
return Optional.of(Collections.singletonList(simulator));
|
||||||
}
|
}
|
||||||
|
|
@ -17,9 +17,9 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.storage;
|
package de.steamwar.bausystem.features.simulator.storage;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -17,9 +17,9 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.storage;
|
package de.steamwar.bausystem.features.simulator.storage;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import yapion.hierarchy.output.FileOutput;
|
import yapion.hierarchy.output.FileOutput;
|
||||||
import yapion.hierarchy.types.YAPIONArray;
|
import yapion.hierarchy.types.YAPIONArray;
|
@ -17,12 +17,12 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2.storage;
|
package de.steamwar.bausystem.features.simulator.storage;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase;
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.tnt;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
|
||||||
import de.steamwar.bausystem.shared.Pair;
|
|
||||||
import de.steamwar.entity.REntity;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public interface SimulatorElement {
|
|
||||||
|
|
||||||
Map<SimulatorElement, Set<Runnable>> observer = new HashMap<>();
|
|
||||||
Map<Runnable, Runnable> closeObserver = new HashMap<>();
|
|
||||||
|
|
||||||
YAPIONObject toYAPION();
|
|
||||||
List<REntity> getEntities();
|
|
||||||
void getEntity(List<SimulatorElement> elements, REntity entity);
|
|
||||||
|
|
||||||
Vector getPosition();
|
|
||||||
void setPosition(Vector position);
|
|
||||||
|
|
||||||
void remove(TNTElement tntElement);
|
|
||||||
|
|
||||||
SWItem menu(Player p);
|
|
||||||
boolean locations(Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result, Region region, Location location); // Ticks to subtick order to spawning runnable to count of activations
|
|
||||||
int tntCount();
|
|
||||||
int tick();
|
|
||||||
|
|
||||||
// Observer
|
|
||||||
default void change() {
|
|
||||||
observer.getOrDefault(this, new HashSet<>()).forEach(Runnable::run);
|
|
||||||
if (this instanceof TNTGroup) {
|
|
||||||
((TNTGroup) this).getElements().forEach(SimulatorElement::change);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default void register(Runnable observer, Runnable close) {
|
|
||||||
SimulatorElement.observer.computeIfAbsent(this, k -> new HashSet<>()).add(observer);
|
|
||||||
SimulatorElement.closeObserver.put(observer, close);
|
|
||||||
}
|
|
||||||
default void unregister(Runnable observer) {
|
|
||||||
SimulatorElement.observer.computeIfPresent(this, (k, v) -> {
|
|
||||||
v.remove(observer);
|
|
||||||
return v.isEmpty() ? null : v;
|
|
||||||
});
|
|
||||||
SimulatorElement.closeObserver.remove(observer);
|
|
||||||
}
|
|
||||||
default void close() {
|
|
||||||
Set<Runnable> allRunnables = observer.remove(this);
|
|
||||||
if (allRunnables == null) return;
|
|
||||||
allRunnables.forEach(runnable -> {
|
|
||||||
Runnable closeRunnable = closeObserver.remove(runnable);
|
|
||||||
if (closeRunnable == null) return;
|
|
||||||
closeRunnable.run();
|
|
||||||
});
|
|
||||||
if (this instanceof TNTGroup) {
|
|
||||||
((TNTGroup) this).getElements().forEach(SimulatorElement::close);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// API
|
|
||||||
Material getMaterial();
|
|
||||||
void setMaterial(Material material);
|
|
||||||
|
|
||||||
boolean isDisabled();
|
|
||||||
void setDisabled(boolean disabled);
|
|
||||||
}
|
|
@ -1,318 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.tnt;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.features.simulator.OrderUtils;
|
|
||||||
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
|
||||||
import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode;
|
|
||||||
import de.steamwar.bausystem.region.utils.RegionExtensionType;
|
|
||||||
import de.steamwar.bausystem.region.utils.RegionType;
|
|
||||||
import de.steamwar.bausystem.shared.Pair;
|
|
||||||
import de.steamwar.entity.REntity;
|
|
||||||
import de.steamwar.entity.REntityServer;
|
|
||||||
import de.steamwar.entity.RFallingBlockEntity;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.entity.TNTPrimed;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class TNTElement implements SimulatorElement {
|
|
||||||
|
|
||||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
|
||||||
|
|
||||||
private final REntityServer entityServer;
|
|
||||||
private RFallingBlockEntity entity;
|
|
||||||
TNTGroup tntGroup = null;
|
|
||||||
|
|
||||||
private final Vector position;
|
|
||||||
private int fuseTicks = 80;
|
|
||||||
private int count = 1;
|
|
||||||
private int tickOffset = 0;
|
|
||||||
|
|
||||||
@Setter
|
|
||||||
private boolean xVelocity = false;
|
|
||||||
|
|
||||||
@Setter
|
|
||||||
private boolean yVelocity = false;
|
|
||||||
|
|
||||||
@Setter
|
|
||||||
private boolean zVelocity = false;
|
|
||||||
private Material order = Material.REPEATER;
|
|
||||||
private Material material = Material.TNT;
|
|
||||||
private boolean disabled = false;
|
|
||||||
|
|
||||||
public TNTElement(Vector position, TNTGroup tntGroup, REntityServer entityServer) {
|
|
||||||
this.entityServer = entityServer;
|
|
||||||
this.tntGroup = tntGroup;
|
|
||||||
this.position = position;
|
|
||||||
initEntity();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TNTElement(YAPIONObject yapionObject, TNTGroup tntGroup, REntityServer entityServer) {
|
|
||||||
this.entityServer = entityServer;
|
|
||||||
this.tntGroup = tntGroup;
|
|
||||||
this.position = new Vector(yapionObject.getDoubleOrDefault("x", yapionObject.getDoubleOrDefault("positionX", 0)), yapionObject.getDoubleOrDefault("y", yapionObject.getDoubleOrDefault("positionY", 0)), yapionObject.getDoubleOrDefault("z", yapionObject.getDoubleOrDefault("positionZ", 0)));
|
|
||||||
this.disabled = yapionObject.getBooleanOrDefault("disabled", false);
|
|
||||||
this.fuseTicks = yapionObject.getIntOrDefault("fuseTicks", 80);
|
|
||||||
this.count = yapionObject.getIntOrDefault("count", 1);
|
|
||||||
this.tickOffset = yapionObject.getIntOrDefault("tickOffset", 0);
|
|
||||||
this.xVelocity = yapionObject.getBooleanOrDefault("xVelocity", false);
|
|
||||||
this.yVelocity = yapionObject.getBooleanOrDefault("yVelocity", false);
|
|
||||||
this.zVelocity = yapionObject.getBooleanOrDefault("zVelocity", false);
|
|
||||||
this.order = Material.valueOf(yapionObject.getStringOrDefault("order", yapionObject.getBooleanOrDefault("comparator", false) ? Material.COMPARATOR.name() : Material.REPEATER.name()));
|
|
||||||
this.material = Material.valueOf(yapionObject.getStringOrDefault("material", Material.TNT.name()));
|
|
||||||
initEntity();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initEntity() {
|
|
||||||
this.entity = new RFallingBlockEntity(entityServer, getPosition().toLocation(WORLD), Material.TNT);
|
|
||||||
this.entity.setNoGravity(true);
|
|
||||||
_updatePosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public YAPIONObject toYAPION() {
|
|
||||||
YAPIONObject yapionObject = new YAPIONObject();
|
|
||||||
yapionObject.add("x", position.getX());
|
|
||||||
yapionObject.add("y", position.getY());
|
|
||||||
yapionObject.add("z", position.getZ());
|
|
||||||
yapionObject.add("fuseTicks", fuseTicks);
|
|
||||||
yapionObject.add("count", count);
|
|
||||||
yapionObject.add("tickOffset", tickOffset);
|
|
||||||
yapionObject.add("xVelocity", xVelocity);
|
|
||||||
yapionObject.add("yVelocity", yVelocity);
|
|
||||||
yapionObject.add("zVelocity", zVelocity);
|
|
||||||
yapionObject.add("order", order.name());
|
|
||||||
yapionObject.add("material", material.name());
|
|
||||||
yapionObject.add("disabled", disabled);
|
|
||||||
return yapionObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<REntity> getEntities() {
|
|
||||||
if (disabled) return new ArrayList<>();
|
|
||||||
return Arrays.asList(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getEntity(List<SimulatorElement> elements, REntity entity) {
|
|
||||||
if (disabled) return;
|
|
||||||
if (this.entity.getEntityId() == entity.getEntityId() || getPosition().distanceSquared(new Vector(entity.getX(), entity.getY(), entity.getZ())) < 0.01) {
|
|
||||||
elements.add(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Vector getPosition() {
|
|
||||||
if (tntGroup != null) {
|
|
||||||
return tntGroup.getPosition().clone().add(position);
|
|
||||||
}
|
|
||||||
return position.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPosition(Vector position) {
|
|
||||||
this.position.setX(position.getX());
|
|
||||||
this.position.setY(position.getY());
|
|
||||||
this.position.setZ(position.getZ());
|
|
||||||
_updatePosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _updatePosition() {
|
|
||||||
if (disabled || (getParent() != null && getParent().isDisabled())) {
|
|
||||||
entity.move(-200000, 0, -200000, 0F, 0F, (byte) 0);
|
|
||||||
} else {
|
|
||||||
Vector position = getPosition();
|
|
||||||
entity.move(position.getX(), position.getY(), position.getZ(), 0F, 0F, (byte) 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTickOffset() {
|
|
||||||
if (tntGroup != null) {
|
|
||||||
return tntGroup.getTickOffset() + tickOffset;
|
|
||||||
}
|
|
||||||
return tickOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(TNTElement tntElement) {
|
|
||||||
entity.die();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SWItem menu(Player p) {
|
|
||||||
List<String> lore = new ArrayList<>();
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_1", p, count));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_2", p, getTickOffset()));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_3", p, getFuseTicks()));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_4", p));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_5", p, getPosition().getX()));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_6", p, getPosition().getY()));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_7", p, getPosition().getZ()));
|
|
||||||
if (disabled) {
|
|
||||||
lore.add("");
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", p));
|
|
||||||
}
|
|
||||||
SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_NAME", p), lore, disabled, null);
|
|
||||||
if (!disabled) swItem.getItemStack().setAmount(Math.max(tntCount(), 1));
|
|
||||||
return swItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean locations(Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result, Region region, Location radius) {
|
|
||||||
if (disabled) return false;
|
|
||||||
Location location = getPosition().toLocation(SimulatorStorage.WORLD);
|
|
||||||
if (region.isGlobal() && location.distanceSquared(radius) > 10000) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!region.inRegion(location, RegionType.NORMAL, RegionExtensionType.NORMAL)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Region thisRegion = Region.getRegion(location);
|
|
||||||
if (thisRegion.getFlagStorage().get(Flag.FREEZE) == FreezeMode.ACTIVE) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>())
|
|
||||||
.computeIfAbsent(OrderUtils.order(order), ignore -> new HashSet<>())
|
|
||||||
.add(new Pair<>(() -> {
|
|
||||||
SimulatorStorage.WORLD.spawn(location, TNTPrimed.class, tntPrimed -> {
|
|
||||||
tntPrimed.setFuseTicks(fuseTicks);
|
|
||||||
if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0));
|
|
||||||
if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0));
|
|
||||||
if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0));
|
|
||||||
});
|
|
||||||
}, count));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int tntCount() {
|
|
||||||
return disabled ? 0 : count;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int tick() {
|
|
||||||
return getTickOffset();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCount(int count) {
|
|
||||||
if (count < 0) count = 0;
|
|
||||||
if (count > 400) count = 400;
|
|
||||||
this.count = count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getOwnTickOffset() {
|
|
||||||
return tickOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getParentTickOffset() {
|
|
||||||
if (tntGroup != null) {
|
|
||||||
return tntGroup.getTickOffset();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTickOffset(int tickOffset) {
|
|
||||||
if (getTickOffset() - this.tickOffset + tickOffset < 0) {
|
|
||||||
this.tickOffset = -this.getParentTickOffset();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (getTickOffset() - this.tickOffset + tickOffset > 400) {
|
|
||||||
this.tickOffset = 400 - this.getParentTickOffset();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.tickOffset = tickOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFuseTicks(int fuseTicks) {
|
|
||||||
if (fuseTicks < 0) fuseTicks = 0;
|
|
||||||
if (fuseTicks > 160) fuseTicks = 160;
|
|
||||||
this.fuseTicks = fuseTicks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector getOwnPosition() {
|
|
||||||
return position.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrder(Material material) {
|
|
||||||
this.order = material;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaterial(Material material) {
|
|
||||||
this.material = material;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasParent() {
|
|
||||||
return tntGroup != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TNTGroup getParent() {
|
|
||||||
return tntGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDisabled(boolean disabled) {
|
|
||||||
this.disabled = disabled;
|
|
||||||
_updatePosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void align(Vector offset) {
|
|
||||||
Vector vector = getPosition();
|
|
||||||
Vector parentVector = new Vector(0, 0, 0);
|
|
||||||
if (tntGroup != null) {
|
|
||||||
parentVector = tntGroup.getPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (offset.getX() != 0) {
|
|
||||||
if (vector.getX() - (int) vector.getX() == 0.49) {
|
|
||||||
vector.setX(vector.getX() + 0.02);
|
|
||||||
}
|
|
||||||
if (vector.getX() - (int) vector.getX() == -0.49) {
|
|
||||||
vector.setX(vector.getX() - 0.02);
|
|
||||||
}
|
|
||||||
vector.setX(vector.getBlockX() + offset.getX());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (offset.getZ() != 0) {
|
|
||||||
if (vector.getZ() - (int) vector.getZ() == 0.49) {
|
|
||||||
vector.setZ(vector.getZ() + 0.02);
|
|
||||||
}
|
|
||||||
if (vector.getZ() - (int) vector.getZ() == -0.49) {
|
|
||||||
vector.setZ(vector.getZ() - 0.02);
|
|
||||||
}
|
|
||||||
vector.setZ(vector.getBlockZ() + offset.getZ());
|
|
||||||
}
|
|
||||||
|
|
||||||
setPosition(vector.subtract(parentVector));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,186 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.tnt;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
|
||||||
import de.steamwar.bausystem.shared.Pair;
|
|
||||||
import de.steamwar.entity.REntity;
|
|
||||||
import de.steamwar.entity.REntityServer;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
import yapion.hierarchy.types.YAPIONArray;
|
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class TNTGroup implements SimulatorElement {
|
|
||||||
|
|
||||||
private final Vector position;
|
|
||||||
private int tickOffset = 0;
|
|
||||||
private Material material = Material.BARREL;
|
|
||||||
private boolean disabled = false;
|
|
||||||
private List<TNTElement> elements = new ArrayList<>();
|
|
||||||
|
|
||||||
public TNTGroup(Vector position) {
|
|
||||||
this.position = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TNTGroup(YAPIONObject yapionObject, REntityServer entityServer) {
|
|
||||||
this.position = new Vector(yapionObject.getDoubleOrDefault("x", 0), yapionObject.getDoubleOrDefault("y", 0), yapionObject.getDoubleOrDefault("z", 0));
|
|
||||||
this.tickOffset = yapionObject.getIntOrDefault("tickOffset", 0);
|
|
||||||
this.material = Material.getMaterial(yapionObject.getStringOrDefault("material", "BARREL"));
|
|
||||||
this.disabled = yapionObject.getBooleanOrDefault("disabled", false);
|
|
||||||
YAPIONArray elements = yapionObject.getArrayOrDefault("elements", new YAPIONArray());
|
|
||||||
for (YAPIONObject element : elements.streamObject().collect(Collectors.toList())) {
|
|
||||||
TNTElement tntElement = new TNTElement(element, this, entityServer);
|
|
||||||
this.elements.add(tntElement);
|
|
||||||
tntElement._updatePosition();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public YAPIONObject toYAPION() {
|
|
||||||
YAPIONObject yapionObject = new YAPIONObject();
|
|
||||||
yapionObject.add("x", position.getX());
|
|
||||||
yapionObject.add("y", position.getY());
|
|
||||||
yapionObject.add("z", position.getZ());
|
|
||||||
yapionObject.add("tickOffset", tickOffset);
|
|
||||||
yapionObject.add("material", material.name());
|
|
||||||
yapionObject.add("disabled", disabled);
|
|
||||||
YAPIONArray yapionArray = new YAPIONArray();
|
|
||||||
for (TNTElement element : elements) {
|
|
||||||
yapionArray.add(element.toYAPION());
|
|
||||||
}
|
|
||||||
yapionObject.add("elements", yapionArray);
|
|
||||||
return yapionObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(TNTElement tntElement) {
|
|
||||||
tntElement.tntGroup = this;
|
|
||||||
elements.add(tntElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<REntity> getEntities() {
|
|
||||||
if (disabled) new ArrayList<>();
|
|
||||||
return elements.stream().flatMap(tntElement -> tntElement.getEntities().stream()).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getEntity(List<SimulatorElement> elements, REntity entity) {
|
|
||||||
if (disabled) return;
|
|
||||||
for (TNTElement tntElement : this.elements) {
|
|
||||||
tntElement.getEntity(elements, entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Vector getPosition() {
|
|
||||||
return position.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPosition(Vector position) {
|
|
||||||
this.position.setX(position.getX());
|
|
||||||
this.position.setY(position.getY());
|
|
||||||
this.position.setZ(position.getZ());
|
|
||||||
elements.forEach(TNTElement::_updatePosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(TNTElement tntElement) {
|
|
||||||
if (elements.remove(tntElement)) {
|
|
||||||
tntElement.remove(tntElement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SWItem menu(Player p) {
|
|
||||||
List<String> lore = new ArrayList<>();
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_LORE_1", p, elements.size()));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_LORE_2", p, tickOffset));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_LORE_3", p));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_LORE_4", p, position.getX()));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_LORE_5", p, position.getY()));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_LORE_6", p, position.getZ()));
|
|
||||||
if (disabled) {
|
|
||||||
lore.add("");
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", p));
|
|
||||||
}
|
|
||||||
SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_NAME", p), lore, disabled, null);
|
|
||||||
if (!disabled) swItem.getItemStack().setAmount(Math.max(tntCount(), 1));
|
|
||||||
return swItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean locations(Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result, Region region, Location location) {
|
|
||||||
if (disabled) return false;
|
|
||||||
for (TNTElement element : elements) {
|
|
||||||
if (element.locations(result, region, location)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int tntCount() {
|
|
||||||
if (disabled) return 0;
|
|
||||||
return elements.stream().mapToInt(TNTElement::tntCount).sum();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int tick() {
|
|
||||||
return getTickOffset();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTickOffset(int tickOffset) {
|
|
||||||
if (tickOffset < 0) tickOffset = 0;
|
|
||||||
if (tickOffset > 400) tickOffset = 400;
|
|
||||||
for (TNTElement tntElement : elements) {
|
|
||||||
if (tntElement.getTickOffset() - this.tickOffset + tickOffset < 0) {
|
|
||||||
tickOffset = Math.max(tickOffset, -tntElement.getOwnTickOffset());
|
|
||||||
}
|
|
||||||
if (tntElement.getTickOffset() - this.tickOffset + tickOffset > 400) {
|
|
||||||
tickOffset = Math.min(tickOffset, 400 - tntElement.getOwnTickOffset());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.tickOffset = tickOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaterial(Material material) {
|
|
||||||
this.material = material;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDisabled(boolean disabled) {
|
|
||||||
this.disabled = disabled;
|
|
||||||
elements.forEach(TNTElement::_updatePosition);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,416 +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.simulator2;
|
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.Reflection;
|
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.SWUtils;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorElement;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.execute.SimulatorExecutor;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.SimulatorGroupGui;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.SimulatorGui;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
|
|
||||||
import de.steamwar.bausystem.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 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.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class SimulatorCursor implements Listener {
|
|
||||||
|
|
||||||
private final World WORLD = Bukkit.getWorlds().get(0);
|
|
||||||
private Class<?> position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition");
|
|
||||||
private Class<?> look = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInLook");
|
|
||||||
private Class<?> positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook");
|
|
||||||
|
|
||||||
private Map<Player, CursorType> cursorType = Collections.synchronizedMap(new HashMap<>());
|
|
||||||
private Map<Player, REntityServer> cursors = Collections.synchronizedMap(new HashMap<>());
|
|
||||||
|
|
||||||
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) {
|
|
||||||
calcCursor(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
|
||||||
calcCursor(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
|
||||||
calcCursor(event.getPlayer());
|
|
||||||
}, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
||||||
cursorType.remove(event.getPlayer());
|
|
||||||
cursors.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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void calcCursor(Player player) {
|
|
||||||
if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) {
|
|
||||||
removeCursor(player);
|
|
||||||
SimulatorWatcher.show(null, player);
|
|
||||||
SWUtils.sendToActionbar(player, "");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Simulator simulator = SimulatorStorage.getSimulator(player);
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
showCursor(player, rayTraceResult, simulator != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void removeCursor(Player player) {
|
|
||||||
REntityServer entityServer = cursors.get(player);
|
|
||||||
if (entityServer != null) {
|
|
||||||
entityServer.getEntities().forEach(REntity::die);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 getPosTNT(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 getPosRedstoneBlock(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::getPosTNT, "TNT", vector -> new TNTElement(vector).add(new TNTPhase())),
|
|
||||||
REDSTONE_BLOCK(Material.REDSTONE_BLOCK, SimulatorCursor::getPosRedstoneBlock, "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase())),
|
|
||||||
;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
return TNT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
|
||||||
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(simulator);
|
|
||||||
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) {
|
|
||||||
player.sendMessage("§cThe simulator " + s + " already exists");
|
|
||||||
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.getElements().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.getElements().add(group);
|
|
||||||
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
|
|
||||||
element.open(player, simulator, group, simulatorGui);
|
|
||||||
SimulatorWatcher.update(simulator);
|
|
||||||
calcCursor(player);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,162 +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.simulator2;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import de.steamwar.bausystem.SWUtils;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.storage.SimFormatSimulatorLoader;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.storage.SimulatorFormatSimulatorLoader;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.storage.SimulatorSaver;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.storage.YAPIONFormatSimulatorLoader;
|
|
||||||
import de.steamwar.bausystem.utils.ItemUtils;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import de.steamwar.linkage.api.Enable;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class SimulatorStorage implements Enable {
|
|
||||||
|
|
||||||
public static final File simulatorsDir = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "simulators");
|
|
||||||
private static Map<String, Simulator> simulatorMap = new HashMap<>();
|
|
||||||
private static NamespacedKey simulatorSelection = SWUtils.getNamespaceKey("simulator_selection");
|
|
||||||
|
|
||||||
public static Simulator getSimulator(Player player) {
|
|
||||||
Simulator simulator = getSimulator(player.getInventory().getItemInMainHand());
|
|
||||||
if (simulator != null) return simulator;
|
|
||||||
return getSimulator(player.getInventory().getItemInOffHand());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Simulator getSimulator(ItemStack itemStack) {
|
|
||||||
if (!SimulatorCursor.isSimulatorItem(itemStack)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
String selection = ItemUtils.getTag(itemStack, simulatorSelection);
|
|
||||||
if (selection == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return simulatorMap.get(selection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Simulator getSimulator(String name) {
|
|
||||||
return simulatorMap.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addSimulator(String name, Simulator simulator) {
|
|
||||||
simulatorMap.putIfAbsent(name, simulator);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void enable() {
|
|
||||||
SimFormatSimulatorLoader simFormatSimulatorLoader = new SimFormatSimulatorLoader();
|
|
||||||
SimulatorFormatSimulatorLoader simulatorFormatSimulatorLoader = new SimulatorFormatSimulatorLoader();
|
|
||||||
YAPIONFormatSimulatorLoader yapionFormatSimulatorLoader = new YAPIONFormatSimulatorLoader();
|
|
||||||
|
|
||||||
for (File file : simulatorsDir.listFiles()) {
|
|
||||||
try {
|
|
||||||
List<Simulator> simulators = simFormatSimulatorLoader.load(file)
|
|
||||||
.orElse(null);
|
|
||||||
if (simulators != null) {
|
|
||||||
simulators.forEach(simulator -> {
|
|
||||||
simulatorMap.put(simulator.getName(), simulator);
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
List<Simulator> simulators = simulatorFormatSimulatorLoader.load(file)
|
|
||||||
.orElse(null);
|
|
||||||
if (simulators != null) {
|
|
||||||
simulators.forEach(simulator -> {
|
|
||||||
simulatorMap.put(simulator.getName(), simulator);
|
|
||||||
SimulatorSaver.saveSimulator(simulatorsDir, simulator);
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
List<Simulator> simulators = yapionFormatSimulatorLoader.load(file)
|
|
||||||
.orElse(null);
|
|
||||||
if (simulators != null) {
|
|
||||||
simulators.forEach(simulator -> {
|
|
||||||
simulatorMap.put(simulator.getName(), simulator);
|
|
||||||
SimulatorSaver.saveSimulator(simulatorsDir, simulator);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openSimulatorSelector(Player player) {
|
|
||||||
SimulatorPageGui<Simulator> simulatorPageGui = new SimulatorPageGui<Simulator>(player, null, 6 * 9, new ArrayList<>(simulatorMap.values())) {
|
|
||||||
@Override
|
|
||||||
public String baseTitle() {
|
|
||||||
return "Simulators";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SWItem convert(Simulator simulator) {
|
|
||||||
return simulator.toItem(player, clickType -> {
|
|
||||||
setSimulator(player, simulator);
|
|
||||||
player.closeInventory();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
simulatorPageGui.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setSimulator(Player player, Simulator simulator) {
|
|
||||||
ItemStack mainHand = player.getInventory().getItemInMainHand();
|
|
||||||
ItemStack offHand = player.getInventory().getItemInOffHand();
|
|
||||||
ItemStack itemStack;
|
|
||||||
if (SimulatorCursor.isSimulatorItem(mainHand)) {
|
|
||||||
itemStack = mainHand;
|
|
||||||
} else if (SimulatorCursor.isSimulatorItem(offHand)) {
|
|
||||||
itemStack = offHand;
|
|
||||||
} else {
|
|
||||||
itemStack = null;
|
|
||||||
}
|
|
||||||
if (itemStack == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemUtils.setTag(itemStack, simulatorSelection, simulator.getName());
|
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
|
||||||
itemMeta.setDisplayName(BauSystem.MESSAGE.parse("SIMULATOR_WAND_NAME_SELECTED", player, simulator.getName()));
|
|
||||||
itemStack.setItemMeta(itemMeta);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,53 +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.simulator2;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstonePhase;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTPhase;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.execute.SimulatorExecutor;
|
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.SimulatorGui;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import jdk.jfr.Registered;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class SimulatorTestCommand extends SWCommand {
|
|
||||||
|
|
||||||
static final Simulator SIMULATOR = new Simulator("TestSim");
|
|
||||||
|
|
||||||
public SimulatorTestCommand() {
|
|
||||||
super("simtest");
|
|
||||||
|
|
||||||
SimulatorGroup group1 = new SimulatorGroup().add(new TNTElement(new Vector(-477.5, 46, 311.5)).add(new TNTPhase()));
|
|
||||||
SIMULATOR.getElements().add(group1);
|
|
||||||
|
|
||||||
SimulatorGroup group2 = new SimulatorGroup().add(new TNTElement(new Vector(-477.5, 47, 312.5)).add(new TNTPhase()));
|
|
||||||
SIMULATOR.getElements().add(group2);
|
|
||||||
|
|
||||||
SimulatorGroup group3 = new SimulatorGroup().add(new RedstoneElement(new Vector(-484, 47, 307)).add(new RedstonePhase()));
|
|
||||||
SIMULATOR.getElements().add(group3);
|
|
||||||
}
|
|
||||||
}
|
|
In neuem Issue referenzieren
Einen Benutzer sperren