-
Notifications
You must be signed in to change notification settings - Fork 8
/
CommandVault.cs
129 lines (121 loc) · 4.82 KB
/
CommandVault.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using Rocket.API;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using System.Collections.Generic;
using UnityEngine;
namespace NEXIS.Vaults
{
public class CommandVault : IRocketCommand
{
public AllowedCaller AllowedCaller
{
get { return AllowedCaller.Player; }
}
public bool AllowFromConsole
{
get { return false; }
}
public string Name
{
get { return "vault"; }
}
public string Help
{
get { return "Save and load items from your inventory to your own personal Vault."; }
}
public List<string> Aliases
{
get { return new List<string>() { }; }
}
public string Syntax
{
get { return "/vault <save|load|delete|help> <itemId>"; }
}
public List<string> Permissions
{
get
{
return new List<string>() { "nexis.vault" };
}
}
public void Execute(IRocketPlayer caller, params string[] param)
{
UnturnedPlayer player = (UnturnedPlayer)caller;
if (Vault.Instance.Configuration.Instance.VaultsEnabled)
{
if (param.Length > 0)
{
if (param.Length == 1 && Vault.Instance.Configuration.Instance.VaultsSaveEntireInventory)
{
switch (param[0])
{
case "save":
// save player vault to database
Vault.Instance.Database.SavePlayerInventory(player);
break;
case "open":
case "load":
// open player vault from database
Vault.Instance.Database.OpenPlayerInventory(player);
break;
case "delete":
// open player vault from database
Vault.Instance.Database.DeletePlayerVault(player);
break;
case "help":
UnturnedChat.Say(caller, Help, Color.white);
UnturnedChat.Say(caller, Syntax, Color.white);
break;
default:
// invalid action
UnturnedChat.Say(caller, Vault.Instance.Translations.Instance.Translate("vault_action_invalid"), Color.red);
break;
}
}
else if (param.Length == 2 && !Vault.Instance.Configuration.Instance.VaultsSaveEntireInventory)
{
ushort itemId;
if (ushort.TryParse(param[1], out itemId))
{
switch (param[0])
{
case "save":
// save player vault to database
Vault.Instance.Database.SavePlayerInventory(player, itemId);
break;
case "open":
case "load":
// open player vault from database
Vault.Instance.Database.OpenPlayerInventory(player, itemId);
break;
case "help":
UnturnedChat.Say(caller, Help, Color.white);
UnturnedChat.Say(caller, Syntax, Color.white);
break;
default:
// invalid action
UnturnedChat.Say(caller, Vault.Instance.Translations.Instance.Translate("vault_action_invalid"), Color.red);
break;
}
}
}
else
{
UnturnedChat.Say(caller, "Incorrect Syntax! Use:" + Syntax, Color.white);
}
}
else
{
// user typed /vault only
UnturnedChat.Say(caller, Help, Color.white);
}
}
else
{
// vault disabled in configuration
UnturnedChat.Say(caller, Vault.Instance.Translations.Instance.Translate("vault_disabled"), Color.yellow);
}
}
}
}