mod api impl

This commit is contained in:
zznty
2023-11-10 16:02:14 +07:00
parent ec5e20b922
commit 78164fd6be
4 changed files with 69 additions and 2 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</Version>
<Version>v5.4.106.1</Version>
</PluginManifest>

View File

@@ -6,6 +6,7 @@ using LuckPerms.Torch.Extensions;
using LuckPerms.Torch.Impl.Calculator;
using LuckPerms.Torch.Impl.Listeners;
using LuckPerms.Torch.Impl.Messaging;
using LuckPerms.Torch.ModApi;
using LuckPerms.Torch.PlatformHooks;
using me.lucko.luckperms.common.api;
using me.lucko.luckperms.common.calculator;
@@ -71,6 +72,7 @@ public class LpTorchPlugin(LuckPermsBootstrap bootstrap, ITorchBase torch) : Abs
_trackManager = new(this);
_connectionListener = new(this);
torch.Managers.GetManager<ITorchSessionManager>().AddFactory(_ => _connectionListener);
torch.Managers.GetManager<ITorchSessionManager>().AddFactory(_ => new ModApiManager());
}
protected override CalculatorFactory provideCalculatorFactory() => new LpCalculatorFactory(this);

View File

@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ikvm.extensions;
using ikvm.runtime;
using java.lang;
using Torch.API.Managers;
using VRage.Scripting;
namespace LuckPerms.Torch.ModApi;
public class ModApiManager : IManager
{
public void Attach()
{
// TODO make and reference platform helpers (uuid extensions, delegate converters etc)
MyScriptCompiler.Static.AddConditionalCompilationSymbols("LUCKPERMS_API");
MyScriptCompiler.Static.AddReferencedAssemblies(
typeof(net.luckperms.api.LuckPerms).Assembly.Location, // net.luckperms.api.dll
typeof(java.lang.Boolean).Assembly.Location // IKVM.Java.dll
);
using var whitelist = MyScriptCompiler.Static.Whitelist.OpenBatch();
whitelist.AllowNamespaceOfTypes(MyWhitelistTarget.ModApi, typeof(net.luckperms.api.LuckPerms).Assembly.GetTypes().Distinct(TypeNamespaceComparer.Instance).ToArray());
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));
whitelist.AllowMembers(MyWhitelistTarget.ModApi,
typeof(Class).GetMethod("op_Implicit", new[] { typeof(Type) }),
typeof(Class).GetMethod(nameof(Class.getName)),
typeof(Class).GetMethod(nameof(Class.getTypeName)),
typeof(Util).GetMethod(nameof(Util.getClassFromObject)),
typeof(Util).GetMethod(nameof(Util.getFriendlyClassFromType)),
typeof(Util).GetMethod(nameof(Util.getInstanceTypeFromClass)),
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)));
}
public void Detach()
{
}
private sealed class TypeNamespaceComparer : IEqualityComparer<Type>
{
public static readonly IEqualityComparer<Type> Instance = new TypeNamespaceComparer();
public bool Equals(Type x, Type y)
{
if (ReferenceEquals(x, y)) return true;
if (ReferenceEquals(x, null)) return false;
if (ReferenceEquals(y, null)) return false;
if (x.GetType() != y.GetType()) return false;
return x.Namespace == y.Namespace;
}
public int GetHashCode(Type obj)
{
return obj.Namespace != null ? obj.Namespace.GetHashCode() : 0;
}
}
}

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</Version>
<Version>v5.4.106.1</Version>
</PluginManifest>