forked from SteamWar/SteamWar
Merge pull request 'Add SimulatorCommand.rename' (#38) from BauSystem/SimulatorRename into main
Reviewed-on: https://steamwar.de/devlabs/SteamWar/SteamWar/pulls/38 Reviewed-by: Lixfel <lixfel@steamwar.de>
This commit is contained in:
@@ -271,6 +271,7 @@ SIMULATOR_CHANGE_HELP=§8/§esimulator change §8-§7 Change your simulator wand
|
||||
SIMULATOR_DELETE_HELP=§8/§esimulator delete §8[§7name§8] §8-§7 Deletes the simulator
|
||||
SIMULATOR_START_HELP=§8/§esimulator start §8[§7name§8] §8-§7 Starts the simulator
|
||||
SIMULATOR_COPY_HELP=§8/§esimulator copy §8[§7to-copy§8] §8[§7name§8] §8-§7 Copy the simulator
|
||||
SIMULATOR_RENAME_HELP=§8/§esimulator rename §8[§7to-rename§8] §8[§7name§8] §8-§7 Rename the simulator
|
||||
SIMULATOR_GUI_ITEM_NAME=§eTNT Simulator
|
||||
SIMULATOR_NO_SIM_IN_HAND=§cNo simulator item selected
|
||||
SIMULATOR_GUI_SELECT_SIM=Simulator selection
|
||||
@@ -307,6 +308,7 @@ SIMULATOR_POSITION_Z=§7z-Position
|
||||
SIMULATOR_BACK=§eBack
|
||||
SIMULATOR_GUI_TOTAL_TNT=§7Total TNT§8: §e{0}
|
||||
SIMULATOR_DELETED=§cSimulator deleted
|
||||
SIMULATOR_RENAMED=§cSimulator renamed from {0} to {1}
|
||||
## GUI
|
||||
SIMULATOR_POSITION_EDIT=§eEdit position
|
||||
SIMULATOR_POSITION_ADD=§eSet position
|
||||
|
||||
@@ -254,6 +254,7 @@ SIMULATOR_CHANGE_HELP=§8/§esimulator change §8-§7 Wechsel zu einem anderen S
|
||||
SIMULATOR_DELETE_HELP=§8/§esimulator delete §8[§7name§8] §8-§7 Löscht den Simulator
|
||||
SIMULATOR_START_HELP=§8/§esimulator start §8[§7name§8] §8-§7 Startet die Simulation
|
||||
SIMULATOR_COPY_HELP=§8/§esimulator copy §8[§7to-copy§8] §8[§7name§8] §8-§7 Kopiert einen Simulator
|
||||
SIMULATOR_RENAME_HELP=§8/§esimulator rename §8[§7to-rename§8] §8[§7name§8] §8-§7 Benennt einen Simulator um
|
||||
SIMULATOR_GUI_ITEM_NAME=§eTNT Simulator
|
||||
SIMULATOR_NO_SIM_IN_HAND=§cKein Simulator Item gewählt
|
||||
SIMULATOR_GUI_SELECT_SIM=Simulator wählen
|
||||
@@ -290,6 +291,7 @@ SIMULATOR_POSITION_Z=§7z-Position
|
||||
SIMULATOR_BACK=§eZurück
|
||||
SIMULATOR_GUI_TOTAL_TNT=§7Gesamt TNT§8: §e{0}
|
||||
SIMULATOR_DELETED=§cSimulator gelöscht
|
||||
SIMULATOR_RENAMED=§cSimulator von {0} zu {1} umbenannt
|
||||
## GUI
|
||||
SIMULATOR_POSITION_EDIT=§ePosition bearbeiten
|
||||
SIMULATOR_POSITION_ADD=§ePosition setzen
|
||||
|
||||
+27
-10
@@ -20,7 +20,6 @@
|
||||
package de.steamwar.bausystem.features.simulator;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor;
|
||||
@@ -63,15 +62,7 @@ public class SimulatorCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(value = "copy", description = "SIMULATOR_COPY_HELP")
|
||||
public void copy(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator, String name) {
|
||||
if (SimulatorStorage.getSimulator(name) != null) {
|
||||
BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", p);
|
||||
return;
|
||||
}
|
||||
if (!name.matches("[a-zA-Z_0-9-]+")) {
|
||||
BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", p);
|
||||
return;
|
||||
}
|
||||
public void copy(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator, @Validator("simulatorName") String name) {
|
||||
if (!SimulatorStorage.copy(simulator, name)) {
|
||||
BauSystem.MESSAGE.send("SIMULATOR_ERROR_COPY", p);
|
||||
}
|
||||
@@ -88,6 +79,17 @@ public class SimulatorCommand extends SWCommand {
|
||||
SimulatorExecutor.run(simulator);
|
||||
}
|
||||
|
||||
@Register(value = "rename", description = "SIMULATOR_RENAME_HELP")
|
||||
public void rename(@Validator Player p, @ErrorMessage("SIMULATOR_NOT_EXISTS") Simulator simulator, @Validator("simulatorName") String name) {
|
||||
String oldName = simulator.getName();
|
||||
if (SimulatorStorage.copy(simulator, name)) {
|
||||
SimulatorStorage.delete(simulator);
|
||||
BauSystem.MESSAGE.send("SIMULATOR_RENAMED", p, oldName, name);
|
||||
} else {
|
||||
BauSystem.MESSAGE.send("SIMULATOR_ERROR_COPY", p);
|
||||
}
|
||||
}
|
||||
|
||||
@ClassMapper(value = Simulator.class, local = true)
|
||||
public TypeMapper<Simulator> allSimulators() {
|
||||
return new TypeMapper<>() {
|
||||
@@ -102,4 +104,19 @@ public class SimulatorCommand extends SWCommand {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Validator(value = "simulatorName", local = true)
|
||||
public TypeValidator<String> simulatorName() {
|
||||
return (commandSender, name, messageSender) -> {
|
||||
if (SimulatorStorage.getSimulator(name) != null) {
|
||||
messageSender.send("SIMULATOR_NAME_ALREADY_EXISTS");
|
||||
return false;
|
||||
}
|
||||
if (!name.matches("[a-zA-Z_0-9-]+")) {
|
||||
messageSender.send("SIMULATOR_NAME_INVALID");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user