From 7fa6382250f8c5a2de7b3139efdf2827bc9ac931 Mon Sep 17 00:00:00 2001 From: GnomeffinWay Date: Sat, 23 Mar 2013 00:27:32 -0500 Subject: [PATCH] Engrave option for GIVE --- .../scripts/commands/core/GiveCommand.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/GiveCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/GiveCommand.java index 59b5994edb..4f6dad1acc 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/GiveCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/GiveCommand.java @@ -8,6 +8,7 @@ import net.aufdemrand.denizen.utilities.arguments.aH; import net.aufdemrand.denizen.utilities.debugging.dB; import net.aufdemrand.denizen.utilities.depends.Depends; +import net.aufdemrand.denizen.utilities.nbt.NBTItem; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -37,6 +38,7 @@ public class GiveCommand extends AbstractCommand { GiveType giveType; int theAmount; Item theItem; + boolean engrave; @Override public void onEnable() { @@ -49,13 +51,14 @@ public void parseArgs(ScriptEntry scriptEntry) /* Initialize variables */ if (scriptEntry.getArguments () == null) { - throw new InvalidArgumentsException ("...Usage: GIVE [MONEY|#(:#)|MATERIAL_TYPE(:#)] (QTY:#)"); + throw new InvalidArgumentsException ("...Usage: GIVE [MONEY|#(:#)|MATERIAL_TYPE(:#)] (QTY:#) (ENGRAVE)"); } player = scriptEntry.getPlayer(); giveType = null; theAmount = 1; theItem = null; + engrave = false; /* Match arguments to expected variables */ for (String thisArg : scriptEntry.getArguments()) { @@ -75,6 +78,12 @@ else if (aH.matchesArg("XP", thisArg) dB.echoDebug ("...giving EXP."); } + else if (aH.matchesArg("ENGRAVE", thisArg)) { + this.engrave = true; + dB.echoDebug ("...item will be engraved."); + } + + else if (aH.matchesItem(thisArg) || aH.matchesItem("item:" + thisArg)) { theItem = aH.getItemFrom (thisArg); this.giveType = GiveType.ITEM; @@ -111,9 +120,14 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { case ITEM: theItem.setAmount(theAmount); + if(engrave) { + dB.echoDebug("...engraving " + theItem + " to the player"); + NBTItem.addCustomNBT(theItem, "owner", player.getName()); + } dB.echoDebug("..giving player " + theAmount + " of " + theItem); HashMap leftovers = player.getInventory().addItem(theItem); + if (!leftovers.isEmpty()) { dB.echoDebug ("...Player did not have enough space in their inventory, the rest of the items have been placed on the floor."); for (Map.Entry leftoverItem : leftovers.entrySet()) {