SteamWar/BauSystem2.0
Archiviert
12
0
Add BackupCommand /bu gui

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-08-05 17:24:58 +02:00
Ursprung 8d23831687
Commit efead4b8ef
3 geänderte Dateien mit 42 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
PREFIX = §eBau§8System §8»
PREFIX = §eBau§8System§8»
TIME = HH:mm:ss
DATE=........
COMMAND_HELP_HEAD=§7---=== (§e{0}§7) ===---
@ -108,10 +108,13 @@ BACKUP_NO_PERMS=§cDu darfst hier nicht das Backup System verwenden
BACKUP_CREATE_SUCCESS=§7Das Backup wurde erstellt
BACKUP_CREATE_FAILURE=§cDas Backup erstellen ist schiefgegangen
BACKUP_CREATE_NO_CHANGE=§7Die Region hat keine Veränderung
BACKUP_LIST_HEAD=§7---=== (§eBackup§7) ===---
BACKUP_LIST_HEAD=§7---=== (§eBackup §7{0}§7) ===---
BACKUP_LIST_ENTRY=§7{0} §e[Laden]
BACKUP_LOAD_FAILURE=§cDas Backup laden ist schiefgegangen
BACKUP_LOAD=§7Backup geladen
BACKUP_INV_NAME=§eBackup
BACKUP_ITEM_NAME=§eBackup §7von §e{0}
BACKUP_LORE=§eKlicken zum Laden
# Bau
BAU_COMMAND_HELP1 = §8/§ebau togglewe §8[§7Player§8] §8- §7Editiere die WorldEdit Rechte eines Spielers

Datei anzeigen

@ -28,10 +28,15 @@ import de.steamwar.bausystem.region.tags.Tag;
import de.steamwar.command.SWCommand;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@ -108,12 +113,35 @@ public class BackupCommand extends SWCommand {
if (checkGlobalRegion(region, p)) {
return;
}
BauSystem.MESSAGE.send("BACKUP_LIST_HEAD", p);
listBackup(p).forEach(s -> {
BauSystem.MESSAGE.send("BACKUP_LIST_ENTRY", p, "/backup load " + s, new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/backup load " + s.replace('_', ' ')), s);
List<String> backups = listBackup(p);
BauSystem.MESSAGE.send("BACKUP_LIST_HEAD", p, backups.size());
backups.forEach(s -> {
BauSystem.MESSAGE.send("BACKUP_LIST_ENTRY", p, "/backup load " + s, new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/backup load " + s), s);
});
}
@Register("gui")
public void backupGui(Player p) {
Region region = Region.getRegion(p.getLocation());
if (checkGlobalRegion(region, p)) {
return;
}
List<String> backups = listBackup(p);
List<SWListInv.SWListEntry<String>> swListEntries = new ArrayList<>();
List<String> lore = Arrays.asList(BauSystem.MESSAGE.parse("BACKUP_LORE", p));
for (int i = 0; i < backups.size(); i++) {
String s = backups.get(i);
SWItem swItem = new SWItem(Material.BRICK, BauSystem.MESSAGE.parse("BACKUP_ITEM_NAME", p, s), lore, false, clickType -> {});
swItem.getItemStack().setAmount(i + 1);
swListEntries.add(new SWListInv.SWListEntry<>(swItem, s));
}
SWListInv<String> swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("BACKUP_INV_NAME", p), swListEntries, (clickType, s) -> {
p.getOpenInventory().close();
backupLoad(p, s);
});
swListInv.open();
}
@Mapper(value = "backupName", local = true)
public TypeMapper<String> backupMapper() {
return SWCommandUtils.createMapper(s -> s, (commandSender, s) -> listBackup((Player) commandSender));
@ -130,5 +158,4 @@ public class BackupCommand extends SWCommand {
return Collections.emptyList();
}
}
}

Datei anzeigen

@ -478,7 +478,7 @@ public class Region {
definedBackupFolder.mkdirs();
File[] currentBackups = definedBackupFolder.listFiles();
if (currentBackups.length >= 20) {
if (currentBackups != null && currentBackups.length >= 20) {
List<File> files = new ArrayList<>(Arrays.asList(currentBackups));
files.sort(Comparator.comparingLong(File::lastModified));
while (files.size() >= 20) files.remove(0).delete();
@ -493,7 +493,11 @@ public class Region {
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"))));
File[] currentBackups = definedBackupFolder.listFiles();
List<File> files = new ArrayList<>(Arrays.asList(currentBackups));
files.sort(Comparator.comparingLong(File::lastModified));
return files.stream().map(File::getName).collect(Collectors.toList());
}
public File getBackupFile(String backupName) {