Skip to content

Commit

Permalink
Merge pull request #46 from mcmonkey4eva/master
Browse files Browse the repository at this point in the history
Patch issues with inventory trait relating to "/npc inventory"
  • Loading branch information
fullwall committed Mar 14, 2019
2 parents abf7ba0 + ccb076e commit 81385f4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/java/net/citizensnpcs/api/trait/trait/Inventory.java
Expand Up @@ -42,7 +42,7 @@ public Inventory() {
* @return ItemStack array of an NPC's inventory contents
*/
public ItemStack[] getContents() {
if (view != null) {
if (view != null && !views.isEmpty()) {
return view.getContents();
}
return contents;
Expand All @@ -58,7 +58,7 @@ public void inventoryCloseEvent(InventoryCloseEvent event) {
return;
ItemStack[] contents = event.getInventory().getContents();
for (int i = 0; i < contents.length; i++) {
this.contents[i] = contents[i];
this.contents[i] = contents[i];
if (i == 0) {
npc.getTrait(Equipment.class).setItemInHand(contents[i]);
}
Expand Down Expand Up @@ -148,15 +148,15 @@ public void save(DataKey key) {
}

private void saveContents(Entity entity) {
if (view != null && !views.isEmpty()) {
contents = view.getContents();
}
else if (entity instanceof InventoryHolder) {
contents = ((InventoryHolder) entity).getInventory().getContents();
}
if (entity instanceof Player) {
contents = ((Player) entity).getInventory().getContents();
npc.getTrait(Equipment.class).setItemInHand(contents[0]);
}
if (view != null) {
for (int i = 0; i < view.getSize(); i++) {
view.setItem(i, contents[i]);
}
}
}

/**
Expand Down

0 comments on commit 81385f4

Please sign in to comment.