Skip to content

Commit

Permalink
Merge pull request #28 from YongAn404/master
Browse files Browse the repository at this point in the history
代码优化
  • Loading branch information
XLittleLeft authored Dec 10, 2024
2 parents b7271bb + ccaac31 commit e1d2138
Show file tree
Hide file tree
Showing 31 changed files with 198 additions and 352 deletions.
2 changes: 1 addition & 1 deletion HelpSense/API/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace HelpSense.API
{
public static class API
{
public static List<string> TimerHidden { get; } = new List<string>();
public static List<string> TimerHidden { get; } = [];

public static bool TryGetLog(string id, out PlayerLog log)
{
Expand Down
19 changes: 1 addition & 18 deletions HelpSense/API/Extensions/StringBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
using GameCore;
using HelpSense.API.Features;
using MapGeneration.Distributors;
using PlayerRoles;
using PlayerRoles.PlayableScps.Scp079;
using PluginAPI.Core;
using Respawning;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using static HelpSense.API.Features.TimerView;
using HelpSense.Helper;

namespace HelpSense.API.Extensions
namespace HelpSense.API.Extensions
{
public static class StringBuilderExtensions
{
Expand Down
8 changes: 1 addition & 7 deletions HelpSense/API/Features/Pool/IPool.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HelpSense.API.Features.Pool
namespace HelpSense.API.Features.Pool
{
public interface IPool<T>
{
Expand Down
41 changes: 19 additions & 22 deletions HelpSense/API/Features/TimerView.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using HelpSense.API.Extensions;
using HelpSense.ConfigSystem;
using HelpSense.ConfigSystem;
using PluginAPI.Core;
using Respawning;
using Serialization;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HelpSense.API.Features
{
Expand Down Expand Up @@ -64,27 +60,28 @@ public static void GetNew(string name)
Log.Debug($"{name} 成功加载!", Plugin.Instance.Config.Debug);
}

/* public string GetText(int? spectatorCount = null)
{
StringBuilder.Clear();
StringBuilder.Append(
RespawnManager.Singleton._curSequence is not RespawnManager.RespawnSequencePhase.PlayingEntryAnimations or RespawnManager.RespawnSequencePhase.SpawningSelectedTeam
? BeforeRespawnString
: DuringRespawnString);
/* public string GetText(int? spectatorCount = null)
{
StringBuilder.Clear();
StringBuilder.Append(
RespawnManager.Singleton._curSequence is not RespawnManager.RespawnSequencePhase.PlayingEntryAnimations or RespawnManager.RespawnSequencePhase.SpawningSelectedTeam
? BeforeRespawnString
: DuringRespawnString);
StringBuilder.SetAllProperties(spectatorCount);
StringBuilder.Replace('{', '[').Replace('}', ']');
StringBuilder.SetAllProperties(spectatorCount);
StringBuilder.Replace('{', '[').Replace('}', ']');
HintInterval++;
if (HintInterval == Properties.HintInterval)
{
HintInterval = 0;
IncrementHintIndex();
}
HintInterval++;
if (HintInterval == Properties.HintInterval)
{
HintInterval = 0;
IncrementHintIndex();
}
return StringBuilder.ToString();
}*/
return StringBuilder.ToString();
}*/

[Obsolete("SCP:SL 14.0 Obsolete", false)]
private void IncrementHintIndex()
{
HintIndex++;
Expand Down
5 changes: 1 addition & 4 deletions HelpSense/API/InfoExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

namespace HelpSense.API
{
using System;
using System.Linq;
using HelpSense.API.Serialization;
using HelpSense.ConfigSystem;
using HelpSense.Helper;
using MEC;
using PlayerRoles;
using PluginAPI.Core;
using System;

public static class InfoExtension
{
Expand Down
6 changes: 3 additions & 3 deletions HelpSense/API/Serialization/PlayerLog.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using LiteDB;
using LiteDB;
using System;

namespace HelpSense.API.Serialization
{
Expand All @@ -11,7 +11,7 @@ public class PlayerLog
public DateTime LastLeftTime { get; set; }
public int PlayedTimes { get; set; }
public int PlayerKills { get; set; }
public int PlayerDeath { get; set; }
public int PlayerDeath { get; set; }
public int PlayerSCPKills { get; set; }
public float PlayerDamage { get; set; }
public int RolePlayed { get; set; }
Expand Down
12 changes: 2 additions & 10 deletions HelpSense/Commands/ChatCommand/AcCommand.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using CommandSystem;
using HelpSense.Helper;
using HelpSense.Helper.Chat;
using PluginAPI.Core;
using System;
using System.Linq;

namespace HelpSense.Commands.ChatCommand
{
Expand All @@ -12,7 +10,7 @@ public class AcCommand : ICommand
{
public string Command => "AC";

public string[] Aliases => new[]{ "私聊管理" };
public string[] Aliases => ["私聊管理"];

public string Description => "私聊管理";

Expand All @@ -32,13 +30,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
return false;
}

if (arguments.At( 0).Contains("<"))
{
response = "包含敏感字符";
return false;
}

ChatHelper.SendMessage(player, ChatMessage.MessageType.AdminPrivateChat, string.Join(" ", arguments));
ChatHelper.SendMessage(player, ChatMessage.MessageType.AdminPrivateChat, $"<noparse>{string.Join(" ", arguments)}</noparse>");

Log.Info(player.Nickname + " 发送了 " + arguments.At(0));
response = "发送成功";
Expand Down
12 changes: 2 additions & 10 deletions HelpSense/Commands/ChatCommand/BcCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using CommandSystem;
using HelpSense.Helper;
using HelpSense.Helper.Chat;
using PlayerRoles;
using PluginAPI.Core;
using System;

Expand All @@ -12,7 +10,7 @@ public class BcCommand : ICommand
{
public string Command => "BC";

public string[] Aliases => new[]{"广播"};
public string[] Aliases => ["广播"];

public string Description => "全服聊天";

Expand All @@ -32,13 +30,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
return false;
}

if (arguments.At(0).Contains("<"))
{
response = "包含敏感字符";
return false;
}

ChatHelper.SendMessage(player, ChatMessage.MessageType.BroadcastChat, string.Join(" ", arguments));
ChatHelper.SendMessage(player, ChatMessage.MessageType.BroadcastChat, $"<noparse>{string.Join(" ", arguments)}</noparse>");

Log.Info(player.Nickname + " 发送了 " + arguments.At(0));
response = "发送成功";
Expand Down
12 changes: 2 additions & 10 deletions HelpSense/Commands/ChatCommand/CCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using CommandSystem;
using HelpSense.Helper;
using HelpSense.Helper.Chat;
using PlayerRoles;
using PluginAPI.Core;
using System;

Expand All @@ -12,7 +10,7 @@ public class CCommand : ICommand
{
public string Command => "C";

public string[] Aliases => new[]{"队伍广播"};
public string[] Aliases => ["CC", "队伍广播"];

public string Description => "队伍聊天";

Expand All @@ -32,13 +30,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
return false;
}

if (arguments.At(0).Contains("<"))
{
response = "包含敏感字符";
return false;
}

ChatHelper.SendMessage(player, ChatMessage.MessageType.TeamChat, string.Join(" ", arguments));
ChatHelper.SendMessage(player, ChatMessage.MessageType.TeamChat, $"<noparse>{string.Join(" ", arguments)}</noparse>");

Log.Info(player.Nickname + " 发送了 " + arguments.At(0));

Expand Down
4 changes: 2 additions & 2 deletions HelpSense/Commands/InfoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public class InfoCommand : ICommand
{
public string Command => "Info";

public string[] Aliases => new[] { "info" };
public string[] Aliases => ["info"];

public string Description => "查询在本服务器游玩的时间和击杀人数";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
Player player;

if(sender is null || (player = Player.Get(sender)) is null)
if (sender is null || (player = Player.Get(sender)) is null)
{
response = "执行指令时发生错误,请稍后重试";
return false;
Expand Down
8 changes: 4 additions & 4 deletions HelpSense/Commands/RescueCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ public class RescueCommand : ICommand
{
public string Command => "ZiJiu";

public string[] Aliases => new[] { "Rescue", "ZJ" };
public string[] Aliases => ["Rescue", "ZJ"];

public string Description => "卡虚空自救";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
Player player;

if(sender is null || (player = Player.Get(sender)) is null)
if (sender is null || (player = Player.Get(sender)) is null)
{
response = "执行指令时发生错误,请稍后再试";
return false;
}

WaypointBase.GetRelativePosition(player.Position, out byte id, out _);

if (!player.IsAlive ||
if (!player.IsAlive ||
player.Zone is not MapGeneration.FacilityZone.None ||
!WaypointBase.TryGetWaypoint(id, out WaypointBase waypoint) ||
waypoint is ElevatorWaypoint)
Expand All @@ -50,7 +50,7 @@ player.Zone is not MapGeneration.FacilityZone.None ||
player.IsGodModeEnabled = false;
});
}
catch(Exception ex)
catch (Exception ex)
{
player.IsGodModeEnabled = false;
Log.Error(ex.ToString());
Expand Down
2 changes: 1 addition & 1 deletion HelpSense/Commands/Timer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Timer : ICommand
{
public string Command => "timer";

public string[] Aliases => Array.Empty<string>();
public string[] Aliases => [];

public string Description => "显示或者关闭刷新时间";

Expand Down
8 changes: 4 additions & 4 deletions HelpSense/Commands/VersionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ public class VersionCommand : ICommand
{
public string Command => "Version";

public string[] Aliases => new[]{"VersionInfo", "VI"};
public string[] Aliases => ["VersionInfo", "VI"];

public string Description => "查询HelpSense插件版本和信息";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
var config = Plugin.Instance.Config;

var sb = StringBuilderPool.Pool.Get();

//Version and update time
Expand Down Expand Up @@ -47,10 +47,10 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

response = sb.ToString();
StringBuilderPool.Pool.Return(sb);

return true;
}

public string BoolTranslate(bool value) => value? "✔":"✖";
public string BoolTranslate(bool value) => value ? "✔" : "✖";
}
}
13 changes: 6 additions & 7 deletions HelpSense/ConfigSystem/Config.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.ComponentModel;
using HelpSense.Helper.Lobby;
using PlayerRoles;
using System.Collections.Generic;
using HelpSense.Helper;
using PluginAPI.Helpers;
using System.IO;
using System;
using HelpSense.Helper.Lobby;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;

namespace HelpSense.ConfigSystem
{
Expand Down Expand Up @@ -92,7 +91,7 @@ public class Config
[Description("启用修改SCP血量系统")]
public bool EnableChangeSCPHPSystem { get; set; } = true;
[Description("SCP173,SCP939,SCP049,SCP049-2,SCP096,SCP106血量")]
public List<float> SCPsHP { get; set; } = new List<float> { 4200,2700,2200,400,2500,2200};
public List<float> SCPsHP { get; set; } = new List<float> { 4200, 2700, 2200, 400, 2500, 2200 };

// /////////////////////////////////////////////////
[Description("启用.bc和.c聊天系统")]
Expand Down Expand Up @@ -191,7 +190,7 @@ public class Config

/// //////////////////////////////////////////////////////////
[Description("SCP-191")]
public bool SCP191 { get;set; } = true;
public bool SCP191 { get; set; } = true;
[Description("子弹对SCP-191造成的单发伤害")]
public float SCP191Ammo { get; set; } = 10;
[Description("SCP-073")]
Expand Down
7 changes: 1 addition & 6 deletions HelpSense/ConfigSystem/TranslateConfig.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using HelpSense.Helper;
using HelpSense.Helper.Chat;
using HelpSense.Helper.Chat;
using PlayerRoles;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HelpSense.ConfigSystem
{
Expand Down
Loading

0 comments on commit e1d2138

Please sign in to comment.