From c1a04fe5bf8b0033713d825aa28b63b73586c4e5 Mon Sep 17 00:00:00 2001 From: BruceChen Date: Fri, 7 Oct 2022 21:49:05 +0800 Subject: [PATCH] Bug fix --- MinecraftClient/ChatBots/AutoAttack.cs | 2 +- MinecraftClient/ChatBots/AutoCraft.cs | 9 ++++++--- MinecraftClient/ChatBots/AutoRelog.cs | 11 +++++------ MinecraftClient/ChatBots/Map.cs | 1 - MinecraftClient/Commands/Chunk.cs | 17 ++++++++--------- MinecraftClient/Program.cs | 1 - MinecraftClient/Protocol/Handlers/Protocol18.cs | 1 + MinecraftClient/Resources/lang/en.ini | 6 ++++++ MinecraftClient/Resources/lang/zh-Hans.ini | 6 ++++++ MinecraftClient/Resources/lang/zh-Hant.ini | 6 ++++++ MinecraftClient/Translations.cs | 14 +++++++++++++- README.md | 10 +++++----- 12 files changed, 57 insertions(+), 27 deletions(-) diff --git a/MinecraftClient/ChatBots/AutoAttack.cs b/MinecraftClient/ChatBots/AutoAttack.cs index ab5a6b64..dcd73349 100644 --- a/MinecraftClient/ChatBots/AutoAttack.cs +++ b/MinecraftClient/ChatBots/AutoAttack.cs @@ -39,7 +39,7 @@ namespace MinecraftClient.ChatBots public bool Attack_Passive = false; [TomlInlineComment("$config.ChatBot.AutoAttack.List_Mode$")] - public ListType List_Mode = ListType.blacklist; + public ListType List_Mode = ListType.whitelist; [TomlInlineComment("$config.ChatBot.AutoAttack.Entites_List$")] public List Entites_List = new() { EntityType.Zombie, EntityType.Cow }; diff --git a/MinecraftClient/ChatBots/AutoCraft.cs b/MinecraftClient/ChatBots/AutoCraft.cs index c2128ad5..d463b024 100644 --- a/MinecraftClient/ChatBots/AutoCraft.cs +++ b/MinecraftClient/ChatBots/AutoCraft.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; using MinecraftClient.Inventory; using MinecraftClient.Mapping; using Tomlet.Attributes; @@ -298,8 +299,10 @@ namespace MinecraftClient.ChatBots switch (args[0]) { case "list": - string names = string.Join(", ", Config.Recipes.ToList()); - return Translations.Get("bot.autoCraft.cmd.list", Config.Recipes.Length, names); + StringBuilder nameList = new(); + foreach (RecipeConfig recipe in Config.Recipes) + nameList.Append(recipe.Name).Append(", "); + return Translations.Get("bot.autoCraft.cmd.list", Config.Recipes.Length, nameList.ToString()); case "start": if (args.Length >= 2) { @@ -435,7 +438,7 @@ namespace MinecraftClient.ChatBots Dictionary materials = new(); for (int i = 0; i < recipeConfig.Slots.Length; ++i) if (recipeConfig.Slots[i] != ItemType.Null) - materials[i] = recipeConfig.Slots[i]; + materials[i + 1] = recipeConfig.Slots[i]; ItemType ResultItem = recipeConfig.Result; diff --git a/MinecraftClient/ChatBots/AutoRelog.cs b/MinecraftClient/ChatBots/AutoRelog.cs index 71f078ca..071873ce 100644 --- a/MinecraftClient/ChatBots/AutoRelog.cs +++ b/MinecraftClient/ChatBots/AutoRelog.cs @@ -31,7 +31,7 @@ namespace MinecraftClient.ChatBots public string[] Kick_Messages = new string[] { "Connection has been lost", "Server is restarting", "Server is full", "Too Many people" }; [NonSerialized] - public int _DelayMin, _DelayMax; + public static int _BotRecoAttempts = 0; public void OnSettingUpdate() { @@ -43,9 +43,6 @@ namespace MinecraftClient.ChatBots if (Delay.min > Delay.max) (Delay.min, Delay.max) = (Delay.max, Delay.min); - - _DelayMin = (int)Math.Round(Delay.min * 10); - _DelayMax = (int)Math.Round(Delay.max * 10); if (Retries == -1) Retries = int.MaxValue; @@ -100,7 +97,7 @@ namespace MinecraftClient.ChatBots { LogDebugToConsoleTranslated("bot.autoRelog.ignore_user_logout"); } - else + else if (Config.Retries < 0 || Configs._BotRecoAttempts < Config.Retries) { message = GetVerbatim(message); string comp = message.ToLower(); @@ -109,6 +106,7 @@ namespace MinecraftClient.ChatBots if (Config.Ignore_Kick_Message) { + Configs._BotRecoAttempts++; LaunchDelayedReconnection(null); return true; } @@ -117,6 +115,7 @@ namespace MinecraftClient.ChatBots { if (comp.Contains(msg)) { + Configs._BotRecoAttempts++; LaunchDelayedReconnection(msg); return true; } @@ -130,7 +129,7 @@ namespace MinecraftClient.ChatBots private void LaunchDelayedReconnection(string? msg) { - int delay = random.Next(Config._DelayMin, Config._DelayMax); + int delay = random.Next((int)Config.Delay.min, (int)Config.Delay.max); LogDebugToConsoleTranslated(String.IsNullOrEmpty(msg) ? "bot.autoRelog.reconnect_always" : "bot.autoRelog.reconnect", msg); LogToConsoleTranslated("bot.autoRelog.wait", delay); System.Threading.Thread.Sleep(delay * 1000); diff --git a/MinecraftClient/ChatBots/Map.cs b/MinecraftClient/ChatBots/Map.cs index 299c48a6..c589b6b6 100644 --- a/MinecraftClient/ChatBots/Map.cs +++ b/MinecraftClient/ChatBots/Map.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Drawing; using System.Globalization; using System.IO; -using System.Runtime.InteropServices; using System.Runtime.Versioning; using MinecraftClient.Mapping; using MinecraftClient.Protocol.Handlers; diff --git a/MinecraftClient/Commands/Chunk.cs b/MinecraftClient/Commands/Chunk.cs index 5e793152..8d606e25 100644 --- a/MinecraftClient/Commands/Chunk.cs +++ b/MinecraftClient/Commands/Chunk.cs @@ -32,16 +32,16 @@ namespace MinecraftClient.Commands sb.Append(World.GetChunkLoadingStatus(handler.GetWorld())); sb.Append('\n'); - sb.Append(String.Format("Current location:{0}, chunk: ({1}, {2}).\n", current, current.ChunkX, current.ChunkZ)); + sb.AppendLine(Translations.Get("cmd.chunk.current", current, current.ChunkX, current.ChunkZ)); if (markedChunkPos != null) { - sb.Append("Marked location: "); + sb.Append(Translations.Get("cmd.chunk.marked")); if (args.Length == 1 + 3) sb.Append(String.Format("X:{0:0.00} Y:{1:0.00} Z:{2:0.00}, ", double.Parse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture), double.Parse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture), double.Parse(args[3], NumberStyles.Any, CultureInfo.CurrentCulture))); - sb.Append(String.Format("chunk: ({0}, {1}).\n", markChunkX, markChunkZ)); + sb.AppendLine(Translations.Get("cmd.chunk.chunk_pos", markChunkX, markChunkZ));; } int consoleHeight = Math.Max(Console.BufferHeight - 2, 25); @@ -127,7 +127,7 @@ namespace MinecraftClient.Commands if (markedChunkPos != null && (((Math.Max(bottomMost, markChunkZ) - Math.Min(topMost, markChunkZ) + 1) > consoleHeight) || ((Math.Max(rightMost, markChunkX) - Math.Min(leftMost, markChunkX) + 1) > consoleWidth))) - sb.Append("§x§0Since the marked chunk is outside the graph, it will not be displayed!§r\n"); + sb.AppendLine(Translations.Get("cmd.chunk.outside")); else { topMost = Math.Min(topMost, markChunkZ); @@ -165,8 +165,7 @@ namespace MinecraftClient.Commands sb.Append('\n'); } - sb.Append("Player:§z §r, MarkedChunk:§w §r, "); - sb.Append(string.Format("NotReceived:{0}, Loading:{1}, Loaded:{2}", chunkStatusStr[0], chunkStatusStr[1], chunkStatusStr[2])); + sb.AppendLine(Translations.Get("cmd.chunk.icon", "§z §r", "§w §r", chunkStatusStr[0], chunkStatusStr[1], chunkStatusStr[2])); return sb.ToString(); } else if (args[0] == "setloading") // For debugging @@ -174,7 +173,7 @@ namespace MinecraftClient.Commands Tuple? chunkPos = ParseChunkPos(args); if (chunkPos != null) { - handler.Log.Info("§x§0This command is used for debugging, make sure you know what you are doing.§r"); + handler.Log.Info(Translations.Get("cmd.chunk.for_debug")); World world = handler.GetWorld(); (int chunkX, int chunkZ) = chunkPos; ChunkColumn? chunkColumn = world[chunkX, chunkZ]; @@ -191,7 +190,7 @@ namespace MinecraftClient.Commands Tuple? chunkPos = ParseChunkPos(args); if (chunkPos != null) { - handler.Log.Info("§x§0This command is used for debugging, make sure you know what you are doing.§r"); + handler.Log.Info(Translations.Get("cmd.chunk.for_debug")); World world = handler.GetWorld(); (int chunkX, int chunkZ) = chunkPos; ChunkColumn? chunkColumn = world[chunkX, chunkZ]; @@ -208,7 +207,7 @@ namespace MinecraftClient.Commands Tuple? chunkPos = ParseChunkPos(args); if (chunkPos != null) { - handler.Log.Info("§x§0This command is used for debugging, make sure you know what you are doing.§r"); + handler.Log.Info(Translations.Get("cmd.chunk.for_debug")); World world = handler.GetWorld(); (int chunkX, int chunkZ) = chunkPos; world[chunkX, chunkZ] = null; diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 211b4acc..7cda97c9 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -5,7 +5,6 @@ using System.IO; using System.Linq; using System.Net.Http; using System.Reflection; -using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading; diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 78868cbb..86fd1b86 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -243,6 +243,7 @@ namespace MinecraftClient.Protocol.Handlers } catch (ObjectDisposedException) { } catch (OperationCanceledException) { } + catch (NullReferenceException) { } if (cancelToken.IsCancellationRequested) return; diff --git a/MinecraftClient/Resources/lang/en.ini b/MinecraftClient/Resources/lang/en.ini index 0d006ad3..2113581a 100644 --- a/MinecraftClient/Resources/lang/en.ini +++ b/MinecraftClient/Resources/lang/en.ini @@ -237,6 +237,12 @@ cmd.changeSlot.fail=Could not change slot # Chunk cmd.chunk.desc=Displays the chunk loading status.\nChange EnableEmoji=false in the settings if the display is confusing. +cmd.chunk.current=Current location:{0}, chunk: ({1}, {2}). +cmd.chunk.marked=Marked location: +cmd.chunk.chunk_pos=chunk: ({0}, {1}). +cmd.chunk.outside=§x§0Since the marked chunk is outside the graph, it will not be displayed!§r +cmd.chunk.icon=Player:{0}, MarkedChunk:{1}, NotReceived:{2}, Loading:{3}, Loaded:{4} +cmd.chunk.for_debug=§x§0This command is used for debugging, make sure you know what you are doing.§r # Connect cmd.connect.desc=connect to the specified server. diff --git a/MinecraftClient/Resources/lang/zh-Hans.ini b/MinecraftClient/Resources/lang/zh-Hans.ini index c04965d1..7f1f7a4b 100644 --- a/MinecraftClient/Resources/lang/zh-Hans.ini +++ b/MinecraftClient/Resources/lang/zh-Hans.ini @@ -237,6 +237,12 @@ cmd.changeSlot.fail=无法变更栏位 # Chunk cmd.chunk.desc=显示区块加载状态。\n如果显示错乱竟在设置中更改 EnableEmoji=false 。 +cmd.chunk.current=当前位置:{0},所在区块:({1}, {2})。 +cmd.chunk.marked=标记的位置: +cmd.chunk.chunk_pos=区块:({0}, {1})。 +cmd.chunk.outside=§x§0由于被标记的区块距离玩家太远,它不会被显示在图中§r +cmd.chunk.icon=玩家:{0},标记的区块:{1},未收到:{2},加载中:{3},已加载:{4} +cmd.chunk.for_debug=§x§0此命令仅用于调试使用,确保你已经了解执行该命令会造成的影响。§r # Connect cmd.connect.desc=连接到指定的服务器。 diff --git a/MinecraftClient/Resources/lang/zh-Hant.ini b/MinecraftClient/Resources/lang/zh-Hant.ini index 9b53ae72..3b2ebb94 100644 --- a/MinecraftClient/Resources/lang/zh-Hant.ini +++ b/MinecraftClient/Resources/lang/zh-Hant.ini @@ -237,6 +237,12 @@ cmd.changeSlot.fail=無法變更欄位 # Chunk cmd.chunk.desc=顯示區塊載入狀態。\n如果顯示錯亂竟在設定中更改 EnableEmoji=false 。 +cmd.chunk.current=當前位置:{0},所在區塊:({1}, {2})。 +cmd.chunk.marked=標記的位置: +cmd.chunk.chunk_pos=區塊:({0}, {1})。 +cmd.chunk.outside=§x§0由於被標記的區塊距離玩家太遠,它不會被顯示在圖中§r +cmd.chunk.icon=玩家:{0},標記的區塊:{1},未收到:{2},載入中:{3},已載入:{4} +cmd.chunk.for_debug=§x§0此命令僅用於除錯使用,確保你已經瞭解執行該命令會造成的影響。§r # Connect cmd.connect.desc=連線到指定的伺服器。 diff --git a/MinecraftClient/Translations.cs b/MinecraftClient/Translations.cs index e6ee6628..b4a81024 100644 --- a/MinecraftClient/Translations.cs +++ b/MinecraftClient/Translations.cs @@ -15,7 +15,7 @@ namespace MinecraftClient /// public static class Translations { - private static readonly Dictionary translations = new(); + private static Dictionary translations; private static readonly string translationFilePath = "lang" + Path.DirectorySeparatorChar + "mcc"; private static readonly Regex translationKeyRegex = new(@"\(\[(.*?)\]\)", RegexOptions.Compiled); // Extract string inside ([ ]) @@ -89,6 +89,16 @@ namespace MinecraftClient return Get(m.Groups[1].Value); } + /// + /// Initialize translations depending on system language. + /// English is the default for all unknown system languages. + /// + static Translations() + { + string[] engLang = DefaultConfigResource.Translation_en.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); // use embedded translations + translations = ParseTranslationContent(engLang); + } + public static Tuple GetTranslationPriority() { string gameLanguage = "en_gb"; @@ -579,6 +589,8 @@ namespace MinecraftClient /// public static void LoadTranslationFile(string[] languageList) { + translations = new(); + /* * External translation files * These files are loaded from the installation directory as: diff --git a/README.md b/README.md index d70d0414..d5a5bd5b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [Documentation](https://mccteam.github.io/) | [Download](#download) | [Installation](https://mccteam.github.io/guide/installation.html) | [Configuration](https://mccteam.github.io/guide/configuration.html) | [Usage](https://mccteam.github.io/guide/usage.html) -[English](https://github.com/MCCTeam/Minecraft-Console-Client/blob/master/README.md) | [Nederlands](https://github.com/MCCTeam/Minecraft-Console-Client/blob/master/README-nl.md) | [Türkçe](https://github.com/MCCTeam/Minecraft-Console-Client/blob/master/README-tr.md) | [Tiếng Việt](https://github.com/MCCTeam/Minecraft-Console-Client/blob/master/README-vi-vn.md) | [简体中文](https://github.com/MCCTeam/Minecraft-Console-Client/blob/master/README-zh-Hans.md) +[English](https://github.com/MCCTeam/Minecraft-Console-Client/blob/master/README.md) | [Nederlands](https://github.com/MCCTeam/Minecraft-Console-Client/blob/master/README-nl.md) | [Српски](https://github.com/MCCTeam/Minecraft-Console-Client/blob/master/README-sr.md) | [Türkçe](https://github.com/MCCTeam/Minecraft-Console-Client/blob/master/README-tr.md) | [Tiếng Việt](https://github.com/MCCTeam/Minecraft-Console-Client/blob/master/README-vi-vn.md) | [简体中文](https://github.com/MCCTeam/Minecraft-Console-Client/blob/master/README-zh-Hans.md) [![GitHub Actions build status](https://github.com/MCCTeam/Minecraft-Console-Client/actions/workflows/build-and-release.yml/badge.svg)](https://github.com/MCCTeam/Minecraft-Console-Client/releases/latest) Discord server @@ -50,11 +50,11 @@ If you'd like to contribute to Minecraft Console Client, great, just fork the re Check out: [How to update or add translations for MCC](https://mccteam.github.io/guide/contibuting.html#translations). MCC now supports the following languages (Alphabetical order) : - * `de.ini` (57.30% translated) : Deutsch - German + * `de.ini` (57.12% translated) : Deutsch - German * `en.ini` : English - English - * `fr.ini` (57.30% translated) : Français (France) - French - * `ru.ini` (56.36% translated) : Русский (Russkiy) - Russian - * `vi.ini` (56.36% translated) : Tiếng Việt (Việt Nam) - Vietnamese + * `fr.ini` (57.12% translated) : Français (France) - French + * `ru.ini` (56.18% translated) : Русский (Russkiy) - Russian + * `vi.ini` (56.18% translated) : Tiếng Việt (Việt Nam) - Vietnamese * `zh-Hans.ini` (100.00% translated) : 简体中文 - Chinese Simplified * `zh-Hant.ini` (100.00% translated) : 繁體中文 - Chinese Traditional