Add storage api and implement SimulatorStorage
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed
Dieser Commit ist enthalten in:
Ursprung
61d1f0bd45
Commit
b49c75d6bd
@ -27,8 +27,8 @@ version '1.0'
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
sourceCompatibility = 11
|
||||
targetCompatibility = 11
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
|
@ -27,8 +27,8 @@ version '1.0'
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
sourceCompatibility = 11
|
||||
targetCompatibility = 11
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
|
@ -27,8 +27,8 @@ version '1.0'
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
sourceCompatibility = 11
|
||||
targetCompatibility = 11
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
|
@ -27,8 +27,8 @@ version '1.0'
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
sourceCompatibility = 11
|
||||
targetCompatibility = 11
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
|
@ -27,8 +27,8 @@ version '1.0'
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
sourceCompatibility = 11
|
||||
targetCompatibility = 11
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
|
@ -27,8 +27,8 @@ version '1.0'
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
sourceCompatibility = 11
|
||||
targetCompatibility = 11
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
|
@ -48,7 +48,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Linked
|
||||
// @Linked
|
||||
public class SimulatorStorage implements Enable, Disable {
|
||||
|
||||
public static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
@ -22,21 +22,28 @@ package de.steamwar.bausystem.features.simulator2;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
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.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.inventory.SWItem;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.api.Enable;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
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 NamespacedKey simulatorSelection = SWUtils.getNamespaceKey("simulator_selection");
|
||||
|
||||
@ -65,8 +72,53 @@ public class SimulatorStorage {
|
||||
simulatorMap.putIfAbsent(name, simulator);
|
||||
}
|
||||
|
||||
private static Simulator loadSimulator(String name) {
|
||||
return SimulatorTestCommand.SIMULATOR; // TODO: Implement Loading and legacy Loading
|
||||
@Override
|
||||
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) {
|
||||
|
@ -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.SimulatorGroup;
|
||||
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.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
@ -69,6 +70,7 @@ public class SimulatorWatcher {
|
||||
simulatorRunnablePair.getValue().run();
|
||||
}
|
||||
});
|
||||
SimulatorSaver.saveSimulator(SimulatorStorage.simulatorsDir, simulator);
|
||||
}
|
||||
|
||||
@Linked
|
||||
|
@ -66,7 +66,7 @@ public class SimulatorFormatSimulatorLoader implements SimulatorLoader {
|
||||
}
|
||||
}
|
||||
|
||||
file.delete();
|
||||
// file.delete();
|
||||
return Optional.of(Collections.singletonList(simulator));
|
||||
}
|
||||
|
||||
|
@ -41,13 +41,12 @@ public class SimulatorSaver {
|
||||
YAPIONObject groupObject = new YAPIONObject();
|
||||
groupObject.add("material", group.getMaterial().name());
|
||||
groupObject.add("disabled", group.isDisabled());
|
||||
groups.add(groupObject);
|
||||
|
||||
YAPIONArray elements = new YAPIONArray();
|
||||
group.getElements().forEach(element -> {
|
||||
YAPIONObject elementObject = new YAPIONObject();
|
||||
elementObject.add("type", element.getType());
|
||||
elementObject.add("material", element.getMaterial());
|
||||
elementObject.add("material", element.getMaterial().name());
|
||||
elementObject.add("disabled", element.isDisabled());
|
||||
elementObject.add("x", element.getPosition().getX());
|
||||
elementObject.add("y", element.getPosition().getY());
|
||||
@ -73,7 +72,7 @@ public class SimulatorSaver {
|
||||
|
||||
File file = new File(directory, simulator.getName() + ".sim");
|
||||
try {
|
||||
simulatorObject.toJSON(new FileOutput(file)).close();
|
||||
simulatorObject.toJSONLossy(new FileOutput(file)).close();
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren