From 3ec3a5d9b0d0b6e8ff8e1f9c5cc4d45e30154af2 Mon Sep 17 00:00:00 2001 From: JustinM95 Date: Fri, 21 Jan 2022 10:54:47 -0600 Subject: [PATCH 1/6] Added max lore feature #4772 https://github.com/EssentialsX/Essentials/discussions/4772 --- .../com/earth2me/essentials/ISettings.java | 2 ++ .../java/com/earth2me/essentials/Settings.java | 5 +++++ .../essentials/commands/Commanditemlore.java | 18 ++++++++++++------ Essentials/src/main/resources/config.yml | 3 +++ .../src/main/resources/messages.properties | 1 + 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java index 405fe5dc0de..3eb0832b37a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -396,6 +396,8 @@ public interface ISettings extends IConf { boolean showZeroBaltop(); + int getMaxItemLore(); + enum KeepInvPolicy { KEEP, DELETE, diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index 47eecc98568..768cc159d94 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -1919,4 +1919,9 @@ public boolean isUpdateCheckEnabled() { public boolean showZeroBaltop() { return config.getBoolean("show-zero-baltop", true); } + + @Override + public int getMaxItemLore() { + return config.getInt("max-item-lore", 10); + } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemlore.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemlore.java index 3ee0a4eb8b5..e11bd25500f 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemlore.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemlore.java @@ -34,13 +34,19 @@ protected void run(final Server server, final User user, final String commandLab } final ItemMeta im = item.getItemMeta(); + final int loreSize = im.hasLore() ? im.getLore().size() : 0; + final int maxLoreSize = ess.getSettings().getMaxItemLore(); if (args[0].equalsIgnoreCase("add") && args.length > 1) { - final String line = FormatUtil.formatString(user, "essentials.itemlore", getFinalArg(args, 1)).trim(); - final List lore = im.hasLore() ? im.getLore() : new ArrayList<>(); - lore.add(line); - im.setLore(lore); - item.setItemMeta(im); - user.sendMessage(tl("itemloreSuccess", line)); + if (loreSize < maxLoreSize) { + final String line = FormatUtil.formatString(user, "essentials.itemlore", getFinalArg(args, 1)).trim(); + final List lore = im.hasLore() ? im.getLore() : new ArrayList<>(); + lore.add(line); + im.setLore(lore); + item.setItemMeta(im); + user.sendMessage(tl("itemloreSuccess", line)); + } else { + throw new Exception(tl("itemloreMaxLore")); + } } else if (args[0].equalsIgnoreCase("clear")) { im.setLore(new ArrayList<>()); item.setItemMeta(im); diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml index bd96fcaf48e..6bdfe612145 100644 --- a/Essentials/src/main/resources/config.yml +++ b/Essentials/src/main/resources/config.yml @@ -727,6 +727,9 @@ log-command-block-commands: true # Set the maximum speed for projectiles spawned with /fireball. max-projectile-speed: 8 +# The max lines of lore that can be set with /itemlore set +max-item-lore: 10 + # Should EssentialsX check for updates? # If set to true, EssentialsX will show notifications when a new version is available. # This uses the public GitHub API and no identifying information is sent or stored. diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index 526dc22db3c..22817721605 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -554,6 +554,7 @@ itemloreCommandUsage2Description=Sets the specified line of the held item's lore itemloreCommandUsage3=/ clear itemloreCommandUsage3Description=Clears the held item's lore itemloreInvalidItem=\u00a74You need to hold an item to edit its lore. +itemloreMaxLore=\u00a74You cannot add more lore to this item. itemloreNoLine=\u00a74Your held item does not have lore text on line \u00a7c{0}\u00a74. itemloreNoLore=\u00a74Your held item does not have any lore text. itemloreSuccess=\u00a76You have added "\u00a7c{0}\u00a76" to your held item''s lore. From b220c228866ef532f0c85e30b46b2f31999b43d8 Mon Sep 17 00:00:00 2001 From: JustinM95 Date: Fri, 21 Jan 2022 11:18:01 -0600 Subject: [PATCH 2/6] Updated max-item-lore config comment for accuracy --- Essentials/src/main/resources/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml index 6bdfe612145..2adf8f4f22c 100644 --- a/Essentials/src/main/resources/config.yml +++ b/Essentials/src/main/resources/config.yml @@ -727,7 +727,7 @@ log-command-block-commands: true # Set the maximum speed for projectiles spawned with /fireball. max-projectile-speed: 8 -# The max lines of lore that can be set with /itemlore set +# Set the max lines of lore that can be added with /itemlore add max-item-lore: 10 # Should EssentialsX check for updates? From cfa9d9dbbfc2b0d5c122e18fb0349132d83e46a9 Mon Sep 17 00:00:00 2001 From: Justin Mitchell Date: Sat, 22 Jan 2022 19:02:51 -0600 Subject: [PATCH 3/6] Update Essentials/src/main/resources/config.yml Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com> --- Essentials/src/main/resources/config.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml index 2adf8f4f22c..8ec92af1ea7 100644 --- a/Essentials/src/main/resources/config.yml +++ b/Essentials/src/main/resources/config.yml @@ -727,8 +727,9 @@ log-command-block-commands: true # Set the maximum speed for projectiles spawned with /fireball. max-projectile-speed: 8 -# Set the max lines of lore that can be added with /itemlore add -max-item-lore: 10 +# Set the maximum amount of lore lines a user can set with the /itemlore command. +# Users with the essentials.itemlore.bypass permission will be able to bypass this limit. +max-itemlore-lines: 10 # Should EssentialsX check for updates? # If set to true, EssentialsX will show notifications when a new version is available. From 5ea7af258845d1d6f644492e54c377e4eadabffe Mon Sep 17 00:00:00 2001 From: Justin Mitchell Date: Sat, 22 Jan 2022 19:03:04 -0600 Subject: [PATCH 4/6] Update Essentials/src/main/java/com/earth2me/essentials/Settings.java Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com> --- Essentials/src/main/java/com/earth2me/essentials/Settings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index 768cc159d94..a3cd79d14f6 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -1922,6 +1922,6 @@ public boolean showZeroBaltop() { @Override public int getMaxItemLore() { - return config.getInt("max-item-lore", 10); + return config.getInt("max-itemlore-lines", 10); } } From f36a76655a86951ec03006d19e5d0b4a68cb934c Mon Sep 17 00:00:00 2001 From: Justin Mitchell Date: Sat, 22 Jan 2022 19:03:10 -0600 Subject: [PATCH 5/6] Update Essentials/src/main/resources/messages.properties Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com> --- Essentials/src/main/resources/messages.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index 22817721605..1b81e9e3b2e 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -554,7 +554,7 @@ itemloreCommandUsage2Description=Sets the specified line of the held item's lore itemloreCommandUsage3=/ clear itemloreCommandUsage3Description=Clears the held item's lore itemloreInvalidItem=\u00a74You need to hold an item to edit its lore. -itemloreMaxLore=\u00a74You cannot add more lore to this item. +itemloreMaxLore=\u00a74You cannot add any more lore lines to this item. itemloreNoLine=\u00a74Your held item does not have lore text on line \u00a7c{0}\u00a74. itemloreNoLore=\u00a74Your held item does not have any lore text. itemloreSuccess=\u00a76You have added "\u00a7c{0}\u00a76" to your held item''s lore. From 79a8268ce3e32f4530f981618255128a8db3db37 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Tue, 8 Aug 2023 14:43:36 -0400 Subject: [PATCH 6/6] changes --- .../essentials/commands/Commanditemlore.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemlore.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemlore.java index 9f56bf9ad10..c754454af3b 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemlore.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemlore.java @@ -36,18 +36,17 @@ protected void run(final Server server, final User user, final String commandLab final ItemMeta im = item.getItemMeta(); final int loreSize = im.hasLore() ? im.getLore().size() : 0; - final int maxLoreSize = ess.getSettings().getMaxItemLore(); if (args[0].equalsIgnoreCase("add") && args.length > 1) { - if (loreSize < maxLoreSize) { - final String line = FormatUtil.formatString(user, "essentials.itemlore", getFinalArg(args, 1)).trim(); - final List lore = im.hasLore() ? im.getLore() : new ArrayList<>(); - lore.add(line); - im.setLore(lore); - item.setItemMeta(im); - user.sendMessage(tl("itemloreSuccess", line)); - } else { + if (loreSize >= ess.getSettings().getMaxItemLore() && !user.isAuthorized("essentials.itemlore.bypass")) { throw new Exception(tl("itemloreMaxLore")); } + + final String line = FormatUtil.formatString(user, "essentials.itemlore", getFinalArg(args, 1)).trim(); + final List lore = im.hasLore() ? im.getLore() : new ArrayList<>(); + lore.add(line); + im.setLore(lore); + item.setItemMeta(im); + user.sendMessage(tl("itemloreSuccess", line)); } else if (args[0].equalsIgnoreCase("clear")) { im.setLore(new ArrayList<>()); item.setItemMeta(im);