mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2024-11-15 10:55:20 +01:00
Add new addItem methods
This commit is contained in:
parent
b52f43ce13
commit
02e1b478a5
4
pom.xml
4
pom.xml
@ -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>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user