Add clickable menus support (#1818)

* Add missing disable-command-feedback config check

* Draft clickable menu support

* Fix console support, rename methods

* Add Javadocs, remove unused imports

* Fix a couple prompts that slipped through
This commit is contained in:
datatags 2021-10-24 21:48:12 -07:00 committed by GitHub
parent 18e29ce396
commit 1e91a8568a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 194 additions and 141 deletions

View File

@ -25,12 +25,12 @@
<repository>
<!-- Citizens, Denizen -->
<id>citizens-repo</id>
<url>http://repo.citizensnpcs.co/</url>
<url>https://repo.citizensnpcs.co/</url>
</repository>
<repository>
<!-- WorldEdit -->
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
<url>https://maven.sk89q.com/repo/</url>
</repository>
<repository>
<!-- Parties -->
@ -40,19 +40,19 @@
<repository>
<!-- PlaceholderAPI -->
<id>papi-repo</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<!-- Heroes, Vault -->
<id>hc-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases/</url>
<url>https://nexus.hc.to/content/repositories/pub_releases/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

View File

@ -12,12 +12,22 @@
package me.blackvein.quests.convo;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.ChatColor;
import org.bukkit.conversations.Conversable;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.NumericPrompt;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
public abstract class QuestsNumericPrompt extends NumericPrompt {
private static final HandlerList HANDLERS = new HandlerList();
private static final Pattern NUMBER_PATTERN = Pattern.compile("^(\\d+) - ");
public QuestsNumericPrompt() {
}
@ -32,4 +42,46 @@ public abstract class QuestsNumericPrompt extends NumericPrompt {
public static HandlerList getHandlerList() {
return HANDLERS;
}
@Override
public String getPromptText(ConversationContext cc) {
return sendClickableSelection(getBasicPromptText(cc), cc.getForWhom());
}
public abstract String getBasicPromptText(ConversationContext cc);
/**
* Takes a Quests-styled conversation interface and decides how to send it
* to the target. Players receive clickable text, others (i.e. console)
* receive plain text, which is returned to be delivered through the
* Conversations API.
*
* @param input the Quests-styled conversation interface
* @param forWhom the conversation participant
* @return plain text to deliver
*/
public static String sendClickableSelection(String input, Conversable forWhom) {
if (!(forWhom instanceof Player)) {
return input;
}
String[] basicText = input.split("\n");
TextComponent component = new TextComponent("");
boolean first = true;
for (String line : basicText) {
Matcher matcher = NUMBER_PATTERN.matcher(ChatColor.stripColor(line));
TextComponent lineComponent = new TextComponent(TextComponent.fromLegacyText(line));
if (matcher.find()) {
lineComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, matcher.group(1)));
}
if (first) {
first = false;
} else {
component.addExtra("\n");
}
component.addExtra(lineComponent);
}
Player player = (Player)forWhom;
player.spigot().sendMessage(component);
return "";
}
}

View File

@ -12,9 +12,17 @@
package me.blackvein.quests.convo;
import java.util.List;
import org.bukkit.conversations.Conversable;
import org.bukkit.conversations.StringPrompt;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
public abstract class QuestsStringPrompt extends StringPrompt {
private static final HandlerList HANDLERS = new HandlerList();
@ -32,4 +40,41 @@ public abstract class QuestsStringPrompt extends StringPrompt {
public static HandlerList getHandlerList() {
return HANDLERS;
}
/**
* Takes a header, footer, and a list of names, formats them in Quests
* style, and decides how to deliver the result. Players are sent
* clickable text, all others (i.e. console) are sent plain text,
* which is returned to be delivered through the Conversations API.
*
* @param header the menu header
* @param list a list of strings to display
* @param footer the menu footer
* @param forWhom the conversation participant
* @return plain text to deliver
*/
protected String sendClickableMenu(String header, List<String> list, String footer, Conversable forWhom) {
if (!(forWhom instanceof Player)) {
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");
component.setColor(ChatColor.GOLD);
final TextComponent footerComponent = new TextComponent("\n" + footer);
footerComponent.setColor(ChatColor.YELLOW);
final TextComponent separator = new TextComponent(", ");
separator.setColor(ChatColor.GRAY);
for (int i = 0; i < list.size(); i++) {
final TextComponent questName = new TextComponent(list.get(i));
questName.setColor(ChatColor.AQUA);
questName.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, list.get(i)));
component.addExtra(questName);
if (i < (list.size() - 1)) {
component.addExtra(separator);
}
}
component.addExtra(footerComponent);
Player player = (Player)forWhom;
player.spigot().sendMessage(component);
return "";
}
}

View File

@ -17,6 +17,7 @@ import me.blackvein.quests.QuestMob;
import me.blackvein.quests.Quests;
import me.blackvein.quests.Stage;
import me.blackvein.quests.actions.Action;
import me.blackvein.quests.convo.QuestsNumericPrompt;
import me.blackvein.quests.convo.actions.ActionsEditorNumericPrompt;
import me.blackvein.quests.convo.actions.ActionsEditorStringPrompt;
import me.blackvein.quests.convo.actions.tasks.EffectPrompt;
@ -178,7 +179,7 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
final ActionsEditorPostOpenNumericPromptEvent event = new ActionsEditorPostOpenNumericPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
@ -369,7 +370,7 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
final ActionsEditorPostOpenNumericPromptEvent event
= new ActionsEditorPostOpenNumericPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
@ -545,7 +546,7 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (questMob == null) {
questMob = new QuestMob();
}
@ -1082,7 +1083,7 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
}
return text.toString();
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom());
}
@Override
@ -1162,7 +1163,7 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
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));
}
return text.toString();
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom());
}
@Override

View File

@ -16,6 +16,7 @@ import me.blackvein.quests.Quest;
import me.blackvein.quests.Quests;
import me.blackvein.quests.Stage;
import me.blackvein.quests.actions.Action;
import me.blackvein.quests.convo.QuestsNumericPrompt;
import me.blackvein.quests.convo.actions.ActionsEditorNumericPrompt;
import me.blackvein.quests.convo.actions.ActionsEditorStringPrompt;
import me.blackvein.quests.convo.actions.main.ActionMainPrompt;
@ -27,6 +28,7 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.LinkedList;
@ -92,7 +94,7 @@ public class ActionMenuPrompt extends ActionsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
final ActionsEditorPostOpenNumericPromptEvent event
= new ActionsEditorPostOpenNumericPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
@ -235,17 +237,8 @@ public class ActionMenuPrompt extends ActionsEditorNumericPrompt {
final ActionsEditorPostOpenStringPromptEvent event
= new ActionsEditorPostOpenStringPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
final StringBuilder text = new StringBuilder(ChatColor.GOLD + getTitle(context) + "\n");
final List<String> names = plugin.getLoadedActions().stream().map(Action::getName).collect(Collectors.toList());
for (int i = 0; i < names.size(); i++) {
text.append(ChatColor.AQUA).append(names.get(i));
if (i < (names.size() - 1)) {
text.append(ChatColor.GRAY).append(", ");
}
}
text.append("\n").append(ChatColor.YELLOW).append(getQueryText(context));
return text.toString();
return sendClickableMenu(getTitle(context), names, getQueryText(context), context.getForWhom());
}
@Override
@ -290,17 +283,8 @@ public class ActionMenuPrompt extends ActionsEditorNumericPrompt {
final ActionsEditorPostOpenStringPromptEvent event
= new ActionsEditorPostOpenStringPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
final StringBuilder text = new StringBuilder(ChatColor.GOLD + getTitle(context) + "\n");
final List<String> names = plugin.getLoadedActions().stream().map(Action::getName).collect(Collectors.toList());
for (int i = 0; i < names.size(); i++) {
text.append(ChatColor.AQUA).append(names.get(i));
if (i < (names.size() - 1)) {
text.append(ChatColor.GRAY).append(", ");
}
}
text.append("\n").append(ChatColor.YELLOW).append(getQueryText(context));
return text.toString();
return sendClickableMenu(getTitle(context), names, getQueryText(context), context.getForWhom());
}
@Override
@ -399,7 +383,7 @@ public class ActionMenuPrompt extends ActionsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
}
return text.toString();
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom());
}
@Override

View File

@ -127,7 +127,7 @@ public class EffectPrompt extends ActionsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
final ActionsEditorPostOpenNumericPromptEvent event
= new ActionsEditorPostOpenNumericPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
@ -247,7 +247,7 @@ public class EffectPrompt extends ActionsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
final ActionsEditorPostOpenNumericPromptEvent event
= new ActionsEditorPostOpenNumericPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);

View File

@ -205,7 +205,7 @@ public class PlayerPrompt extends ActionsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
if (context.getSessionData(CK.E_CLEAR_INVENTORY) == null) {
context.setSessionData(CK.E_CLEAR_INVENTORY, Lang.get("noWord"));
}
@ -382,7 +382,7 @@ public class PlayerPrompt extends ActionsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(CK.E_ITEMS) != null) {
@ -530,7 +530,7 @@ public class PlayerPrompt extends ActionsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
final ActionsEditorPostOpenNumericPromptEvent event
= new ActionsEditorPostOpenNumericPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);

View File

@ -98,7 +98,7 @@ public class TimerPrompt extends ActionsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
if (context.getSessionData(CK.E_CANCEL_TIMER) == null) {
context.setSessionData(CK.E_CANCEL_TIMER, Lang.get("noWord"));
}

View File

@ -134,7 +134,7 @@ public class WeatherPrompt extends ActionsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
final ActionsEditorPostOpenNumericPromptEvent event
= new ActionsEditorPostOpenNumericPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
@ -251,7 +251,7 @@ public class WeatherPrompt extends ActionsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
final ActionsEditorPostOpenNumericPromptEvent event
= new ActionsEditorPostOpenNumericPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
@ -465,7 +465,7 @@ public class WeatherPrompt extends ActionsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
final ActionsEditorPostOpenNumericPromptEvent event
= new ActionsEditorPostOpenNumericPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);

View File

@ -16,6 +16,7 @@ import me.blackvein.quests.Quest;
import me.blackvein.quests.Quests;
import me.blackvein.quests.Stage;
import me.blackvein.quests.conditions.Condition;
import me.blackvein.quests.convo.QuestsNumericPrompt;
import me.blackvein.quests.convo.conditions.ConditionsEditorNumericPrompt;
import me.blackvein.quests.convo.conditions.ConditionsEditorStringPrompt;
import me.blackvein.quests.convo.conditions.tasks.EntityPrompt;
@ -28,6 +29,7 @@ import me.blackvein.quests.util.Lang;
import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
@ -121,7 +123,7 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
final ConditionsEditorPostOpenNumericPromptEvent event
= new ConditionsEditorPostOpenNumericPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
@ -325,7 +327,7 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final ConditionsEditorPostOpenNumericPromptEvent event
= new ConditionsEditorPostOpenNumericPromptEvent(context, this);
@ -550,7 +552,7 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
}
return text.toString();
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom());
}
@Override
@ -631,7 +633,7 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
}
return text.toString();
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom());
}
@Override

View File

@ -16,6 +16,7 @@ import me.blackvein.quests.Quest;
import me.blackvein.quests.Quests;
import me.blackvein.quests.Stage;
import me.blackvein.quests.conditions.Condition;
import me.blackvein.quests.convo.QuestsNumericPrompt;
import me.blackvein.quests.convo.conditions.ConditionsEditorNumericPrompt;
import me.blackvein.quests.convo.conditions.ConditionsEditorStringPrompt;
import me.blackvein.quests.convo.conditions.main.ConditionMainPrompt;
@ -27,6 +28,7 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.LinkedList;
@ -92,7 +94,7 @@ public class ConditionMenuPrompt extends ConditionsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
final ConditionsEditorPostOpenNumericPromptEvent event
= new ConditionsEditorPostOpenNumericPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
@ -234,17 +236,8 @@ public class ConditionMenuPrompt extends ConditionsEditorNumericPrompt {
final ConditionsEditorPostOpenStringPromptEvent event
= new ConditionsEditorPostOpenStringPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
final StringBuilder text = new StringBuilder(ChatColor.GOLD + getTitle(context) + "\n");
final List<String> names = plugin.getLoadedConditions().stream().map(Condition::getName).collect(Collectors.toList());
for (int i = 0; i < names.size(); i++) {
text.append(ChatColor.AQUA).append(names.get(i));
if (i < (names.size() - 1)) {
text.append(ChatColor.GRAY).append(", ");
}
}
text.append("\n").append(ChatColor.YELLOW).append(getQueryText(context));
return text.toString();
return sendClickableMenu(getTitle(context), names, getQueryText(context), context.getForWhom());
}
@Override
@ -289,17 +282,8 @@ public class ConditionMenuPrompt extends ConditionsEditorNumericPrompt {
final ConditionsEditorPostOpenStringPromptEvent event
= new ConditionsEditorPostOpenStringPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
final StringBuilder text = new StringBuilder(ChatColor.GOLD + getTitle(context) + "\n");
final List<String> names = plugin.getLoadedConditions().stream().map(Condition::getName).collect(Collectors.toList());
for (int i = 0; i < names.size(); i++) {
text.append(ChatColor.AQUA).append(names.get(i));
if (i < (names.size() - 1)) {
text.append(ChatColor.GRAY).append(", ");
}
}
text.append("\n").append(ChatColor.YELLOW).append(getQueryText(context));
return text.toString();
return sendClickableMenu(getTitle(context), names, getQueryText(context), context.getForWhom());
}
@Override
@ -398,7 +382,7 @@ public class ConditionMenuPrompt extends ConditionsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
}
return text.toString();
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom());
}
@Override

View File

@ -129,7 +129,7 @@ public class EntityPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);

View File

@ -119,7 +119,7 @@ public class PlayerPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(CK.C_WHILE_HOLDING_MAIN_HAND) != null) {
@ -284,7 +284,7 @@ public class PlayerPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public String getPromptText(final ConversationContext context) {
public String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(CK.C_WHILE_HOLDING_MAIN_HAND) != null) {

View File

@ -146,7 +146,7 @@ public class WorldPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);

View File

@ -223,7 +223,7 @@ public class ItemStackPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
Bukkit.getServer().getPluginManager().callEvent(event);

View File

@ -15,6 +15,7 @@ package me.blackvein.quests.convo.quests.main;
import com.sk89q.worldguard.protection.managers.RegionManager;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quests;
import me.blackvein.quests.convo.QuestsNumericPrompt;
import me.blackvein.quests.convo.generic.ItemStackPrompt;
import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt;
import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt;
@ -242,7 +243,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
@ -726,7 +727,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
final ItemStack stack = (ItemStack) context.getSessionData("tempStack");
@ -838,7 +839,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
}
return text.toString();
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom());
}
@Override
@ -962,7 +963,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
}
return text.toString();
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom());
}
@Override

View File

@ -14,6 +14,7 @@ package me.blackvein.quests.convo.quests.menu;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quests;
import me.blackvein.quests.convo.QuestsNumericPrompt;
import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt;
import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt;
import me.blackvein.quests.convo.quests.main.QuestMainPrompt;
@ -25,6 +26,7 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.LinkedList;
@ -90,7 +92,7 @@ public class QuestMenuPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
@ -220,17 +222,8 @@ public class QuestMenuPrompt extends QuestsEditorNumericPrompt {
final QuestsEditorPostOpenStringPromptEvent event
= new QuestsEditorPostOpenStringPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
final StringBuilder text = new StringBuilder(ChatColor.GOLD + getTitle(context) + "\n");
final List<String> names = plugin.getLoadedQuests().stream().map(Quest::getName).collect(Collectors.toList());
for (int i = 0; i < names.size(); i++) {
text.append(ChatColor.AQUA).append(names.get(i));
if (i < (names.size() - 1)) {
text.append(ChatColor.GRAY).append(", ");
}
}
text.append("\n").append(ChatColor.YELLOW).append(getQueryText(context));
return text.toString();
return sendClickableMenu(getTitle(context), names, getQueryText(context), context.getForWhom());
}
@Override
@ -272,18 +265,8 @@ public class QuestMenuPrompt extends QuestsEditorNumericPrompt {
final QuestsEditorPostOpenStringPromptEvent event
= new QuestsEditorPostOpenStringPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
final StringBuilder text = new StringBuilder(ChatColor.GOLD + getTitle(context) + "\n");
final List<String> names = plugin.getLoadedQuests().stream().map(Quest::getName)
.collect(Collectors.toList());
for (int i = 0; i < names.size(); i++) {
text.append(ChatColor.AQUA).append(names.get(i));
if (i < (names.size() - 1)) {
text.append(ChatColor.GRAY).append(", ");
}
}
text.append("\n").append(ChatColor.YELLOW).append(getQueryText(context));
return text.toString();
final List<String> names = plugin.getLoadedQuests().stream().map(Quest::getName).collect(Collectors.toList());
return sendClickableMenu(getTitle(context), names, getQueryText(context), context.getForWhom());
}
@Override
@ -381,7 +364,7 @@ public class QuestMenuPrompt extends QuestsEditorNumericPrompt {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i));
}
return text.toString();
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom());
}
@Override

View File

@ -164,7 +164,7 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
context.setSessionData(pref, Boolean.TRUE);
if (context.getPlugin() != null) {
@ -312,7 +312,7 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
@ -683,7 +683,7 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
@ -1051,7 +1051,7 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
@ -1417,7 +1417,7 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);

View File

@ -177,7 +177,7 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) != null) {
@ -311,7 +311,7 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) != null) {
@ -433,7 +433,7 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_SMELT_ITEMS) != null) {
@ -555,7 +555,7 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_ENCHANT_ITEMS) != null) {
@ -675,7 +675,7 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_BREW_ITEMS) != null) {
@ -795,7 +795,7 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_CONSUME_ITEMS) != null) {

View File

@ -203,7 +203,7 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
context.setSessionData(pref, Boolean.TRUE);
if (context.getPlugin() != null) {
@ -394,7 +394,7 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
@ -972,7 +972,7 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
@ -1247,7 +1247,7 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);

View File

@ -166,7 +166,7 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
context.setSessionData(pref, Boolean.TRUE);
if (context.getPlugin() != null) {
@ -331,7 +331,7 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_DELIVERY_ITEMS) != null) {
@ -661,7 +661,7 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);

View File

@ -85,7 +85,7 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
@ -500,7 +500,7 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
@ -674,7 +674,7 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);

View File

@ -182,7 +182,7 @@ public class DateTimePrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);

View File

@ -156,7 +156,7 @@ public class PlannerPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);

View File

@ -323,7 +323,7 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
final String input = (String) context.getSessionData(classPrefix + "-override");
if (input != null && !input.equalsIgnoreCase(Lang.get("cancel"))) {
if (input.equalsIgnoreCase(Lang.get("clear"))) {
@ -646,7 +646,7 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(CK.REQ_ITEMS) != null) {
@ -987,7 +987,7 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
@ -1214,7 +1214,7 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);

View File

@ -388,7 +388,7 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
final String input = (String) context.getSessionData(classPrefix + "-override");
if (input != null && !input.equalsIgnoreCase(Lang.get("cancel"))) {
if (input.equalsIgnoreCase(Lang.get("clear"))) {
@ -748,7 +748,7 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(CK.REW_ITEMS) != null) {
@ -969,7 +969,7 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
@ -1217,7 +1217,7 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
@ -1478,7 +1478,7 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);

View File

@ -16,6 +16,7 @@ import me.blackvein.quests.CustomObjective;
import me.blackvein.quests.Quests;
import me.blackvein.quests.actions.Action;
import me.blackvein.quests.conditions.Condition;
import me.blackvein.quests.convo.QuestsNumericPrompt;
import me.blackvein.quests.convo.generic.OverridePrompt;
import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt;
import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt;
@ -431,7 +432,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public @NotNull String getPromptText(final ConversationContext context) {
public @NotNull String getBasicPromptText(final ConversationContext context) {
final String input = (String) context.getSessionData(classPrefix + "-override");
if (input != null && !input.equalsIgnoreCase(Lang.get("cancel"))) {
if (input.equalsIgnoreCase(Lang.get("clear"))) {
@ -731,7 +732,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
@ -1064,7 +1065,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
@ -1366,7 +1367,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
@ -2341,7 +2342,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
text.append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i).append(ChatColor.RESET)
.append(" - ").append(getSelectionText(context, i)).append("\n");
}
return text.toString();
return QuestsNumericPrompt.sendClickableSelection(text.toString(), context.getForWhom());
}
@Override

View File

@ -79,7 +79,7 @@ public class StageMenuPrompt extends QuestsEditorNumericPrompt {
}
@Override
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);

View File

@ -31,7 +31,7 @@
<repositories>
<repository>
<id>elmakers-repo</id>
<url>http://maven.elmakers.com/repository/</url>
<url>https://maven.elmakers.com/repository/</url>
</repository>
</repositories>
</project>