Skip to content

Commit

Permalink
Added closing check for inventories and menu sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
JVerbruggen committed Jun 23, 2024
1 parent 9dfc826 commit ef8d072
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ private void onItemTowardsMenu(InventoryInteractEvent event, Inventory destinati
@EventHandler
public void onClose(InventoryCloseEvent event){
Player player = playerManager.getPlayer((org.bukkit.entity.Player) event.getPlayer());
menuSessionManager.removeOpenMenu(player);
Menu menu = menuSessionManager.getOpenMenu(player);

if(menu.matchesInventory(event.getView())){
menuSessionManager.removeOpenMenu(player);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.jverbruggen.jrides.api.JRidesPlayer;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -60,6 +61,11 @@ public Inventory getInventoryFor(JRidesPlayer player){
return inventory;
}

@Override
public boolean matchesInventory(InventoryView inventoryView) {
return inventoryView.getTitle().equalsIgnoreCase(inventoryTitle);
}

@Override
public Menu addButton(MenuButton button) {
buttons.put(button.getUuid(), button);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/jverbruggen/jrides/models/menu/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.jverbruggen.jrides.api.JRidesPlayer;
import com.jverbruggen.jrides.models.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;

import java.util.Map;
import java.util.UUID;
Expand All @@ -30,6 +31,7 @@ public interface Menu {
void removeSession(JRidesPlayer player);

Inventory getInventoryFor(JRidesPlayer player);
boolean matchesInventory(InventoryView inventoryView);
Menu addButton(MenuButton button);
MenuButton getButton(UUID buttonUUID);
void sendUpdate();
Expand Down

0 comments on commit ef8d072

Please sign in to comment.