Add help information for inventory command (#1170)

* Add help information for inventory command

* Change optional parameter representation
This commit is contained in:
ReinforceZwei 2020-08-03 20:13:07 +08:00 committed by GitHub
parent 712875251e
commit ca1e902307
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,7 +9,7 @@ namespace MinecraftClient.Commands
class Inventory : Command
{
public override string CMDName { get { return "inventory"; } }
public override string CMDDesc { get { return "inventory <<id>|player|container> <list|close|drop <slot> <1|all>|click <slot> <left|right|middle>> | inventory creativegive <slot> <itemtype> <count>: Interact with inventories"; } }
public override string CMDDesc { get { return GetCommandDesc(); } }
public override string Run(McClient handler, string command, Dictionary<string, object> localVars)
{
@ -21,26 +21,13 @@ namespace MinecraftClient.Commands
try
{
int inventoryId;
if (args[0].ToLower() == "player")
{
// player inventory is always ID 0
inventoryId = 0;
}
else if (args[0].ToLower() == "container")
{
List<int> availableIds = handler.GetInventories().Keys.ToList();
availableIds.Remove(0); // remove player inventory ID from list
if (availableIds.Count == 1)
inventoryId = availableIds[0]; // one container, use it
else return "Cannot find container, please retry with explicit ID";
}
else if (args[0].ToLower() == "creativegive")
if (args[0].ToLower() == "creativegive")
{
if (args.Length >= 4)
{
int slot = int.Parse(args[1]);
ItemType itemType = ItemType.Stone;
if (Enum.TryParse(args[2], out itemType))
if (Enum.TryParse(args[2], true, out itemType))
{
if (handler.GetGamemode() == 1)
{
@ -58,6 +45,27 @@ namespace MinecraftClient.Commands
}
else return CMDDesc;
}
else if (args[0].ToLower().StartsWith("p"))
{
// player inventory is always ID 0
inventoryId = 0;
}
else if (args[0].ToLower().StartsWith("c"))
{
List<int> availableIds = handler.GetInventories().Keys.ToList();
availableIds.Remove(0); // remove player inventory ID from list
if (availableIds.Count == 1)
inventoryId = availableIds[0]; // one container, use it
else return "Cannot find container, please retry with explicit ID";
}
else if (args[0].ToLower() == "help")
{
if (args.Length >= 2)
{
return GetSubCommandHelp(args[1]);
}
else return GetHelp();
}
else inventoryId = int.Parse(args[0]);
string action = args.Length > 1
? args[1].ToLower()
@ -153,5 +161,55 @@ namespace MinecraftClient.Commands
}
else return "Please enable inventoryhandling in config to use this command.";
}
#region Methods for commands help
private string GetCommandDesc()
{
return GetBasicUsage() + " Type \"/inventory help\" for more help";
}
private string GetAvailableActions()
{
return "Available actions: list, close, click, drop.";
}
private string GetBasicUsage()
{
return "Basic usage: /inventory <player|container|<id>> <action>.";
}
private string GetHelp()
{
return GetBasicUsage()
+ "\n " + GetAvailableActions() + " Use \"/inventory help <action>\" for action help."
+ "\n Creative mode give: " + GetCreativeGiveHelp()
+ "\n \"player\" and \"container\" can be simplified to \"p\" and \"c\"."
+ "\n Note that parameters in \"[]\" are optional.";
}
private string GetCreativeGiveHelp()
{
return "Usage: /inventory creativegive <slot> <itemtype> <count>";
}
private string GetSubCommandHelp(string cmd)
{
switch (cmd)
{
case "list":
return "List your inventory. Usage: /inventory <player|container|<id>> list";
case "close":
return "Close an opened container. Usage: /inventory <player|container|<id>> close";
case "click":
return "Click on an item. Usage: /inventory <player|container|<id>> click <slot> [left|right|middle]. \nDefault is left click";
case "drop":
return "Drop an item from inventory. Usage: /inventory <player|container|<id>> drop <slot> [all]. \nAll means drop full stack";
case "help":
return GetHelp();
default:
return "Unknown action. " + GetAvailableActions();
}
}
#endregion
}
}