SteamWar/BauSystem2.0
Archiviert
12
0

Add OrderUtils
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Update some menus

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-06-10 14:00:42 +02:00
Ursprung 11560865a8
Commit b755b89a8c
4 geänderte Dateien mit 125 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -592,10 +592,13 @@ SIMULATOR_TNT_SPAWN_VELOCITY_OFF = §coff
SIMULATOR_TNT_SPAWN_POSITION_X = §7x-Position §8- §e{0}
SIMULATOR_TNT_SPAWN_POSITION_Y = §7y-Position §8- §e{0}
SIMULATOR_TNT_SPAWN_POSITION_Z = §7z-Position §8- §e{0}
SIMULATOR_TNT_SPAWN_ACTIVATED_NAME = §7Primed by
SIMULATOR_TNT_SPAWN_ACTIVATED_WITH = §7Primed by §8- §e{0}
SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_COMPARATOR = Comparator
SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_REPEATER = Repeater
SIMULATOR_TNT_SPAWN_ACTIVATED_UNKNOWN = Unknown
SIMULATOR_TNT_SPAWN_INACTIVE = §7> §7{0}
SIMULATOR_TNT_SPAWN_ACTIVE = §e> §7{0}
SIMULATOR_TNT_SPAWN_MATERIAL = §eMaterial
SIMULATOR_TNT_SPAWN_MATERIAL_LORE_1 = §7Current material§8: §e{0}
SIMULATOR_TNT_SPAWN_MATERIAL_LORE_2 = §eLeft-Click §7to change

Datei anzeigen

@ -0,0 +1,93 @@
/*
* 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.simulatorn;
import de.steamwar.bausystem.BauSystem;
import lombok.experimental.UtilityClass;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@UtilityClass
public class OrderUtils {
private final List<Material> activationOrder = new ArrayList<>();
private final Map<Material, String> nameMap = new HashMap<>();
private final Map<Integer, Material> reverseActivationOrderLookupTable = new HashMap<>();
static {
add(Material.REPEATER, "SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_REPEATER");
add(Material.COMPARATOR, "SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_COMPARATOR");
}
public Material next(Material material) {
int index = activationOrder.indexOf(material);
if (index == -1) {
return activationOrder.get(0);
}
if (index + 1 >= activationOrder.size()) {
return activationOrder.get(0);
}
return activationOrder.get(index + 1);
}
public Material previous(Material material) {
int index = activationOrder.indexOf(material);
if (index == -1) {
return activationOrder.get(0);
}
if (index - 1 < 0) {
return activationOrder.get(activationOrder.size() - 1);
}
return activationOrder.get(index - 1);
}
public List<String> orderList(Material material, Player player) {
List<String> lore = new ArrayList<>();
for (Material m : activationOrder) {
String element = BauSystem.MESSAGE.parse(name(m), player);
if (m == material) {
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ACTIVE", player, element));
} else {
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_INACTIVE", player, element));
}
}
return lore;
}
public int order(Material material) {
return activationOrder.indexOf(material);
}
public String name(Material material) {
return nameMap.getOrDefault(material, "SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_UNKNOWN");
}
private void add(Material material, String name) {
activationOrder.add(material);
reverseActivationOrderLookupTable.put(activationOrder.size() - 1, material);
nameMap.put(material, name);
}
}

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.bausystem.features.simulatorn.gui;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.simulatorn.OrderUtils;
import de.steamwar.bausystem.features.simulatorn.SimulatorStorage;
import de.steamwar.bausystem.features.simulatorn.TNTSimulator;
import de.steamwar.bausystem.features.simulatorn.tnt.TNTElement;
@ -96,7 +97,7 @@ public class TNTElementGUI {
List<String> otherLore = new ArrayList<>();
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, BauSystem.MESSAGE.parse(OrderUtils.name(tntElement.getOrder()), player)));
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 -> {
editOther(player, tntElement, () -> open(player, tntElement, back));
@ -192,6 +193,12 @@ public class TNTElementGUI {
if (tntSimulator != null) tntSimulator.show(tntElement);
tntElement.change();
}));
// Alignment
/*
inv.setItem(24, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("", player), clickType -> {
}));
*/
};
editObserver.run();
tntElement.register(editObserver);
@ -304,7 +311,14 @@ public class TNTElementGUI {
}
Runnable editObserver = () -> {
inv.setItem(42, new SWItem(tntElement.getOrder(), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ACTIVATED_NAME", player), OrderUtils.orderList(tntElement.getOrder(), player), false, clickType -> {
if (clickType.isShiftClick()) {
tntElement.setOrder(OrderUtils.previous(tntElement.getOrder()));
} else {
tntElement.setOrder(OrderUtils.next(tntElement.getOrder()));
}
tntElement.change();
}));
};
editObserver.run();
tntElement.register(editObserver);
@ -317,22 +331,6 @@ public class TNTElementGUI {
return active ? BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_ON", p) : BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_OFF", p);
}
private String activationType(Player p, int order) {
String s;
switch (order) {
case 0:
s = "SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_REPEATER";
break;
case 1:
s = "SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_COMPARATOR";
break;
default:
s = "SIMULATOR_TNT_SPAWN_ACTIVATED_UNKNOWN";
break;
}
return BauSystem.MESSAGE.parse(s, p);
}
private Material getWool(boolean b) {
return b ? Material.LIME_WOOL : Material.RED_WOOL;
}

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.simulatorn.tnt;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
import de.steamwar.bausystem.features.simulatorn.OrderUtils;
import de.steamwar.bausystem.features.simulatorn.SimulatorStorage;
import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode;
import de.steamwar.bausystem.shared.Pair;
@ -56,7 +57,7 @@ public class TNTElement implements SimulatorElement {
@Setter
private boolean zVelocity = false;
private int order = 0;
private Material order = Material.REPEATER;
private Material material = Material.TNT;
private boolean disabled = false;
@ -74,7 +75,11 @@ public class TNTElement implements SimulatorElement {
this.xVelocity = yapionObject.getBooleanOrDefault("xVelocity", false);
this.yVelocity = yapionObject.getBooleanOrDefault("yVelocity", false);
this.zVelocity = yapionObject.getBooleanOrDefault("zVelocity", false);
this.order = yapionObject.getIntOrDefault("order", yapionObject.getBooleanOrDefault("comparator", false) ? 1 : 0);
if (yapionObject.containsKey("order", Integer.class)) {
this.order = yapionObject.getIntOrDefault("order", 0) == 0 ? Material.REPEATER : Material.COMPARATOR;
} else {
this.order = Material.valueOf(yapionObject.getStringOrDefault("order", yapionObject.getBooleanOrDefault("comparator", false) ? Material.COMPARATOR.name() : Material.REPEATER.name()));
}
this.material = Material.valueOf(yapionObject.getStringOrDefault("material", Material.TNT.name()));
}
@ -90,7 +95,7 @@ public class TNTElement implements SimulatorElement {
yapionObject.add("xVelocity", xVelocity);
yapionObject.add("yVelocity", yVelocity);
yapionObject.add("zVelocity", zVelocity);
yapionObject.add("order", order);
yapionObject.add("order", order.name());
yapionObject.add("material", material.name());
return yapionObject;
}
@ -160,7 +165,7 @@ public class TNTElement implements SimulatorElement {
public void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result) {
if (disabled) return;
result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>())
.computeIfAbsent(order, ignore -> new Pair<>(() -> {
.computeIfAbsent(OrderUtils.order(order), ignore -> new Pair<>(() -> {
SimulatorStorage.WORLD.spawn(getPosition().toLocation(SimulatorStorage.WORLD), TNTPrimed.class, tntPrimed -> {
tntPrimed.setFuseTicks(fuseTicks);
if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0));
@ -209,4 +214,8 @@ public class TNTElement implements SimulatorElement {
}
return new Vector(0, 0, 0);
}
public void setOrder(Material material) {
this.order = material;
}
}