Makes some changes to formatting and un-signing
All checks were successful
EpicKnarvik97/Books-Without-Borders/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Books-Without-Borders/pipeline/head This commit looks good
Makes the unsign command convert formatting codes to human editable ones Makes the format command work on unsigned books
This commit is contained in:
@@ -30,15 +30,12 @@ public class CommandFormat implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
|
||||
stringFormatter.replacePlaceholder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK, "{action}",
|
||||
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_FORMAT)),
|
||||
stringFormatter.replacePlaceholder(Translatable.ERROR_ONLY_ONE_BOOK, "{action}",
|
||||
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_FORMAT)))) {
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player);
|
||||
if (heldBook == null) {
|
||||
stringFormatter.displayErrorMessage(sender, Translatable.ERROR_NOT_HOLDING_ANY_BOOK);
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player, true);
|
||||
|
||||
BookMeta meta = (BookMeta) heldBook.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
|
@@ -68,6 +68,8 @@ public class CommandUnSign implements TabExecutor {
|
||||
if (book == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
reverseColorCodes(book);
|
||||
InventoryHelper.replaceHeldItem(player, book, mainHand);
|
||||
}
|
||||
|
||||
@@ -78,4 +80,25 @@ public class CommandUnSign implements TabExecutor {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses colors of a previously formatted book
|
||||
*
|
||||
* @param book <p>The book to reverse colors of</p>
|
||||
*/
|
||||
private void reverseColorCodes(@NotNull ItemStack book) {
|
||||
try {
|
||||
BookMeta meta = (BookMeta) book.getItemMeta();
|
||||
if (meta != null) {
|
||||
List<String> newPages = new ArrayList<>(meta.getPages().size());
|
||||
for (String page : meta.getPages()) {
|
||||
newPages.add(page.replaceAll("§", "&"));
|
||||
}
|
||||
meta.setPages(newPages);
|
||||
book.setItemMeta(meta);
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user