diff --git a/pom.xml b/pom.xml index 46c8ba3..49554d6 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ ultrabackpacks-api UltraBackpacks API jar - 1.1.3 + 1.2.0 UltraBackpacksAPI-${project.version} diff --git a/src/main/java/dev/drawethree/ultrabackpacks/api/UltraBackpacksAPI.java b/src/main/java/dev/drawethree/ultrabackpacks/api/UltraBackpacksAPI.java index 1756d3b..ab98561 100644 --- a/src/main/java/dev/drawethree/ultrabackpacks/api/UltraBackpacksAPI.java +++ b/src/main/java/dev/drawethree/ultrabackpacks/api/UltraBackpacksAPI.java @@ -1,5 +1,6 @@ package dev.drawethree.ultrabackpacks.api; +import dev.drawethree.ultrabackpacks.api.exception.BackpackNotFoundException; import dev.drawethree.ultrabackpacks.api.model.backpack.IBackpackData; import dev.drawethree.ultrabackpacks.api.service.BackendAPI; import org.bukkit.block.Block; @@ -7,7 +8,7 @@ import java.util.List; -public class UltraBackpacksAPI { +public final class UltraBackpacksAPI { private UltraBackpacksAPI() { throw new UnsupportedOperationException("Cannot instantiate UltraBackpacksAPI!"); @@ -29,7 +30,7 @@ public static boolean hasBackpack(Player player) { * @param player Player * @return BackpackData.class */ - public static IBackpackData getBackpackData(Player player) { + public static IBackpackData getBackpackData(Player player) throws BackpackNotFoundException { return BackendAPI.getImplementation().getBackpackData(player); } @@ -39,7 +40,7 @@ public static IBackpackData getBackpackData(Player player) { * @param player Player * @param sellAll If true, sells whole backpack. If false, sells only x amount of items based on AutoSell backpack enchant. */ - public static void sellBackpack(Player player, boolean sellAll) { + public static void sellBackpack(Player player, boolean sellAll) throws BackpackNotFoundException { BackendAPI.getImplementation().sellBackpack(player, sellAll); } diff --git a/src/main/java/dev/drawethree/ultrabackpacks/api/event/BackpackSellEvent.java b/src/main/java/dev/drawethree/ultrabackpacks/api/event/BackpackSellEvent.java index 2c14977..472dadc 100644 --- a/src/main/java/dev/drawethree/ultrabackpacks/api/event/BackpackSellEvent.java +++ b/src/main/java/dev/drawethree/ultrabackpacks/api/event/BackpackSellEvent.java @@ -4,7 +4,7 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -public class BackpackSellEvent extends Event { +public final class BackpackSellEvent extends Event { private static final HandlerList handlers = new HandlerList(); diff --git a/src/main/java/dev/drawethree/ultrabackpacks/api/exception/BackpackNotFoundException.java b/src/main/java/dev/drawethree/ultrabackpacks/api/exception/BackpackNotFoundException.java new file mode 100644 index 0000000..e3e9895 --- /dev/null +++ b/src/main/java/dev/drawethree/ultrabackpacks/api/exception/BackpackNotFoundException.java @@ -0,0 +1,10 @@ +package dev.drawethree.ultrabackpacks.api.exception; + +import org.bukkit.entity.Player; + +public final class BackpackNotFoundException extends Throwable { + + public BackpackNotFoundException(Player player) { + super("Player " + player.getName() + " does not have backpack."); + } +} diff --git a/src/main/java/dev/drawethree/ultrabackpacks/api/model/backpack/BackpackEnchantment.java b/src/main/java/dev/drawethree/ultrabackpacks/api/model/backpack/BackpackEnchantment.java new file mode 100644 index 0000000..135a509 --- /dev/null +++ b/src/main/java/dev/drawethree/ultrabackpacks/api/model/backpack/BackpackEnchantment.java @@ -0,0 +1,7 @@ +package dev.drawethree.ultrabackpacks.api.model.backpack; + +public enum BackpackEnchantment { + SELL_MULTI, + CAPACITY, + AUTO_SELL +} diff --git a/src/main/java/dev/drawethree/ultrabackpacks/api/model/backpack/IBackpackData.java b/src/main/java/dev/drawethree/ultrabackpacks/api/model/backpack/IBackpackData.java index a1a6a11..7e9db6b 100644 --- a/src/main/java/dev/drawethree/ultrabackpacks/api/model/backpack/IBackpackData.java +++ b/src/main/java/dev/drawethree/ultrabackpacks/api/model/backpack/IBackpackData.java @@ -1,21 +1,45 @@ package dev.drawethree.ultrabackpacks.api.model.backpack; -import java.util.Map; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import java.util.List; public interface IBackpackData { /** - * Returns Map of enchants that player has in his backpack. - * Key - Id of enchant - * Value - Level of enchant - * @return Map of enchants belonging to player + * Returns List of backpack items {@link IBackpackItem} + * + * @return list of item in backpack + */ + List getItems(); + + /** + * Adds an item to backpack. If item with type already exists, it adds the quantity to already existing item. + * + * @return Added / Updated {@link IBackpackItem} + */ + IBackpackItem addItem(ItemStack item); + + /** + * Removes an item from backpack. + * + * @return removed {@link IBackpackItem}, or null if not found. + */ + IBackpackItem removeItem(Material type); + + /** + * Sets the enchant level of given enchant + * + * @return removed {@link IBackpackItem} */ - Map getEnchants(); + boolean setEnchantLevel(BackpackEnchantment enchantment, long level); /** - * Returns Map - * Key - {@link CompMaterial} - * @return Map of backpack contents + * Return the current enchant level + * + * @param enchantment {@link BackpackEnchantment} + * @return current level of enchant */ - Map getItems(); + long getEnchantLevel(BackpackEnchantment enchantment); } diff --git a/src/main/java/dev/drawethree/ultrabackpacks/api/model/backpack/IBackpackItem.java b/src/main/java/dev/drawethree/ultrabackpacks/api/model/backpack/IBackpackItem.java new file mode 100644 index 0000000..2c4e848 --- /dev/null +++ b/src/main/java/dev/drawethree/ultrabackpacks/api/model/backpack/IBackpackItem.java @@ -0,0 +1,24 @@ +package dev.drawethree.ultrabackpacks.api.model.backpack; + +import org.bukkit.Material; + +public interface IBackpackItem { + + /** + * Gets the type of item. + * @return {@link Material} + */ + Material getType(); + + /** + * Gets the amount of item. + * @return amount + */ + long getAmount(); + + /** + * Sets the amount of item + * @param amount amount + */ + void setAmount(long amount); +} diff --git a/src/main/java/dev/drawethree/ultrabackpacks/api/service/BackendAPI.java b/src/main/java/dev/drawethree/ultrabackpacks/api/service/BackendAPI.java index e2dcd08..52b0b42 100644 --- a/src/main/java/dev/drawethree/ultrabackpacks/api/service/BackendAPI.java +++ b/src/main/java/dev/drawethree/ultrabackpacks/api/service/BackendAPI.java @@ -1,5 +1,6 @@ package dev.drawethree.ultrabackpacks.api.service; +import dev.drawethree.ultrabackpacks.api.exception.BackpackNotFoundException; import dev.drawethree.ultrabackpacks.api.model.backpack.IBackpackData; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -24,16 +25,18 @@ public abstract class BackendAPI { * * @param player Player * @return BackpackData.class + * @throws BackpackNotFoundException if player has no backpack */ - public abstract IBackpackData getBackpackData(Player player); + public abstract IBackpackData getBackpackData(Player player) throws BackpackNotFoundException; /** * Sells the contents of player backpack. * * @param player Player * @param sellAll If true, sells whole backpack. If false, sells only x amount of items based on AutoSell backpack enchant. + * @throws BackpackNotFoundException if player has no backpack */ - public abstract void sellBackpack(Player player, boolean sellAll); + public abstract void sellBackpack(Player player, boolean sellAll) throws BackpackNotFoundException; /** * Handles the specified broken blocks and tries to add them into backpack