Add new addItem methods

This commit is contained in:
GeorgH93 2019-11-21 16:55:02 +01:00
parent b52f43ce13
commit 02e1b478a5
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
2 changed files with 26 additions and 2 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>Minepacks-API</artifactId>
<version>2.0.11</version>
<version>2.1-ALPHA-SNAPSHOTS</version>
<scm>
<connection>scm:git:git@github.com:GeorgH93/Minepacks.git</connection>
@ -68,7 +68,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.8</version>
<configuration>
<source>1.8</source>
<target>1.8</target>

View File

@ -21,9 +21,13 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
@SuppressWarnings("unused")
public interface Backpack extends InventoryHolder
{
/**
@ -101,4 +105,24 @@ public interface Backpack extends InventoryHolder
* @param location The location the content of the backpack should be dropped to.
*/
void drop(Location location);
/**
* @param stack The item stack that should be added to the backpack.
* @return null if the entire item stack has been added. An item stack containing the items that did not fit into the backpack.
*/
default @Nullable ItemStack addItem(ItemStack stack)
{
Map<Integer, ItemStack> left = addItems(stack);
if(left.isEmpty()) return null;
return left.get(0);
}
/**
* @param itemStacks The item that should be added to the backpack.
* @return A HashMap containing items that didn't fit. The key is the number of the added item
*/
default @NotNull Map<Integer, ItemStack> addItems(ItemStack... itemStacks)
{
return getInventory().addItem(itemStacks);
}
}