diff --git a/src/main/java/com/mattmx/nametags/config/TextDisplayMetaConfiguration.java b/src/main/java/com/mattmx/nametags/config/TextDisplayMetaConfiguration.java index 3585217..ef636d6 100644 --- a/src/main/java/com/mattmx/nametags/config/TextDisplayMetaConfiguration.java +++ b/src/main/java/com/mattmx/nametags/config/TextDisplayMetaConfiguration.java @@ -54,15 +54,24 @@ public static void applyMeta(@NotNull ConfigurationSection section, @NotNull Tex } else if (NamedTextColor.NAMES.value(backgroundColor) != null) { background = 0x40000000 | Objects.requireNonNull(NamedTextColor.NAMES.value(backgroundColor)).value(); } else if (backgroundColor.startsWith("#")) { - int intValue = Integer.parseInt(backgroundColor.replace("#", ""), 16); - Color color = Color.fromARGB(intValue); - - // Set a default alpha of 0x40 (minecraft's internal default) - if (color.getAlpha() == 0 && !backgroundColor.startsWith("#00")) { - background = color.setAlpha(0x40).asARGB(); + String hex = backgroundColor.replace("#", ""); + + int rgb; + int a; + if (hex.length() == 6) { + rgb = Integer.parseInt(hex, 16); + // Set a default alpha of 0x40 (minecraft's internal default) + a = 0x40; + } else if (hex.length() == 8) { + rgb = Integer.parseInt(hex.substring(2), 16); + a = Integer.parseInt(hex.substring(0, 2), 16); } else { - background = color.asARGB(); + throw new RuntimeException(String.format("Invalid hex string '#%s'!", hex)); } + + Color color = Color.fromARGB(rgb).setAlpha(a); + + background = color.asARGB(); } else { background = NameTags.TRANSPARENT; } diff --git a/src/main/java/com/mattmx/nametags/entity/trait/SneakTrait.java b/src/main/java/com/mattmx/nametags/entity/trait/SneakTrait.java index 7f38a15..3a18f65 100644 --- a/src/main/java/com/mattmx/nametags/entity/trait/SneakTrait.java +++ b/src/main/java/com/mattmx/nametags/entity/trait/SneakTrait.java @@ -24,12 +24,6 @@ public void updateSneak(boolean sneaking) { Color color = Color.fromARGB(meta.getBackgroundColor()); if (sneaking) { - - // If it's transparent then we shouldn't do anything really - if (color.getAlpha() == 0) { - return; - } - previousBackgroundOpacity = color.getAlpha(); previousTextOpacity = meta.getTextOpacity(); @@ -45,6 +39,10 @@ public void updateSneak(boolean sneaking) { } public Color withCustomSneakOpacity(@NotNull Color previous) { + if (previous.getAlpha() == 0) { + return previous; + } + return previous.setAlpha(getCustomOpacity()); }