forked from SteamWar/SteamWar
Reduce to 24 compiler errors
This commit is contained in:
+34
-35
@@ -19,27 +19,23 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.backup;
|
package de.steamwar.bausystem.features.backup;
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.region.Region;
|
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.ChangedMode;
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
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.SWCommand;
|
||||||
import de.steamwar.command.SWCommandUtils;
|
|
||||||
import de.steamwar.command.TypeMapper;
|
import de.steamwar.command.TypeMapper;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.inventory.SWListInv;
|
import de.steamwar.inventory.SWListInv;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.File;
|
import java.util.*;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
@@ -67,7 +63,8 @@ public class BackupCommand extends SWCommand {
|
|||||||
BauSystem.MESSAGE.send("BACKUP_CREATE_NO_CHANGE", p);
|
BauSystem.MESSAGE.send("BACKUP_CREATE_NO_CHANGE", p);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (region.backup(false)) {
|
Optional<RegionBackups.Backup> backup = region.getBackups().create(RegionBackups.BackupType.MANUAL);
|
||||||
|
if (backup.isPresent()) {
|
||||||
BauSystem.MESSAGE.send("BACKUP_CREATE_SUCCESS", p);
|
BauSystem.MESSAGE.send("BACKUP_CREATE_SUCCESS", p);
|
||||||
} else {
|
} else {
|
||||||
BauSystem.MESSAGE.send("BACKUP_CREATE_FAILURE", p);
|
BauSystem.MESSAGE.send("BACKUP_CREATE_FAILURE", p);
|
||||||
@@ -75,25 +72,17 @@ public class BackupCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = "load", description = "BACKUP_HELP_LOAD")
|
@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());
|
Region region = Region.getRegion(p.getLocation());
|
||||||
if (checkGlobalRegion(region, p)) {
|
if (checkGlobalRegion(region, p)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File backupFile = region.getBackupFile(backupName.replace('_', ' '));
|
if (backup.load()) {
|
||||||
if (backupFile == null) {
|
BauSystem.MESSAGE.send("BACKUP_LOAD", p);
|
||||||
|
} else {
|
||||||
BauSystem.MESSAGE.send("BACKUP_LOAD_FAILURE", p);
|
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")
|
@Register(value = "list", description = "BACKUP_HELP_LIST")
|
||||||
@@ -102,10 +91,10 @@ public class BackupCommand extends SWCommand {
|
|||||||
if (checkGlobalRegion(region, p)) {
|
if (checkGlobalRegion(region, p)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<String> backups = listBackup(p);
|
List<RegionBackups.Backup> backups = listBackup(p);
|
||||||
BauSystem.MESSAGE.send("BACKUP_LIST_HEAD", p, backups.size());
|
BauSystem.MESSAGE.send("BACKUP_LIST_HEAD", p, backups.size());
|
||||||
backups.forEach(s -> {
|
backups.forEach(backup -> {
|
||||||
BauSystem.MESSAGE.send("BACKUP_LIST_ENTRY", p, "/backup load " + s, new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/backup load " + s), s);
|
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)) {
|
if (checkGlobalRegion(region, p)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<String> backups = listBackup(p);
|
List<RegionBackups.Backup> backups = listBackup(p);
|
||||||
List<SWListInv.SWListEntry<String>> swListEntries = new ArrayList<>();
|
List<SWListInv.SWListEntry<RegionBackups.Backup>> swListEntries = new ArrayList<>();
|
||||||
List<String> lore = Arrays.asList(BauSystem.MESSAGE.parse("BACKUP_LORE", p));
|
List<String> lore = Arrays.asList(BauSystem.MESSAGE.parse("BACKUP_LORE", p));
|
||||||
for (int i = 0; i < backups.size(); i++) {
|
for (int i = 0; i < backups.size(); i++) {
|
||||||
String s = backups.get(i);
|
RegionBackups.Backup backup = backups.get(i);
|
||||||
SWItem swItem = new SWItem(Material.BRICK, BauSystem.MESSAGE.parse("BACKUP_ITEM_NAME", p, s), lore, false, clickType -> {});
|
SWItem swItem = new SWItem(Material.BRICK, BauSystem.MESSAGE.parse("BACKUP_ITEM_NAME", p, backup.getName()), lore, false, clickType -> {});
|
||||||
swItem.getItemStack().setAmount(i + 1);
|
swItem.getItemStack().setAmount(i + 1);
|
||||||
swListEntries.add(new SWListInv.SWListEntry<>(swItem, s));
|
swListEntries.add(new SWListInv.SWListEntry<>(swItem, backup));
|
||||||
}
|
}
|
||||||
SWListInv<String> swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("BACKUP_INV_NAME", p), swListEntries, (clickType, s) -> {
|
SWListInv<RegionBackups.Backup> swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("BACKUP_INV_NAME", p), swListEntries, (clickType, s) -> {
|
||||||
p.getOpenInventory().close();
|
p.getOpenInventory().close();
|
||||||
p.performCommand("backup load " + s);
|
p.performCommand("backup load " + s);
|
||||||
});
|
});
|
||||||
swListInv.open();
|
swListInv.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mapper(value = "backupName", local = true)
|
@Mapper(value = "backup", local = true)
|
||||||
public TypeMapper<String> backupMapper() {
|
public TypeMapper<RegionBackups.Backup> backupMapper() {
|
||||||
return SWCommandUtils.createMapper(s -> s, (commandSender, s) -> listBackup((Player) commandSender));
|
return new TypeMapper<RegionBackups.Backup>() {
|
||||||
|
@Override
|
||||||
|
public RegionBackups.Backup map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||||
|
return Region.getRegion(((Player) commandSender).getLocation()).getBackups().get(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
|
||||||
|
return listBackup((Player) sender).stream().map(RegionBackups.Backup::getName).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> listBackup(Player p) {
|
private List<RegionBackups.Backup> listBackup(Player p) {
|
||||||
Region region = Region.getRegion(p.getLocation());
|
Region region = Region.getRegion(p.getLocation());
|
||||||
if (checkGlobalRegion(region, p)) {
|
if (checkGlobalRegion(region, p)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return region.listBackup().stream().map(s -> s.substring(0, s.length() - 6).replace(' ', '_')).collect(Collectors.toList());
|
return region.getBackups().list();
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.region;
|
package de.steamwar.bausystem.features.region;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.bausystem.utils.ScoreboardElement;
|
import de.steamwar.bausystem.utils.ScoreboardElement;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
@@ -40,8 +41,6 @@ public class RegionScoreboardElement implements ScoreboardElement {
|
|||||||
@Override
|
@Override
|
||||||
public String get(Region region, Player p) {
|
public String get(Region region, Player p) {
|
||||||
if (region.getType().isGlobal()) return null;
|
if (region.getType().isGlobal()) return null;
|
||||||
// TODO: Fix this!
|
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + region.getName();
|
||||||
// return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + region.getName();
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ public class ResetCommand extends SWCommand {
|
|||||||
PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getResetFile(RegionType.NORMAL)))
|
PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getResetFile(RegionType.NORMAL)))
|
||||||
.color(region.getFlags().get(Flag.COLOR).getWithDefault());
|
.color(region.getFlags().get(Flag.COLOR).getWithDefault());
|
||||||
region.getArea().reset(pasteBuilder, false);
|
region.getArea().reset(pasteBuilder, false);
|
||||||
for (Flag value : Flag.getResetFlags()) {
|
for (Flag value : Flag.getFlags()) {
|
||||||
region.getFlags().set(value, value.getDefaultValue());
|
region.getFlags().set(value, value.getDefaultValue());
|
||||||
}
|
}
|
||||||
RegionUtils.message(region, "REGION_RESET_RESETED");
|
RegionUtils.message(region, "REGION_RESET_RESETED");
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.team;
|
package de.steamwar.bausystem.features.team;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.team.boundary.BoundaryViewer;
|
import de.steamwar.bausystem.features.team.boundary.BoundaryViewer;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
@@ -74,7 +75,7 @@ public class SkinCommand extends SWCommand {
|
|||||||
|
|
||||||
String name = String.join(" ", names);
|
String name = String.join(" ", names);
|
||||||
File arenaFile = new File("sections19/" + name + "/" + typeKuerzel + "Arena.schem");
|
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();
|
arenaFile.getParentFile().mkdirs();
|
||||||
if (testblockFile != null) {
|
if (testblockFile != null) {
|
||||||
@@ -89,9 +90,11 @@ public class SkinCommand extends SWCommand {
|
|||||||
return;
|
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) {
|
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();
|
YAPIONObject yapionObject = new YAPIONObject();
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.steamwar.bausystem.region;
|
package de.steamwar.bausystem.region;
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.region.flags.ChangedMode;
|
import de.steamwar.bausystem.region.flags.ChangedMode;
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
@@ -9,6 +8,7 @@ import de.steamwar.linkage.api.Enable;
|
|||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class BackupScheduler implements Enable {
|
public class BackupScheduler implements Enable {
|
||||||
@@ -41,10 +41,11 @@ public class BackupScheduler implements Enable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Region region = regionsToBackup.next();
|
Region region = regionsToBackup.next();
|
||||||
EditSession editSession = region.getArea()
|
Optional<RegionBackups.Backup> backup = region.getBackups()
|
||||||
.copy(false);
|
.create(RegionBackups.BackupType.AUTOMATIC);
|
||||||
// TODO: Implement saving EditSession to schematic!
|
if (backup.isPresent()) {
|
||||||
region.getFlags().set(Flag.CHANGED, ChangedMode.NO_CHANGE);
|
region.getFlags().set(Flag.CHANGED, ChangedMode.NO_CHANGE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.runTaskTimer(BauSystem.getInstance(), 0, 20 * 60);
|
}.runTaskTimer(BauSystem.getInstance(), 0, 20 * 60);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,9 +35,11 @@ public interface Region {
|
|||||||
static Stream<Region> getRegions() {
|
static Stream<Region> getRegions() {
|
||||||
return RegionSystem.INSTANCE.getRegions();
|
return RegionSystem.INSTANCE.getRegions();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Region getRegion(Location location) {
|
static Region getRegion(Location location) {
|
||||||
return RegionSystem.INSTANCE.get(location);
|
return RegionSystem.INSTANCE.get(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Region getGlobalRegion() {
|
static Region getGlobalRegion() {
|
||||||
return RegionSystem.INSTANCE.getGlobalRegion();
|
return RegionSystem.INSTANCE.getGlobalRegion();
|
||||||
}
|
}
|
||||||
@@ -58,6 +60,8 @@ public interface Region {
|
|||||||
|
|
||||||
RegionHistory getHistory();
|
RegionHistory getHistory();
|
||||||
|
|
||||||
|
RegionBackups getBackups();
|
||||||
|
|
||||||
interface Area {
|
interface Area {
|
||||||
|
|
||||||
Area EMPTY = new Area() {
|
Area EMPTY = new Area() {
|
||||||
|
|||||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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<Backup> create(BackupType backupType);
|
||||||
|
|
||||||
|
List<Backup> list();
|
||||||
|
|
||||||
|
Backup get(String name);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user