SteamWar/BauSystem2.0
Archiviert
12
0

Add edit properties menu and edit location menu
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-06-10 11:07:47 +02:00
Ursprung 804afe9cb7
Commit 11560865a8
6 geänderte Dateien mit 355 neuen und 35 gelöschten Zeilen

Datei anzeigen

@ -106,6 +106,12 @@ public class TNTSimulator {
}); });
} }
public void hide(TNTElement tntElement) {
playerShowMode.forEach((player, simulatorEntityShowMode) -> {
tntElement.hide(simulatorEntityShowMode);
});
}
public void show(Player player) { public void show(Player player) {
SimulatorEntityShowMode showMode = playerShowMode.computeIfAbsent(player, SimulatorEntityShowMode::new); SimulatorEntityShowMode showMode = playerShowMode.computeIfAbsent(player, SimulatorEntityShowMode::new);
tntElementList.forEach(simulatorElement -> { tntElementList.forEach(simulatorElement -> {
@ -113,6 +119,12 @@ public class TNTSimulator {
}); });
} }
public void show(TNTElement tntElement) {
playerShowMode.forEach((player, simulatorEntityShowMode) -> {
tntElement.show(simulatorEntityShowMode);
});
}
public List<Entity> getEntities() { public List<Entity> getEntities() {
return tntElementList.stream().flatMap(element -> element.getEntities().stream()).collect(Collectors.toList()); return tntElementList.stream().flatMap(element -> element.getEntities().stream()).collect(Collectors.toList());
} }
@ -129,7 +141,7 @@ public class TNTSimulator {
if (result == null) { if (result == null) {
TNTSimulatorGui.open(player, vector -> { TNTSimulatorGui.open(player, vector -> {
}, getTntElementList(), null); }, null, getTntElementList(), null);
return; return;
} }
@ -142,7 +154,7 @@ public class TNTSimulator {
if (elements.size() == 1) { if (elements.size() == 1) {
TNTElementGUI.open(player, (TNTElement) elements.get(0), null); TNTElementGUI.open(player, (TNTElement) elements.get(0), null);
} else { } else {
TNTSimulatorGui.open(player, null, elements, null); TNTSimulatorGui.open(player, null, null, elements, null);
} }
return; return;
} }

Datei anzeigen

@ -47,6 +47,7 @@ import java.util.function.Function;
public class TNTSimulatorListener implements Listener { public class TNTSimulatorListener implements Listener {
private boolean permissionCheck(Player player) { private boolean permissionCheck(Player player) {
if (true) return true;
if (!Permission.hasPermission(player, Permission.WORLD)) { if (!Permission.hasPermission(player, Permission.WORLD)) {
BauSystem.MESSAGE.send("SIMULATOR_NO_PERMS", player); BauSystem.MESSAGE.send("SIMULATOR_NO_PERMS", player);
return false; return false;

Datei anzeigen

@ -20,19 +20,41 @@
package de.steamwar.bausystem.features.simulatorn.gui; package de.steamwar.bausystem.features.simulatorn.gui;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.simulatorn.SimulatorStorage;
import de.steamwar.bausystem.features.simulatorn.TNTSimulator;
import de.steamwar.bausystem.features.simulatorn.tnt.TNTElement; import de.steamwar.bausystem.features.simulatorn.tnt.TNTElement;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Consumer;
import org.bukkit.util.Vector;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
@UtilityClass @UtilityClass
public class TNTElementGUI { public class TNTElementGUI {
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);
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) { private SWInventory open(Player player, String name) {
SWInventory inv = new SWInventory(player, 45, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_GUI_NAME", player, 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 -> {}); SWItem gray = new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§f", clickType -> {});
@ -49,35 +71,40 @@ public class TNTElementGUI {
inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run()));
} }
List<String> locationLore = new ArrayList<>(); Runnable editObserver = () -> {
locationLore.add(""); List<String> locationLore = new ArrayList<>();
locationLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, tntElement.getPosition().getX())); locationLore.add("");
locationLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, tntElement.getPosition().getY())); locationLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, tntElement.getPosition().getX()));
locationLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, tntElement.getPosition().getZ())); locationLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, tntElement.getPosition().getY()));
inv.setItem(20, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_LOCATION", player), locationLore, false, clickType -> { locationLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, tntElement.getPosition().getZ()));
editLocation(player, tntElement, () -> open(player, tntElement, back)); inv.setItem(20, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_LOCATION", player), locationLore, false, clickType -> {
})); editLocation(player, tntElement, () -> open(player, tntElement, back));
}));
List<String> propertiesLore = new ArrayList<>(); List<String> propertiesLore = new ArrayList<>();
propertiesLore.add(""); propertiesLore.add("");
propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_COUNT", player, tntElement.getCount())); propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_COUNT", player, tntElement.getCount()));
propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, tntElement.getTickOffset())); propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, tntElement.getTickOffset()));
propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_FUSE", player, tntElement.getFuseTicks())); propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_FUSE", player, tntElement.getFuseTicks()));
propertiesLore.add(""); propertiesLore.add("");
propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_X", player, active(player, tntElement.isXVelocity()))); propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_X", player, active(player, tntElement.isXVelocity())));
propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Y", player, active(player, tntElement.isYVelocity()))); propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Y", player, active(player, tntElement.isYVelocity())));
propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Z", player, active(player, tntElement.isZVelocity()))); propertiesLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Z", player, active(player, tntElement.isZVelocity())));
inv.setItem(22, new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_PROPERTIES", player), propertiesLore, false, clickType -> { inv.setItem(22, new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_PROPERTIES", player), propertiesLore, false, clickType -> {
editProperties(player, tntElement, () -> open(player, tntElement, back)); editProperties(player, tntElement, () -> open(player, tntElement, back));
})); }));
List<String> otherLore = new ArrayList<>(); List<String> otherLore = new ArrayList<>();
otherLore.add(""); otherLore.add("");
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ACTIVATED_WITH", player, activationType(player, tntElement.getOrder()))); otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ACTIVATED_WITH", player, activationType(player, tntElement.getOrder())));
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME_LORE", player, tntElement.getMaterial().name())); otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME_LORE", player, tntElement.getMaterial().name()));
inv.setItem(24, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_OTHER", player), otherLore, false, clickType -> { inv.setItem(24, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_OTHER", player), otherLore, false, clickType -> {
editOther(player, tntElement, () -> open(player, tntElement, back)); editOther(player, tntElement, () -> open(player, tntElement, back));
})); }));
};
editObserver.run();
tntElement.register(editObserver);
inv.addCloseRunnable(() -> tntElement.unregister(editObserver));
inv.open(); inv.open();
} }
@ -88,6 +115,88 @@ public class TNTElementGUI {
inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); 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));
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();
}));
};
editObserver.run();
tntElement.register(editObserver);
inv.addCloseRunnable(() -> tntElement.unregister(editObserver));
inv.open(); inv.open();
} }
@ -97,6 +206,94 @@ public class TNTElementGUI {
inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); 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 = () -> {
// Change Count of spawned TNT
inv.setItem(10, new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> {
tntElement.setCount(tntElement.getCount() + ((clickType.isShiftClick()) ? 5 : 1));
tntElement.change();
}));
SWItem countItem = new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_COUNT", player, tntElement.getCount()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_COUNT_ANVIL_GUI_NAME", player), tntElement.getCount(), c -> {
tntElement.setCount(c);
tntElement.change();
editProperties(player, tntElement, back);
}, () -> editProperties(player, tntElement, back)));
countItem.getItemStack().setAmount(tntElement.getCount());
inv.setItem(19, countItem);
inv.setItem(28, new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> {
tntElement.setCount(tntElement.getCount() - ((clickType.isShiftClick()) ? 5 : 1));
tntElement.change();
}));
// Change TickOffset
inv.setItem(11, new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> {
tntElement.setTickOffset(tntElement.getOwnTickOffset() + (clickType.isShiftClick() ? 5 : 1));
tntElement.change();
}));
SWItem tickItem = new SWItem(SWItem.getMaterial("DIODE"), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, tntElement.getTickOffset()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK_ANVIL_GUI_NAME", player), tntElement.getTickOffset(), tick -> {
tntElement.setTickOffset(tick - tntElement.getParentTickOffset());
tntElement.change();
editProperties(player, tntElement, back);
}, () -> editProperties(player, tntElement, back)));
tickItem.getItemStack().setAmount(Math.max(tntElement.getTickOffset(), 1));
inv.setItem(20, tickItem);
inv.setItem(29, new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> {
tntElement.setTickOffset(tntElement.getOwnTickOffset() - (clickType.isShiftClick() ? 5 : 1));
tntElement.change();
}));
// Change FuseTicks
inv.setItem(12, new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> {
tntElement.setFuseTicks(tntElement.getFuseTicks() + (clickType.isShiftClick() ? 5 : 1));
tntElement.change();
}));
SWItem fuseTickItem = new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_FUSE", player, tntElement.getFuseTicks()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_FUSE_ANVIL_GUI_NAME", player), tntElement.getFuseTicks(), tick -> {
tntElement.setFuseTicks(tick);
tntElement.change();
editProperties(player, tntElement, back);
}, () -> editProperties(player, tntElement, back)));
fuseTickItem.getItemStack().setAmount(Math.max(tntElement.getFuseTicks(), 1));
inv.setItem(21, fuseTickItem);
inv.setItem(30, new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> {
tntElement.setFuseTicks(tntElement.getFuseTicks() - (clickType.isShiftClick() ? 5 : 1));
tntElement.change();
}));
// Velocity Settings
inv.setItem(24, Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_NAME", player), clickType -> {
if (tntElement.isXVelocity() || tntElement.isYVelocity() || tntElement.isZVelocity()) {
tntElement.setXVelocity(false);
tntElement.setYVelocity(false);
tntElement.setZVelocity(false);
} else {
tntElement.setXVelocity(true);
tntElement.setYVelocity(true);
tntElement.setZVelocity(true);
}
tntElement.change();
});
inv.setItem(32, new SWItem(getWool(tntElement.isXVelocity()), getColor(tntElement.isXVelocity()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_X", player, active(player, tntElement.isXVelocity())), clickType -> {
tntElement.setXVelocity(!tntElement.isXVelocity());
tntElement.change();
}));
inv.setItem(15, new SWItem(getWool(tntElement.isYVelocity()), getColor(tntElement.isYVelocity()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Y", player, active(player, tntElement.isYVelocity())), clickType -> {
tntElement.setYVelocity(!tntElement.isYVelocity());
tntElement.change();
}));
inv.setItem(34, new SWItem(getWool(tntElement.isZVelocity()), getColor(tntElement.isZVelocity()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Z", player, active(player, tntElement.isZVelocity())), clickType -> {
tntElement.setZVelocity(!tntElement.isZVelocity());
tntElement.change();
}));
};
editObserver.run();
tntElement.register(editObserver);
inv.addCloseRunnable(() -> tntElement.unregister(editObserver));
inv.open(); inv.open();
} }
@ -106,6 +303,13 @@ public class TNTElementGUI {
inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run()));
} }
Runnable editObserver = () -> {
};
editObserver.run();
tntElement.register(editObserver);
inv.addCloseRunnable(() -> tntElement.unregister(editObserver));
inv.open(); inv.open();
} }
@ -128,4 +332,42 @@ public class TNTElementGUI {
} }
return BauSystem.MESSAGE.parse(s, p); return BauSystem.MESSAGE.parse(s, p);
} }
private Material getWool(boolean b) {
return b ? Material.LIME_WOOL : Material.RED_WOOL;
}
private byte getColor(boolean b) {
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);
swAnvilInv.setCallback(s -> {
try {
result.accept(Integer.parseInt(s));
} catch (NumberFormatException e) {
failure.run();
}
});
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();
}
} }

Datei anzeigen

@ -37,7 +37,7 @@ import java.util.function.Consumer;
@UtilityClass @UtilityClass
public class TNTSimulatorGui { public class TNTSimulatorGui {
public void open(Player player, Consumer<Vector> moveAll, List<SimulatorElement> simulatorElements, Runnable back) { public void open(Player player, Consumer<Vector> moveAll, Consumer<Material> materialChanger, List<SimulatorElement> simulatorElements, Runnable back) {
List<SWListInv.SWListEntry<SimulatorElement>> swListEntryList = new ArrayList<>(); List<SWListInv.SWListEntry<SimulatorElement>> swListEntryList = new ArrayList<>();
for (SimulatorElement element : simulatorElements) { for (SimulatorElement element : simulatorElements) {
@ -50,9 +50,9 @@ public class TNTSimulatorGui {
List<SimulatorElement> elements = new ArrayList<>(tntGroup.getElements()); List<SimulatorElement> elements = new ArrayList<>(tntGroup.getElements());
open(player, vector -> { open(player, vector -> {
}, elements, () -> open(player, moveAll, simulatorElements, back)); }, material -> {}, elements, () -> open(player, moveAll, materialChanger, simulatorElements, back));
} else { } else {
TNTElementGUI.open(player, (TNTElement) simulatorElement, () -> open(player, moveAll, simulatorElements, back)); TNTElementGUI.open(player, (TNTElement) simulatorElement, () -> open(player, moveAll, materialChanger, simulatorElements, back));
} }
}); });
if (back != null) { if (back != null) {

Datei anzeigen

@ -24,15 +24,15 @@ import de.steamwar.bausystem.shared.Pair;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONObject;
import java.util.List; import java.util.*;
import java.util.Map;
public interface SimulatorElement { public interface SimulatorElement {
Map<SimulatorElement, Set<Runnable>> observer = new HashMap<>();
YAPIONObject toYAPION(); YAPIONObject toYAPION();
List<Entity> getEntities(); List<Entity> getEntities();
void getEntity(List<SimulatorElement> elements, Entity entity); void getEntity(List<SimulatorElement> elements, Entity entity);
@ -45,4 +45,18 @@ public interface SimulatorElement {
SWItem menu(Player p); SWItem menu(Player p);
void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result); // Ticks to subtick order to spawning runnable to count of activations void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result); // Ticks to subtick order to spawning runnable to count of activations
// Observer
default void change() {
observer.getOrDefault(this, new HashSet<>()).forEach(Runnable::run);
}
default void register(Runnable observer) {
SimulatorElement.observer.computeIfAbsent(this, k -> new HashSet<>()).add(observer);
}
default void unregister(Runnable observer) {
SimulatorElement.observer.computeIfPresent(this, (k, v) -> {
v.remove(observer);
return v.isEmpty() ? null : v;
});
}
} }

Datei anzeigen

@ -27,6 +27,7 @@ import de.steamwar.bausystem.shared.Pair;
import de.steamwar.bausystem.shared.Position; import de.steamwar.bausystem.shared.Position;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -46,8 +47,14 @@ public class TNTElement implements SimulatorElement {
private int fuseTicks = 80; private int fuseTicks = 80;
private int count = 1; private int count = 1;
private int tickOffset = 0; private int tickOffset = 0;
@Setter
private boolean xVelocity = false; private boolean xVelocity = false;
@Setter
private boolean yVelocity = false; private boolean yVelocity = false;
@Setter
private boolean zVelocity = false; private boolean zVelocity = false;
private int order = 0; private int order = 0;
private Material material = Material.TNT; private Material material = Material.TNT;
@ -91,12 +98,14 @@ public class TNTElement implements SimulatorElement {
@Override @Override
public List<Entity> getEntities() { public List<Entity> getEntities() {
if (disabled) return new ArrayList<>(); if (disabled) return new ArrayList<>();
entity.setPosition(getPosition());
return Arrays.asList(entity.getBukkitEntity()); return Arrays.asList(entity.getBukkitEntity());
} }
@Override @Override
public void getEntity(List<SimulatorElement> elements, Entity entity) { public void getEntity(List<SimulatorElement> elements, Entity entity) {
if (disabled) return; if (disabled) return;
this.entity.setPosition(getPosition());
if (this.entity.getId() == entity.getEntityId() || getPosition().equals(entity.getLocation().toVector())) { if (this.entity.getId() == entity.getEntityId() || getPosition().equals(entity.getLocation().toVector())) {
elements.add(this); elements.add(this);
} }
@ -120,12 +129,14 @@ public class TNTElement implements SimulatorElement {
@Override @Override
public void show(SimulatorEntityShowMode showMode) { public void show(SimulatorEntityShowMode showMode) {
if (disabled) return; if (disabled) return;
entity.setPosition(getPosition());
showMode.show(new Position(getPosition())); showMode.show(new Position(getPosition()));
} }
@Override @Override
public void hide(SimulatorEntityShowMode showMode) { public void hide(SimulatorEntityShowMode showMode) {
if (disabled) return; if (disabled) return;
entity.setPosition(getPosition());
showMode.hide(new Position(getPosition())); showMode.hide(new Position(getPosition()));
} }
@ -158,4 +169,44 @@ public class TNTElement implements SimulatorElement {
}); });
}, count)); }, count));
} }
public void setCount(int count) {
if (count < 0) count = 1;
if (count > 400) count = 400;
this.count = count;
}
public int getOwnTickOffset() {
return tickOffset;
}
public int getParentTickOffset() {
if (tntGroup != null) {
return tntGroup.getTickOffset();
}
return 0;
}
public void setTickOffset(int tickOffset) {
if (tickOffset < 0) tickOffset = 0;
if (tickOffset > 400) tickOffset = 400;
this.tickOffset = tickOffset;
}
public void setFuseTicks(int fuseTicks) {
if (fuseTicks < 0) fuseTicks = 0;
if (fuseTicks > 160) fuseTicks = 160;
this.fuseTicks = fuseTicks;
}
public Vector getOwnPosition() {
return position;
}
public Vector getParentPosition() {
if (tntGroup != null) {
return tntGroup.getPosition();
}
return new Vector(0, 0, 0);
}
} }