How do I keep an Item drop from expiring?

Discussion in 'Plugin Development' started by xKYLERxx, Dec 19, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    xKYLERxx

    So, I'm making a shop plugin (yes I know there are thousands) and I am going to have the items displayed as org.bukkit.entity.Items. I coded everything, the Items aren't pick-upable and they center themselves on the block. But I need to make it so after five minutes, they don't die. I couldn't find anything to cancel it so I tried ENTITY_DEATH only to realize that it doesn't have a .setCanceled(true); method. So what even, if any would tell me when an Item is about to expire?
     
  2. Offline

    dbizzzle

    You could just start a runnable/schedular and then every 5 minutes spawn one in the same spot
     
  3. Offline

    xKYLERxx

    How do I run a "runnable/schedular"?
     
  4. Offline

    user_43347

    I believe, under onPlayerItemDrop, you can get the item and set it's time, which, is not a very good idea, considering those items are just building up and can lag the server, but it is possible. I would personally run a scheduler every few minutes, get every item in world, and reset its life time.

    Edit: http://wiki.bukkit.org/Scheduler_Programming (Look for repeating tasks.)
     
  5. Offline

    dbizzzle

    Ah, didn't realize you could set the life time.
     
  6. Offline

    user_43347

    Just for reference, its...
    Code:
    Item i = event.getItem();
    i.setTicksLived(0);
    And since items expire after 5 minutes, and theirs 20 ticks per second, an item survives for 6000 ticks. So..
    Code:
    Item i = ev.getItem();
    if (i.getTicksLived() == 6000) {
        i.setTicksLived(0);
    }
     
  7. Offline

    dbizzzle

  8. Offline

    user_43347

    Whoops :p, lemme fix it.
    Edit: Fixed.
     
  9. Offline

    dbizzzle

Thread Status:
Not open for further replies.

Share This Page