SteamWar/BauSystem2.0
Archiviert
12
0

Add only similar elements inside of groups
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:
yoyosource 2023-10-28 23:14:35 +02:00
Ursprung 06a68a7004
Commit fdc201e99d
13 geänderte Dateien mit 254 neuen und 59 gelöschten Zeilen

Datei anzeigen

@ -94,7 +94,9 @@ public class SimulatorCursor implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
calcCursor(event.getPlayer());
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
calcCursor(event.getPlayer());
}, 0);
}
@EventHandler

Datei anzeigen

@ -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.YAPIONFormatSimulatorLoader;
import de.steamwar.bausystem.utils.ItemUtils;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.MinVersion;
@ -133,6 +134,28 @@ public class SimulatorStorage implements Enable {
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
public SWItem convert(Simulator simulator) {
return simulator.toItem(player, clickType -> {

Datei anzeigen

@ -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.setY(position.getY() + y);
position.setZ(position.getZ() + z);
@ -83,6 +83,8 @@ public abstract class SimulatorElement<T extends SimulatorPhase> {
public abstract Material getWorldDisabledMaterial();
public abstract boolean canBeInGroup(SimulatorGroup simulatorGroup);
public Vector getWorldPos() {
return position;
}

Datei anzeigen

@ -30,7 +30,6 @@ import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
@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 -> {
simulatorElement.move(x, y, z);
});

Datei anzeigen

@ -49,6 +49,11 @@ public final class RedstoneElement extends SimulatorElement<RedstonePhase> {
return Material.WHITE_STAINED_GLASS;
}
@Override
public boolean canBeInGroup(SimulatorGroup simulatorGroup) {
return simulatorGroup.getElements().stream().allMatch(RedstoneElement.class::isInstance);
}
@Override
public Vector getWorldPos() {
return position.clone().add(new Vector(0.5, 0, 0.5));

Datei anzeigen

@ -88,6 +88,11 @@ public final class TNTElement extends SimulatorElement<TNTPhase> {
return Material.RED_STAINED_GLASS;
}
@Override
public boolean canBeInGroup(SimulatorGroup simulatorGroup) {
return simulatorGroup.getElements().stream().allMatch(TNTElement.class::isInstance);
}
@Override
public void open(Player player, Simulator simulator, SimulatorGroup group, SimulatorBaseGui back) {
new SimulatorTNTGui(player, simulator, this, group, back).open();

Datei anzeigen

@ -39,7 +39,7 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui<SimulatorGroup> {
private final 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.parent = parent;
this.back = back;

Datei anzeigen

@ -72,6 +72,11 @@ public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
back.open();
}));
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
simulatorGroup.getElements().clear();
SimulatorWatcher.update(simulator);
}));
inventory.setItem(4, simulatorGroup.toItem(player, clickType -> {
if (simulatorGroup.getMaterial() == null) return;
new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open();

Datei anzeigen

@ -22,11 +22,13 @@ package de.steamwar.bausystem.features.simulator.gui;
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator;
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.SimulatorBaseGui;
import de.steamwar.inventory.SWItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.Arrays;
@ -62,7 +64,8 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
inventory.setItem(4, simulatorGroup.toItem(player, clickType -> {
if (simulatorGroup.getMaterial() == null) return;
new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open();
}, clickType -> {}));
}, clickType -> {
}));
// Base Tick
int baseTicks = simulatorGroup.getBaseTick();
@ -89,36 +92,84 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
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
inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
simulatorGroup.move(clickType.isShiftClick() ? 5 : 1, 0, 0);
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() ? (allTNT ? 0.0625 : 5) : 1, 0, 0);
SimulatorWatcher.update(simulator);
});
inventory.setItem(24, new SWItem(Material.PAPER, "§eX"));
inventory.setItem(33, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
simulatorGroup.move(clickType.isShiftClick() ? -5 : -1, 0, 0);
inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> {
// TODO: Change X Anvil GUI
}));
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);
});
//Pos Y
inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
simulatorGroup.move(0, clickType.isShiftClick() ? 5 : 1, 0);
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() ? (allTNT ? 0.0625 : 5) : 1, 0);
SimulatorWatcher.update(simulator);
});
inventory.setItem(25, new SWItem(Material.PAPER, "§eY"));
inventory.setItem(34, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
simulatorGroup.move(0, clickType.isShiftClick() ? -5 : -1, 0);
inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> {
// TODO: Change Y Anvil GUI
}));
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);
});
//Pos Z
inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
simulatorGroup.move(0, 0, clickType.isShiftClick() ? 5 : 1);
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() ? (allTNT ? 0.0625 : 5) : 1);
SimulatorWatcher.update(simulator);
});
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ"));
inventory.setItem(35, SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
simulatorGroup.move(0, 0, clickType.isShiftClick() ? -5 : -1);
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> {
// TODO: Change Z Anvil GUI
}));
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);
});
}

Datei anzeigen

@ -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.SimulatorScrollGui;
import de.steamwar.inventory.SWItem;
import lombok.AllArgsConstructor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import java.util.ArrayList;
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 RedstoneElement redstone;
private final 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.redstone = redstone;
this.back = back;
@ -59,7 +64,12 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
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
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
inventory.setItem(4, redstone.toItem(player, clickType -> {
new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open();
@ -91,11 +106,11 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
}));
// 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();
}));
//Enable/Disable
// Enable/Disable
inventory.setItem(50, new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
redstone.setDisabled(!redstone.isDisabled());
SimulatorWatcher.update(simulator);
@ -103,25 +118,63 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
}
@Override
public SWItem[] column(RedstonePhase redstoneSetting) {
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 -> {
if (clickType == ClickType.MIDDLE) this.redstone.getPhases().remove(redstoneSetting);
SimulatorWatcher.update(simulator);
});
redstone.getItemStack().setAmount(Math.max(1, Math.min(redstoneSetting.getTickOffset(), 64)));
public SWItem[] column(RedstoneSubPhase redstoneSubPhase, int index) {
// TODO: Add to the phase edit menus and split those to better reflect the scroll gui state
int min;
if (index % 2 == 0 && index > 0) {
RedstoneSubPhase subPhase = data.get(index - 1);
min = subPhase.phase.getTickOffset() + subPhase.phase.getLifetime() + 1;
} else {
min = 0;
}
return new SWItem[]{
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
redstoneSetting.setTickOffset(redstoneSetting.getTickOffset() + (clickType.isShiftClick() ? 5 : 1));
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[] {
new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1)));
SimulatorWatcher.update(simulator);
}),
redstone,
new SWItem(SWItem.getDye(redstoneSetting.getTickOffset() > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> {
redstoneSetting.setTickOffset(Math.max(0, redstoneSetting.getTickOffset() - (clickType.isShiftClick() ? 5 : 1)));
new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> {
setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1)));
SimulatorWatcher.update(simulator);
}),
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 -> {
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);
}),
new SWItem(SWItem.getDye(8), "§7", clickType -> {
@ -142,10 +195,39 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<RedstonePhase> {
private void addNewPhase(boolean shift) {
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);
scroll++;
scroll += 2;
redstone.add(newPhase);
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());
}
}
}

Datei anzeigen

@ -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
inventory.setItem(4, tnt.toItem(player, clickType -> {
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();
}));
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();
}));
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());
SimulatorWatcher.update(simulator);
}));
}
@Override
public SWItem[] column(TNTPhase tntSetting) {
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 -> {
if (clickType == ClickType.MIDDLE) this.tnt.getPhases().remove(tntSetting);
SimulatorWatcher.update(simulator);
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"), "", "§7Click§8:§e Edit", "§7Middle-Click§8:§e Remove"), false, clickType -> {
if (clickType == ClickType.MIDDLE) {
this.tnt.getPhases().remove(tntSetting);
SimulatorWatcher.update(simulator);
} else {
new SimulatorTNTPhaseSettingsGui(player, simulator, this.tnt, tntSetting, this).open();
}
});
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 -> {
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);
}),
new SWItem(SWItem.getDye(8), "§7", clickType -> {

Datei anzeigen

@ -25,8 +25,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
public class SimulatorAnvilGui<T extends Number> {
@ -37,11 +36,17 @@ public class SimulatorAnvilGui<T extends Number> {
if (defaultText == null) {
anvilInv = new SWAnvilInv(player, title);
} else {
anvilInv = new SWAnvilInv(player, title, defaultText);
anvilInv = new SWAnvilInv(player, title + ": " + defaultText);
}
AtomicBoolean error = new AtomicBoolean();
anvilInv.addCloseCallback(() -> {
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
back.open();
if (error.get()) {
anvilInv.open();
} else {
back.open();
}
error.set(false);
}, 0);
});
anvilInv.setCallback(s -> {
@ -49,15 +54,15 @@ public class SimulatorAnvilGui<T extends Number> {
try {
t = mapper.apply(s);
} catch (NumberFormatException e) {
new SimulatorAnvilGui<>(player, title, s, mapper, value, back).open();
error.set(true);
return;
}
try {
if (!value.apply(t)) {
new SimulatorAnvilGui<>(player, title, s, mapper, value, back).open();
error.set(true);
}
} finally {
back.open();
} catch (Exception e) {
// Ignore
}
});
}

Datei anzeigen

@ -67,7 +67,7 @@ public abstract class SimulatorScrollGui<T> extends SimulatorBaseGui {
for (int i = 0; i < 9; i++) {
if (scroll + i < data.size()) {
T element = data.get(scroll + i);
SWItem[] column = column(element);
SWItem[] column = column(element, scroll + i);
populateColumn(column, i);
} else {
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();
}