SteamWar/BauSystem2.0
Archiviert
12
0

Prototyping BackupCommand

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-07-06 11:34:02 +02:00
Ursprung c79cf13cb9
Commit 6436cacb04
3 geänderte Dateien mit 108 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -99,6 +99,13 @@ AUTOSTART_MESSAGE_RESULT1 = §eZeit §7bis zur §eExplosion §7am Gegner§8:§e
AUTOSTART_MESSAGE_RESULT2 = §eZeitdifferenz in ticks §7bis 60 Sekunden§8:§e {0} AUTOSTART_MESSAGE_RESULT2 = §eZeitdifferenz in ticks §7bis 60 Sekunden§8:§e {0}
AUTOSTART_MESSAGE_RESULT3 = §7Positiv, wenn zu wenig, negativ wenn zu viel AUTOSTART_MESSAGE_RESULT3 = §7Positiv, wenn zu wenig, negativ wenn zu viel
# Backup
BACKUP_REGION_NO_REGION=§cDu bist in keiner Region
BACKUP_NO_PERMS=§cDu darfst hier nicht das Backup System verwenden
BACKUP_SUCCESS=§7Das Backup wurde erstellt
BACKUP_FAILURE=§cDas Backup erstellen ist schiefgegangen
BACKUP_NO_CHANGE=§7Die Region hat keine Veränderung
# Bau # Bau
BAU_COMMAND_HELP1 = §8/§ebau togglewe §8[§7Player§8] §8- §7Editiere die WorldEdit Rechte eines Spielers BAU_COMMAND_HELP1 = §8/§ebau togglewe §8[§7Player§8] §8- §7Editiere die WorldEdit Rechte eines Spielers
BAU_COMMAND_HELP2 = §8/§ebau toggleworld §8[§7Player§8] §8- §7Editiere die Welt Rechte eines Spielers BAU_COMMAND_HELP2 = §8/§ebau toggleworld §8[§7Player§8] §8- §7Editiere die Welt Rechte eines Spielers

Datei anzeigen

@ -19,9 +19,21 @@
package de.steamwar.bausystem.features.backup; package de.steamwar.bausystem.features.backup;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
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.region.Region;
import de.steamwar.bausystem.region.tags.Tag;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@Linked(LinkageType.COMMAND) @Linked(LinkageType.COMMAND)
public class BackupCommand extends SWCommand { public class BackupCommand extends SWCommand {
@ -30,4 +42,82 @@ public class BackupCommand extends SWCommand {
super("backup", "bu"); super("backup", "bu");
} }
@Register(help = true)
public void genericHelp(Player p, String... args) {
BauSystem.MESSAGE.sendPrefixless("COMMAND_HELP_HEAD", p, "Backup");
BauSystem.MESSAGE.sendPrefixless("DETONATOR_HELP_1", p);
}
static boolean checkGlobalRegion(Region region, Player p) {
if (region.isGlobal()) {
BauSystem.MESSAGE.send("BACKUP_REGION_NO_REGION", p);
return true;
}
return false;
}
private boolean permissionCheck(Player player, Permission permission) {
if (Permission.hasPermission(player, permission)) {
return true;
}
BauSystem.MESSAGE.send("BACKUP_NO_PERMS", player);
return false;
}
@Register("create")
public void backupCreate(Player p) {
if (!permissionCheck(p, Permission.WORLDEDIT)) return;
Region region = Region.getRegion(p.getLocation());
if (checkGlobalRegion(region, p)) {
return;
}
if (!region.get(Tag.CHANGED)) {
BauSystem.MESSAGE.send("BACKUP_NO_CHANGE", p);
return;
}
if (region.backup()) {
BauSystem.MESSAGE.send("BACKUP_SUCCESS", p);
} else {
BauSystem.MESSAGE.send("BACKUP_FAILURE", p);
}
}
@Register("load")
public void backupLoad(Player p, @Mapper("backupName") String backupName) {
if (!permissionCheck(p, Permission.WORLDEDIT)) return;
Region region = Region.getRegion(p.getLocation());
if (checkGlobalRegion(region, p)) {
return;
}
System.out.println(backupName);
}
@Register("list")
public void backupList(Player p) {
Region region = Region.getRegion(p.getLocation());
if (checkGlobalRegion(region, p)) {
return;
}
listbackup(p).forEach(s -> {
p.sendMessage("HERE: " + s);
});
}
@Mapper(value = "backupName", local = true)
public TypeMapper<String> backupMapper() {
return SWCommandUtils.createMapper(s -> s, (commandSender, s) -> listbackup((Player) commandSender));
}
private List<String> listbackup(Player p) {
Region region = Region.getRegion(p.getLocation());
if (checkGlobalRegion(region, p)) {
return Collections.emptyList();
}
try {
return region.listBackup().stream().map(s -> s.substring(0, s.length() - 6)).collect(Collectors.toList());
} catch (NullPointerException e) {
return Collections.emptyList();
}
}
} }

Datei anzeigen

@ -29,8 +29,6 @@ import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.bausystem.shared.SizedStack; import de.steamwar.bausystem.shared.SizedStack;
import de.steamwar.core.VersionedCallable; import de.steamwar.core.VersionedCallable;
import de.steamwar.sql.Schematic; import de.steamwar.sql.Schematic;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
@ -42,10 +40,9 @@ import yapion.hierarchy.types.YAPIONValue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.time.LocalDateTime;
import java.util.HashSet; import java.time.format.DateTimeFormatter;
import java.util.Map; import java.util.*;
import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -57,7 +54,7 @@ public class Region {
@Getter @Getter
private static final Map<String, Region> REGION_MAP = new HashMap<>(); private static final Map<String, Region> REGION_MAP = new HashMap<>();
private static final File backupFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "backup"); private static final File backupFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "backup");
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH-mm-ss'#'dd-MM-yyyy"); private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss' 'dd.MM.yyyy");
public static Region getRegion(Location location) { public static Region getRegion(Location location) {
return REGION_MAP.values().stream() return REGION_MAP.values().stream()
@ -473,4 +470,11 @@ public class Region {
//noinspection unchecked //noinspection unchecked
return VersionedCallable.call(new VersionedCallable<>(() -> Region_15.backup(minPoint, maxPoint, backupFile), 15)); return VersionedCallable.call(new VersionedCallable<>(() -> Region_15.backup(minPoint, maxPoint, backupFile), 15));
} }
public List<String> listBackup() {
final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name);
//noinspection ResultOfMethodCallIgnored
definedBackupFolder.mkdirs();
return Arrays.asList(Objects.requireNonNull(definedBackupFolder.list((dir, name) -> name.endsWith(".schem"))));
}
} }