diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/config/ConfigHandler.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/config/ConfigHandler.java index 15f16ec..f203993 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/config/ConfigHandler.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/config/ConfigHandler.java @@ -229,6 +229,21 @@ public class ConfigHandler { return config.getInt("hover-text-amount-lighter", 20); } + /** Returns a String that represents either a Chat Color, hex color code, or a Style. Default values are: + *

Style: "italic"

+ *

Color: "gray"

*/ + public String getSharedByTextDecoration(boolean getStyle) { + String def = getStyle ? "italic" : "gray"; + return getDecorationString(null, getStyle, def, "shared-by"); + } + + /** Returns a String that represents either a Chat Color, hex color code, or a Style. Default values are: + *

Style: "none"

+ *

Color: "#845EC2"

*/ + public String getSharerNameDecoration(boolean getStyle) { + return getDecorationString(null, getStyle, "#845EC2", "player-name"); + } + /** Returns a String that represents either a Chat Color, hex color code, or a Style. Default values are:

Style: "none"

Color Top: "green"

@@ -360,6 +375,9 @@ public class ConfigHandler { /** Returns the config section that contains the relevant color or style option. */ private @Nullable ConfigurationSection getRelevantSection(Target selection) { + if (selection == null) { //rather than rework the whole Target enum, I have added shared-stats as the null-option for now + return config.getConfigurationSection("shared-stats"); + } switch (selection) { case TOP -> { return config.getConfigurationSection("top-list"); diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/BukkitConsoleComponentFactory.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/BukkitConsoleComponentFactory.java index 20198c1..d55d471 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/BukkitConsoleComponentFactory.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/BukkitConsoleComponentFactory.java @@ -4,6 +4,7 @@ import com.gmail.artemis.the.gr8.playerstats.config.ConfigHandler; import com.gmail.artemis.the.gr8.playerstats.enums.DebugLevel; import com.gmail.artemis.the.gr8.playerstats.enums.PluginColor; import com.gmail.artemis.the.gr8.playerstats.utils.MyLogger; +import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextColor; public class BukkitConsoleComponentFactory extends ComponentFactory { @@ -31,4 +32,10 @@ public class BukkitConsoleComponentFactory extends ComponentFactory { public TextColor getSharerNameColor() { return PluginColor.NAME_5.getConsoleColor(); } + + @Override + protected TextColor getHexColor(String hexColor) { + TextColor hex = TextColor.fromHexString(hexColor); + return hex != null ? NamedTextColor.nearestTo(hex) : NamedTextColor.WHITE; + } } \ No newline at end of file diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/ComponentFactory.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/ComponentFactory.java index 44ef554..f0bcfec 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/ComponentFactory.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/ComponentFactory.java @@ -65,11 +65,6 @@ public class ComponentFactory { HOVER_ACCENT = PluginColor.LIGHT_GOLD.getColor(); } - //TODO try the share-purple for sharer-names - public TextColor getSharerNameColor() { - return PluginColor.NAME_5.getColor(); - } - public TextColor prefix() { return PREFIX; } @@ -101,6 +96,10 @@ public class ComponentFactory { return HOVER_ACCENT; } + public TextColor getSharerNameColor() { + return getColorFromString(config.getSharerNameDecoration(false)); + } + /** Returns [PlayerStats]. */ public TextComponent pluginPrefixComponent() { @@ -321,17 +320,19 @@ public class ComponentFactory { public TextComponent messageSharedComponent(Component playerName) { return surroundingBracketComponent( - text().append(text("Shared by") - .color(BRACKETS) - .decorate(TextDecoration.ITALIC)) + text().append( + getComponent("Shared by", + getColorFromString(config.getSharedByTextDecoration(false)), + getStyleFromString(config.getSharedByTextDecoration(true)))) .append(space()) .append(playerName) .build()); } public TextComponent sharerNameComponent(String sharerName) { - return text(sharerName) - .color(getSharerNameColor()); + return getComponent(sharerName, + getSharerNameColor(), + getStyleFromString(config.getSharerNameDecoration(true))); } private TextComponent surroundingBracketComponent(TextComponent component) { @@ -394,7 +395,7 @@ public class ComponentFactory { if (configString != null) { try { if (configString.contains("#")) { - return TextColor.fromHexString(configString); + return getHexColor(configString); } else { return getTextColorByName(configString); @@ -407,6 +408,10 @@ public class ComponentFactory { return null; } + protected TextColor getHexColor(String hexColor) { + return TextColor.fromHexString(hexColor); + } + private TextColor getTextColorByName(String textColor) { Index names = NamedTextColor.NAMES; return names.value(textColor); diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/MessageWriter.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/MessageWriter.java index f519bcb..80c81ac 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/MessageWriter.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/MessageWriter.java @@ -167,7 +167,7 @@ public class MessageWriter { .append(getStatUnitComponent(request.getStatistic(), request.getSelection(), request.isConsoleSender())) //space is provided by statUnitComponent .build(); - return getFormattingFunction(playerStat); + return getFormattingFunction(playerStat, config.useEnters()); } public BiFunction formattedServerStatFunction(long stat, @NotNull StatRequest request) { @@ -182,18 +182,20 @@ public class MessageWriter { .append(getStatUnitComponent(request.getStatistic(), request.getSelection(), request.isConsoleSender())) //space is provided by statUnit .build(); - return getFormattingFunction(serverStat); + return getFormattingFunction(serverStat, config.useEnters()); } public BiFunction formattedTopStatFunction(@NotNull LinkedHashMap topStats, @NotNull StatRequest request) { - TextComponent title = getTopStatsTitle(request, topStats.size()); - TextComponent shortTitle = getTopStatsTitleShort(request, topStats.size()); - TextComponent list = getTopStatList(topStats, request); + final TextComponent title = getTopStatsTitle(request, topStats.size()); + final TextComponent shortTitle = getTopStatsTitleShort(request, topStats.size()); + final TextComponent list = getTopStatList(topStats, request); + final boolean useEnters = config.useEnters(); - //TODO make use-enters configurable return (shareCode, sender) -> { - TextComponent.Builder topBuilder = text().append(newline()); - + TextComponent.Builder topBuilder = text(); + if (useEnters) { + topBuilder.append(newline()); + } //if we're adding a share-button if (shareCode != null) { topBuilder.append(title) @@ -222,11 +224,13 @@ public class MessageWriter { }; } - private BiFunction getFormattingFunction(@NotNull TextComponent statResult) { + private BiFunction getFormattingFunction(@NotNull TextComponent statResult, boolean useEnters) { return (shareCode, sender) -> { - TextComponent.Builder statBuilder = text().append(newline()); + TextComponent.Builder statBuilder = text(); + if (useEnters) { + statBuilder.append(newline()); + } - //TODO make use-enters configurable //if we're adding a share-button if (shareCode != null) { statBuilder.append(statResult) @@ -282,7 +286,7 @@ public class MessageWriter { for (String playerName : playerNames) { TextComponent.Builder playerNameBuilder = componentFactory.playerNameBuilder(playerName, Target.TOP); topList.append(newline()) - .append(componentFactory.rankingNumberComponent(++count + ".")) + .append(componentFactory.rankingNumberComponent(" " + ++count + ".")) .append(space()); if (useDots) { topList.append(playerNameBuilder) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 26ac7fa..829a9e9 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -121,6 +121,15 @@ hover-text-amount-lighter: 40 # # black white # # # # ------------------------------ # # + +shared-stats: + shared-by: gray + shared-by-style: italic + + player-name: "#EE8A19" + player-name-style: none + + top-list: title: '#FFD52B' title-style: none