Files
libremetaverse/Programs/examples/TestClient/Commands/Inventory/GiveItemCommand.cs

59 lines
2.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2021-07-25 11:10:52 -05:00
using System.Linq;
namespace OpenMetaverse.TestClient.Commands.Inventory.Shell
{
class GiveItemCommand : Command
{
private InventoryManager Manager;
private OpenMetaverse.Inventory Inventory;
public GiveItemCommand(TestClient client)
{
Name = "give";
Description = "Gives items from the current working directory to an avatar.";
Category = CommandCategory.Inventory;
}
public override string Execute(string[] args, UUID fromAgentID)
{
if (args.Length < 2)
{
return "Usage: give <agent uuid> itemname";
}
UUID dest;
if (!UUID.TryParse(args[0], out dest))
{
return "First argument expected agent UUID.";
}
Manager = Client.Inventory;
Inventory = Manager.Store;
string ret = "";
2022-02-25 19:38:11 -06:00
string target = args.Aggregate(string.Empty, (current, t) => current + t + " ");
target = target.TrimEnd();
string inventoryName = target;
// WARNING: Uses local copy of inventory contents, need to download them first.
List<InventoryBase> contents = Inventory.GetContents(Client.CurrentDirectory);
bool found = false;
2024-07-04 16:26:15 -05:00
foreach (var b in contents.Where(b => inventoryName == b.Name || inventoryName == b.UUID.ToString()))
{
2024-07-04 16:26:15 -05:00
found = true;
if (b is InventoryItem item)
{
2024-07-04 16:26:15 -05:00
Manager.GiveItem(item.UUID, item.Name, item.AssetType, dest, true);
ret += "Gave " + item.Name + " (" + item.AssetType + ")" + '\n';
}
else
{
ret += "Unable to give folder " + b.Name + '\n';
}
}
if (!found)
2024-07-04 16:26:15 -05:00
ret += "No inventory item named " + inventoryName + " found." + '\n';
return ret;
}
}
}