mirror of
https://github.com/itHotL/PlayerStats.git
synced 2024-11-26 12:36:16 +01:00
Made enters configurable, improved indentation, found issue for ComponentFactory getting created twice (is normal)
This commit is contained in:
parent
e06802c906
commit
2bfbf3c73c
@ -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:
|
||||
* <p>Style: "italic"</p>
|
||||
* <p>Color: "gray"</p>*/
|
||||
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:
|
||||
* <p>Style: "none"</p>
|
||||
* <p>Color: "#845EC2"</p>*/
|
||||
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:
|
||||
<p>Style: "none"</p>
|
||||
<p>Color Top: "green"</p>
|
||||
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<String, NamedTextColor> names = NamedTextColor.NAMES;
|
||||
return names.value(textColor);
|
||||
|
@ -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<UUID, CommandSender, TextComponent> 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<UUID, CommandSender, TextComponent> formattedTopStatFunction(@NotNull LinkedHashMap<String, Integer> 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<UUID, CommandSender, TextComponent> getFormattingFunction(@NotNull TextComponent statResult) {
|
||||
private BiFunction<UUID, CommandSender, TextComponent> 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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user