diff --git a/src/main/java/tsp/headdb/HeadDB.java b/src/main/java/tsp/headdb/HeadDB.java index 7cd0a45..695be82 100644 --- a/src/main/java/tsp/headdb/HeadDB.java +++ b/src/main/java/tsp/headdb/HeadDB.java @@ -20,6 +20,9 @@ import tsp.headdb.util.Utils; import javax.annotation.Nullable; import java.io.File; +/** + * Main class of HeadDB + */ public class HeadDB extends JavaPlugin { private static HeadDB instance; diff --git a/src/main/java/tsp/headdb/api/HeadAPI.java b/src/main/java/tsp/headdb/api/HeadAPI.java index 80a6b53..22a4e4a 100644 --- a/src/main/java/tsp/headdb/api/HeadAPI.java +++ b/src/main/java/tsp/headdb/api/HeadAPI.java @@ -1,5 +1,6 @@ package tsp.headdb.api; +import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -47,7 +48,9 @@ public final class HeadAPI { * * @param player Target player */ - public static void openDatabase(Player player) { + public static void openDatabase(@Nonnull Player player) { + Validate.notNull(player, "Player can not be null!"); + InventoryUtils.openDatabase(player); } @@ -57,7 +60,10 @@ public final class HeadAPI { * @param player Target player * @param category Category to open */ - public static void openCategoryDatabase(Player player, Category category) { + public static void openCategoryDatabase(@Nonnull Player player, @Nonnull Category category) { + Validate.notNull(player, "Player can not be null!"); + Validate.notNull(category, "Category can not be null!"); + InventoryUtils.openCategoryDatabase(player, category); } @@ -67,7 +73,10 @@ public final class HeadAPI { * @param player Target player * @param search Search term */ - public static void openSearchDatabase(Player player, String search) { + public static void openSearchDatabase(@Nonnull Player player, @Nonnull String search) { + Validate.notNull(player, "Player can not be null!"); + Validate.notNull(search, "Search can not be null!"); + InventoryUtils.openSearchDatabase(player, search); } @@ -77,7 +86,10 @@ public final class HeadAPI { * @param player Target player * @param tag Tag search term */ - public static void openTagSearchDatabase(Player player, String tag) { + public static void openTagSearchDatabase(@Nonnull Player player, @Nonnull String tag) { + Validate.notNull(player, "Player can not be null!"); + Validate.notNull(tag, "Tag can not be null!"); + InventoryUtils.openTagSearchDatabase(player, tag); } @@ -99,7 +111,9 @@ public final class HeadAPI { * @return The head */ @Nullable - public static Head getHeadByUniqueId(UUID uuid) { + public static Head getHeadByUniqueId(@Nonnull UUID uuid) { + Validate.notNull(uuid, "UUID can not be null!"); + return database.getHeadByUniqueId(uuid); } @@ -110,7 +124,9 @@ public final class HeadAPI { * @return List of heads */ @Nonnull - public static List
getHeadsByTag(String tag) { + public static List getHeadsByTag(@Nonnull String tag) { + Validate.notNull(tag, "Tag can not be null!"); + return database.getHeadsByTag(tag); } @@ -121,7 +137,9 @@ public final class HeadAPI { * @return List of heads */ @Nonnull - public static List getHeadsByName(String name) { + public static List getHeadsByName(@Nonnull String name) { + Validate.notNull(name, "Name can not be null!"); + return database.getHeadsByName(name); } @@ -133,7 +151,10 @@ public final class HeadAPI { * @return List of heads */ @Nonnull - public static List getHeadsByName(Category category, String name) { + public static List getHeadsByName(@Nonnull Category category, @Nonnull String name) { + Validate.notNull(category, "Category can not be null!"); + Validate.notNull(name, "Name can not be null!"); + return database.getHeadsByName(category, name); } @@ -144,7 +165,9 @@ public final class HeadAPI { * @return The head */ @Nullable - public static Head getHeadByValue(String value) { + public static Head getHeadByValue(@Nonnull String value) { + Validate.notNull(value, "Value can not be null!"); + return database.getHeadByValue(value); } @@ -155,7 +178,9 @@ public final class HeadAPI { * @return List of heads */ @Nonnull - public static List getHeads(Category category) { + public static List getHeads(@Nonnull Category category) { + Validate.notNull(category, "Category can not be null!"); + return database.getHeads(category); } @@ -175,7 +200,10 @@ public final class HeadAPI { * @param uuid The player's unique id * @param textureValue The head's texture value */ - public static void addFavoriteHead(UUID uuid, String textureValue) { + public static void addFavoriteHead(@Nonnull UUID uuid, @Nonnull String textureValue) { + Validate.notNull(uuid, "UUID can not be null!"); + Validate.notNull(textureValue, "Value can not be null!"); + HeadDB.getInstance().getPlayerData().modifyFavorite(uuid, textureValue, PlayerDataFile.ModificationType.SET); } @@ -185,7 +213,10 @@ public final class HeadAPI { * @param uuid The player's unique id * @param textureValue The head's texture value */ - public static void removeFavoriteHead(UUID uuid, String textureValue) { + public static void removeFavoriteHead(@Nonnull UUID uuid, @Nonnull String textureValue) { + Validate.notNull(uuid, "UUID can not be null!"); + Validate.notNull(textureValue, "Value can not be null!"); + HeadDB.getInstance().getPlayerData().modifyFavorite(uuid, textureValue, PlayerDataFile.ModificationType.REMOVE); } @@ -196,9 +227,12 @@ public final class HeadAPI { * @return List of favorite {@link Head}'s for the player */ @Nonnull - public static List getFavoriteHeads(UUID uuid) { + public static List getFavoriteHeads(@Nonnull UUID uuid) { + Validate.notNull(uuid, "UUID can not be null!"); + return HeadDB.getInstance().getPlayerData().getFavoriteHeadsByTexture(uuid).stream() .map(HeadAPI::getHeadByValue) + .filter(head -> head != null) .collect(Collectors.toList()); } diff --git a/src/main/java/tsp/headdb/api/event/PlayerHeadPurchaseEvent.java b/src/main/java/tsp/headdb/api/event/PlayerHeadPurchaseEvent.java index 55cbbc5..a9faf87 100644 --- a/src/main/java/tsp/headdb/api/event/PlayerHeadPurchaseEvent.java +++ b/src/main/java/tsp/headdb/api/event/PlayerHeadPurchaseEvent.java @@ -21,6 +21,7 @@ public class PlayerHeadPurchaseEvent extends Event implements Cancellable { private double cost; public PlayerHeadPurchaseEvent(Player player, Head head, double cost) { + super(true); this.player = player; this.head = head; this.cost = cost; diff --git a/src/main/java/tsp/headdb/economy/TreasuryProvider.java b/src/main/java/tsp/headdb/economy/TreasuryProvider.java index 1db6b9e..480f107 100644 --- a/src/main/java/tsp/headdb/economy/TreasuryProvider.java +++ b/src/main/java/tsp/headdb/economy/TreasuryProvider.java @@ -26,6 +26,7 @@ import java.util.function.Consumer; public class TreasuryProvider implements BasicEconomyProvider { private EconomyProvider provider; + private EconomyTransactionInitiator> transactionInitiator; private Currency currency; @Override @@ -58,7 +59,7 @@ public class TreasuryProvider implements BasicEconomyProvider { }).whenComplete((account, ex) -> { account.withdrawBalance( amount, - EconomyTransactionInitiator.createInitiator(EconomyTransactionInitiator.Type.PLUGIN, "HeadDB"), + transactionInitiator, currency, new EconomySubscriber