Add only similar elements inside of groups
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Add delete to group gui and redstone and tnt Rework SimulatorRedstoneGui Add 'Make Group' option to SimulatorTNTGui Fix Player Join server crash Add 'Create Sim' to Select Simulator Gui
Dieser Commit ist enthalten in:
Ursprung
06a68a7004
Commit
fdc201e99d
@ -94,7 +94,9 @@ public class SimulatorCursor implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
calcCursor(event.getPlayer());
|
calcCursor(event.getPlayer());
|
||||||
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -29,6 +29,7 @@ import de.steamwar.bausystem.features.simulator.storage.SimulatorFormatSimulator
|
|||||||
import de.steamwar.bausystem.features.simulator.storage.SimulatorSaver;
|
import de.steamwar.bausystem.features.simulator.storage.SimulatorSaver;
|
||||||
import de.steamwar.bausystem.features.simulator.storage.YAPIONFormatSimulatorLoader;
|
import de.steamwar.bausystem.features.simulator.storage.YAPIONFormatSimulatorLoader;
|
||||||
import de.steamwar.bausystem.utils.ItemUtils;
|
import de.steamwar.bausystem.utils.ItemUtils;
|
||||||
|
import de.steamwar.inventory.SWAnvilInv;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import de.steamwar.linkage.MinVersion;
|
import de.steamwar.linkage.MinVersion;
|
||||||
@ -133,6 +134,28 @@ public class SimulatorStorage implements Enable {
|
|||||||
return "Simulators";
|
return "Simulators";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void headerAndFooter() {
|
||||||
|
inventory.setItem(49, new SWItem(Material.NAME_TAG, "§eCreate", clickType -> {
|
||||||
|
SWAnvilInv anvilInv = new SWAnvilInv(player, "Name");
|
||||||
|
anvilInv.setCallback(s -> {
|
||||||
|
Simulator sim = SimulatorStorage.getSimulator(s);
|
||||||
|
if (sim != null) {
|
||||||
|
BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!s.matches("[a-zA-Z_0-9-]+")) {
|
||||||
|
BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sim = new Simulator(s);
|
||||||
|
SimulatorStorage.addSimulator(s, sim);
|
||||||
|
SimulatorStorage.setSimulator(player, sim);
|
||||||
|
});
|
||||||
|
anvilInv.open();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SWItem convert(Simulator simulator) {
|
public SWItem convert(Simulator simulator) {
|
||||||
return simulator.toItem(player, clickType -> {
|
return simulator.toItem(player, clickType -> {
|
||||||
|
@ -73,7 +73,7 @@ public abstract class SimulatorElement<T extends SimulatorPhase> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void move(int x, int y, int z) {
|
public void move(double x, double y, double z) {
|
||||||
position.setX(position.getX() + x);
|
position.setX(position.getX() + x);
|
||||||
position.setY(position.getY() + y);
|
position.setY(position.getY() + y);
|
||||||
position.setZ(position.getZ() + z);
|
position.setZ(position.getZ() + z);
|
||||||
@ -83,6 +83,8 @@ public abstract class SimulatorElement<T extends SimulatorPhase> {
|
|||||||
|
|
||||||
public abstract Material getWorldDisabledMaterial();
|
public abstract Material getWorldDisabledMaterial();
|
||||||
|
|
||||||
|
public abstract boolean canBeInGroup(SimulatorGroup simulatorGroup);
|
||||||
|
|
||||||
public Vector getWorldPos() {
|
public Vector getWorldPos() {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ import org.bukkit.entity.Player;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@ -64,7 +63,7 @@ public final class SimulatorGroup {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void move(int x, int y, int z) {
|
public void move(double x, double y, double z) {
|
||||||
elements.forEach(simulatorElement -> {
|
elements.forEach(simulatorElement -> {
|
||||||
simulatorElement.move(x, y, z);
|
simulatorElement.move(x, y, z);
|
||||||
});
|
});
|
||||||
|
@ -49,6 +49,11 @@ public final class RedstoneElement extends SimulatorElement<RedstonePhase> {
|
|||||||
return Material.WHITE_STAINED_GLASS;
|
return Material.WHITE_STAINED_GLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBeInGroup(SimulatorGroup simulatorGroup) {
|
||||||
|
return simulatorGroup.getElements().stream().allMatch(RedstoneElement.class::isInstance);
|
||||||
|
}
|
||||||
|
|
||||||
@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));
|
||||||
|
@ -88,6 +88,11 @@ public final class TNTElement extends SimulatorElement<TNTPhase> {
|
|||||||
return Material.RED_STAINED_GLASS;
|
return Material.RED_STAINED_GLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBeInGroup(SimulatorGroup simulatorGroup) {
|
||||||
|
return simulatorGroup.getElements().stream().allMatch(TNTElement.class::isInstance);
|
||||||
|
}
|
||||||
|
|
||||||
@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();
|
||||||
|
@ -39,7 +39,7 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui<SimulatorGroup> {
|
|||||||
private final SimulatorBaseGui back;
|
private final SimulatorBaseGui back;
|
||||||
|
|
||||||
public SimulatorGroupChooserGui(Player player, Simulator simulator, SimulatorElement<?> subject, SimulatorGroup parent, SimulatorBaseGui back) {
|
public SimulatorGroupChooserGui(Player player, Simulator simulator, SimulatorElement<?> subject, SimulatorGroup parent, SimulatorBaseGui back) {
|
||||||
super(player, simulator, 6 * 9, simulator.getGroups().stream().filter(e -> e != parent).collect(Collectors.toList()));
|
super(player, simulator, 6 * 9, simulator.getGroups().stream().filter(e -> e != parent).filter(e -> subject.canBeInGroup(e)).collect(Collectors.toList()));
|
||||||
this.subject = subject;
|
this.subject = subject;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.back = back;
|
this.back = back;
|
||||||
|
@ -72,6 +72,11 @@ public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
|
|||||||
back.open();
|
back.open();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
|
||||||
|
simulatorGroup.getElements().clear();
|
||||||
|
SimulatorWatcher.update(simulator);
|
||||||
|
}));
|
||||||
|
|
||||||
inventory.setItem(4, simulatorGroup.toItem(player, clickType -> {
|
inventory.setItem(4, simulatorGroup.toItem(player, clickType -> {
|
||||||
if (simulatorGroup.getMaterial() == null) return;
|
if (simulatorGroup.getMaterial() == null) return;
|
||||||
new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open();
|
new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open();
|
||||||
|
@ -22,11 +22,13 @@ package de.steamwar.bausystem.features.simulator.gui;
|
|||||||
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||||
|
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
|
||||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@ -62,7 +64,8 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
|
|||||||
inventory.setItem(4, simulatorGroup.toItem(player, clickType -> {
|
inventory.setItem(4, simulatorGroup.toItem(player, clickType -> {
|
||||||
if (simulatorGroup.getMaterial() == null) return;
|
if (simulatorGroup.getMaterial() == null) return;
|
||||||
new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open();
|
new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open();
|
||||||
}, clickType -> {}));
|
}, clickType -> {
|
||||||
|
}));
|
||||||
|
|
||||||
// Base Tick
|
// Base Tick
|
||||||
int baseTicks = simulatorGroup.getBaseTick();
|
int baseTicks = simulatorGroup.getBaseTick();
|
||||||
@ -89,36 +92,84 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
|
|||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
boolean allTNT = simulatorGroup.getElements().stream().allMatch(TNTElement.class::isInstance);
|
||||||
|
|
||||||
|
if (allTNT) {
|
||||||
|
// Subpixel Alignment
|
||||||
|
inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> {
|
||||||
|
simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> {
|
||||||
|
tnt.align(new Vector(0.5, 0, 0.5));
|
||||||
|
});
|
||||||
|
SimulatorWatcher.update(simulator);
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Z
|
||||||
|
inventory.setItem(20, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> {
|
||||||
|
simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> {
|
||||||
|
tnt.align(new Vector(0, 0, 0.49));
|
||||||
|
});
|
||||||
|
SimulatorWatcher.update(simulator);
|
||||||
|
}));
|
||||||
|
|
||||||
|
inventory.setItem(22, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> {
|
||||||
|
simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> {
|
||||||
|
tnt.align(new Vector(0, 0, 0.51));
|
||||||
|
});
|
||||||
|
SimulatorWatcher.update(simulator);
|
||||||
|
}));
|
||||||
|
|
||||||
|
// X
|
||||||
|
inventory.setItem(12, new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> {
|
||||||
|
simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> {
|
||||||
|
tnt.align(new Vector(0.49, 0, 0));
|
||||||
|
});
|
||||||
|
SimulatorWatcher.update(simulator);
|
||||||
|
}));
|
||||||
|
|
||||||
|
inventory.setItem(30, new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> {
|
||||||
|
simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tnt -> {
|
||||||
|
tnt.align(new Vector(0.51, 0, 0));
|
||||||
|
});
|
||||||
|
SimulatorWatcher.update(simulator);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
//Pos X
|
//Pos X
|
||||||
inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> {
|
||||||
simulatorGroup.move(clickType.isShiftClick() ? 5 : 1, 0, 0);
|
simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0, 0);
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
});
|
});
|
||||||
inventory.setItem(24, new SWItem(Material.PAPER, "§eX"));
|
inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> {
|
||||||
inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
// TODO: Change X Anvil GUI
|
||||||
simulatorGroup.move(clickType.isShiftClick() ? -5 : -1, 0, 0);
|
}));
|
||||||
|
inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> {
|
||||||
|
simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0, 0);
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
});
|
});
|
||||||
|
|
||||||
//Pos Y
|
//Pos Y
|
||||||
inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> {
|
||||||
simulatorGroup.move(0, clickType.isShiftClick() ? 5 : 1, 0);
|
simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0);
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
});
|
});
|
||||||
inventory.setItem(25, new SWItem(Material.PAPER, "§eY"));
|
inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> {
|
||||||
inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
// TODO: Change Y Anvil GUI
|
||||||
simulatorGroup.move(0, clickType.isShiftClick() ? -5 : -1, 0);
|
}));
|
||||||
|
inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> {
|
||||||
|
simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0);
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
});
|
});
|
||||||
|
|
||||||
//Pos Z
|
//Pos Z
|
||||||
inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> {
|
||||||
simulatorGroup.move(0, 0, clickType.isShiftClick() ? 5 : 1);
|
simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1);
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
});
|
});
|
||||||
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ"));
|
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> {
|
||||||
inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
// TODO: Change Z Anvil GUI
|
||||||
simulatorGroup.move(0, 0, clickType.isShiftClick() ? -5 : -1);
|
}));
|
||||||
|
inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> {
|
||||||
|
simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1);
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -27,20 +27,25 @@ import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
|
|||||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui;
|
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
|
public class SimulatorRedstoneGui extends SimulatorScrollGui<SimulatorRedstoneGui.RedstoneSubPhase> {
|
||||||
|
|
||||||
private final SimulatorGroup parent;
|
private final SimulatorGroup parent;
|
||||||
private final RedstoneElement redstone;
|
private final RedstoneElement redstone;
|
||||||
private final SimulatorBaseGui back;
|
private final SimulatorBaseGui back;
|
||||||
|
|
||||||
public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup parent, RedstoneElement redstone, SimulatorBaseGui back) {
|
public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup parent, RedstoneElement redstone, SimulatorBaseGui back) {
|
||||||
super(player, simulator, 6 * 9, redstone.getPhases());
|
super(player, simulator, 6 * 9, new ArrayList<>());
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.redstone = redstone;
|
this.redstone = redstone;
|
||||||
this.back = back;
|
this.back = back;
|
||||||
@ -59,7 +64,12 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
redstone.sort();
|
data.clear();
|
||||||
|
redstone.getPhases().forEach(redstonePhase -> {
|
||||||
|
data.add(new RedstoneSubPhase(true, redstonePhase));
|
||||||
|
data.add(new RedstoneSubPhase(false, redstonePhase));
|
||||||
|
});
|
||||||
|
data.sort(null);
|
||||||
|
|
||||||
// Back Arrow
|
// Back Arrow
|
||||||
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
|
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
|
||||||
@ -80,6 +90,11 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
|
||||||
|
redstone.getPhases().clear();
|
||||||
|
SimulatorWatcher.update(simulator);
|
||||||
|
}));
|
||||||
|
|
||||||
// Material Chooser
|
// Material Chooser
|
||||||
inventory.setItem(4, redstone.toItem(player, clickType -> {
|
inventory.setItem(4, redstone.toItem(player, clickType -> {
|
||||||
new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open();
|
new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open();
|
||||||
@ -91,7 +106,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// Group chooser
|
// Group chooser
|
||||||
inventory.setItem(49, new SWItem(Material.LEAD, "§eMove", clickType -> {
|
inventory.setItem(49, new SWItem(Material.LEAD, "§eJoin Group", clickType -> {
|
||||||
new SimulatorGroupChooserGui(player, simulator, redstone, redstone.getGroup(simulator), this).open();
|
new SimulatorGroupChooserGui(player, simulator, redstone, redstone.getGroup(simulator), this).open();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -103,25 +118,63 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SWItem[] column(RedstonePhase redstoneSetting) {
|
public SWItem[] column(RedstoneSubPhase redstoneSubPhase, int index) {
|
||||||
SWItem redstone = new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§7 " + redstoneSetting.getTickOffset(), Arrays.asList("§7Activation Time§8:§e " + redstoneSetting.getLifetime(), "", "§7Middle-Click§8:§e Remove"), false, clickType -> {
|
// TODO: Add to the phase edit menus and split those to better reflect the scroll gui state
|
||||||
if (clickType == ClickType.MIDDLE) this.redstone.getPhases().remove(redstoneSetting);
|
int min;
|
||||||
SimulatorWatcher.update(simulator);
|
if (index % 2 == 0 && index > 0) {
|
||||||
});
|
RedstoneSubPhase subPhase = data.get(index - 1);
|
||||||
redstone.getItemStack().setAmount(Math.max(1, Math.min(redstoneSetting.getTickOffset(), 64)));
|
min = subPhase.phase.getTickOffset() + subPhase.phase.getLifetime() + 1;
|
||||||
|
} else {
|
||||||
|
min = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int max;
|
||||||
|
if (index % 2 == 0 && index < data.size() - 2) {
|
||||||
|
RedstoneSubPhase subPhase = data.get(index + 2);
|
||||||
|
max = subPhase.phase.getTickOffset() - redstoneSubPhase.phase.getLifetime() - 1;
|
||||||
|
} else if (index % 2 != 0 && index < data.size() - 1) {
|
||||||
|
RedstoneSubPhase subPhase = data.get(index + 1);
|
||||||
|
max = subPhase.phase.getTickOffset() - redstoneSubPhase.phase.getTickOffset() - 1;
|
||||||
|
} else {
|
||||||
|
max = Integer.MAX_VALUE - 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> lore = new ArrayList<>();
|
||||||
|
int time = redstoneSubPhase.phase.getTickOffset() + (redstoneSubPhase.place ? 0 : redstoneSubPhase.phase.getLifetime());
|
||||||
|
if (redstoneSubPhase.place) {
|
||||||
|
lore.add("§7Time§8:§e " + time);
|
||||||
|
lore.add("§7Order§8:§e " + redstoneSubPhase.phase.getOrder());
|
||||||
|
} else {
|
||||||
|
lore.add("§7Time§8:§e " + time);
|
||||||
|
lore.add("§7Activation Time§8:§e " + redstoneSubPhase.phase.getLifetime());
|
||||||
|
}
|
||||||
|
lore.add("");
|
||||||
|
lore.add("§7Click§8:§e Edit");
|
||||||
|
lore.add("§7Middle-Click§8:§e Remove");
|
||||||
|
SWItem redstone = new SWItem(redstoneSubPhase.place ? Material.REDSTONE_BLOCK : Material.STONE, redstoneSubPhase.place ? "§eActivate" : "§eDeactivate", lore, false, clickType -> {
|
||||||
|
if (clickType == ClickType.MIDDLE) {
|
||||||
|
this.redstone.getPhases().remove(redstoneSubPhase.phase);
|
||||||
|
SimulatorWatcher.update(simulator);
|
||||||
|
} else {
|
||||||
|
new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
redstone.getItemStack().setAmount(Math.max(1, Math.min(time, 64)));
|
||||||
|
|
||||||
|
Supplier<Integer> getter = redstoneSubPhase.place ? redstoneSubPhase.phase::getTickOffset : redstoneSubPhase.phase::getLifetime;
|
||||||
|
Consumer<Integer> setter = redstoneSubPhase.place ? redstoneSubPhase.phase::setTickOffset : redstoneSubPhase.phase::setLifetime;
|
||||||
return new SWItem[] {
|
return new SWItem[] {
|
||||||
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||||
redstoneSetting.setTickOffset(redstoneSetting.getTickOffset() + (clickType.isShiftClick() ? 5 : 1));
|
setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1)));
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
}),
|
}),
|
||||||
redstone,
|
redstone,
|
||||||
new SWItem(SWItem.getDye(redstoneSetting.getTickOffset() > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> {
|
new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> {
|
||||||
redstoneSetting.setTickOffset(Math.max(0, redstoneSetting.getTickOffset() - (clickType.isShiftClick() ? 5 : 1)));
|
setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1)));
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
}),
|
}),
|
||||||
new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> {
|
new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> {
|
||||||
new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSetting, this).open();
|
new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open();
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -132,7 +185,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
|
|||||||
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||||
addNewPhase(clickType.isShiftClick());
|
addNewPhase(clickType.isShiftClick());
|
||||||
}),
|
}),
|
||||||
new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§a New Phase", clickType -> {
|
new SWItem(Material.REDSTONE, "§eRedstone§8:§a New Phase", clickType -> {
|
||||||
addNewPhase(false);
|
addNewPhase(false);
|
||||||
}),
|
}),
|
||||||
new SWItem(SWItem.getDye(8), "§7", clickType -> {
|
new SWItem(SWItem.getDye(8), "§7", clickType -> {
|
||||||
@ -142,10 +195,39 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
|
|||||||
|
|
||||||
private void addNewPhase(boolean shift) {
|
private void addNewPhase(boolean shift) {
|
||||||
RedstonePhase lastElement = redstone.getPhases().get(redstone.getPhases().size() - 1);
|
RedstonePhase lastElement = redstone.getPhases().get(redstone.getPhases().size() - 1);
|
||||||
RedstonePhase newPhase = new RedstonePhase(lastElement.getTickOffset() + 1);
|
RedstonePhase newPhase = new RedstonePhase(lastElement.getTickOffset() + lastElement.getLifetime() + 1);
|
||||||
if (shift) newPhase.setTickOffset(newPhase.getTickOffset() + 5);
|
if (shift) newPhase.setTickOffset(newPhase.getTickOffset() + 5);
|
||||||
scroll++;
|
scroll += 2;
|
||||||
redstone.add(newPhase);
|
redstone.add(newPhase);
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class RedstoneSubPhase implements Comparable<RedstoneSubPhase> {
|
||||||
|
private boolean place;
|
||||||
|
private RedstonePhase phase;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(RedstoneSubPhase o) {
|
||||||
|
int thisTick = phase.getTickOffset() + (place ? 0 : phase.getLifetime());
|
||||||
|
int otherTick = o.phase.getTickOffset() + (o.place ? 0 : o.phase.getLifetime());
|
||||||
|
|
||||||
|
int compare = Integer.compare(thisTick, otherTick);
|
||||||
|
if (compare != 0) {
|
||||||
|
return compare;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (place && !o.place) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!place && o.place) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!place) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Integer.compare(phase.getOrder(), o.phase.getOrder());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,28 +80,44 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
|
||||||
|
tnt.getPhases().clear();
|
||||||
|
SimulatorWatcher.update(simulator);
|
||||||
|
}));
|
||||||
|
|
||||||
// Material Chooser
|
// Material Chooser
|
||||||
inventory.setItem(4, tnt.toItem(player, clickType -> {
|
inventory.setItem(4, tnt.toItem(player, clickType -> {
|
||||||
new SimulatorMaterialGui(player, simulator, tnt::getMaterial, tnt::setMaterial, this).open();
|
new SimulatorMaterialGui(player, simulator, tnt::getMaterial, tnt::setMaterial, this).open();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
|
inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
|
||||||
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(48, new SWItem(Material.LEAD, "§eJoin Group", clickType -> {
|
||||||
new SimulatorGroupChooserGui(player, simulator, tnt, tnt.getGroup(simulator), 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(Material.CHEST, parent.getElements().size() == 1 ? "§eMake Group" : "§eAdd another TNT to Group", clickType -> {
|
||||||
|
TNTElement tntElement = new TNTElement(tnt.getPosition().clone());
|
||||||
|
tntElement.add(new TNTPhase());
|
||||||
|
parent.add(tntElement);
|
||||||
|
new SimulatorGroupGui(player, simulator, parent, new SimulatorGui(player, simulator)).open();
|
||||||
|
SimulatorWatcher.update(simulator);
|
||||||
|
}));
|
||||||
|
inventory.setItem(51, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||||
tnt.setDisabled(!tnt.isDisabled());
|
tnt.setDisabled(!tnt.isDisabled());
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SWItem[] column(TNTPhase tntSetting) {
|
public SWItem[] column(TNTPhase tntSetting, int index) {
|
||||||
SWItem tnt = new SWItem(Material.TNT, "§eTNT§8:§7 " + tntSetting.getCount(), Arrays.asList("§7Tick§8: §e" + tntSetting.getTickOffset(), "§7Fuse§8:§e " + tntSetting.getLifetime(), "", "§7Order§8:§e " + tntSetting.getOrder(), "", "§7X-Jump§8: " + (tntSetting.isXJump() ? "§aOn" : "§cOff"), "§7Y-Jump§8: " + (tntSetting.isYJump() ? "§aOn" : "§cOff"), "§7Z-Jump§8: " + (tntSetting.isZJump() ? "§aOn" : "§cOff"), "", "§7Middle-Click§8:§e Remove"), false, clickType -> {
|
SWItem tnt = new SWItem(Material.TNT, "§eTNT§8:§7 " + tntSetting.getCount(), Arrays.asList("§7Tick§8: §e" + tntSetting.getTickOffset(), "§7Fuse§8:§e " + tntSetting.getLifetime(), "", "§7Order§8:§e " + tntSetting.getOrder(), "", "§7X-Jump§8: " + (tntSetting.isXJump() ? "§aOn" : "§cOff"), "§7Y-Jump§8: " + (tntSetting.isYJump() ? "§aOn" : "§cOff"), "§7Z-Jump§8: " + (tntSetting.isZJump() ? "§aOn" : "§cOff"), "", "§7Click§8:§e Edit", "§7Middle-Click§8:§e Remove"), false, clickType -> {
|
||||||
if (clickType == ClickType.MIDDLE) this.tnt.getPhases().remove(tntSetting);
|
if (clickType == ClickType.MIDDLE) {
|
||||||
|
this.tnt.getPhases().remove(tntSetting);
|
||||||
SimulatorWatcher.update(simulator);
|
SimulatorWatcher.update(simulator);
|
||||||
|
} else {
|
||||||
|
new SimulatorTNTPhaseSettingsGui(player, simulator, this.tnt, tntSetting, this).open();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
tnt.getItemStack().setAmount(Math.min(tntSetting.getCount(), 64));
|
tnt.getItemStack().setAmount(Math.min(tntSetting.getCount(), 64));
|
||||||
|
|
||||||
@ -127,7 +143,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
|
|||||||
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||||
addNewPhase(clickType.isShiftClick());
|
addNewPhase(clickType.isShiftClick());
|
||||||
}),
|
}),
|
||||||
new SWItem(Material.TNT, "§eTNT§8:§a New Phase", clickType -> {
|
new SWItem(Material.GUNPOWDER, "§eTNT§8:§a New Phase", clickType -> {
|
||||||
addNewPhase(false);
|
addNewPhase(false);
|
||||||
}),
|
}),
|
||||||
new SWItem(SWItem.getDye(8), "§7", clickType -> {
|
new SWItem(SWItem.getDye(8), "§7", clickType -> {
|
||||||
|
@ -25,8 +25,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class SimulatorAnvilGui<T extends Number> {
|
public class SimulatorAnvilGui<T extends Number> {
|
||||||
@ -37,11 +36,17 @@ public class SimulatorAnvilGui<T extends Number> {
|
|||||||
if (defaultText == null) {
|
if (defaultText == null) {
|
||||||
anvilInv = new SWAnvilInv(player, title);
|
anvilInv = new SWAnvilInv(player, title);
|
||||||
} else {
|
} else {
|
||||||
anvilInv = new SWAnvilInv(player, title, defaultText);
|
anvilInv = new SWAnvilInv(player, title + ": " + defaultText);
|
||||||
}
|
}
|
||||||
|
AtomicBoolean error = new AtomicBoolean();
|
||||||
anvilInv.addCloseCallback(() -> {
|
anvilInv.addCloseCallback(() -> {
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
|
if (error.get()) {
|
||||||
|
anvilInv.open();
|
||||||
|
} else {
|
||||||
back.open();
|
back.open();
|
||||||
|
}
|
||||||
|
error.set(false);
|
||||||
}, 0);
|
}, 0);
|
||||||
});
|
});
|
||||||
anvilInv.setCallback(s -> {
|
anvilInv.setCallback(s -> {
|
||||||
@ -49,15 +54,15 @@ public class SimulatorAnvilGui<T extends Number> {
|
|||||||
try {
|
try {
|
||||||
t = mapper.apply(s);
|
t = mapper.apply(s);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
new SimulatorAnvilGui<>(player, title, s, mapper, value, back).open();
|
error.set(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (!value.apply(t)) {
|
if (!value.apply(t)) {
|
||||||
new SimulatorAnvilGui<>(player, title, s, mapper, value, back).open();
|
error.set(true);
|
||||||
}
|
}
|
||||||
} finally {
|
} catch (Exception e) {
|
||||||
back.open();
|
// Ignore
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ public abstract class SimulatorScrollGui<T> extends SimulatorBaseGui {
|
|||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
if (scroll + i < data.size()) {
|
if (scroll + i < data.size()) {
|
||||||
T element = data.get(scroll + i);
|
T element = data.get(scroll + i);
|
||||||
SWItem[] column = column(element);
|
SWItem[] column = column(element, scroll + i);
|
||||||
populateColumn(column, i);
|
populateColumn(column, i);
|
||||||
} else {
|
} else {
|
||||||
SWItem[] column = lastColumn();
|
SWItem[] column = lastColumn();
|
||||||
@ -88,7 +88,7 @@ public abstract class SimulatorScrollGui<T> extends SimulatorBaseGui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract SWItem[] column(T t);
|
public abstract SWItem[] column(T t, int index);
|
||||||
|
|
||||||
public abstract SWItem[] lastColumn();
|
public abstract SWItem[] lastColumn();
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren