Clickable custom module prompts

This commit is contained in:
PikaMug 2022-01-04 01:15:52 -05:00
parent e325e67635
commit 0850f4c404
4 changed files with 227 additions and 54 deletions

View File

@ -143,6 +143,17 @@ public class NpcOfferQuestPrompt extends MiscStringPrompt {
final MiscPostNpcOfferQuestEvent event = new MiscPostNpcOfferQuestEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
if (!(context.getForWhom() instanceof Player) || !plugin.getSettings().canClickablePrompts()) {
final StringBuilder text = new StringBuilder(ChatColor.WHITE + getTitle(context));
size = quests.size();
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));
}
text.append("\n").append(ChatColor.WHITE).append(getQueryText(context));
return text.toString();
}
final TextComponent component = new TextComponent(getTitle(context));
component.setColor(net.md_5.bungee.api.ChatColor.WHITE);
size = quests.size();

View File

@ -14,7 +14,9 @@ package me.blackvein.quests.convo.quests.requirements;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.herocraftonline.heroes.characters.classes.HeroClass;
import me.blackvein.quests.CustomObjective;
import me.blackvein.quests.CustomRequirement;
import me.blackvein.quests.CustomReward;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quests;
import me.blackvein.quests.convo.generic.ItemStackPrompt;
@ -27,10 +29,13 @@ import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -1414,20 +1419,44 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
= new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
if (plugin.getCustomRequirements().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules").append(ChatColor.RESET)
.append("\n");
text.append(ChatColor.DARK_PURPLE).append("(").append(Lang.get("stageEditorNoModules")).append(") ");
if (!(context.getForWhom() instanceof Player)
|| !((Quests)context.getPlugin()).getSettings().canClickablePrompts()) {
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
if (plugin.getCustomRequirements().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules").append(ChatColor.RESET)
.append("\n");
text.append(ChatColor.DARK_PURPLE).append("(").append(Lang.get("stageEditorNoModules"))
.append(") ");
} else {
for (final String name : plugin.getCustomRequirements().stream()
.map(CustomRequirement::getModuleName).collect(Collectors.toCollection(TreeSet::new))) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(name).append("\n");
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
}
final TextComponent component = new TextComponent(getTitle(context) + "\n");
component.setColor(net.md_5.bungee.api.ChatColor.LIGHT_PURPLE);
final TextComponent line = new TextComponent("");
if (plugin.getCustomObjectives().isEmpty()) {
final TextComponent link = new TextComponent("https://pikamug.gitbook.io/quests/casual/modules\n");
link.setColor(net.md_5.bungee.api.ChatColor.DARK_AQUA);
link.setUnderlined(true);
line.addExtra(link);
line.addExtra(ChatColor.DARK_AQUA + "(" + Lang.get("stageEditorNoModules") + ") ");
} else {
for (final String name : plugin.getCustomRequirements().stream().map(CustomRequirement::getModuleName)
.collect(Collectors.toCollection(TreeSet::new))) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(name).append("\n");
final TextComponent click = new TextComponent(ChatColor.DARK_PURPLE + " - " + name + "\n");
click.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, name));
line.addExtra(click);
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
component.addExtra(line);
component.addExtra(ChatColor.YELLOW + getQueryText(context));
((Player)context.getForWhom()).spigot().sendMessage(component);
return "";
}
@Override
@ -1498,18 +1527,45 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
= new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
if (plugin.getCustomRequirements().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules\n").append(ChatColor.DARK_PURPLE)
.append("(").append(Lang.get("stageEditorNoModules")).append(") ");
if (!(context.getForWhom() instanceof Player)
|| !((Quests)context.getPlugin()).getSettings().canClickablePrompts()) {
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
if (plugin.getCustomRequirements().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules\n").append(ChatColor.DARK_PURPLE)
.append("(").append(Lang.get("stageEditorNoModules")).append(") ");
} else {
for (final CustomRequirement cr : plugin.getCustomRequirements()) {
if (cr.getModuleName().equals(moduleName)) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(cr.getName()).append("\n");
}
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
}
final TextComponent component = new TextComponent(getTitle(context) + "\n");
component.setColor(net.md_5.bungee.api.ChatColor.LIGHT_PURPLE);
final TextComponent line = new TextComponent("");
if (plugin.getCustomObjectives().isEmpty()) {
final TextComponent link = new TextComponent("https://pikamug.gitbook.io/quests/casual/modules\n");
link.setColor(net.md_5.bungee.api.ChatColor.DARK_AQUA);
link.setUnderlined(true);
line.addExtra(link);
line.addExtra(ChatColor.DARK_AQUA + "(" + Lang.get("stageEditorNoModules") + ") ");
} else {
for (final CustomRequirement cr : plugin.getCustomRequirements()) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(cr.getName()).append("\n");
for (final CustomRequirement co : plugin.getCustomRequirements()) {
if (co.getModuleName().equals(moduleName)) {
final TextComponent click = new TextComponent(ChatColor.DARK_PURPLE + " - " + co.getName()
+ "\n");
click.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, co.getName()));
line.addExtra(click);
}
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
component.addExtra(line);
component.addExtra(ChatColor.YELLOW + getQueryText(context));
((Player)context.getForWhom()).spigot().sendMessage(component);
return "";
}
@SuppressWarnings("unchecked")

View File

@ -16,6 +16,7 @@ import com.codisimus.plugins.phatloots.PhatLoot;
import com.codisimus.plugins.phatloots.PhatLootsAPI;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.herocraftonline.heroes.characters.classes.HeroClass;
import me.blackvein.quests.CustomObjective;
import me.blackvein.quests.CustomRequirement;
import me.blackvein.quests.CustomReward;
import me.blackvein.quests.Quests;
@ -29,10 +30,13 @@ import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -1796,20 +1800,44 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
= new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
if (plugin.getCustomRewards().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules").append(ChatColor.RESET)
.append("\n");
text.append(ChatColor.DARK_PURPLE).append("(").append(Lang.get("stageEditorNoModules")).append(") ");
if (!(context.getForWhom() instanceof Player)
|| !((Quests)context.getPlugin()).getSettings().canClickablePrompts()) {
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
if (plugin.getCustomRewards().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules").append(ChatColor.RESET)
.append("\n");
text.append(ChatColor.DARK_PURPLE).append("(").append(Lang.get("stageEditorNoModules"))
.append(") ");
} else {
for (final String name : plugin.getCustomRewards().stream().map(CustomReward::getModuleName)
.collect(Collectors.toCollection(TreeSet::new))) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(name).append("\n");
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
}
final TextComponent component = new TextComponent(getTitle(context) + "\n");
component.setColor(net.md_5.bungee.api.ChatColor.LIGHT_PURPLE);
final TextComponent line = new TextComponent("");
if (plugin.getCustomObjectives().isEmpty()) {
final TextComponent link = new TextComponent("https://pikamug.gitbook.io/quests/casual/modules\n");
link.setColor(net.md_5.bungee.api.ChatColor.DARK_AQUA);
link.setUnderlined(true);
line.addExtra(link);
line.addExtra(ChatColor.DARK_AQUA + "(" + Lang.get("stageEditorNoModules") + ") ");
} else {
for (final String name : plugin.getCustomRewards().stream().map(CustomReward::getModuleName)
.collect(Collectors.toCollection(TreeSet::new))) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(name).append("\n");
final TextComponent click = new TextComponent(ChatColor.DARK_PURPLE + " - " + name + "\n");
click.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, name));
line.addExtra(click);
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
component.addExtra(line);
component.addExtra(ChatColor.YELLOW + getQueryText(context));
((Player)context.getForWhom()).spigot().sendMessage(component);
return "";
}
@Override
@ -1880,21 +1908,45 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
= new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
if (plugin.getCustomRequirements().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules\n").append(ChatColor.DARK_PURPLE)
.append("(").append(Lang.get("stageEditorNoModules")).append(") ");
} else {
for (final CustomRequirement cr : plugin.getCustomRequirements()) {
if (cr.getModuleName().equals(moduleName)) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(cr.getName()).append("\n");
if (!(context.getForWhom() instanceof Player)
|| !((Quests)context.getPlugin()).getSettings().canClickablePrompts()) {
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
if (plugin.getCustomRewards().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules\n").append(ChatColor.DARK_PURPLE)
.append("(").append(Lang.get("stageEditorNoModules")).append(") ");
} else {
for (final CustomReward cr : plugin.getCustomRewards()) {
if (cr.getModuleName().equals(moduleName)) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(cr.getName()).append("\n");
}
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
}
final TextComponent component = new TextComponent(getTitle(context) + "\n");
component.setColor(net.md_5.bungee.api.ChatColor.LIGHT_PURPLE);
final TextComponent line = new TextComponent("");
if (plugin.getCustomObjectives().isEmpty()) {
final TextComponent link = new TextComponent("https://pikamug.gitbook.io/quests/casual/modules\n");
link.setColor(net.md_5.bungee.api.ChatColor.DARK_AQUA);
link.setUnderlined(true);
line.addExtra(link);
line.addExtra(ChatColor.DARK_AQUA + "(" + Lang.get("stageEditorNoModules") + ") ");
} else {
for (final CustomReward co : plugin.getCustomRewards()) {
if (co.getModuleName().equals(moduleName)) {
final TextComponent click = new TextComponent(ChatColor.DARK_PURPLE + " - " + co.getName()
+ "\n");
click.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, co.getName()));
line.addExtra(click);
}
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
component.addExtra(line);
component.addExtra(ChatColor.YELLOW + getQueryText(context));
((Player)context.getForWhom()).spigot().sendMessage(component);
return "";
}
@SuppressWarnings("unchecked")

View File

@ -30,6 +30,9 @@ import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Block;
@ -2383,20 +2386,44 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
= new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
if (!(context.getForWhom() instanceof Player)
|| !((Quests)context.getPlugin()).getSettings().canClickablePrompts()) {
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
if (plugin.getCustomObjectives().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules").append(ChatColor.RESET)
.append("\n");
text.append(ChatColor.DARK_PURPLE).append("(").append(Lang.get("stageEditorNoModules"))
.append(") ");
} else {
for (final String name : plugin.getCustomObjectives().stream().map(CustomObjective::getModuleName)
.collect(Collectors.toCollection(TreeSet::new))) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(name).append("\n");
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
}
final TextComponent component = new TextComponent(getTitle(context) + "\n");
component.setColor(net.md_5.bungee.api.ChatColor.LIGHT_PURPLE);
final TextComponent line = new TextComponent("");
if (plugin.getCustomObjectives().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules").append(ChatColor.RESET)
.append("\n");
text.append(ChatColor.DARK_PURPLE).append("(").append(Lang.get("stageEditorNoModules")).append(") ");
final TextComponent link = new TextComponent("https://pikamug.gitbook.io/quests/casual/modules\n");
link.setColor(net.md_5.bungee.api.ChatColor.DARK_AQUA);
link.setUnderlined(true);
line.addExtra(link);
line.addExtra(ChatColor.DARK_AQUA + "(" + Lang.get("stageEditorNoModules") + ") ");
} else {
for (final String name : plugin.getCustomObjectives().stream().map(CustomObjective::getModuleName)
.collect(Collectors.toCollection(TreeSet::new))) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(name).append("\n");
final TextComponent click = new TextComponent(ChatColor.DARK_PURPLE + " - " + name + "\n");
click.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, name));
line.addExtra(click);
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
component.addExtra(line);
component.addExtra(ChatColor.YELLOW + getQueryText(context));
((Player)context.getForWhom()).spigot().sendMessage(component);
return "";
}
@Override
@ -2467,20 +2494,47 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
= new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + "- " + getTitle(context) + " -\n");
if (!(context.getForWhom() instanceof Player)
|| !((Quests)context.getPlugin()).getSettings().canClickablePrompts()) {
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + "- " + getTitle(context)
+ " -\n");
if (plugin.getCustomObjectives().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules\n");
text.append(ChatColor.DARK_PURPLE).append("(").append(Lang.get("stageEditorNoModules"))
.append(") ");
} else {
for (final CustomObjective co : plugin.getCustomObjectives()) {
if (co.getModuleName().equals(moduleName)) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(co.getName()).append("\n");
}
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
}
final TextComponent component = new TextComponent(getTitle(context) + "\n");
component.setColor(net.md_5.bungee.api.ChatColor.LIGHT_PURPLE);
final TextComponent line = new TextComponent("");
if (plugin.getCustomObjectives().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules\n");
text.append(ChatColor.DARK_PURPLE).append("(").append(Lang.get("stageEditorNoModules")).append(") ");
final TextComponent link = new TextComponent("https://pikamug.gitbook.io/quests/casual/modules\n");
link.setColor(net.md_5.bungee.api.ChatColor.DARK_AQUA);
link.setUnderlined(true);
line.addExtra(link);
line.addExtra(ChatColor.DARK_AQUA + "(" + Lang.get("stageEditorNoModules") + ") ");
} else {
for (final CustomObjective co : plugin.getCustomObjectives()) {
if (co.getModuleName().equals(moduleName)) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(co.getName()).append("\n");
final TextComponent click = new TextComponent(ChatColor.DARK_PURPLE + " - " + co.getName()
+ "\n");
click.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, co.getName()));
line.addExtra(click);
}
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
component.addExtra(line);
component.addExtra(ChatColor.YELLOW + getQueryText(context));
((Player)context.getForWhom()).spigot().sendMessage(component);
return "";
}
@SuppressWarnings("unchecked")