forked from deadfacerip/GlobalBan
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGlobalBan.cs
59 lines (51 loc) · 2.2 KB
/
GlobalBan.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
using Rocket.Core.Plugins;
using System.Collections.Generic;
using Rocket.API.DependencyInjection;
using Rocket.API.Eventing;
using Rocket.Core.Player.Events;
namespace fr34kyn01535.GlobalBan
{
public class GlobalBan : Plugin<GlobalBanConfiguration>, IEventListener<PlayerPreConnectEvent>
{
public GlobalBan(IDependencyContainer container) : base("GlobalBan", container)
{
}
public DatabaseManager Database;
public static Dictionary<string, string> Players = new Dictionary<string, string>();
protected override void OnLoad(bool isFromReload)
{
Database = new DatabaseManager(this);
}
public override Dictionary<string, string> DefaultTranslations => new Dictionary<string, string>
{
{"default_banmessage","you were banned by {0} on {1} for {2} seconds, contact the staff if you feel this is a mistake."},
{"command_generic_invalid_parameter","Invalid parameter"},
{"command_generic_player_not_found","Player not found"},
{"command_ban_public_reason", "The player {0} was banned for: {1}"},
{"command_ban_public","The player {0} was banned"},
{"command_ban_private_default_reason","you were banned from the server"},
{"command_kick_public_reason", "The player {0} was kicked for: {1}"},
{"command_kick_public","The player {0} was kicked"},
{"command_kick_private_default_reason","you were kicked from the server"},
};
public static KeyValuePair<string, string>? GetPlayer(string search)
{
foreach (KeyValuePair<string, string> pair in Players)
{
if (pair.Key.ToLower().Contains(search.ToLower()) || pair.Value.ToLower().Contains(search.ToLower()))
{
return pair;
}
}
return null;
}
public void HandleEvent(IEventEmitter emitter, PlayerPreConnectEvent @event)
{
if (Database.IsBanned(@event.Player))
{
@event.RejectionReason = "You have been banned.";
@event.IsCancelled = true;
}
}
}
}