Add clickable prompts config option (#1847)

This commit is contained in:
datatags 2021-12-16 00:50:36 -08:00 committed by GitHub
parent 25c9f9ece8
commit d084823deb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 45 additions and 27 deletions

View File

@ -637,6 +637,11 @@ public class Quests extends JavaPlugin {
final MiscPostQuestAcceptEvent event = new MiscPostQuestAcceptEvent(context, this); final MiscPostQuestAcceptEvent event = new MiscPostQuestAcceptEvent(context, this);
getServer().getPluginManager().callEvent(event); getServer().getPluginManager().callEvent(event);
if (!getSettings().canClickablePrompts()) {
return ChatColor.YELLOW + getQueryText(context) + " " + ChatColor.GREEN
+ getSelectionText(context, 1) + ChatColor.RESET + " / " + getSelectionText(context, 2);
}
final TextComponent component = new TextComponent(""); final TextComponent component = new TextComponent("");
component.addExtra(ChatColor.YELLOW + getQueryText(context) + " " + ChatColor.GREEN); component.addExtra(ChatColor.YELLOW + getQueryText(context) + " " + ChatColor.GREEN);
final TextComponent yes = new TextComponent(getSelectionText(context, 1)); final TextComponent yes = new TextComponent(getSelectionText(context, 1));

View File

@ -27,6 +27,7 @@ public class Settings {
private boolean allowCommandsForNpcQuests = false; private boolean allowCommandsForNpcQuests = false;
private boolean allowPranks = true; private boolean allowPranks = true;
private boolean askConfirmation = true; private boolean askConfirmation = true;
private boolean clickablePrompts = true;
private int consoleLogging = 1; private int consoleLogging = 1;
private boolean disableCommandFeedback = true; private boolean disableCommandFeedback = true;
private boolean genFilesOnJoin = true; private boolean genFilesOnJoin = true;
@ -79,6 +80,12 @@ public class Settings {
public void setAskConfirmation(final boolean askConfirmation) { public void setAskConfirmation(final boolean askConfirmation) {
this.askConfirmation = askConfirmation; this.askConfirmation = askConfirmation;
} }
public boolean canClickablePrompts() {
return clickablePrompts;
}
public void setClickablePrompts(boolean clickablePrompts) {
this.clickablePrompts = clickablePrompts;
}
public int getConsoleLogging() { public int getConsoleLogging() {
return consoleLogging; return consoleLogging;
} }
@ -189,6 +196,7 @@ public class Settings {
allowCommandsForNpcQuests = config.getBoolean("allow-command-quests-with-npcs", false); allowCommandsForNpcQuests = config.getBoolean("allow-command-quests-with-npcs", false);
allowPranks = config.getBoolean("allow-pranks", true); allowPranks = config.getBoolean("allow-pranks", true);
askConfirmation = config.getBoolean("ask-confirmation", true); askConfirmation = config.getBoolean("ask-confirmation", true);
clickablePrompts = config.getBoolean("clickable-prompts", true);
consoleLogging = config.getInt("console-logging", 1); consoleLogging = config.getInt("console-logging", 1);
disableCommandFeedback = config.getBoolean("disable-command-feedback", true); disableCommandFeedback = config.getBoolean("disable-command-feedback", true);
genFilesOnJoin = config.getBoolean("generate-files-on-join", true); genFilesOnJoin = config.getBoolean("generate-files-on-join", true);

View File

@ -15,13 +15,14 @@ package me.blackvein.quests.convo;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.conversations.Conversable;
import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.NumericPrompt; import org.bukkit.conversations.NumericPrompt;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import me.blackvein.quests.Quests;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -46,7 +47,7 @@ public abstract class QuestsNumericPrompt extends NumericPrompt {
@Override @Override
public @NotNull String getPromptText(@NotNull final ConversationContext cc) { public @NotNull String getPromptText(@NotNull final ConversationContext cc) {
return sendClickableSelection(getBasicPromptText(cc), cc.getForWhom()); return sendClickableSelection(getBasicPromptText(cc), cc);
} }
public abstract String getBasicPromptText(ConversationContext cc); public abstract String getBasicPromptText(ConversationContext cc);
@ -58,11 +59,11 @@ public abstract class QuestsNumericPrompt extends NumericPrompt {
* Conversations API. * Conversations API.
* *
* @param input the Quests-styled conversation interface * @param input the Quests-styled conversation interface
* @param forWhom the conversation participant * @param context the conversation context
* @return plain text to deliver * @return plain text to deliver
*/ */
public static String sendClickableSelection(final String input, final Conversable forWhom) { public static String sendClickableSelection(final String input, final ConversationContext context) {
if (!(forWhom instanceof Player)) { if (!(context.getForWhom() instanceof Player) || !((Quests)context.getPlugin()).getSettings().canClickablePrompts()) {
return input; return input;
} }
final String[] basicText = input.split("\n"); final String[] basicText = input.split("\n");
@ -81,7 +82,7 @@ public abstract class QuestsNumericPrompt extends NumericPrompt {
} }
component.addExtra(lineComponent); component.addExtra(lineComponent);
} }
((Player)forWhom).spigot().sendMessage(component); ((Player)context.getForWhom()).spigot().sendMessage(component);
return ""; return "";
} }
} }

View File

@ -15,11 +15,14 @@ package me.blackvein.quests.convo;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.conversations.Conversable;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.StringPrompt; import org.bukkit.conversations.StringPrompt;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import me.blackvein.quests.Quests;
import java.util.List; import java.util.List;
public abstract class QuestsStringPrompt extends StringPrompt { public abstract class QuestsStringPrompt extends StringPrompt {
@ -49,12 +52,12 @@ public abstract class QuestsStringPrompt extends StringPrompt {
* @param header the menu header * @param header the menu header
* @param list a list of strings to display * @param list a list of strings to display
* @param footer the menu footer * @param footer the menu footer
* @param forWhom the conversation participant * @param context the conversation context
* @return plain text to deliver * @return plain text to deliver
*/ */
protected String sendClickableMenu(final String header, final List<String> list, final String footer, protected String sendClickableMenu(final String header, final List<String> list, final String footer,
final Conversable forWhom) { final ConversationContext context) {
if (!(forWhom instanceof Player)) { if (!(context.getForWhom() instanceof Player) || !((Quests)context.getPlugin()).getSettings().canClickablePrompts()) {
return ChatColor.GOLD + header + "\n" + ChatColor.AQUA + String.join(ChatColor.GRAY + ", " + ChatColor.AQUA, list) + "\n" + ChatColor.YELLOW + footer; return ChatColor.GOLD + header + "\n" + ChatColor.AQUA + String.join(ChatColor.GRAY + ", " + ChatColor.AQUA, list) + "\n" + ChatColor.YELLOW + footer;
} }
final TextComponent component = new TextComponent(header + "\n"); final TextComponent component = new TextComponent(header + "\n");
@ -73,7 +76,7 @@ public abstract class QuestsStringPrompt extends StringPrompt {
} }
} }
component.addExtra(footerComponent); component.addExtra(footerComponent);
((Player)forWhom).spigot().sendMessage(component); ((Player)context.getForWhom()).spigot().sendMessage(component);
return ""; return "";
} }
} }

View File

@ -1084,7 +1084,7 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i) text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)); .append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
} }
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom()); return QuestsNumericPrompt.sendClickableSelection(text.toString(), context);
} }
@Override @Override
@ -1164,7 +1164,7 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
for (int i = 1; i <= size; i++) { for (int i = 1; i <= size; i++) {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i).append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)); text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i).append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
} }
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom()); return QuestsNumericPrompt.sendClickableSelection(text.toString(), context);
} }
@Override @Override

View File

@ -238,7 +238,7 @@ public class ActionMenuPrompt extends ActionsEditorNumericPrompt {
= new ActionsEditorPostOpenStringPromptEvent(context, this); = new ActionsEditorPostOpenStringPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
final List<String> names = plugin.getLoadedActions().stream().map(Action::getName).collect(Collectors.toList()); final List<String> names = plugin.getLoadedActions().stream().map(Action::getName).collect(Collectors.toList());
return sendClickableMenu(getTitle(context), names, getQueryText(context), context.getForWhom()); return sendClickableMenu(getTitle(context), names, getQueryText(context), context);
} }
@Override @Override
@ -284,7 +284,7 @@ public class ActionMenuPrompt extends ActionsEditorNumericPrompt {
= new ActionsEditorPostOpenStringPromptEvent(context, this); = new ActionsEditorPostOpenStringPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
final List<String> names = plugin.getLoadedActions().stream().map(Action::getName).collect(Collectors.toList()); final List<String> names = plugin.getLoadedActions().stream().map(Action::getName).collect(Collectors.toList());
return sendClickableMenu(getTitle(context), names, getQueryText(context), context.getForWhom()); return sendClickableMenu(getTitle(context), names, getQueryText(context), context);
} }
@Override @Override
@ -383,7 +383,7 @@ public class ActionMenuPrompt extends ActionsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i) text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)); .append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
} }
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom()); return QuestsNumericPrompt.sendClickableSelection(text.toString(), context);
} }
@Override @Override

View File

@ -551,7 +551,7 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i) text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)); .append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
} }
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom()); return QuestsNumericPrompt.sendClickableSelection(text.toString(), context);
} }
@Override @Override
@ -632,7 +632,7 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i) text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)); .append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
} }
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom()); return QuestsNumericPrompt.sendClickableSelection(text.toString(), context);
} }
@Override @Override

View File

@ -237,7 +237,7 @@ public class ConditionMenuPrompt extends ConditionsEditorNumericPrompt {
= new ConditionsEditorPostOpenStringPromptEvent(context, this); = new ConditionsEditorPostOpenStringPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
final List<String> names = plugin.getLoadedConditions().stream().map(Condition::getName).collect(Collectors.toList()); final List<String> names = plugin.getLoadedConditions().stream().map(Condition::getName).collect(Collectors.toList());
return sendClickableMenu(getTitle(context), names, getQueryText(context), context.getForWhom()); return sendClickableMenu(getTitle(context), names, getQueryText(context), context);
} }
@Override @Override
@ -283,7 +283,7 @@ public class ConditionMenuPrompt extends ConditionsEditorNumericPrompt {
= new ConditionsEditorPostOpenStringPromptEvent(context, this); = new ConditionsEditorPostOpenStringPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
final List<String> names = plugin.getLoadedConditions().stream().map(Condition::getName).collect(Collectors.toList()); final List<String> names = plugin.getLoadedConditions().stream().map(Condition::getName).collect(Collectors.toList());
return sendClickableMenu(getTitle(context), names, getQueryText(context), context.getForWhom()); return sendClickableMenu(getTitle(context), names, getQueryText(context), context);
} }
@Override @Override
@ -382,7 +382,7 @@ public class ConditionMenuPrompt extends ConditionsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i) text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)); .append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
} }
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom()); return QuestsNumericPrompt.sendClickableSelection(text.toString(), context);
} }
@Override @Override

View File

@ -839,7 +839,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i) text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)); .append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
} }
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom()); return QuestsNumericPrompt.sendClickableSelection(text.toString(), context);
} }
@Override @Override
@ -963,7 +963,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i) text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)); .append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
} }
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom()); return QuestsNumericPrompt.sendClickableSelection(text.toString(), context);
} }
@Override @Override

View File

@ -223,7 +223,7 @@ public class QuestMenuPrompt extends QuestsEditorNumericPrompt {
= new QuestsEditorPostOpenStringPromptEvent(context, this); = new QuestsEditorPostOpenStringPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
final List<String> names = plugin.getLoadedQuests().stream().map(Quest::getName).collect(Collectors.toList()); final List<String> names = plugin.getLoadedQuests().stream().map(Quest::getName).collect(Collectors.toList());
return sendClickableMenu(getTitle(context), names, getQueryText(context), context.getForWhom()); return sendClickableMenu(getTitle(context), names, getQueryText(context), context);
} }
@Override @Override
@ -266,7 +266,7 @@ public class QuestMenuPrompt extends QuestsEditorNumericPrompt {
= new QuestsEditorPostOpenStringPromptEvent(context, this); = new QuestsEditorPostOpenStringPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
final List<String> names = plugin.getLoadedQuests().stream().map(Quest::getName).collect(Collectors.toList()); final List<String> names = plugin.getLoadedQuests().stream().map(Quest::getName).collect(Collectors.toList());
return sendClickableMenu(getTitle(context), names, getQueryText(context), context.getForWhom()); return sendClickableMenu(getTitle(context), names, getQueryText(context), context);
} }
@Override @Override
@ -364,7 +364,7 @@ public class QuestMenuPrompt extends QuestsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i) text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)); .append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
} }
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom()); return QuestsNumericPrompt.sendClickableSelection(text.toString(), context);
} }
@Override @Override

View File

@ -2342,7 +2342,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
text.append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i).append(ChatColor.RESET) text.append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i).append(ChatColor.RESET)
.append(" - ").append(getSelectionText(context, i)).append("\n"); .append(" - ").append(getSelectionText(context, i)).append("\n");
} }
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom()); return QuestsNumericPrompt.sendClickableSelection(text.toString(), context);
} }
@Override @Override

View File

@ -5,6 +5,7 @@ allow-command-quests-with-npcs: false
allow-pranks: true allow-pranks: true
allow-quitting: true allow-quitting: true
ask-confirmation: true ask-confirmation: true
clickable-prompts: true
console-logging: 2 console-logging: 2
disable-command-feedback: false disable-command-feedback: false
generate-files-on-join: true generate-files-on-join: true