Skip to content

Releases: presentkim-pm/session-utils

v1.1.0

21 Mar 13:05

Choose a tag to compare

What's new

SessionSequence — ordered session progression

Multi-step flows like tutorials can now be expressed as a sequence of SequenceSession subclasses.
Each step calls next() to advance, and an onComplete callback fires when the last step finishes.

$sequence = new SessionSequence($plugin,
    TutorialStep1Session::class,
    TutorialStep2Session::class,
    TutorialStep3Session::class,
);

$sequence->onComplete(fn(Player $p) => $p->sendMessage("Tutorial complete!"));

// Start from the beginning, or resume from a saved step
$sequence->start($player);
$sequence->startFrom($player, $savedStep); // int index or class-string

Session self-termination

The Session interface and AbstractSession have been merged into a single Session abstract class
that holds the SessionManager reference directly. Sessions can now terminate themselves with a single call.

// Inside any Session subclass
$this->terminate(SessionTerminateReasons::COMPLETED);

New SessionManager conveniences

// Throw if no session exists
$manager->getSessionOrThrow($player);

// Create if none exists
$manager->getOrCreateSession($player);

// React to session lifecycle from outside the session class
$manager
    ->onSessionCreated(fn(MySession $s) => $this->log("created"))
    ->onSessionTerminated(fn(MySession $s, string $reason) => $this->save($s));

Reduced PMMP listener registrations

PlayerJoinEvent and PlayerQuitEvent are now routed through SessionEventListenerRegistry,
so only one PMMP listener is registered per event regardless of how many SessionManager instances exist.

Bug fixes

  • Fixed a re-entry issue in SessionManager::removeSession() where Session::terminate() calling back
    into removeSession() could cause a double-removal. Sessions are now removed from the internal map
    before terminate() is invoked.

Breaking changes

  • Session interface and AbstractSession have been replaced by the Session abstract class.
    Subclasses must extend Session directly instead of AbstractSession.
  • SessionEventDispatcher has been renamed to BaseSessionEventDispatcher and is now abstract.
    The concrete implementation is SessionMethodDispatcher.
  • File paths under listener/ have changed — SessionEventDispatcher.php is removed and replaced by
    dispatcher/BaseSessionEventDispatcher.php, dispatcher/SessionMethodDispatcher.php, and
    dispatcher/ManagerMethodDispatcher.php.

Full changelog

[1.0.0 → 1.1.0](v1.0.0...v1.1.0)