actually now its usable

This commit is contained in:
zznty
2023-11-13 23:17:39 +07:00
parent aecc7ee66f
commit ce07a1e86a
41 changed files with 1401 additions and 138 deletions

View File

@@ -3,10 +3,13 @@ using System.IO;
using java.lang;
using java.util;
using LuckPerms.Torch.Impl;
using LuckPerms.Torch.PlatformApi;
using NLog;
using Sandbox;
using Torch;
using Torch.API;
using Torch.API.Managers;
using Torch.API.Session;
using Exception = System.Exception;
using Object = java.lang.Object;
@@ -23,58 +26,14 @@ public class Plugin : TorchPluginBase
}
public static readonly ILogger Log = LogManager.GetLogger("LuckPerms");
private LpTorchBootstrap? _bootstrap;
public override void Init(ITorchBase torch)
{
base.Init(torch);
Torch.GameStateChanged += TorchOnGameStateChanged;
_bootstrap = new((ITorchServer)Torch, this, Log, Path.Combine(StoragePath, "luckperms"));
try
{
Log.Info("Initializing LuckPerms");
_bootstrap.Plugin.load();
}
catch (Exception e)
{
Log.Fatal(e);
throw;
}
finally
{
_bootstrap.LoadLatch.countDown();
}
}
private void TorchOnGameStateChanged(MySandboxGame game, TorchGameState newState)
{
if (_bootstrap is null)
throw new InvalidOperationException("Plugin is not initialized");
switch (newState)
{
case TorchGameState.Loading:
try
{
Log.Info("Loading LuckPerms");
Thread.currentThread().setContextClassLoader(LpDependencyManager.CurrentClassLoader);
_bootstrap.Plugin.enable();
}
catch (Exception e)
{
Log.Fatal(e);
throw;
}
finally
{
_bootstrap.EnableLatch.countDown();
}
break;
case TorchGameState.Unloading:
Log.Info("Unloading LuckPerms");
_bootstrap.Plugin.disable();
break;
}
var platformManager = new LuckPermsPlatformManager(this, (ITorchServer)torch, Log);
Torch.Managers.GetManager<ITorchSessionManager>().AddFactory(_ => platformManager);
}
}