mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add help information for inventory command (#1170)
* Add help information for inventory command * Change optional parameter representation
This commit is contained in:
parent
712875251e
commit
ca1e902307
1 changed files with 74 additions and 16 deletions
|
|
@ -9,7 +9,7 @@ namespace MinecraftClient.Commands
|
||||||
class Inventory : Command
|
class Inventory : Command
|
||||||
{
|
{
|
||||||
public override string CMDName { get { return "inventory"; } }
|
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)
|
public override string Run(McClient handler, string command, Dictionary<string, object> localVars)
|
||||||
{
|
{
|
||||||
|
|
@ -21,26 +21,13 @@ namespace MinecraftClient.Commands
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int inventoryId;
|
int inventoryId;
|
||||||
if (args[0].ToLower() == "player")
|
if (args[0].ToLower() == "creativegive")
|
||||||
{
|
|
||||||
// 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.Length >= 4)
|
if (args.Length >= 4)
|
||||||
{
|
{
|
||||||
int slot = int.Parse(args[1]);
|
int slot = int.Parse(args[1]);
|
||||||
ItemType itemType = ItemType.Stone;
|
ItemType itemType = ItemType.Stone;
|
||||||
if (Enum.TryParse(args[2], out itemType))
|
if (Enum.TryParse(args[2], true, out itemType))
|
||||||
{
|
{
|
||||||
if (handler.GetGamemode() == 1)
|
if (handler.GetGamemode() == 1)
|
||||||
{
|
{
|
||||||
|
|
@ -58,6 +45,27 @@ namespace MinecraftClient.Commands
|
||||||
}
|
}
|
||||||
else return CMDDesc;
|
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]);
|
else inventoryId = int.Parse(args[0]);
|
||||||
string action = args.Length > 1
|
string action = args.Length > 1
|
||||||
? args[1].ToLower()
|
? args[1].ToLower()
|
||||||
|
|
@ -153,5 +161,55 @@ namespace MinecraftClient.Commands
|
||||||
}
|
}
|
||||||
else return "Please enable inventoryhandling in config to use this command.";
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue