Moves the save public command to its own class
This commit is contained in:
@@ -39,7 +39,7 @@ public class CommandCopy implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player);
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player, true);
|
||||
|
||||
try {
|
||||
int copies = Integer.parseInt(args[0]);
|
||||
|
@@ -36,7 +36,7 @@ public class CommandDecrypt implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldItem = InventoryHelper.getHeldBook(player);
|
||||
ItemStack heldItem = InventoryHelper.getHeldBook(player, true);
|
||||
BookMeta bookMetadata = (BookMeta) heldItem.getItemMeta();
|
||||
if (bookMetadata == null) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Your book seems to be corrupt!");
|
||||
|
@@ -44,7 +44,7 @@ public class CommandEncrypt implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player);
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player, true);
|
||||
|
||||
if (!((BookMeta) Objects.requireNonNull(heldBook.getItemMeta())).hasPages()) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Book must have contents to encrypt!");
|
||||
|
@@ -45,7 +45,7 @@ public class CommandGroupEncrypt implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player);
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player, true);
|
||||
BookMeta bookMetadata = (BookMeta) heldBook.getItemMeta();
|
||||
|
||||
if (bookMetadata == null) {
|
||||
|
@@ -1,12 +1,45 @@
|
||||
package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
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;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Command executor for the save public command
|
||||
*/
|
||||
public class CommandSavePublic implements CommandExecutor {
|
||||
|
||||
private final BooksWithoutBorders booksWithoutBorders;
|
||||
|
||||
public CommandSavePublic(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;
|
||||
}
|
||||
|
||||
ItemSlot holdingSlot = InventoryHelper.getHeldSlotBook(player, false, false, false, false);
|
||||
if (holdingSlot != ItemSlot.NONE) {
|
||||
ItemStack holdingItem = InventoryHelper.getHeldItem(player, holdingSlot == ItemSlot.MAIN_HAND);
|
||||
if (args.length == 1) {
|
||||
booksWithoutBorders.saveBook(player, holdingItem, args[0], true);
|
||||
} else {
|
||||
booksWithoutBorders.saveBook(player, holdingItem, "false", true);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "You must be holding a written book or book and quill to save it!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user