Minecraft-Console-Client/MinecraftClient/Commands/ChangeSlot.cs

44 lines
1.4 KiB
C#
Raw Normal View History

2020-03-26 15:01:42 +08:00
using System;
using System.Collections.Generic;
namespace MinecraftClient.Commands
{
class ChangeSlot : Command
{
public override string CmdName { get { return "changeslot"; } }
public override string CmdUsage { get { return "changeslot <1-9>"; } }
public override string CmdDesc { get { return Translations.cmd_changeSlot_desc; } }
2020-03-26 15:01:42 +08:00
public override string Run(McClient handler, string command, Dictionary<string, object>? localVars)
2020-03-26 15:01:42 +08:00
{
if (!handler.GetInventoryEnabled())
return Translations.extra_inventory_required;
if (HasArg(command))
2020-03-26 15:01:42 +08:00
{
short slot;
try
{
slot = Convert.ToInt16(GetArg(command));
2020-03-26 15:01:42 +08:00
}
catch (FormatException)
{
return Translations.cmd_changeSlot_nan;
2020-03-26 15:01:42 +08:00
}
if (slot >= 1 && slot <= 9)
{
if (handler.ChangeSlot(slot -= 1))
2020-03-26 15:01:42 +08:00
{
return string.Format(Translations.cmd_changeSlot_changed, (slot += 1));
2020-03-26 15:01:42 +08:00
}
else
{
return Translations.cmd_changeSlot_fail;
2020-03-26 15:01:42 +08:00
}
}
}
return GetCmdDescTranslated();
2020-03-26 15:01:42 +08:00
}
}
}