SteamWar/BauSystem2.0
Archiviert
12
0

Add TNTSimulatorGui
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-06-09 20:47:09 +02:00
Ursprung 8b351fe871
Commit 4ac101dcb1
6 geänderte Dateien mit 110 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -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_4 = §7x§8: §e{0}
SIMULATOR_GUI_TNT_SPAWN_LORE_5 = §7y§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_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_NAME = Simulator
SIMULATOR_GUI_DELETE = §cdelete TNT SIMULATOR_GUI_DELETE = §cDelete TNT
SIMULATOR_GUI_START = §eStart SIMULATOR_GUI_START = §eStart
SIMULATOR_GUI_AUTO_TRACE = §eAutoTrace§8: §7{0} SIMULATOR_GUI_AUTO_TRACE = §eAutoTrace§8: §7{0}
SIMULATOR_GUI_MOVE_ALL = §eMove all SIMULATOR_GUI_MOVE_ALL = §eMove all

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bausystem.features.simulatorn; 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.show.SimulatorEntityShowMode;
import de.steamwar.bausystem.features.simulatorn.tnt.SimulatorElement; import de.steamwar.bausystem.features.simulatorn.tnt.SimulatorElement;
import de.steamwar.bausystem.features.simulatorn.tnt.TNTElement; 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.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.RayTraceResult; import org.bukkit.util.RayTraceResult;
import org.bukkit.util.Vector;
import yapion.hierarchy.types.YAPIONArray; import yapion.hierarchy.types.YAPIONArray;
import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONObject;
import yapion.hierarchy.types.YAPIONType; 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; import java.util.stream.Collectors;
@Getter @Getter
@ -123,30 +126,23 @@ public class TNTSimulator {
public void edit(Player player, RayTraceResult result) { public void edit(Player player, RayTraceResult result) {
if (result == null) { if (result == null) {
// TODO: Open gui TNTSimulatorGui.open(player, this, getTntElementList());
return; return;
} }
SimulatorCursor.show(player, this, result); SimulatorCursor.show(player, this, result);
if (result.getHitEntity() != null) { if (result.getHitEntity() != null) {
return; List<SimulatorElement> elements = getEntity(result.getHitEntity());
} if (elements.isEmpty()) return;
/* if (elements.size() == 1) {
if (result.getHitEntity() != null) { // elements.get(0).edit(player, result);
List<de.steamwar.bausystem.features.simulator.TNTSimulator.TNTSpawn> tntSpawns = getEntity(result.getHitEntity());
if (tntSpawns.isEmpty()) {
return;
}
if (tntSpawns.size() == 1) {
tntSpawns.get(0).editTNT(spawns);
} else { } else {
showGUI(new HashSet<>(tntSpawns)); TNTSimulatorGui.open(player, null, elements);
} }
return; return;
} }
*/
tntElementList.add(new TNTElement(SimulatorCursor.getPos(player, result))); tntElementList.add(new TNTElement(SimulatorCursor.getPos(player, result)));
playerShowMode.forEach((p, simulatorEntityShowMode) -> { playerShowMode.forEach((p, simulatorEntityShowMode) -> {

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<SimulatorElement> simulatorElements) {
List<SWListInv.SWListEntry<SimulatorElement>> swListEntryList = new ArrayList<>();
for (SimulatorElement element : simulatorElements) {
swListEntryList.add(new SWListInv.SWListEntry<>(element.menu(player), element));
}
SWListInv<SimulatorElement> inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_GUI_NAME", player), false, swListEntryList, (clickType, simulatorElement) -> {
});
// TODO: Add button
inv.open();
}
}

Datei anzeigen

@ -21,7 +21,9 @@ package de.steamwar.bausystem.features.simulatorn.tnt;
import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode; import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import de.steamwar.inventory.SWItem;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONObject;
@ -41,6 +43,6 @@ public interface SimulatorElement {
void show(SimulatorEntityShowMode showMode); void show(SimulatorEntityShowMode showMode);
void hide(SimulatorEntityShowMode showMode); void hide(SimulatorEntityShowMode showMode);
ItemStack menu(); SWItem menu(Player p);
void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result); // Ticks to subtick order to spawning runnable to count of activations void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result); // Ticks to subtick order to spawning runnable to count of activations
} }

Datei anzeigen

@ -19,23 +19,23 @@
package de.steamwar.bausystem.features.simulatorn.tnt; package de.steamwar.bausystem.features.simulatorn.tnt;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
import de.steamwar.bausystem.features.simulatorn.SimulatorStorage; import de.steamwar.bausystem.features.simulatorn.SimulatorStorage;
import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode; import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import de.steamwar.bausystem.shared.Position; import de.steamwar.bausystem.shared.Position;
import de.steamwar.inventory.SWItem;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONObject;
import java.util.Arrays; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Getter @Getter
public class TNTElement implements SimulatorElement { public class TNTElement implements SimulatorElement {
@ -52,6 +52,7 @@ public class TNTElement implements SimulatorElement {
private boolean zVelocity = false; private boolean zVelocity = false;
private int order = 0; private int order = 0;
private Material material = Material.TNT; private Material material = Material.TNT;
private boolean disabled = false;
public TNTElement(Vector position) { public TNTElement(Vector position) {
this.position = position; this.position = position;
@ -90,11 +91,13 @@ public class TNTElement implements SimulatorElement {
@Override @Override
public List<Entity> getEntities() { public List<Entity> getEntities() {
if (disabled) return new ArrayList<>();
return Arrays.asList(entity.getBukkitEntity()); return Arrays.asList(entity.getBukkitEntity());
} }
@Override @Override
public void getEntity(List<SimulatorElement> elements, Entity entity) { public void getEntity(List<SimulatorElement> elements, Entity entity) {
if (disabled) return;
if (this.entity.getId() == entity.getEntityId() || getPosition().equals(entity.getLocation().toVector())) { if (this.entity.getId() == entity.getEntityId() || getPosition().equals(entity.getLocation().toVector())) {
elements.add(this); elements.add(this);
} }
@ -117,21 +120,35 @@ public class TNTElement implements SimulatorElement {
@Override @Override
public void show(SimulatorEntityShowMode showMode) { public void show(SimulatorEntityShowMode showMode) {
if (disabled) return;
showMode.show(new Position(getPosition())); showMode.show(new Position(getPosition()));
} }
@Override @Override
public void hide(SimulatorEntityShowMode showMode) { public void hide(SimulatorEntityShowMode showMode) {
if (disabled) return;
showMode.hide(new Position(getPosition())); showMode.hide(new Position(getPosition()));
} }
@Override @Override
public ItemStack menu() { public SWItem menu(Player p) {
return null; 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, 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 @Override
public void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result) { public void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result) {
if (disabled) return;
result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>()) result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>())
.computeIfAbsent(order, ignore -> new Pair<>(() -> { .computeIfAbsent(order, ignore -> new Pair<>(() -> {
SimulatorStorage.WORLD.spawn(getPosition().toLocation(SimulatorStorage.WORLD), TNTPrimed.class, tntPrimed -> { SimulatorStorage.WORLD.spawn(getPosition().toLocation(SimulatorStorage.WORLD), TNTPrimed.class, tntPrimed -> {

Datei anzeigen

@ -19,17 +19,20 @@
package de.steamwar.bausystem.features.simulatorn.tnt; package de.steamwar.bausystem.features.simulatorn.tnt;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode; import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import de.steamwar.inventory.SWItem;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import yapion.hierarchy.types.YAPIONArray; import yapion.hierarchy.types.YAPIONArray;
import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -40,6 +43,7 @@ public class TNTGroup implements SimulatorElement {
private final Vector position; private final Vector position;
private int tickOffset = 0; private int tickOffset = 0;
private Material material = Material.BARREL; private Material material = Material.BARREL;
private boolean disabled = false;
private List<TNTElement> elements = new ArrayList<>(); private List<TNTElement> elements = new ArrayList<>();
public TNTGroup(Vector position) { 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.position = new Vector(yapionObject.getDoubleOrDefault("x", 0), yapionObject.getDoubleOrDefault("y", 0), yapionObject.getDoubleOrDefault("z", 0));
this.tickOffset = yapionObject.getIntOrDefault("tickOffset", 0); this.tickOffset = yapionObject.getIntOrDefault("tickOffset", 0);
this.material = Material.getMaterial(yapionObject.getStringOrDefault("material", "BARREL")); this.material = Material.getMaterial(yapionObject.getStringOrDefault("material", "BARREL"));
this.disabled = yapionObject.getBooleanOrDefault("disabled", false);
YAPIONArray elements = yapionObject.getArrayOrDefault("elements", new YAPIONArray()); YAPIONArray elements = yapionObject.getArrayOrDefault("elements", new YAPIONArray());
for (YAPIONObject element : elements.streamObject().collect(Collectors.toList())) { for (YAPIONObject element : elements.streamObject().collect(Collectors.toList())) {
TNTElement tntElement = new TNTElement(element); TNTElement tntElement = new TNTElement(element);
@ -66,6 +71,7 @@ public class TNTGroup implements SimulatorElement {
yapionObject.add("z", position.getZ()); yapionObject.add("z", position.getZ());
yapionObject.add("tickOffset", tickOffset); yapionObject.add("tickOffset", tickOffset);
yapionObject.add("material", material.name()); yapionObject.add("material", material.name());
yapionObject.add("disabled", disabled);
YAPIONArray yapionArray = new YAPIONArray(); YAPIONArray yapionArray = new YAPIONArray();
for (TNTElement element : elements) { for (TNTElement element : elements) {
yapionArray.add(element.toYAPION()); yapionArray.add(element.toYAPION());
@ -76,11 +82,13 @@ public class TNTGroup implements SimulatorElement {
@Override @Override
public List<Entity> getEntities() { public List<Entity> getEntities() {
if (disabled) new ArrayList<>();
return elements.stream().flatMap(tntElement -> tntElement.getEntities().stream()).collect(Collectors.toList()); return elements.stream().flatMap(tntElement -> tntElement.getEntities().stream()).collect(Collectors.toList());
} }
@Override @Override
public void getEntity(List<SimulatorElement> elements, Entity entity) { public void getEntity(List<SimulatorElement> elements, Entity entity) {
if (disabled) return;
for (TNTElement tntElement : this.elements) { for (TNTElement tntElement : this.elements) {
tntElement.getEntity(elements, entity); tntElement.getEntity(elements, entity);
} }
@ -88,6 +96,7 @@ public class TNTGroup implements SimulatorElement {
@Override @Override
public void show(SimulatorEntityShowMode showMode) { public void show(SimulatorEntityShowMode showMode) {
if (disabled) return;
elements.forEach(tntElement -> { elements.forEach(tntElement -> {
tntElement.show(showMode); tntElement.show(showMode);
}); });
@ -95,18 +104,26 @@ public class TNTGroup implements SimulatorElement {
@Override @Override
public void hide(SimulatorEntityShowMode showMode) { public void hide(SimulatorEntityShowMode showMode) {
if (disabled) return;
elements.forEach(tntElement -> { elements.forEach(tntElement -> {
tntElement.hide(showMode); tntElement.hide(showMode);
}); });
} }
@Override @Override
public ItemStack menu() { public SWItem menu(Player p) {
return null; List<String> 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 @Override
public void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result) { public void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result) {
if (disabled) return;
elements.forEach(tntElement -> { elements.forEach(tntElement -> {
tntElement.locations(result); tntElement.locations(result);
}); });