Skip to content

Commit

Permalink
Merge pull request #2 from Drawethree/feature/1.2.0
Browse files Browse the repository at this point in the history
Feature/1.2.0
  • Loading branch information
Drawethree authored Jul 10, 2022
2 parents 7af3e3f + cb6ace7 commit 5b168a8
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>ultrabackpacks-api</artifactId>
<name>UltraBackpacks API</name>
<packaging>jar</packaging>
<version>1.1.3</version>
<version>1.2.0</version>

<build>
<finalName>UltraBackpacksAPI-${project.version}</finalName>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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;
import org.bukkit.entity.Player;

import java.util.List;

public class UltraBackpacksAPI {
public final class UltraBackpacksAPI {

private UltraBackpacksAPI() {
throw new UnsupportedOperationException("Cannot instantiate UltraBackpacksAPI!");
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.drawethree.ultrabackpacks.api.model.backpack;

public enum BackpackEnchantment {
SELL_MULTI,
CAPACITY,
AUTO_SELL
}
Original file line number Diff line number Diff line change
@@ -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<? extends IBackpackItem> 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<Integer, Long> 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<?, Long> getItems();
long getEnchantLevel(BackpackEnchantment enchantment);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 5b168a8

Please sign in to comment.