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);
|
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:
|
/** Returns a String that represents either a Chat Color, hex color code, or a Style. Default values are:
|
||||||
<p>Style: "none"</p>
|
<p>Style: "none"</p>
|
||||||
<p>Color Top: "green"</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. */
|
/** Returns the config section that contains the relevant color or style option. */
|
||||||
private @Nullable ConfigurationSection getRelevantSection(Target selection) {
|
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) {
|
switch (selection) {
|
||||||
case TOP -> {
|
case TOP -> {
|
||||||
return config.getConfigurationSection("top-list");
|
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.DebugLevel;
|
||||||
import com.gmail.artemis.the.gr8.playerstats.enums.PluginColor;
|
import com.gmail.artemis.the.gr8.playerstats.enums.PluginColor;
|
||||||
import com.gmail.artemis.the.gr8.playerstats.utils.MyLogger;
|
import com.gmail.artemis.the.gr8.playerstats.utils.MyLogger;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
|
||||||
public class BukkitConsoleComponentFactory extends ComponentFactory {
|
public class BukkitConsoleComponentFactory extends ComponentFactory {
|
||||||
@ -31,4 +32,10 @@ public class BukkitConsoleComponentFactory extends ComponentFactory {
|
|||||||
public TextColor getSharerNameColor() {
|
public TextColor getSharerNameColor() {
|
||||||
return PluginColor.NAME_5.getConsoleColor();
|
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();
|
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() {
|
public TextColor prefix() {
|
||||||
return PREFIX;
|
return PREFIX;
|
||||||
}
|
}
|
||||||
@ -101,6 +96,10 @@ public class ComponentFactory {
|
|||||||
return HOVER_ACCENT;
|
return HOVER_ACCENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TextColor getSharerNameColor() {
|
||||||
|
return getColorFromString(config.getSharerNameDecoration(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Returns [PlayerStats]. */
|
/** Returns [PlayerStats]. */
|
||||||
public TextComponent pluginPrefixComponent() {
|
public TextComponent pluginPrefixComponent() {
|
||||||
@ -321,17 +320,19 @@ public class ComponentFactory {
|
|||||||
|
|
||||||
public TextComponent messageSharedComponent(Component playerName) {
|
public TextComponent messageSharedComponent(Component playerName) {
|
||||||
return surroundingBracketComponent(
|
return surroundingBracketComponent(
|
||||||
text().append(text("Shared by")
|
text().append(
|
||||||
.color(BRACKETS)
|
getComponent("Shared by",
|
||||||
.decorate(TextDecoration.ITALIC))
|
getColorFromString(config.getSharedByTextDecoration(false)),
|
||||||
|
getStyleFromString(config.getSharedByTextDecoration(true))))
|
||||||
.append(space())
|
.append(space())
|
||||||
.append(playerName)
|
.append(playerName)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextComponent sharerNameComponent(String sharerName) {
|
public TextComponent sharerNameComponent(String sharerName) {
|
||||||
return text(sharerName)
|
return getComponent(sharerName,
|
||||||
.color(getSharerNameColor());
|
getSharerNameColor(),
|
||||||
|
getStyleFromString(config.getSharerNameDecoration(true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private TextComponent surroundingBracketComponent(TextComponent component) {
|
private TextComponent surroundingBracketComponent(TextComponent component) {
|
||||||
@ -394,7 +395,7 @@ public class ComponentFactory {
|
|||||||
if (configString != null) {
|
if (configString != null) {
|
||||||
try {
|
try {
|
||||||
if (configString.contains("#")) {
|
if (configString.contains("#")) {
|
||||||
return TextColor.fromHexString(configString);
|
return getHexColor(configString);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return getTextColorByName(configString);
|
return getTextColorByName(configString);
|
||||||
@ -407,6 +408,10 @@ public class ComponentFactory {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected TextColor getHexColor(String hexColor) {
|
||||||
|
return TextColor.fromHexString(hexColor);
|
||||||
|
}
|
||||||
|
|
||||||
private TextColor getTextColorByName(String textColor) {
|
private TextColor getTextColorByName(String textColor) {
|
||||||
Index<String, NamedTextColor> names = NamedTextColor.NAMES;
|
Index<String, NamedTextColor> names = NamedTextColor.NAMES;
|
||||||
return names.value(textColor);
|
return names.value(textColor);
|
||||||
|
@ -167,7 +167,7 @@ public class MessageWriter {
|
|||||||
.append(getStatUnitComponent(request.getStatistic(), request.getSelection(), request.isConsoleSender())) //space is provided by statUnitComponent
|
.append(getStatUnitComponent(request.getStatistic(), request.getSelection(), request.isConsoleSender())) //space is provided by statUnitComponent
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return getFormattingFunction(playerStat);
|
return getFormattingFunction(playerStat, config.useEnters());
|
||||||
}
|
}
|
||||||
|
|
||||||
public BiFunction<UUID, CommandSender, TextComponent> formattedServerStatFunction(long stat, @NotNull StatRequest request) {
|
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
|
.append(getStatUnitComponent(request.getStatistic(), request.getSelection(), request.isConsoleSender())) //space is provided by statUnit
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return getFormattingFunction(serverStat);
|
return getFormattingFunction(serverStat, config.useEnters());
|
||||||
}
|
}
|
||||||
|
|
||||||
public BiFunction<UUID, CommandSender, TextComponent> formattedTopStatFunction(@NotNull LinkedHashMap<String, Integer> topStats, @NotNull StatRequest request) {
|
public BiFunction<UUID, CommandSender, TextComponent> formattedTopStatFunction(@NotNull LinkedHashMap<String, Integer> topStats, @NotNull StatRequest request) {
|
||||||
TextComponent title = getTopStatsTitle(request, topStats.size());
|
final TextComponent title = getTopStatsTitle(request, topStats.size());
|
||||||
TextComponent shortTitle = getTopStatsTitleShort(request, topStats.size());
|
final TextComponent shortTitle = getTopStatsTitleShort(request, topStats.size());
|
||||||
TextComponent list = getTopStatList(topStats, request);
|
final TextComponent list = getTopStatList(topStats, request);
|
||||||
|
final boolean useEnters = config.useEnters();
|
||||||
|
|
||||||
//TODO make use-enters configurable
|
|
||||||
return (shareCode, sender) -> {
|
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 we're adding a share-button
|
||||||
if (shareCode != null) {
|
if (shareCode != null) {
|
||||||
topBuilder.append(title)
|
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) -> {
|
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 we're adding a share-button
|
||||||
if (shareCode != null) {
|
if (shareCode != null) {
|
||||||
statBuilder.append(statResult)
|
statBuilder.append(statResult)
|
||||||
@ -282,7 +286,7 @@ public class MessageWriter {
|
|||||||
for (String playerName : playerNames) {
|
for (String playerName : playerNames) {
|
||||||
TextComponent.Builder playerNameBuilder = componentFactory.playerNameBuilder(playerName, Target.TOP);
|
TextComponent.Builder playerNameBuilder = componentFactory.playerNameBuilder(playerName, Target.TOP);
|
||||||
topList.append(newline())
|
topList.append(newline())
|
||||||
.append(componentFactory.rankingNumberComponent(++count + "."))
|
.append(componentFactory.rankingNumberComponent(" " + ++count + "."))
|
||||||
.append(space());
|
.append(space());
|
||||||
if (useDots) {
|
if (useDots) {
|
||||||
topList.append(playerNameBuilder)
|
topList.append(playerNameBuilder)
|
||||||
|
@ -121,6 +121,15 @@ hover-text-amount-lighter: 40
|
|||||||
# # black white # #
|
# # black white # #
|
||||||
# # ------------------------------ # #
|
# # ------------------------------ # #
|
||||||
|
|
||||||
|
|
||||||
|
shared-stats:
|
||||||
|
shared-by: gray
|
||||||
|
shared-by-style: italic
|
||||||
|
|
||||||
|
player-name: "#EE8A19"
|
||||||
|
player-name-style: none
|
||||||
|
|
||||||
|
|
||||||
top-list:
|
top-list:
|
||||||
title: '#FFD52B'
|
title: '#FFD52B'
|
||||||
title-style: none
|
title-style: none
|
||||||
|
Loading…
Reference in New Issue
Block a user