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 "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.Get("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.Get("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 Translations.Get("cmd.changeSlot.changed", (slot += 1));
2020-03-26 15:01:42 +08:00
}
else
{
return Translations.Get("cmd.changeSlot.fail");
2020-03-26 15:01:42 +08:00
}
}
}
return GetCmdDescTranslated();
2020-03-26 15:01:42 +08:00
}
}
}