Skip to content

Commit da319b6

Browse files
authored
Fix bugs in reloading. (#122)
- Fixes `/tpra region regenerate all` breaking on latest Towny release. - Closes #121 - Fixes an issue cancelling the map task when no map task is run. - Bump min. Towny version to 0.102.0.0.
1 parent 1022ebd commit da319b6

File tree

5 files changed

+41
-28
lines changed

5 files changed

+41
-28
lines changed

pom.xml

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<java.version>1.16</java.version>
1212
<project.bukkitAPIVersion>1.15</project.bukkitAPIVersion>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14-
<towny.version>0.101.2.5</towny.version>
14+
<towny.version>0.102.0.0</towny.version>
1515
</properties>
1616

1717
<repositories>
@@ -38,32 +38,18 @@
3838
</repositories>
3939

4040
<dependencies>
41-
42-
<dependency>
43-
<groupId>io.papermc.paper</groupId>
44-
<artifactId>paper-api</artifactId>
45-
<version>1.21.8-R0.1-SNAPSHOT</version>
46-
<scope>provided</scope>
47-
</dependency>
48-
<!-- <dependency>
49-
<groupId>com.palmergames.bukkit.towny</groupId>
50-
<artifactId>towny</artifactId>
51-
<version>${towny.version}</version>
52-
<scope>provided</scope>
53-
</dependency>-->
54-
<dependency>
55-
<groupId>com.github.TownyAdvanced.Towny</groupId>
56-
<artifactId>towny</artifactId>
57-
<version>master-4907b3123a-1</version>
58-
</dependency>
59-
<!--
6041
<dependency>
61-
<groupId>us.dynmap</groupId>
62-
<artifactId>dynmap-api</artifactId>
63-
<version>2.5</version>
42+
<groupId>io.papermc.paper</groupId>
43+
<artifactId>paper-api</artifactId>
44+
<version>1.21.8-R0.1-SNAPSHOT</version>
45+
<scope>provided</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>com.palmergames.bukkit.towny</groupId>
49+
<artifactId>towny</artifactId>
50+
<version>${towny.version}</version>
6451
<scope>provided</scope>
6552
</dependency>
66-
-->
6753
<dependency>
6854
<groupId>us.dynmap</groupId>
6955
<artifactId>dynmap-api</artifactId>

src/main/java/io/github/townyadvanced/townyprovinces/TownyProvinces.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class TownyProvinces extends JavaPlugin {
4242
public static final Object PRICE_RECALCULATION_JOB_LOCK = new Object();
4343
public static final Object MAP_DISPLAY_JOB_LOCK = new Object();
4444
private static TownyProvinces plugin;
45-
private static final Version requiredTownyVersion = Version.fromString("0.101.2.5");
45+
private static final Version requiredTownyVersion = Version.fromString("0.102.0.0");
4646
private final TaskScheduler scheduler;
4747

4848
public TownyProvinces() {

src/main/java/io/github/townyadvanced/townyprovinces/jobs/map_display/MapDisplayTaskController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public static boolean startTask() {
2727

2828
public static void reloadIntegrations() {
2929

30-
mapDisplayTask.cancel();
30+
if (mapDisplayTask != null)
31+
mapDisplayTask.cancel();
3132
synchronized (TownyProvinces.MAP_DISPLAY_JOB_LOCK) {
3233
synchronized (TownyProvinces.REGION_REGENERATION_JOB_LOCK) {
3334
synchronized (TownyProvinces.PRICE_RECALCULATION_JOB_LOCK) {

src/main/java/io/github/townyadvanced/townyprovinces/objects/Region.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package io.github.townyadvanced.townyprovinces.objects;
22

33
import com.palmergames.bukkit.towny.object.Coord;
4-
import com.palmergames.util.FileMgmt;
54
import io.github.townyadvanced.townyprovinces.settings.TownyProvincesSettings;
5+
import io.github.townyadvanced.townyprovinces.util.FileUtil;
6+
67
import org.bukkit.Location;
78

89
import java.io.File;
@@ -36,7 +37,7 @@ public class Region {
3637
private Set<Province> provinces; //Set of provinces. Assigned when required
3738

3839
public Region(File regionDefinitionFile) {
39-
Map<String, String> regionDefinitions = FileMgmt.loadFileIntoHashMap(regionDefinitionFile);
40+
Map<String, String> regionDefinitions = FileUtil.loadFileIntoHashMap(regionDefinitionFile);
4041
this.name = TownyProvincesSettings.getRegionName(regionDefinitions);
4142
this.brushSquareRadiusInChunks = TownyProvincesSettings.getBrushSquareRadiusInChunks(regionDefinitions);
4243
this.provinceSquareRadius = TownyProvincesSettings.calculateProvinceSquareRadius(regionDefinitions);

src/main/java/io/github/townyadvanced/townyprovinces/util/FileUtil.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
package io.github.townyadvanced.townyprovinces.util;
22

3+
import com.palmergames.bukkit.towny.Towny;
34
import com.palmergames.util.FileMgmt;
45
import io.github.townyadvanced.townyprovinces.TownyProvinces;
56
import io.github.townyadvanced.townyprovinces.messaging.Messaging;
67
import org.bukkit.Bukkit;
78

89
import java.io.File;
10+
import java.io.FileInputStream;
911
import java.io.IOException;
12+
import java.io.InputStreamReader;
13+
import java.nio.charset.StandardCharsets;
1014
import java.nio.file.Path;
1115
import java.util.ArrayList;
1216
import java.util.Arrays;
17+
import java.util.HashMap;
1318
import java.util.List;
1419
import java.util.Map;
1520
import java.util.Objects;
21+
import java.util.Properties;
22+
import java.util.logging.Level;
1623

1724
public class FileUtil {
1825

@@ -124,4 +131,22 @@ public static boolean createRegionDefinitionsFolderAndSampleFiles() {
124131
return false;
125132
}
126133
}
134+
135+
public static HashMap<String, String> loadFileIntoHashMap(File file) {
136+
137+
HashMap<String, String> keys = new HashMap<>();
138+
try (FileInputStream fis = new FileInputStream(file);
139+
InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8)) {
140+
Properties properties = new Properties();
141+
properties.load(isr);
142+
for (String key : properties.stringPropertyNames()) {
143+
String value = properties.getProperty(key);
144+
keys.put(key, String.valueOf(value));
145+
}
146+
} catch (IOException e) {
147+
Towny.getPlugin().getLogger().log(Level.WARNING, "An exception occurred while reading file " + file.getName(), e);
148+
}
149+
return keys;
150+
151+
}
127152
}

0 commit comments

Comments
 (0)