Tab complete applicable quests only

This commit is contained in:
PikaMug 2022-04-27 05:24:27 -04:00
parent 684a3ebbdb
commit 2d3592a89c
7 changed files with 99 additions and 20 deletions

View File

@ -1595,7 +1595,7 @@ public class Quests extends JavaPlugin implements QuestsAPI {
} }
/** /**
* Show the player a list of their quests * Show the player a list of their available quests
* *
* @param quester Quester to show the list * @param quester Quester to show the list
* @param page Page to display, with 7 quests per page * @param page Page to display, with 7 quests per page

View File

@ -12,6 +12,7 @@
package me.blackvein.quests.commands.questadmin.subcommands; package me.blackvein.quests.commands.questadmin.subcommands;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests; import me.blackvein.quests.Quests;
import me.blackvein.quests.commands.QuestsSubCommand; import me.blackvein.quests.commands.QuestsSubCommand;
import me.blackvein.quests.player.IQuester; import me.blackvein.quests.player.IQuester;
@ -114,9 +115,21 @@ public class QuestadminFinishCommand extends QuestsSubCommand {
return null; // Shows online players return null; // Shows online players
} else if (args.length == 3) { } else if (args.length == 3) {
final List<String> results = new ArrayList<>(); final List<String> results = new ArrayList<>();
for (final IQuest quest : plugin.getLoadedQuests()) { final Player player = Bukkit.getPlayer(args[1]);
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) { if (player != null) {
results.add(ChatColor.stripColor(quest.getName())); final Quester quester = plugin.getQuester(player.getUniqueId());
if (quester != null) {
for (final IQuest quest : quester.getCurrentQuests().keySet()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(ChatColor.stripColor(quest.getName()));
}
}
}
} else {
for (final IQuest quest : plugin.getLoadedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(ChatColor.stripColor(quest.getName()));
}
} }
} }
return results; return results;

View File

@ -12,6 +12,7 @@
package me.blackvein.quests.commands.questadmin.subcommands; package me.blackvein.quests.commands.questadmin.subcommands;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests; import me.blackvein.quests.Quests;
import me.blackvein.quests.commands.QuestsSubCommand; import me.blackvein.quests.commands.QuestsSubCommand;
import me.blackvein.quests.player.IQuester; import me.blackvein.quests.player.IQuester;
@ -114,9 +115,21 @@ public class QuestadminNextstageCommand extends QuestsSubCommand {
return null; // Shows online players return null; // Shows online players
} else if (args.length == 3) { } else if (args.length == 3) {
final List<String> results = new ArrayList<>(); final List<String> results = new ArrayList<>();
for (final IQuest quest : plugin.getLoadedQuests()) { final Player player = Bukkit.getPlayer(args[1]);
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) { if (player != null) {
results.add(ChatColor.stripColor(quest.getName())); final Quester quester = plugin.getQuester(player.getUniqueId());
if (quester != null) {
for (final IQuest quest : quester.getCurrentQuests().keySet()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(ChatColor.stripColor(quest.getName()));
}
}
}
} else {
for (final IQuest quest : plugin.getLoadedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(ChatColor.stripColor(quest.getName()));
}
} }
} }
return results; return results;

View File

@ -12,6 +12,7 @@
package me.blackvein.quests.commands.questadmin.subcommands; package me.blackvein.quests.commands.questadmin.subcommands;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests; import me.blackvein.quests.Quests;
import me.blackvein.quests.commands.QuestsSubCommand; import me.blackvein.quests.commands.QuestsSubCommand;
import me.blackvein.quests.player.IQuester; import me.blackvein.quests.player.IQuester;
@ -109,9 +110,21 @@ public class QuestadminQuitCommand extends QuestsSubCommand {
return null; // Shows online players return null; // Shows online players
} else if (args.length == 3) { } else if (args.length == 3) {
final List<String> results = new ArrayList<>(); final List<String> results = new ArrayList<>();
for (final IQuest quest : plugin.getLoadedQuests()) { final Player player = Bukkit.getPlayer(args[1]);
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) { if (player != null) {
results.add(ChatColor.stripColor(quest.getName())); final Quester quester = plugin.getQuester(player.getUniqueId());
if (quester != null) {
for (final IQuest quest : quester.getCurrentQuests().keySet()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(ChatColor.stripColor(quest.getName()));
}
}
}
} else {
for (final IQuest quest : plugin.getLoadedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(ChatColor.stripColor(quest.getName()));
}
} }
} }
return results; return results;

View File

@ -12,6 +12,7 @@
package me.blackvein.quests.commands.questadmin.subcommands; package me.blackvein.quests.commands.questadmin.subcommands;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests; import me.blackvein.quests.Quests;
import me.blackvein.quests.commands.QuestsSubCommand; import me.blackvein.quests.commands.QuestsSubCommand;
import me.blackvein.quests.player.IQuester; import me.blackvein.quests.player.IQuester;
@ -21,6 +22,7 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -89,7 +91,7 @@ public class QuestadminRemoveCommand extends QuestsSubCommand {
} else { } else {
msg = msg.replace("<player>", ChatColor.GREEN + args[1] + ChatColor.GOLD); msg = msg.replace("<player>", ChatColor.GREEN + args[1] + ChatColor.GOLD);
} }
msg = msg.replace("<quest>", ChatColor.DARK_PURPLE + toRemove.getName() + ChatColor.AQUA); msg = msg.replace("<quest>", ChatColor.DARK_PURPLE + toRemove.getName() + ChatColor.GOLD);
cs.sendMessage(ChatColor.GOLD + msg); cs.sendMessage(ChatColor.GOLD + msg);
cs.sendMessage(ChatColor.DARK_PURPLE + " UUID: " + ChatColor.DARK_AQUA + quester.getUUID().toString()); cs.sendMessage(ChatColor.DARK_PURPLE + " UUID: " + ChatColor.DARK_AQUA + quester.getUUID().toString());
quester.hardRemove(toRemove); quester.hardRemove(toRemove);
@ -106,9 +108,21 @@ public class QuestadminRemoveCommand extends QuestsSubCommand {
return null; // Shows online players return null; // Shows online players
} else if (args.length == 3) { } else if (args.length == 3) {
final List<String> results = new ArrayList<>(); final List<String> results = new ArrayList<>();
for (final IQuest quest : plugin.getLoadedQuests()) { final Player player = Bukkit.getPlayer(args[1]);
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) { if (player != null) {
results.add(ChatColor.stripColor(quest.getName())); final Quester quester = plugin.getQuester(player.getUniqueId());
if (quester != null) {
for (final IQuest quest : quester.getCompletedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(ChatColor.stripColor(quest.getName()));
}
}
}
} else {
for (final IQuest quest : plugin.getLoadedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(ChatColor.stripColor(quest.getName()));
}
} }
} }
return results; return results;

View File

@ -13,6 +13,7 @@
package me.blackvein.quests.commands.questadmin.subcommands; package me.blackvein.quests.commands.questadmin.subcommands;
import me.blackvein.quests.Quest; import me.blackvein.quests.Quest;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests; import me.blackvein.quests.Quests;
import me.blackvein.quests.commands.QuestsSubCommand; import me.blackvein.quests.commands.QuestsSubCommand;
import me.blackvein.quests.player.IQuester; import me.blackvein.quests.player.IQuester;
@ -22,6 +23,7 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -134,9 +136,21 @@ public class QuestadminSetstageCommand extends QuestsSubCommand {
return null; // Shows online players return null; // Shows online players
} else if (args.length == 3) { } else if (args.length == 3) {
final List<String> results = new ArrayList<>(); final List<String> results = new ArrayList<>();
for (final IQuest quest : plugin.getLoadedQuests()) { final Player player = Bukkit.getPlayer(args[1]);
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) { if (player != null) {
results.add(quest.getName()); final Quester quester = plugin.getQuester(player.getUniqueId());
if (quester != null) {
for (final IQuest quest : quester.getCurrentQuests().keySet()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(ChatColor.stripColor(quest.getName()));
}
}
}
} else {
for (final IQuest quest : plugin.getLoadedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(ChatColor.stripColor(quest.getName()));
}
} }
} }
return results; return results;

View File

@ -12,6 +12,7 @@
package me.blackvein.quests.commands.quests.subcommands; package me.blackvein.quests.commands.quests.subcommands;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests; import me.blackvein.quests.Quests;
import me.blackvein.quests.commands.QuestsSubCommand; import me.blackvein.quests.commands.QuestsSubCommand;
import me.blackvein.quests.player.IQuester; import me.blackvein.quests.player.IQuester;
@ -100,9 +101,20 @@ public class QuestsQuitCommand extends QuestsSubCommand {
public List<String> tabComplete(CommandSender commandSender, String[] args) { public List<String> tabComplete(CommandSender commandSender, String[] args) {
if (args.length == 2) { if (args.length == 2) {
final List<String> results = new ArrayList<>(); final List<String> results = new ArrayList<>();
for (final IQuest quest : plugin.getLoadedQuests()) { if (commandSender instanceof Player) {
if (quest.getName().toLowerCase().startsWith(args[1].toLowerCase())) { final Quester quester = plugin.getQuester(((Player) commandSender).getUniqueId());
results.add(ChatColor.stripColor(quest.getName())); if (quester != null) {
for (final IQuest quest : quester.getCurrentQuests().keySet()) {
if (quest.getName().toLowerCase().startsWith(args[1].toLowerCase())) {
results.add(ChatColor.stripColor(quest.getName()));
}
}
}
} else {
for (final IQuest quest : plugin.getLoadedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[1].toLowerCase())) {
results.add(ChatColor.stripColor(quest.getName()));
}
} }
} }
return results; return results;