diff --git a/pom.xml b/pom.xml index 6761579..c7f05d6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 io.github.townyadvanced TownyProvinces - 2.3.0 + 2.3.1 townyprovinces diff --git a/src/main/java/io/github/townyadvanced/townyprovinces/data/DataHandlerUtil.java b/src/main/java/io/github/townyadvanced/townyprovinces/data/DataHandlerUtil.java index 870477d..e882505 100644 --- a/src/main/java/io/github/townyadvanced/townyprovinces/data/DataHandlerUtil.java +++ b/src/main/java/io/github/townyadvanced/townyprovinces/data/DataHandlerUtil.java @@ -1,6 +1,5 @@ package io.github.townyadvanced.townyprovinces.data; -import com.palmergames.util.FileMgmt; import io.github.townyadvanced.townyprovinces.TownyProvinces; import io.github.townyadvanced.townyprovinces.objects.Province; import io.github.townyadvanced.townyprovinces.objects.ProvinceType; @@ -89,8 +88,13 @@ private static void loadAllProvinces() { public static void loadProvince(File provinceFile) { //Read values from province file - Map fileEntries = FileMgmt.loadFileIntoHashMap(provinceFile); - TPCoord homeBlock = unpackCoord(fileEntries.get("home_block")); + Map fileEntries = FileUtil.loadFileIntoHashMap(provinceFile); + String homeblockEntry = fileEntries.get("home_block"); + if (homeblockEntry == null) { + TownyProvinces.severe("Could not read home_block value in " + provinceFile.getPath().toString() + ", this province file will not be loaded."); + return; + } + TPCoord homeBlock = unpackCoord(homeblockEntry); //Create province object Province province = new Province(homeBlock); //Read more values @@ -149,8 +153,8 @@ private static Set unpackCoords(String allCoordsAsString) { private static TPCoord unpackCoord(String coordAsString) { String[] coordAsArray = coordAsString.split(","); - int x = Integer.parseInt(coordAsArray[0]); - int z = Integer.parseInt(coordAsArray[1]); + int x = Integer.parseInt(coordAsArray[0].trim()); + int z = Integer.parseInt(coordAsArray[1].trim()); return new TPFinalCoord(x,z); } diff --git a/src/main/java/io/github/townyadvanced/townyprovinces/util/FileUtil.java b/src/main/java/io/github/townyadvanced/townyprovinces/util/FileUtil.java index 0caf712..cfc2884 100644 --- a/src/main/java/io/github/townyadvanced/townyprovinces/util/FileUtil.java +++ b/src/main/java/io/github/townyadvanced/townyprovinces/util/FileUtil.java @@ -1,6 +1,5 @@ package io.github.townyadvanced.townyprovinces.util; -import com.palmergames.bukkit.towny.Towny; import com.palmergames.util.FileMgmt; import io.github.townyadvanced.townyprovinces.TownyProvinces; import io.github.townyadvanced.townyprovinces.messaging.Messaging; @@ -19,7 +18,6 @@ import java.util.Map; import java.util.Objects; import java.util.Properties; -import java.util.logging.Level; public class FileUtil { @@ -79,6 +77,24 @@ public static void saveListIntoFile(List linesToWrite, String filePath) } } + public static HashMap loadFileIntoHashMap(File file) { + + HashMap keys = new HashMap<>(); + try (FileInputStream fis = new FileInputStream(file); + InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8)) { + Properties properties = new Properties(); + properties.load(isr); + for (String key : properties.stringPropertyNames()) { + String value = properties.getProperty(key); + keys.put(key, String.valueOf(value)); + } + } catch (IOException e) { + TownyProvinces.severe("An exception occurred while reading file " + file.getName()); + e.printStackTrace(); + } + return keys; + } + public static List readRegionDefinitionFiles() { return readListOfFiles(REGION_DEFINITIONS_FOLDER_PATH); } @@ -131,22 +147,4 @@ public static boolean createRegionDefinitionsFolderAndSampleFiles() { return false; } } - - public static HashMap loadFileIntoHashMap(File file) { - - HashMap keys = new HashMap<>(); - try (FileInputStream fis = new FileInputStream(file); - InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8)) { - Properties properties = new Properties(); - properties.load(isr); - for (String key : properties.stringPropertyNames()) { - String value = properties.getProperty(key); - keys.put(key, String.valueOf(value)); - } - } catch (IOException e) { - Towny.getPlugin().getLogger().log(Level.WARNING, "An exception occurred while reading file " + file.getName(), e); - } - return keys; - - } }