Skip to content

Commit

Permalink
feat: simplify the registration of event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Mar 23, 2024
1 parent 40bcd26 commit 4b2cb56
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions include/example_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ class ExamplePlugin : public endstone::Plugin {
}

// You can register an event handler directly in the Plugin class.
registerEventHandler<endstone::ServerLoadEvent>(&ExamplePlugin::onServerLoad, *this);
registerEvent(&ExamplePlugin::onServerLoad, *this);

// You can also create a separate class (e.g. ExampleListener) and register the event handler from that class.
listener_ = std::make_unique<ExampleListener>(*this);
registerEventHandler<endstone::ServerLoadEvent>(&ExampleListener::onServerLoad, *listener_,
endstone::EventPriority::HIGH);
registerEvent(&ExampleListener::onServerLoad, *listener_, endstone::EventPriority::High);
}

void onDisable() override
Expand Down Expand Up @@ -60,7 +59,7 @@ class ExamplePlugin : public endstone::Plugin {

void onServerLoad(endstone::ServerLoadEvent &event)
{
getLogger().info("ServerLoadEvent is passed to ExamplePlugin::onServerLoad");
getLogger().info("{} is passed to ExamplePlugin::onServerLoad", event.getEventName());
}

private:
Expand Down

0 comments on commit 4b2cb56

Please sign in to comment.