-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommand.cs
More file actions
66 lines (63 loc) · 2.17 KB
/
Command.cs
File metadata and controls
66 lines (63 loc) · 2.17 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rocket.Core.Utils;
namespace SPlayTime;
public class Command : IRocketCommand
{
public AllowedCaller AllowedCaller => AllowedCaller.Both;
public string Name => "playtime";
public string Help => $"/{Name}";
public string Syntax => Help;
public List<string> Aliases => new();
public List<string> Permissions => new() { Name };
public void Execute(IRocketPlayer caller, string[] command)
{
#if !DEBUG
Task.Run(() => {
#endif
var arg = string.Join(" ", command);
var target = caller;
var color = Color.green;
var msg = "";
if (caller.HasPermission($"{Name}.other") && !string.IsNullOrWhiteSpace(arg))
{
target = UP.FromName(arg);
if (target is null && ulong.TryParse(arg, out var id))
target = new RocketPlayer(arg, arg);
}
if(target is not null)
msg = GetMessage(caller, target);
else
{
msg = TranslatePlayerNotFound(arg);
color = Color.red;
}
if (string.IsNullOrWhiteSpace(msg))
return;
TaskDispatcher.QueueOnMainThread(() => UnturnedChat.Say(caller, msg, color, true));
#if !DEBUG
});
#endif
}
static string GetMessage(IRocketPlayer caller, IRocketPlayer target)
{
var seconds = Main.DBConnector.GetSeconds(target.Id);
var time = TimeSpan.FromSeconds(seconds);
var format = TranslateTimeFormat();
var formattedTime = time.ToString(format);
return caller.Id == target.Id ?
TranslateMyPlaytimeFormat(formattedTime) :
TranslateOtherPlaytimeFormat(target.DisplayName, formattedTime);
}
}
public static partial class Translations
{
public const string
MyPlaytimeFormat = "Your playtime is: {0}.",
OtherPlaytimeFormat = "Playtime of '{0}' is: {1}.",
PlayerNotFound = "Player '{0}' is not found.",
TimeFormat = @"dd' Days 'hh' Hours 'mm' Minutes 'ss' Seconds'";
}