From dcabd2eb94c66874f63d31cd1920cce0c85aa7ce Mon Sep 17 00:00:00 2001 From: Martin <7252614+Lhoerion@users.noreply.github.com> Date: Mon, 9 Dec 2019 13:29:11 +0100 Subject: [PATCH] Refactor event handlers, update example resource (#110) * Refactor event handlers, rename attributes, update SampleResource * Refactor async event handlers, rename async attributes, update EventAttribute, update SampleResource * Fix warnings in Alt.RegisterEvents & AltAsync.RegisterEvents, fix implicitly called closures in AsyncModule, update example resource --- api/AltV.Net.Async/AltAsync.Off.cs | 493 +++++++++ api/AltV.Net.Async/AltAsync.On.cs | 288 ++++- api/AltV.Net.Async/AltAsync.RegisterEvents.cs | 454 ++++---- ...cEvent.cs => AsyncClientEventAttribute.cs} | 4 +- api/AltV.Net.Async/AsyncEventAttribute.cs | 16 + api/AltV.Net.Async/AsyncModule.cs | 300 +++++- ...tEvent.cs => AsyncScriptEventAttribute.cs} | 28 +- .../AsyncServerEventAttribute.cs | 15 + api/AltV.Net.Example/SampleResource.cs | 93 +- api/AltV.Net.Example/SampleScript.cs | 4 +- api/AltV.Net/Alt.CustomEventParser.cs | 739 +++++++++++++ api/AltV.Net/Alt.CustomParser.cs | 151 --- api/AltV.Net/Alt.Off.cs | 988 +++++++++--------- api/AltV.Net/Alt.On.cs | 282 +++++ api/AltV.Net/Alt.RegisterEvents.cs | 506 ++++----- api/AltV.Net/Alt.ServerCustomParser.cs | 151 --- .../{Event.cs => ClientEventAttribute.cs} | 4 +- api/AltV.Net/EventAttribute.cs | 16 + api/AltV.Net/Module.cs | 245 +++-- .../ResourceSharedAssembliesAttribute.cs | 4 +- ...ScriptEvent.cs => ScriptEventAttribute.cs} | 28 +- api/AltV.Net/ServerEventAttribute.cs | 15 + 22 files changed, 3341 insertions(+), 1483 deletions(-) create mode 100644 api/AltV.Net.Async/AltAsync.Off.cs rename api/AltV.Net.Async/{AsyncEvent.cs => AsyncClientEventAttribute.cs} (59%) create mode 100644 api/AltV.Net.Async/AsyncEventAttribute.cs rename api/AltV.Net.Async/{AsyncScriptEvent.cs => AsyncScriptEventAttribute.cs} (61%) create mode 100644 api/AltV.Net.Async/AsyncServerEventAttribute.cs create mode 100644 api/AltV.Net/Alt.CustomEventParser.cs delete mode 100644 api/AltV.Net/Alt.CustomParser.cs delete mode 100644 api/AltV.Net/Alt.ServerCustomParser.cs rename api/AltV.Net/{Event.cs => ClientEventAttribute.cs} (61%) create mode 100644 api/AltV.Net/EventAttribute.cs rename api/AltV.Net/{ScriptEvent.cs => ScriptEventAttribute.cs} (62%) create mode 100644 api/AltV.Net/ServerEventAttribute.cs diff --git a/api/AltV.Net.Async/AltAsync.Off.cs b/api/AltV.Net.Async/AltAsync.Off.cs new file mode 100644 index 000000000..6d28695cf --- /dev/null +++ b/api/AltV.Net.Async/AltAsync.Off.cs @@ -0,0 +1,493 @@ +using System; +using AltV.Net.Async.Events; + +namespace AltV.Net.Async +{ + public partial class AltAsync + { + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, Function function) => Module.Off(eventName, function); + + [Obsolete("This method is obsolete. Use AltAsync.OffClient instead.")] + public static void OffClient(string eventName, ClientEventAsyncDelegate clientEventDelegate) + { + Module.OffClient(eventName, clientEventDelegate); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer instead.")] + public static void OffServer(string eventName, ServerEventAsyncDelegate serverEventDelegate) + { + Module.OffServer(eventName, serverEventDelegate); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use AltAsync.OffServer or AltAsync.OffClient instead.")] + public static void Off( + string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + public static void OffServer(string eventName, Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer( + string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer( + string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer( + string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + + public static void OffClient(string eventName, Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient( + string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient( + string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient( + string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + } +} \ No newline at end of file diff --git a/api/AltV.Net.Async/AltAsync.On.cs b/api/AltV.Net.Async/AltAsync.On.cs index d569c94d6..ad2e5b38f 100644 --- a/api/AltV.Net.Async/AltAsync.On.cs +++ b/api/AltV.Net.Async/AltAsync.On.cs @@ -5,206 +5,488 @@ namespace AltV.Net.Async { public static partial class AltAsync { + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Function function) => Module.On(eventName, function); - + + [Obsolete("This method is obsolete. Use AltAsync.OnClient instead.")] public static void OnClient(string eventName, ClientEventAsyncDelegate clientEventDelegate) { Module.OnClient(eventName, clientEventDelegate); } - + + [Obsolete("This method is obsolete. Use AltAsync.OnServer instead.")] public static void OnServer(string eventName, ServerEventAsyncDelegate serverEventDelegate) { Module.OnServer(eventName, serverEventDelegate); } - + + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use AltAsync.OnServer or AltAsync.OnClient instead.")] public static void On( string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + + public static void OnServer(string eventName, Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer( + string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer( + string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer( + string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + + public static void OnClient(string eventName, Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient( + string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient( + string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient( + string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); } } \ No newline at end of file diff --git a/api/AltV.Net.Async/AltAsync.RegisterEvents.cs b/api/AltV.Net.Async/AltAsync.RegisterEvents.cs index 9b12268a1..03c586261 100644 --- a/api/AltV.Net.Async/AltAsync.RegisterEvents.cs +++ b/api/AltV.Net.Async/AltAsync.RegisterEvents.cs @@ -1,222 +1,234 @@ -using AltV.Net.Elements.Entities; -using AltV.Net.FunctionParser; - -namespace AltV.Net.Async -{ - public partial class AltAsync - { - public static void RegisterEvents(object target) - { - ModuleScriptMethodIndexer.Index(target, new[] {typeof(AsyncEvent), typeof(AsyncScriptEvent)}, - (baseEvent, eventMethod, eventMethodDelegate) => - { - switch (baseEvent) - { - case AsyncScriptEvent scriptEvent: - var scriptEventType = scriptEvent.EventType; - ScriptFunction scriptFunction; - switch (scriptEventType) - { - case ScriptEventType.Checkpoint: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(ICheckpoint), typeof(IEntity), typeof(bool)}); - if (scriptFunction == null) return; - OnCheckpoint += (checkpoint, entity, state) => - { - scriptFunction.Set(checkpoint); - scriptFunction.Set(entity); - scriptFunction.Set(state); - return scriptFunction.CallAsync(); - }; - break; - case ScriptEventType.PlayerConnect: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IPlayer), typeof(string)}); - if (scriptFunction == null) return; - OnPlayerConnect += (player, reason) => - { - scriptFunction.Set(player); - scriptFunction.Set(reason); - return scriptFunction.CallAsync(); - }; - break; - case ScriptEventType.PlayerDamage: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IPlayer), typeof(IEntity), typeof(uint), typeof(ushort)}); - if (scriptFunction == null) return; - OnPlayerDamage += (player, attacker, - oldHealth, oldArmor, - oldMaxHealth, oldMaxArmor, - weapon, damage) => - { - scriptFunction.Set(player); - scriptFunction.Set(attacker); - scriptFunction.Set(weapon); - scriptFunction.Set(damage); - return scriptFunction.CallAsync(); - }; - break; - case ScriptEventType.PlayerDead: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IPlayer), typeof(IEntity), typeof(uint)}); - if (scriptFunction == null) return; - OnPlayerDead += (player, attacker, weapon) => - { - scriptFunction.Set(player); - scriptFunction.Set(attacker); - scriptFunction.Set(weapon); - return scriptFunction.CallAsync(); - }; - break; - case ScriptEventType.PlayerDisconnect: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IPlayer), typeof(string)}); - if (scriptFunction == null) return; - OnPlayerDisconnect += (player, reason) => - { - scriptFunction.Set(player); - scriptFunction.Set(reason); - return scriptFunction.CallAsync(); - }; - break; - case ScriptEventType.PlayerRemove: - scriptFunction = - ScriptFunction.Create(eventMethodDelegate, new[] {typeof(IPlayer)}); - if (scriptFunction == null) return; - OnPlayerRemove += player => - { - scriptFunction.Set(player); - return scriptFunction.CallAsync(); - }; - break; - case ScriptEventType.VehicleRemove: - scriptFunction = - ScriptFunction.Create(eventMethodDelegate, new[] {typeof(IVehicle)}); - if (scriptFunction == null) return; - OnVehicleRemove += vehicle => - { - scriptFunction.Set(vehicle); - return scriptFunction.CallAsync(); - }; - break; - case ScriptEventType.PlayerChangeVehicleSeat: - scriptFunction = - ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IVehicle), typeof(IPlayer), typeof(byte), typeof(byte)}); - if (scriptFunction == null) return; - OnPlayerChangeVehicleSeat += (vehicle, player, seat, newSeat) => - { - scriptFunction.Set(vehicle); - scriptFunction.Set(player); - scriptFunction.Set(seat); - scriptFunction.Set(newSeat); - return scriptFunction.CallAsync(); - }; - break; - case ScriptEventType.PlayerEnterVehicle: - scriptFunction = - ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IVehicle), typeof(IPlayer), typeof(byte)}); - if (scriptFunction == null) return; - OnPlayerEnterVehicle += (vehicle, player, seat) => - { - scriptFunction.Set(vehicle); - scriptFunction.Set(player); - scriptFunction.Set(seat); - return scriptFunction.CallAsync(); - }; - break; - case ScriptEventType.PlayerLeaveVehicle: - scriptFunction = - ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IVehicle), typeof(IPlayer), typeof(byte)}); - if (scriptFunction == null) return; - OnPlayerLeaveVehicle += (vehicle, player, seat) => - { - scriptFunction.Set(vehicle); - scriptFunction.Set(player); - scriptFunction.Set(seat); - return scriptFunction.CallAsync(); - }; - break; - case ScriptEventType.PlayerEvent: - scriptFunction = - ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IPlayer), typeof(string), typeof(object[])}); - if (scriptFunction == null) return; - OnPlayerEvent += (player, name, args) => - { - scriptFunction.Set(player); - scriptFunction.Set(name); - scriptFunction.Set(args); - return scriptFunction.CallAsync(); - }; - break; - case ScriptEventType.PlayerCustomEvent: - Alt.Log("PlayerCustomEvent does not exists in async"); - break; - case ScriptEventType.ServerEvent: - Alt.Log("PlayerCustomEvent does not exists in async"); - break; - case ScriptEventType.ServerCustomEvent: - Alt.Log("PlayerCustomEvent does not exists in async"); - break; - case ScriptEventType.ConsoleCommand: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(string), typeof(string[])}); - if (scriptFunction == null) return; - OnConsoleCommand += (name, args) => - { - scriptFunction.Set(name); - scriptFunction.Set(args); - return scriptFunction.CallAsync(); - }; - break; - case ScriptEventType.MetaDataChange: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IEntity), typeof(string), typeof(object)}); - if (scriptFunction == null) return; - OnMetaDataChange += (entity, key, value) => - { - scriptFunction.Set(entity); - scriptFunction.Set(key); - scriptFunction.Set(value); - return scriptFunction.CallAsync(); - }; - break; - case ScriptEventType.SyncedMetaDataChange: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IEntity), typeof(string), typeof(object)}); - if (scriptFunction == null) return; - OnSyncedMetaDataChange += (entity, key, value) => - { - scriptFunction.Set(entity); - scriptFunction.Set(key); - scriptFunction.Set(value); - return scriptFunction.CallAsync(); - }; - break; - case ScriptEventType.ColShape: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IColShape), typeof(IEntity), typeof(bool)}); - if (scriptFunction == null) return; - OnColShape += (shape, entity, state) => - { - scriptFunction.Set(shape); - scriptFunction.Set(entity); - scriptFunction.Set(state); - return scriptFunction.CallAsync(); - }; - break; - } - - break; - case AsyncEvent @event: - var eventName = @event.Name ?? eventMethod.Name; - Module.On(eventName, Function.Create(eventMethodDelegate)); - break; - } - }); - } - } +using AltV.Net.Elements.Entities; +using AltV.Net.FunctionParser; + +namespace AltV.Net.Async +{ + public partial class AltAsync + { + public static void RegisterEvents(object target) + { +#pragma warning disable 612, 618 + ModuleScriptMethodIndexer.Index(target, new[] {typeof(AsyncEventAttribute), typeof(AsyncServerEventAttribute), typeof(AsyncClientEventAttribute), typeof(AsyncScriptEventAttribute)}, +#pragma warning restore 612, 618 + (baseEvent, eventMethod, eventMethodDelegate) => + { + switch (baseEvent) + { + case AsyncScriptEventAttribute scriptEvent: + var scriptEventType = scriptEvent.EventType; + ScriptFunction scriptFunction; + switch (scriptEventType) + { + case ScriptEventType.Checkpoint: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(ICheckpoint), typeof(IEntity), typeof(bool)}); + if (scriptFunction == null) return; + OnCheckpoint += (checkpoint, entity, state) => + { + scriptFunction.Set(checkpoint); + scriptFunction.Set(entity); + scriptFunction.Set(state); + return scriptFunction.CallAsync(); + }; + break; + case ScriptEventType.PlayerConnect: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IPlayer), typeof(string)}); + if (scriptFunction == null) return; + OnPlayerConnect += (player, reason) => + { + scriptFunction.Set(player); + scriptFunction.Set(reason); + return scriptFunction.CallAsync(); + }; + break; + case ScriptEventType.PlayerDamage: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IPlayer), typeof(IEntity), typeof(uint), typeof(ushort)}); + if (scriptFunction == null) return; + OnPlayerDamage += (player, attacker, + oldHealth, oldArmor, + oldMaxHealth, oldMaxArmor, + weapon, damage) => + { + scriptFunction.Set(player); + scriptFunction.Set(attacker); + scriptFunction.Set(weapon); + scriptFunction.Set(damage); + return scriptFunction.CallAsync(); + }; + break; + case ScriptEventType.PlayerDead: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IPlayer), typeof(IEntity), typeof(uint)}); + if (scriptFunction == null) return; + OnPlayerDead += (player, attacker, weapon) => + { + scriptFunction.Set(player); + scriptFunction.Set(attacker); + scriptFunction.Set(weapon); + return scriptFunction.CallAsync(); + }; + break; + case ScriptEventType.PlayerDisconnect: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IPlayer), typeof(string)}); + if (scriptFunction == null) return; + OnPlayerDisconnect += (player, reason) => + { + scriptFunction.Set(player); + scriptFunction.Set(reason); + return scriptFunction.CallAsync(); + }; + break; + case ScriptEventType.PlayerRemove: + scriptFunction = + ScriptFunction.Create(eventMethodDelegate, new[] {typeof(IPlayer)}); + if (scriptFunction == null) return; + OnPlayerRemove += player => + { + scriptFunction.Set(player); + return scriptFunction.CallAsync(); + }; + break; + case ScriptEventType.VehicleRemove: + scriptFunction = + ScriptFunction.Create(eventMethodDelegate, new[] {typeof(IVehicle)}); + if (scriptFunction == null) return; + OnVehicleRemove += vehicle => + { + scriptFunction.Set(vehicle); + return scriptFunction.CallAsync(); + }; + break; + case ScriptEventType.PlayerChangeVehicleSeat: + scriptFunction = + ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IVehicle), typeof(IPlayer), typeof(byte), typeof(byte)}); + if (scriptFunction == null) return; + OnPlayerChangeVehicleSeat += (vehicle, player, seat, newSeat) => + { + scriptFunction.Set(vehicle); + scriptFunction.Set(player); + scriptFunction.Set(seat); + scriptFunction.Set(newSeat); + return scriptFunction.CallAsync(); + }; + break; + case ScriptEventType.PlayerEnterVehicle: + scriptFunction = + ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IVehicle), typeof(IPlayer), typeof(byte)}); + if (scriptFunction == null) return; + OnPlayerEnterVehicle += (vehicle, player, seat) => + { + scriptFunction.Set(vehicle); + scriptFunction.Set(player); + scriptFunction.Set(seat); + return scriptFunction.CallAsync(); + }; + break; + case ScriptEventType.PlayerLeaveVehicle: + scriptFunction = + ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IVehicle), typeof(IPlayer), typeof(byte)}); + if (scriptFunction == null) return; + OnPlayerLeaveVehicle += (vehicle, player, seat) => + { + scriptFunction.Set(vehicle); + scriptFunction.Set(player); + scriptFunction.Set(seat); + return scriptFunction.CallAsync(); + }; + break; + case ScriptEventType.PlayerEvent: + scriptFunction = + ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IPlayer), typeof(string), typeof(object[])}); + if (scriptFunction == null) return; + OnPlayerEvent += (player, name, args) => + { + scriptFunction.Set(player); + scriptFunction.Set(name); + scriptFunction.Set(args); + return scriptFunction.CallAsync(); + }; + break; + case ScriptEventType.PlayerCustomEvent: + Alt.Log("PlayerCustomEvent does not exists in async"); + break; + case ScriptEventType.ServerEvent: + Alt.Log("PlayerCustomEvent does not exists in async"); + break; + case ScriptEventType.ServerCustomEvent: + Alt.Log("PlayerCustomEvent does not exists in async"); + break; + case ScriptEventType.ConsoleCommand: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(string), typeof(string[])}); + if (scriptFunction == null) return; + OnConsoleCommand += (name, args) => + { + scriptFunction.Set(name); + scriptFunction.Set(args); + return scriptFunction.CallAsync(); + }; + break; + case ScriptEventType.MetaDataChange: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IEntity), typeof(string), typeof(object)}); + if (scriptFunction == null) return; + OnMetaDataChange += (entity, key, value) => + { + scriptFunction.Set(entity); + scriptFunction.Set(key); + scriptFunction.Set(value); + return scriptFunction.CallAsync(); + }; + break; + case ScriptEventType.SyncedMetaDataChange: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IEntity), typeof(string), typeof(object)}); + if (scriptFunction == null) return; + OnSyncedMetaDataChange += (entity, key, value) => + { + scriptFunction.Set(entity); + scriptFunction.Set(key); + scriptFunction.Set(value); + return scriptFunction.CallAsync(); + }; + break; + case ScriptEventType.ColShape: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IColShape), typeof(IEntity), typeof(bool)}); + if (scriptFunction == null) return; + OnColShape += (shape, entity, state) => + { + scriptFunction.Set(shape); + scriptFunction.Set(entity); + scriptFunction.Set(state); + return scriptFunction.CallAsync(); + }; + break; + } + + break; +#pragma warning disable 612, 618 + case AsyncEventAttribute @event: + var eventName = @event.Name ?? eventMethod.Name; + Module.On(eventName, Function.Create(eventMethodDelegate)); + break; +#pragma warning restore 612, 618 + case AsyncServerEventAttribute @event: + var serverEventName = @event.Name ?? eventMethod.Name; + Module.OnServer(serverEventName, Function.Create(eventMethodDelegate)); + break; + case AsyncClientEventAttribute @event: + var clientEventName = @event.Name ?? eventMethod.Name; + Module.OnClient(clientEventName, Function.Create(eventMethodDelegate)); + break; + } + }); + } + } } \ No newline at end of file diff --git a/api/AltV.Net.Async/AsyncEvent.cs b/api/AltV.Net.Async/AsyncClientEventAttribute.cs similarity index 59% rename from api/AltV.Net.Async/AsyncEvent.cs rename to api/AltV.Net.Async/AsyncClientEventAttribute.cs index 4d9870b7a..5db8ce0e2 100644 --- a/api/AltV.Net.Async/AsyncEvent.cs +++ b/api/AltV.Net.Async/AsyncClientEventAttribute.cs @@ -3,11 +3,11 @@ namespace AltV.Net.Async { [AttributeUsage(AttributeTargets.Method)] - public class AsyncEvent : Attribute + public sealed class AsyncClientEventAttribute : Attribute { public string Name { get; } - public AsyncEvent(string name = null) + public AsyncClientEventAttribute(string name = null) { Name = name; } diff --git a/api/AltV.Net.Async/AsyncEventAttribute.cs b/api/AltV.Net.Async/AsyncEventAttribute.cs new file mode 100644 index 000000000..e3f33b1c7 --- /dev/null +++ b/api/AltV.Net.Async/AsyncEventAttribute.cs @@ -0,0 +1,16 @@ +using System; + +namespace AltV.Net.Async +{ + [Obsolete("This attribute is obsolete. Use AsyncServerEventAttribute or AsyncClientEventAttribute instead.")] + [AttributeUsage(AttributeTargets.Method)] + public sealed class AsyncEventAttribute : Attribute + { + public string Name { get; } + + public AsyncEventAttribute(string name = null) + { + Name = name; + } + } +} \ No newline at end of file diff --git a/api/AltV.Net.Async/AsyncModule.cs b/api/AltV.Net.Async/AsyncModule.cs index 1dcbbaa70..399d67613 100644 --- a/api/AltV.Net.Async/AsyncModule.cs +++ b/api/AltV.Net.Async/AsyncModule.cs @@ -8,15 +8,26 @@ using AltV.Net.Elements.Entities; using AltV.Net.Elements.Args; using AltV.Net.Elements.Refs; -using AltV.Net.Native; namespace AltV.Net.Async { public class AsyncModule : Module { - internal readonly Dictionary> AsyncEventHandlers = + private readonly Dictionary> asyncEventBus = new Dictionary>(); + private readonly Dictionary> asyncEventBusClient = + new Dictionary>(); + + private readonly Dictionary> asyncEventBusServer = + new Dictionary>(); + + private readonly Dictionary> asyncEventBusClientDelegate = + new Dictionary>(); + + private readonly Dictionary> asyncEventBusServerDelegate = + new Dictionary>(); + internal readonly AsyncEventHandler CheckpointAsyncEventHandler = new AsyncEventHandler(); @@ -69,14 +80,6 @@ internal readonly AsyncEventHandler internal readonly AsyncEventHandler ColShapeAsyncDelegateHandlers = new AsyncEventHandler(); - private readonly Dictionary> clientEventAsyncDelegateHandlers - = - new Dictionary>(); - - private readonly Dictionary> serverEventAsyncDelegateHandlers - = - new Dictionary>(); - public AsyncModule(IServer server, AssemblyLoadContext assemblyLoadContext, INativeResource moduleResource, IBaseBaseObjectPool baseBaseObjectPool, IBaseEntityPool baseEntityPool, IEntityPool playerPool, IEntityPool vehiclePool, @@ -382,9 +385,59 @@ public override void OnClientEventEvent(IPlayer player, string name, IntPtr[] ar object[] objects) { base.OnClientEventEvent(player, name, args, mValues, objects); - int length = args.Length; + var length = args.Length; + + if (asyncEventBus.Count != 0 && asyncEventBus.TryGetValue(name, out var eventHandlers)) + { + if (mValues == null) + { + mValues = new MValueConst[length]; + for (var i = 0; i < length; i++) + { + mValues[i] = new MValueConst(args[i]); + } + } + + if (objects == null) + { + objects = new object[length]; + for (var i = 0; i < length; i++) + { + objects[i] = mValues[i].ToObject(); + } + } + + Task.Factory.StartNew(async obj => + { + var (taskPlayer, taskObjects, taskEventHandlers, taskName) = + (ValueTuple, string>) obj; + foreach (var eventHandler in taskEventHandlers) + { + var invokeValues = eventHandler.CalculateInvokeValues(taskPlayer, taskObjects); + if (invokeValues != null) + { + try + { + var task = eventHandler.InvokeTaskOrNull(invokeValues); + if (task != null) + { + await task; + } + } + catch (Exception e) + { + AltAsync.Log($"Execution of {taskName} threw an error: {e}"); + } + } + else + { + AltAsync.Log("Wrong function params for " + taskName); + } + } + }, new ValueTuple, string>(player, objects, eventHandlers, name)); + } - if (AsyncEventHandlers.Count != 0 && AsyncEventHandlers.TryGetValue(name, out var eventHandlers)) + if (asyncEventBusClient.Count != 0 && asyncEventBusClient.TryGetValue(name, out var eventHandlersClient)) { if (mValues == null) { @@ -404,11 +457,13 @@ public override void OnClientEventEvent(IPlayer player, string name, IntPtr[] ar } } - Task.Run(async () => + Task.Factory.StartNew(async obj => { - foreach (var eventHandler in eventHandlers) + var (taskPlayer, taskObjects, taskEventHandlers, taskName) = + (ValueTuple, string>) obj; + foreach (var eventHandler in taskEventHandlers) { - var invokeValues = eventHandler.CalculateInvokeValues(player, objects); + var invokeValues = eventHandler.CalculateInvokeValues(taskPlayer, taskObjects); if (invokeValues != null) { try @@ -421,19 +476,19 @@ public override void OnClientEventEvent(IPlayer player, string name, IntPtr[] ar } catch (Exception e) { - AltAsync.Log($"Execution of {name} threw an error: {e}"); + AltAsync.Log($"Execution of {taskName} threw an error: {e}"); } } else { - AltAsync.Log("Wrong function params for " + name); + AltAsync.Log("Wrong function params for " + taskName); } } - }); + }, new ValueTuple, string>(player, objects, eventHandlersClient, name)); } - if (clientEventAsyncDelegateHandlers.Count != 0 && - clientEventAsyncDelegateHandlers.TryGetValue(name, out var eventDelegates)) + if (asyncEventBusClientDelegate.Count != 0 && + asyncEventBusClientDelegate.TryGetValue(name, out var eventDelegates)) { if (mValues == null) { @@ -453,14 +508,16 @@ public override void OnClientEventEvent(IPlayer player, string name, IntPtr[] ar } } - Task.Run(() => + Task.Factory.StartNew(obj => { - foreach (var eventHandler in eventDelegates) + var (taskPlayer, taskObjects, taskEventHandlers) = + (ValueTuple>) obj; + foreach (var eventHandler in taskEventHandlers) { AsyncEventHandler.ExecuteEventAsyncWithoutTask(eventHandler, - @delegate => @delegate(player, objects)); + @delegate => @delegate(taskPlayer, taskObjects)); } - }); + }, new ValueTuple>(player, objects, eventDelegates)); } if (PlayerClientEventAsyncEventHandler.HasEvents()) @@ -483,14 +540,16 @@ public override void OnClientEventEvent(IPlayer player, string name, IntPtr[] ar } } - Task.Run(() => + Task.Factory.StartNew(obj => { - foreach (var eventHandler in PlayerClientEventAsyncEventHandler.GetEvents()) + var (taskPlayer, taskObjects, taskEventHandlers, taskName) = + (ValueTuple, string>) obj; + foreach (var eventHandler in taskEventHandlers.GetEvents()) { AsyncEventHandler.ExecuteEventAsyncWithoutTask(eventHandler, - @delegate => @delegate(player, name, objects)); + @delegate => @delegate(taskPlayer, taskName, taskObjects)); } - }); + }, new ValueTuple, string>(player, objects, PlayerClientEventAsyncEventHandler, name)); } } @@ -499,7 +558,57 @@ public override void OnServerEventEvent(string name, IntPtr[] args, MValueConst[ base.OnServerEventEvent(name, args, mValues, objects); var length = args.Length; - if (AsyncEventHandlers.Count != 0 && AsyncEventHandlers.TryGetValue(name, out var eventHandlers)) + if (asyncEventBusServer.Count != 0 && asyncEventBusServer.TryGetValue(name, out var eventHandlersServer)) + { + if (mValues == null) + { + mValues = new MValueConst[length]; + for (var i = 0; i < length; i++) + { + mValues[i] = new MValueConst(args[i]); + } + } + + if (objects == null) + { + objects = new object[length]; + for (var i = 0; i < length; i++) + { + objects[i] = mValues[i].ToObject(); + } + } + + Task.Factory.StartNew(async obj => + { + var (taskObjects, taskEventHandlers, taskName) = + (ValueTuple, string>) obj; + foreach (var eventHandler in taskEventHandlers) + { + var invokeValues = eventHandler.CalculateInvokeValues(taskObjects); + if (invokeValues != null) + { + try + { + var task = eventHandler.InvokeTaskOrNull(invokeValues); + if (task != null) + { + await task; + } + } + catch (Exception e) + { + AltAsync.Log($"Execution of {taskName} threw an error: {e}"); + } + } + else + { + AltAsync.Log("Wrong function params for " + taskName); + } + } + }, new ValueTuple, string>(objects, eventHandlersServer, name)); + } + + if (asyncEventBus.Count != 0 && asyncEventBus.TryGetValue(name, out var eventHandlers)) { if (mValues == null) { @@ -519,11 +628,13 @@ public override void OnServerEventEvent(string name, IntPtr[] args, MValueConst[ } } - Task.Run(async () => + Task.Factory.StartNew(async obj => { - foreach (var eventHandler in eventHandlers) + var (taskObjects, taskEventHandlers, taskName) = + (ValueTuple, string>) obj; + foreach (var eventHandler in taskEventHandlers) { - var invokeValues = eventHandler.CalculateInvokeValues(objects); + var invokeValues = eventHandler.CalculateInvokeValues(taskObjects); if (invokeValues != null) { try @@ -536,19 +647,19 @@ public override void OnServerEventEvent(string name, IntPtr[] args, MValueConst[ } catch (Exception e) { - AltAsync.Log($"Execution of {name} threw an error: {e}"); + AltAsync.Log($"Execution of {taskName} threw an error: {e}"); } } else { - AltAsync.Log("Wrong function params for " + name); + AltAsync.Log("Wrong function params for " + taskName); } } - }); + }, new ValueTuple, string>(objects, eventHandlers, name)); } - if (serverEventAsyncDelegateHandlers.Count != 0 && - serverEventAsyncDelegateHandlers.TryGetValue(name, out var eventDelegates)) + if (asyncEventBusServerDelegate.Count != 0 && + asyncEventBusServerDelegate.TryGetValue(name, out var eventDelegates)) { if (mValues == null) { @@ -568,14 +679,16 @@ public override void OnServerEventEvent(string name, IntPtr[] args, MValueConst[ } } - Task.Run(() => + Task.Factory.StartNew(obj => { - foreach (var eventHandler in eventDelegates) + var (taskObjects, taskEventHandlers, taskName) = + (ValueTuple, string>) obj; + foreach (var eventHandler in taskEventHandlers) { AsyncEventHandler.ExecuteEventAsyncWithoutTask(eventHandler, - @delegate => @delegate(objects)); + @delegate => @delegate(taskObjects)); } - }); + }, new ValueTuple, string>(objects, eventDelegates, name)); } } @@ -688,45 +801,124 @@ await ColShapeAsyncDelegateHandlers.CallAsync(@delegate => } } + [Obsolete] + public new void On(string eventName, Function function) + { + if (function == null) return; + if (asyncEventBus.TryGetValue(eventName, out var eventHandlersForEvent)) + { + eventHandlersForEvent.Add(function); + } + else + { + eventHandlersForEvent = new HashSet {function}; + asyncEventBus[eventName] = eventHandlersForEvent; + } + } + + [Obsolete] + public new void Off(string eventName, Function function) + { + if (function == null) return; + if (asyncEventBus.TryGetValue(eventName, out var eventHandlers)) + { + eventHandlers.Remove(function); + } + } + + public new void OnClient(string eventName, Function function) + { + if (function == null) return; + if (asyncEventBusClient.TryGetValue(eventName, out var eventHandlersForEvent)) + { + eventHandlersForEvent.Add(function); + } + else + { + eventHandlersForEvent = new HashSet {function}; + asyncEventBusClient[eventName] = eventHandlersForEvent; + } + } + + public new void OffClient(string eventName, Function function) + { + if (function == null) return; + if (asyncEventBusClient.TryGetValue(eventName, out var eventHandlers)) + { + eventHandlers.Remove(function); + } + } + + public new void OnServer(string eventName, Function function) + { + if (function == null) return; + if (asyncEventBusServer.TryGetValue(eventName, out var eventHandlersForEvent)) + { + eventHandlersForEvent.Add(function); + } + else + { + eventHandlersForEvent = new HashSet {function}; + asyncEventBusServer[eventName] = eventHandlersForEvent; + } + } + + public new void OffServer(string eventName, Function function) + { + if (function == null) return; + if (asyncEventBusClient.TryGetValue(eventName, out var eventHandlers)) + { + eventHandlers.Remove(function); + } + } + + [Obsolete] public void OnClient(string eventName, ClientEventAsyncDelegate eventDelegate) { if (eventDelegate == null) return; - if (clientEventAsyncDelegateHandlers.TryGetValue(eventName, out var eventHandlersForEvent)) + if (asyncEventBusClientDelegate.TryGetValue(eventName, out var eventHandlersForEvent)) { eventHandlersForEvent.Add(eventDelegate); } else { eventHandlersForEvent = new HashSet {eventDelegate}; - clientEventAsyncDelegateHandlers[eventName] = eventHandlersForEvent; + asyncEventBusClientDelegate[eventName] = eventHandlersForEvent; + } + } + + [Obsolete] + public void OffClient(string eventName, ClientEventAsyncDelegate eventDelegate) + { + if (eventDelegate == null) return; + if (asyncEventBusClientDelegate.TryGetValue(eventName, out var eventHandlers)) + { + eventHandlers.Remove(eventDelegate); } } + [Obsolete] public void OnServer(string eventName, ServerEventAsyncDelegate eventDelegate) { if (eventDelegate == null) return; - if (serverEventAsyncDelegateHandlers.TryGetValue(eventName, out var eventHandlersForEvent)) + if (asyncEventBusServerDelegate.TryGetValue(eventName, out var eventHandlersForEvent)) { eventHandlersForEvent.Add(eventDelegate); } else { eventHandlersForEvent = new HashSet {eventDelegate}; - serverEventAsyncDelegateHandlers[eventName] = eventHandlersForEvent; + asyncEventBusServerDelegate[eventName] = eventHandlersForEvent; } } - public new void On(string eventName, Function function) + [Obsolete] + public void OffServer(string eventName, ServerEventAsyncDelegate serverEventDelegate) { - if (function == null) return; - if (AsyncEventHandlers.TryGetValue(eventName, out var eventHandlersForEvent)) + if (serverEventDelegate == null) return; + if (asyncEventBusServerDelegate.TryGetValue(eventName, out var eventHandlers)) { - eventHandlersForEvent.Add(function); - } - else - { - eventHandlersForEvent = new HashSet {function}; - AsyncEventHandlers[eventName] = eventHandlersForEvent; + eventHandlers.Remove(serverEventDelegate); } } diff --git a/api/AltV.Net.Async/AsyncScriptEvent.cs b/api/AltV.Net.Async/AsyncScriptEventAttribute.cs similarity index 61% rename from api/AltV.Net.Async/AsyncScriptEvent.cs rename to api/AltV.Net.Async/AsyncScriptEventAttribute.cs index 0868bb5bf..07e92a375 100644 --- a/api/AltV.Net.Async/AsyncScriptEvent.cs +++ b/api/AltV.Net.Async/AsyncScriptEventAttribute.cs @@ -1,15 +1,15 @@ -using System; - -namespace AltV.Net.Async -{ - [AttributeUsage(AttributeTargets.Method)] - public class AsyncScriptEvent : Attribute - { - public ScriptEventType EventType { get; } - - public AsyncScriptEvent(ScriptEventType eventType) - { - EventType = eventType; - } - } +using System; + +namespace AltV.Net.Async +{ + [AttributeUsage(AttributeTargets.Method)] + public sealed class AsyncScriptEventAttribute : Attribute + { + public ScriptEventType EventType { get; } + + public AsyncScriptEventAttribute(ScriptEventType eventType) + { + EventType = eventType; + } + } } \ No newline at end of file diff --git a/api/AltV.Net.Async/AsyncServerEventAttribute.cs b/api/AltV.Net.Async/AsyncServerEventAttribute.cs new file mode 100644 index 000000000..bb2cf24b0 --- /dev/null +++ b/api/AltV.Net.Async/AsyncServerEventAttribute.cs @@ -0,0 +1,15 @@ +using System; + +namespace AltV.Net.Async +{ + [AttributeUsage(AttributeTargets.Method)] + public sealed class AsyncServerEventAttribute : Attribute + { + public string Name { get; } + + public AsyncServerEventAttribute(string name = null) + { + Name = name; + } + } +} \ No newline at end of file diff --git a/api/AltV.Net.Example/SampleResource.cs b/api/AltV.Net.Example/SampleResource.cs index 45d2a2216..d39317e6f 100644 --- a/api/AltV.Net.Example/SampleResource.cs +++ b/api/AltV.Net.Example/SampleResource.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using AltV.Net.Async; @@ -49,7 +48,7 @@ public override void OnStart() } }; - Alt.On("array_test", objects => + Alt.OnServer("array_test", objects => { Console.WriteLine("count:" + objects.Length); Console.WriteLine("1:" + objects[0]); @@ -59,10 +58,10 @@ public override void OnStart() Console.WriteLine("2:" + ((object[])objects[2])[0]); }); Alt.Emit("array_test", new object[] {new object[] {"test", "test4", new[] {1337}}}); - Alt.On("array_test2", objects => + Alt.OnServer("array_test2", objects => { Console.WriteLine("count2:" + objects.Length); - Console.WriteLine("count3:" + ((object[])(((object[])objects)[0]))[0]); + Console.WriteLine("count3:" + ((object[])objects[0])[0]); }); Alt.Emit("array_test2", new object[] {new object[] {new object[]{1337}}}); @@ -75,12 +74,12 @@ public override void OnStart() var mValuesListGet = mValueList.GetList(); for (var i = 0; i < mValuesListGet.Length; i++) { - Console.WriteLine("val: " + mValuesListGet[i].ToString()); + Console.WriteLine("val: " + mValuesListGet[i]); mValuesListGet[i].Dispose(); } MValueAdapters.Register(new ConvertibleObject.ConvertibleObjectAdapter()); - Alt.On("convertible_test", delegate(ConvertibleObject convertible) + Alt.OnServer("convertible_test", delegate(ConvertibleObject convertible) { Console.WriteLine("convertible_test received"); Console.WriteLine(convertible.Test); @@ -103,14 +102,14 @@ public override void OnStart() //mValueFromConvertible.Dispose(); Alt.Emit("convertible_test", convertibleObject); - Alt.On("test", s => { Alt.Log("test=" + s); }); - Alt.OnServer("test", args => { Alt.Log("args=" + args[0]); }); + Alt.OnServer("test", s => { Alt.Log("test=" + s); }); + Alt.OnServer("test", args => { Alt.Log("args=" + args[0]); }); Alt.Emit("test", "bla"); - Alt.On("bla", bla); - Alt.On("bla2", bla2); - Alt.On("bla3", bla3); - Alt.On("bla4", bla4); - Alt.On("vehicleTest", myVehicle => + Alt.OnServer("bla", bla); + Alt.OnServer("bla2", bla2); + Alt.OnServer("bla3", bla3); + Alt.OnServer("bla4", bla4); + Alt.OnServer("vehicleTest", myVehicle => { Console.WriteLine("inside invoke"); Alt.Log("myData: " + myVehicle?.MyData); @@ -132,7 +131,7 @@ public override void OnStart() AltAsync.Log("event:" + name); return Task.CompletedTask; }; - AltAsync.OnServer("bla", + AltAsync.OnServer("bla", async args => { await AltAsync.Do(() => Alt.Log("bla with no args:" + args.Length)); }); Alt.Emit("bla"); @@ -143,7 +142,7 @@ public override void OnStart() Alt.Log(checkpoint.Color.ToString()); var voiceChannel = Alt.CreateVoiceChannel(true, 10f); - Alt.Log(voiceChannel.MaxDistance.ToString()); + Alt.Log(voiceChannel.MaxDistance.ToString("R")); var vehicle = Alt.CreateVehicle(VehicleModel.Apc, new Position(1, 2, 3), new Rotation(1, 2, 3)); vehicle.SetSyncedMetaData("test", 123); @@ -186,7 +185,7 @@ public override void OnStart() Alt.Emit("vehicleTest", vehicle); - Alt.On("event_name", + Alt.OnServer("event_name", delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVehicle arg5, Dictionary arg6, IMyVehicle[] myVehicles, string probablyNull, string[] nullArray, Dictionary bla) @@ -202,7 +201,7 @@ public override void OnStart() Alt.Log("bla2:" + bla["test"]); }); - Alt.On("entity-array-obj", + Alt.OnServer("entity-array-obj", delegate(object[] myVehicles) { Alt.Log("entity-array-obj: " + ((MyVehicle) myVehicles[0]).Position.X + " " + @@ -215,8 +214,7 @@ async delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVe Dictionary bla) { await Task.Delay(500); - var asyncVehicle = - await AltAsync.CreateVehicle(VehicleModel.Apc, Position.Zero, new Rotation(1, 2, 3)); + await AltAsync.CreateVehicle(VehicleModel.Apc, Position.Zero, new Rotation(1, 2, 3)); AltAsync.Log("async-param1:" + s); AltAsync.Log("async-param2:" + s1); @@ -238,15 +236,15 @@ async delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVe //["test2"] = new Dictionary {["test"] = 1}, //["test3"] = new Dictionary {["test"] = 42} }, - new IMyVehicle[] {(IMyVehicle) vehicle}, null, new string[] {null}, + new[] {(IMyVehicle) vehicle}, null, new string[] {null}, new Dictionary { ["test"] = null }); - Alt.On("test_string_array", s => { Alt.Log("string-array-entry-0:" + s[0]); }); + Alt.OnServer("test_string_array", s => { Alt.Log("string-array-entry-0:" + s[0]); }); - Alt.Emit("test_string_array", new object[] {new string[] {"bla"}}); + Alt.Emit("test_string_array", new object[] {new[] {"bla"}}); /*Alt.On("function_event", delegate(Function.Func func) { @@ -260,8 +258,9 @@ async delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVe return 42; }));*/ - foreach (var player in Alt.GetAllPlayers()) + foreach (var pl in Alt.GetAllPlayers()) { + Alt.Log("player:" + pl.Position.X + " " + pl.Position.Y + " " + pl.Position.Z); } foreach (var veh in Alt.GetAllVehicles()) @@ -269,7 +268,7 @@ async delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVe Alt.Log("vehicle:" + veh.Position.X + " " + veh.Position.Y + " " + veh.Position.Z); } - Alt.On("1337", delegate(int int1) { Alt.Log("int1:" + int1); }); + Alt.OnServer("1337", delegate(int int1) { Alt.Log("int1:" + int1); }); AltAsync.On("1337", delegate(int int1) { Alt.Log("int1:" + int1); }); @@ -281,7 +280,7 @@ async delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVe Alt.Emit("MyServerEvent3", vehicle); - Alt.Emit("entity-array-obj", new[] {new[] {vehicle}}); + Alt.Emit("entity-array-obj", new object[] {new[] {vehicle}}); vehicle.Remove(); @@ -295,7 +294,7 @@ async delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVe Alt.Emit("MyServerEvent", "test-custom-parser"); - Alt.Emit("MyServerEvent2", new object[] {new string[] {"test-custom-parser-array"}}); + Alt.Emit("MyServerEvent2", new object[] {new[] {"test-custom-parser-array"}}); //dynamic dynamic = new ExpandoObject(); @@ -303,17 +302,13 @@ async delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVe Alt.Export("GetBla", () => { Alt.Log("GetBla called"); }); - Action action; - - Alt.Import("example", "GetBla", out action); + Alt.Import(Alt.Server.Resource.Name, "GetBla", out Action action); action(); Alt.Export("functionExport", delegate(string name) { Alt.Log("called with:" + name); }); - Action action2; - - Alt.Import("example", "functionExport", out action2); + Alt.Import(Alt.Server.Resource.Name, "functionExport", out Action action2); action2("123"); /*if (Alt.Import("Bla", "GetBla", out Action value)) @@ -326,14 +321,14 @@ async delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVe Alt.Emit("none-existing-event", new ConvertibleObject()); // You need to catch this with a exception because its not possible to construct a invalid entity - // Remember not all vehicles you receive from events has to be constructored by this constructor when there got created from different resources ect. + // Remember not all vehicles you receive from events has to be constructed by this constructor when there got created from different resources ect. // But when you don't use a entity factory you can validate that by checking if the ivehicle is a imyvehicle try { - IMyVehicle myConstructedVehicle = + IMyVehicle unused = new MyVehicle((uint) VehicleModel.Apc, new Position(1, 1, 1), new Rotation(1, 1, 1)); } - catch (BaseObjectRemovedException baseObjectRemovedException) + catch (BaseObjectRemovedException) { } @@ -353,19 +348,19 @@ async delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVe var colShapeCylinder = Alt.CreateColShapeCylinder(new Position(1337, 1337, 1337), 10, 10); colShapeCylinder.SetMetaData("bla", 1); - colShapeCylinder.SetData("bla", (int) 2); + colShapeCylinder.SetData("bla", 2); var colShapeCircle = Alt.CreateColShapeCircle(new Position(1337, 1337, 1337), 10); colShapeCircle.SetMetaData("bla", 3); - colShapeCircle.SetData("bla", (int) 4); + colShapeCircle.SetData("bla", 4); AltChat.SendBroadcast("Test"); var vehicle2 = Alt.CreateVehicle(VehicleModel.Adder, new Position(1337, 1337, 1337), Rotation.Zero); - Alt.On("onEnum", OnEnum); + Alt.OnServer("onEnum", OnEnum); Alt.Emit("onEnum", vehicle2, VehicleModel.Adder.ToString()); - Alt.On("EmptyParams", TestEmptyParams); + Alt.OnServer("EmptyParams", TestEmptyParams); Alt.Emit("EmptyParams", 1, 2, 3); Alt.Emit("chat:message", "/dynamicArgs2 7"); @@ -380,33 +375,33 @@ async delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVe Alt.Emit("chat:message", "/invalidCommand"); Alt.Emit("chat:message", "/invalidCommand 3535"); - Alt.On("onOptionalAndParamArray", OnOptionalAndParamArray); + Alt.OnServer("onOptionalAndParamArray", OnOptionalAndParamArray); Alt.Emit("onOptionalAndParamArray", 5, 42, "test"); } - public void OnOptionalAndParamArray(int test, params object[] args) { - System.Console.WriteLine($"Event({test}, [{string.Join(',', System.Array.ConvertAll(args ?? new object[] {""}, el => el.ToString()))}])"); + public static void OnOptionalAndParamArray(int test, params object[] args) { + Console.WriteLine($"Event({test}, [{string.Join(',', Array.ConvertAll(args ?? new object[] {""}, el => el.ToString()))}])"); } - public void TestEmptyParams() + public static void TestEmptyParams() { Alt.Log("Empty params"); } - public void OnEnum(IVehicle vehicle, VehicleModel vehicleModel) + public static void OnEnum(IVehicle vehicle, VehicleModel vehicleModel) { Console.WriteLine("vehicle:" + vehicle.Id); Console.WriteLine("vehicle-model:" + vehicleModel); } - [Event("bla2")] + [ServerEvent("bla2")] public void MyServerEventHandler2(string myString) { Alt.Log(myString); } - [AsyncEvent] + [AsyncServerEvent] public void asyncBla3(string myString) { AltAsync.Log(myString); @@ -554,9 +549,9 @@ public async void Bla2(IPlayer player) } await player.SetPositionAsync(new Position(1, 2, 3)); - var position = await player.GetPositionAsync(); + var unused = await player.GetPositionAsync(); await AltAsync.Do(() => { }); - var vehicle = await AltAsync.Do(() => + var unused2 = await AltAsync.Do(() => Alt.CreateVehicle(VehicleModel.Apc, new Position(1, 2, 3), new Rotation(1, 2, 3))); } @@ -596,7 +591,7 @@ private void OnPlayerDisconnect(IPlayer player, string reason) private async Task OnPlayerDisconnectAsync(IPlayer player, string reason) { - if (player is IMyPlayer myPlayer) + if (player is IMyPlayer unused3) { } diff --git a/api/AltV.Net.Example/SampleScript.cs b/api/AltV.Net.Example/SampleScript.cs index 5b3da2a47..a30820d51 100644 --- a/api/AltV.Net.Example/SampleScript.cs +++ b/api/AltV.Net.Example/SampleScript.cs @@ -44,12 +44,12 @@ public void MyCommandWithDynamicArgs2(IPlayer player, int arg1, int? arg2, param Console.WriteLine("Command:" + arg1 + " " + arg2 + " remaining args " + string.Join(",", args)); } - [Event("eventName")] + [ServerEvent("eventName")] public void MyEvent(IPlayer player) { } - [Event] + [ServerEvent] public void MyEventName(string message) { Console.WriteLine(message); diff --git a/api/AltV.Net/Alt.CustomEventParser.cs b/api/AltV.Net/Alt.CustomEventParser.cs new file mode 100644 index 000000000..2e498ecf6 --- /dev/null +++ b/api/AltV.Net/Alt.CustomEventParser.cs @@ -0,0 +1,739 @@ +using System; +using AltV.Net.FunctionParser; + +namespace AltV.Net +{ + public partial class Alt + { + public static void OnClient(string eventName, Action action, ClientEventParser parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, Action action, ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, Action action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, Action action, + ClientEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnClient(string eventName, Action action, + ClientEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnClient(string eventName, Action action, + ClientEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnClient(string eventName, Action action, + ClientEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Action action, + ClientEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Action action, + ClientEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Action action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Action action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Action action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Action action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Action action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Action action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Action action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient( + string eventName, + Action action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, Func action, ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, Func action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, Func action, + ClientEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnClient(string eventName, Func action, + ClientEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnClient(string eventName, Func action, + ClientEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnClient(string eventName, Func action, + ClientEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Func action, + ClientEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Func action, + ClientEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Func action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Func action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Func action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Func action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Func action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Func action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient(string eventName, + Func action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient( + string eventName, + Func action, + ClientEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnClient( + string eventName, + Func action, + ClientEventParser> + parser) => + Module.On(eventName, action, parser); + + public static void OffClient(string eventName, Action action, ClientEventParser parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, Action action, ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, Action action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, Action action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, Action action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, Action action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Action action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Action action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient( + string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, Func action, ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, Func action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, Func action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, Func action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, Func action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Func action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Func action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient(string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient( + string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffClient( + string eventName, + Func action, + ClientEventParser> + parser) => + Module.Off(eventName, action, parser); + + + public static void OnServer(string eventName, Action action, ServerEventParser parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, Action action, ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, Action action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, Action action, + ServerEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnServer(string eventName, Action action, + ServerEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnServer(string eventName, Action action, + ServerEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnServer(string eventName, Action action, + ServerEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Action action, + ServerEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Action action, + ServerEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Action action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Action action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Action action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Action action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Action action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Action action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Action action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer( + string eventName, + Action action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, Func action, ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, Func action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, Func action, + ServerEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnServer(string eventName, Func action, + ServerEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnServer(string eventName, Func action, + ServerEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnServer(string eventName, Func action, + ServerEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Func action, + ServerEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Func action, + ServerEventParser> parser) => Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Func action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Func action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Func action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Func action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Func action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Func action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer(string eventName, + Func action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer( + string eventName, + Func action, + ServerEventParser> parser) => + Module.On(eventName, action, parser); + + public static void OnServer( + string eventName, + Func action, + ServerEventParser> + parser) => + Module.On(eventName, action, parser); + + public static void OffServer(string eventName, Action action, ClientEventParser parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Action action, ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Action action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Action action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Action action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Action action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer( + string eventName, + Action action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Func action, ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Func action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Func action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Func action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Func action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ClientEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer( + string eventName, + Func action, + ClientEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer( + string eventName, + Func action, + ClientEventParser> + parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Action action, ServerEventParser parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Action action, ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Action action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Action action, + ServerEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Action action, + ServerEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Action action, + ServerEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Action action, + ServerEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ServerEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ServerEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Action action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer( + string eventName, + Action action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Func action, ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Func action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Func action, + ServerEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Func action, + ServerEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Func action, + ServerEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, Func action, + ServerEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ServerEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ServerEventParser> parser) => Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer(string eventName, + Func action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer( + string eventName, + Func action, + ServerEventParser> parser) => + Module.Off(eventName, action, parser); + + public static void OffServer( + string eventName, + Func action, + ServerEventParser> + parser) => + Module.Off(eventName, action, parser); + } +} \ No newline at end of file diff --git a/api/AltV.Net/Alt.CustomParser.cs b/api/AltV.Net/Alt.CustomParser.cs deleted file mode 100644 index 65940fa43..000000000 --- a/api/AltV.Net/Alt.CustomParser.cs +++ /dev/null @@ -1,151 +0,0 @@ -using System; -using AltV.Net.FunctionParser; - -namespace AltV.Net -{ - public partial class Alt - { - public static void OnClient(string eventName, Action action, ClientEventParser parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, Action action, ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void - OnClient(string eventName, Action action, ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, Action action, - ClientEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnClient(string eventName, Action action, - ClientEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnClient(string eventName, Action action, - ClientEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnClient(string eventName, Action action, - ClientEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnClient(string eventName, Action action, - ClientEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Action action, - ClientEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Action action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Action action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Action action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Action action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Action action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Action action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Action action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Action action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - - public static void OnClient(string eventName, Func action, ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void - OnClient(string eventName, Func action, ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, Func action, - ClientEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnClient(string eventName, Func action, - ClientEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnClient(string eventName, Func action, - ClientEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnClient(string eventName, Func action, - ClientEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnClient(string eventName, Func action, - ClientEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Func action, - ClientEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Func action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Func action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Func action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Func action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Func action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Func action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Func action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient(string eventName, - Func action, - ClientEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnClient( - string eventName, - Func action, - ClientEventParser> - parser) => - Module.On(eventName, action, parser); - } -} \ No newline at end of file diff --git a/api/AltV.Net/Alt.Off.cs b/api/AltV.Net/Alt.Off.cs index c2780f506..a9e4523b6 100644 --- a/api/AltV.Net/Alt.Off.cs +++ b/api/AltV.Net/Alt.Off.cs @@ -1,497 +1,493 @@ -using System; -using AltV.Net.Events; -using AltV.Net.FunctionParser; - -namespace AltV.Net -{ - public partial class Alt - { - public static void Off(string eventName, Function function) => Module.Off(eventName, function); - - public static void OffClient(string eventName, ClientEventDelegate clientEventDelegate) - { - Module.OffClient(eventName, clientEventDelegate); - } - - public static void OffServer(string eventName, ServerEventDelegate serverEventDelegate) - { - Module.OffServer(eventName, serverEventDelegate); - } - - public static void Off(string eventName, Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Action function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, - Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off( - string eventName, - Func function) - { - Module.Off(eventName, Function.Create(function)); - } - - public static void Off(string eventName, Action action, ClientEventParser parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, Action action, ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void - Off(string eventName, Action action, ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, Action action, - ClientEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Action action, - ClientEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Action action, - ClientEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Action action, - ClientEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Action action, - ClientEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ClientEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - - public static void Off(string eventName, Func action, ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void - Off(string eventName, Func action, ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, Func action, - ClientEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Func action, - ClientEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Func action, - ClientEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Func action, - ClientEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Func action, - ClientEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ClientEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ClientEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off( - string eventName, - Func action, - ClientEventParser> - parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, Action action, ServerEventParser parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, Action action, ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void - Off(string eventName, Action action, ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, Action action, - ServerEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Action action, - ServerEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Action action, - ServerEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Action action, - ServerEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Action action, - ServerEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ServerEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Action action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - - public static void Off(string eventName, Func action, ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void - Off(string eventName, Func action, ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, Func action, - ServerEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Func action, - ServerEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Func action, - ServerEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Func action, - ServerEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, Func action, - ServerEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ServerEventParser> parser) => Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off(string eventName, - Func action, - ServerEventParser> parser) => - Module.Off(eventName, action, parser); - - public static void Off( - string eventName, - Func action, - ServerEventParser> - parser) => - Module.Off(eventName, action, parser); - } +using System; +using AltV.Net.Events; + +namespace AltV.Net +{ + public partial class Alt + { + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, Function function) => Module.Off(eventName, function); + + [Obsolete("This method is obsolete. Use Alt.OffClient instead.")] + public static void OffClient(string eventName, ClientEventDelegate clientEventDelegate) + { + Module.OffClient(eventName, clientEventDelegate); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer instead.")] + public static void OffServer(string eventName, ServerEventDelegate serverEventDelegate) + { + Module.OffServer(eventName, serverEventDelegate); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Action function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off(string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + [Obsolete("This method is obsolete. Use Alt.OffServer or Alt.OffClient instead.")] + public static void Off( + string eventName, + Func function) + { + Module.Off(eventName, Function.Create(function)); + } + + public static void OffServer(string eventName, Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer( + string eventName, + Action action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer(string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer( + string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + public static void OffServer( + string eventName, + Func action) => + Module.OffServer(eventName, Function.Create(action)); + + + public static void OffClient(string eventName, Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient( + string eventName, + Action action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient(string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient( + string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + + public static void OffClient( + string eventName, + Func action) => + Module.OffClient(eventName, Function.Create(action)); + } } \ No newline at end of file diff --git a/api/AltV.Net/Alt.On.cs b/api/AltV.Net/Alt.On.cs index a159c8808..a615f3e24 100644 --- a/api/AltV.Net/Alt.On.cs +++ b/api/AltV.Net/Alt.On.cs @@ -5,206 +5,488 @@ namespace AltV.Net { public static partial class Alt { + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Function function) => Module.On(eventName, function); + [Obsolete("This method is obsolete. Use Alt.OnClient instead.")] public static void OnClient(string eventName, ClientEventDelegate clientEventDelegate) { Module.OnClient(eventName, clientEventDelegate); } + [Obsolete("This method is obsolete. Use Alt.OnServer instead.")] public static void OnServer(string eventName, ServerEventDelegate serverEventDelegate) { Module.OnServer(eventName, serverEventDelegate); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Action function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On(string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + [Obsolete("This method is obsolete. Use Alt.OnServer or Alt.OnClient instead.")] public static void On( string eventName, Func function) { Module.On(eventName, Function.Create(function)); } + + public static void OnServer(string eventName, Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer( + string eventName, + Action action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer(string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer( + string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + public static void OnServer( + string eventName, + Func action) => + Module.OnServer(eventName, Function.Create(action)); + + + public static void OnClient(string eventName, Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient( + string eventName, + Action action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient(string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient( + string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); + + public static void OnClient( + string eventName, + Func action) => + Module.OnClient(eventName, Function.Create(action)); } } \ No newline at end of file diff --git a/api/AltV.Net/Alt.RegisterEvents.cs b/api/AltV.Net/Alt.RegisterEvents.cs index 79c18f933..2a321d7f6 100644 --- a/api/AltV.Net/Alt.RegisterEvents.cs +++ b/api/AltV.Net/Alt.RegisterEvents.cs @@ -1,247 +1,261 @@ -using AltV.Net.Elements.Args; -using AltV.Net.Elements.Entities; -using AltV.Net.FunctionParser; -using AltV.Net.Native; - -namespace AltV.Net -{ - public partial class Alt - { - public static void RegisterEvents(object target) - { - ModuleScriptMethodIndexer.Index(target, new[] {typeof(Event), typeof(ScriptEvent)}, - (baseEvent, eventMethod, eventMethodDelegate) => - { - switch (baseEvent) - { - case ScriptEvent scriptEvent: - var scriptEventType = scriptEvent.EventType; - ScriptFunction scriptFunction; - switch (scriptEventType) - { - case ScriptEventType.Checkpoint: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(ICheckpoint), typeof(IEntity), typeof(bool)}); - if (scriptFunction == null) return; - OnCheckpoint += (checkpoint, entity, state) => - { - scriptFunction.Set(checkpoint); - scriptFunction.Set(entity); - scriptFunction.Set(state); - scriptFunction.Call(); - }; - break; - case ScriptEventType.PlayerConnect: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IPlayer), typeof(string)}); - if (scriptFunction == null) return; - OnPlayerConnect += (player, reason) => - { - scriptFunction.Set(player); - scriptFunction.Set(reason); - scriptFunction.Call(); - }; - break; - case ScriptEventType.PlayerDamage: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IPlayer), typeof(IEntity), typeof(uint), typeof(ushort)}); - if (scriptFunction == null) return; - OnPlayerDamage += (player, attacker, weapon, damage) => - { - scriptFunction.Set(player); - scriptFunction.Set(attacker); - scriptFunction.Set(weapon); - scriptFunction.Set(damage); - scriptFunction.Call(); - }; - break; - case ScriptEventType.PlayerDead: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IPlayer), typeof(IEntity), typeof(uint)}); - if (scriptFunction == null) return; - OnPlayerDead += (player, attacker, weapon) => - { - scriptFunction.Set(player); - scriptFunction.Set(attacker); - scriptFunction.Set(weapon); - scriptFunction.Call(); - }; - break; - case ScriptEventType.PlayerDisconnect: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IPlayer), typeof(string)}); - if (scriptFunction == null) return; - OnPlayerDisconnect += (player, reason) => - { - scriptFunction.Set(player); - scriptFunction.Set(reason); - scriptFunction.Call(); - }; - break; - case ScriptEventType.PlayerRemove: - scriptFunction = - ScriptFunction.Create(eventMethodDelegate, new[] {typeof(IPlayer)}); - if (scriptFunction == null) return; - OnPlayerRemove += player => - { - scriptFunction.Set(player); - scriptFunction.Call(); - }; - break; - case ScriptEventType.VehicleRemove: - scriptFunction = - ScriptFunction.Create(eventMethodDelegate, new[] {typeof(IVehicle)}); - if (scriptFunction == null) return; - OnVehicleRemove += vehicle => - { - scriptFunction.Set(vehicle); - scriptFunction.Call(); - }; - break; - case ScriptEventType.PlayerChangeVehicleSeat: - scriptFunction = - ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IVehicle), typeof(IPlayer), typeof(byte), typeof(byte)}); - if (scriptFunction == null) return; - OnPlayerChangeVehicleSeat += (vehicle, player, seat, newSeat) => - { - scriptFunction.Set(vehicle); - scriptFunction.Set(player); - scriptFunction.Set(seat); - scriptFunction.Set(newSeat); - scriptFunction.Call(); - }; - break; - case ScriptEventType.PlayerEnterVehicle: - scriptFunction = - ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IVehicle), typeof(IPlayer), typeof(byte)}); - if (scriptFunction == null) return; - OnPlayerEnterVehicle += (vehicle, player, seat) => - { - scriptFunction.Set(vehicle); - scriptFunction.Set(player); - scriptFunction.Set(seat); - scriptFunction.Call(); - }; - break; - case ScriptEventType.PlayerLeaveVehicle: - scriptFunction = - ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IVehicle), typeof(IPlayer), typeof(byte)}); - if (scriptFunction == null) return; - OnPlayerLeaveVehicle += (vehicle, player, seat) => - { - scriptFunction.Set(vehicle); - scriptFunction.Set(player); - scriptFunction.Set(seat); - scriptFunction.Call(); - }; - break; - case ScriptEventType.PlayerEvent: - scriptFunction = - ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IPlayer), typeof(string), typeof(object[])}); - if (scriptFunction == null) return; - OnPlayerEvent += (player, name, args) => - { - scriptFunction.Set(player); - scriptFunction.Set(name); - scriptFunction.Set(args); - scriptFunction.Call(); - }; - break; - case ScriptEventType.PlayerCustomEvent: - scriptFunction = - ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IPlayer), typeof(string), typeof(MValueConst[])}); - if (scriptFunction == null) return; - OnPlayerCustomEvent += (IPlayer player, string name, MValueConst[] array) => - { - scriptFunction.Set(player); - scriptFunction.Set(name); - scriptFunction.Set(array); - scriptFunction.Call(); - }; - break; - case ScriptEventType.ServerEvent: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(string), typeof(object[])}); - if (scriptFunction == null) return; - OnServerEvent += (serverEventName, serverEventArgs) => - { - scriptFunction.Set(serverEventName); - scriptFunction.Set(serverEventArgs); - scriptFunction.Call(); - }; - break; - case ScriptEventType.ServerCustomEvent: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(string), typeof(MValueConst[])}); - if (scriptFunction == null) return; - OnServerCustomEvent += (string name, MValueConst[] array) => - { - scriptFunction.Set(name); - scriptFunction.Set(array); - scriptFunction.Call(); - }; - break; - case ScriptEventType.ConsoleCommand: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(string), typeof(string[])}); - if (scriptFunction == null) return; - OnConsoleCommand += (name, args) => - { - scriptFunction.Set(name); - scriptFunction.Set(args); - scriptFunction.Call(); - }; - break; - case ScriptEventType.MetaDataChange: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IEntity), typeof(string), typeof(object)}); - if (scriptFunction == null) return; - OnMetaDataChange += (entity, key, value) => - { - scriptFunction.Set(entity); - scriptFunction.Set(key); - scriptFunction.Set(value); - scriptFunction.Call(); - }; - break; - case ScriptEventType.SyncedMetaDataChange: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IEntity), typeof(string), typeof(object)}); - if (scriptFunction == null) return; - OnSyncedMetaDataChange += (entity, key, value) => - { - scriptFunction.Set(entity); - scriptFunction.Set(key); - scriptFunction.Set(value); - scriptFunction.Call(); - }; - break; - case ScriptEventType.ColShape: - scriptFunction = ScriptFunction.Create(eventMethodDelegate, - new[] {typeof(IColShape), typeof(IEntity), typeof(bool)}); - if (scriptFunction == null) return; - OnColShape += (shape, entity, state) => - { - scriptFunction.Set(shape); - scriptFunction.Set(entity); - scriptFunction.Set(state); - scriptFunction.Call(); - }; - break; - } - - break; - case Event @event: - var eventName = @event.Name ?? eventMethod.Name; - Module.On(eventName, Function.Create(eventMethodDelegate)); - break; - } - }); - } - } +using System; +using AltV.Net.Elements.Args; +using AltV.Net.Elements.Entities; +using AltV.Net.FunctionParser; + +namespace AltV.Net +{ + public partial class Alt + { + public static void RegisterEvents(object target) + { +#pragma warning disable 612, 618 + ModuleScriptMethodIndexer.Index(target, new[] {typeof(EventAttribute), typeof(ServerEventAttribute), typeof(ClientEventAttribute), typeof(ScriptEventAttribute)}, +#pragma warning restore 612, 618 + (baseEvent, eventMethod, eventMethodDelegate) => + { + switch (baseEvent) + { + case ScriptEventAttribute scriptEvent: + var scriptEventType = scriptEvent.EventType; + ScriptFunction scriptFunction; + switch (scriptEventType) + { + case ScriptEventType.Checkpoint: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(ICheckpoint), typeof(IEntity), typeof(bool)}); + if (scriptFunction == null) return; + OnCheckpoint += (checkpoint, entity, state) => + { + scriptFunction.Set(checkpoint); + scriptFunction.Set(entity); + scriptFunction.Set(state); + scriptFunction.Call(); + }; + break; + case ScriptEventType.PlayerConnect: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IPlayer), typeof(string)}); + if (scriptFunction == null) return; + OnPlayerConnect += (player, reason) => + { + scriptFunction.Set(player); + scriptFunction.Set(reason); + scriptFunction.Call(); + }; + break; + case ScriptEventType.PlayerDamage: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IPlayer), typeof(IEntity), typeof(uint), typeof(ushort)}); + if (scriptFunction == null) return; + OnPlayerDamage += (player, attacker, weapon, damage) => + { + scriptFunction.Set(player); + scriptFunction.Set(attacker); + scriptFunction.Set(weapon); + scriptFunction.Set(damage); + scriptFunction.Call(); + }; + break; + case ScriptEventType.PlayerDead: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IPlayer), typeof(IEntity), typeof(uint)}); + if (scriptFunction == null) return; + OnPlayerDead += (player, attacker, weapon) => + { + scriptFunction.Set(player); + scriptFunction.Set(attacker); + scriptFunction.Set(weapon); + scriptFunction.Call(); + }; + break; + case ScriptEventType.PlayerDisconnect: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IPlayer), typeof(string)}); + if (scriptFunction == null) return; + OnPlayerDisconnect += (player, reason) => + { + scriptFunction.Set(player); + scriptFunction.Set(reason); + scriptFunction.Call(); + }; + break; + case ScriptEventType.PlayerRemove: + scriptFunction = + ScriptFunction.Create(eventMethodDelegate, new[] {typeof(IPlayer)}); + if (scriptFunction == null) return; + OnPlayerRemove += player => + { + scriptFunction.Set(player); + scriptFunction.Call(); + }; + break; + case ScriptEventType.VehicleRemove: + scriptFunction = + ScriptFunction.Create(eventMethodDelegate, new[] {typeof(IVehicle)}); + if (scriptFunction == null) return; + OnVehicleRemove += vehicle => + { + scriptFunction.Set(vehicle); + scriptFunction.Call(); + }; + break; + case ScriptEventType.PlayerChangeVehicleSeat: + scriptFunction = + ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IVehicle), typeof(IPlayer), typeof(byte), typeof(byte)}); + if (scriptFunction == null) return; + OnPlayerChangeVehicleSeat += (vehicle, player, seat, newSeat) => + { + scriptFunction.Set(vehicle); + scriptFunction.Set(player); + scriptFunction.Set(seat); + scriptFunction.Set(newSeat); + scriptFunction.Call(); + }; + break; + case ScriptEventType.PlayerEnterVehicle: + scriptFunction = + ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IVehicle), typeof(IPlayer), typeof(byte)}); + if (scriptFunction == null) return; + OnPlayerEnterVehicle += (vehicle, player, seat) => + { + scriptFunction.Set(vehicle); + scriptFunction.Set(player); + scriptFunction.Set(seat); + scriptFunction.Call(); + }; + break; + case ScriptEventType.PlayerLeaveVehicle: + scriptFunction = + ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IVehicle), typeof(IPlayer), typeof(byte)}); + if (scriptFunction == null) return; + OnPlayerLeaveVehicle += (vehicle, player, seat) => + { + scriptFunction.Set(vehicle); + scriptFunction.Set(player); + scriptFunction.Set(seat); + scriptFunction.Call(); + }; + break; + case ScriptEventType.PlayerEvent: + scriptFunction = + ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IPlayer), typeof(string), typeof(object[])}); + if (scriptFunction == null) return; + OnPlayerEvent += (player, name, args) => + { + scriptFunction.Set(player); + scriptFunction.Set(name); + scriptFunction.Set(args); + scriptFunction.Call(); + }; + break; + case ScriptEventType.PlayerCustomEvent: + scriptFunction = + ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IPlayer), typeof(string), typeof(MValueConst[])}); + if (scriptFunction == null) return; + OnPlayerCustomEvent += (player, name, array) => + { + scriptFunction.Set(player); + scriptFunction.Set(name); + scriptFunction.Set(array); + scriptFunction.Call(); + }; + break; + case ScriptEventType.ServerEvent: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(string), typeof(object[])}); + if (scriptFunction == null) return; + OnServerEvent += (scriptEventName, scriptEventArgs) => + { + scriptFunction.Set(scriptEventName); + scriptFunction.Set(scriptEventArgs); + scriptFunction.Call(); + }; + break; + case ScriptEventType.ServerCustomEvent: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(string), typeof(MValueConst[])}); + if (scriptFunction == null) return; + OnServerCustomEvent += (name, array) => + { + scriptFunction.Set(name); + scriptFunction.Set(array); + scriptFunction.Call(); + }; + break; + case ScriptEventType.ConsoleCommand: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(string), typeof(string[])}); + if (scriptFunction == null) return; + OnConsoleCommand += (name, args) => + { + scriptFunction.Set(name); + scriptFunction.Set(args); + scriptFunction.Call(); + }; + break; + case ScriptEventType.MetaDataChange: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IEntity), typeof(string), typeof(object)}); + if (scriptFunction == null) return; + OnMetaDataChange += (entity, key, value) => + { + scriptFunction.Set(entity); + scriptFunction.Set(key); + scriptFunction.Set(value); + scriptFunction.Call(); + }; + break; + case ScriptEventType.SyncedMetaDataChange: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IEntity), typeof(string), typeof(object)}); + if (scriptFunction == null) return; + OnSyncedMetaDataChange += (entity, key, value) => + { + scriptFunction.Set(entity); + scriptFunction.Set(key); + scriptFunction.Set(value); + scriptFunction.Call(); + }; + break; + case ScriptEventType.ColShape: + scriptFunction = ScriptFunction.Create(eventMethodDelegate, + new[] {typeof(IColShape), typeof(IEntity), typeof(bool)}); + if (scriptFunction == null) return; + OnColShape += (shape, entity, state) => + { + scriptFunction.Set(shape); + scriptFunction.Set(entity); + scriptFunction.Set(state); + scriptFunction.Call(); + }; + break; + default: + throw new ArgumentOutOfRangeException(); + } + + break; +#pragma warning disable 612, 618 + case EventAttribute @event: + var eventName = @event.Name ?? eventMethod.Name; + Module.On(eventName, Function.Create(eventMethodDelegate)); + break; +#pragma warning restore 612, 618 + case ServerEventAttribute @event: + var serverEventName = @event.Name ?? eventMethod.Name; + Module.OnServer(serverEventName, Function.Create(eventMethodDelegate)); + break; + case ClientEventAttribute @event: + var clientEventName = @event.Name ?? eventMethod.Name; + Module.OnClient(clientEventName, Function.Create(eventMethodDelegate)); + break; + } + }); + } + } } \ No newline at end of file diff --git a/api/AltV.Net/Alt.ServerCustomParser.cs b/api/AltV.Net/Alt.ServerCustomParser.cs deleted file mode 100644 index 4623f48eb..000000000 --- a/api/AltV.Net/Alt.ServerCustomParser.cs +++ /dev/null @@ -1,151 +0,0 @@ -using System; -using AltV.Net.FunctionParser; - -namespace AltV.Net -{ - public partial class Alt - { - public static void OnServer(string eventName, Action action, ServerEventParser parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, Action action, ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void - OnServer(string eventName, Action action, ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, Action action, - ServerEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnServer(string eventName, Action action, - ServerEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnServer(string eventName, Action action, - ServerEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnServer(string eventName, Action action, - ServerEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnServer(string eventName, Action action, - ServerEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Action action, - ServerEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Action action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Action action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Action action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Action action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Action action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Action action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Action action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Action action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - - public static void OnServer(string eventName, Func action, ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void - OnServer(string eventName, Func action, ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, Func action, - ServerEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnServer(string eventName, Func action, - ServerEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnServer(string eventName, Func action, - ServerEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnServer(string eventName, Func action, - ServerEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnServer(string eventName, Func action, - ServerEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Func action, - ServerEventParser> parser) => Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Func action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Func action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Func action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Func action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Func action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Func action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Func action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer(string eventName, - Func action, - ServerEventParser> parser) => - Module.On(eventName, action, parser); - - public static void OnServer( - string eventName, - Func action, - ServerEventParser> - parser) => - Module.On(eventName, action, parser); - } -} \ No newline at end of file diff --git a/api/AltV.Net/Event.cs b/api/AltV.Net/ClientEventAttribute.cs similarity index 61% rename from api/AltV.Net/Event.cs rename to api/AltV.Net/ClientEventAttribute.cs index 654ca44c9..33077d15e 100644 --- a/api/AltV.Net/Event.cs +++ b/api/AltV.Net/ClientEventAttribute.cs @@ -3,11 +3,11 @@ namespace AltV.Net { [AttributeUsage(AttributeTargets.Method)] - public class Event : Attribute + public sealed class ClientEventAttribute : Attribute { public string Name { get; } - public Event(string name = null) + public ClientEventAttribute(string name = null) { Name = name; } diff --git a/api/AltV.Net/EventAttribute.cs b/api/AltV.Net/EventAttribute.cs new file mode 100644 index 000000000..91aa8192c --- /dev/null +++ b/api/AltV.Net/EventAttribute.cs @@ -0,0 +1,16 @@ +using System; + +namespace AltV.Net +{ + [Obsolete("This attribute is obsolete. Use ServerEventAttribute or ClientEventAttribute instead.")] + [AttributeUsage(AttributeTargets.Method)] + public sealed class EventAttribute : Attribute + { + public string Name { get; } + + public EventAttribute(string name = null) + { + Name = name; + } + } +} \ No newline at end of file diff --git a/api/AltV.Net/Module.cs b/api/AltV.Net/Module.cs index af1bdca76..f73aa3c93 100644 --- a/api/AltV.Net/Module.cs +++ b/api/AltV.Net/Module.cs @@ -46,20 +46,26 @@ public class Module : IDisposable : target.Assemblies; //For custom defined args event handlers - private readonly Dictionary> eventHandlers = + private readonly Dictionary> eventBus = new Dictionary>(); - private readonly Dictionary> parserClientEventHandlers = + private readonly Dictionary> eventBusClient = + new Dictionary>(); + + private readonly Dictionary> eventBusServer = + new Dictionary>(); + + private readonly Dictionary> eventBusClientParser = new Dictionary>(); - private readonly Dictionary> parserServerEventHandlers = + private readonly Dictionary> eventBusServerParser = new Dictionary>(); //For object[] args event handlers - private readonly Dictionary> eventDelegateHandlers = + private readonly Dictionary> eventBusServerDelegate = new Dictionary>(); - private readonly Dictionary> clientEventDelegateHandlers = + private readonly Dictionary> eventBusClientDelegate = new Dictionary>(); internal readonly IEventHandler CheckpointEventHandler = @@ -198,97 +204,149 @@ public Assembly LoadAssemblyFromNativeImagePath(string nativeImagePath, string a return target.LoadFromNativeImagePath(nativeImagePath, assemblyPath); } + [Obsolete] public void On(string eventName, Function function) { if (function == null) return; - if (eventHandlers.TryGetValue(eventName, out var eventHandlersForEvent)) + if (eventBus.TryGetValue(eventName, out var eventHandlers)) { - eventHandlersForEvent.Add(function); + eventHandlers.Add(function); } else { - eventHandlersForEvent = new HashSet {function}; - eventHandlers[eventName] = eventHandlersForEvent; + eventHandlers = new HashSet {function}; + eventBus[eventName] = eventHandlers; } } + [Obsolete] public void Off(string eventName, Function function) { if (function == null) return; - if (eventHandlers.TryGetValue(eventName, out var eventHandlersForEvent)) + if (eventBus.TryGetValue(eventName, out var eventHandlers)) { - eventHandlersForEvent.Remove(function); + eventHandlers.Remove(function); } } - public void OnServer(string eventName, ServerEventDelegate serverEventDelegate) + public void OnClient(string eventName, Function function) { - if (serverEventDelegate == null) return; - if (eventDelegateHandlers.TryGetValue(eventName, out var eventHandlersForEvent)) + if (function == null) return; + if (eventBusClient.TryGetValue(eventName, out var eventHandlers)) { - eventHandlersForEvent.Add(serverEventDelegate); + eventHandlers.Add(function); } else { - eventHandlersForEvent = new HashSet {serverEventDelegate}; - eventDelegateHandlers[eventName] = eventHandlersForEvent; + eventHandlers = new HashSet {function}; + eventBusClient[eventName] = eventHandlers; } } - public void OffServer(string eventName, ServerEventDelegate serverEventDelegate) + public void OffClient(string eventName, Function function) { - if (serverEventDelegate == null) return; - if (eventDelegateHandlers.TryGetValue(eventName, out var eventHandlersForEvent)) + if (function == null) return; + if (eventBusClient.TryGetValue(eventName, out var eventHandlers)) + { + eventHandlers.Remove(function); + } + } + + public void OnServer(string eventName, Function function) + { + if (function == null) return; + if (eventBusServer.TryGetValue(eventName, out var eventHandlers)) + { + eventHandlers.Add(function); + } + else { - eventHandlersForEvent.Remove(serverEventDelegate); + eventHandlers = new HashSet {function}; + eventBusServer[eventName] = eventHandlers; } } + public void OffServer(string eventName, Function function) + { + if (function == null) return; + if (eventBusServer.TryGetValue(eventName, out var eventHandlers)) + { + eventHandlers.Remove(function); + } + } + + [Obsolete] public void OnClient(string eventName, ClientEventDelegate eventDelegate) { if (eventDelegate == null) return; - if (clientEventDelegateHandlers.TryGetValue(eventName, out var eventHandlersForEvent)) + if (eventBusClientDelegate.TryGetValue(eventName, out var eventHandlers)) { - eventHandlersForEvent.Add(eventDelegate); + eventHandlers.Add(eventDelegate); } else { - eventHandlersForEvent = new HashSet {eventDelegate}; - clientEventDelegateHandlers[eventName] = eventHandlersForEvent; + eventHandlers = new HashSet {eventDelegate}; + eventBusClientDelegate[eventName] = eventHandlers; } } + [Obsolete] public void OffClient(string eventName, ClientEventDelegate eventDelegate) { if (eventDelegate == null) return; - if (clientEventDelegateHandlers.TryGetValue(eventName, out var eventHandlersForEvent)) + if (eventBusClientDelegate.TryGetValue(eventName, out var eventHandlers)) + { + eventHandlers.Remove(eventDelegate); + } + } + + [Obsolete] + public void OnServer(string eventName, ServerEventDelegate serverEventDelegate) + { + if (serverEventDelegate == null) return; + if (eventBusServerDelegate.TryGetValue(eventName, out var eventHandlers)) + { + eventHandlers.Add(serverEventDelegate); + } + else + { + eventHandlers = new HashSet {serverEventDelegate}; + eventBusServerDelegate[eventName] = eventHandlers; + } + } + + [Obsolete] + public void OffServer(string eventName, ServerEventDelegate serverEventDelegate) + { + if (serverEventDelegate == null) return; + if (eventBusServerDelegate.TryGetValue(eventName, out var eventHandlers)) { - eventHandlersForEvent.Remove(eventDelegate); + eventHandlers.Remove(serverEventDelegate); } } public void On(string eventName, TFunc func, ClientEventParser parser) where TFunc : Delegate { if (func == null || parser == null) return; - if (parserClientEventHandlers.TryGetValue(eventName, out var eventHandlersForEvent)) + if (eventBusClientParser.TryGetValue(eventName, out var eventHandlers)) { - eventHandlersForEvent.Add(new ParserClientEventHandler(func, parser)); + eventHandlers.Add(new ParserClientEventHandler(func, parser)); } else { - eventHandlersForEvent = new HashSet + eventHandlers = new HashSet {new ParserClientEventHandler(func, parser)}; - parserClientEventHandlers[eventName] = eventHandlersForEvent; + eventBusClientParser[eventName] = eventHandlers; } } public void Off(string eventName, TFunc func, ClientEventParser parser) where TFunc : Delegate { if (func == null || parser == null) return; - if (!parserClientEventHandlers.TryGetValue(eventName, out var eventHandlersForEvent)) return; + if (!eventBusClientParser.TryGetValue(eventName, out var eventHandlers)) return; var parsersToDelete = new LinkedList(); var eventHandlerToFind = new ParserClientEventHandler(func, parser); - foreach (var eventHandler in eventHandlersForEvent.Where(eventHandler => + foreach (var eventHandler in eventHandlers.Where(eventHandler => eventHandler.Equals(eventHandlerToFind))) { parsersToDelete.AddFirst(eventHandler); @@ -296,32 +354,32 @@ public void Off(string eventName, TFunc func, ClientEventParser pa foreach (var parserToDelete in parsersToDelete) { - eventHandlersForEvent.Remove(parserToDelete); + eventHandlers.Remove(parserToDelete); } } public void On(string eventName, TFunc func, ServerEventParser parser) where TFunc : Delegate { if (func == null || parser == null) return; - if (parserServerEventHandlers.TryGetValue(eventName, out var eventHandlersForEvent)) + if (eventBusServerParser.TryGetValue(eventName, out var eventHandlers)) { - eventHandlersForEvent.Add(new ParserServerEventHandler(func, parser)); + eventHandlers.Add(new ParserServerEventHandler(func, parser)); } else { - eventHandlersForEvent = new HashSet + eventHandlers = new HashSet {new ParserServerEventHandler(func, parser)}; - parserServerEventHandlers[eventName] = eventHandlersForEvent; + eventBusServerParser[eventName] = eventHandlers; } } public void Off(string eventName, TFunc func, ServerEventParser parser) where TFunc : Delegate { if (func == null || parser == null) return; - if (!parserServerEventHandlers.TryGetValue(eventName, out var eventHandlersForEvent)) return; + if (!eventBusServerParser.TryGetValue(eventName, out var eventHandlers)) return; var parsersToDelete = new LinkedList(); var eventHandlerToFind = new ParserServerEventHandler(func, parser); - foreach (var eventHandler in eventHandlersForEvent.Where(eventHandler => + foreach (var eventHandler in eventHandlers.Where(eventHandler => eventHandler.Equals(eventHandlerToFind))) { parsersToDelete.AddFirst(eventHandler); @@ -329,7 +387,7 @@ public void Off(string eventName, TFunc func, ServerEventParser pa foreach (var parserToDelete in parsersToDelete) { - eventHandlersForEvent.Remove(parserToDelete); + eventHandlers.Remove(parserToDelete); } } @@ -636,57 +694,72 @@ public void OnClientEvent(IntPtr playerPointer, string name, IntPtr[] args) return; } - int length = args.Length; - MValueConst[] argArray = null; - if (parserClientEventHandlers.Count != 0 && - parserClientEventHandlers.TryGetValue(name, out var parserEventHandlers)) + var length = args.Length; + MValueConst[] mValues = null; + + if (eventBusClientParser.Count != 0 && + eventBusClientParser.TryGetValue(name, out var parserEventHandlers)) { - argArray = new MValueConst[length]; + mValues = new MValueConst[length]; for (var i = 0; i < length; i++) { - argArray[i] = new MValueConst(args[i]); + mValues[i] = new MValueConst(args[i]); } foreach (var parserEventHandler in parserEventHandlers) { - parserEventHandler.Call(player, argArray); + parserEventHandler.Call(player, mValues); } } - - if (this.eventHandlers.Count != 0 && this.eventHandlers.TryGetValue(name, out var eventHandlers)) + + if (eventBusClient.Count != 0 && eventBusClient.TryGetValue(name, out var eventHandlersClient)) { - if (argArray == null) + if (mValues == null) { - argArray = new MValueConst[length]; + mValues = new MValueConst[length]; for (var i = 0; i < length; i++) { - argArray[i] = new MValueConst(args[i]); + mValues[i] = new MValueConst(args[i]); } } + foreach (var eventHandler in eventHandlersClient) + { + eventHandler.Call(player, mValues); + } + } + if (eventBus.Count != 0 && eventBus.TryGetValue(name, out var eventHandlers)) + { + if (mValues == null) + { + mValues = new MValueConst[length]; + for (var i = 0; i < length; i++) + { + mValues[i] = new MValueConst(args[i]); + } + } foreach (var eventHandler in eventHandlers) { - eventHandler.Call(player, argArray); + eventHandler.Call(player, mValues); } } object[] argObjects = null; - if (clientEventDelegateHandlers.Count != 0 && - clientEventDelegateHandlers.TryGetValue(name, out var eventDelegates)) + if (eventBusClientDelegate.Count != 0 && + eventBusClientDelegate.TryGetValue(name, out var eventDelegates)) { - if (argArray == null) + if (mValues == null) { - argArray = new MValueConst[length]; + mValues = new MValueConst[length]; for (var i = 0; i < length; i++) { - argArray[i] = new MValueConst(args[i]); + mValues[i] = new MValueConst(args[i]); } } - argObjects = new object[length]; for (var i = 0; i < length; i++) { - argObjects[i] = argArray[i].ToObject(); + argObjects[i] = mValues[i].ToObject(); } foreach (var eventHandler in eventDelegates) @@ -697,12 +770,12 @@ public void OnClientEvent(IntPtr playerPointer, string name, IntPtr[] args) if (PlayerClientEventEventHandler.HasEvents()) { - if (argArray == null) + if (mValues == null) { - argArray = new MValueConst[length]; + mValues = new MValueConst[length]; for (var i = 0; i < length; i++) { - argArray[i] = new MValueConst(args[i]); + mValues[i] = new MValueConst(args[i]); } } @@ -711,7 +784,7 @@ public void OnClientEvent(IntPtr playerPointer, string name, IntPtr[] args) argObjects = new object[length]; for (var i = 0; i < length; i++) { - argObjects[i] = argArray[i].ToObject(); + argObjects[i] = mValues[i].ToObject(); } } @@ -723,21 +796,21 @@ public void OnClientEvent(IntPtr playerPointer, string name, IntPtr[] args) if (PlayerClientCustomEventEventHandler.HasEvents()) { - if (argArray == null) + if (mValues == null) { - argArray = new MValueConst[length]; + mValues = new MValueConst[length]; for (var i = 0; i < length; i++) { - argArray[i] = new MValueConst(args[i]); + mValues[i] = new MValueConst(args[i]); } } foreach (var eventHandler in PlayerClientCustomEventEventHandler.GetEvents()) { - eventHandler(player, name, argArray); + eventHandler(player, name, mValues); } } - OnClientEventEvent(player, name, args, argArray, argObjects); + OnClientEventEvent(player, name, args, mValues, argObjects); } public virtual void OnClientEventEvent(IPlayer player, string name, IntPtr[] args, MValueConst[] mValues, @@ -747,15 +820,15 @@ public virtual void OnClientEventEvent(IPlayer player, string name, IntPtr[] arg public void OnServerEvent(string name, IntPtr[] args) { - int length = args.Length; + var length = args.Length; var mValues = new MValueConst[length]; for (var i = 0; i < length; i++) { mValues[i] = new MValueConst(args[i]); } - - if (parserServerEventHandlers.Count != 0 && - parserServerEventHandlers.TryGetValue(name, out var parserEventHandlers)) + + if (eventBusServerParser.Count != 0 && + eventBusServerParser.TryGetValue(name, out var parserEventHandlers)) { foreach (var parserEventHandler in parserEventHandlers) { @@ -763,7 +836,27 @@ public void OnServerEvent(string name, IntPtr[] args) } } - if (this.eventHandlers.Count != 0 && this.eventHandlers.TryGetValue(name, out var eventNameEventHandlers)) + if (eventBusServer.Count != 0 && eventBusServer.TryGetValue(name, out var eventHandlersServer)) + { + foreach (var eventNameEventHandler in eventHandlersServer) + { + try + { + eventNameEventHandler.Call(mValues); + } + catch (TargetInvocationException exception) + { + Alt.Log("exception at event:" + name + ":" + exception.InnerException); + } + catch (Exception exception) + { + Alt.Log("exception at event:" + name + ":" + exception); + } + } + } + + + if (eventBus.Count != 0 && eventBus.TryGetValue(name, out var eventNameEventHandlers)) { foreach (var eventNameEventHandler in eventNameEventHandlers) { @@ -784,7 +877,7 @@ public void OnServerEvent(string name, IntPtr[] args) object[] argObjects = null; - if (eventDelegateHandlers.Count != 0 && eventDelegateHandlers.TryGetValue(name, out var eventDelegates)) + if (eventBusServerDelegate.Count != 0 && eventBusServerDelegate.TryGetValue(name, out var eventDelegates)) { argObjects = new object[length]; for (var i = 0; i < length; i++) diff --git a/api/AltV.Net/ResourceSharedAssembliesAttribute.cs b/api/AltV.Net/ResourceSharedAssembliesAttribute.cs index f114b4431..935fd2f0a 100644 --- a/api/AltV.Net/ResourceSharedAssembliesAttribute.cs +++ b/api/AltV.Net/ResourceSharedAssembliesAttribute.cs @@ -2,10 +2,10 @@ namespace AltV.Net { - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] + [AttributeUsage(AttributeTargets.Assembly)] public sealed class ResourceSharedAssembliesAttribute : Attribute { - public string[] Values { get; set; } + private string[] Values { get; set; } public ResourceSharedAssembliesAttribute(params string[] values) { diff --git a/api/AltV.Net/ScriptEvent.cs b/api/AltV.Net/ScriptEventAttribute.cs similarity index 62% rename from api/AltV.Net/ScriptEvent.cs rename to api/AltV.Net/ScriptEventAttribute.cs index 9a2559ed7..6b8d79c29 100644 --- a/api/AltV.Net/ScriptEvent.cs +++ b/api/AltV.Net/ScriptEventAttribute.cs @@ -1,15 +1,15 @@ -using System; - -namespace AltV.Net -{ - [AttributeUsage(AttributeTargets.Method)] - public class ScriptEvent : Attribute - { - public ScriptEventType EventType { get; } - - public ScriptEvent(ScriptEventType eventType) - { - EventType = eventType; - } - } +using System; + +namespace AltV.Net +{ + [AttributeUsage(AttributeTargets.Method)] + public sealed class ScriptEventAttribute : Attribute + { + public ScriptEventType EventType { get; } + + public ScriptEventAttribute(ScriptEventType eventType) + { + EventType = eventType; + } + } } \ No newline at end of file diff --git a/api/AltV.Net/ServerEventAttribute.cs b/api/AltV.Net/ServerEventAttribute.cs new file mode 100644 index 000000000..4d1f24131 --- /dev/null +++ b/api/AltV.Net/ServerEventAttribute.cs @@ -0,0 +1,15 @@ +using System; + +namespace AltV.Net +{ + [AttributeUsage(AttributeTargets.Method)] + public sealed class ServerEventAttribute : Attribute + { + public string Name { get; } + + public ServerEventAttribute(string name = null) + { + Name = name; + } + } +} \ No newline at end of file