-
Notifications
You must be signed in to change notification settings - Fork 34
/
Plugin.cs
114 lines (102 loc) · 4.36 KB
/
Plugin.cs
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
109
110
111
112
113
114
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using cs2_rockthevote.Features;
using Microsoft.Extensions.DependencyInjection;
using static CounterStrikeSharp.API.Core.Listeners;
namespace cs2_rockthevote
{
public class PluginDependencyInjection : IPluginServiceCollection<Plugin>
{
public void ConfigureServices(IServiceCollection serviceCollection)
{
var di = new DependencyManager<Plugin, Config>();
di.LoadDependencies(typeof(Plugin).Assembly);
di.AddIt(serviceCollection);
serviceCollection.AddScoped<StringLocalizer>();
}
}
public partial class Plugin : BasePlugin, IPluginConfig<Config>
{
public override string ModuleName => "RockTheVote";
public override string ModuleVersion => "1.8.5";
public override string ModuleAuthor => "abnerfs";
public override string ModuleDescription => "https://github.com/abnerfs/cs2-rockthevote";
private readonly DependencyManager<Plugin, Config> _dependencyManager;
private readonly NominationCommand _nominationManager;
private readonly ChangeMapManager _changeMapManager;
private readonly VotemapCommand _votemapManager;
private readonly RockTheVoteCommand _rtvManager;
private readonly TimeLeftCommand _timeLeft;
private readonly NextMapCommand _nextMap;
public Plugin(DependencyManager<Plugin, Config> dependencyManager,
NominationCommand nominationManager,
ChangeMapManager changeMapManager,
VotemapCommand voteMapManager,
RockTheVoteCommand rtvManager,
TimeLeftCommand timeLeft,
NextMapCommand nextMap)
{
_dependencyManager = dependencyManager;
_nominationManager = nominationManager;
_changeMapManager = changeMapManager;
_votemapManager = voteMapManager;
_rtvManager = rtvManager;
_timeLeft = timeLeft;
_nextMap = nextMap;
}
public Config? Config { get; set; }
public string Localize(string prefix, string key, params object[] values)
{
return $"{Localizer[prefix]} {Localizer[key, values]}";
}
public override void Load(bool hotReload)
{
_dependencyManager.OnPluginLoad(this);
RegisterListener<OnMapStart>(_dependencyManager.OnMapStart);
}
[GameEventHandler(HookMode.Post)]
public HookResult OnChat(EventPlayerChat @event, GameEventInfo info)
{
var player = Utilities.GetPlayerFromUserid(@event.Userid);
if (player is not null)
{
var text = @event.Text.Trim().ToLower();
if (text == "rtv")
{
_rtvManager.CommandHandler(player);
}
else if (text.StartsWith("nominate"))
{
var split = text.Split("nominate");
var map = split.Length > 1 ? split[1].Trim() : "";
_nominationManager.CommandHandler(player, map);
}
else if (text.StartsWith("votemap"))
{
var split = text.Split("votemap");
var map = split.Length > 1 ? split[1].Trim() : "";
_votemapManager.CommandHandler(player, map);
}
else if (text.StartsWith("timeleft"))
{
_timeLeft.CommandHandler(player);
}
else if (text.StartsWith("nextmap"))
{
_nextMap.CommandHandler(player);
}
}
return HookResult.Continue;
}
public void OnConfigParsed(Config config)
{
Config = config;
if (Config.Version < 9)
Console.WriteLine("[RockTheVote] please delete it from addons/counterstrikesharp/configs/plugins/RockTheVote and let the plugin recreate it on load");
if (Config.Version < 7)
throw new Exception("Your config file is too old, please delete it from addons/counterstrikesharp/configs/plugins/RockTheVote and let the plugin recreate it on load");
_dependencyManager.OnConfigParsed(config);
}
}
}