NEW tab completion for commands

This commit is contained in:
PikaMug 2022-03-10 17:22:11 -05:00
parent 5739998125
commit 6140580fd2
24 changed files with 459 additions and 157 deletions

View File

@ -69,4 +69,11 @@ public interface Requirements {
List<String> getDetailsOverride();
void setDetailsOverride(final List<String> detailsOverride);
/**
* Check if quest has at least one requirement
*
* @return true if quest contains an requirement
*/
boolean hasRequirement();
}

View File

@ -50,4 +50,11 @@ public interface Rewards {
void setCustomRewards(final Map<String, Map<String, Object>> customRewards);
List<String> getDetailsOverride();
void setDetailsOverride(final List<String> detailsOverride);
/**
* Check if quest has at least one reward
*
* @return true if quest contains an reward
*/
boolean hasReward();
}

View File

@ -311,6 +311,9 @@ public class Quest implements IQuest {
}
final IStage currentStage = quester.getCurrentStage(this);
final IStage nextStage = getStage(stage);
if (currentStage == null || nextStage == null) {
return;
}
if (player.isOnline()) {
final QuesterPreChangeStageEvent preEvent
= new QuesterPreChangeStageEvent((Quester) quester, this, currentStage, nextStage);

View File

@ -83,6 +83,7 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.TabExecutor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
@ -150,7 +151,7 @@ public class Quests extends JavaPlugin implements QuestsAPI {
private Collection<IAction> actions = new ConcurrentSkipListSet<>();
private Collection<ICondition> conditions = new ConcurrentSkipListSet<>();
private LinkedList<Integer> questNpcIds = new LinkedList<>();
private CommandExecutor cmdExecutor;
private TabExecutor cmdExecutor;
private ConversationFactory conversationFactory;
private ConversationFactory npcConversationFactory;
private QuestFactory questFactory;
@ -230,13 +231,16 @@ public class Quests extends JavaPlugin implements QuestsAPI {
// 8 - Setup commands
if (getCommand("quests") != null) {
Objects.requireNonNull(getCommand("quests")).setExecutor(getCommandExecutor());
Objects.requireNonNull(getCommand("quests")).setExecutor(getTabExecutor());
Objects.requireNonNull(getCommand("quests")).setTabCompleter(getTabExecutor());
}
if (getCommand("questadmin") != null) {
Objects.requireNonNull(getCommand("questadmin")).setExecutor(getCommandExecutor());
Objects.requireNonNull(getCommand("questadmin")).setExecutor(getTabExecutor());
Objects.requireNonNull(getCommand("questadmin")).setTabCompleter(getTabExecutor());
}
if (getCommand("quest") != null) {
Objects.requireNonNull(getCommand("quest")).setExecutor(getCommandExecutor());
Objects.requireNonNull(getCommand("quest")).setExecutor(getTabExecutor());
Objects.requireNonNull(getCommand("quest")).setTabCompleter(getTabExecutor());
}
// 9 - Build conversation factories
@ -530,6 +534,10 @@ public class Quests extends JavaPlugin implements QuestsAPI {
return cmdExecutor;
}
public TabExecutor getTabExecutor() {
return cmdExecutor;
}
public ConversationFactory getConversationFactory() {
return conversationFactory;
}

View File

@ -19,6 +19,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
@ -38,6 +39,10 @@ public abstract class QuestsSubCommand {
public abstract void execute(CommandSender commandSender, String[] args);
public List<String> tabComplete(CommandSender commandSender, String[] args) {
return Collections.emptyList();
}
public static boolean assertNonPlayer(CommandSender commandSender) {
if (!(commandSender instanceof Player)) {
commandSender.sendMessage(ChatColor.YELLOW + Lang.get("consoleError"));

View File

@ -25,6 +25,10 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class QuestCommandHandler {
private final Quests plugin;
@ -74,6 +78,19 @@ public class QuestCommandHandler {
return true;
}
public List<String> suggest(final CommandSender cs, final String[] args) {
if (args.length != 1) {
return Collections.emptyList();
}
final List<String> results = new ArrayList<>();
for (final IQuest quest : plugin.getLoadedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[0].toLowerCase())) {
results.add(quest.getName());
}
}
return results;
}
private void showQuestDetails(final CommandSender cs, final String[] args) {
if (cs.hasPermission("quests.questinfo")) {
StringBuilder name = new StringBuilder();
@ -105,105 +122,107 @@ public class QuestCommandHandler {
}
cs.sendMessage(" ");
if (plugin.getSettings().canShowQuestReqs()) {
cs.sendMessage(ChatColor.GOLD + Lang.get("requirements"));
final Requirements reqs = q.getRequirements();
if (!reqs.getPermissions().isEmpty()) {
for (final String perm : reqs.getPermissions()) {
if (plugin.getDependencies().getVaultPermission().has(player, perm)) {
cs.sendMessage(ChatColor.GREEN + Lang.get("permissionDisplay") + " " + perm);
} else {
cs.sendMessage(ChatColor.RED + Lang.get("permissionDisplay") + " " + perm);
if (reqs.hasRequirement()) {
cs.sendMessage(ChatColor.GOLD + Lang.get("requirements"));
if (!reqs.getPermissions().isEmpty()) {
for (final String perm : reqs.getPermissions()) {
if (plugin.getDependencies().getVaultPermission().has(player, perm)) {
cs.sendMessage(ChatColor.GREEN + Lang.get("permissionDisplay") + " " + perm);
} else {
cs.sendMessage(ChatColor.RED + Lang.get("permissionDisplay") + " " + perm);
}
}
}
}
if (reqs.getHeroesPrimaryClass() != null) {
if (plugin.getDependencies()
.testPrimaryHeroesClass(reqs.getHeroesPrimaryClass(), player.getUniqueId())) {
cs.sendMessage(ChatColor.BOLD + "" + ChatColor.GREEN + reqs.getHeroesPrimaryClass()
+ ChatColor.RESET + "" + ChatColor.DARK_GREEN + " " + Lang.get("heroesClass"));
} else {
cs.sendMessage(ChatColor.BOLD + "" + ChatColor.DARK_RED + reqs.getHeroesPrimaryClass()
+ ChatColor.RESET + "" + ChatColor.RED + " " + Lang.get("heroesClass"));
}
}
if (reqs.getHeroesSecondaryClass() != null) {
if (plugin.getDependencies()
.testSecondaryHeroesClass(reqs.getHeroesSecondaryClass(), player.getUniqueId())) {
cs.sendMessage(ChatColor.BOLD + "" + ChatColor.DARK_RED + reqs.getHeroesSecondaryClass()
+ ChatColor.RESET + "" + ChatColor.RED + " " + Lang.get("heroesClass"));
} else {
cs.sendMessage(ChatColor.BOLD + "" + ChatColor.GREEN + reqs.getHeroesSecondaryClass()
+ ChatColor.RESET + "" + ChatColor.DARK_GREEN + " " + Lang.get("heroesClass"));
}
}
if (!reqs.getMcmmoSkills().isEmpty()) {
for (final String skill : reqs.getMcmmoSkills()) {
final int level = plugin.getDependencies().getMcmmoSkillLevel(Quests
.getMcMMOSkill(skill), player.getName());
final int req = reqs.getMcmmoAmounts().get(reqs.getMcmmoSkills().indexOf(skill));
final String skillName = MiscUtil.getCapitalized(skill);
if (level >= req) {
cs.sendMessage(ChatColor.GREEN + skillName + " " + Lang.get("mcMMOLevel") + " " + req);
if (reqs.getHeroesPrimaryClass() != null) {
if (plugin.getDependencies()
.testPrimaryHeroesClass(reqs.getHeroesPrimaryClass(), player.getUniqueId())) {
cs.sendMessage(ChatColor.BOLD + "" + ChatColor.GREEN + reqs.getHeroesPrimaryClass()
+ ChatColor.RESET + "" + ChatColor.DARK_GREEN + " " + Lang.get("heroesClass"));
} else {
cs.sendMessage(ChatColor.RED + skillName + " " + Lang.get("mcMMOLevel") + " " + req);
cs.sendMessage(ChatColor.BOLD + "" + ChatColor.DARK_RED + reqs.getHeroesPrimaryClass()
+ ChatColor.RESET + "" + ChatColor.RED + " " + Lang.get("heroesClass"));
}
}
}
if (reqs.getQuestPoints() != 0) {
if (quester.getQuestPoints() >= reqs.getQuestPoints()) {
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + reqs.getQuestPoints() + " "
+ Lang.get("questPoints"));
} else {
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + reqs.getQuestPoints() + " "
+ Lang.get("questPoints"));
}
}
if (reqs.getMoney() != 0) {
if (plugin.getDependencies().getVaultEconomy() != null && plugin.getDependencies()
.getVaultEconomy().getBalance(quester.getOfflinePlayer()) >= reqs.getMoney()) {
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + reqs.getMoney() + " "
+ (reqs.getMoney() > 1 ? plugin.getDependencies().getVaultEconomy()
.currencyNamePlural() : plugin.getDependencies().getVaultEconomy()
.currencyNameSingular()));
} else {
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + reqs.getMoney() + " "
+ (reqs.getMoney() > 1 ? plugin.getDependencies().getVaultEconomy()
.currencyNamePlural() : plugin.getDependencies().getVaultEconomy()
.currencyNameSingular()));
}
}
if (!reqs.getItems().isEmpty()) {
for (final ItemStack is : reqs.getItems()) {
if (plugin.getQuester(player.getUniqueId()).hasItem(is)) {
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + ItemUtil.getString(is));
if (reqs.getHeroesSecondaryClass() != null) {
if (plugin.getDependencies()
.testSecondaryHeroesClass(reqs.getHeroesSecondaryClass(), player.getUniqueId())) {
cs.sendMessage(ChatColor.BOLD + "" + ChatColor.DARK_RED + reqs.getHeroesSecondaryClass()
+ ChatColor.RESET + "" + ChatColor.RED + " " + Lang.get("heroesClass"));
} else {
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + ItemUtil.getString(is));
cs.sendMessage(ChatColor.BOLD + "" + ChatColor.GREEN + reqs.getHeroesSecondaryClass()
+ ChatColor.RESET + "" + ChatColor.DARK_GREEN + " " + Lang.get("heroesClass"));
}
}
}
if (!reqs.getNeededQuests().isEmpty()) {
for (final IQuest quest : reqs.getNeededQuests()) {
if (quester.getCompletedQuestsTemp().contains(quest)) {
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + Lang.get("complete") + " "
+ ChatColor.ITALIC + quest.getName());
} else {
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + Lang.get("complete") + " "
+ ChatColor.ITALIC + quest.getName());
if (!reqs.getMcmmoSkills().isEmpty()) {
for (final String skill : reqs.getMcmmoSkills()) {
final int level = plugin.getDependencies().getMcmmoSkillLevel(Quests
.getMcMMOSkill(skill), player.getName());
final int req = reqs.getMcmmoAmounts().get(reqs.getMcmmoSkills().indexOf(skill));
final String skillName = MiscUtil.getCapitalized(skill);
if (level >= req) {
cs.sendMessage(ChatColor.GREEN + skillName + " " + Lang.get("mcMMOLevel") + " " + req);
} else {
cs.sendMessage(ChatColor.RED + skillName + " " + Lang.get("mcMMOLevel") + " " + req);
}
}
}
}
if (!reqs.getBlockQuests().isEmpty()) {
for (final IQuest quest : reqs.getBlockQuests()) {
if (quester.getCompletedQuestsTemp().contains(quest)) {
String msg = Lang.get("haveCompleted");
msg = msg.replace("<quest>", ChatColor.ITALIC + "" + ChatColor.DARK_PURPLE
+ quest.getName() + ChatColor.RED);
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + msg);
if (reqs.getQuestPoints() != 0) {
if (quester.getQuestPoints() >= reqs.getQuestPoints()) {
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + reqs.getQuestPoints() + " "
+ Lang.get("questPoints"));
} else {
String msg = Lang.get("cannotComplete");
msg = msg.replace("<quest>", ChatColor.ITALIC + "" + ChatColor.DARK_PURPLE
+ quest.getName() + ChatColor.GREEN);
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + msg);
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + reqs.getQuestPoints() + " "
+ Lang.get("questPoints"));
}
}
if (reqs.getMoney() != 0) {
if (plugin.getDependencies().getVaultEconomy() != null && plugin.getDependencies()
.getVaultEconomy().getBalance(quester.getOfflinePlayer()) >= reqs.getMoney()) {
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + reqs.getMoney() + " "
+ (reqs.getMoney() > 1 ? plugin.getDependencies().getVaultEconomy()
.currencyNamePlural() : plugin.getDependencies().getVaultEconomy()
.currencyNameSingular()));
} else {
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + reqs.getMoney() + " "
+ (reqs.getMoney() > 1 ? plugin.getDependencies().getVaultEconomy()
.currencyNamePlural() : plugin.getDependencies().getVaultEconomy()
.currencyNameSingular()));
}
}
if (!reqs.getItems().isEmpty()) {
for (final ItemStack is : reqs.getItems()) {
if (plugin.getQuester(player.getUniqueId()).hasItem(is)) {
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + ItemUtil.getString(is));
} else {
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + ItemUtil.getString(is));
}
}
}
if (!reqs.getNeededQuests().isEmpty()) {
for (final IQuest quest : reqs.getNeededQuests()) {
if (quester.getCompletedQuestsTemp().contains(quest)) {
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + Lang.get("complete") + " "
+ ChatColor.ITALIC + quest.getName());
} else {
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + Lang.get("complete") + " "
+ ChatColor.ITALIC + quest.getName());
}
}
}
if (!reqs.getBlockQuests().isEmpty()) {
for (final IQuest quest : reqs.getBlockQuests()) {
if (quester.getCompletedQuestsTemp().contains(quest)) {
String msg = Lang.get("haveCompleted");
msg = msg.replace("<quest>", ChatColor.ITALIC + "" + ChatColor.DARK_PURPLE
+ quest.getName() + ChatColor.RED);
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + msg);
} else {
String msg = Lang.get("cannotComplete");
msg = msg.replace("<quest>", ChatColor.ITALIC + "" + ChatColor.DARK_PURPLE
+ quest.getName() + ChatColor.GREEN);
cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + msg);
}
}
}
}

View File

@ -31,6 +31,9 @@ import me.blackvein.quests.util.Lang;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -71,48 +74,27 @@ public class QuestadminCommandHandler {
}
}
cs.sendMessage(ChatColor.YELLOW + Lang.get("questsUnknownAdminCommand"));
/*if (args[0].equalsIgnoreCase("stats") || args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_STATS"))) {
new QuestadminStatsCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("give") || args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_GIVE"))) {
new QuestadminGiveCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("quit") || args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_QUIT"))) {
new QuestadminQuitCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("points")
|| args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_POINTS"))) {
new QuestadminPointsCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("takepoints")
|| args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_TAKEPOINTS"))) {
new QuestadminTakepointsCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("givepoints")
|| args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_GIVEPOINTS"))) {
new QuestadminGivepointsCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("pointsall")
|| args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_POINTSALL"))) {
new QuestadminPointsallCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("finish")
|| args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_FINISH"))) {
new QuestadminFinishCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("nextstage")
|| args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_NEXTSTAGE"))) {
new QuestadminNextstageCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("setstage")
|| args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_SETSTAGE"))) {
new QuestadminSetstageCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("reset")
|| args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_RESET"))) {
new QuestadminResetCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("remove")
|| args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_REMOVE"))) {
new QuestadminRemoveCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("reload")
|| args[0].equalsIgnoreCase(Lang.get("COMMAND_QUESTADMIN_RELOAD"))) {
new QuestadminReloadCommand(plugin).execute(cs, args);
} else {
cs.sendMessage(ChatColor.YELLOW + Lang.get("questsUnknownAdminCommand"));
}*/
return true;
}
public List<String> suggest(final CommandSender cs, final String[] args) {
if (args.length == 1) {
final List<String> results = new ArrayList<>();
for (Map.Entry<String, QuestsSubCommand> cmd : subCommands.entrySet()) {
if (cmd.getKey().startsWith(args[0]) || cmd.getValue().getNameI18N().startsWith(args[0])) {
results.add(cmd.getValue().getNameI18N());
}
}
return results;
}
for (Map.Entry<String, QuestsSubCommand> cmd : subCommands.entrySet()) {
if (args[0].equalsIgnoreCase(cmd.getKey()) || args[0].equalsIgnoreCase(cmd.getValue().getNameI18N())) {
return cmd.getValue().tabComplete(cs, args);
}
}
return Collections.emptyList();
}
private void printAdminHelp(final CommandSender cs) {
if (!(cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin"))) {
cs.sendMessage(ChatColor.RED + Lang.get("noPermission"));

View File

@ -23,6 +23,9 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class QuestadminFinishCommand extends QuestsSubCommand {
@ -99,4 +102,20 @@ public class QuestadminFinishCommand extends QuestsSubCommand {
cs.sendMessage(ChatColor.RED + Lang.get("noPermission"));
}
}
@Override
public List<String> tabComplete(CommandSender commandSender, String[] args) {
if (args.length == 2) {
return null; // Shows online players
} else if (args.length == 3) {
final List<String> results = new ArrayList<>();
for (final IQuest quest : plugin.getLoadedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(quest.getName());
}
}
return results;
}
return Collections.emptyList();
}
}

View File

@ -23,6 +23,9 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class QuestadminGiveCommand extends QuestsSubCommand {
@ -118,4 +121,20 @@ public class QuestadminGiveCommand extends QuestsSubCommand {
cs.sendMessage(ChatColor.RED + Lang.get("noPermission"));
}
}
@Override
public List<String> tabComplete(CommandSender commandSender, String[] args) {
if (args.length == 2) {
return null; // Shows online players
} else if (args.length == 3) {
final List<String> results = new ArrayList<>();
for (final IQuest quest : plugin.getLoadedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(quest.getName());
}
}
return results;
}
return Collections.emptyList();
}
}

View File

@ -22,6 +22,8 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class QuestadminGivepointsCommand extends QuestsSubCommand {
@ -94,4 +96,12 @@ public class QuestadminGivepointsCommand extends QuestsSubCommand {
cs.sendMessage(ChatColor.RED + Lang.get("noPermission"));
}
}
@Override
public List<String> tabComplete(CommandSender commandSender, String[] args) {
if (args.length == 2) {
return null; // Shows online players
}
return Collections.emptyList();
}
}

View File

@ -23,6 +23,9 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class QuestadminNextstageCommand extends QuestsSubCommand {
@ -99,4 +102,20 @@ public class QuestadminNextstageCommand extends QuestsSubCommand {
cs.sendMessage(ChatColor.RED + Lang.get("noPermission"));
}
}
@Override
public List<String> tabComplete(CommandSender commandSender, String[] args) {
if (args.length == 2) {
return null; // Shows online players
} else if (args.length == 3) {
final List<String> results = new ArrayList<>();
for (final IQuest quest : plugin.getLoadedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(quest.getName());
}
}
return results;
}
return Collections.emptyList();
}
}

View File

@ -22,6 +22,8 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class QuestadminPointsCommand extends QuestsSubCommand {
@ -94,4 +96,12 @@ public class QuestadminPointsCommand extends QuestsSubCommand {
cs.sendMessage(ChatColor.RED + Lang.get("noPermission"));
}
}
@Override
public List<String> tabComplete(CommandSender commandSender, String[] args) {
if (args.length == 2) {
return null; // Shows online players
}
return Collections.emptyList();
}
}

View File

@ -23,6 +23,9 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class QuestadminQuitCommand extends QuestsSubCommand {
@ -94,4 +97,20 @@ public class QuestadminQuitCommand extends QuestsSubCommand {
cs.sendMessage(ChatColor.RED + Lang.get("noPermission"));
}
}
@Override
public List<String> tabComplete(CommandSender commandSender, String[] args) {
if (args.length == 2) {
return null; // Shows online players
} else if (args.length == 3) {
final List<String> results = new ArrayList<>();
for (final IQuest quest : plugin.getLoadedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(quest.getName());
}
}
return results;
}
return Collections.emptyList();
}
}

View File

@ -22,6 +22,9 @@ import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class QuestadminRemoveCommand extends QuestsSubCommand {
@ -91,4 +94,20 @@ public class QuestadminRemoveCommand extends QuestsSubCommand {
cs.sendMessage(ChatColor.RED + Lang.get("noPermission"));
}
}
@Override
public List<String> tabComplete(CommandSender commandSender, String[] args) {
if (args.length == 2) {
return null; // Shows online players
} else if (args.length == 3) {
final List<String> results = new ArrayList<>();
for (final IQuest quest : plugin.getLoadedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(quest.getName());
}
}
return results;
}
return Collections.emptyList();
}
}

View File

@ -23,6 +23,8 @@ import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentSkipListSet;
@ -103,4 +105,12 @@ public class QuestadminResetCommand extends QuestsSubCommand {
cs.sendMessage(ChatColor.RED + Lang.get("noPermission"));
}
}
@Override
public List<String> tabComplete(CommandSender commandSender, String[] args) {
if (args.length == 2) {
return null; // Shows online players
}
return Collections.emptyList();
}
}

View File

@ -12,6 +12,7 @@
package me.blackvein.quests.commands.questadmin.subcommands;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quests;
import me.blackvein.quests.commands.QuestsSubCommand;
import me.blackvein.quests.player.IQuester;
@ -22,6 +23,9 @@ import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class QuestadminSetstageCommand extends QuestsSubCommand {
@ -91,6 +95,20 @@ public class QuestadminSetstageCommand extends QuestsSubCommand {
cs.sendMessage(ChatColor.RED + Lang.get("questNotFound"));
return;
}
if (!quester.getCurrentQuestsTemp().containsKey(quest)) {
String msg1 = Lang.get("questForceTake");
msg1 = msg1.replace("<player>", ChatColor.GREEN + quester.getLastKnownName() + ChatColor.GOLD);
msg1 = msg1.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.GOLD);
cs.sendMessage(ChatColor.GOLD + msg1);
if (quester.getPlayer() != null && quester.getPlayer().isOnline()) {
String msg2 = Lang.get("questForcedTake");
msg2 = msg2.replace("<player>", ChatColor.GREEN + quester.getLastKnownName() + ChatColor.GOLD);
msg2 = msg2.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.GOLD);
quester.sendMessage(ChatColor.GREEN + msg2);
}
quester.takeQuest(quest, true);
quester.saveData();
}
try {
quest.setStage(quester, stage - 1);
} catch (final IndexOutOfBoundsException e) {
@ -104,4 +122,29 @@ public class QuestadminSetstageCommand extends QuestsSubCommand {
cs.sendMessage(ChatColor.RED + Lang.get("noPermission"));
}
}
@Override
public List<String> tabComplete(CommandSender commandSender, String[] args) {
if (args.length == 2) {
return null; // Shows online players
} else if (args.length == 3) {
final List<String> results = new ArrayList<>();
for (final IQuest quest : plugin.getLoadedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
results.add(quest.getName());
}
}
return results;
} else if (args.length > 3) {
final Quest quest = plugin.getQuest(args[2]);
if (quest != null) {
final List<String> results = new ArrayList<>();
for (int i = 1; i <= quest.getStages().size(); i++) {
results.add(String.valueOf(i));
}
return results;
}
}
return Collections.emptyList();
}
}

View File

@ -22,6 +22,8 @@ import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@ -109,4 +111,12 @@ public class QuestadminStatsCommand extends QuestsSubCommand {
cs.sendMessage(ChatColor.RED + Lang.get("noPermission"));
}
}
@Override
public List<String> tabComplete(CommandSender commandSender, String[] args) {
if (args.length == 2) {
return null; // Shows online players
}
return Collections.emptyList();
}
}

View File

@ -22,6 +22,8 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class QuestadminTakepointsCommand extends QuestsSubCommand {
@ -94,4 +96,12 @@ public class QuestadminTakepointsCommand extends QuestsSubCommand {
cs.sendMessage(ChatColor.RED + Lang.get("noPermission"));
}
}
@Override
public List<String> tabComplete(CommandSender commandSender, String[] args) {
if (args.length == 2) {
return null; // Shows online players
}
return Collections.emptyList();
}
}

View File

@ -29,6 +29,9 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -66,34 +69,27 @@ public class QuestsCommandHandler {
}
}
cs.sendMessage(ChatColor.YELLOW + Lang.get("questsUnknownCommand"));
/*if (args[0].equalsIgnoreCase("list") || args[0].equalsIgnoreCase(Lang.get("COMMAND_LIST"))) {
new QuestsListCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("take") || args[0].equalsIgnoreCase(Lang.get("COMMAND_TAKE"))) {
new QuestsTakeCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("quit") || args[0].equalsIgnoreCase(Lang.get("COMMAND_QUIT"))) {
new QuestsQuitCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("stats") || args[0].equalsIgnoreCase(Lang.get("COMMAND_STATS"))) {
new QuestsStatsCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("journal") || args[0].equalsIgnoreCase(Lang.get("COMMAND_JOURNAL"))) {
new QuestsJournalCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("top") || args[0].equalsIgnoreCase(Lang.get("COMMAND_TOP"))) {
new QuestsTopCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("editor") || args[0].equalsIgnoreCase(Lang.get("COMMAND_EDITOR"))) {
new QuestsEditorCommand(plugin).execute(cs, args);
} else if (args[0].startsWith("action") || args[0].startsWith("event")
|| args[0].startsWith(Lang.get("COMMAND_EVENTS_EDITOR"))) {
new QuestsActionsCommand(plugin).execute(cs, args);
} else if (args[0].startsWith("condition") || args[0].startsWith(Lang.get("COMMAND_CONDITIONS_EDITOR"))) {
new QuestsConditionsCommand(plugin).execute(cs, args);
} else if (args[0].equalsIgnoreCase("info") || args[0].equalsIgnoreCase(Lang.get("COMMAND_INFO"))) {
new QuestsInfoCommand(plugin).execute(cs, args);
} else {
cs.sendMessage(ChatColor.YELLOW + Lang.get("questsUnknownCommand"));
return true;
}*/
return true;
}
public List<String> suggest(final CommandSender cs, final String[] args) {
if (args.length == 1) {
final List<String> results = new ArrayList<>();
for (Map.Entry<String, QuestsSubCommand> cmd : subCommands.entrySet()) {
if (cmd.getKey().startsWith(args[0]) || cmd.getValue().getNameI18N().startsWith(args[0])) {
results.add(cmd.getValue().getNameI18N());
}
}
return results;
}
for (Map.Entry<String, QuestsSubCommand> cmd : subCommands.entrySet()) {
if (args[0].equalsIgnoreCase(cmd.getKey()) || args[0].equalsIgnoreCase(cmd.getValue().getNameI18N())) {
return cmd.getValue().tabComplete(cs, args);
}
}
return Collections.emptyList();
}
private void printHelp(final CommandSender cs) {
if (!cs.hasPermission("quests.quests")) {
cs.sendMessage(ChatColor.RED + Lang.get("noPermission"));

View File

@ -21,6 +21,10 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class QuestsQuitCommand extends QuestsSubCommand {
private final Quests plugin;
@ -86,4 +90,18 @@ public class QuestsQuitCommand extends QuestsSubCommand {
Lang.send(player, ChatColor.RED + Lang.get(player, "noPermission"));
}
}
@Override
public List<String> tabComplete(CommandSender commandSender, String[] args) {
if (args.length == 2) {
final List<String> results = new ArrayList<>();
for (final IQuest quest : plugin.getLoadedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[1].toLowerCase())) {
results.add(quest.getName());
}
}
return results;
}
return Collections.emptyList();
}
}

View File

@ -21,6 +21,10 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class QuestsTakeCommand extends QuestsSubCommand {
private final Quests plugin;
@ -86,4 +90,18 @@ public class QuestsTakeCommand extends QuestsSubCommand {
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "questTakeDisabled"));
}
}
@Override
public List<String> tabComplete(CommandSender commandSender, String[] args) {
if (args.length == 2) {
final List<String> results = new ArrayList<>();
for (final IQuest quest : plugin.getLoadedQuests()) {
if (quest.getName().toLowerCase().startsWith(args[1].toLowerCase())) {
results.add(quest.getName());
}
}
return results;
}
return Collections.emptyList();
}
}

View File

@ -19,15 +19,17 @@ import me.blackvein.quests.commands.quests.QuestsCommandHandler;
import me.blackvein.quests.util.Lang;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CommandManager implements CommandExecutor {
public class CommandManager implements TabExecutor {
private final Quests plugin;
private final Map<String, Integer> commandSizes = new HashMap<>();
private final Map<String, Integer> adminCommandSizes = new HashMap<>();
@ -64,6 +66,22 @@ public class CommandManager implements CommandExecutor {
}
return false;
}
@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender cs, @NotNull Command cmd,
@NotNull String label, @NotNull String[] args) {
if (args.length > 0) {
if (cmd.getName().equalsIgnoreCase("quest")) {
return new QuestCommandHandler(plugin).suggest(cs, args);
} else if (cmd.getName().equalsIgnoreCase("quests")) {
return new QuestsCommandHandler(plugin).suggest(cs, args);
} else if (cmd.getName().equalsIgnoreCase("questadmin")) {
return new QuestadminCommandHandler(plugin).suggest(cs, args);
}
}
return null;
}
private void init() {
// [] - required

View File

@ -112,4 +112,20 @@ public class BukkitRequirements implements Requirements {
public void setDetailsOverride(final List<String> detailsOverride) {
this.detailsOverride = detailsOverride;
}
@Override
public boolean hasRequirement() {
if (money != 0) { return true; }
if (questPoints != 0) { return true; }
if (!items.isEmpty()) { return true; }
if (!removeItems.isEmpty()) { return true; }
if (!neededQuests.isEmpty()) { return true; }
if (!blockQuests.isEmpty()) { return true; }
if (!permissions.isEmpty()) { return true; }
if (!mcmmoSkills.isEmpty()) { return true; }
if (!mcmmoAmounts.isEmpty()) { return true; }
if (heroesPrimaryClass != null) { return true; }
if (heroesSecondaryClass != null) { return true; }
return !customRequirements.isEmpty();
}
}

View File

@ -133,4 +133,21 @@ public class BukkitRewards implements Rewards {
public void setDetailsOverride(final List<String> detailsOverride) {
this.detailsOverride = detailsOverride;
}
@Override
public boolean hasReward() {
if (money != 0) { return true; }
if (questPoints != 0) { return true; }
if (exp != 0) { return true; }
if (!commands.isEmpty()) { return true; }
if (!permissions.isEmpty()) { return true; }
if (!items.isEmpty()) { return true; }
if (!mcmmoSkills.isEmpty()) { return true; }
if (!mcmmoAmounts.isEmpty()) { return true; }
if (!heroesClasses.isEmpty()) { return true; }
if (!heroesAmounts.isEmpty()) { return true; }
if (partiesExperience != 0) { return true; }
if (!phatLoots.isEmpty()) { return true; }
return !customRewards.isEmpty();
}
}