Added PluginColor enum, rewrote help message (previous commit), messed with color scheme slightly, reworked isConsoleSender to be more Bukkit-specific

This commit is contained in:
Artemis-the-gr8 2022-06-29 14:09:19 +02:00
parent b2bc509933
commit 82a0196214
10 changed files with 165 additions and 144 deletions

View File

@ -10,6 +10,7 @@ import com.gmail.artemis.the.gr8.playerstats.msg.MessageWriter;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.command.Command;
@ -38,18 +39,19 @@ public class StatCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
boolean isBukkitConsole = sender instanceof ConsoleCommandSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit");
if (args.length == 0 || args[0].equalsIgnoreCase("help")) { //in case of less than 1 argument or "help", display the help message
adventure.sender(sender).sendMessage(messageWriter.helpMsg(sender instanceof ConsoleCommandSender));
}
else if (args[0].equalsIgnoreCase("examples") ||
args[0].equalsIgnoreCase("example")) { //in case of "statistic examples", show examples
adventure.sender(sender).sendMessage(messageWriter.usageExamples(sender instanceof ConsoleCommandSender));
adventure.sender(sender).sendMessage(messageWriter.usageExamples(isBukkitConsole));
}
else if (args[0].equalsIgnoreCase("test")) {
TextComponent msg = text("Tier 1").color(PluginColor.GOLD.getColor())
.append(text("Tier 2").color(PluginColor.MEDIUM_GOLD.getColor())
.append(text("Tier 3").color(TextColor.fromHexString("#FFEA40"))
.append(text("Tier 4").color(PluginColor.YELLOW.getColor()))
.append(text("Tier 4").color(PluginColor.LIGHT_GOLD.getColor()))
.append(text("Tier 3?")))
.append(text("Tier 2?")))
.append(text("Tier 1?"));
@ -57,7 +59,7 @@ public class StatCommand implements CommandExecutor {
}
else {
StatRequest request = generateRequest(sender, args);
TextComponent issues = checkRequest(request);
TextComponent issues = checkRequest(request, isBukkitConsole);
if (issues == null) {
threadManager.startStatThread(request);
}
@ -154,20 +156,19 @@ public class StatCommand implements CommandExecutor {
<p>2. Is a subStat needed, and is a subStat Enum Constant present? (block/entity/item)</p>
<p>3. If the target is PLAYER, is a valid PlayerName provided? </p>
@return null if the Request is valid, and an explanation message otherwise. */
private @Nullable TextComponent checkRequest(StatRequest request) {
boolean isConsoleSender = request.getCommandSender() instanceof ConsoleCommandSender;
private @Nullable TextComponent checkRequest(StatRequest request, boolean isBukkitConsole) {
if (request.getStatistic() == null) {
return messageWriter.missingStatName(isConsoleSender);
return messageWriter.missingStatName(isBukkitConsole);
}
Statistic.Type type = request.getStatistic().getType();
if (request.getSubStatEntry() == null && type != Statistic.Type.UNTYPED) {
return messageWriter.missingSubStatName(type, isConsoleSender);
return messageWriter.missingSubStatName(type, isBukkitConsole);
}
else if (!matchingSubStat(request)) {
return messageWriter.wrongSubStatType(type, request.getSubStatEntry(), isConsoleSender);
return messageWriter.wrongSubStatType(type, request.getSubStatEntry(), isBukkitConsole);
}
else if (request.getSelection() == Target.PLAYER && request.getPlayerName() == null) {
return messageWriter.missingPlayerName(isConsoleSender);
return messageWriter.missingPlayerName(isBukkitConsole);
}
else {
return null;

View File

@ -23,7 +23,7 @@ public class ConfigHandler {
saveDefaultConfig();
config = YamlConfiguration.loadConfiguration(configFile);
configVersion = 4.1;
configVersion = 4;
checkConfigVersion();
MyLogger.setDebugLevel(debugLevel());

View File

@ -36,12 +36,9 @@ public class ConfigUpdateHandler {
/** Adjusts some of the default colors to migrate from versions 2 or 3 to version 4.1.*/
private void updateDefaultColors(YamlConfiguration configuration) {
updateColor(configuration, "top-list.title", "yellow", "#FFEA40");
updateColor(configuration, "top-list-title", "#FFD52B", "#FFEA40");
updateColor(configuration, "top-list.stat-names", "yellow", "#FFEA40");
updateColor(configuration, "top-list-stat-names", "#FFD52B", "#FFEA40");
updateColor(configuration, "top-list.title", "yellow", "#FFD52B");
updateColor(configuration, "top-list.stat-names", "yellow", "#FFD52B");
updateColor(configuration, "top-list.sub-stat-names", "#FFD52B", "yellow");
updateColor(configuration, "individual-statistics.stat-names", "yellow", "#FFD52B");
updateColor(configuration, "individual-statistics.sub-stat-names", "#FFD52B", "yellow");
updateColor(configuration, "total-server.title", "gold", "#55AAFF");

View File

@ -9,20 +9,21 @@ import net.kyori.adventure.text.format.TextColor;
<p>MEDIUM_BLUE: #55AAFF (used for all plain feedback and error messages)</p>
<p>LIGHT_BLUE: #55C6FF (used for default hover-text)</p>
<p>GOLD: ChatColor Gold (used for first parts of usage messages and for first parts of hover-text accent)</p>
<p>LIGHT_GOLD: #FFB80E (used for second parts of usage messages and for second parts of hover-text accent) </p>
<p>YELLOW: ChatColor Yellow (used for third parts of usage messages)</p>
<p>MEDIUM_GOLD: #FFD52B (used for second parts of usage messages and for second parts of hover-text accent) </p>
<p>LIGHT_GOLD: #FFEA40 (used for third parts of usage messages)</p>
<p>LIGHT_YELLOW: #FFFF8E (used for last parts of explanation message)</p>
*/
public enum PluginColor {
GRAY (NamedTextColor.GRAY),
GRAY (NamedTextColor.GRAY), //#AAAAAA
DARK_PURPLE (TextColor.fromHexString("#6E3485")),
MEDIUM_BLUE (TextColor.fromHexString("#55AAFF")),
LIGHT_BLUE (TextColor.fromHexString("#55C6FF")),
GOLD (NamedTextColor.GOLD),
GOLD (NamedTextColor.GOLD), //#FFAA00
MEDIUM_GOLD (TextColor.fromHexString("#FFD52B")),
YELLOW (NamedTextColor.YELLOW),
LIGHT_GOLD (TextColor.fromHexString("#FFEA40")),
LIGHT_YELLOW (TextColor.fromHexString("#FFFF8E"));
//TODO try "#55AAFF" for LIGHT_BLUE
private final TextColor color;
PluginColor(TextColor color) {

View File

@ -21,6 +21,7 @@ import org.jetbrains.annotations.Nullable;
import static net.kyori.adventure.text.Component.*;
import static net.kyori.adventure.text.Component.text;
/** Constructs Components with */
public class ComponentFactory {
private static ConfigHandler config;
@ -32,7 +33,7 @@ public class ComponentFactory {
}
/** Returns [PlayerStats] followed by a single space. */
public TextComponent pluginPrefix(boolean isConsoleSender) {
public TextComponent pluginPrefix(boolean isBukkitConsole) {
return text("[")
.color(PluginColor.GRAY.getColor())
.append(text("PlayerStats").color(PluginColor.GOLD.getColor()))
@ -41,17 +42,14 @@ public class ComponentFactory {
}
/** Returns [PlayerStats] surrounded by underscores on both sides. */
public TextComponent prefixTitle(boolean isConsoleSender) {
public TextComponent prefixTitle(boolean isBukkitConsole) {
String underscores = "____________"; //12 underscores for both console and in-game
TextColor underscoreColor = PluginColor.DARK_PURPLE.getColor();
if (isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit")) {
underscoreColor = NamedTextColor.DARK_PURPLE;
}
TextColor underscoreColor = isBukkitConsole ?
PluginColor.DARK_PURPLE.getConsoleColor() : PluginColor.DARK_PURPLE.getColor();
return text(underscores).color(underscoreColor)
.append(text(" ")) //4 spaces
.append(pluginPrefix(isConsoleSender))
.append(pluginPrefix(isBukkitConsole))
.append(text(" ")) //3 spaces (since prefix already has one)
.append(text(underscores));
}
@ -62,13 +60,14 @@ public class ComponentFactory {
}
/** Returns a TextComponents that represents a full message, with [PlayerStats] prepended. */
public TextComponent msg(String msg, boolean isConsoleSender) {
return pluginPrefix(isConsoleSender)
public TextComponent msg(String msg, boolean isBukkitConsole) {
return pluginPrefix(isBukkitConsole)
.append(text(msg)
.color(PluginColor.MEDIUM_BLUE.getColor()));
}
/** Returns a plain TextComponent that represents a single message line.
A space will be inserted after part1, part2 and part3.
Each message part has its own designated color.
@param part1 color DARK_GOLD
@param part2 color MEDIUM_GOLD
@ -76,39 +75,60 @@ public class ComponentFactory {
@param part4 color GRAY
*/
public TextComponent msgPart(@Nullable String part1, @Nullable String part2, @Nullable String part3, @Nullable String part4) {
return msgPart(part1, part2, part3, part4, false);
}
/** Returns a plain TextComponent that represents a single message line.
A space will be inserted after part1, part2 and part3.
Each message part has its own designated color.
if isBukkitConsole is true, the colors will be the nearest ChatColor to the below colors.
@param part1 color DARK_GOLD
@param part2 color MEDIUM_GOLD
@param part3 color YELLOW
@param part4 color GRAY
*/
public TextComponent msgPart(@Nullable String part1, @Nullable String part2, @Nullable String part3, @Nullable String part4, boolean isBukkitConsole) {
TextComponent.Builder msg = Component.text();
if (part1 != null) {
TextColor pluginColor = isBukkitConsole ? PluginColor.GOLD.getConsoleColor() : PluginColor.GOLD.getColor();
msg.append(text(part1)
.color(PluginColor.GOLD.getColor()));
if (part2 != null || part3 != null || part4 != null) {
msg.append(space());
}
.color(pluginColor))
.append(space());
}
if (part2 != null) {
TextColor pluginColor = isBukkitConsole ? PluginColor.MEDIUM_GOLD.getConsoleColor() : PluginColor.MEDIUM_GOLD.getColor();
msg.append(text(part2)
.color(PluginColor.MEDIUM_GOLD.getColor()));
if (part3 != null || part4 != null) {
msg.append(space());
}
.color(pluginColor))
.append(space());
}
if (part3 != null) {
TextColor pluginColor = isBukkitConsole ? PluginColor.LIGHT_GOLD.getConsoleColor() : PluginColor.LIGHT_GOLD.getColor();
msg.append(text(part3)
.color(PluginColor.YELLOW.getColor()));
if (part4 != null) {
msg.append(space());
}
.color(pluginColor))
.append(space());
}
if (part4 != null) {
TextColor pluginColor = isBukkitConsole ? PluginColor.GRAY.getConsoleColor() : PluginColor.GRAY.getColor();
msg.append(text(part4)
.color(PluginColor.GRAY.getColor()));
.color(pluginColor));
}
return msg.build();
}
/** Returns a TextComponent with a single line of hover-text in the specified color.
@param plainText the base message
@param hoverText the hovering text
@param hoverColor color of the hovering text */
public TextComponent simpleHoverPart(String plainText, String hoverText, PluginColor hoverColor) {
return simpleHoverPart(plainText, null, hoverText, hoverColor);
}
/** Returns a TextComponent with a single line of hover-text in the specified color.
If a PluginColor is provided for the plainText, the base color is set as well.
@param plainText the base message
@param plainColor color of the base message
@param hoverText the hovering text
@param hoverColor color of the hovering text */
public TextComponent simpleHoverPart(String plainText, @Nullable PluginColor plainColor, String hoverText, PluginColor hoverColor) {
TextComponent.Builder msg = Component.text()
.append(text(plainText))
@ -127,10 +147,10 @@ public class ComponentFactory {
@param plainText the non-hovering part
@param color the color for the non-hovering part
@param hoverLineOne text on the first line, with color LIGHT_BLUE
@param hoverLineTwoA text on the second line, with color DARK_GOLD
@param hoverLineTwoB text on the second part of the second line, with color MEDIUM_GOLD
@param hoverLineTwoA text on the second line, with color GOLD
@param hoverLineTwoB text on the second part of the second line, with color LIGHT_GOLD
*/
public TextComponent complexHoverPart(@NotNull String plainText, @NotNull PluginColor color, @Nullable String hoverLineOne, @Nullable String hoverLineTwoA, @Nullable String hoverLineTwoB) {
public TextComponent complexHoverPart(@NotNull String plainText, @NotNull PluginColor color, String hoverLineOne, String hoverLineTwoA, String hoverLineTwoB) {
TextComponent base = Component.text(plainText).color(color.getColor());
TextComponent.Builder hoverText = Component.text();
if (hoverLineOne != null) {
@ -148,13 +168,13 @@ public class ComponentFactory {
}
}
if (hoverLineTwoB != null) {
hoverText.append(text(hoverLineTwoB).color(PluginColor.MEDIUM_GOLD.getColor()));
hoverText.append(text(hoverLineTwoB).color(PluginColor.LIGHT_GOLD.getColor()));
}
return base.hoverEvent(HoverEvent.showText(hoverText.build()));
}
public TextComponent playerName(Target selection, String playerName) {
public TextComponent playerName(String playerName, Target selection) {
return createComponent(playerName,
getColorFromString(config.getPlayerNameFormatting(selection, false)),
getStyleFromString(config.getPlayerNameFormatting(selection, true)));
@ -177,12 +197,12 @@ public class ComponentFactory {
}
}
}
return statName(request.getSelection(), statName, subStatName);
return statName(statName, subStatName, request.getSelection());
}
private TranslatableComponent statName(@NotNull Target selection, @NotNull String statKey, @Nullable String subStatKey) {
private TranslatableComponent statName(@NotNull String statKey, String subStatKey, @NotNull Target selection) {
TranslatableComponent.Builder totalName;
TextComponent subStat = subStatName(selection, subStatKey);
TextComponent subStat = subStatName(subStatKey, selection);
TextColor statNameColor = getColorFromString(config.getStatNameFormatting(selection, false));
TextDecoration statNameStyle = getStyleFromString(config.getStatNameFormatting(selection, true));
@ -203,7 +223,7 @@ public class ComponentFactory {
.build();
}
private @Nullable TextComponent subStatName(Target selection, @Nullable String subStatName) {
private @Nullable TextComponent subStatName(@Nullable String subStatName, Target selection) {
if (subStatName != null) {
TextDecoration style = getStyleFromString(config.getSubStatNameFormatting(selection, true));
TextComponent.Builder subStat = text()
@ -243,13 +263,13 @@ public class ComponentFactory {
.args(subStat));
}
public TextComponent statNumber(Target selection, long number) {
public TextComponent statNumber(long number, Target selection) {
return createComponent(NumberFormatter.format(number),
getColorFromString(config.getStatNumberFormatting(selection, false)),
getStyleFromString(config.getStatNumberFormatting(selection, true)));
}
public TextComponent title(Target selection, String content) {
public TextComponent title(String content, Target selection) {
return createComponent(content,
getColorFromString(config.getTitleFormatting(selection, false)),
getStyleFromString(config.getTitleFormatting(selection, true)));
@ -261,9 +281,9 @@ public class ComponentFactory {
getStyleFromString(config.getTitleNumberFormatting(true)));
}
public TextComponent serverName() {
public TextComponent serverName(String serverName) {
TextComponent colon = text(":").color(getColorFromString(config.getServerNameFormatting(false)));
return createComponent(config.getServerName(),
return createComponent(serverName,
getColorFromString(config.getServerNameFormatting(false)),
getStyleFromString(config.getServerNameFormatting(true)))
.append(colon);

View File

@ -18,7 +18,7 @@ import java.util.*;
import static net.kyori.adventure.text.Component.*;
/** Composes messages to send to Players or Console. This class is responsible
for constructing a final component with the text content of the desired message.
for constructing a final Component with the text content of the desired message.
The component parts (with appropriate formatting) are supplied by a ComponentFactory.*/
public class MessageWriter {
@ -30,68 +30,68 @@ public class MessageWriter {
componentFactory = new ComponentFactory(c, l);
}
public TextComponent reloadedConfig(boolean isConsoleSender) {
public TextComponent reloadedConfig(boolean isBukkitConsole) {
return componentFactory.msg(
"Config reloaded!", isConsoleSender);
"Config reloaded!", isBukkitConsole);
}
public TextComponent stillReloading(boolean isConsoleSender) {
public TextComponent stillReloading(boolean isBukkitConsole) {
return componentFactory.msg(
"The plugin is still (re)loading, " +
"your request will be processed when it is done!", isConsoleSender);
"your request will be processed when it is done!", isBukkitConsole);
}
public TextComponent partiallyReloaded(boolean isConsoleSender) {
public TextComponent partiallyReloaded(boolean isBukkitConsole) {
return componentFactory.msg(
"The reload process was interrupted. " +
"If you notice unexpected behavior, " +
"please reload PlayerStats again to fix it!", isConsoleSender);
"please reload PlayerStats again to fix it!", isBukkitConsole);
}
public TextComponent waitAMoment(boolean longWait, boolean isConsoleSender) {
public TextComponent waitAMoment(boolean longWait, boolean isBukkitConsole) {
String msg = longWait ? "Calculating statistics, this may take a minute..." :
"Calculating statistics, this may take a few moments...";
return componentFactory.msg(msg, isConsoleSender);
return componentFactory.msg(msg, isBukkitConsole);
}
public TextComponent formatExceptions(@NotNull String exception, boolean isConsoleSender) {
return componentFactory.msg(exception, isConsoleSender);
public TextComponent formatExceptions(@NotNull String exception, boolean isBukkitConsole) {
return componentFactory.msg(exception, isBukkitConsole);
}
public TextComponent missingStatName(boolean isConsoleSender) {
public TextComponent missingStatName(boolean isBukkitConsole) {
return componentFactory.msg(
"Please provide a valid statistic name!", isConsoleSender);
"Please provide a valid statistic name!", isBukkitConsole);
}
public TextComponent missingSubStatName(Statistic.Type statType, boolean isConsoleSender) {
public TextComponent missingSubStatName(Statistic.Type statType, boolean isBukkitConsole) {
return componentFactory.msg(
"Please add a valid " +
getSubStatTypeName(statType) +
" to look up this statistic!", isConsoleSender);
" to look up this statistic!", isBukkitConsole);
}
public TextComponent missingPlayerName(boolean isConsoleSender) {
public TextComponent missingPlayerName(boolean isBukkitConsole) {
return componentFactory.msg(
"Please specify a valid player-name!", isConsoleSender);
"Please specify a valid player-name!", isBukkitConsole);
}
public TextComponent wrongSubStatType(Statistic.Type statType, String subStatEntry, boolean isConsoleSender) {
public TextComponent wrongSubStatType(Statistic.Type statType, String subStatEntry, boolean isBukkitConsole) {
return componentFactory.msg(
"\"" + subStatEntry + "\" is not a valid " + getSubStatTypeName(statType) + "!", isConsoleSender);
"\"" + subStatEntry + "\" is not a valid " + getSubStatTypeName(statType) + "!", isBukkitConsole);
}
public TextComponent unknownError(boolean isConsoleSender) {
public TextComponent unknownError(boolean isBukkitConsole) {
return componentFactory.msg(
"Something went wrong with your request, " +
"please try again or see /statistic for a usage explanation!", isConsoleSender);
"please try again or see /statistic for a usage explanation!", isBukkitConsole);
}
public TextComponent formatPlayerStat(int stat, @NotNull StatRequest request) {
if (!request.isValid()) return unknownError(request.isConsoleSender());
if (!request.isValid()) return unknownError(request.isBukkitConsoleSender());
return Component.text()
.append(componentFactory.playerName(Target.PLAYER, request.getPlayerName() + ": "))
.append(componentFactory.statNumber(Target.PLAYER, stat))
.append(componentFactory.playerName( request.getPlayerName() + ": ", Target.PLAYER))
.append(componentFactory.statNumber(stat, Target.PLAYER))
.append(space())
.append(componentFactory.statName(request))
.append(space())
@ -99,12 +99,12 @@ public class MessageWriter {
}
public TextComponent formatTopStats(@NotNull LinkedHashMap<String, Integer> topStats, @NotNull StatRequest request) {
if (!request.isValid()) return unknownError(request.isConsoleSender());
if (!request.isValid()) return unknownError(request.isBukkitConsoleSender());
TextComponent.Builder topList = Component.text()
.append(newline())
.append(componentFactory.pluginPrefix(request.isConsoleSender()))
.append(componentFactory.title(Target.TOP, config.getTopStatsTitle()))
.append(componentFactory.pluginPrefix(request.isBukkitConsoleSender()))
.append(componentFactory.title(config.getTopStatsTitle(), Target.TOP))
.append(space())
.append(componentFactory.titleNumber(topStats.size()))
.append(space())
@ -122,7 +122,7 @@ public class MessageWriter {
topList.append(newline())
.append(componentFactory.rankingNumber(count + ". "))
.append(componentFactory.playerName(Target.TOP, playerName));
.append(componentFactory.playerName(playerName, Target.TOP));
if (useDots) {
topList.append(space());
@ -139,21 +139,21 @@ public class MessageWriter {
}
}
else {
topList.append(componentFactory.playerName(Target.TOP, ":"));
topList.append(componentFactory.playerName(":", Target.TOP));
}
topList.append(space()).append(componentFactory.statNumber(Target.TOP, topStats.get(playerName)));
topList.append(space()).append(componentFactory.statNumber(topStats.get(playerName), Target.TOP));
}
return topList.build();
}
public TextComponent formatServerStat(long stat, @NotNull StatRequest request) {
if (!request.isValid()) return unknownError(request.isConsoleSender());
if (!request.isValid()) return unknownError(request.isBukkitConsoleSender());
return Component.text()
.append(componentFactory.title(Target.SERVER, config.getServerTitle()))
.append(componentFactory.title(config.getServerTitle(), Target.SERVER))
.append(space())
.append(componentFactory.serverName())
.append(componentFactory.serverName(config.getServerName()))
.append(space())
.append(componentFactory.statNumber(Target.SERVER, stat))
.append(componentFactory.statNumber(stat, Target.SERVER))
.append(space())
.append(componentFactory.statName(request))
.append(space())
@ -172,39 +172,37 @@ public class MessageWriter {
return subStat;
}
public TextComponent usageExamples(boolean isConsoleSender) {
boolean isBukkitConsole = (isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit"));
public TextComponent usageExamples(boolean isBukkitConsole) {
TextColor mainColor = isBukkitConsole ? PluginColor.GOLD.getConsoleColor() : PluginColor.GOLD.getColor();
TextColor accentColor1 = isBukkitConsole ? PluginColor.MEDIUM_GOLD.getConsoleColor() : PluginColor.MEDIUM_GOLD.getColor();
TextColor accentColor3 = isBukkitConsole ? PluginColor.LIGHT_YELLOW.getConsoleColor() : PluginColor.LIGHT_YELLOW.getColor();
String arrow = isBukkitConsole ? " -> " : ""; //4 spaces, alt + 26, 1 space
return Component.newline()
.append(componentFactory.prefixTitle(isConsoleSender))
.append(componentFactory.prefixTitle(isBukkitConsole))
.append(newline())
.append(text("Examples: ").color(mainColor)
.append(newline())
.append(text(arrow))
.append(text("/statistic ").color(mainColor)
.append(text("Examples: ").color(mainColor))
.append(newline())
.append(text(arrow).color(mainColor)
.append(text("/statistic ")
.append(text("animals_bred ").color(accentColor1)
.append(text("top").color(accentColor3))))
.append(newline())
.append(text(arrow))
.append(text("/statistic ").color(mainColor)
.append(text("top").color(accentColor3)))))
.append(newline())
.append(text(arrow).color(mainColor)
.append(text("/statistic ")
.append(text("mine_block diorite ").color(accentColor1)
.append(text("me").color(accentColor3))))
.append(newline())
.append(text(arrow))
.append(text("/statistic ").color(mainColor)
.append(text("me").color(accentColor3)))))
.append(newline())
.append(text(arrow).color(mainColor)
.append(text("/statistic ")
.append(text("deaths ").color(accentColor1)
.append(text("player ").color(accentColor3)
.append(text("Artemis_the_gr8")))))
.append(newline()));
.append(text("Artemis_the_gr8"))))));
}
public TextComponent helpMsg(boolean isConsoleSender) {
if (isConsoleSender || !config.useHoverText()) {
return helpMsgPlain(isConsoleSender);
return helpMsgPlain(isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit"));
}
else {
return helpMsgHover();
@ -213,7 +211,7 @@ public class MessageWriter {
/** Returns the usage-explanation with hovering text */
private TextComponent helpMsgHover() {
String arrow = " "; //4 spaces, alt + 26, 1 space
String arrow = ""; //4 spaces, alt + 26
return Component.newline()
.append(componentFactory.prefixTitle(false))
.append(newline())
@ -222,18 +220,18 @@ public class MessageWriter {
.append(componentFactory.msgPart("Usage:", null, "/statistic", null))
.append(newline())
.append(componentFactory.msgPart(arrow, null, null, null)
.append(componentFactory.complexHoverPart("name", PluginColor.YELLOW,
.append(componentFactory.complexHoverPart("name", PluginColor.LIGHT_GOLD,
"The name that describes the statistic",
"Example:",
"\"animals_bred\"")))
.append(newline())
.append(componentFactory.msgPart(arrow, null, null, null)
.append(componentFactory.complexHoverPart("sub-statistic", PluginColor.YELLOW,
.append(componentFactory.complexHoverPart("sub-statistic", PluginColor.LIGHT_GOLD,
"Some statistics need an item, block or entity as extra input",
"Example:",
"\"mine_block diorite\"")))
.append(newline())
.append(text(" ").color(PluginColor.YELLOW.getColor())
.append(text(" ").color(PluginColor.LIGHT_GOLD.getColor())
.append(componentFactory.simpleHoverPart(
"", PluginColor.GOLD,
"Choose one", PluginColor.DARK_PURPLE))
@ -255,43 +253,39 @@ public class MessageWriter {
"See the top " + config.getTopListMaxSize(), PluginColor.LIGHT_BLUE)))
.append(newline())
.append(componentFactory.msgPart(arrow, null, null, null)
.append(text("player-name").color(PluginColor.YELLOW.getColor())
.append(text("player-name").color(PluginColor.LIGHT_GOLD.getColor())
.hoverEvent(HoverEvent.showText(
text("In case you typed ").color(PluginColor.LIGHT_BLUE.getColor())
.append(text("\"player\"").color(PluginColor.MEDIUM_GOLD.getColor()))
.append(text(", add the player's name"))))));
}
//TODO create ConsoleComponentFactory for Bukkit
/** Returns the usage-explanation without any hovering text.
If BukkitVersion is CraftBukkit, this doesn't use unicode symbols or hex colors */
private TextComponent helpMsgPlain(boolean isConsoleSender) {
boolean isBukkitConsole = (isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit"));
private TextComponent helpMsgPlain(boolean isBukkitConsole) {
String arrow = isBukkitConsole ? " ->" : ""; //4 spaces, alt + 26
String bullet = isBukkitConsole ? " *" : ""; //8 spaces, alt + 7
return Component.newline()
.append(componentFactory.prefixTitle(isConsoleSender))
.append(componentFactory.prefixTitle(isBukkitConsole))
.append(newline())
.append(componentFactory.subTitle("Type \"statistic examples\" to see examples!"))
.append(newline())
.append(componentFactory.msgPart("Usage:", null, "/statistic", null))
.append(componentFactory.msgPart("Usage:", null, "/statistic", null, isBukkitConsole))
.append(newline())
.append(componentFactory.msgPart(arrow, null, "name", null))
.append(componentFactory.msgPart(arrow, null, "name", null, isBukkitConsole))
.append(newline())
.append(componentFactory.msgPart(arrow, null, "{sub-statistic}", "(a block, item or entity)"))
.append(componentFactory.msgPart(arrow, null, "{sub-statistic}", "(a block, item or entity)", isBukkitConsole))
.append(newline())
.append(componentFactory.msgPart(arrow, null, "me | player | server | top", null))
.append(componentFactory.msgPart(arrow, null, "me | player | server | top", null, isBukkitConsole))
.append(newline())
.append(componentFactory.msgPart(bullet, "me:", null, "your own statistic"))
.append(componentFactory.msgPart(bullet, "me:", null, "your own statistic", isBukkitConsole))
.append(newline())
.append(componentFactory.msgPart(bullet, "player:", null, "choose a player"))
.append(componentFactory.msgPart(bullet, "player:", null, "choose a player", isBukkitConsole))
.append(newline())
.append(componentFactory.msgPart(bullet, "server:", null, "everyone on the server combined"))
.append(componentFactory.msgPart(bullet, "server:", null, "everyone on the server combined", isBukkitConsole))
.append(newline())
.append(componentFactory.msgPart(bullet, "top:", null, "the top " + config.getTopListMaxSize()))
.append(componentFactory.msgPart(bullet, "top:", null, "the top " + config.getTopListMaxSize(), isBukkitConsole))
.append(newline())
.append(componentFactory.msgPart(arrow, null, "{player-name}", null));
.append(componentFactory.msgPart(arrow, null, "{player-name}", null, isBukkitConsole));
}
}

View File

@ -23,9 +23,9 @@ public class PrideComponentFactory extends ComponentFactory {
@Override
public TextComponent prefixTitle(boolean isConsoleSender) {
if (cancelRainbow(isConsoleSender)) {
return super.prefixTitle(isConsoleSender);
public TextComponent prefixTitle(boolean isBukkitConsole) {
if (cancelRainbow(isBukkitConsole)) {
return super.prefixTitle(isBukkitConsole);
}
else {
String title = "<rainbow:16>____________ [PlayerStats] ____________</rainbow>"; //12 underscores
@ -61,8 +61,8 @@ public class PrideComponentFactory extends ComponentFactory {
/** Don't use rainbow formatting if the rainbow Prefix is disabled,
if festive formatting is disabled or it is not pride month,
or the commandsender is a Bukkit or Spigot console.*/
private boolean cancelRainbow(boolean isConsoleSender) {
private boolean cancelRainbow(boolean isBukkitConsole) {
return !(config.useRainbowPrefix() || (config.useFestiveFormatting() && LocalDate.now().getMonth().equals(Month.JUNE))) ||
(isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit"));
(isBukkitConsole);
}
}

View File

@ -69,6 +69,7 @@ public class ReloadThread extends Thread {
}
plugin.getLogger().info("Reloading!");
if (config.reloadConfig()) {
boolean isBukkitConsole = sender instanceof ConsoleCommandSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit");
try {
OfflinePlayerHandler.updateOfflinePlayerList(getPlayerMap());
@ -76,13 +77,13 @@ public class ReloadThread extends Thread {
catch (ConcurrentModificationException e) {
MyLogger.logException(e, "ReloadThread", "run(), trying to update OfflinePlayerList during a reload");
if (sender != null) {
adventure.sender(sender).sendMessage(messageWriter.partiallyReloaded(sender instanceof ConsoleCommandSender));
adventure.sender(sender).sendMessage(messageWriter.partiallyReloaded(isBukkitConsole));
}
}
MyLogger.logTimeTakenDefault("ReloadThread", ("loaded " + OfflinePlayerHandler.getOfflinePlayerCount() + " offline players"), time);
if (sender != null) {
adventure.sender(sender).sendMessage(messageWriter.reloadedConfig(sender instanceof ConsoleCommandSender));
adventure.sender(sender).sendMessage(messageWriter.reloadedConfig(isBukkitConsole));
}
}
}

View File

@ -1,6 +1,7 @@
package com.gmail.artemis.the.gr8.playerstats.statistic;
import com.gmail.artemis.the.gr8.playerstats.enums.Target;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.command.CommandSender;
@ -57,6 +58,10 @@ public class StatRequest {
return sender instanceof ConsoleCommandSender;
}
public boolean isBukkitConsoleSender() {
return sender instanceof ConsoleCommandSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit");
}
public void setStatistic(Statistic statistic) {
this.statistic = statistic;
}

View File

@ -10,6 +10,7 @@ import com.gmail.artemis.the.gr8.playerstats.utils.MyLogger;
import com.gmail.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler;
import com.google.common.collect.ImmutableList;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
@ -60,12 +61,15 @@ public class StatThread extends Thread {
if (request == null) {
throw new NullPointerException("No statistic request was found!");
}
CommandSender sender = request.getCommandSender();
boolean isBukkitConsole = sender instanceof ConsoleCommandSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit");
if (reloadThread != null && reloadThread.isAlive()) {
try {
MyLogger.waitingForOtherThread(this.getName(), reloadThread.getName());
adventure.sender(request.getCommandSender())
.sendMessage(messageWriter
.stillReloading(request.getCommandSender() instanceof ConsoleCommandSender));
.stillReloading(isBukkitConsole));
reloadThread.join();
} catch (InterruptedException e) {
plugin.getLogger().warning(e.toString());
@ -73,16 +77,14 @@ public class StatThread extends Thread {
}
}
CommandSender sender = request.getCommandSender();
boolean isConsoleSencer = sender instanceof ConsoleCommandSender;
Target selection = request.getSelection();
if (selection == Target.TOP || selection == Target.SERVER) {
if (ThreadManager.getLastRecordedCalcTime() > 20000) {
adventure.sender(sender).sendMessage(messageWriter.waitAMoment(true, isConsoleSencer));
adventure.sender(sender).sendMessage(messageWriter.waitAMoment(true, isBukkitConsole));
}
else if (ThreadManager.getLastRecordedCalcTime() > 2000) {
adventure.sender(sender).sendMessage(messageWriter.waitAMoment(false, isConsoleSencer));
adventure.sender(sender).sendMessage(messageWriter.waitAMoment(false, isBukkitConsole));
}
try {
@ -94,11 +96,11 @@ public class StatThread extends Thread {
}
} catch (ConcurrentModificationException e) {
if (!isConsoleSencer) {
if (!isBukkitConsole) {
adventure.sender(sender).sendMessage(messageWriter.unknownError(false));
}
} catch (Exception e) {
adventure.sender(sender).sendMessage(messageWriter.formatExceptions(e.toString(), isConsoleSencer));
adventure.sender(sender).sendMessage(messageWriter.formatExceptions(e.toString(), isBukkitConsole));
MyLogger.logException(e, "StatThread", "run(), trying to calculate or format a top or server statistic");
}
}
@ -109,7 +111,7 @@ public class StatThread extends Thread {
messageWriter.formatPlayerStat(getIndividualStat(), request));
} catch (UnsupportedOperationException | NullPointerException e) {
adventure.sender(sender).sendMessage(messageWriter.formatExceptions(e.toString(), isConsoleSencer));
adventure.sender(sender).sendMessage(messageWriter.formatExceptions(e.toString(), isBukkitConsole));
}
}
}