From 1546f354683ec0312d9e5d916d6e6d07a3d8ba3f Mon Sep 17 00:00:00 2001 From: CarmJos Date: Sat, 19 Feb 2022 03:26:49 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=87=E7=94=A8=E5=8E=9F=E5=A7=8B=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/RegionManager.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/cc/carm/plugin/regionprotection/manager/RegionManager.java b/src/main/java/cc/carm/plugin/regionprotection/manager/RegionManager.java index 7fc5105..5386cd8 100644 --- a/src/main/java/cc/carm/plugin/regionprotection/manager/RegionManager.java +++ b/src/main/java/cc/carm/plugin/regionprotection/manager/RegionManager.java @@ -1,16 +1,17 @@ package cc.carm.plugin.regionprotection.manager; -import cc.carm.lib.easyplugin.configuration.file.FileConfig; import cc.carm.plugin.regionprotection.Main; import cc.carm.plugin.regionprotection.model.ProtectedRegion; import com.google.common.collect.ImmutableMap; import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; +import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -19,12 +20,18 @@ public class RegionManager { - private FileConfig regionsConfiguration; + private File configFile; + private FileConfiguration configuration; private Map regions = new HashMap<>(); public boolean initConfiguration() { try { - this.regionsConfiguration = new FileConfig(Main.getInstance(), "regions.yml"); + this.configFile = new File(Main.getInstance().getDataFolder(), "regions.yml"); + if (!this.configFile.exists()) { + Main.getInstance().saveResource("regions.yml", false); + } + + this.configuration = YamlConfiguration.loadConfiguration(this.configFile); return true; } catch (Exception ex) { ex.printStackTrace(); @@ -33,13 +40,8 @@ public boolean initConfiguration() { } public int reload() { - try { - this.regionsConfiguration.reload(); - return loadRegions(); - } catch (IOException e) { - e.printStackTrace(); - return -1; - } + initConfiguration(); + return loadRegions(); } public int loadRegions() { @@ -89,13 +91,13 @@ public void removeRegion(@NotNull String name) { } protected FileConfiguration getRegionsConfiguration() { - return this.regionsConfiguration.getConfig(); + return this.configuration; } public void saveConfig() { try { Main.debugging("Try saving regions.yml"); - this.regionsConfiguration.save(); + this.configuration.save(this.configFile); } catch (IOException e) { e.printStackTrace(); }