Skip to content

Commit

Permalink
Engrave option for GIVE
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomeffinWay committed Mar 23, 2013
1 parent 0e94fd3 commit 7fa6382
Showing 1 changed file with 15 additions and 1 deletion.
Expand Up @@ -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;
Expand Down Expand Up @@ -37,6 +38,7 @@ public class GiveCommand extends AbstractCommand {
GiveType giveType;
int theAmount;
Item theItem;
boolean engrave;

@Override
public void onEnable() {
Expand All @@ -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()) {
Expand All @@ -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;
Expand Down Expand Up @@ -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<Integer, ItemStack> 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<Integer, ItemStack> leftoverItem : leftovers.entrySet()) {
Expand Down

0 comments on commit 7fa6382

Please sign in to comment.