SteamWar/BauSystem2.0
Archiviert
12
0

Add some QOL Simulator changes
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
yoyosource 2023-10-25 23:03:59 +02:00
Ursprung 21ec66b4e2
Commit 61f7218fc0
11 geänderte Dateien mit 83 neuen und 37 gelöschten Zeilen

Datei anzeigen

@ -59,10 +59,7 @@ 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.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -279,7 +276,11 @@ public class SimulatorCursor implements Listener {
}
pos.setX(pos.getBlockX() + 0.5);
pos.setY(pos.getBlockY());
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;
}
@ -374,12 +375,19 @@ public class SimulatorCursor implements Listener {
element.open(player, simulator, group1, back);
break;
default:
// Open multi element present in Simulator
SimulatorGroup group2 = new SimulatorGroup();
group2.setMaterial(null);
group2.getElements().addAll(elements);
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
new SimulatorGroupGui(player, simulator, group2, simulatorGui).open();
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;

Datei anzeigen

@ -19,6 +19,7 @@
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;
@ -27,6 +28,7 @@ import de.steamwar.inventory.SWItem;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.HashMap;
@ -76,7 +78,26 @@ public class SimulatorStorage {
@Override
public SWItem convert(Simulator simulator) {
return simulator.toItem(player, clickType -> {
System.out.println(clickType);
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;
}
// TODO: Dynamic Item Lore, and remove if simulator does not exist anymore (On Join for every Player Inventory Slot with Simulator...)
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);
player.closeInventory();
});
}
};

Datei anzeigen

@ -50,14 +50,4 @@ public class SimulatorTestCommand extends SWCommand {
SimulatorGroup group3 = new SimulatorGroup().add(new RedstoneElement(new Vector(-484, 47, 307)).add(new RedstonePhase()));
SIMULATOR.getElements().add(group3);
}
@Register("open")
public void openCommand(Player player) {
new SimulatorGui(player, SIMULATOR).open();
}
@Register("run")
public void runCommand(Player player) {
SimulatorExecutor.run(SIMULATOR);
}
}

Datei anzeigen

@ -88,13 +88,12 @@ public class SimulatorWatcher {
Map<Vector, Set<Class<?>>> positionCache = new HashMap<>();
simulator.getElements().stream().map(group -> group.getElements().stream().map(element -> new Pair<>(group, element)).collect(Collectors.toList())).flatMap(List::stream).forEach(pair -> {
SimulatorGroup group = pair.getKey();
// TODO: Disabled material
SimulatorElement<?> element = pair.getValue();
boolean wasNotPresent = positionCache.computeIfAbsent(element.getPosition(), __ -> new HashSet<>())
.add(element.getClass());
if (!wasNotPresent) return;
Material material = element.getWorldMaterial();
Material material = group.isDisabled() || element.isDisabled() ? element.getWorldDisabledMaterial() : element.getWorldMaterial();
Location location = element.getWorldPos().toLocation(WORLD);
RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(server, location, material);
rFallingBlockEntity.setNoGravity(true);

Datei anzeigen

@ -79,6 +79,8 @@ public abstract class SimulatorElement<T extends SimulatorPhase> {
public abstract Material getWorldMaterial();
public abstract Material getWorldDisabledMaterial();
public Vector getWorldPos() {
return position;
}

Datei anzeigen

@ -44,6 +44,11 @@ public class RedstoneElement extends SimulatorElement<RedstonePhase> {
return Material.REDSTONE_BLOCK;
}
@Override
public Material getWorldDisabledMaterial() {
return Material.WHITE_STAINED_GLASS;
}
@Override
public Vector getWorldPos() {
return position.clone().add(new Vector(0.5, 0, 0.5));

Datei anzeigen

@ -82,6 +82,11 @@ public class TNTElement extends SimulatorElement<TNTPhase> {
return Material.TNT;
}
@Override
public Material getWorldDisabledMaterial() {
return Material.RED_STAINED_GLASS;
}
@Override
public void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back) {
new SimulatorTNTGui(player, simulator, this, group, back).open();

Datei anzeigen

@ -31,9 +31,12 @@ import de.steamwar.inventory.SWItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.stream.Collectors;
public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
private final SimulatorGroup simulatorGroup;
private SimulatorGroup simulatorGroup;
private final SimulatorBaseGui back;
public SimulatorGroupGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, SimulatorBaseGui back) {
@ -49,6 +52,14 @@ public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
@Override
public void headerAndFooter() {
if (simulatorGroup.getMaterial() == null) {
List<SimulatorGroup> parents = data.stream().map(e -> e.getGroup(simulator)).distinct().collect(Collectors.toList());
if (parents.size() == 1) {
simulatorGroup = parents.get(0);
data = simulatorGroup.getElements();
}
}
if (simulatorGroup.getElements().removeIf(element -> element.getPhases().isEmpty())) {
SimulatorWatcher.update(simulator);
}
@ -69,15 +80,20 @@ public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
}, clickType -> {
}));
inventory.setItem(simulatorGroup.getMaterial() != null ? 48 : 49, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open();
}));
if (simulatorGroup.getMaterial() != null) {
inventory.setItem(50, new SWItem(simulatorGroup.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
simulatorGroup.setDisabled(!simulatorGroup.isDisabled());
SimulatorWatcher.update(simulator);
}));
}
boolean disabled = simulatorGroup.getMaterial() == null ? simulatorGroup.getElements().stream().allMatch(SimulatorElement::isDisabled) : simulatorGroup.isDisabled();
inventory.setItem(50, new SWItem(disabled ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
if (simulatorGroup.getMaterial() == null) {
simulatorGroup.getElements().forEach(simulatorElement -> {
simulatorElement.setDisabled(!disabled);
});
} else {
simulatorGroup.setDisabled(!disabled);
}
SimulatorWatcher.update(simulator);
}));
}
@Override

Datei anzeigen

@ -85,14 +85,14 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open();
}));
//Settings
// Settings
inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
new SimulatorRedstoneSettingsGui(player, simulator, redstone, this).open();
}));
//Group chooser
// Group chooser
inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> {
new SimulatorGroupChooserGui(player, simulator, redstone, parent, this).open();
new SimulatorGroupChooserGui(player, simulator, redstone, redstone.getGroup(simulator), this).open();
}));
//Enable/Disable

Datei anzeigen

@ -89,7 +89,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, tnt, parent, this).open();
new SimulatorGroupChooserGui(player, simulator, tnt, tnt.getGroup(simulator), 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

@ -29,7 +29,7 @@ import java.util.List;
public abstract class SimulatorPageGui<T> extends SimulatorBaseGui {
protected int page = 0;
protected final List<T> data;
protected List<T> data;
protected SimulatorPageGui(Player player, Simulator simulator, int size, List<T> data) {
super(player, simulator, size);