SteamWar/BauSystem2.0
Archiviert
12
0

Add storage api and implement SimulatorStorage
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
yoyosource 2023-10-26 22:31:30 +02:00
Ursprung 61d1f0bd45
Commit b49c75d6bd
11 geänderte Dateien mit 77 neuen und 24 gelöschten Zeilen

Datei anzeigen

@ -27,8 +27,8 @@ version '1.0'
compileJava.options.encoding = 'UTF-8' compileJava.options.encoding = 'UTF-8'
sourceCompatibility = 1.8 sourceCompatibility = 11
targetCompatibility = 1.8 targetCompatibility = 11
sourceSets { sourceSets {
main { main {

Datei anzeigen

@ -27,8 +27,8 @@ version '1.0'
compileJava.options.encoding = 'UTF-8' compileJava.options.encoding = 'UTF-8'
sourceCompatibility = 1.8 sourceCompatibility = 11
targetCompatibility = 1.8 targetCompatibility = 11
sourceSets { sourceSets {
main { main {

Datei anzeigen

@ -27,8 +27,8 @@ version '1.0'
compileJava.options.encoding = 'UTF-8' compileJava.options.encoding = 'UTF-8'
sourceCompatibility = 1.8 sourceCompatibility = 11
targetCompatibility = 1.8 targetCompatibility = 11
sourceSets { sourceSets {
main { main {

Datei anzeigen

@ -27,8 +27,8 @@ version '1.0'
compileJava.options.encoding = 'UTF-8' compileJava.options.encoding = 'UTF-8'
sourceCompatibility = 1.8 sourceCompatibility = 11
targetCompatibility = 1.8 targetCompatibility = 11
sourceSets { sourceSets {
main { main {

Datei anzeigen

@ -27,8 +27,8 @@ version '1.0'
compileJava.options.encoding = 'UTF-8' compileJava.options.encoding = 'UTF-8'
sourceCompatibility = 1.8 sourceCompatibility = 11
targetCompatibility = 1.8 targetCompatibility = 11
sourceSets { sourceSets {
main { main {

Datei anzeigen

@ -27,8 +27,8 @@ version '1.0'
compileJava.options.encoding = 'UTF-8' compileJava.options.encoding = 'UTF-8'
sourceCompatibility = 1.8 sourceCompatibility = 11
targetCompatibility = 1.8 targetCompatibility = 11
sourceSets { sourceSets {
main { main {

Datei anzeigen

@ -48,7 +48,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Linked // @Linked
public class SimulatorStorage implements Enable, Disable { public class SimulatorStorage implements Enable, Disable {
public static final World WORLD = Bukkit.getWorlds().get(0); public static final World WORLD = Bukkit.getWorlds().get(0);

Datei anzeigen

@ -22,21 +22,28 @@ package de.steamwar.bausystem.features.simulator2;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.features.simulator2.data.Simulator; 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.bausystem.features.simulator2.gui.base.SimulatorPageGui;
import de.steamwar.bausystem.features.simulator2.storage.SimFormatSimulatorLoader;
import de.steamwar.bausystem.features.simulator2.storage.SimulatorFormatSimulatorLoader;
import de.steamwar.bausystem.features.simulator2.storage.SimulatorSaver;
import de.steamwar.bausystem.features.simulator2.storage.YAPIONFormatSimulatorLoader;
import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.bausystem.utils.ItemUtils;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.api.Enable;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList; import java.io.File;
import java.util.HashMap; import java.util.*;
import java.util.Map;
public class SimulatorStorage { @Linked
public class SimulatorStorage implements Enable {
public static final File simulatorsDir = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "simulators");
private static Map<String, Simulator> simulatorMap = new HashMap<>(); private static Map<String, Simulator> simulatorMap = new HashMap<>();
private static NamespacedKey simulatorSelection = SWUtils.getNamespaceKey("simulator_selection"); private static NamespacedKey simulatorSelection = SWUtils.getNamespaceKey("simulator_selection");
@ -65,8 +72,53 @@ public class SimulatorStorage {
simulatorMap.putIfAbsent(name, simulator); simulatorMap.putIfAbsent(name, simulator);
} }
private static Simulator loadSimulator(String name) { @Override
return SimulatorTestCommand.SIMULATOR; // TODO: Implement Loading and legacy Loading public void enable() {
SimFormatSimulatorLoader simFormatSimulatorLoader = new SimFormatSimulatorLoader();
SimulatorFormatSimulatorLoader simulatorFormatSimulatorLoader = new SimulatorFormatSimulatorLoader();
YAPIONFormatSimulatorLoader yapionFormatSimulatorLoader = new YAPIONFormatSimulatorLoader();
for (File file : simulatorsDir.listFiles()) {
try {
List<Simulator> simulators = simFormatSimulatorLoader.load(file)
.orElse(null);
if (simulators != null) {
simulators.forEach(simulator -> {
simulatorMap.put(simulator.getName(), simulator);
});
continue;
}
} catch (Exception e) {
// Ignore
}
try {
List<Simulator> simulators = simulatorFormatSimulatorLoader.load(file)
.orElse(null);
if (simulators != null) {
simulators.forEach(simulator -> {
simulatorMap.put(simulator.getName(), simulator);
SimulatorSaver.saveSimulator(simulatorsDir, simulator);
});
continue;
}
} catch (Exception e) {
// Ignore
}
try {
List<Simulator> simulators = yapionFormatSimulatorLoader.load(file)
.orElse(null);
if (simulators != null) {
simulators.forEach(simulator -> {
simulatorMap.put(simulator.getName(), simulator);
SimulatorSaver.saveSimulator(simulatorsDir, simulator);
});
}
} catch (Exception e) {
// Ignore
}
}
} }
public static void openSimulatorSelector(Player player) { public static void openSimulatorSelector(Player player) {

Datei anzeigen

@ -23,6 +23,7 @@ import de.steamwar.bausystem.features.simulator2.data.Simulator;
import de.steamwar.bausystem.features.simulator2.data.SimulatorElement; import de.steamwar.bausystem.features.simulator2.data.SimulatorElement;
import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup; import de.steamwar.bausystem.features.simulator2.data.SimulatorGroup;
import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement; import de.steamwar.bausystem.features.simulator2.data.tnt.TNTElement;
import de.steamwar.bausystem.features.simulator2.storage.SimulatorSaver;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import de.steamwar.entity.REntity; import de.steamwar.entity.REntity;
import de.steamwar.entity.REntityServer; import de.steamwar.entity.REntityServer;
@ -69,6 +70,7 @@ public class SimulatorWatcher {
simulatorRunnablePair.getValue().run(); simulatorRunnablePair.getValue().run();
} }
}); });
SimulatorSaver.saveSimulator(SimulatorStorage.simulatorsDir, simulator);
} }
@Linked @Linked

Datei anzeigen

@ -66,7 +66,7 @@ public class SimulatorFormatSimulatorLoader implements SimulatorLoader {
} }
} }
file.delete(); // file.delete();
return Optional.of(Collections.singletonList(simulator)); return Optional.of(Collections.singletonList(simulator));
} }

Datei anzeigen

@ -41,13 +41,12 @@ public class SimulatorSaver {
YAPIONObject groupObject = new YAPIONObject(); YAPIONObject groupObject = new YAPIONObject();
groupObject.add("material", group.getMaterial().name()); groupObject.add("material", group.getMaterial().name());
groupObject.add("disabled", group.isDisabled()); groupObject.add("disabled", group.isDisabled());
groups.add(groupObject);
YAPIONArray elements = new YAPIONArray(); YAPIONArray elements = new YAPIONArray();
group.getElements().forEach(element -> { group.getElements().forEach(element -> {
YAPIONObject elementObject = new YAPIONObject(); YAPIONObject elementObject = new YAPIONObject();
elementObject.add("type", element.getType()); elementObject.add("type", element.getType());
elementObject.add("material", element.getMaterial()); elementObject.add("material", element.getMaterial().name());
elementObject.add("disabled", element.isDisabled()); elementObject.add("disabled", element.isDisabled());
elementObject.add("x", element.getPosition().getX()); elementObject.add("x", element.getPosition().getX());
elementObject.add("y", element.getPosition().getY()); elementObject.add("y", element.getPosition().getY());
@ -73,7 +72,7 @@ public class SimulatorSaver {
File file = new File(directory, simulator.getName() + ".sim"); File file = new File(directory, simulator.getName() + ".sim");
try { try {
simulatorObject.toJSON(new FileOutput(file)).close(); simulatorObject.toJSONLossy(new FileOutput(file)).close();
} catch (IOException e) { } catch (IOException e) {
// Ignore // Ignore
} }