Moves the setTitle command to its own file
This commit is contained in:
@@ -35,7 +35,7 @@ public class CommandCopy implements CommandExecutor {
|
||||
}
|
||||
|
||||
if (args.length < 1) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "You must specifiy the number of copies to be made!");
|
||||
BooksWithoutBorders.sendErrorMessage(player, "You must specify the number of copies to be made!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -44,13 +44,13 @@ public class CommandCopy implements CommandExecutor {
|
||||
try {
|
||||
int copies = Integer.parseInt(args[0]);
|
||||
if (copies > 0) {
|
||||
if (BooksWithoutBorders.authorOnlyCopy && !player.hasPermission("bookswithoutborders.bypassauthoronlycopy")) {
|
||||
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") &&
|
||||
!player.hasPermission("bookswithoutborders.bypassBookPrice") &&
|
||||
booksWithoutBorders.cannotPayForBookPrinting(player, copies)) {
|
||||
return false;
|
||||
}
|
||||
|
@@ -70,7 +70,7 @@ public class CommandGive implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
//bwb give [bookname] [player] [numCopies] [issigned]
|
||||
//bwb give [book name] [player] [numCopies] [is signed]
|
||||
try {
|
||||
|
||||
if (isSigned != null && copies != null) {
|
||||
|
@@ -0,0 +1,64 @@
|
||||
package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
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 org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
/**
|
||||
* Command executor for the set title command
|
||||
*/
|
||||
public class CommandSetTitle implements CommandExecutor {
|
||||
|
||||
@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 (args.length < 1) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Too few command arguments!");
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldItem = InventoryHelper.getHeldItem(player, true);
|
||||
if (heldItem.getType() == Material.AIR) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "You must be holding an item to set title!");
|
||||
return false;
|
||||
}
|
||||
|
||||
String title = String.join(" ", args);
|
||||
title = ChatColor.translateAlternateColorCodes('&', title);
|
||||
|
||||
ItemMeta itemMetadata = heldItem.getItemMeta();
|
||||
if (itemMetadata == null) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "Unable to get metadata for your held item!");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Get and change metadata
|
||||
ItemMeta newMetaData;
|
||||
if (heldItem.getType() == Material.WRITTEN_BOOK) {
|
||||
BookMeta bookMetadata = (BookMeta) itemMetadata;
|
||||
bookMetadata.setTitle(title);
|
||||
newMetaData = bookMetadata;
|
||||
} else {
|
||||
itemMetadata.setDisplayName(title);
|
||||
newMetaData = itemMetadata;
|
||||
}
|
||||
|
||||
//Set the new metadata
|
||||
heldItem.setItemMeta(newMetaData);
|
||||
BooksWithoutBorders.sendSuccessMessage(sender, "Title set to " + title + "!");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user