diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/MapSettingsSerializer.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/MapSettingsSerializer.java index 3d897505..7a551e2c 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/MapSettingsSerializer.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/MapSettingsSerializer.java @@ -6,7 +6,6 @@ import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import de.bluecolored.bluemap.core.map.lowres.LowresTileManager; -import de.bluecolored.bluemap.core.util.ConfigUtils; import de.bluecolored.bluemap.core.util.math.Color; import java.lang.reflect.Type; @@ -48,7 +47,7 @@ public JsonElement serialize(BmMap map, Type typeOfSrc, JsonSerializationContext root.add("startPos", context.serialize(startPos)); // skyColor - Color skyColor = new Color().set(ConfigUtils.parseColorFromString(map.getMapSettings().getSkyColor())); + Color skyColor = new Color().parse(map.getMapSettings().getSkyColor()); root.add("skyColor", context.serialize(skyColor)); // ambientLight diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/BlockColorCalculatorFactory.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/BlockColorCalculatorFactory.java index 3e6f69ac..d19498f3 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/BlockColorCalculatorFactory.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/BlockColorCalculatorFactory.java @@ -27,7 +27,6 @@ import com.flowpowered.math.GenericMath; import com.google.gson.stream.JsonReader; import de.bluecolored.bluemap.api.debug.DebugDump; -import de.bluecolored.bluemap.core.util.ConfigUtils; import de.bluecolored.bluemap.core.util.math.Color; import de.bluecolored.bluemap.core.world.Biome; import de.bluecolored.bluemap.core.world.BlockNeighborhood; @@ -79,7 +78,7 @@ public void load(Path configFile) throws IOException { break; default: final Color color = new Color(); - color.set(ConfigUtils.parseColorFromString(value)).premultiplied(); + color.parse(value).premultiplied(); colorFunction = (calculator, block, target) -> target.set(color); break; } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/adapter/ColorAdapter.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/adapter/ColorAdapter.java index cfbed50f..9f04740c 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/adapter/ColorAdapter.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/adapter/ColorAdapter.java @@ -4,7 +4,6 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; import com.google.gson.stream.JsonWriter; -import de.bluecolored.bluemap.core.util.ConfigUtils; import de.bluecolored.bluemap.core.util.math.Color; import java.io.IOException; @@ -55,7 +54,7 @@ public Color read(JsonReader in) throws IOException { in.endObject(); break; case STRING: - value.set(ConfigUtils.parseColorFromString(in.nextString())); + value.parse(in.nextString()); break; case NUMBER: int color = in.nextInt(); diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/ConfigUtils.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/ConfigUtils.java deleted file mode 100644 index 33f82a4e..00000000 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/ConfigUtils.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of BlueMap, licensed under the MIT License (MIT). - * - * Copyright (c) Blue (Lukas Rieger) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package de.bluecolored.bluemap.core.util; - -public class ConfigUtils { - - private ConfigUtils(){} - - /** - * Returns a color-integer. The value can be an integer in String-Format or a string in hexadecimal format prefixed with # (css-style: e.g. #f16 becomes #ff1166). - * @param val The String to parse - * @return The parsed Integer - * @throws NumberFormatException If the value is not formatted correctly or if there is no value present. - */ - public static int parseColorFromString(String val) { - if (val.charAt(0) == '#') { - val = val.substring(1); - if (val.length() == 3) val = val + "f"; - if (val.length() == 4) val = "" + val.charAt(0) + val.charAt(0) + val.charAt(1) + val.charAt(1) + val.charAt(2) + val.charAt(2) + val.charAt(3) + val.charAt(3); - if (val.length() == 6) val = val + "ff"; - if (val.length() != 8) throw new NumberFormatException("Invalid color format!"); - val = val.substring(6, 8) + val.substring(0, 6); // move alpha to front - return Integer.parseUnsignedInt(val, 16); - } - - int color = Integer.parseInt(val); - if ((color & 0xFF000000) == 0) color |= 0xFF000000; // assume full alpha if not present - return color; - } - -} diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/math/Color.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/math/Color.java index a5355867..56f42b2e 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/math/Color.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/math/Color.java @@ -26,6 +26,7 @@ import de.bluecolored.bluemap.api.debug.DebugDump; +@SuppressWarnings("UnusedReturnValue") @DebugDump public class Color { @@ -162,6 +163,29 @@ public Color straight() { return this; } + /** + * Parses the color from a string and sets it to this Color instance. + * The value can be an integer in String-Format or a string in hexadecimal format prefixed with # (css-style: e.g. #f16 becomes #ff1166). + * @param val The String to parse + * @return The parsed Integer + * @throws NumberFormatException If the value is not formatted correctly or if there is no value present. + */ + public Color parse(String val) { + if (val.charAt(0) == '#') { + val = val.substring(1); + if (val.length() == 3) val = val + "f"; + if (val.length() == 4) val = "" + val.charAt(0) + val.charAt(0) + val.charAt(1) + val.charAt(1) + val.charAt(2) + val.charAt(2) + val.charAt(3) + val.charAt(3); + if (val.length() == 6) val = val + "ff"; + if (val.length() != 8) throw new NumberFormatException("Invalid color format!"); + val = val.substring(6, 8) + val.substring(0, 6); // move alpha to front + return set(Integer.parseUnsignedInt(val, 16)); + } + + int color = Integer.parseInt(val); + if ((color & 0xFF000000) == 0) color |= 0xFF000000; // assume full alpha if not present + return set(color); + } + @Override public String toString() { return "Color{" +