diff --git a/src/main/java/net/knarcraft/bookswithoutborders/state/HoldingItemState.java b/src/main/java/net/knarcraft/bookswithoutborders/state/HoldingItemState.java deleted file mode 100644 index d645fe2..0000000 --- a/src/main/java/net/knarcraft/bookswithoutborders/state/HoldingItemState.java +++ /dev/null @@ -1,28 +0,0 @@ -package net.knarcraft.bookswithoutborders.state; - -/** - * This enum represents the different states of a player holding a given item - */ -public enum HoldingItemState { - - /** - * The player is holding one item in each hand - */ - BOTH_HANDS, - - /** - * The player is holding one item in their main hand - */ - MAIN_HAND, - - /** - * The player is holding one item in their off hand - */ - OFF_HAND, - - /** - * The player is not holding any items - */ - NONE - -} diff --git a/src/main/java/net/knarcraft/bookswithoutborders/utility/InventoryHelper.java b/src/main/java/net/knarcraft/bookswithoutborders/utility/InventoryHelper.java index 8795246..8338a0a 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/utility/InventoryHelper.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/utility/InventoryHelper.java @@ -49,35 +49,22 @@ public class InventoryHelper { } /** - * Performs checks to validate that a player contains exactly one written - * + * Performs checks to validate that a player contains exactly one written book * @param player

The player to validate

* @param noBookMessage

The message to display if the player is not holding a book

* @param twoBooksMessage

The message to display if the player is holding one book in each hand

- * @return

False if the player is holding exactly one written book

- */ - public static boolean notHoldingOneWrittenBookCheck(Player player, String noBookMessage, String twoBooksMessage) { - return notHoldingOneBookCheck(player, noBookMessage, twoBooksMessage, true); - } - - /** - * Performs checks to validate that a player contains exactly one book - * @param player

The player to validate

- * @param noBookMessage

The message to display if the player is not holding a book

- * @param twoBooksMessage

The message to display if the player is holding one book in each hand

- * @param written

Whether to require a written/signed book as opposed to a writable/unsigned book

* @return

False if the player is holding exactly one book

*/ - private static boolean notHoldingOneBookCheck(Player player, String noBookMessage, String twoBooksMessage, boolean written) { + public static boolean notHoldingOneWrittenBookCheck(Player player, String noBookMessage, String twoBooksMessage) { BookHoldingState holdingState = getBookHoldingState(player); - if (holdingState == BookHoldingState.NONE) { + if (holdingState == BookHoldingState.NONE || holdingState == BookHoldingState.UNSIGNED_BOTH_HANDS || + holdingState == BookHoldingState.UNSIGNED_MAIN_HAND || holdingState == BookHoldingState.UNSIGNED_OFF_HAND) { BooksWithoutBorders.sendErrorMessage(player, noBookMessage); return true; } - if ((written && holdingState == BookHoldingState.SIGNED_BOTH_HANDS) || - (!written && holdingState == BookHoldingState.UNSIGNED_BOTH_HANDS)) { + if (holdingState == BookHoldingState.SIGNED_BOTH_HANDS) { BooksWithoutBorders.sendErrorMessage(player, twoBooksMessage); return true; } @@ -85,29 +72,6 @@ public class InventoryHelper { return false; } - /** - * Check whether the player is holding one book - * - * @param player

The player possibly holding a book

- * @param signedBook

Whether to look for signed or unsigned books

- * @return

True if the player is holding one book

- */ - public static boolean isHoldingBook(Player player, boolean signedBook) { - BookHoldingState holdingState = getBookHoldingState(player); - - if (holdingState == BookHoldingState.SIGNED_MAIN_HAND_UNSIGNED_OFF_HAND || - holdingState == BookHoldingState.UNSIGNED_MAIN_HAND_SIGNED_OFF_HAND) { - return true; - } - if (signedBook) { - return holdingState == BookHoldingState.SIGNED_MAIN_HAND || - holdingState == BookHoldingState.SIGNED_OFF_HAND; - } else { - return holdingState == BookHoldingState.UNSIGNED_MAIN_HAND || - holdingState == BookHoldingState.UNSIGNED_OFF_HAND; - } - } - /** * Gets the slot of the player's held book * @param player

The player holding the book