remove an item

Discussion in 'Plugin Development' started by 15987632, Aug 10, 2014.

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

    15987632

    ok so this is what i have run if a player right clicks a piston this runs

    Code:java
    1. for (int x1 = 0; x1 <= 70; x1 += 10) {
    2. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    3.  
    4. public void run() {
    5. Collections.shuffle(list);
    6. ItemStack rItem = new ItemStack(list.get(0), 1);
    7. world.dropItem(newLoc, rItem);
    8.  
    9. }
    10. }, x1);
    11. }

    i have an array list that i shuffle then take a value from and the goal was to get a mysterybox feel to it and have items flashing above the piston. My problem is that i cant think of a way to remove the item. I planed in another delayed task inside that delayed task removing the item but you cant do that. Any ideas?
     
  2. Offline

    Forseth11

    15987632 simply do rItem.remove();
    Edit: My bad. I meant:
    Code:java
    1. Item i = world.dropItem(newLoc, rItem);
    2. i.remove();


    Also if you want to remove it later then make a variable outside of the run method and just change that each time run is called and remove it before you change it again.
     
  3. Offline

    15987632

    Forseth11 wont it just remove the item right away? i want to remove the item 10 ticks after i create it
     
  4. Offline

    Forseth11

    15987632 In that case do this:
    Code:java
    1. for (int x1 = 0; x1 <= 70; x1 += 10) {
    2. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    3. private Item i = null;
    4. public void run() {
    5. if(i != null){
    6. i.remove();
    7. }
    8. Collections.shuffle(list);
    9. ItemStack rItem = new ItemStack(list.get(0), 1);
    10. i = world.dropItem(newLoc, rItem);
    11.  
    12.  
    13. }
    14. }, x1);
    15. }
     
  5. Offline

    15987632

    Forseth11 wouldnt that leave the last item not removed?
     
  6. Offline

    Forseth11

    Yes it would. In that case make Item i in your class so when you cancel the loop (Which btw your task will only run once since it is a delayedTask) you could remove the item.
     
  7. Offline

    15987632

    Forseth11 its in a for loop it should run a few times but i do get what ur saying thanks :)
     
  8. Offline

    Forseth11

    Yes ik the for loop. The for loop is just going to run in several milliseconds then all those delayedTasks will run at the same time. You need to use a delayed repeated task.
     
  9. Offline

    15987632

    Forseth11 all the delayed tasks will run 10 ticks behind each other ive tested that part and its worked before
     
  10. Offline

    Forseth11

    Oh you are right just read the contents of your for loop. My bad.
     
    15987632 likes this.
Thread Status:
Not open for further replies.

Share This Page