forked from SteamWar/SteamWar
Add RegionDataRepository
This commit is contained in:
@@ -28,6 +28,11 @@ public enum RegionType {
|
||||
|
||||
GLOBAL(true),
|
||||
NORMAL(false),
|
||||
|
||||
SPAWN(false),
|
||||
SPAWN_PATH(false),
|
||||
SPAWN_EXTENSION(false),
|
||||
PATH(false),
|
||||
;
|
||||
|
||||
private final boolean global;
|
||||
|
||||
@@ -43,5 +43,4 @@ dependencies {
|
||||
compileOnly(libs.fawe18)
|
||||
|
||||
implementation(libs.luaj)
|
||||
implementation(files("$projectDir/../libs/YAPION-SNAPSHOT.jar"))
|
||||
}
|
||||
|
||||
+1
-3
@@ -66,9 +66,7 @@ public class DynamicRegionSystem implements RegionSystem {
|
||||
if (tile.isEmpty()) return DynamicGlobalRegion.INSTANCE;
|
||||
UUID uuid = tileMap.get(tile.get());
|
||||
if (uuid == null) return DynamicGlobalRegion.INSTANCE;
|
||||
Region region = regionMap.get(uuid);
|
||||
if (region == null) return DynamicGlobalRegion.INSTANCE;
|
||||
return region;
|
||||
return regionMap.getOrDefault(uuid, DynamicGlobalRegion.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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.dynamic;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import de.steamwar.bausystem.region.FlagStorage;
|
||||
import de.steamwar.bausystem.region.RegionBackups;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import lombok.NonNull;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@UtilityClass
|
||||
public class RegionDataRepository {
|
||||
|
||||
private static File regionDataFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions");
|
||||
|
||||
static {
|
||||
regionDataFolder.mkdirs();
|
||||
}
|
||||
|
||||
public File getRegionDirectory(DynamicRegion region) {
|
||||
File file = new File(regionDataFolder, region.getID().toString());
|
||||
file.mkdirs();
|
||||
return file;
|
||||
}
|
||||
|
||||
public void loadFlagStorage(DynamicRegion region, FlagStorage storage) {
|
||||
File file = getRegionDirectory(region);
|
||||
file = new File(file, "flags.json");
|
||||
loadFlagStorage(file, storage);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private void loadFlagStorage(File file, FlagStorage storage) {
|
||||
JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject();
|
||||
for (Flag flag : Flag.getFlags()) {
|
||||
Flag.Value<?> value;
|
||||
try {
|
||||
value = flag.valueOfValue(jsonObject.get(flag.name()).getAsString());
|
||||
} catch (IllegalArgumentException e) {
|
||||
continue;
|
||||
}
|
||||
storage.getBackedMap().put(flag, value);
|
||||
}
|
||||
}
|
||||
|
||||
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd'_'HH:mm:ss");
|
||||
public RegionBackups getBackups(DynamicRegion region) {
|
||||
if (region.getType().isGlobal()) {
|
||||
return RegionBackups.EMPTY;
|
||||
}
|
||||
|
||||
File directory = new File(getRegionDirectory(region), "backup");
|
||||
directory.mkdirs();
|
||||
return new RegionBackups() {
|
||||
@Override
|
||||
public Optional<Backup> create(BackupType backupType) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<Backup> list() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Backup get(String name) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user