Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.townyadvanced</groupId>
<artifactId>TownyProvinces</artifactId>
<version>2.3.0</version>
<version>2.3.1</version>
<name>townyprovinces</name> <!-- Leave lower-cased -->

<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -89,8 +88,13 @@ private static void loadAllProvinces() {

public static void loadProvince(File provinceFile) {
//Read values from province file
Map<String,String> fileEntries = FileMgmt.loadFileIntoHashMap(provinceFile);
TPCoord homeBlock = unpackCoord(fileEntries.get("home_block"));
Map<String,String> 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
Expand Down Expand Up @@ -149,8 +153,8 @@ private static Set<TPCoord> 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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,7 +18,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.logging.Level;

public class FileUtil {

Expand Down Expand Up @@ -79,6 +77,24 @@ public static void saveListIntoFile(List<String> linesToWrite, String filePath)
}
}

public static HashMap<String, String> loadFileIntoHashMap(File file) {

HashMap<String, String> 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<File> readRegionDefinitionFiles() {
return readListOfFiles(REGION_DEFINITIONS_FOLDER_PATH);
}
Expand Down Expand Up @@ -131,22 +147,4 @@ public static boolean createRegionDefinitionsFolderAndSampleFiles() {
return false;
}
}

public static HashMap<String, String> loadFileIntoHashMap(File file) {

HashMap<String, String> 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;

}
}