[SPIGOT-2527] Ability to differentiate between inventory sections. Created: 15/Jul/16  Updated: 14/Apr/19  Resolved: 14/Apr/19

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: PixelPerfect Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: InventoryType, inventory
Environment:

*


Plugin: *

 Description   

Example:
A player has a chest open. A plugin needs to know whether the player clicks an item in their inventory or on the chest. Both items are in their equivalent inventory's slot 0. Currently there is no way, unless you know for absolutely certain that the two items are different or what they both are, to know which inventory the event occurred in. InventoryType will yield CHEST for both areas and the slot is identically numbered in both areas.

This could be resolved through the introduction of a new API that itself reports which section of the inventory (For the example above, CombinedInventorySection.PLAYER would be an easily checked solution for problems like the example above).



 Comments   
Comment by md_5 [ 14/Apr/19 ]

InventoryView.getInventory
InventoryClickEvent.getClickedInventory

Comment by PixelPerfect [ 16/Jul/16 ]

Good point, an alternative may be a couple enums to the earlier mentioned InventoryView and have it return that, then there could be 'OUTSIDE' 'REMOTE' 'LOCAL'.

Comment by Black Hole [ 16/Jul/16 ]

I think you'll need both methods since the slot number could be outside of both inventories.

Comment by PixelPerfect [ 16/Jul/16 ]

That would be an ideal way of doing it. Could even just be one method named something like isRemoteInventoryView(int remoteSlots, int rawSlot)

Comment by Black Hole [ 16/Jul/16 ]

So new methods InventoryView.isTopInventory(int rawSlot) and InventoryView.isBottomInventory(int rawSlot) could be useful.

Comment by BillyGalbreath [ 16/Jul/16 ]

Get the rawslot number and compare it to the inventory size. Thats how you know which side of the inventory was clicked.

http://paste.md-5.net/yibohakiwi.coffee

Comment by Hex [ 16/Jul/16 ]

Re-opened as per reporter's request. Apparently the inventory view reported isn't actually helpful in this way.

Comment by PixelPerfect [ 16/Jul/16 ]

InventoryView.OUTSIDE may be the solution, hard to tell what it does seeing as it has next to no documentation. Other than that, that leads back into InventoryType which is horribly broken and cannot be updated to keep the API backwards-compatible.

EDIT: Following checking the source, I can confirm that OUTSIDE only defines -999 which is a reference to literally clicking outside of the inventory slots.

Comment by Black Hole [ 15/Jul/16 ]

It's already there:
Use InventoryEvent.getView()

Generated at Tue Apr 22 04:30:16 UTC 2025 using Jira 10.3.5#10030005-sha1:190c783f2bd6c69cd5accdb70f97e48812a78d14.