Started working on feedback (#88, #51)

This commit is contained in:
Artemis-the-gr8 2022-10-26 21:20:22 +02:00
parent f69367cb31
commit c7a6160cc8
8 changed files with 75 additions and 73 deletions

View File

@ -47,8 +47,7 @@ public final class ExcludeCommand implements CommandExecutor {
} }
} }
case "info" -> { case "info" -> {
boolean isExcluded = offlinePlayerHandler.isExcludedPlayer(playerName); outputManager.sendExcludeInfo(sender);
sender.sendMessage(playerName+ " is excluded: " + isExcluded);
return true; return true;
} }
} }

View File

@ -91,10 +91,12 @@ public final class StatCommand implements CommandExecutor {
} }
else { else {
Statistic.Type type = processor.statistic.getType(); Statistic.Type type = processor.statistic.getType();
String statType = enumHandler.getSubStatTypeName(type);
if (type != Statistic.Type.UNTYPED && processor.subStatName == null) { if (type != Statistic.Type.UNTYPED && processor.subStatName == null) {
outputManager.sendFeedbackMsgMissingSubStat(sender, type); outputManager.sendFeedbackMsgMissingSubStat(sender, statType);
} else { } else {
outputManager.sendFeedbackMsgWrongSubStat(sender, type, processor.subStatName); outputManager.sendFeedbackMsgWrongSubStat(sender, statType, processor.subStatName);
} }
} }
} }

View File

@ -10,9 +10,11 @@ public enum StandardMessage {
STILL_RELOADING, STILL_RELOADING,
MISSING_STAT_NAME, MISSING_STAT_NAME,
MISSING_PLAYER_NAME, MISSING_PLAYER_NAME,
WAIT_A_MOMENT,
WAIT_A_MINUTE,
REQUEST_ALREADY_RUNNING, REQUEST_ALREADY_RUNNING,
STILL_ON_SHARE_COOLDOWN, STILL_ON_SHARE_COOLDOWN,
RESULTS_ALREADY_SHARED, RESULTS_ALREADY_SHARED,
STAT_RESULTS_TOO_OLD, STAT_RESULTS_TOO_OLD,
UNKNOWN_ERROR UNKNOWN_ERROR
} }

View File

@ -113,65 +113,44 @@ public final class MessageBuilder implements StatFormatter {
} }
public @NotNull TextComponent reloadedConfig() { public @NotNull TextComponent reloadedConfig() {
return componentFactory.pluginPrefix() return composePluginMessage("Config reloaded!");
.append(space())
.append(componentFactory.message().content("Config reloaded!"));
} }
public @NotNull TextComponent stillReloading() { public @NotNull TextComponent stillReloading() {
return componentFactory.pluginPrefix() return composePluginMessage("The plugin is (re)loading, your request will be processed when it is done!");
.append(space())
.append(componentFactory.message().content(
"The plugin is (re)loading, your request will be processed when it is done!"));
} }
public @NotNull TextComponent waitAMoment(boolean longWait) { public @NotNull TextComponent waitAMinute() {
String msg = longWait ? "Calculating statistics, this may take a minute..." : return composePluginMessage("Calculating statistics, this may take a minute...");
"Calculating statistics, this may take a few moments..."; }
return componentFactory.pluginPrefix()
.append(space()) public @NotNull TextComponent waitAMoment() {
.append(componentFactory.message().content(msg)); return composePluginMessage("Calculating statistics, this may take a few moments...");
} }
public @NotNull TextComponent missingStatName() { public @NotNull TextComponent missingStatName() {
return componentFactory.pluginPrefix() return composePluginMessage("Please provide a valid statistic name!");
.append(space())
.append(componentFactory.message().content(
"Please provide a valid statistic name!"));
} }
public @NotNull TextComponent missingSubStatName(Statistic.Type statType) { public @NotNull TextComponent missingSubStatName(String statType) {
return componentFactory.pluginPrefix() return composePluginMessage("Please add a valid " + statType + " to look up this statistic!");
.append(space())
.append(componentFactory.message().content(
"Please add a valid " +
EnumHandler.getInstance().getSubStatTypeName(statType) +
" to look up this statistic!"));
} }
public @NotNull TextComponent missingPlayerName() { public @NotNull TextComponent missingPlayerName() {
return componentFactory.pluginPrefix() return composePluginMessage("Please specify a valid player-name!");
.append(space())
.append(componentFactory.message().content(
"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() return componentFactory.pluginPrefix()
.append(space()) .append(space())
.append(componentFactory.messageAccent().content("\"" + subStatName + "\"")) .append(componentFactory.messageAccent().content("\"" + subStatName + "\""))
.append(space()) .append(space())
.append(componentFactory.message().content( .append(componentFactory.message().content(
"is not a valid " + "is not a valid " + statType + "!"));
EnumHandler.getInstance().getSubStatTypeName(statType) +
"!"));
} }
public @NotNull TextComponent requestAlreadyRunning() { public @NotNull TextComponent requestAlreadyRunning() {
return componentFactory.pluginPrefix() return composePluginMessage("Please wait for your previous lookup to finish!");
.append(space())
.append(componentFactory.message().content(
"Please wait for your previous lookup to finish!"));
} }
public @NotNull TextComponent stillOnShareCoolDown() { public @NotNull TextComponent stillOnShareCoolDown() {
@ -189,24 +168,23 @@ public final class MessageBuilder implements StatFormatter {
} }
public @NotNull TextComponent resultsAlreadyShared() { public @NotNull TextComponent resultsAlreadyShared() {
return componentFactory.pluginPrefix() return composePluginMessage("You already shared these results!");
.append(space())
.append(componentFactory.message().content("You already shared these results!"));
} }
public @NotNull TextComponent statResultsTooOld() { public @NotNull TextComponent statResultsTooOld() {
return componentFactory.pluginPrefix() return composePluginMessage("It has been too long since you looked up " +
.append(space()) "this statistic, please repeat the original command!");
.append(componentFactory.message().content(
"It has been too long since you looked up this statistic, please repeat the original command!"));
} }
public @NotNull TextComponent unknownError() { 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(space())
.append(componentFactory.message().content( .append(componentFactory.message().content(content));
"Something went wrong with your request, " +
"please try again or see /statistic for a usage explanation!"));
} }
@Contract(" -> new") @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 @Override
public @NotNull TextComponent getStatTitle(Statistic statistic, @Nullable String subStatName) { public @NotNull TextComponent getStatTitle(Statistic statistic, @Nullable String subStatName) {
return getTopStatTitleComponent(0, statistic, subStatName, null); return getTopStatTitleComponent(0, statistic, subStatName, null);

View File

@ -11,7 +11,6 @@ import com.artemis.the.gr8.playerstats.statistic.StatRequest;
import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Statistic;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -100,17 +99,12 @@ public final class OutputManager {
} }
} }
public void sendFeedbackMsgWaitAMoment(@NotNull CommandSender sender, boolean longWait) { public void sendFeedbackMsgMissingSubStat(@NotNull CommandSender sender, String statType) {
adventure.sender(sender).sendMessage(getMessageBuilder(sender)
.waitAMoment(longWait));
}
public void sendFeedbackMsgMissingSubStat(@NotNull CommandSender sender, Statistic.Type statType) {
adventure.sender(sender).sendMessage(getMessageBuilder(sender) adventure.sender(sender).sendMessage(getMessageBuilder(sender)
.missingSubStatName(statType)); .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) { if (subStatName == null) {
sendFeedbackMsgMissingSubStat(sender, statType); sendFeedbackMsgMissingSubStat(sender, statType);
} else { } else {
@ -129,6 +123,11 @@ public final class OutputManager {
.helpMsg()); .helpMsg());
} }
public void sendExcludeInfo(@NotNull CommandSender sender) {
adventure.sender(sender).sendMessage(getMessageBuilder(sender)
.excludeInfoMsg());
}
public void sendToAllPlayers(@NotNull TextComponent component) { public void sendToAllPlayers(@NotNull TextComponent component) {
adventure.players().sendMessage(component); adventure.players().sendMessage(component);
} }
@ -176,14 +175,16 @@ public final class OutputManager {
private void prepareFunctions() { private void prepareFunctions() {
standardMessages = new EnumMap<>(StandardMessage.class); standardMessages = new EnumMap<>(StandardMessage.class);
standardMessages.put(RELOADED_CONFIG, (MessageBuilder::reloadedConfig)); standardMessages.put(RELOADED_CONFIG, MessageBuilder::reloadedConfig);
standardMessages.put(STILL_RELOADING, (MessageBuilder::stillReloading)); standardMessages.put(STILL_RELOADING, MessageBuilder::stillReloading);
standardMessages.put(MISSING_STAT_NAME, (MessageBuilder::missingStatName)); standardMessages.put(MISSING_STAT_NAME, MessageBuilder::missingStatName);
standardMessages.put(MISSING_PLAYER_NAME, (MessageBuilder::missingPlayerName)); standardMessages.put(MISSING_PLAYER_NAME, MessageBuilder::missingPlayerName);
standardMessages.put(REQUEST_ALREADY_RUNNING, (MessageBuilder::requestAlreadyRunning)); standardMessages.put(WAIT_A_MOMENT, MessageBuilder::waitAMoment);
standardMessages.put(STILL_ON_SHARE_COOLDOWN, (MessageBuilder::stillOnShareCoolDown)); standardMessages.put(WAIT_A_MINUTE, MessageBuilder::waitAMinute);
standardMessages.put(RESULTS_ALREADY_SHARED, (MessageBuilder::resultsAlreadyShared)); standardMessages.put(REQUEST_ALREADY_RUNNING, MessageBuilder::requestAlreadyRunning);
standardMessages.put(STAT_RESULTS_TOO_OLD, (MessageBuilder::statResultsTooOld)); standardMessages.put(STILL_ON_SHARE_COOLDOWN, MessageBuilder::stillOnShareCoolDown);
standardMessages.put(UNKNOWN_ERROR, (MessageBuilder::unknownError)); standardMessages.put(RESULTS_ALREADY_SHARED, MessageBuilder::resultsAlreadyShared);
standardMessages.put(STAT_RESULTS_TOO_OLD, MessageBuilder::statResultsTooOld);
standardMessages.put(UNKNOWN_ERROR, MessageBuilder::unknownError);
} }
} }

View File

@ -107,9 +107,17 @@ public class ComponentFactory {
/** /**
* Returns a TextComponent with the input String as content, * Returns a TextComponent with the input String as content,
* with color Gray and decoration Italic. * with color Gray.
*/ */
public TextComponent subTitle(String content) { 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); return text(content).color(BRACKETS).decorate(TextDecoration.ITALIC);
} }

View File

@ -93,7 +93,7 @@ public final class HelpMessage implements TextComponent {
return Component.newline() return Component.newline()
.append(factory.pluginPrefixAsTitle()) .append(factory.pluginPrefixAsTitle())
.append(newline()) .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(newline())
.append(text("Usage:").color(factory.MSG_MAIN_2)).append(space()) .append(text("Usage:").color(factory.MSG_MAIN_2)).append(space())
.append(text("/statistic").color(factory.MSG_HOVER_ACCENT)) .append(text("/statistic").color(factory.MSG_HOVER_ACCENT))

View File

@ -48,8 +48,10 @@ final class StatThread extends Thread {
} }
long lastCalc = ThreadManager.getLastRecordedCalcTime(); long lastCalc = ThreadManager.getLastRecordedCalcTime();
if (lastCalc > 2000) { if (lastCalc > 6000) {
outputManager.sendFeedbackMsgWaitAMoment(statRequester, lastCalc > 20000); outputManager.sendFeedbackMsg(statRequester, StandardMessage.WAIT_A_MINUTE);
} else if (lastCalc > 2000) {
outputManager.sendFeedbackMsg(statRequester, StandardMessage.WAIT_A_MOMENT);
} }
try { try {