From c7a6160cc8786c0566326aea93a996c489eeb744 Mon Sep 17 00:00:00 2001 From: Artemis-the-gr8 Date: Wed, 26 Oct 2022 21:20:22 +0200 Subject: [PATCH] Started working on feedback (#88, #51) --- .../playerstats/commands/ExcludeCommand.java | 3 +- .../gr8/playerstats/commands/StatCommand.java | 6 +- .../playerstats/enums/StandardMessage.java | 4 +- .../gr8/playerstats/msg/MessageBuilder.java | 82 ++++++++----------- .../gr8/playerstats/msg/OutputManager.java | 35 ++++---- .../msg/components/ComponentFactory.java | 10 ++- .../msg/components/HelpMessage.java | 2 +- .../multithreading/StatThread.java | 6 +- 8 files changed, 75 insertions(+), 73 deletions(-) diff --git a/src/main/java/com/artemis/the/gr8/playerstats/commands/ExcludeCommand.java b/src/main/java/com/artemis/the/gr8/playerstats/commands/ExcludeCommand.java index c2980fd..f7242b2 100644 --- a/src/main/java/com/artemis/the/gr8/playerstats/commands/ExcludeCommand.java +++ b/src/main/java/com/artemis/the/gr8/playerstats/commands/ExcludeCommand.java @@ -47,8 +47,7 @@ public final class ExcludeCommand implements CommandExecutor { } } case "info" -> { - boolean isExcluded = offlinePlayerHandler.isExcludedPlayer(playerName); - sender.sendMessage(playerName+ " is excluded: " + isExcluded); + outputManager.sendExcludeInfo(sender); return true; } } diff --git a/src/main/java/com/artemis/the/gr8/playerstats/commands/StatCommand.java b/src/main/java/com/artemis/the/gr8/playerstats/commands/StatCommand.java index d09879e..9e921ac 100644 --- a/src/main/java/com/artemis/the/gr8/playerstats/commands/StatCommand.java +++ b/src/main/java/com/artemis/the/gr8/playerstats/commands/StatCommand.java @@ -91,10 +91,12 @@ public final class StatCommand implements CommandExecutor { } else { Statistic.Type type = processor.statistic.getType(); + String statType = enumHandler.getSubStatTypeName(type); + if (type != Statistic.Type.UNTYPED && processor.subStatName == null) { - outputManager.sendFeedbackMsgMissingSubStat(sender, type); + outputManager.sendFeedbackMsgMissingSubStat(sender, statType); } else { - outputManager.sendFeedbackMsgWrongSubStat(sender, type, processor.subStatName); + outputManager.sendFeedbackMsgWrongSubStat(sender, statType, processor.subStatName); } } } diff --git a/src/main/java/com/artemis/the/gr8/playerstats/enums/StandardMessage.java b/src/main/java/com/artemis/the/gr8/playerstats/enums/StandardMessage.java index 46c2360..dd43f03 100644 --- a/src/main/java/com/artemis/the/gr8/playerstats/enums/StandardMessage.java +++ b/src/main/java/com/artemis/the/gr8/playerstats/enums/StandardMessage.java @@ -10,9 +10,11 @@ public enum StandardMessage { STILL_RELOADING, MISSING_STAT_NAME, MISSING_PLAYER_NAME, + WAIT_A_MOMENT, + WAIT_A_MINUTE, REQUEST_ALREADY_RUNNING, STILL_ON_SHARE_COOLDOWN, RESULTS_ALREADY_SHARED, STAT_RESULTS_TOO_OLD, UNKNOWN_ERROR -} +} \ No newline at end of file diff --git a/src/main/java/com/artemis/the/gr8/playerstats/msg/MessageBuilder.java b/src/main/java/com/artemis/the/gr8/playerstats/msg/MessageBuilder.java index 5d7fb7d..4c7955e 100644 --- a/src/main/java/com/artemis/the/gr8/playerstats/msg/MessageBuilder.java +++ b/src/main/java/com/artemis/the/gr8/playerstats/msg/MessageBuilder.java @@ -113,65 +113,44 @@ public final class MessageBuilder implements StatFormatter { } public @NotNull TextComponent reloadedConfig() { - return componentFactory.pluginPrefix() - .append(space()) - .append(componentFactory.message().content("Config reloaded!")); + return composePluginMessage("Config reloaded!"); } public @NotNull TextComponent stillReloading() { - return componentFactory.pluginPrefix() - .append(space()) - .append(componentFactory.message().content( - "The plugin is (re)loading, your request will be processed when it is done!")); + return composePluginMessage("The plugin is (re)loading, your request will be processed when it is done!"); } - public @NotNull TextComponent waitAMoment(boolean longWait) { - String msg = longWait ? "Calculating statistics, this may take a minute..." : - "Calculating statistics, this may take a few moments..."; - return componentFactory.pluginPrefix() - .append(space()) - .append(componentFactory.message().content(msg)); + public @NotNull TextComponent waitAMinute() { + return composePluginMessage("Calculating statistics, this may take a minute..."); + } + + public @NotNull TextComponent waitAMoment() { + return composePluginMessage("Calculating statistics, this may take a few moments..."); } public @NotNull TextComponent missingStatName() { - return componentFactory.pluginPrefix() - .append(space()) - .append(componentFactory.message().content( - "Please provide a valid statistic name!")); + return composePluginMessage("Please provide a valid statistic name!"); } - public @NotNull TextComponent missingSubStatName(Statistic.Type statType) { - return componentFactory.pluginPrefix() - .append(space()) - .append(componentFactory.message().content( - "Please add a valid " + - EnumHandler.getInstance().getSubStatTypeName(statType) + - " to look up this statistic!")); + public @NotNull TextComponent missingSubStatName(String statType) { + return composePluginMessage("Please add a valid " + statType + " to look up this statistic!"); } public @NotNull TextComponent missingPlayerName() { - return componentFactory.pluginPrefix() - .append(space()) - .append(componentFactory.message().content( - "Please specify a valid player-name!")); + return composePluginMessage("Please specify a valid player-name!"); } - public @NotNull TextComponent wrongSubStatType(Statistic.Type statType, String subStatName) { + public @NotNull TextComponent wrongSubStatType(String statType, String subStatName) { return componentFactory.pluginPrefix() .append(space()) .append(componentFactory.messageAccent().content("\"" + subStatName + "\"")) .append(space()) .append(componentFactory.message().content( - "is not a valid " + - EnumHandler.getInstance().getSubStatTypeName(statType) + - "!")); + "is not a valid " + statType + "!")); } public @NotNull TextComponent requestAlreadyRunning() { - return componentFactory.pluginPrefix() - .append(space()) - .append(componentFactory.message().content( - "Please wait for your previous lookup to finish!")); + return composePluginMessage("Please wait for your previous lookup to finish!"); } public @NotNull TextComponent stillOnShareCoolDown() { @@ -189,24 +168,23 @@ public final class MessageBuilder implements StatFormatter { } public @NotNull TextComponent resultsAlreadyShared() { - return componentFactory.pluginPrefix() - .append(space()) - .append(componentFactory.message().content("You already shared these results!")); + return composePluginMessage("You already shared these results!"); } public @NotNull TextComponent statResultsTooOld() { - return componentFactory.pluginPrefix() - .append(space()) - .append(componentFactory.message().content( - "It has been too long since you looked up this statistic, please repeat the original command!")); + return composePluginMessage("It has been too long since you looked up " + + "this statistic, please repeat the original command!"); } public @NotNull TextComponent unknownError() { - return componentFactory.pluginPrefix() + return composePluginMessage("Something went wrong with your request, " + + "please try again or see /statistic for a usage explanation!"); + } + + private @NotNull TextComponent composePluginMessage(String content) { + return getPluginPrefix() .append(space()) - .append(componentFactory.message().content( - "Something went wrong with your request, " + - "please try again or see /statistic for a usage explanation!")); + .append(componentFactory.message().content(content)); } @Contract(" -> new") @@ -223,6 +201,16 @@ public final class MessageBuilder implements StatFormatter { } } + public @NotNull TextComponent excludeInfoMsg() { + return getPluginPrefixAsTitle() + .append(newline()) + .append(componentFactory.subTitle("The /statexclude command " + + "can be used to exclude individual players from /statistic lookups.") + .append(newline()) + .append(text("This means their results won't show up in top-10 results, " + + "and they won't be counted for the server total."))); + } + @Override public @NotNull TextComponent getStatTitle(Statistic statistic, @Nullable String subStatName) { return getTopStatTitleComponent(0, statistic, subStatName, null); diff --git a/src/main/java/com/artemis/the/gr8/playerstats/msg/OutputManager.java b/src/main/java/com/artemis/the/gr8/playerstats/msg/OutputManager.java index 3210dff..8b74d66 100644 --- a/src/main/java/com/artemis/the/gr8/playerstats/msg/OutputManager.java +++ b/src/main/java/com/artemis/the/gr8/playerstats/msg/OutputManager.java @@ -11,7 +11,6 @@ import com.artemis.the.gr8.playerstats.statistic.StatRequest; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.TextComponent; import org.bukkit.Bukkit; -import org.bukkit.Statistic; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.jetbrains.annotations.NotNull; @@ -100,17 +99,12 @@ public final class OutputManager { } } - public void sendFeedbackMsgWaitAMoment(@NotNull CommandSender sender, boolean longWait) { - adventure.sender(sender).sendMessage(getMessageBuilder(sender) - .waitAMoment(longWait)); - } - - public void sendFeedbackMsgMissingSubStat(@NotNull CommandSender sender, Statistic.Type statType) { + public void sendFeedbackMsgMissingSubStat(@NotNull CommandSender sender, String statType) { adventure.sender(sender).sendMessage(getMessageBuilder(sender) .missingSubStatName(statType)); } - public void sendFeedbackMsgWrongSubStat(@NotNull CommandSender sender, Statistic.Type statType, @Nullable String subStatName) { + public void sendFeedbackMsgWrongSubStat(@NotNull CommandSender sender, String statType, @Nullable String subStatName) { if (subStatName == null) { sendFeedbackMsgMissingSubStat(sender, statType); } else { @@ -129,6 +123,11 @@ public final class OutputManager { .helpMsg()); } + public void sendExcludeInfo(@NotNull CommandSender sender) { + adventure.sender(sender).sendMessage(getMessageBuilder(sender) + .excludeInfoMsg()); + } + public void sendToAllPlayers(@NotNull TextComponent component) { adventure.players().sendMessage(component); } @@ -176,14 +175,16 @@ public final class OutputManager { private void prepareFunctions() { standardMessages = new EnumMap<>(StandardMessage.class); - standardMessages.put(RELOADED_CONFIG, (MessageBuilder::reloadedConfig)); - standardMessages.put(STILL_RELOADING, (MessageBuilder::stillReloading)); - standardMessages.put(MISSING_STAT_NAME, (MessageBuilder::missingStatName)); - standardMessages.put(MISSING_PLAYER_NAME, (MessageBuilder::missingPlayerName)); - standardMessages.put(REQUEST_ALREADY_RUNNING, (MessageBuilder::requestAlreadyRunning)); - standardMessages.put(STILL_ON_SHARE_COOLDOWN, (MessageBuilder::stillOnShareCoolDown)); - standardMessages.put(RESULTS_ALREADY_SHARED, (MessageBuilder::resultsAlreadyShared)); - standardMessages.put(STAT_RESULTS_TOO_OLD, (MessageBuilder::statResultsTooOld)); - standardMessages.put(UNKNOWN_ERROR, (MessageBuilder::unknownError)); + standardMessages.put(RELOADED_CONFIG, MessageBuilder::reloadedConfig); + standardMessages.put(STILL_RELOADING, MessageBuilder::stillReloading); + standardMessages.put(MISSING_STAT_NAME, MessageBuilder::missingStatName); + standardMessages.put(MISSING_PLAYER_NAME, MessageBuilder::missingPlayerName); + standardMessages.put(WAIT_A_MOMENT, MessageBuilder::waitAMoment); + standardMessages.put(WAIT_A_MINUTE, MessageBuilder::waitAMinute); + standardMessages.put(REQUEST_ALREADY_RUNNING, MessageBuilder::requestAlreadyRunning); + standardMessages.put(STILL_ON_SHARE_COOLDOWN, MessageBuilder::stillOnShareCoolDown); + standardMessages.put(RESULTS_ALREADY_SHARED, MessageBuilder::resultsAlreadyShared); + standardMessages.put(STAT_RESULTS_TOO_OLD, MessageBuilder::statResultsTooOld); + standardMessages.put(UNKNOWN_ERROR, MessageBuilder::unknownError); } } \ No newline at end of file diff --git a/src/main/java/com/artemis/the/gr8/playerstats/msg/components/ComponentFactory.java b/src/main/java/com/artemis/the/gr8/playerstats/msg/components/ComponentFactory.java index 4f853ae..6c18249 100644 --- a/src/main/java/com/artemis/the/gr8/playerstats/msg/components/ComponentFactory.java +++ b/src/main/java/com/artemis/the/gr8/playerstats/msg/components/ComponentFactory.java @@ -107,9 +107,17 @@ public class ComponentFactory { /** * Returns a TextComponent with the input String as content, - * with color Gray and decoration Italic. + * with color Gray. */ public TextComponent subTitle(String content) { + return text(content).color(BRACKETS); + } + + /** + * Returns a TextComponent with the input String as content, + * with color Gray and decoration Italic. + */ + public TextComponent italicSubTitle(String content) { return text(content).color(BRACKETS).decorate(TextDecoration.ITALIC); } diff --git a/src/main/java/com/artemis/the/gr8/playerstats/msg/components/HelpMessage.java b/src/main/java/com/artemis/the/gr8/playerstats/msg/components/HelpMessage.java index 20ecb02..71e5da4 100644 --- a/src/main/java/com/artemis/the/gr8/playerstats/msg/components/HelpMessage.java +++ b/src/main/java/com/artemis/the/gr8/playerstats/msg/components/HelpMessage.java @@ -93,7 +93,7 @@ public final class HelpMessage implements TextComponent { return Component.newline() .append(factory.pluginPrefixAsTitle()) .append(newline()) - .append(factory.subTitle("Hover over the arguments for more information!")) + .append(factory.italicSubTitle("Hover over the arguments for more information!")) .append(newline()) .append(text("Usage:").color(factory.MSG_MAIN_2)).append(space()) .append(text("/statistic").color(factory.MSG_HOVER_ACCENT)) diff --git a/src/main/java/com/artemis/the/gr8/playerstats/multithreading/StatThread.java b/src/main/java/com/artemis/the/gr8/playerstats/multithreading/StatThread.java index cc01999..f0ee179 100644 --- a/src/main/java/com/artemis/the/gr8/playerstats/multithreading/StatThread.java +++ b/src/main/java/com/artemis/the/gr8/playerstats/multithreading/StatThread.java @@ -48,8 +48,10 @@ final class StatThread extends Thread { } long lastCalc = ThreadManager.getLastRecordedCalcTime(); - if (lastCalc > 2000) { - outputManager.sendFeedbackMsgWaitAMoment(statRequester, lastCalc > 20000); + if (lastCalc > 6000) { + outputManager.sendFeedbackMsg(statRequester, StandardMessage.WAIT_A_MINUTE); + } else if (lastCalc > 2000) { + outputManager.sendFeedbackMsg(statRequester, StandardMessage.WAIT_A_MOMENT); } try {