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

添加插件:SimultaneousUseFix 解决卡双锤卡星旋机枪之类的问题 #48

Merged
merged 8 commits into from
Apr 24, 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
12 changes: 11 additions & 1 deletion Plugin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PersonalPermission", "Perso
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ItemPreserver", "ItemPreserver\ItemPreserver.csproj", "{403509B6-B74A-4E42-A044-EDC8F31DDF6D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Economics.Regain", "Economics.Regain\Economics.Regain.csproj", "{A0146C0E-B33C-49F6-A8FC-94EC67193A03}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Economics.Regain", "Economics.Regain\Economics.Regain.csproj", "{A0146C0E-B33C-49F6-A8FC-94EC67193A03}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimultaneousUseFix", "SimultaneousUseFix\SimultaneousUseFix.csproj", "{32A38583-1944-4542-8424-4427D16491FE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -516,6 +518,14 @@ Global
{A0146C0E-B33C-49F6-A8FC-94EC67193A03}.Release|Any CPU.Build.0 = Release|Any CPU
{A0146C0E-B33C-49F6-A8FC-94EC67193A03}.Release|x64.ActiveCfg = Release|Any CPU
{A0146C0E-B33C-49F6-A8FC-94EC67193A03}.Release|x64.Build.0 = Release|Any CPU
{32A38583-1944-4542-8424-4427D16491FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{32A38583-1944-4542-8424-4427D16491FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32A38583-1944-4542-8424-4427D16491FE}.Debug|x64.ActiveCfg = Debug|Any CPU
{32A38583-1944-4542-8424-4427D16491FE}.Debug|x64.Build.0 = Debug|Any CPU
{32A38583-1944-4542-8424-4427D16491FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32A38583-1944-4542-8424-4427D16491FE}.Release|Any CPU.Build.0 = Release|Any CPU
{32A38583-1944-4542-8424-4427D16491FE}.Release|x64.ActiveCfg = Release|Any CPU
{32A38583-1944-4542-8424-4427D16491FE}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@
| [VeinMiner](VeinMiner/README.md) | 连锁挖矿 | 无 |
| [PersonalPermission](PersonalPermission/README.md) | 为玩家单独设置权限 | 无 |
| [ItemPreserver](ItemPreserver/README.md) | 指定物品不消耗 | 无 |
| [SimultaneousUseFix](SimultaneousUseFix/README.md) | 解决卡双锤卡星旋机枪之类的问题|[Chireiden.TShock.Omni](https://github.com/sgkoishi/yaaiomni/releases)|
63 changes: 63 additions & 0 deletions SimultaneousUseFix/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using Newtonsoft.Json;
using TShockAPI;

namespace fixbugpe
{
public class Configuration
{
public static readonly string FilePath = Path.Combine(TShock.SavePath, "解决卡双锤卡星旋机枪之类的问题.json");
private static readonly int[] DefaultExemptItemList = { 205, 206, 207, 1128 };

[JsonProperty("免检测物品列表")]
public int[] ExemptItemList { get; set; }

[JsonProperty("是否杀死")]
public bool KillPlayerOnUse { get; set; } = true;

[JsonProperty("是否上buff")]
public bool ApplyBuffOnUse { get; set; } = false;

[JsonProperty("buff时长(s)")]
public int Bufftime { get; set; } = 60;

[JsonProperty("上什么buff")]
public int[] BuffTypes { get; set; } = { 163, 149 , 23 , 164 };

[JsonProperty("是否踢出")]
public bool KickPlayerOnUse { get; set; } = false;

public Configuration()
{
ExemptItemList = DefaultExemptItemList;
}

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;
}
}
}
}
}
44 changes: 44 additions & 0 deletions SimultaneousUseFix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# SimultaneousUseFix 解决卡双锤卡星旋机枪之类的问题

- 作者: 肝帝熙恩,恋恋
- 出处: 无
- 解决卡双锤卡星旋机枪之类的问题
- 因为一些检测原因,最后一个桶会被判定,所以加了免检测
- 需要前置:https://github.com/sgkoishi/yaaiomni/releases
## 更新日志

```
暂无
```

## 指令

| 语法 | 权限 | 说明 |
| -------------- | :-----------------: | :------: |
| 无 | SimultaneousUseFix | 完全免检权限 |

## 配置

```json
{
"免检测物品列表": [
205,
206,
207,
1128
],
"是否杀死": true,
"是否上buff": false,
"buff时长(s)": 60,
"上什么buff": [
163,
149,
23,
164
],
"是否踢出": false
}
```
## 反馈
- 共同维护的插件库:https://github.com/THEXN/TShockPlugin/
- 国内社区trhub.cn 或 TShock官方群等
94 changes: 94 additions & 0 deletions SimultaneousUseFix/SimultaneousUseFix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using TerrariaApi.Server;
using TShockAPI;
using Terraria;
using System.Collections.Generic;
using TShockAPI.Hooks;
using Microsoft.Xna.Framework;
using Terraria.ID;

namespace fixbugpe
{
[ApiVersion(2, 1)]
public class SimultaneousUseFix : TerrariaPlugin
{
public override string Author => "熙恩,感谢恋恋";
public override string Description => "解决卡双锤,卡星旋机枪之类的问题";
public override string Name => "SimultaneousUseFix";
public override Version Version => new Version(1, 0, 5);
public static Configuration Config;
public bool otherPluginExists = false;

public SimultaneousUseFix(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(SimultaneousUseFix).Name);
}


public override void Initialize()
{
GeneralHooks.ReloadEvent += ReloadConfig;
ServerApi.Plugins.Get<Chireiden.TShock.Omni.Plugin>().Detections.SwapWhileUse += OnSwapWhileUse;
}

private void OnSwapWhileUse(int playerId, int slot)
{
TSPlayer player = TShock.Players[playerId];

if (player != null && !player.HasPermission("SimultaneousUseFix"))
{
Item item = player.TPlayer.inventory[slot];

if (item != null && Config.ExemptItemList.Contains(item.type))
{
return;
}

if (Config.KickPlayerOnUse)
{
TShock.Utils.Broadcast("玩家 " + player.Name + " 因为卡换格子bug被踢出", Color.Green);
player.Kick("因为卡换格子bug被踢出");
}

if (Config.KillPlayerOnUse)
{
TShock.Utils.Broadcast("玩家 " + player.Name + " 因为卡换格子bug被杀死", Color.Green);
player.KillPlayer();
}

if (Config.ApplyBuffOnUse)
{
TShock.Utils.Broadcast("玩家 " + player.Name + " 因为卡换格子bug被上buff", Color.Green);
foreach (int buffType in Config.BuffTypes)
{
player.SetBuff(buffType, Config.Bufftime);
}
}

}
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
ServerApi.Plugins.Get<Chireiden.TShock.Omni.Plugin>().Detections.SwapWhileUse -= OnSwapWhileUse;
}

base.Dispose(disposing);
}
}
}


11 changes: 11 additions & 0 deletions SimultaneousUseFix/SimultaneousUseFix.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<Reference Include="Chireiden.TShock.Omni">
<HintPath>..\lib\Chireiden.TShock.Omni.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
Loading