mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-27 01:40:48 +08:00
Add default book title and authors (#4920)
Prevents written books from being invalid if no author/title is provided. Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com>
This commit is contained in:
parent
eb76cf0fbb
commit
dfa22969c9
@ -223,11 +223,21 @@ public class MetaItemStack {
|
||||
} else {
|
||||
throw new Exception(tl("onlyPlayerSkulls"));
|
||||
}
|
||||
} else if (split.length > 1 && split[0].equalsIgnoreCase("book") && MaterialUtil.isEditableBook(stack.getType()) && (hasMetaPermission(sender, "book",true, true, ess) || hasMetaPermission(sender, "chapter-" + split[1].toLowerCase(Locale.ENGLISH), true, true, ess))) {
|
||||
} else if (split.length > 1 && split[0].equalsIgnoreCase("book") && MaterialUtil.isEditableBook(stack.getType()) && (hasMetaPermission(sender, "book", true, true, ess) || hasMetaPermission(sender, "chapter-" + split[1].toLowerCase(Locale.ENGLISH), true, true, ess))) {
|
||||
final BookMeta meta = (BookMeta) stack.getItemMeta();
|
||||
final IText input = new BookInput("book", true, ess);
|
||||
final BookPager pager = new BookPager(input);
|
||||
|
||||
// This fix only applies to written books - which require an author and a title. https://bugs.mojang.com/browse/MC-59153
|
||||
if (stack.getType() == WRITTEN_BOOK) {
|
||||
if (!meta.hasAuthor()) {
|
||||
// The sender can be null when this method is called from {@link com.earth2me.essentials.signs.EssentialsSign#getItemMeta(ItemStack, String, IEssentials)}
|
||||
meta.setAuthor(sender == null ? Console.getInstance().getDisplayName() : sender.getPlayer().getName());
|
||||
}
|
||||
if (!meta.hasTitle()) {
|
||||
final String title = FormatUtil.replaceFormat(split[1].replace('_', ' '));
|
||||
meta.setTitle(title.length() > 32 ? title.substring(0, 32) : title);
|
||||
}
|
||||
}
|
||||
final List<String> pages = pager.getPages(split[1]);
|
||||
meta.setPages(pages);
|
||||
stack.setItemMeta(meta);
|
||||
|
@ -412,12 +412,16 @@ public class EssentialsSign {
|
||||
}
|
||||
|
||||
protected final ItemStack getItemMeta(final ItemStack item, final String meta, final IEssentials ess) throws SignException {
|
||||
return this.getItemMeta(null, item, meta, ess);
|
||||
}
|
||||
|
||||
protected final ItemStack getItemMeta(final CommandSource source, final ItemStack item, final String meta, final IEssentials ess) throws SignException {
|
||||
ItemStack stack = item;
|
||||
try {
|
||||
if (!meta.isEmpty()) {
|
||||
final MetaItemStack metaStack = new MetaItemStack(stack);
|
||||
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
|
||||
metaStack.addStringMeta(null, allowUnsafe, meta, ess);
|
||||
metaStack.addStringMeta(source, allowUnsafe, meta, ess);
|
||||
stack = metaStack.getItemStack();
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
|
@ -31,8 +31,8 @@ public class SignFree extends EssentialsSign {
|
||||
@Override
|
||||
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException {
|
||||
ItemStack itemStack = getItemStack(sign.getLine(1), 1, ess);
|
||||
itemStack = getItemMeta(itemStack, sign.getLine(2), ess);
|
||||
final ItemStack item = getItemMeta(itemStack, sign.getLine(3), ess);
|
||||
itemStack = getItemMeta(player.getSource(), itemStack, sign.getLine(2), ess);
|
||||
final ItemStack item = getItemMeta(player.getSource(), itemStack, sign.getLine(3), ess);
|
||||
|
||||
if (item.getType() == Material.AIR) {
|
||||
throw new SignException(tl("cantSpawnItem", "Air"));
|
||||
|
Loading…
Reference in New Issue
Block a user