-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDsuNaming.cs
100 lines (84 loc) · 3.49 KB
/
DsuNaming.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
using CitizenFX.Core.Native;
using PoliceMP.Client.Services.Interfaces;
using PoliceMP.Core.Client;
using PoliceMP.Core.Client.Commands.Interfaces;
using PoliceMP.Core.Client.Communications.Interfaces;
using PoliceMP.Core.Shared;
using PoliceMP.Shared.Constants;
using System.Threading.Tasks;
namespace PoliceMP.Client.Scripts.Dsu
{
public class DsuNaming : Script
{
private readonly IClientCommunicationsManager _comms;
private readonly ILogger<DsuNaming> _logger;
private readonly ICommandManager _commands;
private readonly INotificationService _notifications;
public DsuNaming(ILogger<DsuNaming> logger, ICommandManager commands, IClientCommunicationsManager comms, INotificationService notifications)
{
_logger = logger;
_commands = commands;
_comms = comms;
_notifications = notifications;
}
protected override async Task OnStartAsync()
{
bool aceAllowed = await _comms.Request<bool>(ServerEvents.FetchDsuAceAllowed, "");
if (aceAllowed)
{
_commands.Register("namedog").HasGreedyArgs().WithHandler(dogName =>
{
if (string.IsNullOrEmpty(dogName))
{
_notifications.Error("K9 System", "Please enter a correct name for your dog.");
return;
}
SetDogName(dogName);
});
_commands.Register("kme").HasGreedyArgs().WithHandler(emoteText =>
{
if (string.IsNullOrEmpty(emoteText))
{
_notifications.Error("K9 System", "Please enter a longer message!");
return;
}
string dogName = FetchDogName();
if (string.IsNullOrEmpty(dogName) || dogName == string.Empty || dogName == "none")
{
_notifications.Error("Error", "You haven't set a dog's name.");
return;
}
_comms.ToServer(ServerEvents.SendDogMeCommand, dogName, emoteText);
});
_commands.Register("kdo").HasGreedyArgs().WithHandler(emoteText =>
{
if (string.IsNullOrEmpty(emoteText))
{
_notifications.Error("K9 System", "Please enter a longer message!");
return;
}
string dogName = FetchDogName();
if (string.IsNullOrEmpty(dogName) || dogName == string.Empty || dogName == "none")
{
_notifications.Error("Error", "You haven't set a dog's name.");
return;
}
_comms.ToServer(ServerEvents.SendDogDoCommand, dogName, emoteText);
});
}
}
private void SetDogName(string dogName)
{
_logger.Debug($"Setting Dog Name to: {dogName}");
API.SetResourceKvp($"{ResourceKvp.DogName}", dogName);
}
public static string FetchDogName()
{
if (string.IsNullOrEmpty(API.GetResourceKvpString(ResourceKvp.DogName)))
{
API.SetResourceKvp(ResourceKvp.DogName, "none");
}
return API.GetResourceKvpString(ResourceKvp.DogName);
}
}
}