Skip to content

Commit

Permalink
Adds PlayerInventoryClick to InventoryDataRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
anjoismysign committed Jul 19, 2024
1 parent 00f14f3 commit b4aa6fe
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion local-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.698.28</version>
<version>1.698.29</version>
<relativePath>pom.xml</relativePath>
</parent>
<artifactId>bloblib</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.698.28</version>
<version>1.698.29</version>
<packaging>pom</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class InventoryDataRegistry<T extends InventoryButton> {
private final Map<String, Consumer<InventoryClickEvent>> singleClickEvents;
private final Map<String, BiConsumer<InventoryCloseEvent, SharableInventory<?>>> closeEvents;
private final Map<String, BiConsumer<InventoryClickEvent, T>> clickEvents;
private final Map<String, BiConsumer<InventoryClickEvent, SharableInventory<?>>> playerInventoryClickEvents;

/**
* Will instantiate a new InventoryDataRegistry with the specified default locale.
Expand All @@ -46,6 +47,7 @@ private InventoryDataRegistry(@NotNull String defaultLocale, @NotNull String key
this.singleClickEvents = new HashMap<>();
this.closeEvents = new HashMap<>();
this.clickEvents = new HashMap<>();
this.playerInventoryClickEvents = new HashMap<>();
}

/**
Expand Down Expand Up @@ -164,4 +166,28 @@ public void processCloseEvents(InventoryCloseEvent event, SharableInventory<?> i
closeEvent.accept(event, inventory);
});
}

/**
* Will set the click event whenever clicking on the player's inventory.
*
* @param key the key to add the click event for
* @param event the click event
*/
public void onPlayerInventoryClick(String key, BiConsumer<InventoryClickEvent, SharableInventory<?>> event) {
this.playerInventoryClickEvents.put(key, event);
}

/**
* Will process the click event whenever clicking on the player's inventory.
*
* @param event the click event
* @param inventory the inventory
*/
public void processPlayerInventoryClickEvent(InventoryClickEvent event, SharableInventory<?> inventory) {
playerInventoryClickEvents.values().forEach(playerInventoryClickEvent -> {
if (playerInventoryClickEvent == null)
return;
playerInventoryClickEvent.accept(event, inventory);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ private void onLocaleChange(PlayerLocaleChangeEvent event) {
this.tracker.put(result.getInventory().getInventory(), result);
}

@EventHandler
public void onPlayerInventoryClick(InventoryClickEvent event) {
Inventory clickedInventory = event.getClickedInventory();
if (clickedInventory == null)
return;
Inventory topInventory = event.getView().getTopInventory();
if (clickedInventory.equals(topInventory))
return;
InventoryTracker<?, ?> inventoryTracker = this.tracker.get(topInventory);
if (inventoryTracker == null)
return;
SharableInventory<?> sharableInventory = inventoryTracker.getInventory();
InventoryDataRegistry<?> registry = inventoryTracker.getRegistry();
registry.processPlayerInventoryClickEvent(event, sharableInventory);
}

@EventHandler
private void onClick(InventoryClickEvent event) {
Inventory clickedInventory = event.getClickedInventory();
Expand Down

0 comments on commit b4aa6fe

Please sign in to comment.