-
Notifications
You must be signed in to change notification settings - Fork 31
/
CommandPay.cs
103 lines (91 loc) · 3.6 KB
/
CommandPay.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
using Rocket.API;
using Rocket.Core.Logging;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using System;
using System.Collections.Generic;
namespace fr34kyn01535.Uconomy
{
public class CommandPay : IRocketCommand
{
public string Help
{
get { return "Pays a specific player money from your account"; }
}
public string Name
{
get { return "pay"; }
}
public AllowedCaller AllowedCaller
{
get
{
return AllowedCaller.Both;
}
}
public string Syntax
{
get { return "<player> <amount>"; }
}
public List<string> Aliases
{
get { return new List<string> { "pagar" }; }
}
public List<string> Permissions
{
get
{
return new List<string>() { "uconomy.pay" };
}
}
public void Execute(IRocketPlayer caller, params string[] command)
{
if (command.Length != 2)
{
UnturnedChat.Say(caller, Uconomy.Instance.Translations.Instance.Translate("command_pay_invalid"));
return;
}
UnturnedPlayer otherPlayer = UnturnedPlayer.FromName(command[0]);
if (otherPlayer !=null)
{
if (caller == otherPlayer)
{
UnturnedChat.Say(caller, Uconomy.Instance.Translations.Instance.Translate("command_pay_error_pay_self"));
return;
}
decimal amount = 0;
if (!Decimal.TryParse(command[1], out amount) || amount <= 0)
{
UnturnedChat.Say(caller, Uconomy.Instance.Translations.Instance.Translate("command_pay_error_invalid_amount"));
return;
}
if (caller is ConsolePlayer)
{
Uconomy.Instance.Database.IncreaseBalance(otherPlayer.Id, amount);
UnturnedChat.Say(otherPlayer.CSteamID, Uconomy.Instance.Translations.Instance.Translate("command_pay_console", amount, Uconomy.Instance.Configuration.Instance.MoneyName));
}
else
{
decimal myBalance = Uconomy.Instance.Database.GetBalance(caller.Id);
if ((myBalance - amount) <= 0)
{
UnturnedChat.Say(caller, Uconomy.Instance.Translations.Instance.Translate("command_pay_error_cant_afford"));
return;
}
else
{
Uconomy.Instance.Database.IncreaseBalance(caller.Id, -amount);
UnturnedChat.Say(caller, Uconomy.Instance.Translations.Instance.Translate("command_pay_private", otherPlayer.CharacterName, amount, Uconomy.Instance.Configuration.Instance.MoneyName));
Uconomy.Instance.Database.IncreaseBalance(otherPlayer.Id, amount);
UnturnedChat.Say(otherPlayer.CSteamID, Uconomy.Instance.Translations.Instance.Translate("command_pay_other_private", amount, Uconomy.Instance.Configuration.Instance.MoneyName, caller.DisplayName));
Uconomy.Instance.HasBeenPayed((UnturnedPlayer)caller, otherPlayer, amount);
}
}
}
else
{
UnturnedChat.Say(caller, Uconomy.Instance.Translations.Instance.Translate("command_pay_error_player_not_found"));
}
}
}
}