Change Map Reduction flag to be an int property to avoid number parsing (#2460)

* Change Map Reduction flag to be an int property to avoid number parsing
This commit is contained in:
GreatWyrm 2024-10-31 12:24:53 -07:00 committed by GitHub
parent 16c9182ab0
commit c148954a47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 10 deletions

View File

@ -56,7 +56,7 @@ public final class ServerFlag {
// Maps
public static final @NotNull String MAP_RGB_MAPPING = stringProperty("minestom.map.rgbmapping", "lazy");
public static final @Nullable String MAP_RGB_REDUCTION = stringProperty("minestom.map.rgbreduction"); // Only used if rgb mapping is "approximate"
public static final int MAP_RGB_REDUCTION = intProperty("minestom.map.rgbreduction", -1); // Only used if rgb mapping is "approximate"
// Entities
public static final boolean ENFORCE_INTERACTION_LIMIT = booleanProperty("minestom.enforce-entity-interaction-range", true);

View File

@ -1,6 +1,5 @@
package net.minestom.server.map;
import net.minestom.server.MinecraftServer;
import net.minestom.server.ServerFlag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -92,15 +91,10 @@ public enum MapColors {
mappingStrategy = strategy;
int reduction = 10;
if (ServerFlag.MAP_RGB_REDUCTION != null) {
try {
reduction = Integer.parseInt(ServerFlag.MAP_RGB_REDUCTION);
} catch (NumberFormatException e) {
logger.error("Invalid integer in reduction argument: {}", ServerFlag.MAP_RGB_REDUCTION);
MinecraftServer.getExceptionManager().handleException(e);
}
if (ServerFlag.MAP_RGB_REDUCTION != -1) {
reduction = ServerFlag.MAP_RGB_REDUCTION;
if (reduction < 0 || reduction >= 255) {
if (reduction < 0 || reduction > 255) {
logger.warn("Reduction was found to be invalid: {}. Must in 0-255, defaulting to 10.", reduction);
reduction = 10;
}