title: How to modify an event through a Runnable
body: <p>I have a runnable that fires on an event. I am trying to get a list from the event and clear it, but put the list in Metadata storage in the entity that is created during the event. So far I have tried:</p>
  
  <p>Note: the class this is in implements and is an event listener.</p>
  
  <pre><code>@EventHandler
  public synchronized void playerDeathEvent(final EntityDeathEvent event) {
  
      Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
          public void run() {
              Entity p = event.getEntity();
              // Spawn the Firework, get the FireworkMeta.
              Firework fw = (Firework) p.getWorld().spawnEntity(p.getLocation(), EntityType.FIREWORK);
              FireworkMeta fwm = fw.getFireworkMeta();
  
              // Our random generator
              Random r = new Random();   
  
              // Get the type
              int rt = r.nextInt(4) + 1;
              Type type = Type.BALL;       
              if (rt == 1) type = Type.BALL;
              if (rt == 2) type = Type.BALL_LARGE;
              if (rt == 3) type = Type.BURST;
              if (rt == 4) type = Type.CREEPER;
              if (rt == 5) type = Type.STAR;
  
              //Get our random colors   
              int r1i = r.nextInt(15) + 1;
              int r2i = r.nextInt(15) + 1;
              Color c1 = getColor(r1i);
              Color c2 = getColor(r2i);
  
              // Create our effect with this
              FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
  
              // Then apply the effect to the meta
              fwm.addEffect(effect);
  
              // Generate some random power and set it
              int rp = r.nextInt(2) + 1;
              fwm.setPower(rp);
  
              // Then apply this to our rocket
              fw.setFireworkMeta(fwm);  
              // Clear drops and set the drops to be released on explosion
  
              //TODO: fix problem where list is cleared before put into Metadata
              List&lt;ItemStack&gt; list = new ArrayList&lt;ItemStack&gt;();
              for (ItemStack stack : event.getDrops())
                  list.add(stack);
              fw.setMetadata("dropItems", new FixedMetadataValue(GLDPlugin, list));
              event.getDrops().clear();
              forceDelete(event);
          }
      });
  
  }
  
  public void forceDelete(EntityDeathEvent event) {
      for (int i = 0; i &lt; event.getDrops().size(); i++)
          event.getDrops().remove(i);
  }
  </code></pre>
  
  <p>And (just the last section):</p>
  
  <pre><code>            @EventHandler
              public synchronized void onEntityDeath(EntityDeathEvent evt)
              final EntityDeathEvent event = evt;
  
              //No code in this section was changed from the code above.
  
              //TODO: fix problem where list is cleared before put into Metadata
              List&lt;ItemStack&gt; list = new ArrayList&lt;ItemStack&gt;();
              for (ItemStack stack : event.getDrops())
                  list.add(stack);
              fw.setMetadata("dropItems", new FixedMetadataValue(GLDPlugin, list));
  
          }
      });
      evt = event;
      evt.getDrops().clear();
      forceDelete(evt);
  }
  </code></pre>
  
  <p>In the top one, it will NOT clear <code>event.getDrops()</code> and WILL put <code>list</code> into the entity's metadata, duplicating <code>event.getDrops()</code>. In the bottom example, it WILL clear <code>event.getDrops()</code> but will NOT put <code>list</code> into the entity's metadata, obliterating <code>event.getDrops()</code>. Both of these outputs are unacceptable, as this causes no items or double items to be spawned. Any ideas?</p>
  
  <p>Edit: Better explanation for those of you who are more bukkit-savvy:</p>
  
  <p>I am trying to make it so the player does not drop items on death, but they are still removed from their inventory. I also need it so the <code>List&lt;ItemStack&gt;</code> is put into the spawned firework's metadata.</p>