-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuicideCommandMain.cs
More file actions
108 lines (88 loc) · 3.27 KB
/
SuicideCommandMain.cs
File metadata and controls
108 lines (88 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#nullable enable
using CommandSystem;
using LabApi.Features;
using LabApi.Features.Wrappers;
using LabApi.Loader;
using LabApi.Loader.Features.Plugins;
using System;
using PlayerStatsSystem;
namespace LabAPI_SuicideCommand;
public sealed class SuicideCommandMain : Plugin
{
private static readonly SuicideCommandConfig DefaultConfig = new();
public static SuicideCommandMain? MainSingleton { get; private set; }
public override string Name => "Suicide Command Plugin";
public override string Description => "Player suicide command plugin";
public override string Author => "TASA-Ed Studio";
public override Version Version => new(1, 1, 0, 0);
public override Version RequiredApiVersion => new(LabApiProperties.CompiledVersion);
public SuicideCommandConfig? Config { get; private set; } = DefaultConfig;
public override void LoadConfigs()
{
base.LoadConfigs();
Config = this.LoadConfig<SuicideCommandConfig>("configs.yml") ?? DefaultConfig;
SuicideCommand.UpdateConfig(Config);
}
public override void Enable()
{
MainSingleton = this;
}
public override void Disable()
{
SuicideCommand.UpdateConfig(null);
Config = null;
MainSingleton = null;
}
/// <summary>
/// 注册一个允许玩家瞬间杀死自己的指令。
/// </summary>
[CommandHandler(typeof(ClientCommandHandler))]
public sealed class SuicideCommand : ICommand
{
private static SuicideCommandConfig _config = DefaultConfig;
public string Command => "suicide";
public string[] Aliases => _config.CommandAlias;
public string Description => _config.CommandDescription;
internal static void UpdateConfig(SuicideCommandConfig? config)
{
_config = config ?? DefaultConfig;
}
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
var player = Player.Get(sender);
if (player == null)
{
// 非玩家
response = _config.CommandResponseNotPlayer;
return false;
}
if (!player.IsAlive)
{
// 玩家未存活
response = _config.CommandResponseNotAlive;
return false;
}
if (player.IsSCP)
Announcer.ScpTermination(player, new UniversalDamageHandler());
// 杀死玩家
if (player.Kill(_config.CauseOfDeath))
{
// 成功
response = _config.CommandResponseSuccess;
return true;
}
// 失败
response = "failed to commit suicide.";
return false;
}
}
}
public sealed class SuicideCommandConfig
{
public string[] CommandAlias { get; set; } = ["killme", "killself"];
public string CommandDescription { get; set; } = "Suicide command";
public string CommandResponseNotPlayer { get; set; } = "You're not a player.";
public string CommandResponseNotAlive { get; set; } = "You're not alive.";
public string CauseOfDeath { get; set; } = "He/she committed suicide~";
public string CommandResponseSuccess { get; set; } = "Now you dead~";
}