From 009ab19665a2f254d52be30bdaef60c0efd1445b Mon Sep 17 00:00:00 2001 From: Evidentsinger14 Date: Thu, 11 May 2023 20:55:20 -0400 Subject: [PATCH 1/7] add `/recipe hand` to get the recipe of item in main hand. --- .../essentials/commands/Commandrecipe.java | 18 +++++++++++++++++- .../src/main/resources/messages.properties | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java index abd91a14d43..b104533c051 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java @@ -53,7 +53,23 @@ public void run(final Server server, final CommandSource sender, final String co throw new NotEnoughArgumentsException(); } - final ItemStack itemType = ess.getItemDb().get(args[0]); + final ItemStack itemType; + + if (args[0].equalsIgnoreCase("hand")) { + final User user = ess.getUser(sender.getPlayer()); + if (user == null) { + throw new Exception(tl("recipeConsoleNoHands")); + } + final Material item = user.getItemInHand().getType(); + + if (item.isAir()) { + throw new Exception(tl("recipeCannotBeAir")); + } + itemType = ess.getItemDb().get(item.toString()); + } else { + itemType = ess.getItemDb().get(args[0]); + } + int recipeNo = 0; if (args.length > 1) { diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index 46567df00eb..0d9bd4d402a 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -1024,10 +1024,12 @@ realnameCommandUsage1Description=Displays the username of a user based on the gi recentlyForeverAlone=\u00a74{0} recently went offline. recipe=\u00a76Recipe for \u00a7c{0}\u00a76 (\u00a7c{1}\u00a76 of \u00a7c{2}\u00a76) recipeBadIndex=There is no recipe by that number. +recipeCannotBeAir=No recipes exist for air. recipeCommandDescription=Displays how to craft items. recipeCommandUsage=/ [number] recipeCommandUsage1=/ [page] recipeCommandUsage1Description=Displays how to craft the given item +recipeConsoleNoHands=Console does not have hands. recipeFurnace=\u00a76Smelt\: \u00a7c{0}\u00a76. recipeGrid=\u00a7c{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X recipeGridItem=\u00a7c{0}X \u00a76is \u00a7c{1} From d830e1e070df9dbdf193d3cf0a025661025650c0 Mon Sep 17 00:00:00 2001 From: Evidentsinger14 Date: Fri, 26 May 2023 21:22:58 -0400 Subject: [PATCH 2/7] remove redundant check to see if item is air. --- .../java/com/earth2me/essentials/commands/Commandrecipe.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java index b104533c051..87f5d671cec 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java @@ -62,9 +62,6 @@ public void run(final Server server, final CommandSource sender, final String co } final Material item = user.getItemInHand().getType(); - if (item.isAir()) { - throw new Exception(tl("recipeCannotBeAir")); - } itemType = ess.getItemDb().get(item.toString()); } else { itemType = ess.getItemDb().get(args[0]); From ee2b1d9baac0e24264e40ce6ff91f5a8fecd23f8 Mon Sep 17 00:00:00 2001 From: Evidentsinger14 Date: Fri, 26 May 2023 21:36:04 -0400 Subject: [PATCH 3/7] change consoles message to be less specific --- .../java/com/earth2me/essentials/commands/Commandrecipe.java | 2 +- Essentials/src/main/resources/messages.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java index 87f5d671cec..e719abe7426 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java @@ -58,7 +58,7 @@ public void run(final Server server, final CommandSource sender, final String co if (args[0].equalsIgnoreCase("hand")) { final User user = ess.getUser(sender.getPlayer()); if (user == null) { - throw new Exception(tl("recipeConsoleNoHands")); + throw new Exception(tl("consoleCannotUseCommand")); } final Material item = user.getItemInHand().getType(); diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index 0d9bd4d402a..af133ef49c7 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -157,6 +157,7 @@ commandHelpLine3=\u00a76Usage(s); commandHelpLine4=\u00a76Aliases(s): \u00a7f{0} commandHelpLineUsage={0} \u00a76- {1} commandNotLoaded=\u00a74Command {0} is improperly loaded. +consoleCannotUseCommand=This command cannot be used by Console. compassBearing=\u00a76Bearing\: {0} ({1} degrees). compassCommandDescription=Describes your current bearing. compassCommandUsage=/ @@ -1029,7 +1030,6 @@ recipeCommandDescription=Displays how to craft items. recipeCommandUsage=/ [number] recipeCommandUsage1=/ [page] recipeCommandUsage1Description=Displays how to craft the given item -recipeConsoleNoHands=Console does not have hands. recipeFurnace=\u00a76Smelt\: \u00a7c{0}\u00a76. recipeGrid=\u00a7c{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X recipeGridItem=\u00a7c{0}X \u00a76is \u00a7c{1} From 51a39892d6e05630dcb47af1f1e2c941159a02df Mon Sep 17 00:00:00 2001 From: Evidentsinger14 Date: Fri, 26 May 2023 21:41:54 -0400 Subject: [PATCH 4/7] forgot to modify usage message --- Essentials/src/main/resources/messages.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index af133ef49c7..79bb558be92 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -1027,8 +1027,8 @@ recipe=\u00a76Recipe for \u00a7c{0}\u00a76 (\u00a7c{1}\u00a76 of \u00a7c{2}\u00a recipeBadIndex=There is no recipe by that number. recipeCannotBeAir=No recipes exist for air. recipeCommandDescription=Displays how to craft items. -recipeCommandUsage=/ [number] -recipeCommandUsage1=/ [page] +recipeCommandUsage=/ <|hand> [number] +recipeCommandUsage1=/ <|hand> [page] recipeCommandUsage1Description=Displays how to craft the given item recipeFurnace=\u00a76Smelt\: \u00a7c{0}\u00a76. recipeGrid=\u00a7c{0}X \u00a76| \u00a7{1}X \u00a76| \u00a7{2}X From 989a0ae817c0af5df5759513ad3aac41180d7b7c Mon Sep 17 00:00:00 2001 From: Charles DeLancey <46200123+Evidentsinger14@users.noreply.github.com> Date: Fri, 26 May 2023 21:58:34 -0400 Subject: [PATCH 5/7] Update Essentials/src/main/resources/messages.properties Co-authored-by: pop4959 --- Essentials/src/main/resources/messages.properties | 1 - 1 file changed, 1 deletion(-) diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index 79bb558be92..3801a8a18ad 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -1025,7 +1025,6 @@ realnameCommandUsage1Description=Displays the username of a user based on the gi recentlyForeverAlone=\u00a74{0} recently went offline. recipe=\u00a76Recipe for \u00a7c{0}\u00a76 (\u00a7c{1}\u00a76 of \u00a7c{2}\u00a76) recipeBadIndex=There is no recipe by that number. -recipeCannotBeAir=No recipes exist for air. recipeCommandDescription=Displays how to craft items. recipeCommandUsage=/ <|hand> [number] recipeCommandUsage1=/ <|hand> [page] From 640ed2425a0d28f863bb489dfc78b3543f73064b Mon Sep 17 00:00:00 2001 From: Charles DeLancey <46200123+Evidentsinger14@users.noreply.github.com> Date: Fri, 26 May 2023 22:06:55 -0400 Subject: [PATCH 6/7] Update Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com> --- .../com/earth2me/essentials/commands/Commandrecipe.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java index e719abe7426..dcb4d4fba1a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java @@ -56,13 +56,12 @@ public void run(final Server server, final CommandSource sender, final String co final ItemStack itemType; if (args[0].equalsIgnoreCase("hand")) { - final User user = ess.getUser(sender.getPlayer()); - if (user == null) { + if (!sender.isPlayer()) { throw new Exception(tl("consoleCannotUseCommand")); } - final Material item = user.getItemInHand().getType(); - - itemType = ess.getItemDb().get(item.toString()); + final User user = sender.getUser(ess); + + itemType = user.getItemInHand(); } else { itemType = ess.getItemDb().get(args[0]); } From 9ee9ffc0a31307debe191c0543390cfd1fd66404 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Sun, 28 May 2023 14:24:31 -0400 Subject: [PATCH 7/7] fix build --- .../java/com/earth2me/essentials/commands/Commandrecipe.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java index dcb4d4fba1a..411a83afeb8 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java @@ -2,6 +2,7 @@ import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.User; +import com.earth2me.essentials.craftbukkit.Inventories; import com.earth2me.essentials.utils.EnumUtil; import com.earth2me.essentials.utils.NumberUtil; import com.earth2me.essentials.utils.VersionUtil; @@ -59,9 +60,8 @@ public void run(final Server server, final CommandSource sender, final String co if (!sender.isPlayer()) { throw new Exception(tl("consoleCannotUseCommand")); } - final User user = sender.getUser(ess); - itemType = user.getItemInHand(); + itemType = Inventories.getItemInHand(sender.getPlayer()); } else { itemType = ess.getItemDb().get(args[0]); }