Moves the setTitle command to its own file
This commit is contained in:
parent
7247098a54
commit
bc93ddcec5
@ -24,4 +24,4 @@ Ever wanted to export your book to a text file? Ever want to import it back in?
|
|||||||
* Give first time players a single book or a set of books when they join
|
* Give first time players a single book or a set of books when they join
|
||||||
* Configurable option to require certain items or pay via Vault compatible economy to create books via command
|
* Configurable option to require certain items or pay via Vault compatible economy to create books via command
|
||||||
* Add lore to any item with a simple command
|
* Add lore to any item with a simple command
|
||||||
* Supports adding and saving color to titles, lore, and book contents
|
* Supports adding and saving color to title, lore, and book contents
|
@ -24,6 +24,7 @@ import net.knarcraft.bookswithoutborders.command.CommandSavePublic;
|
|||||||
import net.knarcraft.bookswithoutborders.command.CommandSetAuthor;
|
import net.knarcraft.bookswithoutborders.command.CommandSetAuthor;
|
||||||
import net.knarcraft.bookswithoutborders.command.CommandSetBookPrice;
|
import net.knarcraft.bookswithoutborders.command.CommandSetBookPrice;
|
||||||
import net.knarcraft.bookswithoutborders.command.CommandSetLore;
|
import net.knarcraft.bookswithoutborders.command.CommandSetLore;
|
||||||
|
import net.knarcraft.bookswithoutborders.command.CommandSetTitle;
|
||||||
import net.knarcraft.bookswithoutborders.command.CommandUnSign;
|
import net.knarcraft.bookswithoutborders.command.CommandUnSign;
|
||||||
import net.knarcraft.bookswithoutborders.command.GiveTabCompleter;
|
import net.knarcraft.bookswithoutborders.command.GiveTabCompleter;
|
||||||
import net.knarcraft.bookswithoutborders.state.EncryptionStyle;
|
import net.knarcraft.bookswithoutborders.state.EncryptionStyle;
|
||||||
@ -48,7 +49,6 @@ import org.bukkit.inventory.ItemFactory;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.inventory.meta.BookMeta;
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -105,6 +105,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
|||||||
registerCommand("savePublic", new CommandSavePublic(this), null);
|
registerCommand("savePublic", new CommandSavePublic(this), null);
|
||||||
registerCommand("save", new CommandSave(this), null);
|
registerCommand("save", new CommandSave(this), null);
|
||||||
registerCommand("setAuthor", new CommandSetAuthor(), null);
|
registerCommand("setAuthor", new CommandSetAuthor(), null);
|
||||||
|
registerCommand("setTitle", new CommandSetTitle(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -359,7 +360,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
|||||||
sendSuccessMessage(sender, "If true is specified the book will be signed, if false it will be");
|
sendSuccessMessage(sender, "If true is specified the book will be signed, if false it will be");
|
||||||
sendSuccessMessage(sender, "unsigned");
|
sendSuccessMessage(sender, "unsigned");
|
||||||
}
|
}
|
||||||
if (sender.hasPermission("bookswithoutborders.loadpublic")) {
|
if (sender.hasPermission("bookswithoutborders.loadPublic")) {
|
||||||
sender.sendMessage(commandColor + "loadPublic [file name or number] [# of copies] [true/false]:");
|
sender.sendMessage(commandColor + "loadPublic [file name or number] [# of copies] [true/false]:");
|
||||||
sendSuccessMessage(sender, "Same as Load, but views files in the public directory");
|
sendSuccessMessage(sender, "Same as Load, but views files in the public directory");
|
||||||
}
|
}
|
||||||
@ -464,7 +465,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
|||||||
if (sender instanceof Player player) {
|
if (sender instanceof Player player) {
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("loadPublic")) {
|
if (args[0].equalsIgnoreCase("loadPublic")) {
|
||||||
if (!sender.hasPermission("bookswithoutborders.loadpublic")) {
|
if (!sender.hasPermission("bookswithoutborders.loadPublic")) {
|
||||||
sendErrorMessage(sender, " You don't have permission to use this command!");
|
sendErrorMessage(sender, " You don't have permission to use this command!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -561,46 +562,11 @@ public class BooksWithoutBorders extends JavaPlugin {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("setTitle")) {
|
|
||||||
if (!sender.hasPermission("bookswithoutborders.settitle")) {
|
|
||||||
sendErrorMessage(sender, " You don't have permission to use this command!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length < 2) {
|
|
||||||
sendErrorMessage(sender, "Too few command arguments!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((Player) sender).getItemInHand().getType() == Material.AIR) {
|
|
||||||
sendErrorMessage(sender, "You must be holding an item to set title!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String title = String.join(" ", args);
|
|
||||||
title = ChatColor.translateAlternateColorCodes('&', title);
|
|
||||||
|
|
||||||
ItemMeta meta;
|
|
||||||
if (((Player) sender).getItemInHand().getType() == Material.WRITTEN_BOOK) {
|
|
||||||
BookMeta bMeta = (BookMeta) ((Player) sender).getItemInHand().getItemMeta();
|
|
||||||
bMeta.setTitle(title);
|
|
||||||
meta = bMeta;
|
|
||||||
} else {
|
|
||||||
ItemMeta iMeta = ((Player) sender).getItemInHand().getItemMeta();
|
|
||||||
iMeta.setDisplayName(title);
|
|
||||||
meta = iMeta;
|
|
||||||
}
|
|
||||||
|
|
||||||
((Player) sender).getItemInHand().setItemMeta(meta);
|
|
||||||
sendSuccessMessage(sender, "Title set to " + title + "!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("givePublic")) {
|
if (args[0].equalsIgnoreCase("givePublic")) {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
if (!sender.hasPermission("bookswithoutborders.givepublic")) {
|
if (!sender.hasPermission("bookswithoutborders.givePublic")) {
|
||||||
sendErrorMessage(sender, " You don't have permission to use this command!");
|
sendErrorMessage(sender, " You don't have permission to use this command!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -661,7 +627,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("deletepublic")) {
|
if (args[0].equalsIgnoreCase("deletePublic")) {
|
||||||
|
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
if (!sender.hasPermission("bookswithoutborders.admin")) {
|
if (!sender.hasPermission("bookswithoutborders.admin")) {
|
||||||
@ -981,7 +947,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
|||||||
book.setItemMeta(bookMetadata);
|
book.setItemMeta(bookMetadata);
|
||||||
book.setAmount(numCopies);
|
book.setAmount(numCopies);
|
||||||
|
|
||||||
if (booksHavePrice() && !sender.hasPermission("bookswithoutborders.bypassbookprice") &&
|
if (booksHavePrice() && !sender.hasPermission("bookswithoutborders.bypassBookPrice") &&
|
||||||
(dir.equalsIgnoreCase("public") || dir.equalsIgnoreCase("player") ||
|
(dir.equalsIgnoreCase("public") || dir.equalsIgnoreCase("player") ||
|
||||||
dir.equalsIgnoreCase("")) &&
|
dir.equalsIgnoreCase("")) &&
|
||||||
cannotPayForBookPrinting((Player) sender, numCopies)) {
|
cannotPayForBookPrinting((Player) sender, numCopies)) {
|
||||||
|
@ -35,7 +35,7 @@ public class CommandCopy implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args.length < 1) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,13 +44,13 @@ public class CommandCopy implements CommandExecutor {
|
|||||||
try {
|
try {
|
||||||
int copies = Integer.parseInt(args[0]);
|
int copies = Integer.parseInt(args[0]);
|
||||||
if (copies > 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())))
|
if (!booksWithoutBorders.isAuthor(player, (BookMeta) Objects.requireNonNull(heldBook.getItemMeta())))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (booksWithoutBorders.booksHavePrice() &&
|
if (booksWithoutBorders.booksHavePrice() &&
|
||||||
!player.hasPermission("bookswithoutborders.bypassbookprice") &&
|
!player.hasPermission("bookswithoutborders.bypassBookPrice") &&
|
||||||
booksWithoutBorders.cannotPayForBookPrinting(player, copies)) {
|
booksWithoutBorders.cannotPayForBookPrinting(player, copies)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -61,6 +61,10 @@ commands:
|
|||||||
description: Sets the author of the held book
|
description: Sets the author of the held book
|
||||||
usage: /<command> <author>
|
usage: /<command> <author>
|
||||||
permission: bookswithoutborders.setauthor
|
permission: bookswithoutborders.setauthor
|
||||||
|
settitle:
|
||||||
|
description: Sets the title of the held book
|
||||||
|
usage: /<command> <title>
|
||||||
|
permission: bookswithoutborders.settitle
|
||||||
permissions:
|
permissions:
|
||||||
bookswithoutborders.admin:
|
bookswithoutborders.admin:
|
||||||
description: Grants all permissions
|
description: Grants all permissions
|
||||||
|
Loading…
Reference in New Issue
Block a user