@Listener public void onInventoryClose(InteractInventoryEvent.Close event, @First Player player) { if ((event.getTargetInventory().equals(this.container))) { if (this.users.contains(player.getUniqueId())) { this.users.remove(player.getUniqueId()); if (this.users.isEmpty()) { em.removeListener(owner, this); // no user left to check } this.onClose.forEach(Runnable::run); } } }
public void submitInventory(Class owner, boolean openInventory) { this.owner = owner; em.registerListener(owner, this); if (openInventory) { for (UUID user : users) { Optional<Player> player = Sponge.getServer().getPlayer(user); if (player.isPresent()) { this.container = player .get() .openInventory(this.inventory, Cause.of(NamedCause.source(player))) .orElse(null); // TODO check if not opened } } } }