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

Simulating Inventory Events #247

Open
ItsLiyua opened this issue Sep 3, 2021 · 5 comments
Open

Simulating Inventory Events #247

ItsLiyua opened this issue Sep 3, 2021 · 5 comments
Labels
enhancement Issue describes an improvement or new feature to MockBukkit

Comments

@ItsLiyua
Copy link

ItsLiyua commented Sep 3, 2021

Hi yall!

I try to make an API, that simplifies the way you create inventory menus.
I want to test it and have simulate clicks, closes and drags in the inventory.
How do I do that?

Kind regards,
Trqhxrd

@seeseemelk
Copy link
Member

We currently do not have support for this yet, although this kind of functionality is perfectly within the scope of MockBukkit.
I'm leaving this open so that it can be closed once this functionality has been added.

@ItsLiyua
Copy link
Author

ItsLiyua commented Dec 1, 2021

Thanks for commenting even after three months! I would really like to see that functionality since I was and still am developing an inventory API.

@0ddlyoko
Copy link
Contributor

Hello @Trqhxrd
It's possible to simulate clicks on an inventory with Mockito, I've already done that for an api that creates inventories:

  • To simulate clicks, you have to use the InventoryClickEvent event.
    • For the first parameter (which is an InventoryView), you can create it (new InventoryView() {...}) while overriding getTopInventory(), getBottomInventory(), getPlayer(), getType() and getTitle(). getBottomInventory() is the player's inventory (player.getInventory()). Don't forget to change player.openInventory(bukkitInventory): when(player.openInventory(bukkitInventory)).thenReturn(inventoryView)
    • PlayerInventory: You can create it using Mockito and change player.getInventory() (Example: when(player.getInventory()).thenReturn(playerInventory);). You also have to change playerInventory.getSize() (Example: when(playerInventory.getSize()).thenReturn(PLAYER_INVENTORY_SIZE);).
    • Close: Don't forget to call the close method once the inventory is closed. You can use something like
doAnswer(invocation -> {
    InventoryCloseEvent event = new InventoryCloseEvent(inventoryView);
    // TODO Call the Bukkit event or a custom method of your inventory class
    return null;
}).when(player).closeInventory();

@Insprill Insprill added the enhancement Issue describes an improvement or new feature to MockBukkit label May 30, 2022
@thelooter
Copy link
Contributor

Is this still open? Or can we close this

@Insprill
Copy link
Contributor

We only have one of the suggested methods, and there are a lot more inventory simulations that can be added so I'd keep it open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issue describes an improvement or new feature to MockBukkit
Projects
None yet
Development

No branches or pull requests

5 participants