Makes more advanced functions for deciding which hand has the correct book
Adds some functions which account for all possible states for books and hands Adds some new enums to keep track of the new states Fixes lots of warnings
This commit is contained in:
@ -12,6 +12,9 @@ import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Command executor for the decrypt command
|
||||
*/
|
||||
public class CommandDecrypt implements CommandExecutor {
|
||||
|
||||
private final BooksWithoutBorders booksWithoutBorders;
|
||||
@ -27,7 +30,7 @@ public class CommandDecrypt implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!InventoryHelper.notHoldingOneWrittenBookCheck(player,
|
||||
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
|
||||
"You must be holding a written book to decrypt it!",
|
||||
"You cannot decrypt two books at once!")) {
|
||||
return false;
|
||||
@ -53,6 +56,7 @@ public class CommandDecrypt implements CommandExecutor {
|
||||
File encryptedDirectory = new File(path);
|
||||
String[] encryptedFiles = encryptedDirectory.list();
|
||||
if (encryptedFiles == null) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Could not find any encrypted files!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -69,7 +73,7 @@ public class CommandDecrypt implements CommandExecutor {
|
||||
//Decrypt the book
|
||||
ItemStack book = booksWithoutBorders.eLoad(player, key, false);
|
||||
if (book != null) {
|
||||
InventoryHelper.setHeldBook(player, book);
|
||||
InventoryHelper.setHeldWrittenBook(player, book);
|
||||
BooksWithoutBorders.sendSuccessMessage(player, "Book auto-decrypted!");
|
||||
return true;
|
||||
} else {
|
||||
@ -89,10 +93,11 @@ public class CommandDecrypt implements CommandExecutor {
|
||||
//Decrypt the book
|
||||
ItemStack book = booksWithoutBorders.eLoad(player, key, true);
|
||||
if (book != null) {
|
||||
InventoryHelper.setHeldBook(player, book);
|
||||
InventoryHelper.setHeldWrittenBook(player, book);
|
||||
BooksWithoutBorders.sendSuccessMessage(player, "Book decrypted!");
|
||||
return true;
|
||||
} else {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Failed to decrypt book!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.EncryptionStyle;
|
||||
import net.knarcraft.bookswithoutborders.state.EncryptionStyle;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -60,7 +60,7 @@ public class CommandEncrypt implements CommandExecutor {
|
||||
}
|
||||
|
||||
if (encryptedBook != null) {
|
||||
InventoryHelper.setHeldBook(player, encryptedBook);
|
||||
InventoryHelper.setHeldWrittenBook(player, encryptedBook);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.EncryptionStyle;
|
||||
import net.knarcraft.bookswithoutborders.state.EncryptionStyle;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -73,7 +73,7 @@ public class CommandGroupEncrypt implements CommandExecutor {
|
||||
}
|
||||
|
||||
if (eBook != null) {
|
||||
InventoryHelper.setHeldBook(player, eBook);
|
||||
InventoryHelper.setHeldWrittenBook(player, eBook);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -1,13 +1,16 @@
|
||||
package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.BookHoldingState;
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.state.ItemSlot;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Command executor for the un-sign command
|
||||
*/
|
||||
public class CommandUnSign implements CommandExecutor {
|
||||
|
||||
private final BooksWithoutBorders booksWithoutBorders;
|
||||
@ -29,8 +32,8 @@ public class CommandUnSign implements CommandExecutor {
|
||||
}
|
||||
|
||||
//Find which hand the player is using to hold the book. If holding one in each, throw an error
|
||||
BookHoldingState holdingState = InventoryHelper.getHoldingSignedBookState(player);
|
||||
booksWithoutBorders.unSignHeldBook(player, holdingState == BookHoldingState.MAIN_HAND);
|
||||
ItemSlot holdingSlot = InventoryHelper.getHeldSlotBook(player, false, false, true, true);
|
||||
booksWithoutBorders.unSignHeldBook(player, holdingSlot == ItemSlot.MAIN_HAND);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user