Skip to content
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

添加插件:Invincibility 限时无敌 #30

Merged
merged 8 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AutoBroadcast/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{
"Broadcasts": [
{
"Name": "E实例广播",
"Name": "实例广播",
"Enabled": false,
"Messages": [
"这是一条广播",
Expand Down
2 changes: 1 addition & 1 deletion AutoTeam/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

| 语法 | 权限 | 说明 |
| -------------- | :-----------------: | :------: |
| /autoteam或/at | autoteam.toggle | 开关自动队伍功能 |
| /autoteam 或 /at | autoteam.toggle | 开关自动队伍功能 |
| 无 | noautoteam | 有该权限不会被自动分配队伍 |

## 配置
Expand Down
2 changes: 1 addition & 1 deletion Back/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

| 语法 | 权限 | 说明 |
| -------------- | :-----------------: | :------: |
| back | back | 返回死亡地点|
| /back | back | 返回死亡地点|

## 配置

Expand Down
2 changes: 1 addition & 1 deletion BridgeBuilder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

| 语法 | 权限 | 说明 |
| -------------- | :-----------------: | :------: |
| bridgebuilder.bridge | bridge 或 桥来 | 快速铺桥指令|
| /bridge 或 /桥来 | bridgebuilder.bridge | 快速铺桥指令|

## 配置

Expand Down
69 changes: 69 additions & 0 deletions Ezperm/Configuration.cs
Original file line number Diff line number Diff line change
@@ -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<string> AddPermissions { get; set; }
[JsonProperty("删除的权限")]
public List<string> DelPermissions { get; set; }
}

internal class Configuration
{
public static readonly string FilePath = Path.Combine(TShock.SavePath, "ezperm.json");

public List<GroupInfo> 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<GroupInfo>
{
new GroupInfo
{
Name = "default",
AddPermissions = new List<string> { "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<string> { "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<Configuration>(sr.ReadToEnd());
return cf;
}
}
}
}
}

46 changes: 46 additions & 0 deletions Ezperm/README.md
Original file line number Diff line number Diff line change
@@ -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官方群等
77 changes: 77 additions & 0 deletions Ezperm/ezperm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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)
{
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(Ezperm).Name);
}
public override void Initialize()
{
GeneralHooks.ReloadEvent += ReloadConfig;
Commands.ChatCommands.Add(new Command(new List<string>
{
"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)}");
}
}
}
}
5 changes: 5 additions & 0 deletions Ezperm/ezperm.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\template.targets" />

</Project>
56 changes: 56 additions & 0 deletions Invincibility/Configuration.cs
Original file line number Diff line number Diff line change
@@ -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<Configuration>(sr.ReadToEnd());
return cf;
}
}
}
}
}
3 changes: 3 additions & 0 deletions Invincibility/Invincibility.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\template.targets" />
</Project>
Loading
Loading