Solved Canceling a Runnable

Discussion in 'Plugin Development' started by lewysryan, May 14, 2014.

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

    lewysryan

    Code:java
    1. ItemStack apowerup = new ItemStack(Material.ARROW, 3);
    2. final Item a = loc.getWorld().dropItem(loc, apowerup);
    3. task1 = Bukkit.getScheduler().scheduleSyncRepeatingTask((Plugin) HGTraining.getPluginInstance(), new Runnable(){
    4.  
    5. @Override
    6. public void run() {
    7. if(a.isDead()){
    8. Bukkit.getScheduler().cancelTask(task1);
    9. }
    10. ParticleEffect.INSTANT_SPELL.display(a.getLocation(), 0.4F, 0.4F, 0.4F, 1, 20);
    11.  
    12. a.getWorld().playSound(a.getLocation(), Sound.FIREWORK_BLAST, 2.0F, 2.0F);
    13. }
    14. }, 0, 10);


    It works great however, it don't cancel if more than one item is picked up together :/ What's the best way to do this?

    I have tried:
    Code:java
    1. if(a.isOnGround()){
    2. if(a == null){
    3. if(a.isValid){
    4. if(a.isEmpty){
    5.  
    6.  

    Also when a person picks the power up it removed it.
    Code:java
    1. @EventHandler
    2. public void itempickup(PlayerPickupItemEvent e){
    3. Player p = e.getPlayer();
    4.  
    5. if(e.getItem().getItemStack().getType() == Material.ARROW){
    6. Item a = e.getItem();
    7. e.getItem().remove();
    8. e.setCancelled(true);
    9. }
    10. }
     
Thread Status:
Not open for further replies.

Share This Page