Cosmoverse / NpcDialogue

A PocketMine-MP library for making NPC dialogues
https://poggit.pmmp.io/ci/Cosmoverse/NpcDialogue
GNU General Public License v3.0
18 stars 2 forks source link

Dialogue is considered closed upon its creation #1

Open Yexeed opened 2 weeks ago

Yexeed commented 2 weeks ago

Upon sending a dialogue to the player, it's getting status "closed" with closeListener activating. Sample code:

public function onShift(PlayerToggleSneakEvent $e): void{
    $player = $e->getPlayer();
    NpcDialogueManager::send($player, (NpcDialogueBuilder::create())
        ->setText("TEXT")
        ->setName("NAME")
        ->setCloseListener(function(Player $player): void{
            var_dump("closed");
        })
        ->setResponseListener(function(Player $player, int $btn): void{
            var_dump("reponded with $btn");
        })
        ->build()
    );
}

Result:

  1. when I opened it, the “closed” line was dumped, but I did not close the dialogue.
  2. When i've really closed the dialogue, no line was dumped, making me unable to receive data if player really closed the dialogue.

Video: https://imgur.com/a/UTiEMTU

Versions:

This server is running PocketMine-MP
Server version: 5.16.0 (git hash: 22a1549998ef0e4668ed48838900ad84258fe04a)
Compatible Minecraft version: 1.21.0 (protocol version: 685)
PHP version: 8.3.4
PHP JIT: not supported
Operating system: win

NpcDialogue v0.1.1 (from releases)

VaizHD commented 2 weeks ago

Hi ! just add a third argument (true) to the method NpcDialogueManager::send($player,$dialogue,true) ,

Yexeed commented 2 weeks ago

Doesn't help at all, my guy! Sample code:

$builder->setCloseListener(function(Player $player): void{
    $player->sendMessage("closed");
});
$builder->setResponseListener(function(Player $player, int $btn): void{
    $player->sendMessage("Pressed $btn");
});
NpcDialogueManager::send($player, $builder->build(), true);

Result: https://imgur.com/a/kVJ5rVW Pressing on the "X" button is sent by client, BUT however it doesn't gets handled, as far as I can see it, the dialogue should be a NullNpcDialogue instance, however it is not. https://github.com/Cosmoverse/NpcDialogue/blob/master/src/cosmicpe/npcdialogue/player/PlayerInstance.php#L142

Also, pressing on any response button makes dialogue stuck on the player's screen, and you can't close it nor press the button again, as I've shown on video.

Muqsit commented 2 weeks ago
  1. when I opened it, the “closed” line was dumped, but I did not close the dialogue.

I suspect this is due to the event being triggered on-sneak-start and on-sneak-end, causing dialogue to be sent twice. Does the issue persist when you account for $e->isSneaking()?

public function onShift(PlayerToggleSneakEvent $e): void{
+   if(!$e->isSneaking()) return; // player released shift key - ignore
    ...
}
Yexeed commented 2 weeks ago

If only it was the problem :(. My real usage-case is to open dialogue when clicking a form button. It happens once, at any time. For whatever reason, pressing on npc response button doesn't close a dialogue and makes player screen to be stuck with dialogue, can't close or press a response button.

Just a sec ago, I've tried to explicitly close a dialogue, and it worked. Here's sample code. I am just wondering why it isn't specified in docs.

$builder->addSimpleButton("TEXT", function(Player $player) use ($applyFunction): void{
    $applyFunction($player);
    NpcDialogueManager::remove($player);
});

A bug which is still apparent is $onClose callable doesn't gets called when player clicks "X" button. Here's debug output, it looks like to me that dialogue should be a NullNpcDialogue (which it is not), and close packets aren't getting handled correctly.

[15:36:12.689] [Server thread/INFO]: [CommandSaver] [15:36:12] Yexeed: cape
[15:36:13.349] [Server thread/INFO]: [SimpleDuels] TopHologram closed
string(16) "OPENING SHOWCASE"
string(16) "SENDING DIALOGUE"
[15:36:13.509] [Server thread/DEBUG]: [SkinCapes] [Yexeed] Attempting to send dialogue
string(69) "PacketReceived: NpcRequestPacket, type: RequestExecuteOpeningCommands"
string(39) "we got the dialogue status 1 (RECEIVED)"
[15:36:13.602] [Server thread/DEBUG]: [NetworkSession: Yexeed] Unhandled NpcRequestPacket: YhQGAAACMjA=
string(69) "PacketReceived: NpcRequestPacket, type: RequestExecuteClosingCommands"
string(33) "PlayerInstance: onDialogueClose()"
string(39) "$this->current_dialogue !== null ? true"
string(73) "$this->current_dialogue->dialogue === NullNpcDialogue::instance() ? false"
[15:36:14.754] [Server thread/DEBUG]: [NetworkSession: Yexeed] Unhandled NpcRequestPacket: YhQCAAACMjA=

I just can't find the trace from where closeListener get's called. Even if onDialogueClose() works correctly, it still won't call closeListener