Adds an argument for setting a book's display name instead of title #13
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
This commit is contained in:
@@ -88,7 +88,7 @@ An in-game description of available commands is available through the /bwb comma
|
|||||||
| /setbookprice | bwbprice | \<item/eco> \<quantity> | bookswithoutborders.setbookprice | Sets the per-book price to create a book via commands. If "Item", the item in the player's hand in the amount of \<quantity> will be the price. If "Eco", a Vault based economy will be used for price. If neither \<Item/Eco> nor \<quantity> are specified, the current price to create books will be removed. |
|
| /setbookprice | bwbprice | \<item/eco> \<quantity> | bookswithoutborders.setbookprice | Sets the per-book price to create a book via commands. If "Item", the item in the player's hand in the amount of \<quantity> will be the price. If "Eco", a Vault based economy will be used for price. If neither \<Item/Eco> nor \<quantity> are specified, the current price to create books will be removed. |
|
||||||
| /setBookshelfData | bwbshelfdata | \<delete/name/lore> \text> \[more text] | bookswithoutborders.editbookshelf | Sets the name/lore for a bookshelf which is shown when peeking at its contents. |
|
| /setBookshelfData | bwbshelfdata | \<delete/name/lore> \text> \[more text] | bookswithoutborders.editbookshelf | Sets the name/lore for a bookshelf which is shown when peeking at its contents. |
|
||||||
| /setlore | bwblore | \<new lore> | bookswithoutborders.setlore | Sets the lore of the item the player is holding. Insert the lore_line_separator character to force a new line ("~" by default) |
|
| /setlore | bwblore | \<new lore> | bookswithoutborders.setlore | Sets the lore of the item the player is holding. Insert the lore_line_separator character to force a new line ("~" by default) |
|
||||||
| /settitle | bwbtitle | \<title> | bookswithoutborders.settitle | Sets the title of the book/item the player is holding |
|
| /settitle | bwbtitle | \<title> \[title] ... \[setDisplayName (true/false)] | bookswithoutborders.settitle | Sets the title of the book or the display name of the item the player is holding. Add a true at the end (`/settitle some title true`) to set a book's display name instead of its title. |
|
||||||
| /unsignbook | bwbunsign | None | bookswithoutborders.unsign | Un-signs the book the player is holding |
|
| /unsignbook | bwbunsign | None | bookswithoutborders.unsign | Un-signs the book the player is holding |
|
||||||
|
|
||||||
### Permissions:
|
### Permissions:
|
||||||
|
@@ -1,10 +1,9 @@
|
|||||||
package net.knarcraft.bookswithoutborders.command;
|
package net.knarcraft.bookswithoutborders.command;
|
||||||
|
|
||||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||||
|
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
|
||||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||||
import net.knarcraft.knarlib.property.ColorConversion;
|
|
||||||
import net.knarcraft.knarlib.util.ColorHelper;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -42,8 +41,15 @@ public class CommandSetTitle implements TabExecutor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String title = String.join(" ", arguments).strip();
|
boolean setDisplayName = false;
|
||||||
title = ColorHelper.translateColorCodes(title, ColorConversion.RGB);
|
String title;
|
||||||
|
if (InputCleaningHelper.isBoolean(arguments[arguments.length - 1])) {
|
||||||
|
setDisplayName = Boolean.parseBoolean(arguments[arguments.length - 1]);
|
||||||
|
title = InputCleaningHelper.mergeArguments(arguments, 1);
|
||||||
|
} else {
|
||||||
|
title = String.join(" ", arguments);
|
||||||
|
}
|
||||||
|
title = new FormatBuilder(title).color().build();
|
||||||
|
|
||||||
ItemMeta itemMetadata = heldItem.getItemMeta();
|
ItemMeta itemMetadata = heldItem.getItemMeta();
|
||||||
if (itemMetadata == null) {
|
if (itemMetadata == null) {
|
||||||
@@ -53,7 +59,7 @@ public class CommandSetTitle implements TabExecutor {
|
|||||||
|
|
||||||
//Get and change metadata
|
//Get and change metadata
|
||||||
ItemMeta newMetaData;
|
ItemMeta newMetaData;
|
||||||
if (heldItem.getType() == Material.WRITTEN_BOOK) {
|
if (heldItem.getType() == Material.WRITTEN_BOOK && !setDisplayName) {
|
||||||
if (title.length() > 32) {
|
if (title.length() > 32) {
|
||||||
new FormatBuilder(Translatable.ERROR_TITLE_LENGTH).error(player);
|
new FormatBuilder(Translatable.ERROR_TITLE_LENGTH).error(player);
|
||||||
return false;
|
return false;
|
||||||
@@ -68,7 +74,12 @@ public class CommandSetTitle implements TabExecutor {
|
|||||||
|
|
||||||
//Set the new metadata
|
//Set the new metadata
|
||||||
heldItem.setItemMeta(newMetaData);
|
heldItem.setItemMeta(newMetaData);
|
||||||
new FormatBuilder(Translatable.SUCCESS_TITLE_SET).replace("{title}", title).success(player);
|
|
||||||
|
if (heldItem.getType() == Material.WRITTEN_BOOK && !setDisplayName) {
|
||||||
|
new FormatBuilder(Translatable.SUCCESS_TITLE_SET).replace("{title}", title).success(player);
|
||||||
|
} else {
|
||||||
|
new FormatBuilder(Translatable.SUCCESS_DISPLAY_NAME_SET).replace("{displayName}", title).success(player);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +88,9 @@ public class CommandSetTitle implements TabExecutor {
|
|||||||
@NotNull String[] arguments) {
|
@NotNull String[] arguments) {
|
||||||
List<String> options = new ArrayList<>();
|
List<String> options = new ArrayList<>();
|
||||||
options.add("<new title>");
|
options.add("<new title>");
|
||||||
|
if (arguments.length > 1) {
|
||||||
|
options.addAll(List.of("true", "false"));
|
||||||
|
}
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -79,20 +79,20 @@ public enum Translatable implements TranslatableMessage {
|
|||||||
SUCCESS_LORE_SET,
|
SUCCESS_LORE_SET,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The success message displayed when an item's title is successfully set
|
* The success message displayed when a book's title is successfully set
|
||||||
*/
|
*/
|
||||||
SUCCESS_TITLE_SET,
|
SUCCESS_TITLE_SET,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The success message displayed when an item's display name is successfully set
|
||||||
|
*/
|
||||||
|
SUCCESS_DISPLAY_NAME_SET,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The success message displayed when books have been successfully migrated
|
* The success message displayed when books have been successfully migrated
|
||||||
*/
|
*/
|
||||||
SUCCESS_MIGRATED,
|
SUCCESS_MIGRATED,
|
||||||
|
|
||||||
/**
|
|
||||||
* The error to display when the console attempts to run a player-only command
|
|
||||||
*/
|
|
||||||
ERROR_PLAYER_ONLY,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The success message displayed when a book is successfully encrypted
|
* The success message displayed when a book is successfully encrypted
|
||||||
*/
|
*/
|
||||||
@@ -108,6 +108,11 @@ public enum Translatable implements TranslatableMessage {
|
|||||||
*/
|
*/
|
||||||
NEUTRAL_ATTEMPTING_LEGACY_DECRYPTION,
|
NEUTRAL_ATTEMPTING_LEGACY_DECRYPTION,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The error to display when the console attempts to run a player-only command
|
||||||
|
*/
|
||||||
|
ERROR_PLAYER_ONLY,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The error displayed when running a relevant command without holding a written book
|
* The error displayed when running a relevant command without holding a written book
|
||||||
*/
|
*/
|
||||||
|
@@ -164,10 +164,11 @@ commands:
|
|||||||
Note that this behaves differently for signed books compared to other items.
|
Note that this behaves differently for signed books compared to other items.
|
||||||
For signed books, the book's actual name in the book's metadata is changed, and that name is limited to 32 characters.
|
For signed books, the book's actual name in the book's metadata is changed, and that name is limited to 32 characters.
|
||||||
For other items, the display name is set, which has no relevant limit.
|
For other items, the display name is set, which has no relevant limit.
|
||||||
|
Add the argument true after typing in the title to set the display name of a book instead of the title.
|
||||||
Color and formatting codes (#000000, &a, &4, &n, &#ffffff) are supported.
|
Color and formatting codes (#000000, &a, &4, &n, &#ffffff) are supported.
|
||||||
aliases:
|
aliases:
|
||||||
- bwbtitle
|
- bwbtitle
|
||||||
usage: /<command> <title>
|
usage: /<command> <title> [title] ... [setDisplayName (true/false)]
|
||||||
permission: bookswithoutborders.settitle
|
permission: bookswithoutborders.settitle
|
||||||
loadbook:
|
loadbook:
|
||||||
description: |
|
description: |
|
||||||
|
@@ -27,6 +27,7 @@ en:
|
|||||||
SUCCESS_GENERATION_CHANGED: "Book generation successfully changed!"
|
SUCCESS_GENERATION_CHANGED: "Book generation successfully changed!"
|
||||||
SUCCESS_LORE_SET: "Added lore to item!"
|
SUCCESS_LORE_SET: "Added lore to item!"
|
||||||
SUCCESS_TITLE_SET: "Title set to {title}!"
|
SUCCESS_TITLE_SET: "Title set to {title}!"
|
||||||
|
SUCCESS_DISPLAY_NAME_SET: "Display name set to {displayName}!"
|
||||||
SUCCESS_MIGRATED: "Successfully migrated all books"
|
SUCCESS_MIGRATED: "Successfully migrated all books"
|
||||||
SUCCESS_ENCRYPTED: "Book encrypted!"
|
SUCCESS_ENCRYPTED: "Book encrypted!"
|
||||||
SUCCESS_UNSIGNED: "Book un-signed"
|
SUCCESS_UNSIGNED: "Book un-signed"
|
||||||
|
Reference in New Issue
Block a user