Pilz.Dalamud 0.3.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Pilz.Dalamud --version 0.3.1                
NuGet\Install-Package Pilz.Dalamud -Version 0.3.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pilz.Dalamud" Version="0.3.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pilz.Dalamud --version 0.3.1                
#r "nuget: Pilz.Dalamud, 0.3.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Pilz.Dalamud as a Cake Addin
#addin nuget:?package=Pilz.Dalamud&version=0.3.1

// Install Pilz.Dalamud as a Cake Tool
#tool nuget:?package=Pilz.Dalamud&version=0.3.1                

Pilz.Dalamud

This library is a set of usefull functions you can use within your Dalamud plugin.
At the moment it's far away from being complete or even good. Right now it as some basic functions and tools to work with Nameplates and TextPayloads.

How to install

Install the latest version of Pilz.Dalamud via NuGet Package Manager or NuGet Console:
https://www.nuget.org/packages/Pilz.Dalamud

Get started

Initialize Plugin Services

To be able to use most features of that lib you must initialize the Plugin Services. The best time to do this is when you initialize your own Plugin Services at your IDalamudPlugin class constructor.

public Plugin(DalamudPluginInterface pluginInterface)
{
    // Initialize our own Plugin Services if we use them
    PluginServices.Initialize(pluginInterface);
    
    // Initialize Plugin Services for `Pilz.Dalamud` because the lib uses them
    Pilz.Dalamud.PluginServices.Initialize(pluginInterface);
}

Hook into Nameplates

To edit the nameplate, you first need to hook and listen to the Game's updates. Also don't forget to unhook and dispose on unloading the plugins!

public class NameplateFeature : IDisposable
{
    public NameplateManager NameplateManager { get; init; }
    
    /// <summary>
    /// Occurs when a player nameplate is updated by the game.
    /// </summary>
    public event PlayerNameplateUpdatedDelegate? PlayerNameplateUpdated;
    
    public NameplateFeature()
    {
        NameplateManager = new();
        NameplateManager.Hooks.AddonNamePlate_SetPlayerNameManaged += Hooks_AddonNamePlate_SetPlayerNameManaged;
    }
    
    public void Dispose()
    {
        NameplateManager.Hooks.AddonNamePlate_SetPlayerNameManaged -= Hooks_AddonNamePlate_SetPlayerNameManaged;
        NameplateManager.Dispose();
    }
    
    private void Hooks_AddonNamePlate_SetPlayerNameManaged(Pilz.Dalamud.Nameplates.EventArgs.AddonNamePlate_SetPlayerNameManagedEventArgs eventArgs)
    {
    }
}

This is an example of editing the title to "Good Player" and change the color of the name:

private void Hooks_AddonNamePlate_SetPlayerNameManaged(Pilz.Dalamud.Nameplates.EventArgs.AddonNamePlate_SetPlayerNameManagedEventArgs eventArgs)
{
    try
    {
        // Get the referenced player object for the nameplate object
        PlayerCharacter? playerCharacter = NameplateManager.GetNameplateGameObject<PlayerCharacter>(eventArgs.SafeNameplateObject);
        
        if (playerCharacter != null && playerCharacter.StatusFlags.HasFlag(StatusFlags.Friend))
        {
            const string TEXT_GOOD_PLAYER = "Good Player";
            
            // Create a new change
            var nameplateChanges = new NameplateChanges(eventArgs);
            
            // Replace the title
            var titleChange = nameplateChanges.GetChange(NameplateElements.Title, StringPosition.Replace);
            titleChange.Payloads.Add(new TextPayload(TEXT_GOOD_PLAYER));
            
            // Make the name italic
            var nameChangeBefore = nameplateChanges.GetChange(NameplateElements.Name, StringPosition.Before);
            nameChangeBefore.Payloads.Add(new EmphasisItalicPayload(true));
            
            var nameChangeAfter = nameplateChanges.GetChange(NameplateElements.Name, StringPosition.After);
            nameChangeAfter.Payloads.Add(new EmphasisItalicPayload(false));
            
            // Forge the title to be always above the name (this we can edit directly)
            eventArgs.IsTitleAboveName = true;
            
            // Apply the string changes!
            NameplateUpdateFactory.ApplyNameplateChanges(new NameplateChangesProps(nameplateChanges));
        }
    }
    catch (Exception ex)
    {
        PluginLog.Error(ex, $"SetPlayerNameplateDetour");
    }
}

Contribute

  • Freel free to PR changes or new features/libraries.
  • If you want to address bigger changes or want a discussion about something, feel free to open an issue.
Product Compatible and additional computed target framework versions.
.NET net7.0-windows7.0 is compatible.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 89 11/23/2024
1.0.0 90 11/22/2024
0.7.0 84 7/25/2024
0.6.1.1 102 7/20/2024
0.6.1 97 7/20/2024
0.6.0 90 7/17/2024
0.5.2.1 833 10/7/2023
0.5.2 144 10/7/2023
0.5.1 140 10/6/2023
0.5.0 173 10/3/2023
0.4.0 514 5/24/2023
0.3.1 205 4/5/2023
0.3.0 205 4/3/2023
0.2.0 656 1/9/2023
0.1.1 338 11/21/2022
0.1.0 337 11/8/2022