From e1ca099dd9bc5e4bbc3c92624b8d2dcf416e6413 Mon Sep 17 00:00:00 2001 From: zznty <94796179+zznty@users.noreply.github.com> Date: Mon, 20 Nov 2023 19:36:35 +0700 Subject: [PATCH] more api --- LuckPerms.Torch.Api/LuckPerms.Torch.Api.nuspec | 4 ++-- LuckPerms.Torch.Utils/Api/ILpPlayerModel.cs | 14 ++++++++++++++ .../Api/Managers/ILuckPermsPlatformManager.cs | 8 ++++++++ LuckPerms.Torch.Utils/LuckPerms.Torch.Utils.csproj | 12 +++++++----- .../ModApi/TorchApi.cs | 0 .../{ => Utils}/Extensions/DelegateExtensions.cs | 0 .../{ => Utils}/Extensions/EnumerableExtensions.cs | 0 .../{ => Utils}/Extensions/IteratorExtensions.cs | 0 .../{ => Utils}/Extensions/StreamExtensions.cs | 0 .../{ => Utils}/Extensions/UUIDExtensions.cs | 0 LuckPerms.Torch/ModApi/ModApiManager.cs | 6 ++++-- LuckPerms.Torch/PlatformApi/LpPlayerModel.cs | 5 +++-- .../PlatformApi/LuckPermsPlatformManager.cs | 9 ++++++--- LuckPerms.Torch/manifest.xml | 2 +- 14 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 LuckPerms.Torch.Utils/Api/ILpPlayerModel.cs create mode 100644 LuckPerms.Torch.Utils/Api/Managers/ILuckPermsPlatformManager.cs rename {LuckPerms.Torch => LuckPerms.Torch.Utils}/ModApi/TorchApi.cs (100%) rename LuckPerms.Torch.Utils/{ => Utils}/Extensions/DelegateExtensions.cs (100%) rename LuckPerms.Torch.Utils/{ => Utils}/Extensions/EnumerableExtensions.cs (100%) rename LuckPerms.Torch.Utils/{ => Utils}/Extensions/IteratorExtensions.cs (100%) rename LuckPerms.Torch.Utils/{ => Utils}/Extensions/StreamExtensions.cs (100%) rename LuckPerms.Torch.Utils/{ => Utils}/Extensions/UUIDExtensions.cs (100%) diff --git a/LuckPerms.Torch.Api/LuckPerms.Torch.Api.nuspec b/LuckPerms.Torch.Api/LuckPerms.Torch.Api.nuspec index cd9533c..b8613b9 100644 --- a/LuckPerms.Torch.Api/LuckPerms.Torch.Api.nuspec +++ b/LuckPerms.Torch.Api/LuckPerms.Torch.Api.nuspec @@ -2,13 +2,13 @@ LuckPerms.Torch.Api - 5.4 + 5.4.1 LuckPerms.Torch.Api Package Description - + diff --git a/LuckPerms.Torch.Utils/Api/ILpPlayerModel.cs b/LuckPerms.Torch.Utils/Api/ILpPlayerModel.cs new file mode 100644 index 0000000..0a569f5 --- /dev/null +++ b/LuckPerms.Torch.Utils/Api/ILpPlayerModel.cs @@ -0,0 +1,14 @@ +using net.luckperms.api.query; +using net.luckperms.api.util; +using Torch.API; + +namespace LuckPerms.Torch.Api; + +public interface ILpPlayerModel : IPlayer +{ + Tristate HasPermission(string permission); + Tristate HasPermission(string permission, QueryOptions queryOptions); + + string? GetOption(string key); + string? GetOption(string key, QueryOptions queryOptions); +} \ No newline at end of file diff --git a/LuckPerms.Torch.Utils/Api/Managers/ILuckPermsPlatformManager.cs b/LuckPerms.Torch.Utils/Api/Managers/ILuckPermsPlatformManager.cs new file mode 100644 index 0000000..b41781e --- /dev/null +++ b/LuckPerms.Torch.Utils/Api/Managers/ILuckPermsPlatformManager.cs @@ -0,0 +1,8 @@ +using Torch.API.Managers; + +namespace LuckPerms.Torch.Api.Managers; + +public interface ILuckPermsPlatformManager : IManager +{ + net.luckperms.api.LuckPerms Api { get; } +} \ No newline at end of file diff --git a/LuckPerms.Torch.Utils/LuckPerms.Torch.Utils.csproj b/LuckPerms.Torch.Utils/LuckPerms.Torch.Utils.csproj index 2fc61a6..d938c88 100644 --- a/LuckPerms.Torch.Utils/LuckPerms.Torch.Utils.csproj +++ b/LuckPerms.Torch.Utils/LuckPerms.Torch.Utils.csproj @@ -2,26 +2,28 @@ net48 + LuckPerms.Torch 12 enable enable - 1.0.0 + 1.0.1 - + $(ProjectDir)libs\ $(LibsPath)api-5.4.jar - + api true - + - + + diff --git a/LuckPerms.Torch/ModApi/TorchApi.cs b/LuckPerms.Torch.Utils/ModApi/TorchApi.cs similarity index 100% rename from LuckPerms.Torch/ModApi/TorchApi.cs rename to LuckPerms.Torch.Utils/ModApi/TorchApi.cs diff --git a/LuckPerms.Torch.Utils/Extensions/DelegateExtensions.cs b/LuckPerms.Torch.Utils/Utils/Extensions/DelegateExtensions.cs similarity index 100% rename from LuckPerms.Torch.Utils/Extensions/DelegateExtensions.cs rename to LuckPerms.Torch.Utils/Utils/Extensions/DelegateExtensions.cs diff --git a/LuckPerms.Torch.Utils/Extensions/EnumerableExtensions.cs b/LuckPerms.Torch.Utils/Utils/Extensions/EnumerableExtensions.cs similarity index 100% rename from LuckPerms.Torch.Utils/Extensions/EnumerableExtensions.cs rename to LuckPerms.Torch.Utils/Utils/Extensions/EnumerableExtensions.cs diff --git a/LuckPerms.Torch.Utils/Extensions/IteratorExtensions.cs b/LuckPerms.Torch.Utils/Utils/Extensions/IteratorExtensions.cs similarity index 100% rename from LuckPerms.Torch.Utils/Extensions/IteratorExtensions.cs rename to LuckPerms.Torch.Utils/Utils/Extensions/IteratorExtensions.cs diff --git a/LuckPerms.Torch.Utils/Extensions/StreamExtensions.cs b/LuckPerms.Torch.Utils/Utils/Extensions/StreamExtensions.cs similarity index 100% rename from LuckPerms.Torch.Utils/Extensions/StreamExtensions.cs rename to LuckPerms.Torch.Utils/Utils/Extensions/StreamExtensions.cs diff --git a/LuckPerms.Torch.Utils/Extensions/UUIDExtensions.cs b/LuckPerms.Torch.Utils/Utils/Extensions/UUIDExtensions.cs similarity index 100% rename from LuckPerms.Torch.Utils/Extensions/UUIDExtensions.cs rename to LuckPerms.Torch.Utils/Utils/Extensions/UUIDExtensions.cs diff --git a/LuckPerms.Torch/ModApi/ModApiManager.cs b/LuckPerms.Torch/ModApi/ModApiManager.cs index de7b074..90c2821 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.Api; +using LuckPerms.Torch.Api.Managers; using LuckPerms.Torch.Extensions; using LuckPerms.Torch.Utils.Extensions; using Torch.API; @@ -22,7 +24,7 @@ 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(ModApiManager).Assembly.Location, // LuckPerms.Torch.dll + typeof(ILuckPermsPlatformManager).Assembly.Location, // LuckPerms.Torch.Utils.dll typeof(ITorchBase).Assembly.Location // Torch.API.dll ); @@ -48,7 +50,7 @@ public class ModApiManager : IManager 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)); + typeof(IPlayer), typeof(ConnectionState), typeof(ILpPlayerModel)); } public void Detach() diff --git a/LuckPerms.Torch/PlatformApi/LpPlayerModel.cs b/LuckPerms.Torch/PlatformApi/LpPlayerModel.cs index 59b1db3..c36ef96 100644 --- a/LuckPerms.Torch/PlatformApi/LpPlayerModel.cs +++ b/LuckPerms.Torch/PlatformApi/LpPlayerModel.cs @@ -1,4 +1,5 @@ -using LuckPerms.Torch.Impl; +using LuckPerms.Torch.Api; +using LuckPerms.Torch.Impl; using me.lucko.luckperms.common.context.manager; using me.lucko.luckperms.common.model; using me.lucko.luckperms.common.verbose.@event; @@ -8,7 +9,7 @@ using Torch.ViewModels; namespace LuckPerms.Torch.PlatformApi; -public class LpPlayerModel(ulong steamId, string? name = null) : PlayerViewModel(steamId, name) +public class LpPlayerModel(ulong steamId, string? name = null) : PlayerViewModel(steamId, name), ILpPlayerModel { public QueryOptionsCache? QueryOptionsCache { get; private set; } public User? LpUser { get; private set; } diff --git a/LuckPerms.Torch/PlatformApi/LuckPermsPlatformManager.cs b/LuckPerms.Torch/PlatformApi/LuckPermsPlatformManager.cs index afa05cd..e8e9202 100644 --- a/LuckPerms.Torch/PlatformApi/LuckPermsPlatformManager.cs +++ b/LuckPerms.Torch/PlatformApi/LuckPermsPlatformManager.cs @@ -1,18 +1,21 @@ -using System.IO; +using System; +using System.IO; using java.lang; +using LuckPerms.Torch.Api.Managers; using LuckPerms.Torch.Impl; using NLog; using Torch; using Torch.API; -using Torch.API.Managers; using Exception = System.Exception; namespace LuckPerms.Torch.PlatformApi; -public class LuckPermsPlatformManager : IManager +public class LuckPermsPlatformManager : ILuckPermsPlatformManager { private readonly ILogger _log = LogManager.GetCurrentClassLogger(); private readonly LpTorchBootstrap _bootstrap; + + public net.luckperms.api.LuckPerms Api => _bootstrap.EnableLatch.getCount() == 0 ? _bootstrap.Plugin.getApiProvider() : throw new InvalidOperationException("Api is not initialized"); public LuckPermsPlatformManager(TorchPluginBase plugin, ITorchServer server, ILogger log) { diff --git a/LuckPerms.Torch/manifest.xml b/LuckPerms.Torch/manifest.xml index 6c24c11..673d5bd 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.5 + v5.4.106.6 \ No newline at end of file