Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
c327471ef2
Commit
002996afbc
@ -515,9 +515,11 @@ SIMULATOR_EDIT_PROPERTIES = §7Edit properties
|
||||
SIMULATOR_EDIT_OTHER = §7Edit other
|
||||
SIMULATOR_EDIT_GROUP = §7Edit group
|
||||
|
||||
SIMULATOR_EDIT_GROUP_MENU = §eEdit group
|
||||
|
||||
SIMULATOR_WAND_NAME = §eSimulator
|
||||
SIMULATOR_WAND_NAME_SELECTED = §7Simulator §8- §e{0}
|
||||
SIMULATOR_WAND_LORE_1 = §eRigth click §8- §7adds a position
|
||||
SIMULATOR_WAND_LORE_1 = §eRight click §8- §7adds a position
|
||||
SIMULATOR_WAND_LORE_2 = §eSneaking §8- §7Free movement
|
||||
SIMULATOR_WAND_LORE_3 = §eLeft click §8- §7Start the simulation
|
||||
SIMULATOR_WAND_LORE_4 = §eRight click in air §8- §7Opens the gui
|
||||
|
@ -516,6 +516,8 @@ SIMULATOR_EDIT_PROPERTIES = §7Editiere Eigenschaften
|
||||
SIMULATOR_EDIT_OTHER = §7Editiere Andere
|
||||
SIMULATOR_EDIT_GROUP = §7Editiere Gruppe
|
||||
|
||||
SIMULATOR_EDIT_GROUP_MENU = §eEditiere Gruppe
|
||||
|
||||
SIMULATOR_WAND_NAME = §eKanonensimulator
|
||||
SIMULATOR_WAND_NAME_SELECTED = §7Kanonensimulator §8- §e{0}
|
||||
SIMULATOR_WAND_LORE_1 = §eRechtsklick §8- §7Füge eine Position hinzu
|
||||
|
@ -73,6 +73,20 @@ public class TNTSimulator {
|
||||
return yapionObject;
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
playerShowMode.forEach((player, simulatorEntityShowMode) -> {
|
||||
simulatorEntityShowMode.hide();
|
||||
});
|
||||
}
|
||||
|
||||
public void show() {
|
||||
playerShowMode.forEach((player, simulatorEntityShowMode) -> {
|
||||
for (SimulatorElement element : tntElementList) {
|
||||
element.show(simulatorEntityShowMode);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void hide(Player player) {
|
||||
SimulatorEntityShowMode showMode = playerShowMode.get(player);
|
||||
if (showMode == null) {
|
||||
@ -103,9 +117,9 @@ public class TNTSimulator {
|
||||
});
|
||||
}
|
||||
|
||||
public void hide(TNTElement tntElement) {
|
||||
public void hide(SimulatorElement simulatorElement) {
|
||||
playerShowMode.forEach((player, simulatorEntityShowMode) -> {
|
||||
tntElement.hide(simulatorEntityShowMode);
|
||||
simulatorElement.hide(simulatorEntityShowMode);
|
||||
});
|
||||
}
|
||||
|
||||
@ -116,9 +130,9 @@ public class TNTSimulator {
|
||||
});
|
||||
}
|
||||
|
||||
public void show(TNTElement tntElement) {
|
||||
public void show(SimulatorElement simulatorElement) {
|
||||
playerShowMode.forEach((player, simulatorEntityShowMode) -> {
|
||||
tntElement.show(simulatorEntityShowMode);
|
||||
simulatorElement.show(simulatorEntityShowMode);
|
||||
});
|
||||
}
|
||||
|
||||
@ -143,6 +157,7 @@ public class TNTSimulator {
|
||||
if (spawn instanceof TNTGroup) {
|
||||
if (((TNTGroup) spawn).getElements().isEmpty()) {
|
||||
toRemove.add(spawn);
|
||||
spawn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -150,6 +165,15 @@ public class TNTSimulator {
|
||||
tntElement.close();
|
||||
}
|
||||
|
||||
public void change() {
|
||||
tntElementList.forEach(simulatorElement -> {
|
||||
simulatorElement.change();
|
||||
if (simulatorElement instanceof TNTGroup) {
|
||||
((TNTGroup) simulatorElement).getElements().forEach(SimulatorElement::change);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void edit(Player player, RayTraceResult result) {
|
||||
if (result == null) {
|
||||
TNTSimulatorGui.open(player, this, null, this::getTntElementList, null);
|
||||
|
@ -53,8 +53,6 @@ public class SimulatorSelectionGUI {
|
||||
player.closeInventory();
|
||||
});
|
||||
|
||||
// TODO: Add button to create new simulator with AnvilGUI
|
||||
|
||||
inv.open();
|
||||
}
|
||||
}
|
||||
|
@ -23,12 +23,14 @@ import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.simulator.OrderUtils;
|
||||
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
|
||||
import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
||||
import de.steamwar.bausystem.features.simulator.gui.components.ChangeMaterial;
|
||||
import de.steamwar.bausystem.features.simulator.gui.components.ChangePosition;
|
||||
import de.steamwar.bausystem.features.simulator.gui.components.Disabled;
|
||||
import de.steamwar.bausystem.features.simulator.tnt.TNTElement;
|
||||
import de.steamwar.bausystem.features.simulator.tnt.TNTGroup;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -50,14 +52,6 @@ public class TNTElementGUI {
|
||||
private static final Vector FY_VECTOR = new Vector(0, 1, 0);
|
||||
private static final Vector FZ_VECTOR = new Vector(0, 0, 1);
|
||||
|
||||
private static final List<Material> MATERIALS = new ArrayList<>();
|
||||
static {
|
||||
Arrays.stream(Material.values())
|
||||
.filter(Material::isItem)
|
||||
.filter(material -> !material.isLegacy())
|
||||
.forEach(MATERIALS::add);
|
||||
}
|
||||
|
||||
private SWInventory open(Player player, String name) {
|
||||
SWInventory inv = new SWInventory(player, 45, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_GUI_NAME", player, name));
|
||||
SWItem gray = new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§f", clickType -> {});
|
||||
@ -131,74 +125,7 @@ public class TNTElementGUI {
|
||||
Runnable editObserver = () -> {
|
||||
TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player.getInventory().getItemInMainHand());
|
||||
|
||||
// X Position
|
||||
inv.setItem(10, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(tntElement);
|
||||
tntElement.getOwnPosition().add(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR);
|
||||
if (tntSimulator != null) tntSimulator.show(tntElement);
|
||||
tntElement.change();
|
||||
}));
|
||||
inv.setItem(19, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, tntElement.getPosition().getX()), lore, false, clickType -> {
|
||||
changePosition(player, tntElement.getPosition().getX(), x -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(tntElement);
|
||||
tntElement.getOwnPosition().setX(clamp(x - tntElement.getParentPosition().getX()));
|
||||
if (tntSimulator != null) tntSimulator.show(tntElement);
|
||||
tntElement.change();
|
||||
editLocation(player, tntElement, back);
|
||||
}, () -> editLocation(player, tntElement, back));
|
||||
}));
|
||||
inv.setItem(28, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(tntElement);
|
||||
tntElement.getOwnPosition().subtract(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR);
|
||||
if (tntSimulator != null) tntSimulator.show(tntElement);
|
||||
tntElement.change();
|
||||
}));
|
||||
|
||||
// Y Position
|
||||
inv.setItem(11, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(tntElement);
|
||||
tntElement.getOwnPosition().add(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR);
|
||||
if (tntSimulator != null) tntSimulator.show(tntElement);
|
||||
tntElement.change();
|
||||
}));
|
||||
inv.setItem(20, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, tntElement.getPosition().getY()), lore, false, clickType -> {
|
||||
changePosition(player, tntElement.getPosition().getY(), y -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(tntElement);
|
||||
tntElement.getOwnPosition().setY(clamp(y - tntElement.getParentPosition().getY()));
|
||||
if (tntSimulator != null) tntSimulator.show(tntElement);
|
||||
tntElement.change();
|
||||
editLocation(player, tntElement, back);
|
||||
}, () -> editLocation(player, tntElement, back));
|
||||
}));
|
||||
inv.setItem(29, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(tntElement);
|
||||
tntElement.getOwnPosition().subtract(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR);
|
||||
if (tntSimulator != null) tntSimulator.show(tntElement);
|
||||
tntElement.change();
|
||||
}));
|
||||
|
||||
// Z Position
|
||||
inv.setItem(12, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(tntElement);
|
||||
tntElement.getOwnPosition().add(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR);
|
||||
if (tntSimulator != null) tntSimulator.show(tntElement);
|
||||
tntElement.change();
|
||||
}));
|
||||
inv.setItem(21, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, tntElement.getPosition().getZ()), lore, false, clickType -> {
|
||||
changePosition(player, tntElement.getPosition().getZ(), z -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(tntElement);
|
||||
tntElement.getOwnPosition().setZ(clamp(z - tntElement.getParentPosition().getZ()));
|
||||
if (tntSimulator != null) tntSimulator.show(tntElement);
|
||||
tntElement.change();
|
||||
editLocation(player, tntElement, back);
|
||||
}, () -> editLocation(player, tntElement, back));
|
||||
}));
|
||||
inv.setItem(30, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(tntElement);
|
||||
tntElement.getOwnPosition().subtract(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR);
|
||||
if (tntSimulator != null) tntSimulator.show(tntElement);
|
||||
tntElement.change();
|
||||
}));
|
||||
ChangePosition.show(inv, player, tntSimulator, tntElement, tntElement::getOwnPosition, x -> x - tntElement.getParentPosition().getX(), y -> y - tntElement.getParentPosition().getY(), z -> z - tntElement.getParentPosition().getZ(), () -> editLocation(player, tntElement, back));
|
||||
|
||||
// Alignment
|
||||
/*
|
||||
@ -328,36 +255,8 @@ public class TNTElementGUI {
|
||||
tntElement.change();
|
||||
}));
|
||||
|
||||
inv.setItem(21, new SWItem(tntElement.getMaterial(), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL", player), Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL_LORE_1", player, tntElement.getMaterial().name().toLowerCase()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL_LORE_2", player), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL_LORE_3", player)), false, clickType -> {
|
||||
if (clickType.isLeftClick()) {
|
||||
List<SWListInv.SWListEntry<Material>> swListEntries = new ArrayList<>();
|
||||
MATERIALS.forEach(current -> {
|
||||
swListEntries.add(new SWListInv.SWListEntry<>(new SWItem(current, BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME", player, current.name().toLowerCase()), Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_CLICK", player)), false, ignored -> {
|
||||
}), current));
|
||||
});
|
||||
SWListInv<Material> swListInv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_GUI_NAME", player), false, swListEntries, (invClickType, material) -> {
|
||||
tntElement.setMaterial(material);
|
||||
tntElement.change();
|
||||
editOther(player, tntElement, back);
|
||||
});
|
||||
swListInv.open();
|
||||
} else {
|
||||
tntElement.setMaterial(Material.TNT);
|
||||
tntElement.change();
|
||||
editOther(player, tntElement, back);
|
||||
}
|
||||
}));
|
||||
|
||||
inv.setItem(22, new SWItem(tntElement.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, BauSystem.MESSAGE.parse(tntElement.isDisabled() ? "SIMULATOR_TNT_SPAWN_DISABLED" : "SIMULATOR_TNT_SPAWN_ENABLED", player), new ArrayList<>(), !tntElement.isDisabled(), clickType -> {
|
||||
if (!tntElement.isDisabled()) {
|
||||
tntSimulator.hide(tntElement);
|
||||
}
|
||||
tntElement.setDisabled(!tntElement.isDisabled());
|
||||
if (!tntElement.isDisabled()) {
|
||||
tntSimulator.show(tntElement);
|
||||
}
|
||||
tntElement.change();
|
||||
}));
|
||||
ChangeMaterial.show(inv, player, 21, tntElement, Material.BARREL, () -> editOther(player, tntElement, back));
|
||||
Disabled.show(inv, player, 22, tntSimulator, tntElement);
|
||||
|
||||
if (!tntElement.hasParent()) {
|
||||
inv.setItem(24, new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ADD_IGNITION_PHASE", player), Arrays.asList(), false, clickType -> {
|
||||
@ -421,10 +320,6 @@ public class TNTElementGUI {
|
||||
return (byte) (b ? 10 : 1);
|
||||
}
|
||||
|
||||
private double clamp(double d) {
|
||||
return (int) (d * 100) * 0.01;
|
||||
}
|
||||
|
||||
private void changeCount(Player player, String name, int defaultValue, Consumer<Integer> result, Runnable failure) {
|
||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, name, defaultValue + "");
|
||||
swAnvilInv.setItem(Material.PAPER);
|
||||
@ -437,17 +332,4 @@ public class TNTElementGUI {
|
||||
});
|
||||
swAnvilInv.open();
|
||||
}
|
||||
|
||||
private void changePosition(Player player, double defaultValue, Consumer<Double> result, Runnable failure) {
|
||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_ANVIL_GUI_NAME", player), defaultValue + "");
|
||||
swAnvilInv.setItem(Material.PAPER);
|
||||
swAnvilInv.setCallback(s -> {
|
||||
try {
|
||||
result.accept(Double.parseDouble(s.replace(',', '.')));
|
||||
} catch (NumberFormatException e) {
|
||||
failure.run();
|
||||
}
|
||||
});
|
||||
swAnvilInv.open();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 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.simulator.gui;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
|
||||
import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
||||
import de.steamwar.bausystem.features.simulator.gui.components.ChangeMaterial;
|
||||
import de.steamwar.bausystem.features.simulator.gui.components.ChangePosition;
|
||||
import de.steamwar.bausystem.features.simulator.gui.components.Disabled;
|
||||
import de.steamwar.bausystem.features.simulator.tnt.TNTGroup;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Consumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
@UtilityClass
|
||||
public class TNTGroupEditGUI {
|
||||
|
||||
public void open(Player player, TNTGroup tntGroup, Runnable back) {
|
||||
SWInventory inv = new SWInventory(player, 45, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_GROUP_MENU", player));
|
||||
SWItem gray = new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§f", clickType -> {});
|
||||
for (int i = 0; i < 9; i++) {
|
||||
inv.setItem(i, gray);
|
||||
inv.setItem(i + 36, gray);
|
||||
}
|
||||
|
||||
if (back != null) {
|
||||
inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run()));
|
||||
}
|
||||
|
||||
String plusOneName = BauSystem.MESSAGE.parse("SIMULATOR_PLUS_ONE", player);
|
||||
String minusOneName = BauSystem.MESSAGE.parse("SIMULATOR_MINUS_ONE", player);
|
||||
List<String> plusOneFiveShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_FIVE_SHIFT", player));
|
||||
List<String> minusOneFiveShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_FIVE_SHIFT", player));
|
||||
List<String> lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player));
|
||||
|
||||
Runnable editObserver = () -> {
|
||||
TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player.getInventory().getItemInMainHand());
|
||||
|
||||
ChangePosition.show(inv, player, tntSimulator, tntGroup, tntGroup::getPosition, UnaryOperator.identity(), UnaryOperator.identity(), UnaryOperator.identity(), () -> open(player, tntGroup, back));
|
||||
ChangeMaterial.show(inv, player, 14, tntGroup, Material.BARREL, () -> open(player, tntGroup, back));
|
||||
Disabled.show(inv, player, 32, tntSimulator, tntGroup);
|
||||
|
||||
// Change TickOffset
|
||||
inv.setItem(16, new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> {
|
||||
tntGroup.setTickOffset(tntGroup.getTickOffset() + (clickType.isShiftClick() ? 5 : 1));
|
||||
tntGroup.change();
|
||||
}));
|
||||
SWItem tickItem = new SWItem(SWItem.getMaterial("DIODE"), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, tntGroup.getTickOffset()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK_ANVIL_GUI_NAME", player), tntGroup.getTickOffset(), tick -> {
|
||||
tntGroup.setTickOffset(tick);
|
||||
tntGroup.change();
|
||||
open(player, tntGroup, back);
|
||||
}, () -> open(player, tntGroup, back)));
|
||||
tickItem.getItemStack().setAmount(Math.max(tntGroup.getTickOffset(), 1));
|
||||
inv.setItem(25, tickItem);
|
||||
inv.setItem(34, new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> {
|
||||
tntGroup.setTickOffset(tntGroup.getTickOffset() - (clickType.isShiftClick() ? 5 : 1));
|
||||
tntGroup.change();
|
||||
}));
|
||||
};
|
||||
editObserver.run();
|
||||
tntGroup.register(editObserver, player::closeInventory);
|
||||
inv.addCloseRunnable(() -> tntGroup.unregister(editObserver));
|
||||
|
||||
inv.open();
|
||||
}
|
||||
|
||||
private void changeCount(Player player, String name, int defaultValue, Consumer<Integer> result, Runnable failure) {
|
||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, name, defaultValue + "");
|
||||
swAnvilInv.setItem(Material.PAPER);
|
||||
swAnvilInv.setCallback(s -> {
|
||||
try {
|
||||
result.accept(Integer.parseInt(s));
|
||||
} catch (NumberFormatException e) {
|
||||
failure.run();
|
||||
}
|
||||
});
|
||||
swAnvilInv.open();
|
||||
}
|
||||
}
|
@ -24,19 +24,30 @@ import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
||||
import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement;
|
||||
import de.steamwar.bausystem.features.simulator.tnt.TNTElement;
|
||||
import de.steamwar.bausystem.features.simulator.tnt.TNTGroup;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@UtilityClass
|
||||
public class TNTSimulatorGui {
|
||||
|
||||
private static final Vector X_VECTOR = new Vector(0.0625, 0, 0);
|
||||
private static final Vector Y_VECTOR = new Vector(0, 0.0625, 0);
|
||||
private static final Vector Z_VECTOR = new Vector(0, 0, 0.0625);
|
||||
|
||||
private static final Vector FX_VECTOR = new Vector(1, 0, 0);
|
||||
private static final Vector FY_VECTOR = new Vector(0, 1, 0);
|
||||
private static final Vector FZ_VECTOR = new Vector(0, 0, 1);
|
||||
|
||||
public void open(Player player, TNTSimulator currentTntSimulator, TNTGroup currentTntGroup, Supplier<List<SimulatorElement>> simulatorElements, Runnable back) {
|
||||
List<SWListInv.SWListEntry<SimulatorElement>> swListEntryList = new ArrayList<>();
|
||||
|
||||
@ -57,26 +68,110 @@ public class TNTSimulatorGui {
|
||||
}
|
||||
if (currentTntSimulator != null) {
|
||||
inv.setItem(49, new SWItem(Material.MAGENTA_GLAZED_TERRACOTTA, BauSystem.MESSAGE.parse("SIMULATOR_GUI_MOVE_ALL", player), clickType -> {
|
||||
moveAll(player, currentTntSimulator, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back));
|
||||
}));
|
||||
}
|
||||
if (currentTntGroup != null) {
|
||||
List<String> otherLore = new ArrayList<>();
|
||||
otherLore.add("");
|
||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, currentTntGroup.getPosition().getX()));
|
||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, currentTntGroup.getPosition().getY()));
|
||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, currentTntGroup.getPosition().getZ()));
|
||||
otherLore.add("");
|
||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME_LORE", player, currentTntGroup.getMaterial().name()));
|
||||
otherLore.add("");
|
||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, currentTntGroup.getTickOffset()));
|
||||
if (currentTntGroup.isDisabled()) {
|
||||
Runnable editObserver = () -> {
|
||||
List<String> otherLore = new ArrayList<>();
|
||||
otherLore.add("");
|
||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", player));
|
||||
}
|
||||
inv.setItem(51, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_GROUP", player), otherLore, false, clickType -> {
|
||||
}));
|
||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, currentTntGroup.getPosition().getX()));
|
||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, currentTntGroup.getPosition().getY()));
|
||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, currentTntGroup.getPosition().getZ()));
|
||||
otherLore.add("");
|
||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME_LORE", player, currentTntGroup.getMaterial().name()));
|
||||
otherLore.add("");
|
||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, currentTntGroup.getTickOffset()));
|
||||
if (currentTntGroup.isDisabled()) {
|
||||
otherLore.add("");
|
||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", player));
|
||||
}
|
||||
inv.setItem(51, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_GROUP", player), otherLore, false, clickType -> {
|
||||
TNTGroupEditGUI.open(player, currentTntGroup, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back));
|
||||
}));
|
||||
};
|
||||
editObserver.run();
|
||||
currentTntGroup.register(editObserver, player::closeInventory);
|
||||
inv.addCloseRunnable(() -> currentTntGroup.unregister(editObserver));
|
||||
}
|
||||
|
||||
inv.open();
|
||||
}
|
||||
|
||||
public void moveAll(Player player, TNTSimulator tntSimulator, Runnable back) {
|
||||
SWInventory inv = new SWInventory(player, 45, BauSystem.MESSAGE.parse("SIMULATOR_MOVE_ALL_GUI_NAME", player));
|
||||
SWItem gray = new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§f", clickType -> {});
|
||||
for (int i = 0; i < 9; i++) {
|
||||
inv.setItem(i, gray);
|
||||
inv.setItem(i + 36, gray);
|
||||
}
|
||||
|
||||
if (back != null) {
|
||||
inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run()));
|
||||
}
|
||||
|
||||
String plusOneName = BauSystem.MESSAGE.parse("SIMULATOR_PLUS_ONE", player);
|
||||
String minusOneName = BauSystem.MESSAGE.parse("SIMULATOR_MINUS_ONE", player);
|
||||
List<String> plusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_PIXEL_SHIFT", player));
|
||||
List<String> minusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_PIXEL_SHIFT", player));
|
||||
List<String> lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player));
|
||||
|
||||
// X Position
|
||||
inv.setItem(12, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
||||
tntSimulator.hide();
|
||||
moveAll(tntSimulator, clickType.isShiftClick() ? X_VECTOR : FX_VECTOR);
|
||||
tntSimulator.show();
|
||||
tntSimulator.change();
|
||||
}));
|
||||
inv.setItem(21, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_X", player), lore, false, clickType -> {}));
|
||||
inv.setItem(30, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
||||
tntSimulator.hide();
|
||||
moveAll(tntSimulator, (clickType.isShiftClick() ? X_VECTOR : FX_VECTOR).clone().multiply(-1));
|
||||
tntSimulator.show();
|
||||
tntSimulator.change();
|
||||
}));
|
||||
|
||||
// Y Position
|
||||
inv.setItem(13, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
||||
tntSimulator.hide();
|
||||
moveAll(tntSimulator, clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR);
|
||||
tntSimulator.show();
|
||||
tntSimulator.change();
|
||||
}));
|
||||
inv.setItem(22, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_Y", player), lore, false, clickType -> {}));
|
||||
inv.setItem(31, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
||||
tntSimulator.hide();
|
||||
moveAll(tntSimulator, (clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR).clone().multiply(-1));
|
||||
tntSimulator.show();
|
||||
tntSimulator.change();
|
||||
}));
|
||||
|
||||
// Z Position
|
||||
inv.setItem(14, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
||||
tntSimulator.hide();
|
||||
moveAll(tntSimulator, clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR);
|
||||
tntSimulator.show();
|
||||
tntSimulator.change();
|
||||
}));
|
||||
inv.setItem(23, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_Z", player), lore, false, clickType -> {}));
|
||||
inv.setItem(32, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
||||
tntSimulator.hide();
|
||||
moveAll(tntSimulator, (clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR).clone().multiply(-1));
|
||||
tntSimulator.show();
|
||||
}));
|
||||
|
||||
inv.open();
|
||||
}
|
||||
|
||||
public void moveAll(TNTSimulator tntSimulator, Vector vector) {
|
||||
for (SimulatorElement element : tntSimulator.getTntElementList()) {
|
||||
if (element instanceof TNTGroup) {
|
||||
TNTGroup group = (TNTGroup) element;
|
||||
group.getPosition().add(vector);
|
||||
} else if (element instanceof TNTElement) {
|
||||
TNTElement tntElement = (TNTElement) element;
|
||||
tntElement.getOwnPosition().add(vector);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 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.simulator.gui.components;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@UtilityClass
|
||||
public class ChangeMaterial {
|
||||
|
||||
private static final List<Material> MATERIALS = new ArrayList<>();
|
||||
static {
|
||||
Arrays.stream(Material.values())
|
||||
.filter(Material::isItem)
|
||||
.filter(material -> !material.isLegacy())
|
||||
.forEach(MATERIALS::add);
|
||||
}
|
||||
|
||||
public void show(SWInventory inv, Player player, int position, SimulatorElement simulatorElement, Material defaultMaterial, Runnable back) {
|
||||
inv.setItem(position, new SWItem(simulatorElement.getMaterial(), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL", player), Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL_LORE_1", player, simulatorElement.getMaterial().name().toLowerCase()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL_LORE_2", player), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL_LORE_3", player)), false, clickType -> {
|
||||
if (clickType.isLeftClick()) {
|
||||
List<SWListInv.SWListEntry<Material>> swListEntries = new ArrayList<>();
|
||||
MATERIALS.forEach(current -> {
|
||||
swListEntries.add(new SWListInv.SWListEntry<>(new SWItem(current, BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME", player, current.name().toLowerCase()), Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_CLICK", player)), false, ignored -> {
|
||||
}), current));
|
||||
});
|
||||
SWListInv<Material> swListInv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_GUI_NAME", player), false, swListEntries, (invClickType, material) -> {
|
||||
simulatorElement.setMaterial(material);
|
||||
simulatorElement.change();
|
||||
back.run();
|
||||
});
|
||||
swListInv.open();
|
||||
} else {
|
||||
simulatorElement.setMaterial(defaultMaterial);
|
||||
simulatorElement.change();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 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.simulator.gui.components;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
||||
import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Consumer;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
@UtilityClass
|
||||
public class ChangePosition {
|
||||
|
||||
private static final Vector X_VECTOR = new Vector(0.0625, 0, 0);
|
||||
private static final Vector Y_VECTOR = new Vector(0, 0.0625, 0);
|
||||
private static final Vector Z_VECTOR = new Vector(0, 0, 0.0625);
|
||||
|
||||
private static final Vector FX_VECTOR = new Vector(1, 0, 0);
|
||||
private static final Vector FY_VECTOR = new Vector(0, 1, 0);
|
||||
private static final Vector FZ_VECTOR = new Vector(0, 0, 1);
|
||||
|
||||
public void show(SWInventory inv, Player player, TNTSimulator tntSimulator, SimulatorElement simulatorElement, Supplier<Vector> toChangeVector, UnaryOperator<Double> calculatePositionX, UnaryOperator<Double> calculatePositionY, UnaryOperator<Double> calculatePositionZ, Runnable back) {
|
||||
String plusOneName = BauSystem.MESSAGE.parse("SIMULATOR_PLUS_ONE", player);
|
||||
String minusOneName = BauSystem.MESSAGE.parse("SIMULATOR_MINUS_ONE", player);
|
||||
List<String> plusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_PIXEL_SHIFT", player));
|
||||
List<String> minusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_PIXEL_SHIFT", player));
|
||||
List<String> lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player));
|
||||
|
||||
// X Position
|
||||
inv.setItem(10, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(simulatorElement);
|
||||
toChangeVector.get().add(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR);
|
||||
if (tntSimulator != null) tntSimulator.show(simulatorElement);
|
||||
simulatorElement.change();
|
||||
}));
|
||||
inv.setItem(19, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, simulatorElement.getPosition().getX()), lore, false, clickType -> {
|
||||
changePosition(player, simulatorElement.getPosition().getX(), x -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(simulatorElement);
|
||||
toChangeVector.get().setX(clamp(calculatePositionX.apply(x)));
|
||||
if (tntSimulator != null) tntSimulator.show(simulatorElement);
|
||||
simulatorElement.change();
|
||||
back.run();
|
||||
}, back);
|
||||
}));
|
||||
inv.setItem(28, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(simulatorElement);
|
||||
toChangeVector.get().subtract(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR);
|
||||
if (tntSimulator != null) tntSimulator.show(simulatorElement);
|
||||
simulatorElement.change();
|
||||
}));
|
||||
|
||||
// Y Position
|
||||
inv.setItem(11, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(simulatorElement);
|
||||
toChangeVector.get().add(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR);
|
||||
if (tntSimulator != null) tntSimulator.show(simulatorElement);
|
||||
simulatorElement.change();
|
||||
}));
|
||||
inv.setItem(20, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, simulatorElement.getPosition().getY()), lore, false, clickType -> {
|
||||
changePosition(player, simulatorElement.getPosition().getY(), y -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(simulatorElement);
|
||||
toChangeVector.get().setY(clamp(calculatePositionY.apply(y)));
|
||||
if (tntSimulator != null) tntSimulator.show(simulatorElement);
|
||||
simulatorElement.change();
|
||||
back.run();
|
||||
}, back);
|
||||
}));
|
||||
inv.setItem(29, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(simulatorElement);
|
||||
toChangeVector.get().subtract(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR);
|
||||
if (tntSimulator != null) tntSimulator.show(simulatorElement);
|
||||
simulatorElement.change();
|
||||
}));
|
||||
|
||||
// Z Position
|
||||
inv.setItem(12, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(simulatorElement);
|
||||
toChangeVector.get().add(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR);
|
||||
if (tntSimulator != null) tntSimulator.show(simulatorElement);
|
||||
simulatorElement.change();
|
||||
}));
|
||||
inv.setItem(21, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, simulatorElement.getPosition().getZ()), lore, false, clickType -> {
|
||||
changePosition(player, simulatorElement.getPosition().getZ(), z -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(simulatorElement);
|
||||
toChangeVector.get().setZ(clamp(calculatePositionZ.apply(z)));
|
||||
if (tntSimulator != null) tntSimulator.show(simulatorElement);
|
||||
simulatorElement.change();
|
||||
back.run();
|
||||
}, back);
|
||||
}));
|
||||
inv.setItem(30, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
||||
if (tntSimulator != null) tntSimulator.hide(simulatorElement);
|
||||
toChangeVector.get().subtract(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR);
|
||||
if (tntSimulator != null) tntSimulator.show(simulatorElement);
|
||||
simulatorElement.change();
|
||||
}));
|
||||
}
|
||||
|
||||
private double clamp(double d) {
|
||||
return (int) (d * 100) * 0.01;
|
||||
}
|
||||
|
||||
private void changePosition(Player player, double defaultValue, Consumer<Double> result, Runnable failure) {
|
||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_ANVIL_GUI_NAME", player), defaultValue + "");
|
||||
swAnvilInv.setItem(Material.PAPER);
|
||||
swAnvilInv.setCallback(s -> {
|
||||
try {
|
||||
result.accept(Double.parseDouble(s.replace(',', '.')));
|
||||
} catch (NumberFormatException e) {
|
||||
failure.run();
|
||||
}
|
||||
});
|
||||
swAnvilInv.open();
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 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.simulator.gui.components;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
||||
import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@UtilityClass
|
||||
public class Disabled {
|
||||
|
||||
public void show(SWInventory inv, Player player, int position, TNTSimulator tntSimulator, SimulatorElement simulatorElement) {
|
||||
inv.setItem(position, new SWItem(simulatorElement.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, BauSystem.MESSAGE.parse(simulatorElement.isDisabled() ? "SIMULATOR_TNT_SPAWN_DISABLED" : "SIMULATOR_TNT_SPAWN_ENABLED", player), new ArrayList<>(), !simulatorElement.isDisabled(), clickType -> {
|
||||
if (!simulatorElement.isDisabled()) {
|
||||
tntSimulator.hide(simulatorElement);
|
||||
}
|
||||
simulatorElement.setDisabled(!simulatorElement.isDisabled());
|
||||
if (!simulatorElement.isDisabled()) {
|
||||
tntSimulator.show(simulatorElement);
|
||||
}
|
||||
simulatorElement.change();
|
||||
}));
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.simulator.tnt;
|
||||
import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode;
|
||||
import de.steamwar.bausystem.shared.Pair;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
@ -51,6 +52,9 @@ public interface SimulatorElement {
|
||||
// Observer
|
||||
default void change() {
|
||||
observer.getOrDefault(this, new HashSet<>()).forEach(Runnable::run);
|
||||
if (this instanceof TNTGroup) {
|
||||
((TNTGroup) this).getElements().forEach(SimulatorElement::change);
|
||||
}
|
||||
}
|
||||
default void register(Runnable observer, Runnable close) {
|
||||
SimulatorElement.observer.computeIfAbsent(this, k -> new HashSet<>()).add(observer);
|
||||
@ -72,4 +76,11 @@ public interface SimulatorElement {
|
||||
closeRunnable.run();
|
||||
});
|
||||
}
|
||||
|
||||
// API
|
||||
Material getMaterial();
|
||||
void setMaterial(Material material);
|
||||
|
||||
boolean isDisabled();
|
||||
void setDisabled(boolean disabled);
|
||||
}
|
||||
|
@ -141,4 +141,12 @@ public class TNTGroup implements SimulatorElement {
|
||||
public void setTickOffset(int tickOffset) {
|
||||
this.tickOffset = tickOffset;
|
||||
}
|
||||
|
||||
public void setMaterial(Material material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public void setDisabled(boolean disabled) {
|
||||
this.disabled = disabled;
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren