Skip to content

Introduce GuiClickEvent and getItem(Slot slot)#2513

Open
mastrangelolorenzo wants to merge 4 commits into
stefvanschie:masterfrom
mastrangelolorenzo:master
Open

Introduce GuiClickEvent and getItem(Slot slot)#2513
mastrangelolorenzo wants to merge 4 commits into
stefvanschie:masterfrom
mastrangelolorenzo:master

Conversation

@mastrangelolorenzo
Copy link
Copy Markdown

Wrap InventoryClickEvent in GuiClickEvent for pane-level click handlers

Introduce GuiClickEvent, which wraps a Bukkit InventoryClickEvent together
with a pane-relative Slot, so click consumers always receive the slot
position expressed relative to the pane's top-left corner rather than the
raw inventory index.

GuiItem.action and Pane.onClick are now Consumer<? super GuiClickEvent>.
All pane click() implementations construct a GuiClickEvent(event, slot)
before forwarding to callOnClick/callAction. XML-loaded handlers that still
declare an InventoryClickEvent parameter continue to work via an automatic
unwrapping wrapper. Gui-level consumers (onTopClick, onBottomClick, etc.)
are unaffected as they have no pane-relative context.

@mastrangelolorenzo
Copy link
Copy Markdown
Author

1 year and half later 🔥

Copy link
Copy Markdown
Owner

@stefvanschie stefvanschie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your pull request. I think the idea of your pull request is good. I have also been growing discontent with the usage of InventoryClickEvent myself and putting that behind a different type which contains more IF-oriented data seems like a good (first) step.

In my opinion, you could even expand this to click event on guis and gui components, although the absence of this would not be a blocker for this PR.

The main issue, besides the changes I addressed below, is that this is a breaking change, so this cannot be added to the next version, but needs to wait for a version with breaking changes.

Comment thread IF/src/main/java/com/github/stefvanschie/inventoryframework/gui/GuiItem.java Outdated
Comment thread IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/Pane.java Outdated
@mastrangelolorenzo
Copy link
Copy Markdown
Author

Hi, I've decided to remove InventoryClickEvent completely and use just GuiClickEvent since this is already a breaking change, and using only GuiClickEvent is more consistent.
I'll push this ASAP.

Allow XML-defined handlers to receive GuiClickEvent

- onClick handlers in XML now take GuiClickEvent instead of InventoryClickEvent
- Removed wrapper that was unwrapping to InventoryClickEvent
- XMLUtil.loadOnEventAttribute() now accepts any type, not just Bukkit Events

Breaking change: update handler signatures from (InventoryClickEvent) to (GuiClickEvent)
Copy link
Copy Markdown
Owner

@stefvanschie stefvanschie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving everything to GuiClickEvent is fine. Please review the comment I made, then as far as I'm concerned this can go in the next breaking version.

Comment thread .github/workflows/maven.yml Outdated
@mastrangelolorenzo
Copy link
Copy Markdown
Author

mastrangelolorenzo commented May 19, 2026

Moving everything to GuiClickEvent is fine. Please review the comment I made, then as far as I'm concerned this can go in the next breaking version.

Should be done.

Fixing the CI Issue right now.

@mastrangelolorenzo
Copy link
Copy Markdown
Author

I've been using IF for a while, so i know some things that i don't like abt it, and since this is already a breaking change, i will prolly push some other thing on these days.

- PaginatedPane.getPanes(int): validate 'page' argument instead of 'this.page'
  - GuiItem.loadItem(): assign parsed damage value to 'damage', not 'amount'; drop unused 'hasDamage' variable
  - OutlinePane.display(): use getLength() for vertical orientation size, cache getItems() to avoid repeated list allocation per render iteration
  - MasonryPane.click(): guard against null cachedPositions when click is dispatched before first display
  - GuiItemContainer.setItem(): store item reference directly after applyUUID instead of deep-copying on every render
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants