From 9947b89da16ff656b42efb69a1cc565bedbdaa18 Mon Sep 17 00:00:00 2001 From: psu Date: Sat, 27 Jul 2024 20:51:38 +0200 Subject: [PATCH] update last events --- Components/MineSharp.Protocol/Events.cs | 19 ----------- Components/MineSharp.World/Chunks/IChunk.cs | 3 +- .../MineSharp.World/V1_18/Chunk_1_18.cs | 5 +-- MineSharp.Bot/Events.cs | 34 ------------------- 4 files changed, 5 insertions(+), 56 deletions(-) delete mode 100644 Components/MineSharp.Protocol/Events.cs delete mode 100644 MineSharp.Bot/Events.cs diff --git a/Components/MineSharp.Protocol/Events.cs b/Components/MineSharp.Protocol/Events.cs deleted file mode 100644 index 14f06aba..00000000 --- a/Components/MineSharp.Protocol/Events.cs +++ /dev/null @@ -1,19 +0,0 @@ -using MineSharp.Protocol.Packets; - -namespace MineSharp.Protocol; - -/// -/// Event delegates used by MineSharp.Protocol -/// -public static class Events -{ - /// - /// Delegate with MinecraftClient and IPacket - /// - public delegate void ClientPacketEvent(MinecraftClient sender, IPacket packet); - - /// - /// Delegate with MinecraftClient and a string - /// - public delegate void ClientStringEvent(MinecraftClient sender, string message); -} diff --git a/Components/MineSharp.World/Chunks/IChunk.cs b/Components/MineSharp.World/Chunks/IChunk.cs index 0846fa6f..835e33d0 100644 --- a/Components/MineSharp.World/Chunks/IChunk.cs +++ b/Components/MineSharp.World/Chunks/IChunk.cs @@ -1,5 +1,6 @@ using MineSharp.Core.Common.Biomes; using MineSharp.Core.Common.Blocks; +using MineSharp.Core.Events; using MineSharp.Core.Geometry; namespace MineSharp.World.Chunks; @@ -23,7 +24,7 @@ public interface IChunk /// /// Fired whenever a block in the chunk was updated /// - public event Events.ChunkBlockEvent OnBlockUpdated; + public AsyncEvent OnBlockUpdated { get; set; } /// /// Loads the chunk data from raw bytes. diff --git a/Components/MineSharp.World/V1_18/Chunk_1_18.cs b/Components/MineSharp.World/V1_18/Chunk_1_18.cs index f56095dc..af1c3deb 100644 --- a/Components/MineSharp.World/V1_18/Chunk_1_18.cs +++ b/Components/MineSharp.World/V1_18/Chunk_1_18.cs @@ -1,6 +1,7 @@ using MineSharp.Core.Common; using MineSharp.Core.Common.Biomes; using MineSharp.Core.Common.Blocks; +using MineSharp.Core.Events; using MineSharp.Core.Geometry; using MineSharp.Data; using MineSharp.World.Chunks; @@ -42,7 +43,7 @@ public Chunk118(MinecraftData data, ChunkCoordinates coordinates, BlockEntity[] public ChunkCoordinates Coordinates { get; } /// - public event Events.ChunkBlockEvent? OnBlockUpdated; + public AsyncEvent OnBlockUpdated { get; set; } = new(); /// public void LoadData(byte[] buf) @@ -76,7 +77,7 @@ public void SetBlockAt(int state, Position position) (var y, var section) = GetChunkSectionAndNewYFromPosition(position); section.SetBlockAt(state, new(position.X, y, position.Z)); - OnBlockUpdated?.Invoke(this, state, position); + OnBlockUpdated.Dispatch(this, state, position); } /// diff --git a/MineSharp.Bot/Events.cs b/MineSharp.Bot/Events.cs deleted file mode 100644 index 9ed1fc26..00000000 --- a/MineSharp.Bot/Events.cs +++ /dev/null @@ -1,34 +0,0 @@ -using MineSharp.Bot.Chat; -using MineSharp.Core.Common; -using MineSharp.Core.Common.Entities; -using MineSharp.Core.Common.Items; -using MineSharp.Windows; - -namespace MineSharp.Bot; - -/// -/// Event delegates used by MineSharp.Bot -/// -public static class Events -{ -#pragma warning disable CS1591 - - public delegate void BotEvent(MineSharpBot sender); - - public delegate void BotStringEvent(MineSharpBot sender, string message); - - public delegate void BotChatEvent(MineSharpBot sender, ChatComponent.Chat message); - - public delegate void BotChatMessageEvent(MineSharpBot sender, Uuid? player, ChatComponent.Chat message, - ChatMessageType chatPosition); - - public delegate void EntityEvent(MineSharpBot sender, Entity entity); - - public delegate void PlayerEvent(MineSharpBot sender, MinecraftPlayer player); - - public delegate void WindowEvent(MineSharpBot sender, Window window); - - public delegate void ItemEvent(MineSharpBot sender, Item? item); - -#pragma warning restore CS1591 -}