Skip to content

Commit

Permalink
improve example
Browse files Browse the repository at this point in the history
  • Loading branch information
XtraCube committed Dec 8, 2024
1 parent 29c2939 commit c1d2455
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
8 changes: 8 additions & 0 deletions MiraAPI.Example/ExampleEventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static void Initialize()
{
// Register event handlers here
MiraEventManager.RegisterEventHandler<MiraButtonClickEvent<FreezeButton>>(FreezeButtonClickHandler, 1);
MiraEventManager.RegisterEventHandler<MiraButtonCancelledEvent<FreezeButton>>(FreezeButtonCancelledHandler);
}

// Example event handler
Expand All @@ -24,4 +25,11 @@ public static void FreezeButtonClickHandler(MiraButtonClickEvent<FreezeButton> @
@event.Button.SetTimer(15f);
}
}

// Example event handler
public static void FreezeButtonCancelledHandler(MiraButtonCancelledEvent<FreezeButton> @event)
{
Logger<ExamplePlugin>.Warning("Freeze button cancelled!");
@event.Button.OverrideName("Freeze Canceled");
}
}
16 changes: 0 additions & 16 deletions MiraAPI.Example/ExamplePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@ public partial class ExamplePlugin : BasePlugin, IMiraPlugin
public ConfigFile GetConfigFile() => Config;
public override void Load()
{
MiraEventManager.RegisterEventHandler<MiraButtonClickEvent<FreezeButton>>(e=>
{
Logger<ExamplePlugin>.Warning("Freeze button clicked!");

if (PlayerControl.LocalPlayer.Data.PlayerName == "stupid")
{
e.Cancel();
e.Button.SetTimer(15f);
}
});

MiraEventManager.RegisterEventHandler<MiraButtonCancelledEvent<FreezeButton>>(e=>
{
Logger<ExamplePlugin>.Warning("Freeze button cancelled!");
e.Button.OverrideName("Freeze Canceled");
});
Harmony.PatchAll();
}
}

0 comments on commit c1d2455

Please sign in to comment.