SteamWar/BauSystem2.0
Archiviert
12
0

Consolidate Item Generation

Fix Back arrow in element gui
Dieser Commit ist enthalten in:
yoyosource 2023-10-22 13:24:50 +02:00
Ursprung 933e4fe7d9
Commit 327dded73b
14 geänderte Dateien mit 120 neuen und 165 gelöschten Zeilen

Datei anzeigen

@ -19,10 +19,13 @@
package de.steamwar.bausystem.features.simulator2.data;
import de.steamwar.inventory.InvCallback;
import de.steamwar.inventory.SWItem;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
@ -41,4 +44,8 @@ public class Simulator {
simulatorGroup.move(x, y, z);
});
}
public SWItem toItem(Player player, InvCallback invCallback) {
return new SWItem(material, "§e" + name, invCallback);
}
}

Datei anzeigen

@ -19,9 +19,12 @@
package de.steamwar.bausystem.features.simulator2.data;
import de.steamwar.inventory.InvCallback;
import de.steamwar.inventory.SWItem;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.ArrayList;
@ -70,4 +73,19 @@ public abstract class SimulatorElement<T extends SimulatorPhase> {
position.setY(position.getY() + y);
position.setZ(position.getZ() + z);
}
public SWItem toItem(Player player, InvCallback invCallback) {
List<String> lore = new ArrayList<>();
lore.add("§7Phase count§8:§e " + phases.size());
lore.add("§7Tick§8:§e " + getBaseTick());
lore.add("");
lore.add("§7X§8:§e " + position.getX());
lore.add("§7Y§8:§e " + position.getY());
lore.add("§7Z§8:§e " + position.getZ());
if (disabled) {
lore.add("");
lore.add("§cDisabled");
}
return new SWItem(material, "§e" + getName(), lore, disabled, invCallback);
}
}

Datei anzeigen

@ -19,9 +19,12 @@
package de.steamwar.bausystem.features.simulator2.data;
import de.steamwar.inventory.InvCallback;
import de.steamwar.inventory.SWItem;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Comparator;
@ -61,4 +64,19 @@ public class SimulatorGroup {
simulatorElement.move(x, y, z);
});
}
public SWItem toItem(Player player, InvCallback groupCallback, InvCallback itemCallback) {
if (elements.size() == 1) {
return elements.get(0).toItem(player, itemCallback);
} else {
List<String> lore = new ArrayList<>();
lore.add("§7Element count§8:§e " + elements.size());
lore.add("§7Tick§8:§e " + getBaseTick());
if (disabled) {
lore.add("");
lore.add("§cDisabled");
}
return new SWItem(material, "§eGroup", lore, disabled, groupCallback);
}
}
}

Datei anzeigen

@ -23,17 +23,14 @@ import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
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.tnt.TNTElement;
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui;
import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui;
import de.steamwar.inventory.InvCallback;
import de.steamwar.inventory.SWItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class SimulatorGroupChooserGui extends SimulatorPageGui<SimulatorGroup> {
@ -41,8 +38,8 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui<SimulatorGroup> {
private final SimulatorGroup parent;
private final SimulatorBaseGui back;
public SimulatorGroupChooserGui(Player player, Simulator simulator, List<SimulatorGroup> data, SimulatorElement<?> subject, SimulatorGroup parent, SimulatorBaseGui back){
super(player, simulator, 6*9, data);
public SimulatorGroupChooserGui(Player player, Simulator simulator, SimulatorElement<?> subject, SimulatorGroup parent, SimulatorBaseGui back) {
super(player, simulator, 6 * 9, simulator.getElements().stream().filter(e -> e != parent).collect(Collectors.toList()));
this.subject = subject;
this.parent = parent;
this.back = back;
@ -50,11 +47,10 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui<SimulatorGroup> {
@Override
public void headerAndFooter() {
simulator.getElements().removeIf(element -> element.getElements().isEmpty());
inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> {}));
if(parent.getElements().size() != 1){
inventory.setItem(49 , new SWItem(Material.BARRIER, "§c Remove from Group", clickType -> {
inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> {
}));
if (parent.getElements().size() != 1) {
inventory.setItem(49, new SWItem(Material.BARRIER, "§cRemove from Group", clickType -> {
SimulatorGroup newParent = new SimulatorGroup();
newParent.add(subject);
simulator.getElements().add(newParent);
@ -63,51 +59,20 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui<SimulatorGroup> {
}));
}
}
@Override
public String baseTitle() {
return "§eChoose group to add to or element, to create new group";
return "Choose Group";
}
@Override
public SWItem convert(SimulatorGroup simulatorGroup) {
List<SimulatorElement<?>> elements = simulatorGroup.getElements();
if (elements.size() == 1) {
SimulatorElement<?> element = elements.get(0);
List<String> lore = new ArrayList<>();
lore.add("§7Phase count§8:§e " + element.getPhases().size());
lore.add("§7Tick§8:§e " + element.getBaseTick());
lore.add("");
lore.add("§7X§8:§e " + element.getPosition().getX());
lore.add("§7Y§8:§e " + element.getPosition().getY());
lore.add("§7Z§8:§e " + element.getPosition().getZ());
if (element.isDisabled()) {
lore.add("");
lore.add("§cDisabled");
}
return new SWItem(element.getMaterial(), "§e" + element.getName(), lore, element.isDisabled(), clickType -> {
SimulatorGroup newParent = new SimulatorGroup();
newParent.add(subject);
newParent.add(element);
simulatorGroup.getElements().remove(element);
parent.getElements().remove(subject);
simulator.getElements().add(newParent);
back.open();
SimulatorWatcher.update(simulator);
});
}
List<String> lore = new ArrayList<>();
lore.add("§7Element count§8:§e " + elements.size());
lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick());
if (simulatorGroup.isDisabled()) {
lore.add("");
lore.add("§cDisabled");
}
return new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> {
InvCallback invCallback = clickType -> {
simulatorGroup.add(subject);
parent.getElements().remove(subject);
back.open();
SimulatorWatcher.update(simulator);
});
};
return simulatorGroup.toItem(player, invCallback, invCallback);
}
}

Datei anzeigen

@ -32,10 +32,7 @@ import de.steamwar.inventory.SWItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> { //TODO Disolve group option ?
public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
private final SimulatorGroup simulatorGroup;
private final SimulatorBaseGui back;
@ -64,16 +61,9 @@ public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> { /
back.open();
}));
List<String> lore = new ArrayList<>();
lore.add("§7Element count§8:§e " + data.size());
lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick());
if (simulatorGroup.isDisabled()) {
lore.add("");
lore.add("§cDisabled");
}
inventory.setItem(4, new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> {
inventory.setItem(4, simulatorGroup.toItem(player, clickType -> {
new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open();
}));
}, clickType -> {}));
inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open();
@ -86,18 +76,7 @@ public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> { /
@Override
public SWItem convert(SimulatorElement<?> element) {
List<String> lore = new ArrayList<>();
lore.add("§7Phase count§8:§e " + element.getPhases().size());
lore.add("§7Tick§8:§e " + element.getBaseTick());
lore.add("");
lore.add("§7X§8:§e " + element.getPosition().getX());
lore.add("§7Y§8:§e " + element.getPosition().getY());
lore.add("§7Z§8:§e " + element.getPosition().getZ());
if (element.isDisabled()) {
lore.add("");
lore.add("§cDisabled");
}
return new SWItem(element.getMaterial(), "§e" + element.getName(), lore, element.isDisabled(), clickType -> {
return element.toItem(player, clickType -> {
if (element instanceof TNTElement) {
new SimulatorTNTGui(player, simulator, (TNTElement) element, simulatorGroup, this).open();
} else if (element instanceof RedstoneElement) {

Datei anzeigen

@ -28,9 +28,7 @@ import de.steamwar.inventory.SWItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
@ -61,16 +59,9 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
}));
// Material Chooser
List<String> lore = new ArrayList<>();
lore.add("§7Element count§8:§e " + simulatorGroup.getElements().size());
lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick());
if (simulatorGroup.isDisabled()) {
lore.add("");
lore.add("§cDisabled");
}
inventory.setItem(4, new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> {
inventory.setItem(4, simulatorGroup.toItem(player, clickType -> {
new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open();
}));
}, clickType -> {}));
// Base Tick
int baseTicks = simulatorGroup.getBaseTick();

Datei anzeigen

@ -30,11 +30,7 @@ import de.steamwar.inventory.SWItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class SimulatorGui extends SimulatorPageGui<SimulatorGroup> {//TODO Groupcreation
public class SimulatorGui extends SimulatorPageGui<SimulatorGroup> {
public SimulatorGui(Player player, Simulator simulator) {
super(player, simulator, 6 * 9, simulator.getElements());
@ -49,7 +45,7 @@ public class SimulatorGui extends SimulatorPageGui<SimulatorGroup> {//TODO Group
public void headerAndFooter() {
simulator.getElements().removeIf(element -> element.getElements().isEmpty());
inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> {
inventory.setItem(4, simulator.toItem(player, clickType -> {
new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open();
}));
inventory.setItem(49, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
@ -59,21 +55,10 @@ public class SimulatorGui extends SimulatorPageGui<SimulatorGroup> {//TODO Group
@Override
public SWItem convert(SimulatorGroup simulatorGroup) {
List<SimulatorElement<?>> elements = simulatorGroup.getElements();
if (elements.size() == 1) {
SimulatorElement<?> element = elements.get(0);
List<String> lore = new ArrayList<>();
lore.add("§7Phase count§8:§e " + element.getPhases().size());
lore.add("§7Tick§8:§e " + element.getBaseTick());
lore.add("");
lore.add("§7X§8:§e " + element.getPosition().getX());
lore.add("§7Y§8:§e " + element.getPosition().getY());
lore.add("§7Z§8:§e " + element.getPosition().getZ());
if (element.isDisabled()) {
lore.add("");
lore.add("§cDisabled");
}
return new SWItem(element.getMaterial(), "§e" + element.getName(), lore, element.isDisabled(), clickType -> {
return simulatorGroup.toItem(player, clickType -> {
new SimulatorGroupGui(player, simulator, simulatorGroup, this).open();
}, clickType -> {
SimulatorElement<?> element = simulatorGroup.getElements().get(0);
if (element instanceof TNTElement) {
new SimulatorTNTGui(player, simulator, (TNTElement) element, simulatorGroup,this).open();
} else if (element instanceof RedstoneElement) {
@ -81,16 +66,4 @@ public class SimulatorGui extends SimulatorPageGui<SimulatorGroup> {//TODO Group
}
});
}
List<String> lore = new ArrayList<>();
lore.add("§7Element count§8:§e " + elements.size());
lore.add("§7Tick§8:§e " + simulatorGroup.getBaseTick());
if (simulatorGroup.isDisabled()) {
lore.add("");
lore.add("§cDisabled");
}
return new SWItem(simulatorGroup.getMaterial(), "§eGroup", lore, simulatorGroup.isDisabled(), clickType -> {
new SimulatorGroupGui(player, simulator, simulatorGroup, this).open();
});
}
}

Datei anzeigen

@ -35,17 +35,16 @@ import org.bukkit.event.inventory.ClickType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
private final SimulatorGroup simulatorGroup;
private final SimulatorGroup parent;
private final RedstoneElement redstone;
private final SimulatorBaseGui back;
public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, RedstoneElement redstone, SimulatorBaseGui back) {
public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup parent, RedstoneElement redstone, SimulatorBaseGui back) {
super(player, simulator, 6 * 9, redstone.getPhases());
this.simulatorGroup = simulatorGroup;
this.parent = parent;
this.redstone = redstone;
this.back = back;
}
@ -66,22 +65,28 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
// Back Arrow
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
if (parent.getElements().contains(redstone)) {
back.open();
} else {
SimulatorGroup newParent = simulator.getElements().stream()
.filter(simulatorGroup -> simulatorGroup.getElements().contains(redstone))
.findFirst()
.orElse(null);
if (newParent == null) {
player.closeInventory();
return;
}
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
if (newParent.getElements().size() == 1) {
simulatorGui.open();
} else {
new SimulatorGroupGui(player, simulator, newParent, simulatorGui).open();
}
}
}));
// Material Chooser
List<String> lore = new ArrayList<>();
lore.add("§7Activation count§8:§e " + data.size());
lore.add("§7Tick§8:§e " + redstone.getBaseTick());
lore.add("");
lore.add("§7X§8:§e " + redstone.getPosition().getX());
lore.add("§7Y§8:§e " + redstone.getPosition().getY());
lore.add("§7Z§8:§e " + redstone.getPosition().getZ());
if (redstone.isDisabled()) {
lore.add("");
lore.add("§cDisabled");
}
inventory.setItem(4, new SWItem(redstone.getMaterial(), "§eTNT", lore, redstone.isDisabled(), clickType -> {
inventory.setItem(4, redstone.toItem(player, clickType -> {
new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open();
}));
@ -92,7 +97,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
//Group chooser
inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> {
new SimulatorGroupChooserGui(player, simulator, simulator.getElements().stream().filter( e -> e != simulatorGroup).collect(Collectors.toList()), redstone, simulatorGroup, this).open();
new SimulatorGroupChooserGui(player, simulator, redstone, parent, this).open();
}));
//Enable/Disable

Datei anzeigen

@ -62,7 +62,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui {
}));
// Material Chooser
inventory.setItem(4, new SWItem(redstoneElement.getMaterial(), "§eRedstone", clickType -> {
inventory.setItem(4, redstoneElement.toItem(player, clickType -> {
new SimulatorMaterialGui(player, simulator, redstoneElement::getMaterial, redstoneElement::setMaterial, this).open();
}));

Datei anzeigen

@ -60,14 +60,7 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui {
}));
// Material Chooser
List<String> lore = new ArrayList<>();
lore.add("§7Activation count§8:§e " + redstone.getPhases().size());
lore.add("§7Tick§8:§e " + redstone.getBaseTick());
if (redstone.isDisabled()) {
lore.add("");
lore.add("§cDisabled");
}
inventory.setItem(4, new SWItem(redstone.getMaterial(), "§eRedstone", lore, redstone.isDisabled(), clickType -> {
inventory.setItem(4, redstone.toItem(player, clickType -> {
new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open();
}));

Datei anzeigen

@ -51,7 +51,7 @@ public class SimulatorSettingsGui extends SimulatorBaseGui {
}));
// Material Chooser
inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> {
inventory.setItem(4, simulator.toItem(player, clickType -> {
new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open();
}));

Datei anzeigen

@ -67,22 +67,28 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
// Back Arrow
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
if (parent.getElements().contains(tnt)) {
back.open();
} else {
SimulatorGroup newParent = simulator.getElements().stream()
.filter(simulatorGroup -> simulatorGroup.getElements().contains(tnt))
.findFirst()
.orElse(null);
if (newParent == null) {
player.closeInventory();
return;
}
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
if (newParent.getElements().size() == 1) {
simulatorGui.open();
} else {
new SimulatorGroupGui(player, simulator, newParent, simulatorGui).open();
}
}
}));
// Material Chooser
List<String> lore = new ArrayList<>();
lore.add("§7Phase count§8:§e " + data.size());
lore.add("§7Tick§8:§e " + tnt.getBaseTick());
lore.add("");
lore.add("§7X§8:§e " + tnt.getPosition().getX());
lore.add("§7Y§8:§e " + tnt.getPosition().getY());
lore.add("§7Z§8:§e " + tnt.getPosition().getZ());
if (tnt.isDisabled()) {
lore.add("");
lore.add("§cDisabled");
}
inventory.setItem(4, new SWItem(tnt.getMaterial(), "§eTNT", lore, tnt.isDisabled(), clickType -> {
inventory.setItem(4, tnt.toItem(player, clickType -> {
new SimulatorMaterialGui(player, simulator, tnt::getMaterial, tnt::setMaterial, this).open();
}));
@ -90,7 +96,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
new SimulatorTNTSettingsGui(player, simulator, tnt, this).open();
}));
inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> {
new SimulatorGroupChooserGui(player, simulator, simulator.getElements().stream().filter( e -> e != parent).collect(Collectors.toList()), tnt, parent, this).open();
new SimulatorGroupChooserGui(player, simulator, tnt, parent, this).open();
}));
inventory.setItem(50, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
tnt.setDisabled(!tnt.isDisabled());

Datei anzeigen

@ -62,7 +62,7 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui {
}));
// Material Chooser
inventory.setItem(4, new SWItem(tntElement.getMaterial(), "§TNT", clickType -> {
inventory.setItem(4, tntElement.toItem(player, clickType -> {
new SimulatorMaterialGui(player, simulator, tntElement::getMaterial, tntElement::setMaterial, this).open();
}));

Datei anzeigen

@ -68,7 +68,7 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui {
lore.add("");
lore.add("§cDisabled");
}
inventory.setItem(4, new SWItem(tnt.getMaterial(), "§eTNT", lore, tnt.isDisabled(), clickType -> {
inventory.setItem(4, tnt.toItem(player, clickType -> {
new SimulatorMaterialGui(player, simulator, tnt::getMaterial, tnt::setMaterial, this).open();
}));