Skip to content

Commit 42316d9

Browse files
committed
Fix #35 and #36
1 parent d01719c commit 42316d9

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/main/java/fr/minuskube/inv/SmartInventory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ public Inventory open(Player player, int page) {
4545
this.manager.setInventory(player, null);
4646
});
4747

48-
InventoryContents contents = new InventoryContents.Impl(this);
48+
InventoryContents contents = new InventoryContents.Impl(this, player);
4949
contents.pagination().page(page);
5050

5151
this.manager.setContents(player, contents);
52-
provider.init(player, contents);
52+
this.provider.init(player, contents);
5353

5454
InventoryOpener opener = this.manager.findOpener(type)
5555
.orElseThrow(() -> new IllegalStateException("No opener found for the inventory type " + type.name()));

src/main/java/fr/minuskube/inv/content/InventoryContents.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package fr.minuskube.inv.content;
22

33
import fr.minuskube.inv.ClickableItem;
4-
import fr.minuskube.inv.InventoryManager;
54
import fr.minuskube.inv.SmartInventory;
5+
import org.bukkit.entity.Player;
66
import org.bukkit.inventory.Inventory;
77
import org.bukkit.inventory.ItemStack;
88

@@ -52,14 +52,17 @@ InventoryContents fillRect(int fromRow, int fromColumn,
5252
class Impl implements InventoryContents {
5353

5454
private SmartInventory inv;
55+
private Player player;
56+
5557
private ClickableItem[][] contents;
5658

5759
private Pagination pagination = new Pagination.Impl();
5860
private Map<String, SlotIterator> iterators = new HashMap<>();
5961
private Map<String, Object> properties = new HashMap<>();
6062

61-
public Impl(SmartInventory inv) {
63+
public Impl(SmartInventory inv, Player player) {
6264
this.inv = inv;
65+
this.player = player;
6366
this.contents = new ClickableItem[inv.getRows()][inv.getColumns()];
6467
}
6568

@@ -231,13 +234,10 @@ public InventoryContents setProperty(String name, Object value) {
231234
}
232235

233236
private void update(int row, int column, ItemStack item) {
234-
InventoryManager manager = inv.getManager();
237+
Inventory topInventory = player.getOpenInventory().getTopInventory();
235238

236-
manager.getOpenedPlayers(inv)
237-
.forEach(player -> {
238-
Inventory topInventory = player.getOpenInventory().getTopInventory();
239-
topInventory.setItem(inv.getColumns() * row + column, item);
240-
});
239+
if(topInventory != null)
240+
topInventory.setItem(inv.getColumns() * row + column, item);
241241
}
242242

243243
}

0 commit comments

Comments
 (0)