Add "-f" to the /move command (#1874)

This commit is contained in:
Daenges 2021-12-29 15:34:40 +01:00 committed by GitHub
parent 259ef80cf9
commit dd3fd3c9d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 17 deletions

View file

@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using MinecraftClient.Mapping; using MinecraftClient.Mapping;
namespace MinecraftClient.Commands namespace MinecraftClient.Commands
@ -9,30 +8,36 @@ namespace MinecraftClient.Commands
public class Move : Command public class Move : Command
{ {
public override string CmdName { get { return "move"; } } public override string CmdName { get { return "move"; } }
public override string CmdUsage { get { return "move <on|off|get|up|down|east|west|north|south|x y z>"; } } public override string CmdUsage { get { return "move <on|off|get|up|down|east|west|north|south|x y z> [-f]"; } }
public override string CmdDesc { get { return "walk or start walking."; } } public override string CmdDesc { get { return "walk or start walking. \"-f\": force unsafe movements like falling or touching fire"; } }
public override string Run(McClient handler, string command, Dictionary<string, object> localVars) public override string Run(McClient handler, string command, Dictionary<string, object> localVars)
{ {
string[] args = getArgs(command); List<string> args = getArgs(command.ToLower()).ToList();
string argStr = getArg(command).Trim().ToLower(); bool takeRisk = false;
if (argStr == "on") if (args.Contains("-f"))
{
takeRisk = true;
args.Remove("-f");
}
if (args[0] == "on")
{ {
handler.SetTerrainEnabled(true); handler.SetTerrainEnabled(true);
return Translations.Get("cmd.move.enable"); return Translations.Get("cmd.move.enable");
} }
else if (argStr == "off") else if (args[0] == "off")
{ {
handler.SetTerrainEnabled(false); handler.SetTerrainEnabled(false);
return Translations.Get("cmd.move.disable"); return Translations.Get("cmd.move.disable");
} }
else if (handler.GetTerrainEnabled()) else if (handler.GetTerrainEnabled())
{ {
if (args.Length == 1) if (args.Count == 1)
{ {
Direction direction; Direction direction;
switch (argStr) switch (args[0])
{ {
case "up": direction = Direction.Up; break; case "up": direction = Direction.Up; break;
case "down": direction = Direction.Down; break; case "down": direction = Direction.Down; break;
@ -41,16 +46,17 @@ namespace MinecraftClient.Commands
case "north": direction = Direction.North; break; case "north": direction = Direction.North; break;
case "south": direction = Direction.South; break; case "south": direction = Direction.South; break;
case "get": return handler.GetCurrentLocation().ToString(); case "get": return handler.GetCurrentLocation().ToString();
default: return Translations.Get("cmd.look.unknown", argStr); default: return Translations.Get("cmd.look.unknown", args[0]);
} }
if (Movement.CanMove(handler.GetWorld(), handler.GetCurrentLocation(), direction)) if (Movement.CanMove(handler.GetWorld(), handler.GetCurrentLocation(), direction))
{ {
handler.MoveTo(Movement.Move(handler.GetCurrentLocation(), direction)); if (handler.MoveTo(Movement.Move(handler.GetCurrentLocation(), direction), allowUnsafe: takeRisk))
return Translations.Get("cmd.move.moving", argStr); return Translations.Get("cmd.move.moving", args[0]);
else return takeRisk ? Translations.Get("cmd.move.dir_fail") : Translations.Get("cmd.move.suggestforce");
} }
else return Translations.Get("cmd.move.dir_fail"); else return Translations.Get("cmd.move.dir_fail");
} }
else if (args.Length == 3) else if (args.Count == 3)
{ {
try try
{ {
@ -58,9 +64,10 @@ namespace MinecraftClient.Commands
int y = int.Parse(args[1]); int y = int.Parse(args[1]);
int z = int.Parse(args[2]); int z = int.Parse(args[2]);
Location goal = new Location(x, y, z); Location goal = new Location(x, y, z);
if (handler.MoveTo(goal))
if (handler.MoveTo(goal, allowUnsafe: takeRisk))
return Translations.Get("cmd.move.walk", goal); return Translations.Get("cmd.move.walk", goal);
return Translations.Get("cmd.move.fail", goal); else return takeRisk ? Translations.Get("cmd.move.fail", goal) : Translations.Get("cmd.move.suggestforce", goal);
} }
catch (FormatException) { return GetCmdDescTranslated(); } catch (FormatException) { return GetCmdDescTranslated(); }
} }

View file

@ -310,6 +310,7 @@ cmd.move.moving=Laufe {0}
cmd.move.dir_fail=Kann nicht in diese Richtung laufen. cmd.move.dir_fail=Kann nicht in diese Richtung laufen.
cmd.move.walk=Gehe nach {0} cmd.move.walk=Gehe nach {0}
cmd.move.fail=Konnte Pfad nach {0} nicht berechnen. cmd.move.fail=Konnte Pfad nach {0} nicht berechnen.
cmd.move.suggestforce=Weg nach {0} konnte nicht berechnet werden. Benutze den -f Parameter, um unsichere Wege zu aktivieren.
# Reco # Reco
cmd.reco.desc=Starte neu und verbinde erneut zum Server. cmd.reco.desc=Starte neu und verbinde erneut zum Server.

View file

@ -310,6 +310,7 @@ cmd.move.moving=Moving {0}
cmd.move.dir_fail=Cannot move in that direction. cmd.move.dir_fail=Cannot move in that direction.
cmd.move.walk=Walking to {0} cmd.move.walk=Walking to {0}
cmd.move.fail=Failed to compute path to {0} cmd.move.fail=Failed to compute path to {0}
cmd.move.suggestforce=Failed to compute a safe path to {0}. Try -f parameter to allow unsafe movements.
# Reco # Reco
cmd.reco.desc=restart and reconnect to the server. cmd.reco.desc=restart and reconnect to the server.
@ -503,4 +504,4 @@ bot.scriptScheduler.task=triggeronfirstlogin: {0}\n triggeronlogin: {1}\n trigge
# TestBot # TestBot
bot.testBot.told=Bot: {0} told me : {1} bot.testBot.told=Bot: {0} told me : {1}
bot.testBot.said=Bot: {0} said : {1} bot.testBot.said=Bot: {0} said : {1}