From d510bcbfe6d1cd4c41c90e91eda377d7c491c07c Mon Sep 17 00:00:00 2001 From: AlexCai2019 Date: Thu, 16 Feb 2023 03:07:28 +0800 Subject: [PATCH] Release 1.4 Add /lottery and /tool command. Mention the user at lobby channel when get role. Optimize some code. Complete some keys of pom.xml. Translate some JSON keys. --- lang/cn.json | 1 + lang/en.json | 2 + lang/hk.json | 1 + lang/ta.json | 1 + lang/tw.json | 1 + pom.xml | 23 +++- src/main/java/cartoland/Cartoland.java | 11 +- .../java/cartoland/events/ChannelMessage.java | 17 ++- src/main/java/cartoland/events/GetRole.java | 8 +- .../java/cartoland/events/PrivateMessage.java | 2 +- .../events/commands/CommandUsage.java | 28 ++--- .../events/commands/LotteryCommand.java | 7 +- .../events/commands/OneATwoBCommand.java | 6 +- .../events/commands/ToolCommand.java | 115 +++++++++++++----- .../cartoland/mini_games/OneATwoBGame.java | 2 +- .../cartoland/utilities/IDAndEntities.java | 2 +- .../java/cartoland/utilities/JsonHandle.java | 2 +- 17 files changed, 158 insertions(+), 71 deletions(-) diff --git a/lang/cn.json b/lang/cn.json index 4eb0f3e..7ced090 100644 --- a/lang/cn.json +++ b/lang/cn.json @@ -5,6 +5,7 @@ "help.name.cmd": "格式: `/cmd [<命令>]`", "help.name.faq": "格式: `/faq [<问题>]`", "help.name.dtp": "格式: `/dtp [<数据包功能>]`", + "help.name.tool": "格式: `/tool (uuid_string|uuid_array|pack_mcmeta) <参数...>`", "help.name.lang": "格式: `/lang [<代码>]`", "cmd.begin": "`命令: ", "cmd.end": "`", diff --git a/lang/en.json b/lang/en.json index a7db2dd..3853ff7 100644 --- a/lang/en.json +++ b/lang/en.json @@ -7,11 +7,13 @@ "cmd", "faq", "dtp", + "tool", "lang" ], "help.name.cmd": "Syntax: `/cmd []`", "help.name.faq": "Syntax: `/faq []`", "help.name.dtp": "Syntax: `/dtp []`", + "help.name.tool": "Syntax: `/tool (uuid_string|uuid_array|pack_mcmeta) `", "help.name.lang": "Syntax: `/lang []`", "cmd.begin": "`Commands: ", "cmd.end": "`", diff --git a/lang/hk.json b/lang/hk.json index b6f6d53..07e9692 100644 --- a/lang/hk.json +++ b/lang/hk.json @@ -5,6 +5,7 @@ "help.name.cmd": "格式: `/cmd [<指令>]`", "help.name.faq": "格式: `/faq [<問題>]`", "help.name.dtp": "格式: `/dtp [<資料包功能>]`", + "help.name.tool": "格式: `/tool (uuid_string|uuid_array|pack_mcmeta) <引數...>`", "help.name.lang": "格式: `/lang [<代碼>]`", "cmd.begin": "`指令: ", "cmd.end": "`", diff --git a/lang/ta.json b/lang/ta.json index c6cb812..b9f2f16 100644 --- a/lang/ta.json +++ b/lang/ta.json @@ -5,6 +5,7 @@ "help.name.cmd": "格式: `/cmd [<指令>]`", "help.name.faq": "格式: `/faq [<問題>]`", "help.name.dtp": "格式: `/dtp [<資料包功能>]`", + "help.name.tool": "格式: `/tool (uuid_string|uuid_array|pack_mcmeta) <引數...>`", "help.name.lang": "格式: `/lang [<代碼>]`", "cmd.begin": "`指令: ", "cmd.end": "`", diff --git a/lang/tw.json b/lang/tw.json index e6b44d5..d1a2910 100644 --- a/lang/tw.json +++ b/lang/tw.json @@ -5,6 +5,7 @@ "help.name.cmd": "格式: `/cmd [<指令>]`", "help.name.faq": "格式: `/faq [<問題>]`", "help.name.dtp": "格式: `/dtp [<資料包功能>]`", + "help.name.tool": "格式: `/tool (uuid_string|uuid_array|pack_mcmeta) <引數...>`", "help.name.lang": "格式: `/lang [<代碼>]`", "cmd.begin": "指令: `", "cmd.end": "`", diff --git a/pom.xml b/pom.xml index 43d12e8..2b16919 100644 --- a/pom.xml +++ b/pom.xml @@ -6,14 +6,33 @@ org.cartoland Cartoland - 1.0 + 1.4 + + Cartoland Bot + A Discord bot that belongs to a server: Cartoland + https://github.com/AlexCai2019/Cartoland + + + + MIT License + https://github.com/AlexCai2019/Cartoland/blob/master/LICENSE.md + manual + + + + + + Alex Cai + alexcai910630@gmail.com + + net.dv8tion JDA - 5.0.0-beta.2 + 5.0.0-beta.3 diff --git a/src/main/java/cartoland/Cartoland.java b/src/main/java/cartoland/Cartoland.java index 5dd9f99..26850f3 100644 --- a/src/main/java/cartoland/Cartoland.java +++ b/src/main/java/cartoland/Cartoland.java @@ -12,6 +12,7 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData; import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; import net.dv8tion.jda.api.requests.GatewayIntent; +import net.dv8tion.jda.api.utils.MemberCachePolicy; import static cartoland.utilities.IDAndEntities.jda; @@ -37,7 +38,8 @@ public static void main(String[] args) throws InterruptedException new PrivateMessage(), //當有人傳私訊給機器人 new CommandUsage(), //當有人使用指令 new GetRole()) //有人獲得會員身分組 - .enableIntents(GatewayIntent.MESSAGE_CONTENT) + .enableIntents(GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_MEMBERS) + .setMemberCachePolicy(MemberCachePolicy.ALL) .setActivity(Activity.playing("Use /help to check more information")) //正在玩 .build(); @@ -48,6 +50,7 @@ public static void main(String[] args) throws InterruptedException .addChoice("cmd", "cmd") .addChoice("faq", "faq") .addChoice("dtp", "dtp") + .addChoice("tool", "tool") .addChoice("lang", "lang")), Commands.slash("cmd", "Get help of Minecraft commands") .addOption(OptionType.STRING, "cmd_name", "The name of a Minecraft command", false), @@ -73,9 +76,9 @@ public static void main(String[] args) throws InterruptedException .addOption(OptionType.INTEGER, "2", "The [2] of the array", true) .addOption(OptionType.INTEGER, "3", "The [3] of the array", true), new SubcommandData("pack_mcmeta", "Generate a pack.mcmeta") - .addOptions(new OptionData(OptionType.STRING, "pack_type", "Datapack or Resourcepack", true) - .addChoice("Datapack", "d") - .addChoice("Resourcepack", "r"))), + .addOptions(new OptionData(OptionType.STRING, "pack_type", "Data pack or Resource pack", true) + .addChoice("Data pack", "d") + .addChoice("Resource pack", "r"))), Commands.slash("lang", "Change language or check current languages") .addOption(OptionType.STRING, "lang_name", "The language that user want to change", false), Commands.slash("language", "Change language or check current languages") diff --git a/src/main/java/cartoland/events/ChannelMessage.java b/src/main/java/cartoland/events/ChannelMessage.java index 7194394..a424182 100644 --- a/src/main/java/cartoland/events/ChannelMessage.java +++ b/src/main/java/cartoland/events/ChannelMessage.java @@ -12,6 +12,8 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.jetbrains.annotations.NotNull; +import java.util.regex.Pattern; + /** * {@code ChannelMessage} is a listener that triggers when a user types anything in any channel that the bot can * access. This class was registered in {@link cartoland.Cartoland#main}, with the build of JDA. @@ -58,7 +60,10 @@ public class ChannelMessage extends ListenerAdapter "☆めぐみんは最高だ!☆", "☆めぐみん俺の嫁!☆" }; - private final MentionType[] botType = { MentionType.USER, MentionType.ROLE }; + + private static final MentionType[] BOT_TYPE = { MentionType.USER, MentionType.ROLE }; + + private static final Pattern MEGUMIN = Pattern.compile("(?i).*megumin.*"); /** * The method that inherited from {@link ListenerAdapter}, triggers when receive a message from any @@ -73,7 +78,7 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) if (!event.isFromType(ChannelType.TEXT)) //不是文字頻道 return; User author = event.getAuthor(); - if (author.isBot()) //傳訊息的是機器人 + if (author.isBot() || author.isSystem()) //傳訊息的是機器人或系統 return; //不用執行 long userID = author.getIdLong(); @@ -85,12 +90,12 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) long categoryID = category.getIdLong(); TextChannel channel = (TextChannel) message.getChannel(); - if (message.getMentions().isMentioned(IDAndEntities.botItself, botType)) //有人tag機器人 - message.reply(userID == IDAndEntities.AC_ID ? replyACMention[IDAndEntities.random.nextInt(replyACMention.length)] : replyMention[IDAndEntities.random.nextInt(replyMention.length)]) + if (message.getMentions().isMentioned(IDAndEntities.botItself, BOT_TYPE)) //有人tag機器人 + message.reply(userID == IDAndEntities.AC_ID ? replyACMention[IDAndEntities.RANDOM.nextInt(replyACMention.length)] : replyMention[IDAndEntities.RANDOM.nextInt(replyMention.length)]) .mentionRepliedUser(false).queue(); - if (rawMessage.matches("(?i).*megumin.*") || rawMessage.contains("惠惠") || rawMessage.contains("めぐみん")) - channel.sendMessage(megumin[IDAndEntities.random.nextInt(megumin.length)]).queue(); + if (MEGUMIN.matcher(rawMessage).matches() || rawMessage.contains("惠惠") || rawMessage.contains("めぐみん")) + channel.sendMessage(megumin[IDAndEntities.RANDOM.nextInt(megumin.length)]).queue(); if (rawMessage.contains("早安")) channel.sendMessage("早上好中國 現在我有Bing Chilling").queue(); diff --git a/src/main/java/cartoland/events/GetRole.java b/src/main/java/cartoland/events/GetRole.java index a08745e..60fea41 100644 --- a/src/main/java/cartoland/events/GetRole.java +++ b/src/main/java/cartoland/events/GetRole.java @@ -18,6 +18,12 @@ public class GetRole extends ListenerAdapter public void onGuildMemberRoleAdd(@NotNull GuildMemberRoleAddEvent event) { if (event.getRoles().contains(IDAndEntities.memberRole)) - IDAndEntities.lobbyChannel.sendMessage("歡迎 " + event.getUser().getAsTag() + " 加入 " + IDAndEntities.cartolandServer.getName()).queue(); + { + String mentionUser = event.getUser().getAsMention(); + String serverName = IDAndEntities.cartolandServer.getName(); + + IDAndEntities.lobbyChannel.sendMessage("歡迎 " + mentionUser + " 加入 " + serverName + + "\n" + mentionUser + ", welcome to " + serverName).queue(); + } } } \ No newline at end of file diff --git a/src/main/java/cartoland/events/PrivateMessage.java b/src/main/java/cartoland/events/PrivateMessage.java index c35d8b6..19bb746 100644 --- a/src/main/java/cartoland/events/PrivateMessage.java +++ b/src/main/java/cartoland/events/PrivateMessage.java @@ -26,7 +26,7 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) if (!event.isFromType(ChannelType.PRIVATE)) //不是私訊 return; User author = event.getAuthor(); - if (author.isBot()) //是機器人 + if (author.isBot() || author.isSystem()) //是機器人或系統 return; Message message = event.getMessage(); diff --git a/src/main/java/cartoland/events/commands/CommandUsage.java b/src/main/java/cartoland/events/commands/CommandUsage.java index 352b56b..99aaab3 100644 --- a/src/main/java/cartoland/events/commands/CommandUsage.java +++ b/src/main/java/cartoland/events/commands/CommandUsage.java @@ -12,7 +12,6 @@ import java.util.HashMap; import java.util.stream.Collectors; -import java.util.stream.Stream; /** * {@code CommandUsage} is a listener that triggers when a user uses slash command. This class was registered in @@ -42,7 +41,6 @@ public class CommandUsage extends ListenerAdapter */ String commandName; String subCommandName; - Stream optionsStream; /** * 356 images about Megumin. @@ -61,33 +59,33 @@ public CommandUsage() commands.put("invite", event -> event.reply("https://discord.gg/UMYxwHyRNE").queue()); //help - commands.put("help", event -> event.reply(minecraftCommandRelated("help")).queue()); + commands.put("help", event -> event.reply(minecraftCommandRelated("help", event)).queue()); //cmd - alias = event -> event.reply(minecraftCommandRelated("cmd")).queue(); + alias = event -> event.reply(minecraftCommandRelated("cmd", event)).queue(); commands.put("cmd", alias); commands.put("mcc", alias); commands.put("command", alias); //faq - alias = event -> event.reply(minecraftCommandRelated("faq")).queue(); + alias = event -> event.reply(minecraftCommandRelated("faq", event)).queue(); commands.put("faq", alias); commands.put("question", alias); //dtp - alias = event -> event.reply(minecraftCommandRelated("dtp")).queue(); + alias = event -> event.reply(minecraftCommandRelated("dtp", event)).queue(); commands.put("dtp", alias); commands.put("datapack", alias); //lang - alias = event -> event.reply(minecraftCommandRelated("lang")).queue(); + alias = event -> event.reply(minecraftCommandRelated("lang", event)).queue(); commands.put("lang", alias); commands.put("language", alias); commands.put("megumin", event -> { - TA author = twitterAuthors[IDAndEntities.random.nextInt(twitterAuthors.length)]; - long artwork = author.artworks()[IDAndEntities.random.nextInt(author.artworks().length)]; + TA author = twitterAuthors[IDAndEntities.RANDOM.nextInt(twitterAuthors.length)]; + long artwork = author.artworks()[IDAndEntities.RANDOM.nextInt(author.artworks().length)]; event.reply("https://twitter.com/" + author.name() + "/status/" + artwork).queue(); FileHandle.log(userName + "(" + userID + ") used /megumin."); }); //隨機一張惠惠 @@ -127,11 +125,12 @@ public CommandUsage() commands.put("lottery", new LotteryCommand(this)); //tool - commands.put("tool", new ToolCommand(this)); + commands.put("tool", new ToolCommand()); } /** * The method that inherited from {@link ListenerAdapter}, triggers when a user uses slash command. + * * @param event The event that carries information of the user and the command. */ @Override @@ -142,19 +141,18 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent even userName = user.getName(); commandName = event.getName(); subCommandName = event.getSubcommandName(); - optionsStream = event.getOptions().stream(); FileHandle.log(userName + "(" + userID + ") used /" + commandName + (subCommandName != null ? " " + subCommandName + " " : " ") + - optionsStream.map(String::valueOf).collect(Collectors.joining(" ", " ", ""))); + event.getOptions().stream().map(OptionMapping::getName).collect(Collectors.joining(" "))); commands.get(commandName).commandProcess(event); } - private String minecraftCommandRelated(String jsonKey) + private String minecraftCommandRelated(String jsonKey, SlashCommandInteractionEvent event) { - OptionMapping argument = optionsStream.filter(optionMapping -> optionMapping.getName().equals(jsonKey + "_name")).findAny().orElse(null); //獲得參數 + String argument = event.getOption(jsonKey + "_name", OptionMapping::getAsString); //獲得參數 if (argument == null) //沒有參數 return JsonHandle.command(userID, jsonKey); - return JsonHandle.command(userID, jsonKey, argument.getAsString()); + return JsonHandle.command(userID, jsonKey, argument); } } diff --git a/src/main/java/cartoland/events/commands/LotteryCommand.java b/src/main/java/cartoland/events/commands/LotteryCommand.java index b38a498..0a77d3d 100644 --- a/src/main/java/cartoland/events/commands/LotteryCommand.java +++ b/src/main/java/cartoland/events/commands/LotteryCommand.java @@ -25,15 +25,14 @@ public class LotteryCommand implements ICommand public void commandProcess(SlashCommandInteractionEvent event) { long nowHave = JsonHandle.getCommandBlocks(commandCore.userID); - OptionMapping argument = commandCore.optionsStream.filter(optionMapping -> optionMapping.getName().equals("bet")).findAny().orElse(null); + String betString = event.getOption("bet", OptionMapping::getAsString); - if (argument == null) //不帶參數 + if (betString == null) //不帶參數 { event.reply(JsonHandle.getJsonKey(commandCore.userID, "lottery.query").formatted(nowHave)).queue(); return; } - String betString = argument.getAsString(); long bet; if (betString.matches("\\d+")) //賭數字 @@ -62,7 +61,7 @@ else if (betString.matches("\\d+%")) //賭%數 long afterBet; String result; - if (IDAndEntities.random.nextBoolean()) //賭贏 + if (IDAndEntities.RANDOM.nextBoolean()) //賭贏 { afterBet = nowHave + bet; if (afterBet < 0) diff --git a/src/main/java/cartoland/events/commands/OneATwoBCommand.java b/src/main/java/cartoland/events/commands/OneATwoBCommand.java index 70feb25..3063ff8 100644 --- a/src/main/java/cartoland/events/commands/OneATwoBCommand.java +++ b/src/main/java/cartoland/events/commands/OneATwoBCommand.java @@ -64,7 +64,7 @@ public void commandProcess(@NotNull SlashCommandInteractionEvent event) default -> argument + " = " + ab / 10 + " A " + ab % 10 + " B"; }; - if (ab / 10 == OneATwoBGame.ANSWER_LENGTH)//沒有猜出ANSWER_LENGTH個A 遊戲繼續 + if (ab / 10 != OneATwoBGame.ANSWER_LENGTH)//沒有猜出ANSWER_LENGTH個A 遊戲繼續 { event.reply(shouldReply).queue(); return; @@ -73,8 +73,8 @@ public void commandProcess(@NotNull SlashCommandInteractionEvent event) //猜出ANSWER_LENGTH個A 遊戲結束 long second = oneATwoB.getTimePassed(); event.reply(shouldReply + "\nGame Over, the answer is **" + argument + "**.\n" + - "Used Time: " + second / 60 + " minutes " + second % 60 + " seconds.\n" + - "Guesses: " + oneATwoB.getGuesses() + " times.").queue(); + "Used Time: " + second / 60 + " minutes " + second % 60 + " seconds\n" + + "Guesses: " + oneATwoB.getGuesses() + " times").queue(); commandCore.games.remove(commandCore.userID); } } \ No newline at end of file diff --git a/src/main/java/cartoland/events/commands/ToolCommand.java b/src/main/java/cartoland/events/commands/ToolCommand.java index bf37ed3..ecc7095 100644 --- a/src/main/java/cartoland/events/commands/ToolCommand.java +++ b/src/main/java/cartoland/events/commands/ToolCommand.java @@ -17,10 +17,11 @@ public class ToolCommand implements ICommand { private final HashMap subCommands = new HashMap<>(); - ToolCommand(CommandUsage commandCore) + ToolCommand() { - subCommands.put("uuid_string", new ToolUUIDStringCommand(commandCore)); //tool uuid_string - subCommands.put("uuid_array", new ToolUUIDArrayCommand(commandCore)); //tool uuid_array + subCommands.put("uuid_string", new UUIDStringCommand()); //tool uuid_string + subCommands.put("uuid_array", new UUIDArrayCommand()); //tool uuid_array + subCommands.put("pack_mcmeta", new PackMcmetaCommand()); //tool pack_mcmeta } @Override @@ -29,7 +30,7 @@ public void commandProcess(SlashCommandInteractionEvent event) String subCommandName = event.getSubcommandName(); if (subCommandName == null) { - event.reply("Wait, this is impossible!").queue(); + event.reply("Impossible, this is required!").queue(); return; } @@ -45,47 +46,43 @@ public void commandProcess(SlashCommandInteractionEvent event) * * @since 1.4 * @see ToolCommand - * @see ToolUUIDArrayCommand + * @see UUIDArrayCommand * @author Alex Cai */ -record ToolUUIDStringCommand(CommandUsage commandCore) implements ICommand +class UUIDStringCommand implements ICommand { @Override public void commandProcess(SlashCommandInteractionEvent event) { - //不是沒想過和下面一樣直接靠ifPresent - //但是Java要求一定要用1格的String陣列 - //很難看 - OptionMapping argument = commandCore.optionsStream - .filter(optionMapping -> optionMapping.getName().equals("raw_uuid")) - .findAny() - .orElse(null); - - //雖然不檢查是否null也可以 - //反正這是必填項 - //但是IntelliJ IDEA會標註這裡可能會擲出NullPointerException - //看了心情就煩躁 - if (argument == null) + String rawUUID = event.getOption("raw_uuid", OptionMapping::getAsString); + if (rawUUID == null) { - event.reply("Wait, the option is required!").queue(); + event.reply("Impossible, this is required!").queue(); return; } - String rawUUID = argument.getAsString(); String[] uuidStrings; + String dash = rawUUID; + String noDash = rawUUID; //59c1027b-5559-4e6a-91e4-2b8b949656ce if (rawUUID.matches("[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}")) + { uuidStrings = rawUUID.split("-"); + noDash = String.join("", uuidStrings); + } else if (rawUUID.matches("[0-9A-Fa-f]{32}")) //59c1027b55594e6a91e42b8b949656ce + { uuidStrings = new String[] { - rawUUID.substring(0, 8), //8個 + rawUUID.substring(0, 8), //8 rawUUID.substring(8, 12), //4 rawUUID.substring(12, 16), //4 rawUUID.substring(16, 20), //4 rawUUID.substring(20) //12 }; + dash = String.join("-", uuidStrings); + } else //不是一個合法的UUID字串 { event.reply("Please enter a UUID string by right format!").queue(); @@ -100,8 +97,8 @@ else if (rawUUID.matches("[0-9A-Fa-f]{32}")) //59c1027b55594e6a91e42b8b949656ce (int) Long.parseLong(uuidStrings[4].substring(4), 16) }; - event.reply("UUID: `" + String.join("-", uuidStrings) + "`\n" + - "UUID(without dash): `" + String.join("", uuidStrings) + "`\n" + + event.reply("UUID: `" + dash + "`\n" + + "UUID(without dash): `" + noDash + "`\n" + "UUID array: `" + Arrays.toString(uuidArray) + "`").queue(); } } @@ -112,22 +109,23 @@ else if (rawUUID.matches("[0-9A-Fa-f]{32}")) //59c1027b55594e6a91e42b8b949656ce * * @since 1.4 * @see ToolCommand - * @see ToolUUIDStringCommand + * @see UUIDStringCommand * @author Alex Cai */ -record ToolUUIDArrayCommand(CommandUsage commandCore) implements ICommand +class UUIDArrayCommand implements ICommand { @Override public void commandProcess(SlashCommandInteractionEvent event) { - int[] uuidArray = new int[4]; + Integer[] uuidArray = new Integer[4]; for (int i = 0; i < 4; i++) { - int finalI = i; - commandCore.optionsStream - .filter(optionMapping -> optionMapping.getName().equals(String.valueOf(finalI))) - .findAny() - .ifPresent(optionMapping -> uuidArray[finalI] = optionMapping.getAsInt()); + uuidArray[i] = event.getOption(String.valueOf(i), OptionMapping::getAsInt); + if (uuidArray[i] == null) + { + event.reply("Impossible, this is required!").queue(); + return; + } } //因為四個UUID是必填項 所以不須偵測是否存在 直接進程式 @@ -145,4 +143,57 @@ public void commandProcess(SlashCommandInteractionEvent event) "UUID(without dash): `" + String.join("", uuidStrings) + "`\n" + "UUID array: `" + Arrays.toString(uuidArray) + "`").queue(); } +} + +/** + * {@code PackMcmetaCommand} is a class that handles one of the sub commands of {@code /tool} command, which is + * {@code /tool pack_mcmeta}. + * + * @since 1.4 + * @see ToolCommand + * @author Alex Cai + */ +class PackMcmetaCommand implements ICommand +{ + @Override + public void commandProcess(SlashCommandInteractionEvent event) + { + String packType = event.getOption("pack_type", OptionMapping::getAsString); + if (packType == null) + { + event.reply("Impossible, this is required!").queue(); + return; + } + + event.reply(switch (packType.charAt(0)) + { + case 'd' -> + """ + ```json + { + "pack": + { + "pack_format": 10, + "description": "Your description here" + } + } + ``` + """; + + case 'r' -> + """ + ```json + { + "pack": + { + "pack_format": 12, + "description": "Your description here" + } + } + ``` + """; + + default -> "You need to choose whether data pack or resource pack."; + }).queue(); + } } \ No newline at end of file diff --git a/src/main/java/cartoland/mini_games/OneATwoBGame.java b/src/main/java/cartoland/mini_games/OneATwoBGame.java index a308c44..686b95d 100644 --- a/src/main/java/cartoland/mini_games/OneATwoBGame.java +++ b/src/main/java/cartoland/mini_games/OneATwoBGame.java @@ -42,7 +42,7 @@ private void shuffleZeroToNine() { for (int i = 0, destIndex, temp; i < 9; i++) //到8為止 因為第9項沒必要交換 { - destIndex = IDAndEntities.random.nextInt(10 - i) + i; //0會得到0~9 1會得到1~9 2會得到2~9 + destIndex = IDAndEntities.RANDOM.nextInt(10 - i) + i; //0會得到0~9 1會得到1~9 2會得到2~9 //交換 temp = zeroToNine[destIndex]; zeroToNine[destIndex] = zeroToNine[i]; diff --git a/src/main/java/cartoland/utilities/IDAndEntities.java b/src/main/java/cartoland/utilities/IDAndEntities.java index bfe1a83..6a0e31a 100644 --- a/src/main/java/cartoland/utilities/IDAndEntities.java +++ b/src/main/java/cartoland/utilities/IDAndEntities.java @@ -35,7 +35,7 @@ private IDAndEntities() {} public static Role memberRole; public static User botItself; - public static Random random = new Random(); + public static final Random RANDOM = new Random(); /** * Language constants. Can not be initial. diff --git a/src/main/java/cartoland/utilities/JsonHandle.java b/src/main/java/cartoland/utilities/JsonHandle.java index 78eb391..4c5e093 100644 --- a/src/main/java/cartoland/utilities/JsonHandle.java +++ b/src/main/java/cartoland/utilities/JsonHandle.java @@ -105,7 +105,7 @@ public static void addCommandBlocks(long userID, long add) { long level = commandBlocksFile.getLong(userIDString); level += add; - commandBlocksFile.put(userIDString, level > 0 ? level : Long.MAX_VALUE); //避免溢位 + commandBlocksFile.put(userIDString, level >= 0 ? level : Long.MAX_VALUE); //避免溢位 } else commandBlocksFile.put(userIDString, add);