From 646b60a90ba976537ccabb2587ded84e446075c5 Mon Sep 17 00:00:00 2001 From: Charles DeLancey <46200123+Evidentsinger14@users.noreply.github.com> Date: Sun, 28 May 2023 14:27:18 -0400 Subject: [PATCH] Add ability to get recipe of item in hand (#5346) Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com> Co-authored-by: pop4959 --- .../essentials/commands/Commandrecipe.java | 14 +++++++++++++- Essentials/src/main/resources/messages.properties | 5 +++-- 2 files changed, 16 insertions(+), 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 abd91a14d..411a83afe 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 @@ package com.earth2me.essentials.commands; 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; @@ -53,7 +54,18 @@ public class Commandrecipe extends EssentialsCommand { throw new NotEnoughArgumentsException(); } - final ItemStack itemType = ess.getItemDb().get(args[0]); + final ItemStack itemType; + + if (args[0].equalsIgnoreCase("hand")) { + if (!sender.isPlayer()) { + throw new Exception(tl("consoleCannotUseCommand")); + } + + itemType = Inventories.getItemInHand(sender.getPlayer()); + } 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 46567df00..3801a8a18 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=/ @@ -1025,8 +1026,8 @@ 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. 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