Minecraft-Console-Client/MinecraftClient/Scripting/BotMovementLock.cs
Anon 272900d52e Added slab handling for 1.20/.1
Added Farm bot crops handling for 1.20/.1
Added utilities for Containers/Inventories
Added bot movement lock to prevent multiple bots that use movements from running at the same time.
General code improvements.
2023-06-23 16:25:18 +02:00

35 lines
No EOL
852 B
C#

namespace MinecraftClient.Scripting;
public class BotMovementLock
{
private static BotMovementLock? InstancePrivate;
private string _heldBy = string.Empty;
private BotMovementLock()
{
InstancePrivate = this;
}
public static BotMovementLock? Instance => InstancePrivate ??= new BotMovementLock();
public bool Lock(string owner)
{
if (owner.Trim().Length == 0 || _heldBy.Length > 0)
return false;
_heldBy = owner.Trim();
return true;
}
public bool UnLock(string owner)
{
if (owner.Trim().Length == 0 || _heldBy.Length == 0 || !_heldBy.ToLower().Equals(owner.ToLower().Trim()))
return false;
_heldBy = string.Empty;
return true;
}
public bool IsLocked => _heldBy.Length > 0;
public string LockedBy => _heldBy;
}