SteamWar/BauSystem2.0
Archiviert
12
0

SimRework2.0 #216

Zusammengeführt
YoyoNow hat 49 Commits von SimRework2.0 nach master 2023-12-16 12:30:57 +01:00 zusammengeführt
22 geänderte Dateien mit 1577 neuen und 5 gelöschten Zeilen
Nur Änderungen aus Commit fbe4f00ac0 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -0,0 +1,56 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator2;
import de.steamwar.bausystem.features.simulator2.data.Simulator;
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement;
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting;
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement;
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTSetting;
import de.steamwar.bausystem.features.simulator2.gui.SimulatorGui;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
@Linked
public class SimulatorTestCommand extends SWCommand {
private static final Simulator SIMULATOR = new Simulator("TestSim");
public SimulatorTestCommand() {
super("simtest");
SimulatorGroup group1 = new SimulatorGroup().add(new TNTElement(new Vector(0, 0, 0)).add(new TNTSetting())).add(new TNTElement(new Vector(0, 0, 0)).add(new TNTSetting()));
SIMULATOR.getElements().add(group1);
SimulatorGroup group2 = new SimulatorGroup().add(new TNTElement(new Vector(0, 0, 0)).add(new TNTSetting()));
SIMULATOR.getElements().add(group2);
SimulatorGroup group3 = new SimulatorGroup().add(new RedstoneElement(new Vector(0, 0, 0)).add(new RedstoneSetting()));
SIMULATOR.getElements().add(group3);
}
@Register
public void genericCommand(Player player, String... args) {
new SimulatorGui(player, SIMULATOR).open();
}
}

Datei anzeigen

@ -0,0 +1,64 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator2;
import de.steamwar.bausystem.features.simulator2.data.Simulator;
import de.steamwar.bausystem.shared.Pair;
import de.steamwar.linkage.Linked;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@UtilityClass
public class SimulatorWatcher {
private Map<Player, Pair<Simulator, Runnable>> watchers = new HashMap<>();
public void watch(Player player, Simulator simulator, Runnable watcher) {
if (simulator == null || watcher == null) {
watchers.remove(player);
} else {
watchers.put(player, new Pair<>(simulator, watcher));
}
}
public void update(Simulator simulator) {
new ArrayList<>(watchers.values()).forEach(simulatorRunnablePair -> {
if (simulatorRunnablePair.getKey() == simulator) {
simulatorRunnablePair.getValue().run();
}
});
}
@Linked
public static class QuitListener implements Listener {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
watchers.remove(event.getPlayer());
}
}
}

Datei anzeigen

@ -19,13 +19,26 @@
package de.steamwar.bausystem.features.simulator2.data;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.bukkit.Material;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
@RequiredArgsConstructor
public class Simulator {
private Material material = Material.BARREL;
private final String name;
private boolean autoTrace = false;
private List<SimulatorGroup> elements = new ArrayList<>();
private final List<SimulatorGroup> elements = new ArrayList<>();
public void move(int x, int y, int z) {
elements.forEach(simulatorGroup -> {
simulatorGroup.move(x, y, z);
});
}
}

Datei anzeigen

@ -19,15 +19,50 @@
package de.steamwar.bausystem.features.simulator2.data;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Material;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
public abstract class SimulatorElement<T extends SimulatorSetting> {
protected Material material;
protected Vector position;
protected final Vector position;
protected boolean disabled = false;
protected List<T> settings = new ArrayList<>();
protected final List<T> settings = new ArrayList<>();
protected SimulatorElement(Material material, Vector position) {
this.material = material;
this.position = position;
}
public SimulatorElement<T> add(T setting) {
settings.add(setting);
return this;
}
public abstract String getName();
public int getBaseTick() {
return settings.stream()
.mapToInt(value -> value.tickOffset)
.min()
.orElse(0);
}
public void changeBaseTicks(int tick) {
settings.forEach(t -> {
t.tickOffset += tick;
});
}
public void move(int x, int y, int z) {
position.setX(position.getX() + x);
position.setY(position.getY() + y);
position.setZ(position.getZ() + z);
}
}

Datei anzeigen

@ -19,13 +19,41 @@
package de.steamwar.bausystem.features.simulator2.data;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Material;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
public class SimulatorGroup {
private Material material = Material.CHEST;
protected boolean disabled = false;
private List<SimulatorElement<?>> elements = new ArrayList<>();
private final List<SimulatorElement<?>> elements = new ArrayList<>();
public SimulatorGroup add(SimulatorElement<?> element) {
elements.add(element);
return this;
}
public int getBaseTick() {
return elements.stream()
.mapToInt(SimulatorElement::getBaseTick)
.min()
.orElse(0);
}
public void changeBaseTicks(int tick) {
elements.forEach(simulatorElement -> {
simulatorElement.changeBaseTicks(tick);
});
}
public void move(int x, int y, int z) {
elements.forEach(simulatorElement -> {
simulatorElement.move(x, y, z);
});
}
}

Datei anzeigen

@ -19,6 +19,11 @@
package de.steamwar.bausystem.features.simulator2.data;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public abstract class SimulatorSetting {
protected int tickOffset;
protected int lifetime = 80;

Datei anzeigen

@ -20,7 +20,17 @@
package de.steamwar.bausystem.features.simulator2.data.redstone;
import de.steamwar.bausystem.features.simulator2.data.SimulatorElement;
import org.bukkit.Material;
import org.bukkit.util.Vector;
public class RedstoneElement extends SimulatorElement<RedstoneSetting> {
public RedstoneElement(Vector position) {
super(Material.REDSTONE_BLOCK, position);
}
@Override
public String getName() {
return "Redstone";
}
}

Datei anzeigen

@ -20,6 +20,45 @@
package de.steamwar.bausystem.features.simulator2.data.tnt;
import de.steamwar.bausystem.features.simulator2.data.SimulatorElement;
import org.bukkit.Material;
import org.bukkit.util.Vector;
public class TNTElement extends SimulatorElement<TNTSetting> {
public TNTElement(Vector position) {
super(Material.TNT, position);
}
@Override
public String getName() {
return "TNT";
}
public void move(double x, double y, double z) {
position.setX(position.getX() + x);
position.setY(position.getY() + y);
position.setZ(position.getZ() + z);
}
public void align(Vector offset) {
if (offset.getX() != 0) {
if (position.getX() - (int) position.getX() == 0.49) {
position.setX(position.getX() + 0.02);
}
if (position.getX() - (int) position.getX() == -0.49) {
position.setX(position.getX() - 0.02);
}
position.setX(position.getBlockX() + offset.getX());
}
if (offset.getZ() != 0) {
if (position.getZ() - (int) position.getZ() == 0.49) {
position.setZ(position.getZ() + 0.02);
}
if (position.getZ() - (int) position.getZ() == -0.49) {
position.setZ(position.getZ() - 0.02);
}
position.setZ(position.getBlockZ() + offset.getZ());
}
}
}

Datei anzeigen

@ -20,11 +20,14 @@
package de.steamwar.bausystem.features.simulator2.data.tnt;
import de.steamwar.bausystem.features.simulator2.data.SimulatorSetting;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class TNTSetting extends SimulatorSetting {
private int count = 1;
private boolean xJump = false;
private boolean yJump = false;
private boolean zJump = false;
}

Datei anzeigen

@ -0,0 +1,106 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator2.gui;
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.SWItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
private final SimulatorGroup simulatorGroup;
private final SimulatorBaseGui back;
public SimulatorGroupGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, SimulatorBaseGui back) {
super(player, simulator, 6 * 9, simulatorGroup.getElements());
this.simulatorGroup = simulatorGroup;
this.back = back;
}
@Override
public String baseTitle() {
return "Group";
}
@Override
public void headerAndFooter() {
if (simulatorGroup.getElements().size() < 2) {
back.open();
return;
}
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
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 -> {
new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open();
}));
inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open();
}));
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);
}));
}
@Override
public SWItem convert(SimulatorElement<?> element) {
List<String> lore = new ArrayList<>();
lore.add("§7Phase count§8:§e " + element.getSettings().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 -> {
if (element instanceof TNTElement) {
new SimulatorTNTGui(player, simulator, (TNTElement) element, this).open();
} else if (element instanceof RedstoneElement) {
new SimulatorRedstoneGui(player, simulator, simulatorGroup, (RedstoneElement) element, this).open();
}
});
}
}

Datei anzeigen

@ -0,0 +1,126 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator2.gui;
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator2.data.Simulator;
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui;
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 {
private final SimulatorGroup simulatorGroup;
private final SimulatorBaseGui back;
public SimulatorGroupSettingsGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, SimulatorBaseGui back) {
super(player, simulator, 5 * 9);
this.simulatorGroup = simulatorGroup;
this.back = back;
}
@Override
public String title() {
return "Group";
}
@Override
public void populate() {
if (simulatorGroup.getElements().size() < 2) {
back.open();
return;
}
// Back Arrow
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
back.open();
}));
// 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 -> {
new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open();
}));
// Base Tick
int baseTicks = simulatorGroup.getBaseTick();
inventory.setItem(9, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? 5 : 1);
SimulatorWatcher.update(simulator);
});
SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {});
baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64)));
inventory.setItem(18, baseTick);
inventory.setItem(27, SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
if (baseTicks - (clickType.isShiftClick() ? 5 : 1) < 0) {
simulatorGroup.changeBaseTicks(-baseTicks);
} else {
simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? -5 : -1);
}
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);
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);
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);
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);
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);
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);
SimulatorWatcher.update(simulator);
});
}
}

Datei anzeigen

@ -0,0 +1,94 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator2.gui;
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.SimulatorPageGui;
import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui;
import de.steamwar.inventory.SWItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class SimulatorGui extends SimulatorPageGui<SimulatorGroup> {
public SimulatorGui(Player player, Simulator simulator) {
super(player, simulator, 6 * 9, simulator.getElements());
}
@Override
public String baseTitle() {
return "Simulator - " + simulator.getName();
}
@Override
public void headerAndFooter() {
// TODO: Remove empty Groups
inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> {
new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open();
}));
inventory.setItem(49, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
new SimulatorSettingsGui(player, simulator, this).open();
}));
}
@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.getSettings().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 -> {
if (element instanceof TNTElement) {
new SimulatorTNTGui(player, simulator, (TNTElement) element, this).open();
} else if (element instanceof RedstoneElement) {
new SimulatorRedstoneGui(player, simulator, simulatorGroup, (RedstoneElement) element, this).open();
}
});
}
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

@ -0,0 +1,122 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator2.gui;
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator2.data.Simulator;
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement;
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting;
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.SimulatorScrollGui;
import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui;
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 SimulatorRedstoneGui extends SimulatorScrollGui<RedstoneSetting> {
private final SimulatorGroup simulatorGroup;
private final RedstoneElement redstoneElement;
private final SimulatorBaseGui back;
public SimulatorRedstoneGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, RedstoneElement redstoneElement, SimulatorBaseGui back) {
super(player, simulator, 6 * 9, redstoneElement.getSettings());
this.simulatorGroup = simulatorGroup;
this.redstoneElement = redstoneElement;
this.back = back;
}
@Override
public String baseTitle() {
return "Redstone";
}
@Override
public void headerAndFooter() {
if (redstoneElement.getSettings().isEmpty()) {
simulatorGroup.getElements().remove(redstoneElement);
back.open();
return;
}
// TODO Sort Data List
// Back Arrow
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
back.open();
}));
// Material Chooser
List<String> lore = new ArrayList<>();
lore.add("§7Activation count§8:§e " + data.size());
lore.add("§7Tick§8:§e " + redstoneElement.getBaseTick());
lore.add("");
lore.add("§7X§8:§e " + redstoneElement.getPosition().getX());
lore.add("§7Y§8:§e " + redstoneElement.getPosition().getY());
lore.add("§7Z§8:§e " + redstoneElement.getPosition().getZ());
if (redstoneElement.isDisabled()) {
lore.add("");
lore.add("§cDisabled");
}
inventory.setItem(4, new SWItem(redstoneElement.getMaterial(), "§eTNT", lore, redstoneElement.isDisabled(), clickType -> {
new SimulatorMaterialGui(player, simulator, redstoneElement::getMaterial, redstoneElement::setMaterial, this).open();
}));
//Settings
inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
new SimulatorRedstoneSettingsGui(player, simulator, redstoneElement, this).open();
}));
// 49 Lead?
//Enable/Disable
inventory.setItem(50, new SWItem(redstoneElement.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstoneElement.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
redstoneElement.setDisabled(!redstoneElement.isDisabled());
SimulatorWatcher.update(simulator);
}));
}
@Override
public SWItem[] column(RedstoneSetting redstoneSetting) {
SWItem redstone = new SWItem(Material.REDSTONE_BLOCK, "§eRedstone§8:§7 " + redstoneSetting.getTickOffset(), Arrays.asList("§7Fuse§8:§e " + redstoneSetting.getLifetime(), "", "§7Order§8:§e " + redstoneSetting.getOrder()), false, clickType -> {});
redstone.getItemStack().setAmount(Math.max(1, Math.min(redstoneSetting.getTickOffset(), 64)));
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));
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)));
SimulatorWatcher.update(simulator);
}),
new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> {
new SimulatorRedstonePhaseGui(player, simulator, redstoneElement, redstoneSetting, this).open();
}),
};
}
}

Datei anzeigen

@ -0,0 +1,73 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator2.gui;
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator2.data.Simulator;
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement;
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneSetting;
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui;
import de.steamwar.inventory.SWItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
public class SimulatorRedstonePhaseGui extends SimulatorBaseGui {
private final RedstoneElement redstoneElement;
private final RedstoneSetting redstone;
private final SimulatorBaseGui back;
public SimulatorRedstonePhaseGui(Player player, Simulator simulator, RedstoneElement redstoneElement, RedstoneSetting redstone, SimulatorBaseGui back) {
super(player, simulator, 5 * 9);
this.redstoneElement = redstoneElement;
this.redstone = redstone;
this.back = back;
}
@Override
public String title() {
return "Redstone";
}
@Override
public void populate() { // TODO: Finalize
if (!redstoneElement.getSettings().contains(redstone)) {
back.open();
return;
}
// Back Arrow
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
back.open();
}));
// Material Chooser
inventory.setItem(4, new SWItem(redstoneElement.getMaterial(), "§eRedstone", clickType -> {
new SimulatorMaterialGui(player, simulator, redstoneElement::getMaterial, redstoneElement::setMaterial, this).open();
}));
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
redstoneElement.getSettings().remove(redstone);
back.open();
SimulatorWatcher.update(simulator);
}));
}
}

Datei anzeigen

@ -0,0 +1,125 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator2.gui;
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator2.data.Simulator;
import de.steamwar.bausystem.features.simulator2.data.redstone.RedstoneElement;
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui;
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 SimulatorRedstoneSettingsGui extends SimulatorBaseGui {
private final RedstoneElement redstone;
private final SimulatorBaseGui back;
public SimulatorRedstoneSettingsGui(Player player, Simulator simulator, RedstoneElement redstone, SimulatorBaseGui back) {
super(player, simulator, 5 * 9);
this.redstone = redstone;
this.back = back;
}
@Override
public String title() {
return "Redstone";
}
@Override
public void populate() {
if (redstone.getSettings().isEmpty()) {
back.open();
return;
}
// Back Arrow
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
back.open();
}));
// Material Chooser
List<String> lore = new ArrayList<>();
lore.add("§7Activation count§8:§e " + redstone.getSettings().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 -> {
new SimulatorMaterialGui(player, simulator, redstone::getMaterial, redstone::setMaterial, this).open();
}));
// Base Tick
int baseTicks = redstone.getBaseTick();
inventory.setItem(9, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
redstone.changeBaseTicks(clickType.isShiftClick() ? 5 : 1);
SimulatorWatcher.update(simulator);
});
SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {});
baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64)));
inventory.setItem(18, baseTick);
inventory.setItem(27, SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
if (baseTicks - (clickType.isShiftClick() ? 5 : 1) < 0) {
redstone.changeBaseTicks(-baseTicks);
} else {
redstone.changeBaseTicks(clickType.isShiftClick() ? -5 : -1);
}
SimulatorWatcher.update(simulator);
});
//Pos X
inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
redstone.move(clickType.isShiftClick() ? 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 -> {
redstone.move(clickType.isShiftClick() ? -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 -> {
redstone.move(0, clickType.isShiftClick() ? 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 -> {
redstone.move(0, clickType.isShiftClick() ? -5 : -1, 0);
SimulatorWatcher.update(simulator);
});
//Pos Z
inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
redstone.move(0, 0, clickType.isShiftClick() ? 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 -> {
redstone.move(0, 0, clickType.isShiftClick() ? -5 : -1);
SimulatorWatcher.update(simulator);
});
}
}

Datei anzeigen

@ -0,0 +1,97 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator2.gui;
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator2.data.Simulator;
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui;
import de.steamwar.inventory.SWItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.Arrays;
public class SimulatorSettingsGui extends SimulatorBaseGui {
private final SimulatorBaseGui back;
public SimulatorSettingsGui(Player player, Simulator simulator, SimulatorBaseGui back) {
super(player, simulator, 5 * 9);
this.back = back;
}
@Override
public String title() {
return simulator.getName() + " Settings";
}
@Override
public void populate() {
// Back Arrow
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
back.open();
}));
// Material Chooser
inventory.setItem(4, new SWItem(simulator.getMaterial(), "§e" + simulator.getName(), clickType -> {
new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open();
}));
//AutoTrace
inventory.setItem(20, new SWItem(simulator.isAutoTrace() ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, "§eAutoTrace§8: " + (simulator.isAutoTrace() ? "§aOn" : "§cOff"), clickType -> {
simulator.setAutoTrace(!simulator.isAutoTrace());
SimulatorWatcher.update(simulator);
}));
//Pos X
inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
simulator.move(clickType.isShiftClick() ? 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 -> {
simulator.move(clickType.isShiftClick() ? -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 -> {
simulator.move(0, clickType.isShiftClick() ? 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 -> {
simulator.move(0, clickType.isShiftClick() ? -5 : -1, 0);
SimulatorWatcher.update(simulator);
});
//Pos Z
inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
simulator.move(0, 0, clickType.isShiftClick() ? 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 -> {
simulator.move(0, 0, clickType.isShiftClick() ? -5 : -1);
SimulatorWatcher.update(simulator);
});
}
}

Datei anzeigen

@ -0,0 +1,110 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator2.gui;
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator2.data.Simulator;
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement;
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTSetting;
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorScrollGui;
import de.steamwar.bausystem.features.simulator2.gui.utils.SimulatorMaterialGui;
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 SimulatorTNTGui extends SimulatorScrollGui<TNTSetting> {
private TNTElement tntElement;
private SimulatorBaseGui back;
public SimulatorTNTGui(Player player, Simulator simulator, TNTElement tntElement, SimulatorBaseGui back) {
super(player, simulator, 6 * 9, tntElement.getSettings());
this.tntElement = tntElement;
this.back = back;
}
@Override
public String baseTitle() {
return "TNT";
}
@Override
public void headerAndFooter() {
// TODO Back Jump
// Back Arrow
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
back.open();
}));
// TODO Sort Data List
// Material Chooser
List<String> lore = new ArrayList<>();
lore.add("§7Phase count§8:§e " + data.size());
lore.add("§7Tick§8:§e " + tntElement.getBaseTick());
lore.add("");
lore.add("§7X§8:§e " + tntElement.getPosition().getX());
lore.add("§7Y§8:§e " + tntElement.getPosition().getY());
lore.add("§7Z§8:§e " + tntElement.getPosition().getZ());
if (tntElement.isDisabled()) {
lore.add("");
lore.add("§cDisabled");
}
inventory.setItem(4, new SWItem(tntElement.getMaterial(), "§eTNT", lore, tntElement.isDisabled(), clickType -> {
new SimulatorMaterialGui(player, simulator, tntElement::getMaterial, tntElement::setMaterial, this).open();
}));
inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
// new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open();
}));
// 49 Lead?
inventory.setItem(50, new SWItem(tntElement.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tntElement.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
tntElement.setDisabled(!tntElement.isDisabled());
SimulatorWatcher.update(simulator);
}));
}
@Override
public SWItem[] column(TNTSetting 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")), false, clickType -> {});
tnt.getItemStack().setAmount(Math.min(tntSetting.getCount(), 64));
return new SWItem[] {
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
tntSetting.setCount(tntSetting.getCount() + (clickType.isShiftClick() ? 5 : 1));
SimulatorWatcher.update(simulator);
}),
tnt,
new SWItem(SWItem.getDye(tntSetting.getCount() > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> {
tntSetting.setCount(Math.max(1, tntSetting.getCount() - (clickType.isShiftClick() ? 5 : 1)));
SimulatorWatcher.update(simulator);
}),
new SWItem(Material.ANVIL, "§eEdit Phase", clickType -> {
// Open Edit Phase menu
}),
};
}
}

Datei anzeigen

@ -0,0 +1,148 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator2.gui;
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator2.data.Simulator;
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.utils.SimulatorMaterialGui;
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 SimulatorTNTSettingsGui extends SimulatorBaseGui {
private final TNTElement tnt;
private final SimulatorBaseGui back;
public SimulatorTNTSettingsGui(Player player, Simulator simulator, TNTElement tnt, SimulatorBaseGui back) {
super(player, simulator, 5 * 9);
this.tnt = tnt;
this.back = back;
}
@Override
public String title() {
return "TNT";
}
@Override
public void populate() {
// Back Arrow
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
back.open();
}));
// Material Chooser
List<String> lore = new ArrayList<>();
lore.add("§7Phase count§8:§e " + tnt.getSettings().size());
lore.add("§7Tick§8:§e " + tnt.getBaseTick());
if (tnt.isDisabled()) {
lore.add("");
lore.add("§cDisabled");
}
inventory.setItem(4, new SWItem(tnt.getMaterial(), "§eTNT", lore, tnt.isDisabled(), clickType -> {
new SimulatorMaterialGui(player, simulator, tnt::getMaterial, tnt::setMaterial, this).open();
}));
// Base Tick
int baseTicks = tnt.getBaseTick();
inventory.setItem(9, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
tnt.changeBaseTicks(clickType.isShiftClick() ? 5 : 1);
SimulatorWatcher.update(simulator);
});
SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {});
baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64)));
inventory.setItem(18, baseTick);
inventory.setItem(27, SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
if (baseTicks - (clickType.isShiftClick() ? 5 : 1) < 0) {
tnt.changeBaseTicks(-baseTicks);
} else {
tnt.changeBaseTicks(clickType.isShiftClick() ? -5 : -1);
}
SimulatorWatcher.update(simulator);
});
// Subpixel Alignment
inventory.setItem(24, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> {
// tnt.align(new Vector()); TODO Finalize
SimulatorWatcher.update(simulator);
}));
//z
inventory.setItem(23, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> {
SimulatorWatcher.update(simulator);
}));
inventory.setItem(25, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> {
SimulatorWatcher.update(simulator);
}));
//X
inventory.setItem(15, new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> {
SimulatorWatcher.update(simulator);
}));
inventory.setItem(33, new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> {
SimulatorWatcher.update(simulator);
}));
//Pos X
inventory.setItem(15, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> {
tnt.move(clickType.isShiftClick() ? 0.0625 : 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-0.0625"), false, clickType -> {
tnt.move(clickType.isShiftClick() ? -0.0625 : -1, 0, 0);
SimulatorWatcher.update(simulator);
});
//Pos Y
inventory.setItem(16, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> {
tnt.move(0, clickType.isShiftClick() ? 0.0625 : 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-0.0625"), false, clickType -> {
tnt.move(0, clickType.isShiftClick() ? -0.0625 : -1, 0);
SimulatorWatcher.update(simulator);
});
//Pos Z
inventory.setItem(17, SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> {
tnt.move(0, 0, clickType.isShiftClick() ? 0.0625 : 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-0.0625"), false, clickType -> {
tnt.move(0, 0, clickType.isShiftClick() ? -0.0625 : -1);
SimulatorWatcher.update(simulator);
});
}
}

Datei anzeigen

@ -0,0 +1,79 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator2.gui.base;
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator2.data.Simulator;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
public abstract class SimulatorBaseGui {
protected final Player player;
protected final Simulator simulator;
private Inventory inv;
protected SWInventory inventory;
protected final int size;
protected SimulatorBaseGui(Player player, Simulator simulator, int size) {
this.player = player;
this.simulator = simulator;
this.size = size;
}
public final void open() {
if (inv != null) {
if (player.getOpenInventory().getTopInventory() != inv) {
inventory.open();
SimulatorWatcher.watch(player, simulator, this::open);
}
player.getOpenInventory().setTitle(title());
populate();
return;
}
player.getOpenInventory().close();
inventory = new SWInventory(player, () -> {
inv = Bukkit.createInventory(null, size, title());
return inv;
});
for (int i = 0; i < 9; i++) {
inventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§8", clickType -> {}));
inventory.setItem(size - 9 + i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§8", clickType -> {}));
}
inventory.addCloseCallback(clickType -> {
SimulatorWatcher.watch(player, null, null);
});
inventory.open();
SimulatorWatcher.watch(player, simulator, this::open);
populate();
}
public abstract String title();
public abstract void populate();
}

Datei anzeigen

@ -0,0 +1,82 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator2.gui.base;
import de.steamwar.bausystem.features.simulator2.data.Simulator;
import de.steamwar.core.Core;
import de.steamwar.inventory.SWItem;
import org.bukkit.entity.Player;
import java.util.List;
public abstract class SimulatorPageGui<T> extends SimulatorBaseGui {
protected int page = 0;
protected final List<T> data;
protected SimulatorPageGui(Player player, Simulator simulator, int size, List<T> data) {
super(player, simulator, size);
this.data = data;
}
public final int maxPage() {
return data.size() / (size - 18);
}
@Override
public final String title() {
return baseTitle() + " " + (page + 1) + "/" + (maxPage() + 1);
}
@Override
public final void populate() {
headerAndFooter();
page = Math.min(page, maxPage());
inventory.setItem(size - 9, SWItem.getDye(page > 0 ? 10 : 8), page > 0 ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(page > 0 ? "SWLISINV_PREVIOUS_PAGE_ACTIVE" : "SWLISINV_PREVIOUS_PAGE_INACTIVE", player), clickType -> {
if (page > 0) {
page--;
open();
}
});
boolean hasNext = page < maxPage() - (data.size() % (size - 18) == 0 ? 1 : 0);
inventory.setItem(size - 1, SWItem.getDye(hasNext ? 10 : 8), hasNext ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(hasNext ? "SWLISINV_NEXT_PAGE_ACTIVE" : "SWLISINV_NEXT_PAGE_INACTIVE", player), clickType -> {
if (hasNext) {
page++;
open();
}
});
int minElement = page * (size - 18);
int maxElement = Math.min(data.size(), (page + 1) * (size - 18));
int index = 9;
for (int i = minElement; i < maxElement; i++) {
T element = data.get(i);
inventory.setItem(index++, convert(element));
}
}
public abstract String baseTitle();
public void headerAndFooter() {
}
public abstract SWItem convert(T t);
}

Datei anzeigen

@ -0,0 +1,80 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator2.gui.base;
import de.steamwar.bausystem.features.simulator2.data.Simulator;
import de.steamwar.core.Core;
import de.steamwar.inventory.SWItem;
import org.bukkit.entity.Player;
import java.util.List;
public abstract class SimulatorScrollGui<T> extends SimulatorBaseGui { // TODO: Last Column?
protected int scroll = 0;
protected final List<T> data;
protected SimulatorScrollGui(Player player, Simulator simulator, int size, List<T> data) {
super(player, simulator, size);
this.data = data;
}
private int maxScroll() {
return Math.max(0, Math.min(scroll, data.size() - 9));
}
@Override
public final String title() {
return baseTitle() + " " + scroll + "/" + maxScroll();
}
@Override
public final void populate() {
headerAndFooter();
scroll = maxScroll();
inventory.setItem(size - 9, SWItem.getDye(scroll > 0 ? 10 : 8), scroll > 0 ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(scroll > 0 ? "SWLISINV_PREVIOUS_PAGE_ACTIVE" : "SWLISINV_PREVIOUS_PAGE_INACTIVE", player), clickType -> {
if (scroll > 0) {
scroll = Math.max(0, scroll - 9);
open();
}
});
boolean hasNext = scroll < maxScroll() - (data.size() % 9 == 0 ? 1 : 0);
inventory.setItem(size - 1, SWItem.getDye(hasNext ? 10 : 8), hasNext ? (byte) 10 : (byte) 8, Core.MESSAGE.parse(hasNext ? "SWLISINV_NEXT_PAGE_ACTIVE" : "SWLISINV_NEXT_PAGE_INACTIVE", player), clickType -> {
if (hasNext) {
scroll = Math.min(scroll + 9, maxScroll());
open();
}
});
for (int i = 0; i < Math.min(9, data.size()); i++) {
T element = data.get(scroll + i);
SWItem[] column = column(element);
for (int j = 0; j < column.length; j++) {
inventory.setItem(i + j * 9 + 9, column[j]);
}
}
}
public abstract String baseTitle();
public void headerAndFooter() {
}
public abstract SWItem[] column(T t);
}

Datei anzeigen

@ -0,0 +1,77 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.simulator2.gui.utils;
import de.steamwar.bausystem.features.simulator2.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator2.data.Simulator;
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorBaseGui;
import de.steamwar.bausystem.features.simulator2.gui.base.SimulatorPageGui;
import de.steamwar.inventory.SWItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
public class SimulatorMaterialGui extends SimulatorPageGui<Material> {
private static final List<Material> MATERIALS = Arrays.stream(Material.values())
.filter(material -> !material.isAir())
.filter(material -> !material.isLegacy())
.filter(Material::isItem)
.collect(Collectors.toList());
private final Supplier<Material> currentMaterial;
private Material material;
private final Consumer<Material> change;
private final SimulatorBaseGui back;
public SimulatorMaterialGui(Player player, Simulator simulator, Supplier<Material> currentMaterial, Consumer<Material> change, SimulatorBaseGui back) {
super(player, simulator, 6 * 9, MATERIALS);
this.currentMaterial = currentMaterial;
this.change = change;
this.back = back;
}
@Override
public String baseTitle() {
return "Material";
}
@Override
public void headerAndFooter() {
material = currentMaterial.get();
inventory.setItem(4, new SWItem(material, "§eMaterial", clickType -> {}));
inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
back.open();
}));
}
@Override
public SWItem convert(Material material) {
return new SWItem(material, "§eNew Material", Arrays.asList(material == this.material ? "§eSelected" : "§eClick to select"), material == this.material, clickType -> {
change.accept(material);
SimulatorWatcher.update(simulator);
});
}
}