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" -> {
boolean isExcluded = offlinePlayerHandler.isExcludedPlayer(playerName);
sender.sendMessage(playerName+ " is excluded: " + isExcluded);
outputManager.sendExcludeInfo(sender);
return true;
}
}

View File

@ -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);
}
}
}

View File

@ -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
}
}

View File

@ -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);

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.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);
}
}

View File

@ -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);
}

View File

@ -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))

View File

@ -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 {