From 989088cee890aad76218935830374129473159f2 Mon Sep 17 00:00:00 2001 From: zznty <94796179+zznty@users.noreply.github.com> Date: Fri, 10 Nov 2023 20:17:46 +0700 Subject: [PATCH] fix mod api --- LuckPerms.Loader/manifest.xml | 2 +- .../Extensions/KeyedConfigurationExtensions.cs | 2 +- .../Extensions/MultiplayerManagerExtensions.cs | 15 +++++++++++++++ LuckPerms.Torch/Extensions/StreamExtensions.cs | 2 +- LuckPerms.Torch/ModApi/ModApiManager.cs | 13 +++++++++++-- LuckPerms.Torch/ModApi/TorchApi.cs | 12 ++++++++++++ LuckPerms.Torch/manifest.xml | 2 +- 7 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 LuckPerms.Torch/Extensions/MultiplayerManagerExtensions.cs create mode 100644 LuckPerms.Torch/ModApi/TorchApi.cs diff --git a/LuckPerms.Loader/manifest.xml b/LuckPerms.Loader/manifest.xml index 6306778..58adc1a 100644 --- a/LuckPerms.Loader/manifest.xml +++ b/LuckPerms.Loader/manifest.xml @@ -2,5 +2,5 @@ LuckPerms.Loader 7E4B3CC8-64FA-416E-8910-AACDF2DA5E2C - v5.4.106.2 + v5.4.106.3 \ No newline at end of file diff --git a/LuckPerms.Torch/Extensions/KeyedConfigurationExtensions.cs b/LuckPerms.Torch/Extensions/KeyedConfigurationExtensions.cs index d305e86..6ca75d0 100644 --- a/LuckPerms.Torch/Extensions/KeyedConfigurationExtensions.cs +++ b/LuckPerms.Torch/Extensions/KeyedConfigurationExtensions.cs @@ -4,7 +4,7 @@ using me.lucko.luckperms.common.config.generic.key; namespace LuckPerms.Torch.Extensions; -public static class KeyedConfigurationExtensions +internal static class KeyedConfigurationExtensions { public static bool GetBoolean(this KeyedConfiguration config, ConfigKey key, bool defaultValue = default) { diff --git a/LuckPerms.Torch/Extensions/MultiplayerManagerExtensions.cs b/LuckPerms.Torch/Extensions/MultiplayerManagerExtensions.cs new file mode 100644 index 0000000..ca1d50b --- /dev/null +++ b/LuckPerms.Torch/Extensions/MultiplayerManagerExtensions.cs @@ -0,0 +1,15 @@ +using java.util; +using Torch.API; +using Torch.API.Managers; +using Torch.Server.Managers; + +namespace LuckPerms.Torch.Extensions; + +public static class MultiplayerManagerExtensions +{ + public static IPlayer GetPlayer(this IMultiplayerManagerServer manager, ulong steamId) => + ((MultiplayerManagerDedicated)manager).Players[steamId]; + + public static IPlayer GetPlayer(this IMultiplayerManagerServer manager, UUID uuid) => + ((MultiplayerManagerDedicated)manager).Players[uuid.GetSteamId()]; +} \ No newline at end of file diff --git a/LuckPerms.Torch/Extensions/StreamExtensions.cs b/LuckPerms.Torch/Extensions/StreamExtensions.cs index a9f4cf3..67a3895 100644 --- a/LuckPerms.Torch/Extensions/StreamExtensions.cs +++ b/LuckPerms.Torch/Extensions/StreamExtensions.cs @@ -5,7 +5,7 @@ using Torch.Utils; namespace LuckPerms.Torch.Extensions; -public static class StreamExtensions +internal static class StreamExtensions { public static InputStream GetInputStream(this Stream stream) { diff --git a/LuckPerms.Torch/ModApi/ModApiManager.cs b/LuckPerms.Torch/ModApi/ModApiManager.cs index 9f9e6f2..e519961 100644 --- a/LuckPerms.Torch/ModApi/ModApiManager.cs +++ b/LuckPerms.Torch/ModApi/ModApiManager.cs @@ -4,6 +4,8 @@ using System.Linq; using ikvm.extensions; using ikvm.runtime; using java.lang; +using LuckPerms.Torch.Extensions; +using Torch.API; using Torch.API.Managers; using VRage.Scripting; @@ -18,7 +20,8 @@ public class ModApiManager : IManager MyScriptCompiler.Static.AddReferencedAssemblies( typeof(net.luckperms.api.LuckPerms).Assembly.Location, // net.luckperms.api.dll - typeof(java.lang.Boolean).Assembly.Location // IKVM.Java.dll + typeof(java.lang.Boolean).Assembly.Location, // IKVM.Java.dll + typeof(ModApiManager).Assembly.Location // LuckPerms.Torch.dll ); using var whitelist = MyScriptCompiler.Static.Whitelist.OpenBatch(); @@ -27,7 +30,8 @@ public class ModApiManager : IManager whitelist.AllowNamespaceOfTypes(MyWhitelistTarget.ModApi, typeof(java.util.function.Consumer), typeof(java.util.UUID), typeof(java.time.Instant), typeof(java.time.temporal.Temporal)); whitelist.AllowTypes(MyWhitelistTarget.ModApi, typeof(java.lang.Boolean), typeof(java.lang.Enum), typeof(AutoCloseable), typeof(java.util.concurrent.TimeUnit), - typeof(java.util.concurrent.CompletableFuture)); + typeof(java.util.concurrent.CompletableFuture), + typeof(java.util.concurrent.Executor)); whitelist.AllowMembers(MyWhitelistTarget.ModApi, typeof(Class).GetMethod("op_Implicit", new[] { typeof(Type) }), typeof(Class).GetMethod(nameof(Class.getName)), @@ -38,6 +42,11 @@ public class ModApiManager : IManager typeof(Util).GetMethod(nameof(Util.getRuntimeTypeFromClass)), typeof(ExtensionMethods).GetMethod(nameof(ExtensionMethods.getClass), new []{ typeof(object) }), typeof(java.lang.Object).GetMethod(nameof(java.lang.Object.getClass))); + + whitelist.AllowNamespaceOfTypes(MyWhitelistTarget.ModApi, typeof(UuidExtensions)); + whitelist.AllowTypes(MyWhitelistTarget.ModApi, typeof(TorchApi), typeof(IDependencyProvider), typeof(IManager), + typeof(DependencyProviderExtensions), typeof(IMultiplayerManagerServer), typeof(IMultiplayerManagerBase), + typeof(IPlayer), typeof(ConnectionState)); } public void Detach() diff --git a/LuckPerms.Torch/ModApi/TorchApi.cs b/LuckPerms.Torch/ModApi/TorchApi.cs new file mode 100644 index 0000000..13298fe --- /dev/null +++ b/LuckPerms.Torch/ModApi/TorchApi.cs @@ -0,0 +1,12 @@ +using Torch; +using Torch.API.Managers; + +namespace LuckPerms.Torch.ModApi; + +public static class TorchApi +{ + public static IDependencyProvider Managers => +#pragma warning disable CS0618 // Type or member is obsolete + TorchBase.Instance.CurrentSession?.Managers ?? TorchBase.Instance.Managers; +#pragma warning restore CS0618 // Type or member is obsolete +} \ No newline at end of file diff --git a/LuckPerms.Torch/manifest.xml b/LuckPerms.Torch/manifest.xml index d005048..216648e 100644 --- a/LuckPerms.Torch/manifest.xml +++ b/LuckPerms.Torch/manifest.xml @@ -2,5 +2,5 @@ LuckPerms.Torch 7E4B3CC8-64FA-416E-8910-AACDF2DA5E2C - v5.4.106.2 + v5.4.106.3 \ No newline at end of file