Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive GUI inventories do not work for low-latency users #74

Closed
PixelzChris opened this issue Jun 4, 2020 · 39 comments
Closed

Recursive GUI inventories do not work for low-latency users #74

PixelzChris opened this issue Jun 4, 2020 · 39 comments
Labels
bug Something isn't working unconfirmed The issue cannot be reproduced with the provided information

Comments

@PixelzChris
Copy link

public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args): bool { if ($cmd->getName() == "test") { if ($sender instanceof Player) { $this->firstMenu($sender); } } return true; }

This calls...
`public function firstMenu(Player $player){
$this->menu= InvMenu::create(InvMenu::TYPE_CHEST);
$this->menu->readonly();
$this->menu->setName(C::BOLD . "Bruh Menu");

    $this->menu->setListener(function(Player $player, Item $itemTakenOut, Item $itemPuttingIn, SlotChangeAction $action) : void{
        if($itemTakenOut->getName() == C::BOLD . "test secondary menu"){
            $player->removeWindow($action->getInventory());
            $this->secondMenu($player);
            //$this->menu2->send($player);
        }
    });

    $this->menu->getInventory()->setContents([
        12 => Item::get(Item::DIAMOND, 0, 1)->setCustomName(C::BOLD . "test secondary menu"),
        26 => Item::get(Item::STAINED_GLASS, 14, 1)->setCustomName(C::BOLD . "Close the menu")
    ]);
    $this->menu->send($player);
}`

and it has to go on this once the diamond is clicked

`public function secondMenu(Player $player){
$this->menu2= InvMenu::create(InvMenu::TYPE_CHEST);
$this->menu2->readonly();
$this->menu2->setName("Second Menu");

    $this->menu2->getInventory()->setContents([
        13 => Item::get(Item::PAPER, 0, 1)->setCustomName("back"),
        26 => Item::get(Item::STAINED_GLASS, 14, 1)->setCustomName("Close the menu")
    ]);
    $this->menu2->send($player);
}`

So what happens is that diamond gets error
and if i try to add this:

$this->secondMenu($player);

The menu just close the nothing opens :/

I tried adding the code from your examples but it didnt work

Can you tell me how to open a GUI from a command and then once player clicks an item this windows closes and another one opens

@Muqsit
Copy link
Owner

Muqsit commented Jun 5, 2020

This code works fine for me

$menu = InvMenu::create(InvMenu::TYPE_CHEST);
$menu->readonly();
$menu->getInventory()->setContents([Item::get(Item::EMERALD)]);
$menu->setListener(function(Player $player, Item $out, Item $in, SlotChangeAction $action) use($menu) : void{
	if($out->getId() === Item::EMERALD){
		$menu2 = InvMenu::create(InvMenu::TYPE_CHEST);
		$menu2->readonly();
		$menu2->getInventory()->setContents([Item::get(Item::EMERALD)]);
		$menu2->setListener(function(Player $player, Item $out, Item $in, SlotChangeAction $action) use($menu) : void{
			if($out->getId() === Item::EMERALD){
				$menu->send($player);
			}
		});
		$menu2->send($player);
	}
});
$menu->send($sender);

@Muqsit Muqsit added the question Further information is requested label Jun 5, 2020
@PixelzChris
Copy link
Author

It works but not as expected..

I am trying to get a single chest as first menu and then a double chest as second menu

Basically i need to close the first one and open a new gui

example: https://youtu.be/bGvYAQW3XtI
this menu is created with korados api

@Muqsit
Copy link
Owner

Muqsit commented Jun 5, 2020

This is working fine as well, are you sure you're using the latest InvMenu build?

$menu = InvMenu::create(InvMenu::TYPE_CHEST);
$menu->readonly();
$menu->getInventory()->setContents([Item::get(Item::EMERALD)]);
$menu->setListener(function(Player $player, Item $out, Item $in, SlotChangeAction $action) use($menu) : void{
	if($out->getId() === Item::EMERALD){
		$menu2 = InvMenu::create(InvMenu::TYPE_DOUBLE_CHEST);
		$menu2->readonly();
		$menu2->getInventory()->setContents([Item::get(Item::EMERALD)]);
		$menu2->setListener(function(Player $player, Item $out, Item $in, SlotChangeAction $action) use($menu) : void{
			if($out->getId() === Item::EMERALD){
				$menu->send($player);
			}
		});
		$menu2->send($player);
	}
});
$menu->send($sender);

@Ifera
Copy link

Ifera commented Jun 5, 2020

Just to be sure.. have you registered the InvMenuHandler?

@PixelzChris
Copy link
Author

Just to be sure.. have you registered the InvMenuHandler?

Yes i registed InvMenuHandler

I can open guis but i cant close one and open another one (only single chest to single chest worked but the menu did not close and reopen it just change name of the menu and items)

I want from single chest to double chest though

@Muqsit
Copy link
Owner

Muqsit commented Jun 6, 2020

Your code works fine for me, you're probably using an old InvMenu build is all I can say.

@PixelzChris
Copy link
Author

PixelzChris commented Jun 6, 2020

Your code works fine for me, you're probably using an old InvMenu build is all I can say.

So what i did for that (yesterday).
I download the api i extracted it and i placed the folders in the the plugin after src folder
It didnt work.

Note that foreach of my gui plugins there is the folder after src on each plugin and the folder on the other plugins has an old version!

@PixelzChris
Copy link
Author

Your code works fine for me, you're probably using an old InvMenu build is all I can say.

Also i was testing it and sometimes it was working

there is something like a coinflip if it will work or not

(Note that i am win10 use)

@Muqsit
Copy link
Owner

Muqsit commented Jun 6, 2020

@PixelzChris
Copy link
Author

PixelzChris commented Jun 6, 2020

how do i do this "Inject the virion into your plugin phar by running bin/php7/bin/php path/to/InvMenu.phar path/to/yourplugin.phar"

Also after i remove the invmenu folder from the plugin all the invmenu lines has this error

@PixelzChris
Copy link
Author

Σχόλιο 2020-06-06 125258

@Muqsit
Copy link
Owner

Muqsit commented Jun 6, 2020

Run the

bin/php7/bin/php path/to/InvMenu.phar path/to/yourplugin.phar

command in your command line. Make sure you are in pocketmine's root directory (the directory containing bin folder, PocketMine-MP.phar and start.sh) while executing it.

The warning in your IDE means there are multiple InvMenu folders or phars in your project directory, so the IDE isn't sure from which InvMenu folder/phar to pick the class from.

@Muqsit
Copy link
Owner

Muqsit commented Jun 6, 2020

It looks like you are running your plugin from source. In that case you'd want to follow the Running InvMenu from .phar > In a development environment.
In a production environment is useful when you converted your plugin to phar and want to run your plugin from .phar.

@PixelzChris
Copy link
Author

So i did what In a development environment sayed todo but what hapenned is that Error: "Class 'muqsit\invmenu\InvMenuHandler' not found" on enable when it goes to register inv handler

Also i added on the server dev tools, test GUI and then i added the latest invmenu folder in the testGUI plugin and that worked. I am 100% sure that its the latest because the inventory was spawning behind the player which i see first time (nice idea)

Only that way worked for me... Also i am using server pro test server and bluestar host (in server pro only first menu opened and in bluestar was 50% chance to open the second menu) my local host doesnt show the server on mc so i cant test it there..

@PixelzChris
Copy link
Author

PixelzChris commented Jun 6, 2020

Btw both chests spawn but sometimes they disappear (spawn and instantly dissapear) thats the problem maybe a bigger delay??

@Muqsit
Copy link
Owner

Muqsit commented Jun 6, 2020

Delays are long gone, that used to be a bug in older versions. You probably should update InvMenu if you haven't updated it in the past month, some visual bugs were fixed.

@unickorn
Copy link

unickorn commented Jun 7, 2020

Not sure what I'm doing wrong, but the example code (literally copy pasted the one Muqsit sent above) doesn't work for me either. I'm using the latest build with DEVirion on pm 3.13.0 and the inventory just disappears after clicking on the emerald.

@Ifera
Copy link

Ifera commented Jun 7, 2020

Where is the virion located? I mean where have you put the virion? Also you can use VirionTools to inject a virion into a plugin.

@unickorn
Copy link

unickorn commented Jun 7, 2020

The virion is in the virions folder (as a phar), DEVirion.phar is in plugins. It seems to be loading fine too.
image

@Ifera
Copy link

Ifera commented Jun 7, 2020

Could be that some other plugin might be interfering with it. Try without any other plugins. And make sure the handler is registered.

@Muqsit
Copy link
Owner

Muqsit commented Jun 7, 2020

Also remove invmenu folder from the plugin if you haven't already

@PixelzChris
Copy link
Author

Also remove invmenu folder from the plugin if you haven't already

i dont think thats the problem... Like inventories work everything works with that way...
What happens is that you click the item to change window and then the single chest dissapears and the double chest spawns for 1 second and then dissapears as well

Maybe add a check if the chest has spawned then return false else spawn chest again

@Muqsit
Copy link
Owner

Muqsit commented Jun 8, 2020

i dont think thats the problem... Like inventories work everything works with that way...

Code doesn't care about your or anyone's theories. Practically testing is all that matters here.

This is starting to sound like a mess. You should NEVER run invmenu straight from source like the wiki states. The invmenu source folder in your plugin's source could be overriding classes of the invmenu phar in the virions folder, rendering your invmenu phar in virions folder completely unnecessary.

Again, DO. NOT. DOWNLOAD. THE. SOURCE. All you need is the InvMenu virion phar in the virions folder and have the DEVirion plugin enabled.

Maybe add a check if the chest has spawned then return false else spawn chest again

Maybe try removing the invmenu folder. Again, this isn't a bug with InvMenu. This is a you-bug.

@PixelzChris
Copy link
Author

i dont think thats the problem... Like inventories work everything works with that way...

Code doesn't care about your or anyone's theories. Practically testing is all that matters here.

This is starting to sound like a mess. You should NEVER download invmenu source like the wiki states. The invmenu source folder in your plugin's source could be overriding classes of the invmenu phar in the virions folder, rendering your invmenu phar in virions folder completely unnecessary.

Again, DO. NOT. DOWNLOAD. THE. SOURCE. All you need is the InvMenu virion phar in the virions folder and have the DEVirion plugin enabled.

Maybe add a check if the chest has spawned then return false else spawn chest again

Maybe try removing the invmenu folder. Again, this isn't a bug with InvMenu. This is a you-bug.

Okay and i will have to use devirion every time i want to add the plugin somewhere or how that works?

@Muqsit
Copy link
Owner

Muqsit commented Jun 8, 2020

Okay and i will have to use devirion every time i want to add the plugin somewhere or how that works?

If the plugin that is using invmenu is running from source, you need the devirion plugin and the InvMenu virion phar in your virions folder.

If the plugin that is using invmenu is in phar format, inject the virion into your plugin.phar by executing this from the command line:

bin/php7/bin/php virions/InvMenu.phar path/to/your/plugin.phar

@Ifera
Copy link

Ifera commented Jun 8, 2020

Okay and i will have to use devirion every time i want to add the plugin somewhere or how that works?

You will be using DEViriron regardless of virion being in .phar form or folder. The virion should always be present in the virions folder and not anywhere else unless its shaded. But, like Muqsit said, its sounding more like a you-problem and not a problem with the plugin. Anyways remove the virion from everywhere except the virions folder.

Secondly you can use what Muqsit suggested for injecting the virion into your plugin or you can use the VirionTools plugin to do the same.

@Muqsit
Copy link
Owner

Muqsit commented Jun 8, 2020

Btw, if you are publishing the plugin on poggit, poggit can take care of injecting virions in the plugin.
.poggit.yml:

projects:
    libs:
      - src: muqsit/InvMenu/InvMenu
        version: ^3.1.0

@Muqsit
Copy link
Owner

Muqsit commented Jun 8, 2020

If you're on discord, join the pmmp discord server https://discord.gg/XDugAkJ, we can communicate faster there.

@Muqsit Muqsit removed the question Further information is requested label Jun 9, 2020
@Muqsit Muqsit added bug Something isn't working unconfirmed The issue cannot be reproduced with the provided information labels Jun 9, 2020
@Muqsit
Copy link
Owner

Muqsit commented Jun 9, 2020

According to the conversation on discord, this seems like a certain case with locally hosted servers. Not sure whether it is the lack of latency between packets because I have never tested InvMenu on a server with less than 150ms latency and neither have I ever experienced this bug ever since the NetworkStackLatencyPacket handling.

@unickorn
Copy link

Can confirm after a test on a non-local server, a friend with >150ms ping could open menus and I could not with <100.

@Muqsit Muqsit changed the title Recursive GUI inventories Recursive GUI inventories do not work for low-latency users Jun 10, 2020
@PixelzChris
Copy link
Author

Can you fix this though :/

@Itzdvbravo
Copy link

Itzdvbravo commented Jul 21, 2020

So i had an issue like that where when clicking on an item opens another window, however the second window doesn't open, the first window closes, this was all done in my local server hence low-latency, the way i fixed is, adding an delay, i don't know the exact but i tried with 2 tick, 5 tick, it didn't work, so i did 20 ticks, and it worked.
Not sure why but if there's delay between closing the first menu and sending the second menu, it'll fix it. Build 106

@Muqsit
Copy link
Owner

Muqsit commented Jul 21, 2020

@Itzdvbravo The delay-by-ticks mechanism works most of the time only for low latency. This usually isn't the case in production servers, hence destructive.
Recursive inventories require some special handling especially since v1.16. I'm thinking of ditching the bool return value for listeners and replacing it with something that can manually handle such cases. Possibly:

$menu->setListener(function(...) : InvMenuResult{
	if($item->getId() === ItemIds::APPLE){
		return InvMenuResult::REDIRECT($second_menu);
	}
	return InvMenuResult::CANCEL();
});

@Itzdvbravo
Copy link

Itzdvbravo commented Jul 21, 2020

Ah i see, ye prolly, also it's not only for low-latency, it'll work for high-latency players as well but ye it's destructive

@Muqsit
Copy link
Owner

Muqsit commented Jul 21, 2020

The delay-by-ticks mechanism works most of the time only for low latency

I mean as in, the higher your latency, the higher is the chance of it not working.

@Muqsit
Copy link
Owner

Muqsit commented Sep 16, 2020

I can't think of a proper solution for this. I'm thinking of replacing $network->wait($then) with $network->waitUntil(100, $then) which waits at least 100ms.
https://github.com/Muqsit/InvMenu/blob/master/src/muqsit/invmenu/session/PlayerSession.php#L105
If anyone has a better solution, let me know.

@Muqsit
Copy link
Owner

Muqsit commented Oct 5, 2020

Can someone test this plugin? Use /imtest and click an item in the inventory that shows up.

(The .zip file contains a .phar)
IMTest_v0.0.1.zip

@unickorn
Copy link

unickorn commented Oct 5, 2020

Seems to be working on my local pm3 test server. (With the addition of InvCrashFix)

@Shock95
Copy link

Shock95 commented Oct 5, 2020

Seems to be working on my local server too 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed The issue cannot be reproduced with the provided information
Projects
None yet
Development

No branches or pull requests

6 participants