pmmp / PocketMine-MP

A server software for Minecraft: Bedrock Edition in PHP
https://pmmp.io
GNU Lesser General Public License v3.0
3.27k stars 1.55k forks source link

Not sending form after closing an inventory window #3741

Closed CaptainDuck closed 4 years ago

CaptainDuck commented 4 years ago

Issue description

Steps to reproduce the issue

  1. In a plugin, I tried closing a window first after listening to its SlotChangeAction before sending a modal form.
  2. The window was closed but the Modal Form wasn't sent.
  3. Additionally, I also tried the removeAllWindows(); function for the Player, but still it didn't work.

OS and versions

Plugins

Code to reproduce:


use jojoe77777\FormAPI\ModalForm;
use muqsit\invmenu\InvMenu;
use pocketmine\Player;
use pocketmine\item\Item;

$menu = InvMenu::create(InvMenu::TYPE_DOUBLE_CHEST);
            $menu->readonly();
            $menu->setListener(function (Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) {
                $form = new ModalForm(null);
                $form->setButton1("Yes");
                $form->setButton2("No");
                $player->removeWindow($action->getInventory());
                $player->sendForm($form);
            }
            );
            $menu->send($sender);
dktapps commented 4 years ago

This doesn't tell me how to reproduce the bug.

CaptainDuck commented 4 years ago

I just used a command for the code above

dktapps commented 4 years ago

This code doesn't run because it's incomplete.

CaptainDuck commented 4 years ago

The code is meant to be incomplete, I didn't want to add more code for the commands part. The menu was sent, I tried the code and the result was still the same. Do you need a video for demonstration?

dktapps commented 4 years ago

I'm not wasting my time trying to figure out what I need to do to your code in order to make it reproduce the bug. Either provide working code or don't bother.

CaptainDuck commented 4 years ago

Main.php:

<?php

namespace RemoveWindowBug;

use jojoe77777\FormAPI\ModalForm;
use muqsit\invmenu\InvMenu;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\inventory\transaction\action\SlotChangeAction;
use pocketmine\item\Item;
use pocketmine\Player;
use pocketmine\plugin\PluginBase;

class Main extends PluginBase
{

    public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool
    {
        if($sender instanceof Player && $command->getName() === "removetest"){
            $menu = InvMenu::create(InvMenu::TYPE_DOUBLE_CHEST);
            $menu->readonly();
            $menu->setListener(function (Player $player, Item $itemClicked, Item $itemClickedWith, SlotChangeAction $action) {
                $form = new ModalForm(null);
                $form->setButton1("Yes");
                $form->setButton2("No");
                $player->removeWindow($action->getInventory());
                $player->sendForm($form);
            }
            );
            $menu->send($sender);
        }
        return true;
    }

}

plugin.yml:

name: RemoveWindowBug
version: 1.0.0
api: 3.0.0
author: CaptainDuck
main: RemoveWindowBug\Main
commands:
  removetest:
    default: true
    description: Test the bug
eqMFqfFd commented 4 years ago

Hi @CaptainDuck . To accomplish this we:

  1. Use setInventoryCloseListener(), setListener() is for things like moving items in the inventory. Use it like this: setInventoryCloseListener(Player $player, InvMenuInventory $inventory).
  2. You do not have to remove the window $player->getInventory(). It also doesn't give you the opened inventory, and trying to remove it like that gives errors.

It will end like this:

<?php

namespace RemoveWindowBug;

use jojoe77777\FormAPI\ModalForm;
use muqsit\invmenu\InvMenu;
use muqsit\invmenu\inventory\InvMenuInventory;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\inventory\transaction\action\SlotChangeAction;
use pocketmine\item\Item;
use pocketmine\Player;
use pocketmine\plugin\PluginBase;

class Main extends PluginBase
{

    public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool
    {
        if($sender instanceof Player && $command->getName() === "removetest"){
            $menu = InvMenu::create(InvMenu::TYPE_DOUBLE_CHEST);
            $menu->readonly();
            $inventory = $menu->getInventory();
            $menu->setInventoryCloseListener(function (Player $player, InvMenuInventory $inventory){
                $form = new ModalForm(null);
                $form->setButton1("Yes");
                $form->setButton2("No");
                $player->removeWindow($action->getInventory());
                $player->sendForm($form);
            }
            );
            $menu->send($sender);
        }
        return true;
    }

}

You have my

DiscordKevin.#1234
I don't know why you never ask help. 👋

CaptainDuck commented 4 years ago

Thanks for trying to help but what I'm trying to do is that when a player does something with the inventory, it will close and a modal form will open.. this wasn't an issue before v1.16 and worked just as expected. 😞

dktapps commented 4 years ago

FWIW, I doubt this is a PM issue since nothing has changed regarding form handling. It's not likely there's any fix or solution to this.

CaptainDuck commented 4 years ago

Solved with InvMenu's v4.0.0 update, thank you for your time :)