-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCommandVRemove.cs
More file actions
98 lines (85 loc) · 3.53 KB
/
Copy pathCommandVRemove.cs
File metadata and controls
98 lines (85 loc) · 3.53 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
using Rocket.API;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace VirtualStorage
{
class CommandVRemove : IRocketCommand
{
internal static readonly string syntax = "<\"Container Name\">";
internal static readonly string help = "Removes a Container.";
public List<string> Aliases
{
get { return new List<string>() { "vr" }; }
}
public AllowedCaller AllowedCaller
{
get { return AllowedCaller.Both; }
}
public string Help
{
get { return help; }
}
public string Name
{
get { return "vremove"; }
}
public List<string> Permissions
{
get { return new List<string> { "vremove" }; }
}
public string Syntax
{
get { return syntax; }
}
public void Execute(IRocketPlayer caller, string[] command)
{
if (command.Length == 0 || command.Length > 1)
{
UnturnedChat.Say(caller, Syntax + " - " + Help);
return;
}
UnturnedPlayer player = (UnturnedPlayer)caller;
PVirtStorage pComponent = player.GetComponent<PVirtStorage>();
Dictionary<string, object[]> containers = VirtualStorage.Database.GetContainerList(player.CSteamID);
string defaultContainer = VirtualStorage.Database.GetDefaultContainer(player.CSteamID);
object[] container = containers.Values.FirstOrDefault(contents => contents[2].ToString().ToLower() == command[0].ToLower().Trim());
if (container == null)
{
UnturnedChat.Say(caller, VirtualStorage.Instance.Translate("container_name_not_found"), Color.red);
return;
}
ContainerManager cData = null;
// Load the container data, if it isn't already loaded.
if (VirtualStorage.Containers.ContainsKey(player.CSteamID) && VirtualStorage.Containers[player.CSteamID].ContainerName.ToLower() == container[2].ToString().Trim().ToLower())
{
cData = VirtualStorage.Containers[player.CSteamID];
VirtualStorage.Containers.Remove(player.CSteamID);
}
if (cData == null)
{
object[] cObject = VirtualStorage.Database.GetContainerData(player.CSteamID, container[2].ToString());
cData = new ContainerManager(player);
if (!cData.SetContainer((ushort)cObject[0], (byte[])cObject[1], player, (string)cObject[2], (byte)cObject[3], (byte)cObject[4]))
{
if (!cData.SetContainer(VirtualStorage.Instance.Configuration.Instance.FallbackAssetID, (byte[])cObject[1], player, (string)cObject[2], (byte)cObject[3], (byte)cObject[4]))
{
UnturnedChat.Say(caller, VirtualStorage.Instance.Translate("open_invalid"), Color.red);
return;
}
}
}
if (!string.IsNullOrEmpty(defaultContainer))
{
if (defaultContainer.ToLower() == command[0].Trim().ToLower())
VirtualStorage.Database.SaveDefaultContainer(player.CSteamID, string.Empty);
}
VirtualStorage.Database.RemoveContainerFromDB(player.CSteamID, container[2].ToString());
cData.Break();
}
}
}