Polished up the help-message (#32)

This commit is contained in:
Artemis-the-gr8 2022-05-29 22:13:18 +02:00
parent 07668c8010
commit 8fb4154729
4 changed files with 58 additions and 50 deletions

View File

@ -34,7 +34,7 @@ public class Main extends JavaPlugin {
//get instances of the classes that should be initialized
ConfigHandler config = new ConfigHandler(this);
MessageFactory messageFactory = new MessageFactory(config);
MessageFactory messageFactory = new MessageFactory(config, this);
OfflinePlayerHandler offlinePlayerHandler = new OfflinePlayerHandler(config);
getLogger().info("Amount of offline players: " + offlinePlayerHandler.getOfflinePlayerCount());

View File

@ -91,8 +91,7 @@ public class ConfigHandler {
}
public String getPlayerNameFormatting(boolean topStat, boolean isStyle) {
ConfigurationSection section = getRelevantSection(topStat, isStyle);
return section != null ? section.getString("player-names") : null;
return getStringFromConfig(topStat, isStyle, "player-names");
}
public boolean playerNameIsBold() {
@ -105,38 +104,33 @@ public class ConfigHandler {
return false;
}
/*private String getData(boolean topStat, boolean isStyle, String statName){
ConfigurationSection section = getRelevantSection(topStat, isStyle);
return section != null ? section.getString(statName) : null;
}*/
public String getStatNameFormatting(boolean topStat, boolean isStyle) {
//return getData(topStat, isStyle, "stat-names");
ConfigurationSection section = getRelevantSection(topStat, isStyle);
return section != null ? section.getString("stat-names") : null;
return getStringFromConfig(topStat, isStyle, "stat-names");
}
public String getSubStatNameFormatting(boolean topStat, boolean isStyle) {
ConfigurationSection section = getRelevantSection(topStat, isStyle);
return section != null ? section.getString("sub-stat-names") : null;
return getStringFromConfig(topStat, isStyle, "sub-stat-names");
}
public String getStatNumberFormatting(boolean topStat, boolean isStyle) {
ConfigurationSection section = getRelevantSection(topStat, isStyle);
return section != null ? section.getString("stat-numbers") : null;
return getStringFromConfig(topStat, isStyle, "stat-numbers");
}
public String getListNumberFormatting(boolean isStyle) {
//return getData(true, isStyle, "list-numbers");
ConfigurationSection section = getRelevantSection(true, isStyle);
return section != null ? section.getString("list-numbers") : null;
return getStringFromConfig(true, isStyle, "list-numbers");
}
public String getDotsColor() {
ConfigurationSection section = getRelevantSection(true, false);
return section != null ? section.getString("dots") : null;
return getStringFromConfig(true, false, "dots");
}
//returns the config value for a color or style option in string-format, or null if no value was found
private String getStringFromConfig(boolean topStat, boolean isStyle, String pathName){
ConfigurationSection section = getRelevantSection(topStat, isStyle);
return section != null ? section.getString(pathName) : null;
}
//returns the config section that contains the relevant color or style option
private ConfigurationSection getRelevantSection(boolean topStat, boolean isStyle) {
ConfigurationSection section;
try {

View File

@ -1,5 +1,6 @@
package com.gmail.artemis.the.gr8.playerstats.utils;
import com.gmail.artemis.the.gr8.playerstats.Main;
import com.gmail.artemis.the.gr8.playerstats.filehandlers.ConfigHandler;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
@ -18,8 +19,10 @@ import static net.kyori.adventure.text.Component.*;
public class MessageFactory {
private static ConfigHandler config;
private final Main plugin;
public MessageFactory(ConfigHandler c) {
public MessageFactory(ConfigHandler c, Main p) {
plugin = p;
config = c;
}
@ -36,9 +39,9 @@ public class MessageFactory {
TextComponent underscores = text("____________").color(TextColor.fromHexString("#6E3485"));
TextComponent arrow = text("").color(NamedTextColor.GOLD);
TextColor arguments = NamedTextColor.YELLOW;
TextColor hoverDescription = NamedTextColor.GOLD;
TextColor hoverExample1 = TextColor.fromHexString("#FFD52B");
TextColor hoverExample2 = NamedTextColor.YELLOW;
TextColor hoverDescription = TextColor.fromHexString("#55C6FF");
TextColor hoverExample1 = TextColor.fromHexString("#FFB80E");
TextColor hoverExample2 = TextColor.fromHexString("#FFD52B");
return Component.newline()
.append(underscores).append(spaces).append(text(MessageFactory.getPluginPrefix())).append(spaces).append(underscores)
@ -49,31 +52,43 @@ public class MessageFactory {
.append(newline())
.append(spaces).append(arrow)
.append(text("name").color(arguments)
.hoverEvent(HoverEvent.showText(text("The name of the statistic").color(hoverDescription)
.hoverEvent(HoverEvent.showText(text("The name that describes the statistic").color(hoverDescription)
.append(newline())
.append(text("Example: ").color(hoverExample1))
.append(text("\"mine_block\"").color(hoverExample2)))))
.append(text("\"animals_bred\"").color(hoverExample2)))))
.append(newline())
.append(spaces).append(arrow)
.append(text("sub-statistic").color(arguments)
.hoverEvent(HoverEvent.showText(
text("Some statistics require an item, block or entity as sub-statistic").color(hoverDescription)
text("Some statistics need an item, block or entity as sub-statistic").color(hoverDescription)
.append(newline())
.append(text("Example: ").color(hoverExample1)
.append(text("\"mine_block diorite\"").color(hoverExample2))))))
.append(newline())
.append(spaces).append(arrow)
.append(text("me | player | top").color(arguments)
.append(spaces)
.append(text("").color(NamedTextColor.GOLD)
.hoverEvent(HoverEvent.showText(
text("Choose whether you want to see your own statistic, another player's, or the top ").color(hoverDescription)
text("Choose one").color(TextColor.fromHexString("#6E3485")))))
.append(space())
.append(text("me").color(arguments)
.hoverEvent(HoverEvent.showText(
text("See your own statistic").color(hoverDescription))))
.append(text(" | ").color(arguments))
.append(text("player").color(arguments)
.hoverEvent(HoverEvent.showText(
text("Choose any player that has played on your server").color(hoverDescription))))
.append(text(" | ").color(arguments))
.append(text("top").color(arguments)
.hoverEvent(HoverEvent.showText(
text("See the top ").color(hoverDescription)
.append(text(config.getTopListMaxSize()).color(hoverDescription)))))
.append(newline())
.append(spaces).append(arrow)
.append(text("player-name").color(arguments)
.hoverEvent(HoverEvent.showText(
text("In case you selected ").color(hoverDescription)
text("In case you typed ").color(hoverDescription)
.append(text("\"player\"").color(hoverExample2)
.append(text(", specify the player's name here").color(hoverDescription))))));
.append(text(", add the player's name").color(hoverDescription))))));
}
public TextComponent formatPlayerStat(String playerName, String statName, String subStatEntryName, int stat) {
@ -90,6 +105,7 @@ public class MessageFactory {
}
public TextComponent formatTopStats(LinkedHashMap<String, Integer> topStats, String statName, String subStatEntryName) {
long time = System.currentTimeMillis();
TextComponent.Builder topList = Component.text();
String subStat = subStatEntryName != null ?
"(" + subStatEntryName.toLowerCase().replace("_", " ") + ")" : "";
@ -128,6 +144,7 @@ public class MessageFactory {
}
topList.append(space()).append(statNumberComponent(topStats.get(playerName), true));
}
plugin.logTimeTaken("MessageFactory", "applying colors", time);
return topList.build();
}
@ -168,19 +185,18 @@ public class MessageFactory {
private TextComponent.Builder applyColor(String configString, String content, ChatColor defaultColor) {
TextComponent.Builder component = Component.text();
if (configString != null) {
if (configString.contains("#")) {
return component.content(content).color(TextColor.fromHexString(configString));
}
else {
try {
try {
if (configString.contains("#")) {
return component.content(content).color(TextColor.fromHexString(configString));
}
else {
return component.content(content).color(getTextColor(configString));
}
catch (IllegalArgumentException | NullPointerException exception) {
//color = ChatColor.valueOf(configString.toUpperCase().replace(" ", "_"));
exception.printStackTrace();
}
}
catch (IllegalArgumentException | NullPointerException exception) {
plugin.getLogger().warning(exception.toString());
}
}
return component.content(defaultColor + content);

View File

@ -3,12 +3,12 @@
# ------------------------------
# ------ General Options -------
# The following are filtering options to control which players are included when calculating statistics
# Filtering options to control which players should be included in statistic calculations
include-whitelist-only: false
exclude-banned-players: false
# To only show statistics from players that have been online in the last x days, specify the number of days below
# Leave this on 0 if you want to include everyone
# To only show statistics from players that have been online in the last x days, specify the number of days here
# Leave this on 0 to include all players
number-of-days-since-last-joined: 0
# ------ Format Options --------
@ -19,15 +19,14 @@ top-list-max-size: 10
use-dots: true
# ------ Color Options ---------
# The colors below can be chat colors or hex codes if your server supports those (Bukkit does not, Spigot and further forks do)
# Make sure to put hex codes between quotation marks! (format: '#xxxxxx')
# The colors below can be chat color names or hex codes (format: '#xxxxxx' <-- including quotation marks!)
# The style options include: bold, italic, underlined, strikethrough, and magic
individual-statistics-color:
player-names: gold
stat-names: yellow
sub-stat-names: yellow
stat-numbers: white
# This provides additional styling options (italic/underline/bold, and yes, even magic)
individual-statistics-style:
player-names: none
stat-names: none
@ -38,11 +37,10 @@ top-list-color:
player-names: green
stat-names: yellow
sub-stat-names: yellow
stat-numbers: '#40b1f7'
stat-numbers: '#55aaff'
list-numbers: gold
dots: dark_gray
# Note that making the player-names bold could cause the alignment of the stat numbers to shift slightly
top-list-style:
player-names: none
stat-names: none