Properly display command usage

This commit is contained in:
PikaMug 2022-05-15 11:21:54 -04:00
parent 67b8018f93
commit baf377e304
19 changed files with 85 additions and 97 deletions

View File

@ -185,6 +185,7 @@ public class QuestadminCommandHandler {
private String getAdminCommandUsage(final String cmd) {
return ChatColor.RED + Lang.get("usage") + ": " + ChatColor.YELLOW + "/questadmin "
+ Lang.get(Lang.getKeyFromPrefix("COMMAND_QUESTADMIN_", cmd) + "_HELP");
+ Lang.get(Lang.getKeyFromPrefix("COMMAND_QUESTADMIN_", cmd) + "_HELP")
.replace("<command>", cmd.toLowerCase());
}
}

View File

@ -70,7 +70,7 @@ public class QuestadminFinishCommand extends QuestsSubCommand {
@Override
public void execute(CommandSender cs, String[] args) {
if (args.length == 1) {
cs.sendMessage(ChatColor.RED + Lang.get("COMMAND_QUESTADMIN_FINISH_HELP"));
// Shows command usage
return;
}
if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.finish")) {

View File

@ -69,7 +69,7 @@ public class QuestadminGiveCommand extends QuestsSubCommand {
@Override
public void execute(CommandSender cs, String[] args) {
if (args.length == 1) {
cs.sendMessage(ChatColor.RED + Lang.get("COMMAND_QUESTADMIN_GIVE_HELP"));
// Shows command usage
return;
}
if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.give")) {

View File

@ -67,7 +67,7 @@ public class QuestadminGivepointsCommand extends QuestsSubCommand {
@Override
public void execute(CommandSender cs, String[] args) {
if (args.length == 1) {
cs.sendMessage(ChatColor.RED + Lang.get("COMMAND_QUESTADMIN_GIVEPOINTS_HELP"));
// Shows command usage
return;
}
if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.givepoints")) {

View File

@ -70,7 +70,7 @@ public class QuestadminNextstageCommand extends QuestsSubCommand {
@Override
public void execute(CommandSender cs, String[] args) {
if (args.length == 1) {
cs.sendMessage(ChatColor.RED + Lang.get("COMMAND_QUESTADMIN_NEXTSTAGE_HELP"));
// Shows command usage
return;
}
if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.nextstage")) {

View File

@ -67,7 +67,7 @@ public class QuestadminPointsCommand extends QuestsSubCommand {
@Override
public void execute(CommandSender cs, String[] args) {
if (args.length == 1) {
cs.sendMessage(ChatColor.RED + Lang.get("COMMAND_QUESTADMIN_POINTS_HELP"));
// Shows command usage
return;
}
if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.points")) {

View File

@ -67,7 +67,7 @@ public class QuestadminPointsallCommand extends QuestsSubCommand {
@Override
public void execute(CommandSender cs, String[] args) {
if (args.length == 1) {
cs.sendMessage(ChatColor.RED + Lang.get("COMMAND_QUESTADMIN_POINTSALL_HELP"));
// Shows command usage
return;
}
if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.pointsall")) {

View File

@ -70,7 +70,7 @@ public class QuestadminQuitCommand extends QuestsSubCommand {
@Override
public void execute(CommandSender cs, String[] args) {
if (args.length == 1) {
cs.sendMessage(ChatColor.RED + Lang.get("COMMAND_QUESTADMIN_QUIT_HELP"));
// Shows command usage
return;
}
if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.quit")) {

View File

@ -70,7 +70,7 @@ public class QuestadminRemoveCommand extends QuestsSubCommand {
@Override
public void execute(CommandSender cs, String[] args) {
if (args.length == 1) {
cs.sendMessage(ChatColor.RED + Lang.get("COMMAND_QUESTADMIN_REMOVE_HELP"));
// Shows command usage
return;
}
if (cs.hasPermission("quests.admin.*") && cs.hasPermission("quests.admin.remove")) {

View File

@ -69,7 +69,7 @@ public class QuestadminResetCommand extends QuestsSubCommand {
@Override
public void execute(CommandSender cs, String[] args) {
if (args.length == 1) {
cs.sendMessage(ChatColor.RED + Lang.get("COMMAND_QUESTADMIN_RESET_HELP"));
// Shows command usage
return;
}
if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.reset")) {

View File

@ -71,7 +71,7 @@ public class QuestadminSetstageCommand extends QuestsSubCommand {
@Override
public void execute(CommandSender cs, String[] args) {
if (args.length == 1) {
cs.sendMessage(ChatColor.RED + Lang.get("COMMAND_QUESTADMIN_SETSTAGE_HELP"));
// Shows command usage
return;
}
if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.setstage")) {
@ -85,14 +85,10 @@ public class QuestadminSetstageCommand extends QuestsSubCommand {
}
}
int stage = -1;
if (args.length > 3) {
try {
stage = Integer.parseInt(args[args.length - 1]);
} catch (final NumberFormatException e) {
cs.sendMessage(ChatColor.YELLOW + Lang.get("inputNum"));
}
} else {
cs.sendMessage(ChatColor.YELLOW + Lang.get("COMMAND_QUESTADMIN_SETSTAGE_USAGE"));
try {
stage = Integer.parseInt(args[args.length - 1]);
} catch (final NumberFormatException e) {
cs.sendMessage(ChatColor.YELLOW + Lang.get("inputNum"));
return;
}
final IQuester quester = plugin.getQuester(target.getUniqueId());

View File

@ -68,7 +68,7 @@ public class QuestadminStatsCommand extends QuestsSubCommand {
@Override
public void execute(CommandSender cs, String[] args) {
if (args.length == 1) {
cs.sendMessage(ChatColor.RED + Lang.get("COMMAND_QUESTADMIN_STATS_HELP"));
// Shows command usage
return;
}
if (cs.hasPermission("quests.admin.*") && cs.hasPermission("quests.admin.stats")) {

View File

@ -67,7 +67,7 @@ public class QuestadminTakepointsCommand extends QuestsSubCommand {
@Override
public void execute(CommandSender cs, String[] args) {
if (args.length == 1) {
cs.sendMessage(ChatColor.RED + Lang.get("COMMAND_QUESTADMIN_TAKEPOINTS_HELP"));
// Shows command usage
return;
}
if (cs.hasPermission("quests.admin.*") || cs.hasPermission("quests.admin.takepoints")) {

View File

@ -120,6 +120,6 @@ public class QuestsCommandHandler {
private String getCommandUsage(final String cmd) {
return ChatColor.RED + Lang.get("usage") + ": " + ChatColor.YELLOW + "/quests "
+ Lang.get(Lang.getKeyFromPrefix("COMMAND_", cmd) + "_HELP");
+ Lang.get(Lang.getKeyFromPrefix("COMMAND_", cmd) + "_HELP").replace("<command>", cmd.toLowerCase());
}
}

View File

@ -58,12 +58,10 @@ public class QuestsInfoCommand extends QuestsSubCommand {
@Override
public void execute(CommandSender cs, String[] args) {
if (cs.hasPermission("quests.info")) {
cs.sendMessage(ChatColor.YELLOW + "Quests " + ChatColor.GOLD
+ plugin.getDescription().getVersion());
cs.sendMessage(ChatColor.YELLOW + "Quests " + ChatColor.GOLD + plugin.getDescription().getVersion());
cs.sendMessage(ChatColor.GOLD + Lang.get("createdBy") + " " + ChatColor.RED + "Blackvein"
+ ChatColor.GOLD + " " + Lang.get("continuedBy") + " " + ChatColor.RED + "PikaMug & contributors");
cs.sendMessage(ChatColor.DARK_AQUA + "" + ChatColor.UNDERLINE
+ "https://github.com/PikaMug/Quests");
cs.sendMessage(ChatColor.DARK_AQUA + "" + ChatColor.UNDERLINE + "https://github.com/PikaMug/Quests");
}
}
}

View File

@ -66,15 +66,15 @@ public class QuestsQuitCommand extends QuestsSubCommand {
@Override
public void execute(CommandSender cs, String[] args) {
if (args.length == 1) {
// Shows command usage
return;
}
if (assertNonPlayer(cs)) {
return;
}
final Player player = (Player) cs;
if (player.hasPermission(getPermission())) {
if (args.length == 1) {
Lang.send(player, ChatColor.RED + Lang.get(player, "COMMAND_QUIT_HELP"));
return;
}
final IQuester quester = plugin.getQuester(player.getUniqueId());
if (!quester.getCurrentQuestsTemp().isEmpty()) {
final IQuest quest = plugin.getQuestTemp(concatArgArray(args, 1, args.length - 1, ' '));

View File

@ -65,28 +65,28 @@ public class QuestsTakeCommand extends QuestsSubCommand {
@Override
public void execute(CommandSender cs, String[] args) {
if (args.length == 1) {
// Shows command usage
return;
}
if (assertNonPlayer(cs)) {
return;
}
final Player player = (Player) cs;
if (plugin.getSettings().canAllowCommands()) {
if (player.hasPermission(getPermission())) {
if (args.length == 1) {
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "COMMAND_TAKE_USAGE"));
} else {
final IQuest questToFind = plugin.getQuestTemp(concatArgArray(args, 1, args.length - 1, ' '));
final IQuester quester = plugin.getQuester(player.getUniqueId());
if (questToFind != null) {
for (final IQuest q : quester.getCurrentQuestsTemp().keySet()) {
if (q.getId().equals(questToFind.getId())) {
Lang.send(player, ChatColor.RED + Lang.get(player, "questAlreadyOn"));
return;
}
final IQuest questToFind = plugin.getQuestTemp(concatArgArray(args, 1, args.length - 1, ' '));
final IQuester quester = plugin.getQuester(player.getUniqueId());
if (questToFind != null) {
for (final IQuest q : quester.getCurrentQuestsTemp().keySet()) {
if (q.getId().equals(questToFind.getId())) {
Lang.send(player, ChatColor.RED + Lang.get(player, "questAlreadyOn"));
return;
}
quester.offerQuest(questToFind, true);
} else {
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "questNotFound"));
}
quester.offerQuest(questToFind, true);
} else {
Lang.send(player, ChatColor.YELLOW + Lang.get(player, "questNotFound"));
}
} else {
Lang.send(player, ChatColor.RED + Lang.get(player, "noPermission"));

View File

@ -63,65 +63,61 @@ public class QuestsTopCommand extends QuestsSubCommand {
@Override
public int getMaxArguments() {
return 2;
return 1;
}
@Override
public void execute(CommandSender cs, String[] args) {
if (cs.hasPermission(getPermission())) {
if (args.length > 2) {
cs.sendMessage(ChatColor.YELLOW + Lang.get("COMMAND_TOP_USAGE"));
final int topNumber;
if (args.length == 1) {
topNumber = 5; // default
} else {
final int topNumber;
if (args.length == 1) {
topNumber = 5; // default
} else {
try {
topNumber = Integer.parseInt(args[1]);
} catch (final NumberFormatException e) {
cs.sendMessage(ChatColor.YELLOW + Lang.get("inputNum"));
return;
}
}
if (topNumber < 1 || topNumber > plugin.getSettings().getTopLimit()) {
cs.sendMessage(ChatColor.YELLOW + Lang.get("invalidRange").replace("<least>", "1")
.replace("<greatest>", String.valueOf(plugin.getSettings().getTopLimit())));
try {
topNumber = Integer.parseInt(args[1]);
} catch (final NumberFormatException e) {
cs.sendMessage(ChatColor.YELLOW + Lang.get("inputNum"));
return;
}
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
final File folder = new File(plugin.getDataFolder(), "data");
final File[] playerFiles = folder.listFiles();
final Map<String, Integer> questPoints = new HashMap<>();
if (playerFiles != null) {
for (final File f : playerFiles) {
if (!f.isDirectory()) {
final FileConfiguration data = new YamlConfiguration();
try {
data.load(f);
} catch (final IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
questPoints.put(data.getString("lastKnownName", "Unknown"),
data.getInt("quest-points", 0));
}
}
}
final LinkedHashMap<String, Integer> sortedMap = (LinkedHashMap<String, Integer>) sort(questPoints);
int numPrinted = 0;
String msg = Lang.get("topQuestersTitle");
msg = msg.replace("<number>", ChatColor.DARK_PURPLE + "" + topNumber + ChatColor.GOLD);
cs.sendMessage(ChatColor.GOLD + msg);
for (final Map.Entry<String, Integer> entry : sortedMap.entrySet()) {
numPrinted++;
cs.sendMessage(ChatColor.YELLOW + String.valueOf(numPrinted) + ". " + entry.getKey() + " - "
+ ChatColor.DARK_PURPLE + entry.getValue() + ChatColor.YELLOW + " "
+ Lang.get("questPoints"));
if (numPrinted == topNumber) {
break;
}
}
});
}
if (topNumber < 1 || topNumber > plugin.getSettings().getTopLimit()) {
cs.sendMessage(ChatColor.YELLOW + Lang.get("invalidRange").replace("<least>", "1")
.replace("<greatest>", String.valueOf(plugin.getSettings().getTopLimit())));
return;
}
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
final File folder = new File(plugin.getDataFolder(), "data");
final File[] playerFiles = folder.listFiles();
final Map<String, Integer> questPoints = new HashMap<>();
if (playerFiles != null) {
for (final File f : playerFiles) {
if (!f.isDirectory()) {
final FileConfiguration data = new YamlConfiguration();
try {
data.load(f);
} catch (final IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
questPoints.put(data.getString("lastKnownName", "Unknown"),
data.getInt("quest-points", 0));
}
}
}
final LinkedHashMap<String, Integer> sortedMap = (LinkedHashMap<String, Integer>) sort(questPoints);
int numPrinted = 0;
String msg = Lang.get("topQuestersTitle");
msg = msg.replace("<number>", ChatColor.DARK_PURPLE + "" + topNumber + ChatColor.GOLD);
cs.sendMessage(ChatColor.GOLD + msg);
for (final Map.Entry<String, Integer> entry : sortedMap.entrySet()) {
numPrinted++;
cs.sendMessage(ChatColor.YELLOW + String.valueOf(numPrinted) + ". " + entry.getKey() + " - "
+ ChatColor.DARK_PURPLE + entry.getValue() + ChatColor.YELLOW + " "
+ Lang.get("questPoints"));
if (numPrinted == topNumber) {
break;
}
}
});
}
}
}

View File

@ -2,7 +2,6 @@ COMMAND_LIST: "list"
COMMAND_LIST_HELP: "<command> [page] - List available quests"
COMMAND_TAKE: "take"
COMMAND_TAKE_HELP: "<command> [quest] - Accept a quest via command"
COMMAND_TAKE_USAGE: "Usage: /quests take [quest]"
COMMAND_QUIT: "quit"
COMMAND_QUIT_HELP: "<command> [quest] - Quit a current quest"
COMMAND_JOURNAL: "journal"
@ -17,7 +16,6 @@ COMMAND_STATS: "stats"
COMMAND_STATS_HELP: "<command> - View quest statistics"
COMMAND_TOP: "top"
COMMAND_TOP_HELP: "<command> [number] - View plugin leaderboards"
COMMAND_TOP_USAGE: "Usage: /quests top [number]"
COMMAND_INFO: "info"
COMMAND_INFO_HELP: "<command> - View plugin information"
COMMAND_QUEST_HELP: "- View current quest objectives"
@ -43,7 +41,6 @@ COMMAND_QUESTADMIN_NEXTSTAGE: "nextstage"
COMMAND_QUESTADMIN_NEXTSTAGE_HELP: "<command> [player] [quest] - Force a player to complete current stage"
COMMAND_QUESTADMIN_SETSTAGE: "setstage"
COMMAND_QUESTADMIN_SETSTAGE_HELP: "<command> [player] [quest] [stage] - Set the current stage for a player"
COMMAND_QUESTADMIN_SETSTAGE_USAGE: 'Usage: /questadmin setstage [player] [quest] [stage]'
COMMAND_QUESTADMIN_RESET: "reset"
COMMAND_QUESTADMIN_RESET_HELP: "<command> [player] - Clear all questing data of a player"
COMMAND_QUESTADMIN_REMOVE: "remove"