fix mod api

This commit is contained in:
zznty
2023-11-10 20:17:46 +07:00
parent bb5750f754
commit 989088cee8
7 changed files with 42 additions and 6 deletions

View File

@@ -2,5 +2,5 @@
<PluginManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>LuckPerms.Loader</Name>
<Guid>7E4B3CC8-64FA-416E-8910-AACDF2DA5E2C</Guid>
<Version>v5.4.106.2</Version>
<Version>v5.4.106.3</Version>
</PluginManifest>

View File

@@ -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)
{

View File

@@ -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()];
}

View File

@@ -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)
{

View File

@@ -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()

View File

@@ -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
}

View File

@@ -2,5 +2,5 @@
<PluginManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>LuckPerms.Torch</Name>
<Guid>7E4B3CC8-64FA-416E-8910-AACDF2DA5E2C</Guid>
<Version>v5.4.106.2</Version>
<Version>v5.4.106.3</Version>
</PluginManifest>