Skip to content

Commit

Permalink
Try to put items into inventory instead of dropping them all directly
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgH93 committed Jan 26, 2020
1 parent ceeb84a commit 54f69b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>Minepacks</artifactId>
<version>2.1.4-SNAPSHOT</version>
<version>2.1.5</version>

<scm>
<connection>scm:git:git@github.com:GeorgH93/Minepacks.git</connection>
Expand Down
13 changes: 11 additions & 2 deletions src/at/pcgamingfreaks/Minepacks/Bukkit/Backpack.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Backpack(OfflinePlayer owner, int size, int ID)
ownerID = ID;
}

public Backpack(OfflinePlayer owner, ItemStack[] backpack, int ID)
public Backpack(final OfflinePlayer owner, ItemStack[] backpack, final int ID)
{
this(owner, backpack.length, ID);
if(MCVersion.isNewerOrEqualThan(MCVersion.MC_1_14) && backpack.length > 54)
Expand All @@ -126,7 +126,16 @@ public Backpack(OfflinePlayer owner, ItemStack[] backpack, int ID)
Minepacks.getInstance().getLogger().warning(owner.getName() + "'s backpack has to many items.");
if(owner.isOnline())
{
Bukkit.getScheduler().runTask(Minepacks.getInstance(), () -> toMuch.forEach(stack -> owner.getPlayer().getWorld().dropItemNaturally(owner.getPlayer().getLocation(), stack)));
Bukkit.getScheduler().runTask(Minepacks.getInstance(), () -> {
if(owner.isOnline())
{
Player player = owner.getPlayer();
assert player != null;
Map<Integer, ItemStack> left = player.getInventory().addItem(toMuch.toArray(new ItemStack[0]));
left.forEach((id, stack) -> player.getWorld().dropItemNaturally(player.getLocation(), stack));
this.setChanged();
}
});
}
else throw new RuntimeException("Backpack to big for MC 1.14 and up!");
}
Expand Down

0 comments on commit 54f69b4

Please sign in to comment.