Skip to content

Commit

Permalink
Re-add clickable text in 1.19 (#1999) (#2001)
Browse files Browse the repository at this point in the history
  • Loading branch information
datatags authored Aug 13, 2022
1 parent 0df7b37 commit a070255
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static String sendClickableSelection(final String input, final Conversati
final Matcher matcher = NUMBER_PATTERN.matcher(ChatColor.stripColor(line));
final TextComponent lineComponent = new TextComponent(TextComponent.fromLegacyText(line));
if (matcher.find()) {
lineComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, matcher.group(1)));
lineComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/quests choice " + matcher.group(1)));
}
if (first) {
first = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected String sendClickableMenu(final String header, final List<String> list,
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, ChatColor.stripColor(list.get(i))));
questName.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/quests choice " + ChatColor.stripColor(list.get(i))));
component.addExtra(questName);
if (i < (list.size() - 1)) {
component.addExtra(separator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import me.blackvein.quests.Quests;
import me.blackvein.quests.commands.quests.subcommands.QuestsActionsCommand;
import me.blackvein.quests.commands.quests.subcommands.QuestsChoiceCommand;
import me.blackvein.quests.commands.quests.subcommands.QuestsConditionsCommand;
import me.blackvein.quests.commands.quests.subcommands.QuestsEditorCommand;
import me.blackvein.quests.commands.quests.subcommands.QuestsInfoCommand;
Expand Down Expand Up @@ -53,7 +54,8 @@ public QuestsCommandHandler(Quests plugin) {
new QuestsEditorCommand(plugin),
new QuestsActionsCommand(plugin),
new QuestsConditionsCommand(plugin),
new QuestsInfoCommand(plugin))
new QuestsInfoCommand(plugin),
new QuestsChoiceCommand())
.collect(Collectors.toMap(QuestsSubCommand::getName, Function.identity()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package me.blackvein.quests.commands.quests.subcommands;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import me.blackvein.quests.commands.QuestsSubCommand;
import me.blackvein.quests.util.Lang;

public class QuestsChoiceCommand extends QuestsSubCommand {

@Override
public String getName() {
return "choice";
}

@Override
public String getNameI18N() {
return Lang.get("COMMAND_CHOICE");
}

@Override
public String getDescription() {
return Lang.get("COMMAND_CHOICE_HELP");
}

@Override
public String getPermission() {
return "quests.choice";
}

@Override
public String getSyntax() {
return "/quests choice";
}

@Override
public int getMaxArguments() {
return 2;
}

@Override
public void execute(CommandSender cs, String[] args) {
if (assertNonPlayer(cs)) {
return;
}
Player player = (Player) cs;
if (!cs.hasPermission(getPermission())) {
Lang.send(player, ChatColor.RED + Lang.get(player, "noPermission"));
return;
}
if (!player.isConversing()) {
Lang.send(player, ChatColor.RED + Lang.get(player, "notConversing"));
return;
}
if (args.length == 1) {
return;
}
player.acceptConversationInput(concatArgArray(args, 1, args.length - 1, ' '));
}

}
3 changes: 3 additions & 0 deletions core/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ permissions:
quests.journal:
description: Toggle the Quest Journal
default: true
quests.choice:
description: Respond to a Quests prompt
default: true
quests.compass:
description: Use a Compass to target quests
default: true
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/resources/strings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ COMMAND_TOP: "top"
COMMAND_TOP_HELP: "<command> [number] - View plugin leaderboards"
COMMAND_INFO: "info"
COMMAND_INFO_HELP: "<command> - View plugin information"
COMMAND_CHOICE: "choice"
COMMAND_CHOICE_HELP: "<command> <choice> - Make a menu selection"
COMMAND_QUEST_HELP: "- View current quest objectives"
COMMAND_QUESTINFO_HELP: "[quest] - View information about a quest"
COMMAND_QUESTADMIN_HELP: "- Display administrator help"
Expand Down Expand Up @@ -805,4 +807,5 @@ duplicateEditor: "You are already using an editor!"
difference: "The difference is '<data>'."
notInstalled: "Not installed"
confirmDelete: "Are you sure?"
updateTo: "Update to <version>: <url>"
updateTo: "Update to <version>: <url>"
notConversing: "You are not in a conversation!"

0 comments on commit a070255

Please sign in to comment.