diff --git a/src/VeinMiner/Config.cs b/src/VeinMiner/Config.cs index 58052e9f..b888e422 100644 --- a/src/VeinMiner/Config.cs +++ b/src/VeinMiner/Config.cs @@ -29,13 +29,13 @@ public static void Load(ReloadEventArgs args = null) VeinMiner.Config = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(TShock.SavePath, "VeinMiner.json"))); if (args != null) { - TShock.Log.ConsoleInfo($" 配置已重新加载。"); + TShock.Log.ConsoleInfo(GetString(" 配置已重新加载。")); } } catch (Exception ex) { TShock.Log.Error(ex.Message); - TShock.Log.ConsoleError(" 读取配置文件失败。"); + TShock.Log.ConsoleError(GetString(" 读取配置文件失败。")); } } diff --git a/src/VeinMiner/README.md b/src/VeinMiner/README.md index 5ed12d4c..95e977cc 100644 --- a/src/VeinMiner/README.md +++ b/src/VeinMiner/README.md @@ -11,6 +11,9 @@ ## 更新日志 ``` +v1.6.0.5 +修复刷矿,添加英文翻译 + v1.6.0.4 完善卸载函数 diff --git a/src/VeinMiner/VeinMiner.cs b/src/VeinMiner/VeinMiner.cs index c7f35001..122cf020 100644 --- a/src/VeinMiner/VeinMiner.cs +++ b/src/VeinMiner/VeinMiner.cs @@ -9,14 +9,14 @@ namespace VeinMiner; public class VeinMiner : TerrariaPlugin { public override string Name => "VeinMiner"; - public override Version Version => new Version(1, 6, 0, 4); + public override Version Version => new Version(1, 6, 0, 5); public override string Author => "Megghy|YSpoof|Maxthegreat99|肝帝熙恩"; public override string Description => "VeinMiner by Megghy 适用于 TShock 5.2 支持!"; - internal static Config Config = new(); + internal static Config Config = new (); + public VeinMiner(Main game) : base(game) { - } public override void Initialize() @@ -24,19 +24,19 @@ public override void Initialize() Config.Load(); Commands.ChatCommands.Add(new Command( permissions: "veinminer", - cmd: delegate (CommandArgs args) + cmd: delegate(CommandArgs args) { var tsp = args.Player; var result = tsp.GetData("VeinMiner"); if (args.Parameters.Count >= 1) { result.EnableBroadcast = !result.EnableBroadcast; - tsp.SendMessage($"[c/95CFA6: 挖矿消息已{(result.EnableBroadcast ? "开启" : "关闭")}].", Color.White); + tsp.SendMessage(GetString($"[c/95CFA6: 挖矿消息已{(result.EnableBroadcast ? GetString("开启") : GetString("关闭"))}]."), Color.White); } else { result.Enable = !result.Enable; - tsp.SendMessage($"[c/95CFA6: 已{(result.Enable ? "开启" : "关闭! | 要仅关闭挖矿消息提示请输入:/vm {任意参数}")}.]", Color.White); + tsp.SendMessage(GetString($"[c/95CFA6: 已{(result.Enable ? GetString("开启") : GetString("关闭! | 要仅关闭挖矿消息提示请输入:/vm {任意参数}"))}.]"), Color.White); } }, "veinminer", "chain mining", "vm")); @@ -54,6 +54,7 @@ protected override void Dispose(bool disposing) TShockAPI.Hooks.GeneralHooks.ReloadEvent -= Config.Load; ServerApi.Hooks.ServerJoin.Deregister(this, this.OnPlayerJoin); } + base.Dispose(disposing); } @@ -71,18 +72,20 @@ void OnPlayerJoin(JoinEventArgs args) } } - void OnTileEdit(object o, GetDataHandlers.TileEditEventArgs args) + void OnTileEdit(object? sender, GetDataHandlers.TileEditEventArgs args) { - if (Main.tile[args.X, args.Y] is { } tile && args.Player.HasPermission("veinminer") && Config.Enable && args.Player.GetData("VeinMiner").Enable && Config.Tile.Contains(tile.type) && args.Action == GetDataHandlers.EditAction.KillTile && args.EditData == 0) + if (Main.tile[args.X, args.Y] is not { } tile || !args.Player.HasPermission("veinminer") || !Config.Enable || !args.Player.GetData("VeinMiner").Enable || !Config.Tile.Contains(tile.type) || args.Action != GetDataHandlers.EditAction.KillTile || args.EditData != 0) { - args.Handled = true; - this.Mine(args.Player, args.X, args.Y, tile.type); + return; } + + args.Handled = true; + this.Mine(args.Player, args.X, args.Y, tile.type); } void Mine(TSPlayer plr, int x, int y, int type) { - var list = GetVein(new(), x, y, type).Result; + var list = GetVein(new (), x, y, type); var count = list.Count; var item = Utils.GetItemFromTile(x, y); var mineableList = new List(); @@ -112,22 +115,19 @@ void Mine(TSPlayer plr, int x, int y, int type) e.Item.ForEach(ex => plr.GiveItem(ex.Key, ex.Value)); if (e.OnlyGiveItem) { - KillTileAndSend(list, true); + mineCount = KillTileAndSend(list, true); } else { GiveItem(); } - plr.SendMessage($"[c/95CFA6:] 挖掘了 [c/95CFA6: {mineCount} {(item.type == 0 ? "未知" : item.Name)}].", Color.White); - return; - } - else - { - plr.SendInfoMessage($"[c/95CFA6:] 背包已满,还需空位:[c/95CFA6:{e.Item.Count}] ."); - plr.SendTileSquareCentered(x, y, 1); + plr.SendMessage(GetString($"[c/95CFA6:] 挖掘了 [c/95CFA6: {mineCount} {(item.type == 0 ? GetString("未知") : item.Name)}]."), Color.White); return; } + + plr.SendInfoMessage(GetString($"[c/95CFA6:] 背包已满,还需空位:[c/95CFA6:{e.Item.Count}] .")); + plr.SendTileSquareCentered(x, y, 1); }); } else @@ -141,71 +141,80 @@ void GiveItem() { if (plr.IsSpaceEnough(item.netID, mineCount)) { + mineCount = KillTileAndSend(list, true); plr.GiveItem(item.netID, mineCount); - KillTileAndSend(list, true); + } else { WorldGen.KillTile(x, y); - plr.SendInfoMessage($"[c/95CFA6:] 背包已满,需额外空位:[c/95CFA6:{mineCount}] 以放入 [c/95CFA6:{item.Name}] ."); + plr.SendInfoMessage(GetString($"[c/95CFA6:] 背包已满,需额外空位:[c/95CFA6:{mineCount}] 以放入 [c/95CFA6:{item.Name}] .")); } } else { - KillTileAndSend(list, false); + mineCount = KillTileAndSend(list, false); } if (plr.GetData("VeinMiner").EnableBroadcast && Config.Broadcast && mineCount > 1) { - plr.SendMessage($"[c/95CFA6:] 正在挖掘 [c/95CFA6:{mineCount} {(item.type == 0 ? "未知" : item.Name)}].", Color.White); + plr.SendMessage(GetString($"[c/95CFA6:] 正在挖掘 [c/95CFA6:{mineCount} {(item.type == 0 ? "未知" : item.Name)}]."), Color.White); } } } else if (count > 0) { - plr.SendMessage($"[c/95CFA6:] 无法挖取矿石,可能是因为矿石上方有不可破坏的物体.", Color.White); + plr.SendMessage(GetString($"[c/95CFA6:] 无法挖取矿石,可能是因为矿石上方有不可破坏的物体."), Color.White); } } - public static void KillTileAndSend(List list, bool noItem) + public static int KillTileAndSend(List list, bool noItem) { - Task.Run(() => + if (!list.Any()) + { + return 0; + } + + int killCount = 0; + list.ForEach(p => { - if (!list.Any()) + WorldGen.KillTile(p.X, p.Y, false, false, noItem); + NetMessage.SendData(17, -1, -1, null, 4, p.X, p.Y, false.GetHashCode()); + }); + list.ForEach(p => + { + + ITile tile = Main.tile[p.X, p.Y]; + if (tile == null || !tile.active()) { - return; + killCount++; } - list.ForEach(p => - { - WorldGen.KillTile(p.X, p.Y, false, false, noItem); - NetMessage.SendData(17, -1, -1, null, 4, p.X, p.Y, false.GetHashCode()); - }); }); + return killCount; } - public static Task> GetVein(List list, int x, int y, int type) + public static List GetVein(List list, int x, int y, int type) { - return Task.Run(() => + + if (!list.Any(p => p.Equals(new Point(x, y))) && Main.tile[x, y] is { } tile && tile.active() && tile.type == type) { - if (!list.Any(p => p.Equals(new Point(x, y))) && Main.tile[x, y] is { } tile && tile.active() && tile.type == type) + if (list.Count > 5000) { - if (list.Count > 5000) - { - return list; - } - - list.Add(new(x, y)); - list = GetVein(list, x + 1, y, type).Result; - list = GetVein(list, x - 1, y, type).Result; - list = GetVein(list, x, y + 1, type).Result; - list = GetVein(list, x, y - 1, type).Result; - list = GetVein(list, x + 1, y + 1, type).Result; - list = GetVein(list, x + 1, y - 1, type).Result; - list = GetVein(list, x - 1, y + 1, type).Result; - list = GetVein(list, x - 1, y - 1, type).Result; + return list; } - return list; - }); + + list.Add(new (x, y)); + list = GetVein(list, x + 1, y, type); + list = GetVein(list, x - 1, y, type); + list = GetVein(list, x, y + 1, type); + list = GetVein(list, x, y - 1, type); + list = GetVein(list, x + 1, y + 1, type); + list = GetVein(list, x + 1, y - 1, type); + list = GetVein(list, x - 1, y + 1, type); + list = GetVein(list, x - 1, y - 1, type); + } + + return list; } } \ No newline at end of file diff --git a/src/VeinMiner/VeinMiner.csproj b/src/VeinMiner/VeinMiner.csproj index c04234e7..4eb0d2a7 100644 --- a/src/VeinMiner/VeinMiner.csproj +++ b/src/VeinMiner/VeinMiner.csproj @@ -1,3 +1,6 @@  + + + \ No newline at end of file diff --git a/src/VeinMiner/i18n/en-US.po b/src/VeinMiner/i18n/en-US.po new file mode 100644 index 00000000..45dccbb5 --- /dev/null +++ b/src/VeinMiner/i18n/en-US.po @@ -0,0 +1,83 @@ +msgid "" +msgstr "" +"Project-Id-Version: VeinMiner\n" +"POT-Creation-Date: 2024-08-31 17:14:06+0800\n" +"PO-Revision-Date: 2024-08-31 19:55+0800\n" +"Last-Translator: Cai\n" +"Language-Team: UnrealMultiple\n" +"Language: en_US\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 3.5\n" + +#: ..\..\VeinMiner.cs:34 ..\..\VeinMiner.cs:39 +msgid "开启" +msgstr "Activated" + +#: ..\..\VeinMiner.cs:161 +#, csharp-format +msgid "[c/95CFA6:] 正在挖掘 [c/95CFA6:{0} {1}]." +msgstr "[c/95CFA6:] Mining [c/95CFA6: {0} {1} ]." + +#: ..\..\VeinMiner.cs:151 +#, csharp-format +msgid "" +"[c/95CFA6:] 背包已满,需额外空位:[c/95CFA6:{0}] 以" +"放入 [c/95CFA6:{1}] ." +msgstr "" +"[c/95CFA6:] Inventory full, space needed: [c/95CFA6:" +"{0}] to insert [c/95CFA6:{1}] ." + +#: ..\..\VeinMiner.cs:167 +msgid "" +"[c/95CFA6:] 无法挖取矿石,可能是因为矿石上方有不可破" +"坏的物体." +msgstr "" +"[c/95CFA6:] Unable to mine ore, possibly because " +"there is an indestructible object above the ore." + +#: ..\..\Config.cs:38 +msgid " 读取配置文件失败。" +msgstr " Failed to read config file." + +#: ..\..\VeinMiner.cs:129 +#, csharp-format +msgid "" +"[c/95CFA6:] 背包已满,还需空位:[c/95CFA6:{0}] ." +msgstr "" +"[c/95CFA6:] Inventory full, space needed: [c/95CFA6:" +"{0}] ." + +#: ..\..\VeinMiner.cs:39 +#, csharp-format +msgid "[c/95CFA6: 已{0}.]" +msgstr "[c/95CFA6: {0} .]" + +#: ..\..\VeinMiner.cs:39 +msgid "关闭! | 要仅关闭挖矿消息提示请输入:/vm {任意参数}" +msgstr "" +"Deactivated! | To turn off only mining status messages use: /" +"vm msg" + +#: ..\..\Config.cs:32 +msgid " 配置已重新加载。" +msgstr " Config reloaded." + +#: ..\..\VeinMiner.cs:34 +msgid "关闭" +msgstr "Deactivated" + +#: ..\..\VeinMiner.cs:34 +#, csharp-format +msgid "[c/95CFA6: 挖矿消息已{0}]." +msgstr "[c/95CFA6: Mining Status {0}.]" + +#: ..\..\VeinMiner.cs:125 +msgid "未知" +msgstr "Unknown" + +#: ..\..\VeinMiner.cs:125 +#, csharp-format +msgid "[c/95CFA6:] 挖掘了 [c/95CFA6: {0} {1}]." +msgstr "[c/95CFA6:] Mined [c/95CFA6: {0} {1} ]." diff --git a/src/VeinMiner/i18n/template.pot b/src/VeinMiner/i18n/template.pot new file mode 100644 index 00000000..a436eea0 --- /dev/null +++ b/src/VeinMiner/i18n/template.pot @@ -0,0 +1,71 @@ +msgid "" +msgstr "" +"Project-Id-Version: VeinMiner\n" +"POT-Creation-Date: 2024-08-31 17:14:06+0800\n" +"PO-Revision-Date: 2024-08-31 17:14:06+0800\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: GetText.NET Extractor\n" + +#: ..\..\VeinMiner.cs:34 +#: ..\..\VeinMiner.cs:39 +msgid "开启" +msgstr "" + +#: ..\..\VeinMiner.cs:161 +#, csharp-format +msgid "[c/95CFA6:] 正在挖掘 [c/95CFA6:{0} {1}]." +msgstr "" + +#: ..\..\VeinMiner.cs:151 +#, csharp-format +msgid "[c/95CFA6:] 背包已满,需额外空位:[c/95CFA6:{0}] 以放入 [c/95CFA6:{1}] ." +msgstr "" + +#: ..\..\VeinMiner.cs:167 +msgid "[c/95CFA6:] 无法挖取矿石,可能是因为矿石上方有不可破坏的物体." +msgstr "" + +#: ..\..\Config.cs:38 +msgid " 读取配置文件失败。" +msgstr "" + +#: ..\..\VeinMiner.cs:129 +#, csharp-format +msgid "[c/95CFA6:] 背包已满,还需空位:[c/95CFA6:{0}] ." +msgstr "" + +#: ..\..\VeinMiner.cs:39 +#, csharp-format +msgid "[c/95CFA6: 已{0}.]" +msgstr "" + +#: ..\..\VeinMiner.cs:39 +msgid "关闭! | 要仅关闭挖矿消息提示请输入:/vm {任意参数}" +msgstr "" + +#: ..\..\Config.cs:32 +msgid " 配置已重新加载。" +msgstr "" + +#: ..\..\VeinMiner.cs:34 +msgid "关闭" +msgstr "" + +#: ..\..\VeinMiner.cs:34 +#, csharp-format +msgid "[c/95CFA6: 挖矿消息已{0}]." +msgstr "" + +#: ..\..\VeinMiner.cs:125 +msgid "未知" +msgstr "" + +#: ..\..\VeinMiner.cs:125 +#, csharp-format +msgid "[c/95CFA6:] 挖掘了 [c/95CFA6: {0} {1}]." +msgstr "" +