Skip to content

Commit

Permalink
displayitem duration:infinite
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 11, 2021
1 parent ef1d202 commit c30dcb9
Showing 1 changed file with 13 additions and 8 deletions.
Expand Up @@ -47,8 +47,10 @@ public DisplayItemCommand() {
//
// @Description
// This command drops an item at the specified location which cannot be picked up by players.
//
// It accepts a duration which determines how long the item will stay for until disappearing.
// If no duration is specified the item will stay for 1 minute, after which the item will disappear.
// Use "duration:infinite" to indicate that the item should never remove itself.
//
// @Tags
// <EntityTag.item>
Expand Down Expand Up @@ -161,20 +163,23 @@ public void execute(ScriptEntry scriptEntry) {
dropped.setVelocity(new Vector(0, 0, 0));
dropped.setGravity(false);
dropped.setPickupDelay(32767);
NMSHandler.getEntityHelper().setTicksLived(dropped, -duration.getTicksAsInt());
int ticks = duration.getTicksAsInt();
NMSHandler.getEntityHelper().setTicksLived(dropped, ticks <= 0 ? -32768 : -ticks);
if (!dropped.isValid()) {
Debug.echoDebug(scriptEntry, "Item failed to spawned (likely blocked by some plugin).");
return;
}
final UUID itemUUID = dropped.getUniqueId();
protectedEntities.add(itemUUID);
scriptEntry.addObject("dropped", new EntityTag(dropped));
Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(),
() -> {
protectedEntities.remove(itemUUID);
if (dropped.isValid() && !dropped.isDead()) {
dropped.remove();
}
}, duration.getTicks());
if (ticks > 0) {
Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(),
() -> {
protectedEntities.remove(itemUUID);
if (dropped.isValid() && !dropped.isDead()) {
dropped.remove();
}
}, ticks);
}
}
}

0 comments on commit c30dcb9

Please sign in to comment.