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

update PermaBuff v1.0.2 加入清理所有buff子命令 #621

Merged
merged 2 commits into from
Dec 22, 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 src/PermaBuff/DB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public static void Delbuff(string Name, int buffid)

public static void ClearTable()
{
database.Query("TRUNCATE Permabuff");
database.Query("DELETE FROM Permabuff");
}
}
45 changes: 36 additions & 9 deletions src/PermaBuff/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Plugin : TerrariaPlugin

public override string Name => Assembly.GetExecutingAssembly().GetName().Name!;

public override Version Version => new Version(1, 0, 1);
public override Version Version => new Version(1, 0, 2);

private readonly string PATH = Path.Combine(TShock.SavePath, "permbuff.json");

Expand All @@ -38,9 +38,9 @@ public override void Initialize()
ServerApi.Hooks.NetGreetPlayer.Register(this, this.OnJoin);
ServerApi.Hooks.ServerLeave.Register(this, this.OnLeave);
ServerApi.Hooks.GameUpdate.Register(this, this.Update);
Commands.ChatCommands.Add(new Command("permabuff.use", this.PAbuff, "permabuff"));
Commands.ChatCommands.Add(new Command("gpermabuff.use", this.GPbuff, "gpermabuff"));
Commands.ChatCommands.Add(new Command("clearbuffs.use", this.Cbuff, "clearbuffs"));
Commands.ChatCommands.Add(new Command("permabuff.use", this.PAbuff, "permabuff","pbuff"));
Commands.ChatCommands.Add(new Command("gpermabuff.use", this.GPbuff, "gpermabuff","gpbuff"));
Commands.ChatCommands.Add(new Command("clearbuffs.use", this.Cbuff, "clearbuffs","cbuff"));
GeneralHooks.ReloadEvent += this._reloadHandler;
}
protected override void Dispose(bool disposing)
Expand Down Expand Up @@ -73,15 +73,42 @@ private void LoadConfig()

private void Cbuff(CommandArgs args)
{
var buffs = Playerbuffs.GetBuffs(args.Player.Name);
if (buffs.Count == 0)
if (args.Parameters.Count == 0)
{
args.Player.SendSuccessMessage("没有永久buff,无需清空");
var buffs = Playerbuffs.GetBuffs(args.Player.Name);
if (buffs.Count == 0)
{
args.Player.SendSuccessMessage("没有永久buff,无需清空");
}
else
{
buffs.Clear();
buffs.TrimExcess();
args.Player.SendSuccessMessage("已清空所有永久buff");
args.Player.SendData(PacketTypes.PlayerBuff, null, args.Player.Index);
}
}

else if (args.Parameters.Count >= 1 && args.Parameters[0].ToLower() == "all")
{
if (args.Player.HasPermission("clearbuffs.admin"))
{
Playerbuffs.PlayerBuffs.Clear();
DB.ClearTable();
args.Player.SendSuccessMessage("已清空所有玩家永久buff");
foreach (var plr in TShock.Players.Where(p => p != null && p.IsLoggedIn && p.Active))
{
plr.SendData(PacketTypes.PlayerBuff, null, plr.Index);
}
}
else
{
args.Player.SendErrorMessage("权限不足,无法执行此命令");
}
}
else
{
buffs.ForEach(x => Playerbuffs.DelBuff(args.Player.Name, x));
args.Player.SendSuccessMessage("已清空所有永久buff");
args.Player.SendErrorMessage("未知参数,请使用 '/clearbuffs' 或 '/cbuff all'");
}
}

Expand Down
15 changes: 10 additions & 5 deletions src/PermaBuff/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@
## 更新日志

```
v 1.0.2
加入清理所有BUFF子命令:/cbuff all

v.1.0.1
- 完善卸载函数
```

## 指令

| 语法 | 权限 | 说明 |
| ------------------------------- | :------------: | :---------------------------------: |
| /permabuff [buffID] | permabuff.use | 给予自身永久 buff(再次使用移除) |
| /gpermabuff [玩家名称] [buffid] | gpermabuff.use | 给予玩家一个永久 buff(再次使用移除) |
| /clearbuffs | clearbuffs.use | 清空自身所有 buff |
| 语法 | 别名 | 权限 | 说明 |
| -------------------------------- | :---: | :--------------: | :--------------------------------------: |
| /permabuff [buffID] | /pbuff | permabuff.use | 给予自身永久 buff(再次使用移除) |
| /gpermabuff [玩家名称] [buffid] | /gpbuff | gpermabuff.use | 给予玩家一个永久 buff(再次使用移除) |
| /clearbuffs | /cbuff | clearbuffs.use | 清空自身所有 buff |
| /clearbuffs all | /cbuff all | clearbuffs.admin | 清空所有玩家 buff |
| /reload | 无 | tshock.cfg.reload | 重载配置文件 |

## 配置
> 配置文件位置:tshock/permbuff.json
Expand Down
Loading