diff --git a/MinecraftClient/ChatBots/AutoDig.cs b/MinecraftClient/ChatBots/AutoDig.cs index e1da7a51..67d0b199 100644 --- a/MinecraftClient/ChatBots/AutoDig.cs +++ b/MinecraftClient/ChatBots/AutoDig.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using Brigadier.NET.Builder; using MinecraftClient.CommandHandler; using MinecraftClient.CommandHandler.Patch; @@ -102,7 +103,7 @@ namespace MinecraftClient.ChatBots private bool inventoryEnabled; private int counter = 0; - private readonly object stateLock = new(); + private readonly Lock stateLock = new(); private State state = State.WaitJoinGame; bool AlreadyWaitting = false; diff --git a/MinecraftClient/ChatBots/AutoFishing.cs b/MinecraftClient/ChatBots/AutoFishing.cs index f2ab906d..c72dcb40 100644 --- a/MinecraftClient/ChatBots/AutoFishing.cs +++ b/MinecraftClient/ChatBots/AutoFishing.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading; using Brigadier.NET.Builder; using MinecraftClient.CommandHandler; using MinecraftClient.CommandHandler.Patch; @@ -175,7 +176,7 @@ namespace MinecraftClient.ChatBots private Entity fishItem = new(-1, EntityType.Item, Location.Zero); private int counter = 0; - private readonly object stateLock = new(); + private readonly Lock stateLock = new(); private FishingState state = FishingState.WaitJoinGame; private int curLocationIdx = 0, moveDir = 1; diff --git a/MinecraftClient/ChatBots/ChatLog.cs b/MinecraftClient/ChatBots/ChatLog.cs index 37aecd36..d5121897 100644 --- a/MinecraftClient/ChatBots/ChatLog.cs +++ b/MinecraftClient/ChatBots/ChatLog.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Threading; using MinecraftClient.CommandHandler; using MinecraftClient.Scripting; using Tomlet.Attributes; @@ -50,7 +51,7 @@ namespace MinecraftClient.ChatBots private bool saveChat = true; private bool savePrivate = true; private bool saveInternal = true; - private readonly object logfileLock = new(); + private readonly Lock logfileLock = new(); /// /// This bot saves the messages received in the specified file, with some filters and date/time tagging. diff --git a/MinecraftClient/ChatBots/DiscordRpc.cs b/MinecraftClient/ChatBots/DiscordRpc.cs index f4be0532..e3ab09b3 100644 --- a/MinecraftClient/ChatBots/DiscordRpc.cs +++ b/MinecraftClient/ChatBots/DiscordRpc.cs @@ -361,8 +361,8 @@ namespace MinecraftClient.ChatBots private readonly byte[] _buffer = new byte[PipeFrame.MAX_SIZE]; private readonly Queue _frameQueue = new(); - private readonly object _frameQueueLock = new(); - private readonly object _streamLock = new(); + private readonly Lock _frameQueueLock = new(); + private readonly Lock _streamLock = new(); private int _connectedPipe; private NamedPipeClientStream? _stream; diff --git a/MinecraftClient/ChatBots/Mailer.cs b/MinecraftClient/ChatBots/Mailer.cs index 5733b3a8..1d84b74f 100644 --- a/MinecraftClient/ChatBots/Mailer.cs +++ b/MinecraftClient/ChatBots/Mailer.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; +using System.Threading; using Brigadier.NET; using Brigadier.NET.Builder; using MinecraftClient.CommandHandler; @@ -218,7 +219,7 @@ namespace MinecraftClient.ChatBots private IgnoreList ignoreList = new(); private FileMonitor? mailDbFileMonitor; private FileMonitor? ignoreListFileMonitor; - private readonly object readWriteLock = new(); + private readonly Lock readWriteLock = new(); /// /// Initialization of the Mailer bot diff --git a/MinecraftClient/Logger/FileLogLogger.cs b/MinecraftClient/Logger/FileLogLogger.cs index 9614a5c4..a7931202 100644 --- a/MinecraftClient/Logger/FileLogLogger.cs +++ b/MinecraftClient/Logger/FileLogLogger.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Threading; using MinecraftClient.Scripting; namespace MinecraftClient.Logger @@ -8,7 +9,7 @@ namespace MinecraftClient.Logger { private readonly string logFile; private readonly bool prependTimestamp; - private readonly object logFileLock = new(); + private readonly Lock logFileLock = new(); public FileLogLogger(string file, bool prependTimestamp = false) { diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index 45a9f776..2f220594 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -43,7 +43,7 @@ namespace MinecraftClient private static DateTime nextMessageSendTime = DateTime.MinValue; private readonly Queue threadTasks = new(); - private readonly object threadTasksLock = new(); + private readonly Lock threadTasksLock = new(); private readonly List bots = new(); private static readonly List botsOnHold = new(); @@ -58,7 +58,7 @@ namespace MinecraftClient private bool inventoryHandlingRequested = false; private bool entityHandlingEnabled; - private readonly object locationLock = new(); + private readonly Lock locationLock = new(); private bool locationReceived = false; private readonly World world = new(); private Queue? steps; @@ -86,7 +86,7 @@ namespace MinecraftClient private readonly string sessionid; private readonly PlayerKeyPair? playerKeyPair; private DateTime lastKeepAlive; - private readonly object lastKeepAliveLock = new(); + private readonly Lock lastKeepAliveLock = new(); private int respawnTicks = 0; private int gamemode = 0; private bool isSupportPreviewsChat; @@ -94,7 +94,7 @@ namespace MinecraftClient private int playerEntityID; - private object DigLock = new(); + private readonly Lock DigLock = new(); private Tuple? LastDigPosition; private int RemainingDiggingTime = 0; diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 9b35c026..a11efc1e 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -102,7 +102,7 @@ namespace MinecraftClient.Protocol.Handlers private int oldSamplesWeight = 1; private bool receiveDeclareCommands = false, receivePlayerInfo = false; - private object MessageSigningLock = new(); + private readonly Lock MessageSigningLock = new(); private Guid chatUuid = Guid.NewGuid(); private int pendingAcknowledgments = 0, messageIndex = 0; private LastSeenMessagesCollector lastSeenMessagesCollector; diff --git a/MinecraftClient/Scripting/ChatBot.cs b/MinecraftClient/Scripting/ChatBot.cs index 024b74af..be825fe8 100644 --- a/MinecraftClient/Scripting/ChatBot.cs +++ b/MinecraftClient/Scripting/ChatBot.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; +using System.Threading; using Brigadier.NET; using MinecraftClient.CommandHandler; using MinecraftClient.Inventory; @@ -42,7 +43,7 @@ namespace MinecraftClient.Scripting private McClient? _handler = null; private ChatBot? master = null; private readonly List registeredPluginChannels = new(); - private readonly object delayTasksLock = new(); + private readonly Lock delayTasksLock = new(); private readonly List delayedTasks = new(); protected McClient Handler { diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index ab576cc7..6ee9ecfd 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -1011,7 +1011,7 @@ namespace MinecraftClient private readonly Dictionary VarObject = new(); [NonSerialized] - readonly object varLock = new(); + readonly Lock varLock = new(); /// /// Set a custom %variable% which will be available through expandVars() diff --git a/MinecraftClient/TaskWithResult.cs b/MinecraftClient/TaskWithResult.cs index 90e21e8d..4cf28659 100644 --- a/MinecraftClient/TaskWithResult.cs +++ b/MinecraftClient/TaskWithResult.cs @@ -14,7 +14,7 @@ namespace MinecraftClient private T? result = default; private Exception? exception = null; private bool taskRun = false; - private readonly object taskRunLock = new(); + private readonly Lock taskRunLock = new(); /// /// Create a new asynchronous task with return value diff --git a/MinecraftClient/config/sample-script-packet-capture.cs b/MinecraftClient/config/sample-script-packet-capture.cs index bfebb214..981ddb49 100644 --- a/MinecraftClient/config/sample-script-packet-capture.cs +++ b/MinecraftClient/config/sample-script-packet-capture.cs @@ -4,12 +4,14 @@ MCC.LoadBot(new PacketCadenceCaptureBot()); //MCCScript Extensions +using System.Threading; + public class PacketCadenceCaptureBot : ChatBot { private const int CaptureDurationSeconds = 5; private const int CaptureDurationTicks = CaptureDurationSeconds * 20; - private readonly object _countsLock = new(); + private readonly Lock _countsLock = new(); private readonly Dictionary _counts = new() { { "PlayerMovement", 0 },