diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index e886313f..9436e1f2 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -558,8 +558,11 @@ SIMULATOR_GUI_TNT_SPAWN_LORE_3 = §7 SIMULATOR_GUI_TNT_SPAWN_LORE_4 = §7x§8: §e{0} SIMULATOR_GUI_TNT_SPAWN_LORE_5 = §7y§8: §e{0} SIMULATOR_GUI_TNT_SPAWN_LORE_6 = §7z§8: §e{0} +SIMULATOR_GUI_TNT_GROUP_NAME = §eTNT group +SIMULATOR_GUI_TNT_GROUP_LORE_1 = §7Element count§8: §e{0} +SIMULATOR_GUI_TNT_DISABLED = §cDisabled SIMULATOR_GUI_NAME = Simulator -SIMULATOR_GUI_DELETE = §cdelete TNT +SIMULATOR_GUI_DELETE = §cDelete TNT SIMULATOR_GUI_START = §eStart SIMULATOR_GUI_AUTO_TRACE = §eAutoTrace§8: §7{0} SIMULATOR_GUI_MOVE_ALL = §eMove all diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulator.java index fb4f19c3..be4eb8e7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulator.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.simulatorn; +import de.steamwar.bausystem.features.simulatorn.gui.TNTSimulatorGui; import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode; import de.steamwar.bausystem.features.simulatorn.tnt.SimulatorElement; import de.steamwar.bausystem.features.simulatorn.tnt.TNTElement; @@ -28,12 +29,14 @@ import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.RayTraceResult; -import org.bukkit.util.Vector; import yapion.hierarchy.types.YAPIONArray; import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONType; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; @Getter @@ -123,30 +126,23 @@ public class TNTSimulator { public void edit(Player player, RayTraceResult result) { if (result == null) { - // TODO: Open gui + TNTSimulatorGui.open(player, this, getTntElementList()); return; } SimulatorCursor.show(player, this, result); if (result.getHitEntity() != null) { - return; - } + List elements = getEntity(result.getHitEntity()); + if (elements.isEmpty()) return; - /* - if (result.getHitEntity() != null) { - List tntSpawns = getEntity(result.getHitEntity()); - if (tntSpawns.isEmpty()) { - return; - } - if (tntSpawns.size() == 1) { - tntSpawns.get(0).editTNT(spawns); + if (elements.size() == 1) { + // elements.get(0).edit(player, result); } else { - showGUI(new HashSet<>(tntSpawns)); + TNTSimulatorGui.open(player, null, elements); } return; } - */ tntElementList.add(new TNTElement(SimulatorCursor.getPos(player, result))); playerShowMode.forEach((p, simulatorEntityShowMode) -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/gui/TNTSimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/gui/TNTSimulatorGui.java new file mode 100644 index 00000000..4845aac7 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/gui/TNTSimulatorGui.java @@ -0,0 +1,49 @@ +/* + * 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 . + */ + +package de.steamwar.bausystem.features.simulatorn.gui; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.simulatorn.TNTSimulator; +import de.steamwar.bausystem.features.simulatorn.tnt.SimulatorElement; +import de.steamwar.inventory.SWListInv; +import lombok.experimental.UtilityClass; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +@UtilityClass +public class TNTSimulatorGui { + + public void open(Player player, TNTSimulator simulator, List simulatorElements) { + List> swListEntryList = new ArrayList<>(); + + for (SimulatorElement element : simulatorElements) { + swListEntryList.add(new SWListInv.SWListEntry<>(element.menu(player), element)); + } + + SWListInv inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_GUI_NAME", player), false, swListEntryList, (clickType, simulatorElement) -> { + }); + + // TODO: Add button + + inv.open(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/SimulatorElement.java index 8d5ca08a..3931dff4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/SimulatorElement.java @@ -21,7 +21,9 @@ package de.steamwar.bausystem.features.simulatorn.tnt; import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode; import de.steamwar.bausystem.shared.Pair; +import de.steamwar.inventory.SWItem; import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; import yapion.hierarchy.types.YAPIONObject; @@ -41,6 +43,6 @@ public interface SimulatorElement { void show(SimulatorEntityShowMode showMode); void hide(SimulatorEntityShowMode showMode); - ItemStack menu(); + SWItem menu(Player p); void locations(Map>> result); // Ticks to subtick order to spawning runnable to count of activations } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTElement.java index 57263b68..9c0c2039 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTElement.java @@ -19,23 +19,23 @@ package de.steamwar.bausystem.features.simulatorn.tnt; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; import de.steamwar.bausystem.features.simulatorn.SimulatorStorage; import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode; import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Position; +import de.steamwar.inventory.SWItem; import lombok.Getter; import org.bukkit.Material; import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; import yapion.hierarchy.types.YAPIONObject; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; @Getter public class TNTElement implements SimulatorElement { @@ -52,6 +52,7 @@ public class TNTElement implements SimulatorElement { private boolean zVelocity = false; private int order = 0; private Material material = Material.TNT; + private boolean disabled = false; public TNTElement(Vector position) { this.position = position; @@ -90,11 +91,13 @@ public class TNTElement implements SimulatorElement { @Override public List getEntities() { + if (disabled) return new ArrayList<>(); return Arrays.asList(entity.getBukkitEntity()); } @Override public void getEntity(List elements, Entity entity) { + if (disabled) return; if (this.entity.getId() == entity.getEntityId() || getPosition().equals(entity.getLocation().toVector())) { elements.add(this); } @@ -117,21 +120,35 @@ public class TNTElement implements SimulatorElement { @Override public void show(SimulatorEntityShowMode showMode) { + if (disabled) return; showMode.show(new Position(getPosition())); } @Override public void hide(SimulatorEntityShowMode showMode) { + if (disabled) return; showMode.hide(new Position(getPosition())); } @Override - public ItemStack menu() { - return null; + public SWItem menu(Player p) { + List 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, fuseTicks)); + lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_3", p)); + lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_4", p, getPosition().getX())); + lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_5", p, getPosition().getY())); + lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_6", p, getPosition().getZ())); + if (disabled) { + lore.add(""); + lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", p)); + } + return new SWItem(material, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_NAME", p), lore, false, null); } @Override public void locations(Map>> result) { + if (disabled) return; result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>()) .computeIfAbsent(order, ignore -> new Pair<>(() -> { SimulatorStorage.WORLD.spawn(getPosition().toLocation(SimulatorStorage.WORLD), TNTPrimed.class, tntPrimed -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTGroup.java index b01d8023..1669c018 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTGroup.java @@ -19,17 +19,20 @@ package de.steamwar.bausystem.features.simulatorn.tnt; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode; import de.steamwar.bausystem.shared.Pair; +import de.steamwar.inventory.SWItem; import lombok.Getter; import org.bukkit.Material; import org.bukkit.entity.Entity; -import org.bukkit.inventory.ItemStack; +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.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -40,6 +43,7 @@ public class TNTGroup implements SimulatorElement { private final Vector position; private int tickOffset = 0; private Material material = Material.BARREL; + private boolean disabled = false; private List elements = new ArrayList<>(); public TNTGroup(Vector position) { @@ -50,6 +54,7 @@ public class TNTGroup implements SimulatorElement { 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); @@ -66,6 +71,7 @@ public class TNTGroup implements SimulatorElement { 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()); @@ -76,11 +82,13 @@ public class TNTGroup implements SimulatorElement { @Override public List getEntities() { + if (disabled) new ArrayList<>(); return elements.stream().flatMap(tntElement -> tntElement.getEntities().stream()).collect(Collectors.toList()); } @Override public void getEntity(List elements, Entity entity) { + if (disabled) return; for (TNTElement tntElement : this.elements) { tntElement.getEntity(elements, entity); } @@ -88,6 +96,7 @@ public class TNTGroup implements SimulatorElement { @Override public void show(SimulatorEntityShowMode showMode) { + if (disabled) return; elements.forEach(tntElement -> { tntElement.show(showMode); }); @@ -95,18 +104,26 @@ public class TNTGroup implements SimulatorElement { @Override public void hide(SimulatorEntityShowMode showMode) { + if (disabled) return; elements.forEach(tntElement -> { tntElement.hide(showMode); }); } @Override - public ItemStack menu() { - return null; + public SWItem menu(Player p) { + List lore = new ArrayList<>(); + lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_LORE_1", p, elements.size())); + if (disabled) { + lore.add(""); + lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", p)); + } + return new SWItem(material, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_NAME", p), lore, false, null); } @Override public void locations(Map>> result) { + if (disabled) return; elements.forEach(tntElement -> { tntElement.locations(result); });