From fb518efe63dedf0f0330b57b3d47564c22d98c58 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 30 Jul 2025 20:37:52 +0200 Subject: [PATCH] Reduce to 24 compiler errors --- .../features/backup/BackupCommand.java | 69 +++++++++---------- .../region/RegionScoreboardElement.java | 5 +- .../features/region/ResetCommand.java | 2 +- .../bausystem/features/team/SkinCommand.java | 9 ++- .../bausystem/region/BackupScheduler.java | 11 +-- .../de/steamwar/bausystem/region/Region.java | 4 ++ .../bausystem/region/RegionBackups.java | 56 +++++++++++++++ 7 files changed, 109 insertions(+), 47 deletions(-) create mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionBackups.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java index f4d610ee..b2671e84 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java @@ -19,27 +19,23 @@ package de.steamwar.bausystem.features.backup; -import com.sk89q.worldedit.EditSession; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.RegionBackups; import de.steamwar.bausystem.region.flags.ChangedMode; import de.steamwar.bausystem.region.flags.Flag; -import de.steamwar.bausystem.utils.PasteBuilder; +import de.steamwar.command.PreviousArguments; 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 de.steamwar.linkage.Linked; import net.md_5.bungee.api.chat.ClickEvent; import org.bukkit.Material; +import org.bukkit.command.CommandSender; 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.*; import java.util.stream.Collectors; @Linked @@ -67,7 +63,8 @@ public class BackupCommand extends SWCommand { BauSystem.MESSAGE.send("BACKUP_CREATE_NO_CHANGE", p); return; } - if (region.backup(false)) { + Optional backup = region.getBackups().create(RegionBackups.BackupType.MANUAL); + if (backup.isPresent()) { BauSystem.MESSAGE.send("BACKUP_CREATE_SUCCESS", p); } else { BauSystem.MESSAGE.send("BACKUP_CREATE_FAILURE", p); @@ -75,25 +72,17 @@ public class BackupCommand extends SWCommand { } @Register(value = "load", description = "BACKUP_HELP_LOAD") - public void backupLoad(@Validator("owner") Player p, @Mapper("backupName") String backupName) { + public void backupLoad(@Validator("owner") Player p, @Mapper("backup") RegionBackups.Backup backup) { Region region = Region.getRegion(p.getLocation()); if (checkGlobalRegion(region, p)) { return; } - File backupFile = region.getBackupFile(backupName.replace('_', ' ')); - if (backupFile == null) { + if (backup.load()) { + BauSystem.MESSAGE.send("BACKUP_LOAD", p); + } else { BauSystem.MESSAGE.send("BACKUP_LOAD_FAILURE", p); - return; } - EditSession editSession = new PasteBuilder(new PasteBuilder.FileProvider(backupFile)) - .pastePoint(region.getArea().getMinPoint(false).add(region.getPrototype().getSizeX() / 2, 0, region.getPrototype().getSizeZ() / 2)) - .minPoint(region.getArea().getMinPoint(false)) - .maxPoint(region.getArea().getMaxPoint(false)) - .waterLevel(region.getWaterLevel()) - .run(); - region.getHistory().remember(editSession); - BauSystem.MESSAGE.send("BACKUP_LOAD", p); } @Register(value = "list", description = "BACKUP_HELP_LIST") @@ -102,10 +91,10 @@ public class BackupCommand extends SWCommand { if (checkGlobalRegion(region, p)) { return; } - List backups = listBackup(p); + List 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); + backups.forEach(backup -> { + BauSystem.MESSAGE.send("BACKUP_LIST_ENTRY", p, "/backup load " + backup.getName(), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/backup load " + backup.getName()), backup.getName()); }); } @@ -115,34 +104,44 @@ public class BackupCommand extends SWCommand { if (checkGlobalRegion(region, p)) { return; } - List backups = listBackup(p); - List> swListEntries = new ArrayList<>(); + List backups = listBackup(p); + List> swListEntries = new ArrayList<>(); List 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 -> {}); + RegionBackups.Backup backup = backups.get(i); + SWItem swItem = new SWItem(Material.BRICK, BauSystem.MESSAGE.parse("BACKUP_ITEM_NAME", p, backup.getName()), lore, false, clickType -> {}); swItem.getItemStack().setAmount(i + 1); - swListEntries.add(new SWListInv.SWListEntry<>(swItem, s)); + swListEntries.add(new SWListInv.SWListEntry<>(swItem, backup)); } - SWListInv swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("BACKUP_INV_NAME", p), swListEntries, (clickType, s) -> { + SWListInv swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("BACKUP_INV_NAME", p), swListEntries, (clickType, s) -> { p.getOpenInventory().close(); p.performCommand("backup load " + s); }); swListInv.open(); } - @Mapper(value = "backupName", local = true) - public TypeMapper backupMapper() { - return SWCommandUtils.createMapper(s -> s, (commandSender, s) -> listBackup((Player) commandSender)); + @Mapper(value = "backup", local = true) + public TypeMapper backupMapper() { + return new TypeMapper() { + @Override + public RegionBackups.Backup map(CommandSender commandSender, String[] previousArguments, String s) { + return Region.getRegion(((Player) commandSender).getLocation()).getBackups().get(s); + } + + @Override + public Collection tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { + return listBackup((Player) sender).stream().map(RegionBackups.Backup::getName).collect(Collectors.toList()); + } + }; } - private List listBackup(Player p) { + private List 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).replace(' ', '_')).collect(Collectors.toList()); + return region.getBackups().list(); } catch (NullPointerException e) { return Collections.emptyList(); } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java index 7ad6dea1..2e25bafe 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.region; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; @@ -40,8 +41,6 @@ public class RegionScoreboardElement implements ScoreboardElement { @Override public String get(Region region, Player p) { if (region.getType().isGlobal()) return null; - // TODO: Fix this! - // return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + region.getName(); - return null; + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + region.getName(); } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java index e494ac7d..28f10595 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java @@ -57,7 +57,7 @@ public class ResetCommand extends SWCommand { PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getResetFile(RegionType.NORMAL))) .color(region.getFlags().get(Flag.COLOR).getWithDefault()); region.getArea().reset(pasteBuilder, false); - for (Flag value : Flag.getResetFlags()) { + for (Flag value : Flag.getFlags()) { region.getFlags().set(value, value.getDefaultValue()); } RegionUtils.message(region, "REGION_RESET_RESETED"); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/team/SkinCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/team/SkinCommand.java index b2c2bc8c..b97127b1 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/team/SkinCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/team/SkinCommand.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.team; +import com.sk89q.worldedit.EditSession; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.team.boundary.BoundaryViewer; import de.steamwar.bausystem.region.Region; @@ -74,7 +75,7 @@ public class SkinCommand extends SWCommand { String name = String.join(" ", names); File arenaFile = new File("sections19/" + name + "/" + typeKuerzel + "Arena.schem"); - File testblockFile = region.getTestblockArea().isPresent() ? new File("sections19/" + name + "/" + typeKuerzel + "Testblock.schem") : null; + File testblockFile = !region.getTestblockArea().isEmpty() ? new File("sections19/" + name + "/" + typeKuerzel + "Testblock.schem") : null; arenaFile.getParentFile().mkdirs(); if (testblockFile != null) { @@ -89,9 +90,11 @@ public class SkinCommand extends SWCommand { return; } - Region.copy(region.getArea().getMinPoint(false), region.getArea().getMaxPoint(false), arenaFile); + EditSession editSession = region.getArea().copy(false); + // TODO: Save editSession to file if (testblockFile != null) { - Region.copy(region.getTestblockArea().getMinPoint(false), region.getTestblockArea().getMaxPoint(false), testblockFile); + editSession = region.getTestblockArea().copy(false); + // TODO: Save editSession to file } YAPIONObject yapionObject = new YAPIONObject(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/BackupScheduler.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/BackupScheduler.java index 512c0199..902d4a6c 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/BackupScheduler.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/BackupScheduler.java @@ -1,6 +1,5 @@ package de.steamwar.bausystem.region; -import com.sk89q.worldedit.EditSession; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.flags.ChangedMode; import de.steamwar.bausystem.region.flags.Flag; @@ -9,6 +8,7 @@ import de.steamwar.linkage.api.Enable; import org.bukkit.scheduler.BukkitRunnable; import java.util.Iterator; +import java.util.Optional; @Linked public class BackupScheduler implements Enable { @@ -41,10 +41,11 @@ public class BackupScheduler implements Enable { } Region region = regionsToBackup.next(); - EditSession editSession = region.getArea() - .copy(false); - // TODO: Implement saving EditSession to schematic! - region.getFlags().set(Flag.CHANGED, ChangedMode.NO_CHANGE); + Optional backup = region.getBackups() + .create(RegionBackups.BackupType.AUTOMATIC); + if (backup.isPresent()) { + region.getFlags().set(Flag.CHANGED, ChangedMode.NO_CHANGE); + } } }.runTaskTimer(BauSystem.getInstance(), 0, 20 * 60); } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index e2d37c2a..a41f6593 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -35,9 +35,11 @@ public interface Region { static Stream getRegions() { return RegionSystem.INSTANCE.getRegions(); } + static Region getRegion(Location location) { return RegionSystem.INSTANCE.get(location); } + static Region getGlobalRegion() { return RegionSystem.INSTANCE.getGlobalRegion(); } @@ -58,6 +60,8 @@ public interface Region { RegionHistory getHistory(); + RegionBackups getBackups(); + interface Area { Area EMPTY = new Area() { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionBackups.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionBackups.java new file mode 100644 index 00000000..af4bf23b --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionBackups.java @@ -0,0 +1,56 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.region; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.List; +import java.util.Optional; + +public interface RegionBackups { + + @RequiredArgsConstructor + enum BackupType { + MANUAL(5), + AUTOMATIC(20), + ; + + private final int maxBackups; + } + + @RequiredArgsConstructor + @Getter + abstract class Backup { + private final BackupType type; + private final String name; + private final FlagStorage flags; + + public abstract boolean load(); + + public abstract void delete(); + } + + Optional create(BackupType backupType); + + List list(); + + Backup get(String name); +}