Skip to content

Commit

Permalink
Cleaner solution to the issue mentioned in #3.
Browse files Browse the repository at this point in the history
  • Loading branch information
ToberoCat committed Aug 10, 2023
1 parent 78bd049 commit 4835fce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public void clickedComponent(@NotNull InventoryClickEvent event) {
if (null == context || null == api) return;

FunctionProcessor.callFunctions(clickFunctions, api, context);
context.render();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,16 @@ public void add(@NotNull GuiEngineApi api, @NotNull XmlComponent @NotNull ... co
@Override
public void clickedComponent(@NotNull InventoryClickEvent event) {
interpreter().clickedComponent(event);
componentsDescending().filter(x -> x.isInComponent(event.getSlot())).filter(x -> !x.hidden()).findFirst().ifPresentOrElse(component -> {
Bukkit.getPluginManager().callEvent(new GuiComponentClickEvent(this, event, component));
component.clickedComponent(event);
}, () -> Bukkit.getPluginManager().callEvent(new GuiComponentClickEvent(this, event, null)));
componentsDescending()
.filter(x -> x.isInComponent(event.getSlot()))
.filter(x -> !x.hidden())
.findFirst()
.ifPresentOrElse(component -> {
Bukkit.getPluginManager().callEvent(new GuiComponentClickEvent(this, event, component));
component.clickedComponent(event);
}, () -> Bukkit.getPluginManager().callEvent(
new GuiComponentClickEvent(this, event, null)));
render();
}

/**
Expand All @@ -198,6 +204,7 @@ public void draggedComponent(@NotNull InventoryDragEvent event) {
Bukkit.getPluginManager().callEvent(new GuiComponentDragEvent(this, event, null));
interpreter().draggedComponent(event);
});
render();
}

/**
Expand Down

0 comments on commit 4835fce

Please sign in to comment.