Clone
1
LuckPerms Plugin Api
zznty edited this page 2023-11-20 10:29:39 +03:00

LuckPerms Plugin API

Getting Started

Option 1: Convert Your Existing Project to SDK Style and Add NuGet Source

  1. Convert your existing project to the SDK style. For guidance on this process, check out Microsoft documentation on how to do this here: Converting C# projects to the new SDK format.

  2. Then, add a new NuGet source. Open NuGet Packet Manager Settings and add a new package source with the following URL: https://nuget.storage.yandexcloud.net/index.json.

Option 2: Install TorchAPI.Templates and Create a New Project

You can directly install the TorchAPI.Templates NuGet package. You can Install it directly from the NuGet Gallery:

dotnet new install TorchAPI.Templates::X.X.X

Where X.X.X represents the version of the package TorchAPI.Templates you wish to install. For lastest version check nuget page.

After installing the package, create a new project. For help on creating a new project, refer to the Microsoft Docs on Projects.

Add reference to LuckPerms.Torch.Api

Regardless of the path you've chosen to set up your project, the next step will be the same. You'll need to add a reference to LuckPerms.Torch.Api to your project file.

Option 1: Install via package manager interface

You can search for LuckPerms.Torch.Api in Nuget Package Manager. For help on adding nuget packages, refer to the Microsoft Docs on Installing Nuget Packages.

Option 2: Add directly to the project file

<Project Sdk="Microsoft.NET.Sdk">
...
<ItemGroup>
    <PackageReference Include="LuckPerms.Torch.Api" Version="X.X.X" />
</ItemGroup>
...
</Project>

Replace X.X.X with the version number of LuckPerms.Torch.Api you want to use. For the time of writing this page latest api version is 5.4.0.

Obtaining API Instance

An instance of the API can only be obtained after the session manager's attach event. This means you can't get an instance of the API immediately upon starting your application; you'll need to wait for this event before you try to obtain it.

Once that event has taken place, you can get an instance of LuckPerms by using the static get() method from LuckPermsProvider.

var api = LuckPermsProvider.get();

Ensure that you have appropriately dealt with the possibility that the API instance may not be available immediately upon application startup or even completely in case the plugin is not installed.

Platform Specifics

LuckPerms API provides access and interaction with core game elements depending on the platform specifics.

Player Instance

You can obtain Player instance by looking up the "Players" dictionary on the MultiplayerManagerBase manager instance.

var player = multiplayerManager.Players[playerSteamId];

Replace playerSteamId with the actual Id of the player.

Player Type

Always use typeof(IPlayer) in case of player class type requirement in an api call.

For example getting LuckPerms User instance:

var user = luckPerms.getPlayerAdapter(typeof(IPlayer)).getUser(player);

Conversion of Steam IDs and UUIDs

LuckPerms also offer extension methods that allow conversion of Steam IDs to UUID and vice versa.

You can convert Steam IDs to UUID with ulong.GetUuid:

var uuid = someSteamId.GetUuid();

And you can convert UUID back to Steam Id with UUID.GetSteamId:

var steamId = someUuid.GetSteamId();

Using The API

After successfully obtaining the API instance, you can delve deeper into the API basics, functionalities and features. For more detailed information and useful guides, refer to the official LuckPerms documentation on API Usage: LuckPerms - Developer API Usage.