Skip to content

Commit

Permalink
Add pickup delay to drop command. (For Items)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fortifier42 committed Jan 19, 2016
1 parent a6d72c8 commit b5c7cc6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Expand Up @@ -833,7 +833,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name Drop
// @Syntax drop [<entity_type>/xp/<item>|...] (<location>) (quantity:<#>) (speed:<#.#>)
// @Syntax drop [<entity_type>/xp/<item>|...] (<location>) (quantity:<#>) (speed:<#.#>) (delay:<duration>)
// @Required 1
// @Stable stable
// @Short Drops an item, entity, or experience orb on a location.
Expand All @@ -848,6 +848,7 @@ public void registerCoreMembers() {
// For all three usages, you can optionally specify an integer with 'quantity:'
// prefix to drop multiple items/entities/xp.
// For items, you can add 'speed:' to modify the launch velocity.
// You can also add 'delay:' to set the pickup delay of the item.

// @Tags
// <entry[saveName].dropped_entities> returns a list of entities that were dropped.
Expand All @@ -857,16 +858,20 @@ public void registerCoreMembers() {
// - drop i@gold_nugget <cu@<player.location.add[-2,-2,-2]>|<player.location.add[2,2,2]>.get_spawnable_blocks.random>

// @Usage
// Use to reward a player
// Use to reward a player with 500 xp.
// - drop xp quantity:500 <player.location>

// @Usage
// Use to drop a nasty surprise (exploding TNT)
// Use to drop a nasty surprise (exploding TNT).
// - drop e@primed_tnt <player.location>

// @Usage
// Use to drop an item with a pickup delay at the player's location.
// - drop i@diamond_sword <player.location> delay:20s

// -->
registerCoreMember(DropCommand.class,
"DROP", "drop [<entity_type>/xp/<item>|...] (<location>) (qty:<#>) (speed:<#.#>)", 1);
"DROP", "drop [<entity_type>/xp/<item>|...] (<location>) (qty:<#>) (speed:<#.#>) (delay:<duration>)", 1);


// <--[command]
Expand Down
Expand Up @@ -7,14 +7,12 @@
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Mechanism;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.objects.*;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Item;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -70,6 +68,11 @@ else if (!scriptEntry.hasObject("qty")
scriptEntry.addObject("qty", arg.asElement().setPrefix("qty"));
}

else if (!scriptEntry.hasObject("delay") && arg.matchesArgumentType(Duration.class)
&& arg.matchesPrefix("delay", "d")) {
scriptEntry.addObject("delay", arg.asType(Duration.class));
}

else {
arg.reportUnhandled();
}
Expand Down Expand Up @@ -110,14 +113,16 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element speed = scriptEntry.getElement("speed");
List<dItem> items = (List<dItem>) scriptEntry.getObject("item");
dEntity entity = (dEntity) scriptEntry.getObject("entity");
Duration delay = (Duration) scriptEntry.getObject("delay");


// Report to dB
dB.report(scriptEntry, getName(),
action.debug() + location.debug() + qty.debug()
+ (items != null ? aH.debugList("items", items) : "")
+ (entity != null ? entity.debug() : "")
+ (speed != null ? speed.debug() : ""));
+ (speed != null ? speed.debug() : "")
+ (delay != null ? delay.debug() : ""));

dList entityList = new dList();

Expand All @@ -138,6 +143,9 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
dEntity e = new dEntity(location.getWorld().dropItem(location, item.getItemStack()));
if (e.isValid()) {
e.setVelocity(e.getVelocity().multiply(speed != null ? speed.asDouble() : 1d));
if (delay != null) {
((Item) e.getBukkitEntity()).setPickupDelay(delay.getTicksAsInt());
}
}
entityList.add(e.toString());
}
Expand Down

0 comments on commit b5c7cc6

Please sign in to comment.