-
Notifications
You must be signed in to change notification settings - Fork 15
/
Plugin.cs
84 lines (69 loc) · 2.71 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using Dalamud.Game.ClientState;
using Dalamud.Game.Command;
using Dalamud.Game.Gui;
using Dalamud.Interface.Windowing;
using Dalamud.Logging;
using Dalamud.Plugin;
using DalamudPluginProjectTemplate.Attributes;
using System;
namespace DalamudPluginProjectTemplate
{
public class Plugin : IDalamudPlugin
{
private readonly DalamudPluginInterface pluginInterface;
private readonly ChatGui chat;
private readonly ClientState clientState;
private readonly PluginCommandManager<Plugin> commandManager;
private readonly Configuration config;
private readonly WindowSystem windowSystem;
public string Name => "Your Plugin's Display Name";
public Plugin(
DalamudPluginInterface pi,
CommandManager commands,
ChatGui chat,
ClientState clientState)
{
this.pluginInterface = pi;
this.chat = chat;
this.clientState = clientState;
// Get or create a configuration object
this.config = (Configuration)this.pluginInterface.GetPluginConfig()
?? this.pluginInterface.Create<Configuration>();
// Initialize the UI
this.windowSystem = new WindowSystem(typeof(Plugin).AssemblyQualifiedName);
var window = this.pluginInterface.Create<PluginWindow>();
if (window is not null)
{
this.windowSystem.AddWindow(window);
}
this.pluginInterface.UiBuilder.Draw += this.windowSystem.Draw;
// Load all of our commands
this.commandManager = new PluginCommandManager<Plugin>(this, commands);
}
[Command("/example1")]
[HelpMessage("Example help message.")]
public void ExampleCommand1(string command, string args)
{
// You may want to assign these references to private variables for convenience.
// Keep in mind that the local player does not exist until after logging in.
var world = this.clientState.LocalPlayer?.CurrentWorld.GameData;
this.chat.Print($"Hello, {world?.Name}!");
PluginLog.Log("Message sent successfully.");
}
#region IDisposable Support
protected virtual void Dispose(bool disposing)
{
if (!disposing) return;
this.commandManager.Dispose();
this.pluginInterface.SavePluginConfig(this.config);
this.pluginInterface.UiBuilder.Draw -= this.windowSystem.Draw;
this.windowSystem.RemoveAllWindows();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}