Add SimulatorCommand.saveCommand and other
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
2d3dc10e23
Commit
c8ad93a00f
@ -26,9 +26,14 @@ import de.steamwar.bausystem.SWUtils;
|
|||||||
import de.steamwar.bausystem.config.ColorConfig;
|
import de.steamwar.bausystem.config.ColorConfig;
|
||||||
import de.steamwar.bausystem.linkage.LinkageType;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
import de.steamwar.bausystem.linkage.Linked;
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
import de.steamwar.bausystem.worlddata.SimulatorData;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
|
import de.steamwar.command.TypeMapper;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Linked(LinkageType.COMMAND)
|
@Linked(LinkageType.COMMAND)
|
||||||
public class SimulatorCommand extends SWCommand {
|
public class SimulatorCommand extends SWCommand {
|
||||||
|
|
||||||
@ -42,6 +47,10 @@ public class SimulatorCommand extends SWCommand {
|
|||||||
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator start" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Startet die Simulation");
|
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator start" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Startet die Simulation");
|
||||||
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator gui" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Öffnet die GUI");
|
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator gui" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Öffnet die GUI");
|
||||||
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator delete" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Löscht alle TNT");
|
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator delete" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Löscht alle TNT");
|
||||||
|
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator save <Name>" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Speichert den Simulator");
|
||||||
|
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator load <Name>" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Lädt den Simulator");
|
||||||
|
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator list" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Listet alle gespeicherten Simulator");
|
||||||
|
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator remove <Name>" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Löscht den Simulator");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register
|
@Register
|
||||||
@ -66,6 +75,44 @@ public class SimulatorCommand extends SWCommand {
|
|||||||
public void deleteCommand(Player p) {
|
public void deleteCommand(Player p) {
|
||||||
if (cannotUse(p)) return;
|
if (cannotUse(p)) return;
|
||||||
TNTSimulator.get(p).delete();
|
TNTSimulator.get(p).delete();
|
||||||
|
p.sendMessage(ColorConfig.BASE + "Alle TNT wurden gelöscht");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register({"save"})
|
||||||
|
public void saveCommand(Player p, String name) {
|
||||||
|
if (cannotUse(p)) return;
|
||||||
|
TNTSimulator.get(p).save();
|
||||||
|
SimulatorData.saveSimulator(p, name);
|
||||||
|
p.sendMessage(ColorConfig.BASE + "Simulator " + ColorConfig.HIGHLIGHT + name + ColorConfig.BASE + " wurde gespeichert");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register({"load"})
|
||||||
|
public void loadCommand(Player p, @Mapper("SavedSimulators") String name) {
|
||||||
|
if (cannotUse(p)) return;
|
||||||
|
TNTSimulator.get(p).delete();
|
||||||
|
SimulatorData.loadSimulator(p, name);
|
||||||
|
p.sendMessage(ColorConfig.BASE + "Simulator " + ColorConfig.HIGHLIGHT + name + ColorConfig.BASE + " wurde geladen");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register({"remove"})
|
||||||
|
public void removeCommand(Player p, @Mapper("SavedSimulators") String name) {
|
||||||
|
if (cannotUse(p)) return;
|
||||||
|
SimulatorData.removeSimulator(p, name);
|
||||||
|
p.sendMessage(ColorConfig.BASE + "Simulator " + ColorConfig.HIGHLIGHT + name + ColorConfig.BASE + " wurde gelöscht");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register({"list"})
|
||||||
|
public void listCommand(Player p) {
|
||||||
|
if (cannotUse(p)) return;
|
||||||
|
List<String> sims = SimulatorData.listSimulator(p);
|
||||||
|
if (sims.isEmpty()) {
|
||||||
|
p.sendMessage(ColorConfig.BASE + "Keine gespeicherten Simulatoren");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
p.sendMessage(ColorConfig.BASE + "Gespeicherte Simulatoren:");
|
||||||
|
for (String s : sims) {
|
||||||
|
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator load " + s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean cannotUse(Player player) {
|
private boolean cannotUse(Player player) {
|
||||||
@ -76,4 +123,21 @@ public class SimulatorCommand extends SWCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Mapper(value = "SavedSimulators", local = true)
|
||||||
|
public TypeMapper<String> simulatorListTypeMapper() {
|
||||||
|
return new TypeMapper<String>() {
|
||||||
|
@Override
|
||||||
|
public String map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||||
|
if (SimulatorData.listSimulator(((Player) commandSender)).contains(s)) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
|
||||||
|
return SimulatorData.listSimulator(((Player) commandSender));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,22 +80,19 @@ public class TNTSimulator {
|
|||||||
simulator.spawns.forEach(tntSpawn -> {
|
simulator.spawns.forEach(tntSpawn -> {
|
||||||
yapionArray.add(tntSpawn.output());
|
yapionArray.add(tntSpawn.output());
|
||||||
});
|
});
|
||||||
if (yapionArray.isEmpty()) {
|
SimulatorData.saveSimulator(player, yapionArray);
|
||||||
SimulatorData.removeSimulator(player);
|
|
||||||
} else {
|
|
||||||
SimulatorData.saveSimulator(player, new YAPIONObject().add("", yapionArray));
|
|
||||||
}
|
|
||||||
simulator.hide();
|
simulator.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveAndDelete() {
|
public void saveAndDelete() {
|
||||||
save();
|
save();
|
||||||
TNT_SIMULATOR_MAP.remove(player);
|
TNT_SIMULATOR_MAP.remove(player);
|
||||||
|
SimulatorData.removeSimulator(player, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
TNTSimulator simulator = TNT_SIMULATOR_MAP.remove(player);
|
TNTSimulator simulator = TNT_SIMULATOR_MAP.remove(player);
|
||||||
SimulatorData.removeSimulator(player);
|
SimulatorData.removeSimulator(player, "");
|
||||||
simulator.hide();
|
simulator.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,10 +25,12 @@ import lombok.experimental.UtilityClass;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import yapion.hierarchy.output.FileOutput;
|
import yapion.hierarchy.output.FileOutput;
|
||||||
|
import yapion.hierarchy.types.YAPIONArray;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
import yapion.parser.YAPIONParser;
|
import yapion.parser.YAPIONParser;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class SimulatorData {
|
public class SimulatorData {
|
||||||
@ -49,7 +51,7 @@ public class SimulatorData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public void saveSimulator(Player player, YAPIONObject yapionObject) {
|
private void internalSaveSimulator(Player player, YAPIONObject yapionObject) {
|
||||||
File file = getFile(player);
|
File file = getFile(player);
|
||||||
yapionObject.toYAPION(new FileOutput(file)).close();
|
yapionObject.toYAPION(new FileOutput(file)).close();
|
||||||
}
|
}
|
||||||
@ -60,11 +62,34 @@ public class SimulatorData {
|
|||||||
yapionObject.toYAPION(new FileOutput(file)).close();
|
yapionObject.toYAPION(new FileOutput(file)).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSimulator(Player player) {
|
public List<String> listSimulator(Player player) {
|
||||||
File file = getFile(player);
|
List<String> strings = getSimulator(player).getKeys();
|
||||||
if (file.exists()) {
|
strings.remove("");
|
||||||
file.delete();
|
return strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void saveSimulator(Player player, String name) {
|
||||||
|
YAPIONObject yapionObject = getSimulator(player);
|
||||||
|
yapionObject.put(name, yapionObject.getArray("").copy());
|
||||||
|
internalSaveSimulator(player, yapionObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveSimulator(Player player, YAPIONArray simulator) {
|
||||||
|
YAPIONObject yapionObject = getSimulator(player);
|
||||||
|
yapionObject.put("", simulator);
|
||||||
|
internalSaveSimulator(player, yapionObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadSimulator(Player player, String name) {
|
||||||
|
YAPIONObject yapionObject = getSimulator(player);
|
||||||
|
yapionObject.put("", yapionObject.getArray(name).copy());
|
||||||
|
internalSaveSimulator(player, yapionObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeSimulator(Player player, String name) {
|
||||||
|
YAPIONObject yapionObject = getSimulator(player);
|
||||||
|
yapionObject.remove(name);
|
||||||
|
internalSaveSimulator(player, yapionObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getFile(Player player) {
|
private File getFile(Player player) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren