Support certain /quests commands in the console, fixes #758

This commit is contained in:
PikaMug 2019-11-07 17:51:02 -05:00
parent d8c430146f
commit 7f504280e5

View File

@ -211,38 +211,56 @@ public class CmdExecutor implements CommandExecutor {
} }
private boolean questsCommandHandler(final CommandSender cs, String[] args) { private boolean questsCommandHandler(final CommandSender cs, String[] args) {
if (cs instanceof Player) { if (args.length == 0) {
if (args.length == 0) { questsHelp(cs);
questsHelp(cs); return true;
}
boolean translateSubCommands = plugin.getSettings().canTranslateSubCommands();
if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_LIST") : "list")) {
questsList(cs, args);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_TAKE") : "take")) {
if (!(cs instanceof Player)) {
cs.sendMessage(ChatColor.YELLOW + Lang.get("consoleError"));
return true; return true;
} else {
boolean translateSubCommands = plugin.getSettings().canTranslateSubCommands();
if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_LIST") : "list")) {
questsList(cs, args);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_TAKE") : "take")) {
questsTake((Player) cs, args);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUIT") : "quit")) {
questsQuit((Player) cs, args);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_STATS") : "stats")) {
questsStats(cs, null);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_JOURNAL") : "journal")) {
questsJournal((Player) cs);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_TOP") : "top")) {
questsTop(cs, args);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_EDITOR") : "editor")) {
questsEditor(cs);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_EVENTS_EDITOR")
: "actions") || args[0].equalsIgnoreCase("action") || args[0].equalsIgnoreCase("events")) {
questsActions(cs);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_INFO") : "info")) {
questsInfo(cs);
} else {
cs.sendMessage(ChatColor.YELLOW + Lang.get("questsUnknownCommand"));
return true;
}
} }
questsTake((Player) cs, args);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_QUIT") : "quit")) {
if (!(cs instanceof Player)) {
cs.sendMessage(ChatColor.YELLOW + Lang.get("consoleError"));
return true;
}
questsQuit((Player) cs, args);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_STATS") : "stats")) {
if (!(cs instanceof Player)) {
cs.sendMessage(ChatColor.YELLOW + Lang.get("consoleError"));
return true;
}
questsStats(cs, null);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_JOURNAL") : "journal")) {
if (!(cs instanceof Player)) {
cs.sendMessage(ChatColor.YELLOW + Lang.get("consoleError"));
return true;
}
questsJournal((Player) cs);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_TOP") : "top")) {
questsTop(cs, args);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_EDITOR") : "editor")) {
if (!(cs instanceof Player)) {
cs.sendMessage(ChatColor.YELLOW + Lang.get("consoleError"));
return true;
}
questsEditor(cs);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_EVENTS_EDITOR")
: "actions") || args[0].equalsIgnoreCase("action") || args[0].equalsIgnoreCase("events")) {
if (!(cs instanceof Player)) {
cs.sendMessage(ChatColor.YELLOW + Lang.get("consoleError"));
return true;
}
questsActions(cs);
} else if (args[0].equalsIgnoreCase(translateSubCommands ? Lang.get("COMMAND_INFO") : "info")) {
questsInfo(cs);
} else { } else {
cs.sendMessage(ChatColor.YELLOW + Lang.get("consoleError")); cs.sendMessage(ChatColor.YELLOW + Lang.get("questsUnknownCommand"));
return true; return true;
} }
return true; return true;
@ -727,8 +745,16 @@ public class CmdExecutor implements CommandExecutor {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void questsList(final CommandSender cs, String[] args) { private void questsList(final CommandSender cs, String[] args) {
Player player = (Player)cs; if (cs.hasPermission("quests.list")) {
if (player.hasPermission("quests.list")) { if (!(cs instanceof Player)) {
int num = 1;
cs.sendMessage(ChatColor.GOLD + Lang.get("questListTitle"));
for (Quest q : plugin.getQuests()) {
cs.sendMessage(ChatColor.YELLOW + "" + num + ". " + q.getName());
num++;
}
}
Player player = (Player)cs;
if (args.length == 1) { if (args.length == 1) {
Quester quester = plugin.getQuester(player.getUniqueId()); Quester quester = plugin.getQuester(player.getUniqueId());
QuestsCommandPreQuestsListEvent preEvent = new QuestsCommandPreQuestsListEvent(quester, 1); QuestsCommandPreQuestsListEvent preEvent = new QuestsCommandPreQuestsListEvent(quester, 1);
@ -766,73 +792,81 @@ public class CmdExecutor implements CommandExecutor {
} }
private void questsHelp(final CommandSender cs) { private void questsHelp(final CommandSender cs) {
if (((Player) cs).hasPermission("quests.quests")) { if (cs.hasPermission("quests.quests")) {
Player p = (Player) cs; printHelp(cs);
printHelp(p);
} else { } else {
cs.sendMessage(ChatColor.RED + Lang.get("noPermission")); cs.sendMessage(ChatColor.RED + Lang.get("noPermission"));
} }
} }
public void printHelp(Player player) { public void printHelp(CommandSender cs) {
boolean translateSubCommands = plugin.getSettings().canTranslateSubCommands(); boolean translateSubCommands = plugin.getSettings().canTranslateSubCommands();
player.sendMessage(ChatColor.GOLD + Lang.get(player, "questHelpTitle")); cs.sendMessage(ChatColor.GOLD + Lang.get("questHelpTitle"));
player.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get(player, "questDisplayHelp")); cs.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get("questDisplayHelp"));
if (player.hasPermission("quests.list") || player.hasPermission("quests.list")) { if (cs.hasPermission("quests.list") || cs.hasPermission("quests.list")) {
player.sendMessage(ChatColor.YELLOW + "/quests "+ Lang.get(player, "COMMAND_LIST_HELP") cs.sendMessage(ChatColor.YELLOW + "/quests "+ Lang.get("COMMAND_LIST_HELP")
.replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get(player, "COMMAND_LIST") .replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get("COMMAND_LIST")
: "list") + ChatColor.YELLOW)); : "list") + ChatColor.YELLOW));
} }
if (player.hasPermission("quests.take")) { if (cs instanceof Player && cs.hasPermission("quests.take")) {
player.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get(player, "COMMAND_TAKE_HELP") cs.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get("COMMAND_TAKE_HELP")
.replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get(player, "COMMAND_TAKE") .replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get("COMMAND_TAKE")
: "take") + ChatColor.YELLOW)); : "take") + ChatColor.YELLOW));
} }
if (player.hasPermission("quests.quit")) { if (cs instanceof Player && cs.hasPermission("quests.quit")) {
player.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get(player, "COMMAND_QUIT_HELP") cs.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get("COMMAND_QUIT_HELP")
.replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get(player, "COMMAND_QUIT") .replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get("COMMAND_QUIT")
: "quit") + ChatColor.YELLOW)); : "quit") + ChatColor.YELLOW));
} }
if (player.hasPermission("quests.journal")) { if (cs instanceof Player && cs.hasPermission("quests.journal")) {
player.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get(player, "COMMAND_JOURNAL_HELP") cs.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get("COMMAND_JOURNAL_HELP")
.replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get(player, "COMMAND_JOURNAL") .replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get("COMMAND_JOURNAL")
: "journal") + ChatColor.YELLOW)); : "journal") + ChatColor.YELLOW));
} }
if (player.hasPermission("quests.editor.*") || player.hasPermission("quests.editor.editor")) { if (cs instanceof Player && (cs.hasPermission("quests.editor.*") || cs.hasPermission("quests.editor.editor"))) {
player.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get(player, "COMMAND_EDITOR_HELP") cs.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get("COMMAND_EDITOR_HELP")
.replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get(player, "COMMAND_EDITOR") .replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get("COMMAND_EDITOR")
: "editor") + ChatColor.YELLOW)); : "editor") + ChatColor.YELLOW));
} }
if (player.hasPermission("quests.events.*") || player.hasPermission("quests.actions.*") if (cs instanceof Player && (cs.hasPermission("quests.events.*") || cs.hasPermission("quests.actions.*")
|| player.hasPermission("quests.events.editor") || player.hasPermission("quests.actions.editor")) { || cs.hasPermission("quests.events.editor") || cs.hasPermission("quests.actions.editor"))) {
player.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get(player, "COMMAND_EVENTS_EDITOR_HELP") cs.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get("COMMAND_EVENTS_EDITOR_HELP")
.replace("<command>", ChatColor.GOLD + (translateSubCommands .replace("<command>", ChatColor.GOLD + (translateSubCommands
? Lang.get(player, "COMMAND_EVENTS_EDITOR") : "actions") + ChatColor.YELLOW)); ? Lang.get("COMMAND_EVENTS_EDITOR") : "actions") + ChatColor.YELLOW));
} }
if (player.hasPermission("quests.stats")) { if (cs.hasPermission("quests.stats")) {
player.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get(player, "COMMAND_STATS_HELP") cs.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get("COMMAND_STATS_HELP")
.replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get(player, "COMMAND_STATS") .replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get("COMMAND_STATS")
: "stats") + ChatColor.YELLOW)); : "stats") + ChatColor.YELLOW));
} }
if (player.hasPermission("quests.top")) { if (cs.hasPermission("quests.top")) {
player.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get(player, "COMMAND_TOP_HELP") cs.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get("COMMAND_TOP_HELP")
.replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get(player, "COMMAND_TOP") .replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get("COMMAND_TOP")
: "top") + ChatColor.YELLOW)); : "top") + ChatColor.YELLOW));
} }
if (player.hasPermission("quests.info")) { if (cs.hasPermission("quests.info")) {
player.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get(player, "COMMAND_INFO_HELP") cs.sendMessage(ChatColor.YELLOW + "/quests " + Lang.get("COMMAND_INFO_HELP")
.replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get(player, "COMMAND_INFO") .replace("<command>", ChatColor.GOLD + (translateSubCommands ? Lang.get("COMMAND_INFO")
: "info") + ChatColor.YELLOW)); : "info") + ChatColor.YELLOW));
} }
player.sendMessage(ChatColor.DARK_AQUA + "/quest " + ChatColor.YELLOW + Lang.get(player, "COMMAND_QUEST_HELP")); if (cs instanceof Player) {
if (player.hasPermission("quests.questinfo")) { cs.sendMessage(ChatColor.DARK_AQUA + "/quest " + ChatColor.YELLOW + Lang.get("COMMAND_QUEST_HELP"));
player.sendMessage(ChatColor.DARK_AQUA + "/quest " + ChatColor.YELLOW
+ Lang.get(player, "COMMAND_QUESTINFO_HELP"));
} }
if (player.hasPermission("quests.admin.*") || player.hasPermission("quests.admin")) { if (cs instanceof Player && cs.hasPermission("quests.questinfo")) {
player.sendMessage(ChatColor.YELLOW + "/questadmin " + ChatColor.RED cs.sendMessage(ChatColor.DARK_AQUA + "/quest " + ChatColor.YELLOW
+ Lang.get(player, "COMMAND_QUESTADMIN_HELP")); + Lang.get("COMMAND_QUESTINFO_HELP"));
} }
if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin")) {
cs.sendMessage(ChatColor.YELLOW + "/questadmin " + ChatColor.RED
+ Lang.get("COMMAND_QUESTADMIN_HELP"));
}
}
/**
* @deprecated Use {@link #printHelp(CommandSender)}
*/
public void printHelp(Player player) {
printHelp((CommandSender)player);
} }
public String getQuestsCommandUsage(String cmd) { public String getQuestsCommandUsage(String cmd) {