This repository was archived by the owner on Dec 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCommandExp.cs
More file actions
115 lines (100 loc) · 4.62 KB
/
CommandExp.cs
File metadata and controls
115 lines (100 loc) · 4.62 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
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
115
using Rocket.API;
using Rocket.Core.Logging;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using System;
using System.Collections.Generic;
namespace Freenex.FeexExp
{
public class CommandExp : IRocketCommand
{
public string Name
{
get { return "exp"; }
}
public string Help
{
get { return "/exp <experience> [<player>]"; }
}
public string Syntax
{
get { return "<experience> [<player>]"; }
}
public List<string> Aliases
{
get { return new List<string>(); }
}
public AllowedCaller AllowedCaller
{
get { return AllowedCaller.Both; }
}
public List<string> Permissions
{
get
{
return new List<string>()
{
"exp.self",
"exp.give",
"exp.transfer"
};
}
}
public void Execute(IRocketPlayer caller, string[] command)
{
if (command.Length == 1 && !(caller is ConsolePlayer))
{
UnturnedPlayer UPcaller = (UnturnedPlayer)caller;
if (!(caller.HasPermission("exp.self"))) { return; }
uint commandExp;
bool isNumeric = uint.TryParse(command[0], out commandExp);
if (isNumeric)
{
UPcaller.Experience = UPcaller.Experience + commandExp;
UnturnedChat.Say(caller, FeexExp.Instance.Translations.Instance.Translate("exp_self", commandExp));
}
}
else if (command.Length == 2)
{
if (!caller.HasPermission("exp.give") && !caller.HasPermission("exp.transfer") && !(caller is ConsolePlayer)) { return; }
uint commandExp;
bool isNumeric = uint.TryParse(command[0], out commandExp);
if (!isNumeric) { return; }
UnturnedPlayer player = UnturnedPlayer.FromName(command[1]);
if (player == null)
{
if (caller is ConsolePlayer) { Logger.Log(FeexExp.Instance.Translations.Instance.Translate("general_not_found")); }
else { UnturnedChat.Say(caller, FeexExp.Instance.Translations.Instance.Translate("general_not_found")); }
return;
}
if (player.Id == caller.Id) { return; }
if (caller.HasPermission("exp.give") || caller is ConsolePlayer)
{
player.Experience = player.Experience + commandExp;
if (caller is ConsolePlayer) { UnturnedChat.Say(player, FeexExp.Instance.Translations.Instance.Translate("exp_give_player_console", commandExp)); }
else { UnturnedChat.Say(player, FeexExp.Instance.Translations.Instance.Translate("exp_give_player", commandExp, ((UnturnedPlayer)caller).CharacterName)); }
if (caller is ConsolePlayer) { Logger.Log(FeexExp.Instance.Translations.Instance.Translate("exp_give_caller", commandExp, player.CharacterName)); }
else { UnturnedChat.Say(caller, FeexExp.Instance.Translations.Instance.Translate("exp_give_caller", commandExp, player.CharacterName)); }
}
else if (caller.HasPermission("exp.transfer"))
{
UnturnedPlayer UPcaller = (UnturnedPlayer)caller;
if ((Convert.ToDecimal(UPcaller.Experience) - Convert.ToDecimal(commandExp)) < 0)
{
UnturnedChat.Say(caller, FeexExp.Instance.Translations.Instance.Translate("exp_transfer_not_enough", commandExp));
return;
}
UPcaller.Experience = UPcaller.Experience - commandExp;
player.Experience = player.Experience + commandExp;
UnturnedChat.Say(player, FeexExp.Instance.Translations.Instance.Translate("exp_transfer_player", commandExp, ((UnturnedPlayer)caller).CharacterName));
UnturnedChat.Say(caller, FeexExp.Instance.Translations.Instance.Translate("exp_transfer_caller", commandExp, player.CharacterName));
}
}
else
{
if (caller is ConsolePlayer) { Logger.Log(FeexExp.Instance.Translations.Instance.Translate("general_invalid_parameter")); }
else { UnturnedChat.Say(caller, FeexExp.Instance.Translations.Instance.Translate("general_invalid_parameter")); }
}
}
}
}