diff options
Diffstat (limited to 'src/main/java/de/cowtipper/cowlection/command/MooCommand.java')
-rw-r--r-- | src/main/java/de/cowtipper/cowlection/command/MooCommand.java | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/command/MooCommand.java b/src/main/java/de/cowtipper/cowlection/command/MooCommand.java index 43a1335..7a67a0d 100644 --- a/src/main/java/de/cowtipper/cowlection/command/MooCommand.java +++ b/src/main/java/de/cowtipper/cowlection/command/MooCommand.java @@ -1060,22 +1060,41 @@ public class MooCommand extends CommandBase { EnumChatFormatting color; EnumChatFormatting colorSecondary; if (CredentialStorage.isMooValid) { - firstSentence = "You already set your Hypixel API key."; + firstSentence = "[" + Cowlection.MODNAME + "] You already set your Hypixel API key. Run " + EnumChatFormatting.DARK_GREEN + "/" + getCommandName() + " apikey check " + EnumChatFormatting.GREEN + "to see usage statistics."; color = EnumChatFormatting.GREEN; colorSecondary = EnumChatFormatting.DARK_GREEN; } else { - firstSentence = "You haven't set your Hypixel API key yet or the API key is invalid."; + firstSentence = "[" + Cowlection.MODNAME + "] You haven't set your Hypixel API key yet or the API key is invalid."; color = EnumChatFormatting.RED; colorSecondary = EnumChatFormatting.DARK_RED; } main.getChatHelper().sendMessage(color, firstSentence + " Use " + colorSecondary + "/api new" + color + " to request a new API key from Hypixel or use " + colorSecondary + "/" + this.getCommandName() + " apikey <key>" + color + " to manually set your existing API key."); } else { String key = args[1]; - if (Utils.isValidUuid(key)) { - main.getChatHelper().sendMessage(EnumChatFormatting.YELLOW, "Validating API key..."); + if ("check".equalsIgnoreCase(key)) { + if (StringUtils.isNotEmpty(CredentialStorage.moo)) { + ApiUtils.fetchApiKeyInfo(CredentialStorage.moo, hyApiKey -> { + if (hyApiKey != null && hyApiKey.isSuccess()) { + HyApiKey.Record apiKeyRecord = hyApiKey.getRecord(); + if (apiKeyRecord != null) { + main.getChatHelper().sendMessage(EnumChatFormatting.GREEN, "[" + Cowlection.MODNAME + "] Your Hypixel API key was used to execute a total of " + EnumChatFormatting.DARK_GREEN + Utils.formatNumber(apiKeyRecord.getTotalQueries()) + + EnumChatFormatting.GREEN + " API requests. In the last minute, " + EnumChatFormatting.DARK_GREEN + apiKeyRecord.getQueriesInPastMin() + EnumChatFormatting.GREEN + " out of maximum " + EnumChatFormatting.DARK_GREEN + apiKeyRecord.getLimit() + EnumChatFormatting.GREEN + " allowed requests were made."); + } else { + main.getChatHelper().sendMessage(EnumChatFormatting.GREEN, "[" + Cowlection.MODNAME + "] Your Hypixel API key seems to be valid, but processing usage statistics failed."); + } + } else { + String cause = hyApiKey != null ? hyApiKey.getCause() : null; + Cowlection.getInstance().getChatHelper().sendMessage(EnumChatFormatting.RED, "[" + Cowlection.MODNAME + "] Failed to check API key usage statistics: " + (cause != null ? cause : "unknown cause :c")); + } + }); + } else { + throw new MooCommandException("You haven't set your Hypixel API key yet. Use " + EnumChatFormatting.DARK_RED + "/api new" + EnumChatFormatting.RED + " to request a new API key from Hypixel or use " + EnumChatFormatting.DARK_RED + "/" + this.getCommandName() + " apikey <key>" + EnumChatFormatting.RED + " to manually set your existing API key."); + } + } else if (Utils.isValidUuid(key)) { + main.getChatHelper().sendMessage(EnumChatFormatting.YELLOW, "[" + Cowlection.MODNAME + "] Validating API key..."); main.getMoo().setMooIfValid(key, true); } else { - throw new SyntaxErrorException("That doesn't look like a valid API key..."); + throw new SyntaxErrorException("[" + Cowlection.MODNAME + "] That doesn't look like a valid API key... Did you want check your API key usage statistics? Run /" + getCommandName() + " apikey check"); } } } @@ -1193,6 +1212,8 @@ public class MooCommand extends CommandBase { return getListOfStringsMatchingLastWord(args, "off", "on", "disable", "enable"); } else if (args.length == 2 && (args[0].equalsIgnoreCase("chestAnalyzer") || args[0].equalsIgnoreCase("chestAnalyser") || args[0].equalsIgnoreCase("analyzeChests") || args[0].equalsIgnoreCase("analyseChests"))) { return getListOfStringsMatchingLastWord(args, "stop"); + } else if (args.length == 2 && args[0].equalsIgnoreCase("apikey")) { + return getListOfStringsMatchingLastWord(args, "check"); } String commandArg = args[0].toLowerCase(); if (args.length == 2 && (commandArg.equals("s") || commandArg.equals("ss") || commandArg.equals("namechangecheck") || commandArg.contains("stalk") || commandArg.contains("askpolitely"))) { // stalk & stalkskyblock + namechangecheck |