-
Notifications
You must be signed in to change notification settings - Fork 30
更新:白名单插件,删除不必要的自定义提示语 #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b23ab03
更新:阻止地牢神庙插件支持醉酒了
THEXN b1c7e75
Merge branch 'Controllerdestiny:master' into master
THEXN 88e3b5c
添加插件:BetterWhitelist 更好的白名单,下次重写,先这样
THEXN 4731ae8
Update README.md
THEXN ffbf14b
Update README.md
THEXN b9701d3
Update README.md
THEXN c27776e
Merge branch 'Controllerdestiny:master' into master
THEXN 3b5757d
Merge branch 'Controllerdestiny:master' into master
THEXN 2b609bf
更新:白名单插件,删除不必要的自定义提示语
THEXN File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
添加插件:BetterWhitelist 更好的白名单,下次重写,先这样
- Loading branch information
commit 88e3b5c2b3a09c85db0ed7b69a12ac01ee9cd3a0
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace BetterWhitelist | ||
| { | ||
| public class BConfig | ||
| { | ||
| [JsonProperty("插件开关")] | ||
| public bool Disabled { get; set; } | ||
| [JsonProperty("白名单玩家")] | ||
| public List<string> WhitePlayers = new List<string>(); | ||
| public static BConfig Load(string path) | ||
| { | ||
| BConfig result; | ||
| if (File.Exists(path)) | ||
| { | ||
| result = JsonConvert.DeserializeObject<BConfig>(File.ReadAllText(path)); | ||
| } | ||
| else | ||
| { | ||
| result = new BConfig | ||
| { | ||
| Disabled = false | ||
| }; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <Import Project="..\template.targets" /> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace BetterWhitelist | ||
| { | ||
| public class Translation | ||
| { | ||
| public static Translation Load(string path) | ||
| { | ||
| return new Translation | ||
| { | ||
| language = | ||
| { | ||
| { | ||
| "删除成功提示", | ||
| "删除成功!" | ||
| }, | ||
| { | ||
| "添加成功提示", | ||
| "添加成功!" | ||
| }, | ||
| { | ||
| "启用成功提示", | ||
| "启用成功!" | ||
| }, | ||
| { | ||
| "禁用成功提示", | ||
| "禁用成功!" | ||
| }, | ||
| { | ||
| "重载成功提示", | ||
| "重载成功!" | ||
| }, | ||
| { | ||
| "添加失败提示", | ||
| "添加失败! 该玩家已经在白名单中" | ||
| }, | ||
| { | ||
| "删除失败提示", | ||
| "删除失败 ! 该玩家不在白名单中" | ||
| }, | ||
| { | ||
| "启用失败提示", | ||
| "启用失败 ! 插件已打开" | ||
| }, | ||
| { | ||
| "禁用失败提示", | ||
| "禁用失败 ! 插件已关闭" | ||
| }, | ||
| { | ||
| "删除白名单后断开玩家连接提示", | ||
| "你已被移出白名单!" | ||
| }, | ||
| { | ||
| "未知指令提示文本", | ||
| "用法: 输入 /bwl help 显示帮助信息." | ||
| }, | ||
| { | ||
| "未启用插件提示", | ||
| "插件开关已被禁用,请检查配置文件!" | ||
| }, | ||
| { | ||
| "全部的指令帮助提示", | ||
| "/bwl help, 显示帮助信息\n/bwl add {name}, 添加玩家名到白名单中\n/bwl del {name}, 将玩家移出白名单\n/bwl list, 显示白名单上的全部玩家\n/bwl true, 启用插件\n/bwl false, 关闭插件\n/bwl reload, 重载插件" | ||
| }, | ||
| { | ||
| "连接时不在白名单提示", | ||
| "你不在服务器白名单中!" | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| public Dictionary<string, string> language = new Dictionary<string, string>(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,214 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using Newtonsoft.Json; | ||
| using Terraria; | ||
| using TerrariaApi.Server; | ||
| using TShockAPI; | ||
|
|
||
| namespace BetterWhitelist | ||
| { | ||
| [ApiVersion(2, 1)] | ||
| public class Main : TerrariaPlugin | ||
| { | ||
| public Main(Terraria.Main game) : base(game) | ||
| { | ||
| Order = 9999; | ||
| } | ||
|
|
||
| public override string Name => "BetterWhitelist"; | ||
|
|
||
| public override Version Version => new Version(2, 3); | ||
| public override string Author => "豆沙,肝帝熙恩修改"; | ||
|
|
||
| public override string Description => "通过检查玩家姓名的玩家白名单"; | ||
| public override void Initialize() | ||
| { | ||
| string path = Path.Combine(TShock.SavePath, "BetterWhitelist"); | ||
| if (!Directory.Exists(path)) | ||
| { | ||
| Directory.CreateDirectory(path); | ||
| } | ||
|
|
||
| this.Load(); | ||
|
|
||
| Commands.ChatCommands.Add(new Command("bwl.use", new CommandDelegate(this.bwl), new string[] { "bwl" })); | ||
| ServerApi.Hooks.ServerJoin.Register(this, OnJoin); | ||
| ServerApi.Hooks.ServerLeave.Register(this,OnLeave); | ||
| } | ||
|
|
||
|
|
||
| private void OnLeave(LeaveEventArgs args) | ||
| { | ||
| TSPlayer tsplayer = new TSPlayer(args.Who); | ||
| players.Remove(tsplayer.Name); | ||
| } | ||
| private void bwl(CommandArgs args) | ||
| { | ||
| if (args.Parameters.Count < 1) | ||
| { | ||
| args.Player.SendErrorMessage(_translation.language["未知指令提示文本"]); | ||
| return; | ||
| } | ||
|
|
||
| string command = args.Parameters[0]; | ||
|
|
||
| switch (command.ToLowerInvariant()) | ||
| { | ||
| case "help": | ||
| args.Player.SendInfoMessage("-------[BetterWhitelist]-------"); | ||
| args.Player.SendInfoMessage(_translation.language["全部的指令帮助提示"]); | ||
| break; | ||
|
|
||
| case "list": | ||
| foreach (string msg in _config.WhitePlayers) | ||
| { | ||
| args.Player.SendInfoMessage(msg); | ||
| } | ||
| break; | ||
|
|
||
| case "false": | ||
| if (Main._config.Disabled) | ||
| { | ||
| args.Player.SendErrorMessage(Main._translation.language["禁用失败提示"]); | ||
| } | ||
| else | ||
| { | ||
| Main._config.Disabled = true; | ||
| args.Player.SendSuccessMessage(Main._translation.language["禁用成功提示"]); | ||
| File.WriteAllText(Main.config_path, JsonConvert.SerializeObject(Main._config, Formatting.Indented)); | ||
| } | ||
| break; | ||
|
|
||
| case "true": | ||
| if (!Main._config.Disabled) | ||
| { | ||
| args.Player.SendErrorMessage(Main._translation.language["启用失败提示"]); | ||
| } | ||
| else | ||
| { | ||
| Main._config.Disabled = false; | ||
| args.Player.SendSuccessMessage(Main._translation.language["启用成功提示"]); | ||
|
|
||
| if (Main.players.Count > 0) | ||
| { | ||
| if (Main._config.WhitePlayers.Count > 0) | ||
| { | ||
| foreach (TSPlayer tsplayer in Main.players.Values.Where(player => !Main._config.WhitePlayers.Contains(player.Name))) | ||
| { | ||
| tsplayer.Disconnect(Main._translation.language["连接时不在白名单提示"]); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| foreach (TSPlayer tsplayer in Main.players.Values) | ||
| { | ||
| tsplayer.Disconnect(Main._translation.language["连接时不在白名单提示"]); | ||
| } | ||
| } | ||
| } | ||
| File.WriteAllText(Main.config_path, JsonConvert.SerializeObject(Main._config, Formatting.Indented)); | ||
| } | ||
| break; | ||
|
|
||
| case "add": | ||
| if (Main._config.Disabled) | ||
| { | ||
| args.Player.SendErrorMessage(Main._translation.language["未启用插件提示"]); | ||
| } | ||
| else | ||
| { | ||
| string playerNameToAdd = args.Parameters.ElementAtOrDefault(1); | ||
|
|
||
| if (playerNameToAdd != null && !Main._config.WhitePlayers.Contains(playerNameToAdd)) | ||
| { | ||
| Main._config.WhitePlayers.Add(playerNameToAdd); | ||
| args.Player.SendSuccessMessage(Main._translation.language["添加成功提示"]); | ||
| File.WriteAllText(Main.config_path, JsonConvert.SerializeObject(Main._config, Formatting.Indented)); | ||
| } | ||
| else | ||
| { | ||
| args.Player.SendSuccessMessage(Main._translation.language["添加失败提示"]); | ||
| } | ||
| } | ||
| break; | ||
|
|
||
| case "reload": | ||
| Main._config = JsonConvert.DeserializeObject<BConfig>(File.ReadAllText(Main.config_path)); | ||
| Main._translation = JsonConvert.DeserializeObject<Translation>(File.ReadAllText(Main.translation_path)); | ||
| args.Player.SendSuccessMessage(Main._translation.language["重载成功提示"]); | ||
| break; | ||
|
|
||
| case "del": | ||
| if (Main._config.Disabled) | ||
| { | ||
| args.Player.SendErrorMessage(Main._translation.language["未启用插件提示"]); | ||
| } | ||
| else | ||
| { | ||
| string playerNameToDelete = args.Parameters.ElementAtOrDefault(1); | ||
|
|
||
| if (playerNameToDelete != null && Main._config.WhitePlayers.Contains(playerNameToDelete)) | ||
| { | ||
| Main._config.WhitePlayers.Remove(playerNameToDelete); | ||
| args.Player.SendSuccessMessage(Main._translation.language["删除成功提示"]); | ||
| File.WriteAllText(Main.config_path, JsonConvert.SerializeObject(Main._config, Formatting.Indented)); | ||
|
|
||
| if (Main.players.ContainsKey(playerNameToDelete)) | ||
| { | ||
| Main.players[playerNameToDelete].Disconnect(Main._translation.language["删除白名单后断开玩家连接提示"]); | ||
| } | ||
| } | ||
| } | ||
| break; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| private void OnJoin(JoinEventArgs args) | ||
| { | ||
| TSPlayer tsplayer = new TSPlayer(args.Who); | ||
| Main.players.Add(tsplayer.Name, tsplayer); | ||
|
|
||
| if (!Main._config.Disabled && !Main._config.WhitePlayers.Contains(tsplayer.Name)) | ||
| { | ||
| tsplayer.Disconnect(Main._translation.language["连接时不在白名单提示"]); | ||
| } | ||
| else if (Main._config.Disabled) | ||
| { | ||
| TShock.Log.ConsoleInfo(Main._translation.language["未启用插件提示"]); | ||
| } | ||
| } | ||
|
|
||
| private void Load() | ||
| { | ||
| Main._config = BConfig.Load(Main.config_path); | ||
| Main._translation = Translation.Load(Main.translation_path); | ||
| File.WriteAllText(Main.config_path, JsonConvert.SerializeObject(Main._config, Formatting.Indented)); | ||
| File.WriteAllText(Main.translation_path, JsonConvert.SerializeObject(Main._translation, Formatting.Indented)); | ||
| } | ||
|
|
||
| protected override void Dispose(bool disposing) | ||
| { | ||
| if (disposing) | ||
| { | ||
| ServerApi.Hooks.ServerJoin.Deregister(this, OnJoin); | ||
| ServerApi.Hooks.ServerLeave.Deregister(this, OnLeave); | ||
| } | ||
| base.Dispose(disposing); | ||
| } | ||
|
|
||
| public static string bwldir = Path.Combine(TShock.SavePath, "BetterWhitelist"); | ||
|
|
||
| public static string config_path = Path.Combine(Main.bwldir, "config.json"); | ||
|
|
||
| public static string translation_path = Path.Combine(Main.bwldir, "language.json"); | ||
|
|
||
| public static BConfig _config; | ||
|
|
||
| public static Translation _translation; | ||
|
|
||
| public static Dictionary<string, TSPlayer> players = new Dictionary<string, TSPlayer>(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # BetterWhitelist 更好的白名单 | ||
|
|
||
| - 作者: 豆沙,肝帝熙恩修改 | ||
| - 出处: [gitee](https://gitee.com/Crafty/BetterWhitelist) | ||
| - 将玩家名字加入白名单,仅在白名单内的玩家可进入游戏 | ||
|
|
||
| ## 更新日志 | ||
|
|
||
| ``` | ||
| 暂无 | ||
| ``` | ||
|
|
||
| ## 指令 | ||
| | 语法 | 权限 | 说明 | | ||
| | -------------------- | -------- | --------------------- | | ||
| | `/bwl help` | `bwl.use`| 显示帮助信息 | | ||
| | `/bwl add {name}` | `bwl.use`| 添加玩家名到白名单中 | | ||
| | `/bwl del {name}` | `bwl.use`| 将玩家移出白名单 | | ||
| | `/bwl list` | `bwl.use`| 显示白名单上的全部玩家 | | ||
| | `/bwl true` | `bwl.use`| 启用插件 | | ||
| | `/bwl false` | `bwl.use`| 关闭插件 | | ||
| | `/bwl reload` | `bwl.use`| 重载插件 | | ||
|
|
||
| ## 配置 | ||
| > 配置文件位置:tshock/BetterWhitelist/config.json | ||
| ```json | ||
| { | ||
| "启用白名单": true, | ||
|
|
||
| "白名单": [ | ||
| "豆沙", | ||
| "熙恩" | ||
| ] | ||
| } | ||
| ``` | ||
| ## 反馈 | ||
| - 优先发issued -> 共同维护的插件库:https://github.com/Controllerdestiny/TShockPlugin | ||
| - 次优先:TShock官方群:816771079 | ||
| - 大概率看不到但是也可以:国内社区trhub.cn ,bbstr.net , tr.monika.love |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.