Moves more commands to their appropriate classes
This commit is contained in:
@@ -1,12 +1,70 @@
|
||||
package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
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;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class CommandCopy implements CommandExecutor {
|
||||
|
||||
private final BooksWithoutBorders booksWithoutBorders;
|
||||
|
||||
public CommandCopy(BooksWithoutBorders booksWithoutBorders) {
|
||||
this.booksWithoutBorders = booksWithoutBorders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
return false;
|
||||
if (!(sender instanceof Player player)) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (InventoryHelper.notHoldingOneWrittenBookCheck(player, "You must be holding a written book to copy it!",
|
||||
"You cannot copy two books at once!")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length < 1) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "You must specifiy the number of copies to be made!");
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player);
|
||||
|
||||
try {
|
||||
int copies = Integer.parseInt(args[0]);
|
||||
if (copies > 0) {
|
||||
if (BooksWithoutBorders.authorOnlyCopy && !player.hasPermission("bookswithoutborders.bypassauthoronlycopy")) {
|
||||
if (!booksWithoutBorders.isAuthor(player, (BookMeta) Objects.requireNonNull(heldBook.getItemMeta())))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (booksWithoutBorders.booksHavePrice() &&
|
||||
!player.hasPermission("bookswithoutborders.bypassbookprice") &&
|
||||
booksWithoutBorders.cannotPayForBookPrinting(player, copies)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
heldBook.setAmount(heldBook.getAmount() + copies);
|
||||
BooksWithoutBorders.sendSuccessMessage(player, "Book copied!");
|
||||
} else {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Book not copied!");
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Number specified was invalid!");
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Book not copied!");
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Number specified was invalid!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,12 +1,48 @@
|
||||
package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CommandDelete implements CommandExecutor {
|
||||
|
||||
private final BooksWithoutBorders booksWithoutBorders;
|
||||
|
||||
public CommandDelete(BooksWithoutBorders booksWithoutBorders) {
|
||||
this.booksWithoutBorders = booksWithoutBorders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
||||
return false;
|
||||
}
|
||||
|
||||
//List deletable files
|
||||
if (args.length == 0) {
|
||||
BooksWithoutBorders.loadList.put(player.getName(), booksWithoutBorders.listFiles(player, false, false));
|
||||
return true;
|
||||
}
|
||||
//Delete the file
|
||||
if (args.length == 1) {
|
||||
if (!BooksWithoutBorders.loadList.containsKey(player.getName())) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "You must first use /bwb delete to create a list of delete-able files!");
|
||||
return false;
|
||||
} else {
|
||||
if (!BooksWithoutBorders.loadList.get(player.getName()).isEmpty()) {
|
||||
booksWithoutBorders.deleteBook(player, args[0], false);
|
||||
return true;
|
||||
} else {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "No files available to delete!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Incorrect number of arguments for this command!");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,12 +1,66 @@
|
||||
package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.EncryptionStyle;
|
||||
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;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class CommandEncrypt implements CommandExecutor {
|
||||
|
||||
private final BooksWithoutBorders booksWithoutBorders;
|
||||
|
||||
public CommandEncrypt(BooksWithoutBorders booksWithoutBorders) {
|
||||
this.booksWithoutBorders = booksWithoutBorders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
return false;
|
||||
if (!(sender instanceof Player player)) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (InventoryHelper.notHoldingOneWrittenBookCheck(player, "You must be holding a written book to encrypt it!",
|
||||
"You cannot encrypt two books at once!")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length < 1) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "You must specify a key to encrypt a book!");
|
||||
return false;
|
||||
}
|
||||
if (args.length > 2) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Too many command options specified!");
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player);
|
||||
|
||||
if (!((BookMeta) Objects.requireNonNull(heldBook.getItemMeta())).hasPages()) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Book must have contents to encrypt!");
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack encryptedBook;
|
||||
|
||||
if (args.length == 2) {
|
||||
encryptedBook = booksWithoutBorders.encryptBook(player, true, args[0], EncryptionStyle.getFromString(args[1]), "");
|
||||
} else {
|
||||
encryptedBook = booksWithoutBorders.encryptBook(player, true, args[0], EncryptionStyle.SUBSTITUTION, "");
|
||||
}
|
||||
|
||||
if (encryptedBook != null) {
|
||||
InventoryHelper.setHeldBook(player, encryptedBook);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,9 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Command executor for the give command
|
||||
*/
|
||||
public class CommandGive implements CommandExecutor {
|
||||
|
||||
private final BooksWithoutBorders booksWithoutBorders;
|
||||
|
@@ -1,12 +1,83 @@
|
||||
package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.EncryptionStyle;
|
||||
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;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Command executor for the group encrypt command
|
||||
*/
|
||||
public class CommandGroupEncrypt implements CommandExecutor {
|
||||
|
||||
private final BooksWithoutBorders booksWithoutBorders;
|
||||
|
||||
public CommandGroupEncrypt(BooksWithoutBorders booksWithoutBorders) {
|
||||
this.booksWithoutBorders = booksWithoutBorders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
return false;
|
||||
if (!(sender instanceof Player player)) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
|
||||
"You must be holding a written book to encrypt it!",
|
||||
"You cannot encrypt two books at once!")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length < 2) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "You must specify a group name and key to encrypt a book!");
|
||||
return false;
|
||||
}
|
||||
if (args.length > 3) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Too many command options specified!");
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player);
|
||||
BookMeta bookMetadata = (BookMeta) heldBook.getItemMeta();
|
||||
|
||||
if (bookMetadata == null) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Your book seems to be corrupt!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bookMetadata.hasPages()) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Book must have contents to encrypt!");
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> lore = bookMetadata.getLore();
|
||||
if (bookMetadata.hasLore() && lore != null && lore.get(0).contains(" encrypted]")) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Book is already group encrypted!");
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack eBook;
|
||||
|
||||
if (args.length == 3) {
|
||||
eBook = booksWithoutBorders.encryptBook(player, true, args[1], EncryptionStyle.getFromString(args[2]), args[0]);
|
||||
} else {
|
||||
eBook = booksWithoutBorders.encryptBook(player, true, args[1], EncryptionStyle.SUBSTITUTION, args[0]);
|
||||
}
|
||||
|
||||
if (eBook != null) {
|
||||
InventoryHelper.setHeldBook(player, eBook);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,36 @@
|
||||
package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.BookHoldingState;
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
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;
|
||||
|
||||
public class CommandUnSign implements CommandExecutor {
|
||||
|
||||
private final BooksWithoutBorders booksWithoutBorders;
|
||||
|
||||
public CommandUnSign(BooksWithoutBorders booksWithoutBorders) {
|
||||
this.booksWithoutBorders = booksWithoutBorders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (InventoryHelper.notHoldingOneWrittenBookCheck(player, "You must be holding a signed book to un-sign it!",
|
||||
"You cannot un-sign two books at once. Please un-equip one of the books you're holding!")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//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);
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class CommandUnsign implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user