Fixes following pull requests (#1101, #1097)

Fix coding style issues and compile errors
This commit is contained in:
ORelio 2020-07-04 11:12:23 +02:00
parent e9f1a4477c
commit 855bdade0b
4 changed files with 47 additions and 43 deletions

View file

@ -823,11 +823,11 @@ namespace MinecraftClient
/// </summary> /// </summary>
/// <param name="location">Location to reach</param> /// <param name="location">Location to reach</param>
/// <param name="allowUnsafe">Allow possible but unsafe locations thay may hurt the player: lava, cactus...</param> /// <param name="allowUnsafe">Allow possible but unsafe locations thay may hurt the player: lava, cactus...</param>
/// <param name="allowSmallTeleport">Allow non-vanilla small teleport instead of computing path, but may cause invalid moves and/or trigger anti-cheat plugins</param> /// <param name="allowDirectTeleport">Allow non-vanilla teleport instead of computing path, but may cause invalid moves and/or trigger anti-cheat plugins</param>
/// <returns>True if a path has been found</returns> /// <returns>True if a path has been found</returns>
protected bool MoveToLocation(Mapping.Location location, bool allowUnsafe = false, bool allowSmallTeleport = false) protected bool MoveToLocation(Mapping.Location location, bool allowUnsafe = false, bool allowDirectTeleport = false)
{ {
return Handler.MoveTo(location, allowUnsafe, allowSmallTeleport); return Handler.MoveTo(location, allowUnsafe, allowDirectTeleport);
} }
/// <summary> /// <summary>
@ -1145,13 +1145,13 @@ namespace MinecraftClient
/// <summary> /// <summary>
/// Register a command in command prompt /// Register a command in command prompt
/// </summary> /// </summary>
/// <param name="CMDName">Name of the command</param> /// <param name="cmdName">Name of the command</param>
/// <param name="CMDDesc">Description/usage of the command</param> /// <param name="cmdDesc">Description/usage of the command</param>
/// <param name="Run">Method for handling the command</param> /// <param name="callback">Method for handling the command</param>
/// <returns>True if successfully registered</returns> /// <returns>True if successfully registered</returns>
protected bool RegisterChatBotCommand(string CMDName, string CMDDesc, CommandRunner Run) protected bool RegisterChatBotCommand(string cmdName, string cmdDesc, CommandRunner callback)
{ {
return Handler.RegisterCommand(CMDName, CMDDesc, Run); return Handler.RegisterCommand(cmdName, cmdDesc, callback);
} }
/// <summary> /// <summary>
@ -1160,7 +1160,7 @@ namespace MinecraftClient
/// </summary> /// </summary>
/// <param name="command">Full command</param> /// <param name="command">Full command</param>
/// <param name="args">Arguments in the command</param> /// <param name="args">Arguments in the command</param>
/// <returns></returns> /// <returns>Command result to display to the user</returns>
public delegate string CommandRunner(string command, string[] args); public delegate string CommandRunner(string command, string[] args);
/// <summary> /// <summary>
@ -1170,24 +1170,28 @@ namespace MinecraftClient
{ {
public CommandRunner Runner; public CommandRunner Runner;
public override string CMDName { get; } private readonly string _cmdName;
public override string CMDDesc { get; } private readonly string _cmdDesc;
public override string CMDName { get { return _cmdName; } }
public override string CMDDesc { get { return _cmdDesc; } }
public override string Run(McClient handler, string command, Dictionary<string, object> localVars) public override string Run(McClient handler, string command, Dictionary<string, object> localVars)
{ {
return this.Runner(command, getArgs(command)); return this.Runner(command, getArgs(command));
} }
/// <summary> /// <summary>
/// Constructor /// ChatBotCommand Constructor
/// </summary> /// </summary>
/// <param name="CMDName">Name of the command</param> /// <param name="CMDName">Name of the command</param>
/// <param name="CMDDesc">Description/usage of the command</param> /// <param name="CMDDesc">Description/usage of the command</param>
/// <param name="runner">Method for handling the command</param> /// <param name="runner">Method for handling the command</param>
public ChatBotCommand(string CMDName, string CMDDesc, CommandRunner runner) public ChatBotCommand(string cmdName, string cmdDesc, CommandRunner callback)
{ {
this.CMDName = CMDName; this._cmdName = cmdName;
this.CMDDesc = CMDDesc; this._cmdDesc = cmdDesc;
this.Runner = runner; this.Runner = callback;
} }
} }
} }

View file

@ -581,29 +581,27 @@ namespace MinecraftClient
} }
/// <summary> /// <summary>
/// Register a command prompt command /// Register a custom console command
/// </summary> /// </summary>
/// <param name="CMDName">Name of the command</param> /// <param name="cmdName">Name of the command</param>
/// <param name="CMDDesc">Description/usage of the command</param> /// <param name="cmdDesc">Description/usage of the command</param>
/// <param name="runner">Method for handling the command</param> /// <param name="callback">Method for handling the command</param>
/// <returns>True if successfully registered</returns> /// <returns>True if successfully registered</returns>
public bool RegisterCommand(string CMDName, string CMDDesc, CommandRunner runner) public bool RegisterCommand(string cmdName, string cmdDesc, ChatBot.CommandRunner callback)
{ {
if (cmds.ContainsKey(CMDName.ToLower())) if (cmds.ContainsKey(cmdName.ToLower()))
{ {
return false; return false;
} }
else else
{ {
Command cmd = new ChatBotCommand(CMDName, CMDDesc, runner); Command cmd = new ChatBot.ChatBotCommand(cmdName, cmdDesc, callback);
cmds.Add(CMDName.ToLower(), cmd); cmds.Add(cmdName.ToLower(), cmd);
cmd_names.Add(CMDName.ToLower()); cmd_names.Add(cmdName.ToLower());
return true; return true;
} }
} }
#region Management: Load/Unload ChatBots and Enable/Disable settings #region Management: Load/Unload ChatBots and Enable/Disable settings
/// <summary> /// <summary>
@ -828,15 +826,15 @@ namespace MinecraftClient
/// </summary> /// </summary>
/// <param name="location">Location to reach</param> /// <param name="location">Location to reach</param>
/// <param name="allowUnsafe">Allow possible but unsafe locations thay may hurt the player: lava, cactus...</param> /// <param name="allowUnsafe">Allow possible but unsafe locations thay may hurt the player: lava, cactus...</param>
/// <param name="allowSmallTeleport">Allow non-vanilla small teleport instead of computing path, but may cause invalid moves and/or trigger anti-cheat plugins</param> /// <param name="allowDirectTeleport">Allow non-vanilla direct teleport instead of computing path, but may cause invalid moves and/or trigger anti-cheat plugins</param>
/// <returns>True if a path has been found</returns> /// <returns>True if a path has been found</returns>
public bool MoveTo(Location location, bool allowUnsafe = false, bool allowSmallTeleport = false) public bool MoveTo(Location location, bool allowUnsafe = false, bool allowDirectTeleport = false)
{ {
lock (locationLock) lock (locationLock)
{ {
if (allowSmallTeleport) if (allowDirectTeleport)
{ {
// Allow small teleport within a range of 8 blocks. 1-step path to the desired location without checking anything // 1-step path to the desired location without checking anything
UpdateLocation(location, location); // Update yaw and pitch to look at next step UpdateLocation(location, location); // Update yaw and pitch to look at next step
handler.SendLocationUpdate(location, Movement.IsOnGround(world, location), yaw, pitch); handler.SendLocationUpdate(location, Movement.IsOnGround(world, location), yaw, pitch);
return true; return true;

View file

@ -123,6 +123,8 @@
<Compile Include="Mapping\BlockPalettes\Palette115.cs" /> <Compile Include="Mapping\BlockPalettes\Palette115.cs" />
<Compile Include="Mapping\BlockPalettes\BlockPaletteGenerator.cs" /> <Compile Include="Mapping\BlockPalettes\BlockPaletteGenerator.cs" />
<Compile Include="Mapping\BlockPalettes\BlockPalette.cs" /> <Compile Include="Mapping\BlockPalettes\BlockPalette.cs" />
<Compile Include="Mapping\CommandBlockFlags.cs" />
<Compile Include="Mapping\CommandBlockMode.cs" />
<Compile Include="Mapping\Entity.cs" /> <Compile Include="Mapping\Entity.cs" />
<Compile Include="Mapping\EntityPalettes\EntityPalette113.cs" /> <Compile Include="Mapping\EntityPalettes\EntityPalette113.cs" />
<Compile Include="Mapping\EntityPalettes\EntityPalette.cs" /> <Compile Include="Mapping\EntityPalettes\EntityPalette.cs" />

View file

@ -372,17 +372,17 @@ namespace MinecraftClient.Protocol.Handlers
} }
break; break;
case PacketIncomingType.MapData: case PacketIncomingType.MapData:
int mapid = dataTypes.ReadNextVarInt(packetData); int mapid = dataTypes.ReadNextVarInt(packetData);
byte scale = dataTypes.ReadNextByte(packetData); byte scale = dataTypes.ReadNextByte(packetData);
bool trackingposition = dataTypes.ReadNextBool(packetData); bool trackingposition = dataTypes.ReadNextBool(packetData);
bool locked = false; bool locked = false;
if (protocolversion >= MC114Version) if (protocolversion >= MC114Version)
{ {
locked = dataTypes.ReadNextBool(packetData); locked = dataTypes.ReadNextBool(packetData);
} }
int iconcount = dataTypes.ReadNextVarInt(packetData); int iconcount = dataTypes.ReadNextVarInt(packetData);
handler.OnMapData(mapid, scale, trackingposition, locked, iconcount); handler.OnMapData(mapid, scale, trackingposition, locked, iconcount);
break; break;
case PacketIncomingType.Title: case PacketIncomingType.Title:
if (protocolversion >= MC18Version) if (protocolversion >= MC18Version)
{ {