Skip to content

Commit 91e0cdf

Browse files
committed
Account for possible integer-parse exception if there are WAY too many digits in the file-name-pattern
1 parent 0a1dbbe commit 91e0cdf

File tree

1 file changed

+17
-8
lines changed
  • core/src/main/java/de/bluecolored/bluemap/core/world/mca/region

1 file changed

+17
-8
lines changed

core/src/main/java/de/bluecolored/bluemap/core/world/mca/region/RegionType.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package de.bluecolored.bluemap.core.world.mca.region;
2626

2727
import com.flowpowered.math.vector.Vector2i;
28+
import de.bluecolored.bluemap.core.logger.Logger;
2829
import de.bluecolored.bluemap.core.util.Key;
2930
import de.bluecolored.bluemap.core.util.Keyed;
3031
import de.bluecolored.bluemap.core.util.Registry;
@@ -114,16 +115,24 @@ public String getRegionFileName(int regionX, int regionZ) {
114115
Matcher matcher = regionFileNamePattern.matcher(fileName);
115116
if (!matcher.matches()) return null;
116117

117-
int regionX = Integer.parseInt(matcher.group(1));
118-
int regionZ = Integer.parseInt(matcher.group(2));
118+
try {
119119

120-
// sanity-check for roughly minecraft max boundaries (-30 000 000 to 30 000 000)
121-
if (
122-
regionX < -100000 || regionX > 100000 ||
123-
regionZ < -100000 || regionZ > 100000
124-
) return null;
120+
int regionX = Integer.parseInt(matcher.group(1));
121+
int regionZ = Integer.parseInt(matcher.group(2));
125122

126-
return new Vector2i(regionX, regionZ);
123+
// sanity-check for roughly minecraft max boundaries (-30 000 000 to 30 000 000)
124+
if (
125+
regionX < -100000 || regionX > 100000 ||
126+
regionZ < -100000 || regionZ > 100000
127+
) {
128+
return null;
129+
}
130+
131+
return new Vector2i(regionX, regionZ);
132+
133+
} catch (NumberFormatException ex) {
134+
return null;
135+
}
127136
}
128137

129138
}

0 commit comments

Comments
 (0)