mirror of
https://github.com/itHotL/PlayerStats.git
synced 2024-11-26 12:36:16 +01:00
Decided on formatting for shared stat-results in hover-text (#92, #52), added random name-colors for shared-by-player, improved ComponentFactory and MessageWriter (fixed gray brackets not being gray)
This commit is contained in:
parent
20a4743740
commit
8ae089f222
@ -3,6 +3,8 @@ package com.gmail.artemis.the.gr8.playerstats.enums;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/** This enum represents the colorscheme PlayerStats uses in its output messages.
|
||||
<p>GRAY: ChatColor Gray</p>
|
||||
<p>DARK_PURPLE: #6E3485 (used for default sub-titles, title-underscores and brackets)</p>
|
||||
@ -22,7 +24,16 @@ public enum PluginColor {
|
||||
GOLD (NamedTextColor.GOLD), //#FFAA00
|
||||
MEDIUM_GOLD (TextColor.fromHexString("#FFD52B")),
|
||||
LIGHT_GOLD (TextColor.fromHexString("#FFEA40")),
|
||||
LIGHT_YELLOW (TextColor.fromHexString("#FFFF8E"));
|
||||
LIGHT_YELLOW (TextColor.fromHexString("#FFFF8E")),
|
||||
|
||||
NAME_1 (NamedTextColor.BLUE), //#5555FF - blue
|
||||
NAME_2 (TextColor.fromHexString("#4287F5")), //between blue and medium_blue
|
||||
NAME_3 (TextColor.fromHexString("#55AAFF")), //same as medium_blue
|
||||
NAME_4 (TextColor.fromHexString("#D65DB1")), //magenta-purple
|
||||
NAME_5 (TextColor.fromHexString("#EE8A19")), //dark orange
|
||||
NAME_6 (NamedTextColor.GOLD), //same as gold
|
||||
NAME_7 (TextColor.fromHexString("#01C1A7")), //aqua-cyan-green-ish
|
||||
NAME_8 (TextColor.fromHexString("46D858")); //light green
|
||||
|
||||
|
||||
private final TextColor color;
|
||||
@ -38,4 +49,27 @@ public enum PluginColor {
|
||||
public TextColor getConsoleColor() {
|
||||
return NamedTextColor.nearestTo(color);
|
||||
}
|
||||
}
|
||||
|
||||
public static TextColor getRandomNameColor() {
|
||||
return getRandomNameColor(false);
|
||||
}
|
||||
|
||||
public static TextColor getRandomNameColor(boolean isConsole) {
|
||||
Random randomizer = new Random();
|
||||
PluginColor color = switch (randomizer.nextInt(8)) {
|
||||
case 0 -> NAME_1;
|
||||
case 2 -> NAME_3;
|
||||
case 3 -> NAME_4;
|
||||
case 4 -> NAME_5;
|
||||
case 5 -> NAME_6;
|
||||
case 6 -> NAME_7;
|
||||
case 7 -> NAME_8;
|
||||
default -> NAME_2;
|
||||
};
|
||||
return getCorrespondingColor(color, isConsole);
|
||||
}
|
||||
|
||||
private static TextColor getCorrespondingColor(PluginColor nameColor, boolean isConsole) {
|
||||
return isConsole ? nameColor.getConsoleColor() : nameColor.getColor();
|
||||
}
|
||||
}
|
@ -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.TextColor;
|
||||
|
||||
public class BukkitConsoleComponentFactory extends ComponentFactory {
|
||||
|
||||
@ -25,4 +26,9 @@ public class BukkitConsoleComponentFactory extends ComponentFactory {
|
||||
HOVER_MSG = PluginColor.LIGHT_BLUE.getConsoleColor();
|
||||
HOVER_ACCENT = PluginColor.LIGHT_GOLD.getConsoleColor();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextColor getRandomNameColor() {
|
||||
return PluginColor.getRandomNameColor(true);
|
||||
}
|
||||
}
|
@ -44,6 +44,7 @@ public class ComponentFactory {
|
||||
protected static TextColor CLICKED_MSG; //light_purple
|
||||
protected static TextColor HOVER_ACCENT; //light_gold
|
||||
|
||||
|
||||
public ComponentFactory(ConfigHandler c) {
|
||||
config = c;
|
||||
prepareColors();
|
||||
@ -64,6 +65,10 @@ public class ComponentFactory {
|
||||
HOVER_ACCENT = PluginColor.LIGHT_GOLD.getColor();
|
||||
}
|
||||
|
||||
public TextColor getRandomNameColor() {
|
||||
return PluginColor.getRandomNameColor();
|
||||
}
|
||||
|
||||
public TextColor prefix() {
|
||||
return PREFIX;
|
||||
}
|
||||
@ -263,15 +268,14 @@ public class ComponentFactory {
|
||||
if (!(unitName == null && unitKey == null)) {
|
||||
TextComponent.Builder statUnitBuilder = getComponentBuilder(null,
|
||||
getColorFromString(config.getSubStatNameDecoration(selection, false)),
|
||||
getStyleFromString(config.getSubStatNameDecoration(selection, true)))
|
||||
.append(text("["));
|
||||
getStyleFromString(config.getSubStatNameDecoration(selection, true)));
|
||||
if (unitKey != null) {
|
||||
statUnitBuilder.append(translatable()
|
||||
.key(unitKey));
|
||||
} else {
|
||||
statUnitBuilder.append(text(unitName));
|
||||
}
|
||||
return statUnitBuilder.append(text("]")).build();
|
||||
return surroundingBracketComponent(statUnitBuilder.build());
|
||||
}
|
||||
else {
|
||||
return Component.empty();
|
||||
@ -314,25 +318,25 @@ public class ComponentFactory {
|
||||
public TextComponent messageSharedComponent(String playerName) {
|
||||
return messageSharedComponent(
|
||||
text(playerName)
|
||||
.color(MSG_ACCENT));
|
||||
.color(getRandomNameColor()));
|
||||
}
|
||||
|
||||
public TextComponent messageSharedComponent(Component playerName) {
|
||||
return surroundingBracketComponent(
|
||||
text("Shared by")
|
||||
.color(CLICKED_MSG)
|
||||
text().append(text("Shared by")
|
||||
.color(BRACKETS)
|
||||
.decorate(TextDecoration.ITALIC))
|
||||
.append(space())
|
||||
.append(playerName)
|
||||
.append(text("!")));
|
||||
.append(text("!"))
|
||||
.build());
|
||||
}
|
||||
|
||||
private TextComponent surroundingBracketComponent(TextComponent component) {
|
||||
return Component.text()
|
||||
.color(BRACKETS)
|
||||
return getComponent(null, BRACKETS, null)
|
||||
.append(text("["))
|
||||
.append(component)
|
||||
.append(text("]"))
|
||||
.build();
|
||||
.append(text("]"));
|
||||
}
|
||||
|
||||
public TextComponent titleComponent(String content, Target selection) {
|
||||
|
@ -166,16 +166,18 @@ public class MessageWriter {
|
||||
.append(getStatUnitComponent(request.getStatistic(), request.getSelection(), request.isConsoleSender())); //space is provided by statUnitComponent
|
||||
|
||||
return shareCode -> {
|
||||
TextComponent.Builder playerBuilder = text().append(playerStat);
|
||||
//if we're adding a share-button
|
||||
if (shareCode != null) {
|
||||
playerStat.append(space())
|
||||
playerBuilder.append(space())
|
||||
.append(componentFactory.shareButtonComponent(shareCode));
|
||||
}
|
||||
return playerStat.build();
|
||||
return playerBuilder.build();
|
||||
};
|
||||
}
|
||||
|
||||
public Function<UUID,TextComponent> formattedServerStatFunction(long stat, @NotNull StatRequest request) {
|
||||
TextComponent.Builder serverStat = Component.text()
|
||||
TextComponent.Builder serverStat = text()
|
||||
.append(componentFactory.titleComponent(config.getServerTitle(), Target.SERVER))
|
||||
.append(space())
|
||||
.append(componentFactory.serverNameComponent(config.getServerName()))
|
||||
@ -186,11 +188,13 @@ public class MessageWriter {
|
||||
.append(getStatUnitComponent(request.getStatistic(), request.getSelection(), request.isConsoleSender())); //space is provided by statUnit
|
||||
|
||||
return shareCode -> {
|
||||
TextComponent.Builder serverBuilder = text().append(serverStat);
|
||||
//if we're adding a share-button
|
||||
if (shareCode != null) {
|
||||
serverStat.append(space())
|
||||
serverBuilder.append(space())
|
||||
.append(componentFactory.shareButtonComponent(shareCode));
|
||||
}
|
||||
return serverStat.build();
|
||||
return serverBuilder.build();
|
||||
};
|
||||
}
|
||||
public Function<UUID, TextComponent> formattedTopStatFunction(@NotNull LinkedHashMap<String, Integer> topStats, @NotNull StatRequest request) {
|
||||
@ -198,8 +202,9 @@ public class MessageWriter {
|
||||
TextComponent list = getTopStatList(topStats, request);
|
||||
|
||||
return shareCode -> {
|
||||
TextComponent.Builder topBuilder = Component.text();
|
||||
if (shareCode != null) { //if we're adding a share-button
|
||||
TextComponent.Builder topBuilder = text();
|
||||
//if we're adding a share-button
|
||||
if (shareCode != null) {
|
||||
TextComponent newLineTitle = newline().append(title);
|
||||
topBuilder
|
||||
.append(newLineTitle)
|
||||
@ -271,8 +276,6 @@ public class MessageWriter {
|
||||
return topList.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Depending on the config settings, return either a TranslatableComponent representing
|
||||
the statName (and potential subStatName), or a TextComponent with capitalized English names.*/
|
||||
private TextComponent getStatNameComponent(StatRequest request) {
|
||||
|
@ -91,8 +91,9 @@ public class OutputManager {
|
||||
totalResult = msg.startWithNewLine(totalResult);
|
||||
|
||||
adventure.players()
|
||||
.filterAudience(onlinePlayer -> !onlinePlayer.get(Identity.NAME)
|
||||
.orElse("").equalsIgnoreCase(sender.getName())).sendMessage(totalResult);
|
||||
// .filterAudience(onlinePlayer -> !onlinePlayer.get(Identity.NAME)
|
||||
// .orElse("").equalsIgnoreCase(sender.getName()))
|
||||
.sendMessage(totalResult);
|
||||
|
||||
adventure.sender(sender).sendMessage(msg.messageShared(statResult));
|
||||
}
|
||||
|
@ -45,7 +45,8 @@ public class ExampleMessage implements TextComponent {
|
||||
.append(text("/statistic ")
|
||||
.append(text("deaths ").color(componentFactory.msgAccent())
|
||||
.append(text("player ").color(componentFactory.msgAccent2())
|
||||
.append(text("Artemis_the_gr8"))))));
|
||||
.append(text("Artemis_the_gr8")
|
||||
.color(componentFactory.getRandomNameColor()))))));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user