SimRework2.0 #216
@ -59,10 +59,7 @@ import org.bukkit.event.player.*;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -279,7 +276,11 @@ public class SimulatorCursor implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pos.setX(pos.getBlockX() + 0.5);
|
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.setY(pos.getBlockY());
|
||||||
|
}
|
||||||
pos.setZ(pos.getBlockZ() + 0.5);
|
pos.setZ(pos.getBlockZ() + 0.5);
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
@ -374,12 +375,19 @@ public class SimulatorCursor implements Listener {
|
|||||||
element.open(player, simulator, group1, back);
|
element.open(player, simulator, group1, back);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Open multi element present in Simulator
|
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();
|
SimulatorGroup group2 = new SimulatorGroup();
|
||||||
group2.setMaterial(null);
|
group2.setMaterial(null);
|
||||||
group2.getElements().addAll(elements);
|
group2.getElements().addAll(elements);
|
||||||
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
|
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
|
||||||
new SimulatorGroupGui(player, simulator, group2, simulatorGui).open();
|
new SimulatorGroupGui(player, simulator, group2, simulatorGui).open();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator2;
|
package de.steamwar.bausystem.features.simulator2;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.SWUtils;
|
import de.steamwar.bausystem.SWUtils;
|
||||||
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
import de.steamwar.bausystem.features.simulator2.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui;
|
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.NamespacedKey;
|
||||||
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 java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -76,7 +78,26 @@ public class SimulatorStorage {
|
|||||||
@Override
|
@Override
|
||||||
public SWItem convert(Simulator simulator) {
|
public SWItem convert(Simulator simulator) {
|
||||||
return simulator.toItem(player, clickType -> {
|
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();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -50,14 +50,4 @@ public class SimulatorTestCommand extends SWCommand {
|
|||||||
SimulatorGroup group3 = new SimulatorGroup().add(new RedstoneElement(new Vector(-484, 47, 307)).add(new RedstonePhase()));
|
SimulatorGroup group3 = new SimulatorGroup().add(new RedstoneElement(new Vector(-484, 47, 307)).add(new RedstonePhase()));
|
||||||
SIMULATOR.getElements().add(group3);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -88,13 +88,12 @@ public class SimulatorWatcher {
|
|||||||
Map<Vector, Set<Class<?>>> positionCache = new HashMap<>();
|
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 -> {
|
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();
|
SimulatorGroup group = pair.getKey();
|
||||||
// TODO: Disabled material
|
|
||||||
SimulatorElement<?> element = pair.getValue();
|
SimulatorElement<?> element = pair.getValue();
|
||||||
|
|
||||||
boolean wasNotPresent = positionCache.computeIfAbsent(element.getPosition(), __ -> new HashSet<>())
|
boolean wasNotPresent = positionCache.computeIfAbsent(element.getPosition(), __ -> new HashSet<>())
|
||||||
.add(element.getClass());
|
.add(element.getClass());
|
||||||
if (!wasNotPresent) return;
|
if (!wasNotPresent) return;
|
||||||
Material material = element.getWorldMaterial();
|
Material material = group.isDisabled() || element.isDisabled() ? element.getWorldDisabledMaterial() : element.getWorldMaterial();
|
||||||
Location location = element.getWorldPos().toLocation(WORLD);
|
Location location = element.getWorldPos().toLocation(WORLD);
|
||||||
RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(server, location, material);
|
RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(server, location, material);
|
||||||
rFallingBlockEntity.setNoGravity(true);
|
rFallingBlockEntity.setNoGravity(true);
|
||||||
|
@ -79,6 +79,8 @@ public abstract class SimulatorElement<T extends SimulatorPhase> {
|
|||||||
|
|
||||||
public abstract Material getWorldMaterial();
|
public abstract Material getWorldMaterial();
|
||||||
|
|
||||||
|
public abstract Material getWorldDisabledMaterial();
|
||||||
|
|
||||||
public Vector getWorldPos() {
|
public Vector getWorldPos() {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,11 @@ public class RedstoneElement extends SimulatorElement<RedstonePhase> {
|
|||||||
return Material.REDSTONE_BLOCK;
|
return Material.REDSTONE_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material getWorldDisabledMaterial() {
|
||||||
|
return Material.WHITE_STAINED_GLASS;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector getWorldPos() {
|
public Vector getWorldPos() {
|
||||||
return position.clone().add(new Vector(0.5, 0, 0.5));
|
return position.clone().add(new Vector(0.5, 0, 0.5));
|
||||||
|
@ -82,6 +82,11 @@ public class TNTElement extends SimulatorElement<TNTPhase> {
|
|||||||
return Material.TNT;
|
return Material.TNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material getWorldDisabledMaterial() {
|
||||||
|
return Material.RED_STAINED_GLASS;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back) {
|
public void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back) {
|
||||||
new SimulatorTNTGui(player, simulator, this, group, back).open();
|
new SimulatorTNTGui(player, simulator, this, group, back).open();
|
||||||
|
@ -31,9 +31,12 @@ import de.steamwar.inventory.SWItem;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
|
public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
|
||||||
|
|
||||||
private final SimulatorGroup simulatorGroup;
|
private SimulatorGroup simulatorGroup;
|
||||||
private final SimulatorBaseGui back;
|
private final SimulatorBaseGui back;
|
||||||
|
|
||||||
public SimulatorGroupGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, SimulatorBaseGui back) {
|
public SimulatorGroupGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, SimulatorBaseGui back) {
|
||||||
@ -49,6 +52,14 @@ public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void headerAndFooter() {
|
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())) {
|
if (simulatorGroup.getElements().removeIf(element -> element.getPhases().isEmpty())) {
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
}
|
}
|
||||||
@ -69,16 +80,21 @@ public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
|
|||||||
}, clickType -> {
|
}, 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();
|
new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open();
|
||||||
}));
|
}));
|
||||||
if (simulatorGroup.getMaterial() != null) {
|
boolean disabled = simulatorGroup.getMaterial() == null ? simulatorGroup.getElements().stream().allMatch(SimulatorElement::isDisabled) : simulatorGroup.isDisabled();
|
||||||
inventory.setItem(50, new SWItem(simulatorGroup.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
inventory.setItem(50, new SWItem(disabled ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||||
simulatorGroup.setDisabled(!simulatorGroup.isDisabled());
|
if (simulatorGroup.getMaterial() == null) {
|
||||||
|
simulatorGroup.getElements().forEach(simulatorElement -> {
|
||||||
|
simulatorElement.setDisabled(!disabled);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
simulatorGroup.setDisabled(!disabled);
|
||||||
|
}
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SWItem convert(SimulatorElement<?> element) {
|
public SWItem convert(SimulatorElement<?> element) {
|
||||||
|
@ -85,14 +85,14 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
|
|||||||
new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open();
|
new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
//Settings
|
// Settings
|
||||||
inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
|
inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
|
||||||
new SimulatorRedstoneSettingsGui(player, simulator, redstone, this).open();
|
new SimulatorRedstoneSettingsGui(player, simulator, redstone, this).open();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
//Group chooser
|
// Group chooser
|
||||||
inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> {
|
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
|
//Enable/Disable
|
||||||
|
@ -89,7 +89,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
|
|||||||
new SimulatorTNTSettingsGui(player, simulator, tnt, this).open();
|
new SimulatorTNTSettingsGui(player, simulator, tnt, this).open();
|
||||||
}));
|
}));
|
||||||
inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> {
|
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 -> {
|
inventory.setItem(50, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||||
tnt.setDisabled(!tnt.isDisabled());
|
tnt.setDisabled(!tnt.isDisabled());
|
||||||
|
@ -29,7 +29,7 @@ import java.util.List;
|
|||||||
public abstract class SimulatorPageGui<T> extends SimulatorBaseGui {
|
public abstract class SimulatorPageGui<T> extends SimulatorBaseGui {
|
||||||
|
|
||||||
protected int page = 0;
|
protected int page = 0;
|
||||||
protected final List<T> data;
|
protected List<T> data;
|
||||||
|
|
||||||
protected SimulatorPageGui(Player player, Simulator simulator, int size, List<T> data) {
|
protected SimulatorPageGui(Player player, Simulator simulator, int size, List<T> data) {
|
||||||
super(player, simulator, size);
|
super(player, simulator, size);
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren