mirror of https://github.com/PikaMug/Quests.git
Clickable NPC offer quest prompt
This commit is contained in:
parent
d084823deb
commit
089362b0f5
|
@ -12,6 +12,7 @@
|
|||
|
||||
package me.blackvein.quests.convo;
|
||||
|
||||
import me.blackvein.quests.util.Lang;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -63,6 +64,9 @@ public abstract class QuestsNumericPrompt extends NumericPrompt {
|
|||
* @return plain text to deliver
|
||||
*/
|
||||
public static String sendClickableSelection(final String input, final ConversationContext context) {
|
||||
if (context.getPlugin() == null) {
|
||||
return Lang.get("itemCreateCriticalError");
|
||||
}
|
||||
if (!(context.getForWhom() instanceof Player) || !((Quests)context.getPlugin()).getSettings().canClickablePrompts()) {
|
||||
return input;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
package me.blackvein.quests.convo;
|
||||
|
||||
import me.blackvein.quests.util.Lang;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
@ -57,6 +58,9 @@ public abstract class QuestsStringPrompt extends StringPrompt {
|
|||
*/
|
||||
protected String sendClickableMenu(final String header, final List<String> list, final String footer,
|
||||
final ConversationContext context) {
|
||||
if (context.getPlugin() == null) {
|
||||
return Lang.get("itemCreateCriticalError");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,10 @@ import me.blackvein.quests.Quester;
|
|||
import me.blackvein.quests.Quests;
|
||||
import me.blackvein.quests.events.misc.MiscPostNpcOfferQuestEvent;
|
||||
import me.blackvein.quests.util.Lang;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
|
@ -137,15 +141,25 @@ public class NpcOfferQuestPrompt extends MiscStringPrompt {
|
|||
final MiscPostNpcOfferQuestEvent event = new MiscPostNpcOfferQuestEvent(context, this);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
final StringBuilder text = new StringBuilder(ChatColor.WHITE + getTitle(context));
|
||||
final TextComponent component = new TextComponent(getTitle(context));
|
||||
component.setColor(net.md_5.bungee.api.ChatColor.WHITE);
|
||||
size = quests.size();
|
||||
final TextComponent line = new TextComponent("");
|
||||
for (int i = 1; i <= size + 1; i++) {
|
||||
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i).append(". ")
|
||||
.append(ChatColor.RESET).append(getSelectionText(context, i)).append(" ")
|
||||
.append(getAdditionalText(context, i));
|
||||
final TextComponent choice = new TextComponent("\n" + getNumberColor(context, i) + ChatColor.BOLD + i + ". "
|
||||
+ ChatColor.RESET + getSelectionText(context, i));
|
||||
choice.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.valueOf(i)));
|
||||
if (plugin.getSettings().canShowQuestReqs() && i <= size) {
|
||||
choice.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new ComponentBuilder(quests.get(i - 1).getDescription()).create()));
|
||||
}
|
||||
line.addExtra(choice);
|
||||
line.addExtra(getAdditionalText(context, i));
|
||||
}
|
||||
text.append("\n").append(ChatColor.WHITE).append(getQueryText(context));
|
||||
return text.toString();
|
||||
component.addExtra(line);
|
||||
component.addExtra("\n" + ChatColor.WHITE + getQueryText(context));
|
||||
((Player)context.getForWhom()).spigot().sendMessage(component);
|
||||
return "";
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
Loading…
Reference in New Issue