From d4129712d46ab0173af495046012d1affb7f8cd2 Mon Sep 17 00:00:00 2001 From: xien <2383759126@qq.com> Date: Thu, 18 Apr 2024 13:29:22 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=EF=BC=9AInvincibilityPlugin=20=E9=99=90=E6=97=B6=E6=97=A0?= =?UTF-8?q?=E6=95=8C=20=E4=BF=AE=E6=AD=A3=E9=83=A8=E5=88=86readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutoBroadcast/README.md | 2 +- AutoTeam/README.md | 2 +- Back/README.md | 2 +- BridgeBuilder/README.md | 2 +- Invincibility/Configuration.cs | 56 ++++++++++ Invincibility/Invincibility.csproj | 3 + Invincibility/InvincibilityPlugin.cs | 161 +++++++++++++++++++++++++++ Invincibility/README.md | 36 ++++++ Plugin.sln | 10 ++ RainbowChat/README.md | 2 +- 10 files changed, 271 insertions(+), 5 deletions(-) create mode 100644 Invincibility/Configuration.cs create mode 100644 Invincibility/Invincibility.csproj create mode 100644 Invincibility/InvincibilityPlugin.cs create mode 100644 Invincibility/README.md diff --git a/AutoBroadcast/README.md b/AutoBroadcast/README.md index c37674cf3..c3c3531ab 100644 --- a/AutoBroadcast/README.md +++ b/AutoBroadcast/README.md @@ -20,7 +20,7 @@ { "Broadcasts": [ { - "Name": "E实例广播", + "Name": "实例广播", "Enabled": false, "Messages": [ "这是一条广播", diff --git a/AutoTeam/README.md b/AutoTeam/README.md index 572befbb1..70828b6ea 100644 --- a/AutoTeam/README.md +++ b/AutoTeam/README.md @@ -14,7 +14,7 @@ | 语法 | 权限 | 说明 | | -------------- | :-----------------: | :------: | -| /autoteam或/at | autoteam.toggle | 开关自动队伍功能 | +| /autoteam 或 /at | autoteam.toggle | 开关自动队伍功能 | | 无 | noautoteam | 有该权限不会被自动分配队伍 | ## 配置 diff --git a/Back/README.md b/Back/README.md index 6867627ee..b42dd4533 100644 --- a/Back/README.md +++ b/Back/README.md @@ -14,7 +14,7 @@ | 语法 | 权限 | 说明 | | -------------- | :-----------------: | :------: | -| back | back | 返回死亡地点| +| /back | back | 返回死亡地点| ## 配置 diff --git a/BridgeBuilder/README.md b/BridgeBuilder/README.md index abd0a0f93..f01467961 100644 --- a/BridgeBuilder/README.md +++ b/BridgeBuilder/README.md @@ -15,7 +15,7 @@ | 语法 | 权限 | 说明 | | -------------- | :-----------------: | :------: | -| bridgebuilder.bridge | bridge 或 桥来 | 快速铺桥指令| +| /bridge 或 /桥来 | bridgebuilder.bridge | 快速铺桥指令| ## 配置 diff --git a/Invincibility/Configuration.cs b/Invincibility/Configuration.cs new file mode 100644 index 000000000..e9c482623 --- /dev/null +++ b/Invincibility/Configuration.cs @@ -0,0 +1,56 @@ +using System; +using System.IO; +using System.Runtime.CompilerServices; +using Newtonsoft.Json; +using TShockAPI; + +namespace InvincibilityPlugin +{ + public class Configuration + { + public static readonly string FilePath = Path.Combine(TShock.SavePath, "限时无敌.json"); + [JsonProperty("插件自带god无敌开启提示")] + public bool EnableInvincibleReminder { get; set; } = true; + + [JsonProperty("god无敌开启提示自定义文本")] + public string CustomInvincibleReminderText { get; set; } = ""; + + [JsonProperty("god无敌关闭提示自定义文本")] + public string CustomInvincibleDisableText { get; set; } = "你的无敌已关闭!"; + + [JsonProperty("插件自带无敌帧开启提示")] + public bool EnableFrameReminder { get; set; } = true; + + [JsonProperty("无敌帧开始提示文本")] + public string CustomStartFrameText { get; set; } = ""; + + [JsonProperty("无敌帧结束提示文本")] + public string CustomEndFrameText { get; set; } = "无敌帧结束了!"; + + public void Write(string path) + { + using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Write)) + { + var str = JsonConvert.SerializeObject(this, Formatting.Indented); + using (var sw = new StreamWriter(fs)) + { + sw.Write(str); + } + } + } + + public static Configuration Read(string path) + { + if (!File.Exists(path)) + return new Configuration(); + using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + using (var sr = new StreamReader(fs)) + { + var cf = JsonConvert.DeserializeObject(sr.ReadToEnd()); + return cf; + } + } + } + } +} diff --git a/Invincibility/Invincibility.csproj b/Invincibility/Invincibility.csproj new file mode 100644 index 000000000..0d0932af1 --- /dev/null +++ b/Invincibility/Invincibility.csproj @@ -0,0 +1,3 @@ + + + diff --git a/Invincibility/InvincibilityPlugin.cs b/Invincibility/InvincibilityPlugin.cs new file mode 100644 index 000000000..df7cdeab7 --- /dev/null +++ b/Invincibility/InvincibilityPlugin.cs @@ -0,0 +1,161 @@ +using TerrariaApi.Server; +using TShockAPI; +using Terraria; +using Terraria.GameContent.Creative; +using Google.Protobuf.WellKnownTypes; +using System.Configuration; +using TShockAPI.Hooks; + +namespace InvincibilityPlugin +{ + [ApiVersion(2, 1)] + public class InvincibilityPlugin : TerrariaPlugin + { + private Timer invincibleTimer; + private float duration; + public override string Author => "肝帝熙恩"; + public override string Description => "在命令中给予玩家一段时间的无敌状态。"; + public override string Name => "InvincibilityPlugin"; + public override Version Version => new Version(1, 0, 0, 4); + public static Configuration Config; + public InvincibilityPlugin(Main game) : base(game) + { + LoadConfig(); + } + + private static void LoadConfig() + { + Config = Configuration.Read(Configuration.FilePath); + Config.Write(Configuration.FilePath); + + } + private static void ReloadConfig(ReloadEventArgs args) + { + LoadConfig(); + args.Player?.SendSuccessMessage("[{0}] 重新加载配置完毕。", typeof(InvincibilityPlugin).Name); + } + public override void Initialize() + { + GeneralHooks.ReloadEvent += ReloadConfig; + ServerApi.Hooks.GameInitialize.Register(this, OnInitialize); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + ServerApi.Hooks.GameInitialize.Deregister(this, OnInitialize); + } + base.Dispose(disposing); + } + + private void OnInitialize(EventArgs args) + { + Commands.ChatCommands.Add(new Command("限时god无敌", InvincibleCommand, "tgod", "限时god无敌")); + Commands.ChatCommands.Add(new Command("限时无敌帧无敌", ActivateFrameInvincibility, "tframe", "限时无敌帧无敌")); + } + + private void InvincibleCommand(CommandArgs args) + { + if (!args.Player.HasPermission("限时god无敌")) + { + args.Player.SendErrorMessage("你没有执行此命令的权限。"); + return; + } + + if (args.Parameters.Count < 1) + { + args.Player.SendErrorMessage("用法: /限时god无敌 或 tgod <持续时间秒数>"); + return; + } + + if (!float.TryParse(args.Parameters[0], out duration) || duration <= 0) + { + args.Player.SendErrorMessage("无效的持续时间。请输入一个正数。"); + return; + } + + TSPlayer player = TShock.Players[args.Player.Index]; + + if (player == null || !player.Active) + { + args.Player.SendErrorMessage("玩家不在线。"); + return; + } + + addGodMode(player); + + invincibleTimer = new Timer(RemoveInvincibility, player, (int)(duration * 1000), Timeout.Infinite); + } + + + + private void RemoveInvincibility(object state) + { + TSPlayer player = (TSPlayer)state; + delGodMode(player); + invincibleTimer.Dispose(); + } + + private void addGodMode(TSPlayer player) + { + player.GodMode = !player.GodMode; + CreativePowerManager.Instance.GetPower().SetEnabledState(player.Index, player.GodMode); + if (Config.EnableInvincibleReminder) + { + player.SendSuccessMessage($"你将在 {duration} 秒内无敌."); + } + + if (!string.IsNullOrEmpty(Config.CustomInvincibleReminderText)) + { + player.SendSuccessMessage(Config.CustomInvincibleReminderText); + } + + + NetMessage.SendData((int)PacketTypes.PlayerInfo, -1, -1, null, player.Index, 1f); + } + + private void delGodMode(TSPlayer player) + { + player.GodMode = !player.GodMode; + CreativePowerManager.Instance.GetPower().SetEnabledState(player.Index, player.GodMode); + player.SendSuccessMessage($"{Config.CustomInvincibleDisableText}"); + + NetMessage.SendData((int)PacketTypes.PlayerInfo, -1, -1, null, player.Index, 1f); + } + + private async void ActivateFrameInvincibility(CommandArgs args) + { + if (args.Parameters.Count < 1 || !double.TryParse(args.Parameters[0], out double duration) || duration <= 0) + { + args.Player.SendSuccessMessage("用法: /限时无敌帧无敌或tframe <持续时间秒数>"); + return; + } + + TSPlayer player = args.Player; + + if (Config.EnableFrameReminder) + { + args.Player.SendSuccessMessage($"你将在 {args.Parameters[0]} 秒内无敌."); + } + if (!string.IsNullOrEmpty(Config.CustomStartFrameText)) + { + player.SendSuccessMessage(Config.CustomStartFrameText); + } + + while (duration >= 1.33) + { + player.SendData(PacketTypes.PlayerDodge, "", player.Index, 2f, 0f, 0f, 0); + duration -= 0.1; + await Task.Delay(100); + } + + if (!string.IsNullOrEmpty(Config.CustomEndFrameText)) + { + player.SendSuccessMessage(Config.CustomEndFrameText); + } + } + + + } +} diff --git a/Invincibility/README.md b/Invincibility/README.md new file mode 100644 index 000000000..f9b54d3e2 --- /dev/null +++ b/Invincibility/README.md @@ -0,0 +1,36 @@ +# InvincibilityPlugin 限时无敌 + +- 作者: 肝帝熙恩 +- 出处: 无 +- 分为两种,god和frame +- god也就是绝对无敌,蓝量都不消耗的那种 +- frame是给你发无敌帧,如果你自己泡岩浆里还是有可能受到伤害的 + +## 更新日志 + +``` +暂无 +``` + +## 指令 + +| 语法 | 权限 | 说明 | +| -------------- | :-----------------: | :------: | +| /tgod 或 /限时god无敌 | Invincibility.god | god无敌| +| /tframe 或 /限时无敌帧无敌 | Invincibility.frame | 无敌帧无敌| + +## 配置 + +```json +{ + "插件自带god无敌开启提示": true, + "god无敌开启提示自定义文本": "", + "god无敌关闭提示自定义文本": "你的无敌已关闭!", + "插件自带无敌帧开启提示": true, + "无敌帧开始提示文本": "", + "无敌帧结束提示文本": "无敌帧结束了!" +} +``` +## 反馈 +- 共同维护的插件库:https://github.com/THEXN/TShockPlugin/ +- 国内社区trhub.cn 或 TShock官方群等 \ No newline at end of file diff --git a/Plugin.sln b/Plugin.sln index 0eaa1280c..da13c2af2 100644 --- a/Plugin.sln +++ b/Plugin.sln @@ -90,6 +90,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdditionalPylons", "Additio EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "History", "History\History.csproj", "{8A851EF7-2B1D-4A82-A5B9-EF1A96BFE693}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Invincibility", "Invincibility\Invincibility.csproj", "{17819CBB-E56C-4DD8-A762-2037F2C2C388}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -426,6 +428,14 @@ Global {8A851EF7-2B1D-4A82-A5B9-EF1A96BFE693}.Release|Any CPU.Build.0 = Release|Any CPU {8A851EF7-2B1D-4A82-A5B9-EF1A96BFE693}.Release|x64.ActiveCfg = Release|Any CPU {8A851EF7-2B1D-4A82-A5B9-EF1A96BFE693}.Release|x64.Build.0 = Release|Any CPU + {17819CBB-E56C-4DD8-A762-2037F2C2C388}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {17819CBB-E56C-4DD8-A762-2037F2C2C388}.Debug|Any CPU.Build.0 = Debug|Any CPU + {17819CBB-E56C-4DD8-A762-2037F2C2C388}.Debug|x64.ActiveCfg = Debug|Any CPU + {17819CBB-E56C-4DD8-A762-2037F2C2C388}.Debug|x64.Build.0 = Debug|Any CPU + {17819CBB-E56C-4DD8-A762-2037F2C2C388}.Release|Any CPU.ActiveCfg = Release|Any CPU + {17819CBB-E56C-4DD8-A762-2037F2C2C388}.Release|Any CPU.Build.0 = Release|Any CPU + {17819CBB-E56C-4DD8-A762-2037F2C2C388}.Release|x64.ActiveCfg = Release|Any CPU + {17819CBB-E56C-4DD8-A762-2037F2C2C388}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/RainbowChat/README.md b/RainbowChat/README.md index 1a0c194c5..966370151 100644 --- a/RainbowChat/README.md +++ b/RainbowChat/README.md @@ -14,7 +14,7 @@ | 语法 | 权限 | 说明 | | -------------- | :-----------------: | :------: | -| /rainbowchat或/rc | rainbowchat.use | 开关彩虹聊天功能 | +| /rainbowchat 或 /rc | rainbowchat.use | 开关彩虹聊天功能 | ## 配置 From a0de44682870e46da218ff3907e9cb4faf0daa2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=82=9D=E5=B8=9D=E7=86=99=E6=81=A9?= <111548550+THEXN@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:30:41 +0800 Subject: [PATCH 2/7] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5c4f9888d..0938cb7a7 100644 --- a/README.md +++ b/README.md @@ -71,3 +71,4 @@ | [DamageStatistic](DamageStatistic/README.md) | 伤害统计 | 无 | | [AdditionalPylons](AdditionalPylons/README.md) | 放置更多晶塔 | 无 | | [History](History/README.md) | 历史图格记录 | 无 | +| [Invincibility](Invincibility/README.md) | 限时无敌 | 无 | From c3ce0f9a7d26efb3d180b357c19c08c21f87525b Mon Sep 17 00:00:00 2001 From: xien <2383759126@qq.com> Date: Thu, 18 Apr 2024 18:18:42 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E9=99=90=E6=97=B6=E6=97=A0=E6=95=8C?= =?UTF-8?q?=E9=87=8D=E5=86=99=E8=AE=A1=E6=97=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ezperm/Configuration.cs | 69 ++++++++++++++++ Ezperm/ezperm.cs | 75 +++++++++++++++++ Ezperm/ezperm.csproj | 13 +++ Invincibility/InvincibilityPlugin.cs | 117 +++++++++++++++++---------- 4 files changed, 232 insertions(+), 42 deletions(-) create mode 100644 Ezperm/Configuration.cs create mode 100644 Ezperm/ezperm.cs create mode 100644 Ezperm/ezperm.csproj diff --git a/Ezperm/Configuration.cs b/Ezperm/Configuration.cs new file mode 100644 index 000000000..7bc597e08 --- /dev/null +++ b/Ezperm/Configuration.cs @@ -0,0 +1,69 @@ +using Newtonsoft.Json; +using System.Collections.Generic; +using System.IO; +using TShockAPI; + +namespace ezperm +{ + internal class GroupInfo + { + [JsonProperty("组名字")] + public string Name { get; set; } + [JsonProperty("添加的权限")] + public List AddPermissions { get; set; } + [JsonProperty("删除的权限")] + public List DelPermissions { get; set; } + } + + internal class Configuration + { + public static readonly string FilePath = Path.Combine(TShock.SavePath, "ezperm.json"); + + public List Groups { get; set; } + + public void Write(string path) + { + using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Write)) + { + var str = JsonConvert.SerializeObject(this, Formatting.Indented); + using (var sw = new StreamWriter(fs)) + { + sw.Write(str); + } + } + } + + public static Configuration Read(string path) + { + if (!File.Exists(path)) + { + // If the file doesn't exist, create a default configuration + var defaultConfig = new Configuration + { + Groups = new List + { + new GroupInfo + { + Name = "default", + AddPermissions = new List { "tshock.world.movenpc","tshock.tp.pylon","tshock.tp.rod","tshock.npc.startdd2","tshock.tp.wormhole","tshock.npc.summonboss","tshock.npc.startinvasion","tshock.world.time.usesundial" }, + DelPermissions = new List { "tshock.admin" } + } + } + }; + + defaultConfig.Write(path); + return defaultConfig; + } + + using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + using (var sr = new StreamReader(fs)) + { + var cf = JsonConvert.DeserializeObject(sr.ReadToEnd()); + return cf; + } + } + } + } +} + diff --git a/Ezperm/ezperm.cs b/Ezperm/ezperm.cs new file mode 100644 index 000000000..948517b6f --- /dev/null +++ b/Ezperm/ezperm.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using Terraria; +using TerrariaApi.Server; +using TShockAPI; +using static Org.BouncyCastle.Math.EC.ECCurve; +using TShockAPI.Hooks; + +namespace ezperm +{ + [ApiVersion(2, 1)] + public class ezperm : TerrariaPlugin + { + public override string Name => "ezperm"; + public override string Author => "大豆子,肝帝熙恩优化1449"; + public override string Description => "一个指令帮助小白给初始服务器添加缺失的权限,还可以批量添删权限"; + public override Version Version => new Version(1, 2); + internal static Configuration Config; + public ezperm(Main game) : base(game) + { + } + private static void LoadConfig() + { + + Config = Configuration.Read(Configuration.FilePath); + Config.Write(Configuration.FilePath); + + } + private static void ReloadConfig(ReloadEventArgs args) + { + LoadConfig(); + args.Player?.SendSuccessMessage("重新加载{0}配置完毕。", typeof(ezperm).Name); + } + public override void Initialize() + { + GeneralHooks.ReloadEvent += ReloadConfig; + Commands.ChatCommands.Add(new Command(new List + { + "inperms.admin" + }, new CommandDelegate(this.Cmd), new string[] + { + "inperms", + "批量改权限" + })); + } + private void Cmd(CommandArgs args) + { + Configuration config = Configuration.Read(Configuration.FilePath); + + foreach (var groupInfo in config.Groups) + { + string group = groupInfo.Name; + + // 添加权限 + foreach (var addPermission in groupInfo.AddPermissions) + { + string addCommand = $"/group addperm {group} {addPermission}"; + Commands.HandleCommand(TSPlayer.Server, addCommand); + } + + // 删除权限 + foreach (var delPermission in groupInfo.DelPermissions) + { + string delCommand = $"/group delperm {group} {delPermission}"; + Commands.HandleCommand(TSPlayer.Server, delCommand); + } + + // 修改这行,显示具体的组和权限信息 + args.Player.SendSuccessMessage($"成功为组 {group} 添加权限: {string.Join(", ", groupInfo.AddPermissions)}"); + args.Player.SendSuccessMessage($"成功为组 {group} 删除权限: {string.Join(", ", groupInfo.DelPermissions)}"); + } + } + } +} diff --git a/Ezperm/ezperm.csproj b/Ezperm/ezperm.csproj new file mode 100644 index 000000000..f041a9b95 --- /dev/null +++ b/Ezperm/ezperm.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Invincibility/InvincibilityPlugin.cs b/Invincibility/InvincibilityPlugin.cs index df7cdeab7..f3130aa78 100644 --- a/Invincibility/InvincibilityPlugin.cs +++ b/Invincibility/InvincibilityPlugin.cs @@ -11,14 +11,16 @@ namespace InvincibilityPlugin [ApiVersion(2, 1)] public class InvincibilityPlugin : TerrariaPlugin { - private Timer invincibleTimer; - private float duration; public override string Author => "肝帝熙恩"; public override string Description => "在命令中给予玩家一段时间的无敌状态。"; public override string Name => "InvincibilityPlugin"; - public override Version Version => new Version(1, 0, 0, 4); + public override Version Version => new Version(1, 0, 5); public static Configuration Config; - public InvincibilityPlugin(Main game) : base(game) + private Dictionary invincibleStartTime = new Dictionary(); + private Dictionary invincibleDurations = new Dictionary(); + private Dictionary frameDurations = new Dictionary(); + + public InvincibilityPlugin(Main game) : base(game) { LoadConfig(); } @@ -38,21 +40,75 @@ public override void Initialize() { GeneralHooks.ReloadEvent += ReloadConfig; ServerApi.Hooks.GameInitialize.Register(this, OnInitialize); + ServerApi.Hooks.GameUpdate.Register(this, OnUpdate); } - protected override void Dispose(bool disposing) { if (disposing) { ServerApi.Hooks.GameInitialize.Deregister(this, OnInitialize); + ServerApi.Hooks.GameUpdate.Deregister(this, OnUpdate); } base.Dispose(disposing); } private void OnInitialize(EventArgs args) { - Commands.ChatCommands.Add(new Command("限时god无敌", InvincibleCommand, "tgod", "限时god无敌")); - Commands.ChatCommands.Add(new Command("限时无敌帧无敌", ActivateFrameInvincibility, "tframe", "限时无敌帧无敌")); + Commands.ChatCommands.Add(new Command("Invincibility.god", InvincibleCommand, "tgod", "限时god无敌")); + Commands.ChatCommands.Add(new Command("Invincibility.frame", ActivateFrameInvincibility, "tframe", "限时无敌帧无敌")); + } + + private void OnUpdate(EventArgs args) + { + List playersToRemove = new List(); + + // 处理无敌持续时间结束的玩家 + foreach (var pair in invincibleDurations.ToList()) + { + TSPlayer player = pair.Key; + float duration = pair.Value; + + if (DateTime.UtcNow - invincibleStartTime[player] >= TimeSpan.FromSeconds(duration)) + { + delGodMode(player); + playersToRemove.Add(player); + } + } + + // 移除无敌持续时间结束的玩家 + foreach (var player in playersToRemove) + { + invincibleStartTime.Remove(player); + invincibleDurations.Remove(player); + } + + // 处理无敌帧效果 + playersToRemove.Clear(); // 清空玩家列表,用于处理无敌帧结束的玩家 + foreach (var pair in frameDurations.ToList()) + { + TSPlayer player = pair.Key; + float duration = pair.Value; + + if (duration >= 1.33f) + { + // 在玩家的客户端发送无敌帧效果 + player.SendData(PacketTypes.PlayerDodge, "", player.Index, 2f, 0f, 0f, 0); + duration -= 0.1f; + frameDurations[player] = duration; + } + else + { + // 无敌帧结束,添加到待移除玩家列表中 + playersToRemove.Add(player); + } + } + + // 移除无敌帧结束的玩家 + foreach (var player in playersToRemove) + { + frameDurations.Remove(player); + player.SendSuccessMessage($"{Config.CustomEndFrameText}"); + } } private void InvincibleCommand(CommandArgs args) @@ -65,10 +121,11 @@ private void InvincibleCommand(CommandArgs args) if (args.Parameters.Count < 1) { - args.Player.SendErrorMessage("用法: /限时god无敌 或 tgod <持续时间秒数>"); + args.Player.SendErrorMessage("用法: /限时god无敌或tgod <持续时间秒数>"); return; } + float duration; if (!float.TryParse(args.Parameters[0], out duration) || duration <= 0) { args.Player.SendErrorMessage("无效的持续时间。请输入一个正数。"); @@ -83,23 +140,14 @@ private void InvincibleCommand(CommandArgs args) return; } - addGodMode(player); - - invincibleTimer = new Timer(RemoveInvincibility, player, (int)(duration * 1000), Timeout.Infinite); - } - - - - private void RemoveInvincibility(object state) - { - TSPlayer player = (TSPlayer)state; - delGodMode(player); - invincibleTimer.Dispose(); + addGodMode(player, duration); + invincibleStartTime[player] = DateTime.UtcNow; + invincibleDurations[player] = duration; } - private void addGodMode(TSPlayer player) + private void addGodMode(TSPlayer player, float duration) { - player.GodMode = !player.GodMode; + player.GodMode = true; CreativePowerManager.Instance.GetPower().SetEnabledState(player.Index, player.GodMode); if (Config.EnableInvincibleReminder) { @@ -110,25 +158,22 @@ private void addGodMode(TSPlayer player) { player.SendSuccessMessage(Config.CustomInvincibleReminderText); } - - NetMessage.SendData((int)PacketTypes.PlayerInfo, -1, -1, null, player.Index, 1f); } private void delGodMode(TSPlayer player) { - player.GodMode = !player.GodMode; + player.GodMode = false; CreativePowerManager.Instance.GetPower().SetEnabledState(player.Index, player.GodMode); player.SendSuccessMessage($"{Config.CustomInvincibleDisableText}"); - NetMessage.SendData((int)PacketTypes.PlayerInfo, -1, -1, null, player.Index, 1f); } - private async void ActivateFrameInvincibility(CommandArgs args) + private void ActivateFrameInvincibility(CommandArgs args) { - if (args.Parameters.Count < 1 || !double.TryParse(args.Parameters[0], out double duration) || duration <= 0) + if (args.Parameters.Count < 1 || !float.TryParse(args.Parameters[0], out float duration) || duration <= 0) { - args.Player.SendSuccessMessage("用法: /限时无敌帧无敌或tframe <持续时间秒数>"); + args.Player.SendErrorMessage("用法: /限时无敌帧无敌或tframe <持续时间秒数>"); return; } @@ -143,19 +188,7 @@ private async void ActivateFrameInvincibility(CommandArgs args) player.SendSuccessMessage(Config.CustomStartFrameText); } - while (duration >= 1.33) - { - player.SendData(PacketTypes.PlayerDodge, "", player.Index, 2f, 0f, 0f, 0); - duration -= 0.1; - await Task.Delay(100); - } - - if (!string.IsNullOrEmpty(Config.CustomEndFrameText)) - { - player.SendSuccessMessage(Config.CustomEndFrameText); - } + frameDurations[player] = duration; } - - } } From 3416b84f78b7dbf39ebbba013e9cac6cacc12728 Mon Sep 17 00:00:00 2001 From: xien <2383759126@qq.com> Date: Thu, 18 Apr 2024 18:33:29 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=EF=BC=9Aezperm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ezperm/Configuration.cs | 2 +- Ezperm/README.md | 46 +++++++++++++++++++++++++++++++++++++++++ Ezperm/ezperm.cs | 10 ++++----- Ezperm/ezperm.csproj | 10 +-------- Plugin.sln | 10 +++++++++ 5 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 Ezperm/README.md diff --git a/Ezperm/Configuration.cs b/Ezperm/Configuration.cs index 7bc597e08..7b6894e4a 100644 --- a/Ezperm/Configuration.cs +++ b/Ezperm/Configuration.cs @@ -3,7 +3,7 @@ using System.IO; using TShockAPI; -namespace ezperm +namespace Ezperm { internal class GroupInfo { diff --git a/Ezperm/README.md b/Ezperm/README.md new file mode 100644 index 000000000..6bbe5d8d3 --- /dev/null +++ b/Ezperm/README.md @@ -0,0 +1,46 @@ +# Ezperm 便捷权限 + +- 作者: 大豆子,肝帝熙恩优化1449 +- 出处: TShock中文官方群 +- 一个指令帮助小白给初始服务器添加缺失的权限,还可以批量添删权限 +- 其实你也可以直接/group addperm 组名字 权限1 权限2 权限3 + +## 更新日志 + +``` +暂无 +``` + +## 指令 + +| 语法 | 权限 | 说明 | +| -------------- | :-----------------: | :------: | +| /inperms 或 /批量改权限 | inperms.admin | 批量改权限| + +## 配置 + +```json +{ + "Groups": [ + { + "组名字": "default", + "添加的权限": [ + "tshock.world.movenpc", + "tshock.tp.pylon", + "tshock.tp.rod", + "tshock.npc.startdd2", + "tshock.tp.wormhole", + "tshock.npc.summonboss", + "tshock.npc.startinvasion", + "tshock.world.time.usesundial" + ], + "删除的权限": [ + "tshock.admin" + ] + } + ] +} +``` +## 反馈 +- 共同维护的插件库:https://github.com/THEXN/TShockPlugin/ +- 国内社区trhub.cn 或 TShock官方群等 \ No newline at end of file diff --git a/Ezperm/ezperm.cs b/Ezperm/ezperm.cs index 948517b6f..ba677a2df 100644 --- a/Ezperm/ezperm.cs +++ b/Ezperm/ezperm.cs @@ -7,17 +7,17 @@ using static Org.BouncyCastle.Math.EC.ECCurve; using TShockAPI.Hooks; -namespace ezperm +namespace Ezperm { [ApiVersion(2, 1)] - public class ezperm : TerrariaPlugin + public class Ezperm : TerrariaPlugin { - public override string Name => "ezperm"; + public override string Name => "Ezperm"; public override string Author => "大豆子,肝帝熙恩优化1449"; public override string Description => "一个指令帮助小白给初始服务器添加缺失的权限,还可以批量添删权限"; public override Version Version => new Version(1, 2); internal static Configuration Config; - public ezperm(Main game) : base(game) + public Ezperm(Main game) : base(game) { } private static void LoadConfig() @@ -30,7 +30,7 @@ private static void LoadConfig() private static void ReloadConfig(ReloadEventArgs args) { LoadConfig(); - args.Player?.SendSuccessMessage("重新加载{0}配置完毕。", typeof(ezperm).Name); + args.Player?.SendSuccessMessage("重新加载{0}配置完毕。", typeof(Ezperm).Name); } public override void Initialize() { diff --git a/Ezperm/ezperm.csproj b/Ezperm/ezperm.csproj index f041a9b95..8a6a26c41 100644 --- a/Ezperm/ezperm.csproj +++ b/Ezperm/ezperm.csproj @@ -1,13 +1,5 @@ - - net6.0 - enable - enable - - - - - + diff --git a/Plugin.sln b/Plugin.sln index da13c2af2..2a38d0050 100644 --- a/Plugin.sln +++ b/Plugin.sln @@ -92,6 +92,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "History", "History\History. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Invincibility", "Invincibility\Invincibility.csproj", "{17819CBB-E56C-4DD8-A762-2037F2C2C388}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ezperm", "Ezperm\Ezperm.csproj", "{4AB96380-C0D3-4746-87FF-D5FF0AFF1AE3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -436,6 +438,14 @@ Global {17819CBB-E56C-4DD8-A762-2037F2C2C388}.Release|Any CPU.Build.0 = Release|Any CPU {17819CBB-E56C-4DD8-A762-2037F2C2C388}.Release|x64.ActiveCfg = Release|Any CPU {17819CBB-E56C-4DD8-A762-2037F2C2C388}.Release|x64.Build.0 = Release|Any CPU + {4AB96380-C0D3-4746-87FF-D5FF0AFF1AE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4AB96380-C0D3-4746-87FF-D5FF0AFF1AE3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4AB96380-C0D3-4746-87FF-D5FF0AFF1AE3}.Debug|x64.ActiveCfg = Debug|Any CPU + {4AB96380-C0D3-4746-87FF-D5FF0AFF1AE3}.Debug|x64.Build.0 = Debug|Any CPU + {4AB96380-C0D3-4746-87FF-D5FF0AFF1AE3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4AB96380-C0D3-4746-87FF-D5FF0AFF1AE3}.Release|Any CPU.Build.0 = Release|Any CPU + {4AB96380-C0D3-4746-87FF-D5FF0AFF1AE3}.Release|x64.ActiveCfg = Release|Any CPU + {4AB96380-C0D3-4746-87FF-D5FF0AFF1AE3}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 7aaab61fe50b3f9e452ef87d108a65b6761b97bd Mon Sep 17 00:00:00 2001 From: xien <2383759126@qq.com> Date: Thu, 18 Apr 2024 18:34:11 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ezperm/ezperm.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Ezperm/ezperm.cs b/Ezperm/ezperm.cs index ba677a2df..d977e29cf 100644 --- a/Ezperm/ezperm.cs +++ b/Ezperm/ezperm.cs @@ -19,7 +19,9 @@ public class Ezperm : TerrariaPlugin internal static Configuration Config; public Ezperm(Main game) : base(game) { - } + LoadConfig(); + + } private static void LoadConfig() { From 4420b8303bf9b2fe6426affc0cc8593cd868cb3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=82=9D=E5=B8=9D=E7=86=99=E6=81=A9?= <111548550+THEXN@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:35:19 +0800 Subject: [PATCH 6/7] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0938cb7a7..c21defcb0 100644 --- a/README.md +++ b/README.md @@ -72,3 +72,4 @@ | [AdditionalPylons](AdditionalPylons/README.md) | 放置更多晶塔 | 无 | | [History](History/README.md) | 历史图格记录 | 无 | | [Invincibility](Invincibility/README.md) | 限时无敌 | 无 | +| [ezperm](ezperm/README.md) | 批量改权限 | 无 | From 864be8f3a794d6b4bebc4fdcf95be2176b4cb16c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=82=9D=E5=B8=9D=E7=86=99=E6=81=A9?= <111548550+THEXN@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:36:35 +0800 Subject: [PATCH 7/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c21defcb0..cf85eabf0 100644 --- a/README.md +++ b/README.md @@ -72,4 +72,4 @@ | [AdditionalPylons](AdditionalPylons/README.md) | 放置更多晶塔 | 无 | | [History](History/README.md) | 历史图格记录 | 无 | | [Invincibility](Invincibility/README.md) | 限时无敌 | 无 | -| [ezperm](ezperm/README.md) | 批量改权限 | 无 | +| [Ezperm](Ezperm/README.md) | 批量改权限 | 无 |