Removing items on gorund

Discussion in 'Spigot Plugin Development' started by DaanSander, May 23, 2015.

  1. Hello I was just messing around when I mentioned that the items that are in my arraylist are not removing when i call my remove method I altready tried to loop through all the items and set them to null but that did not work can someone help me with remeving these itemstacks of the ground

    Code (Text):
    private ArrayList<ItemStack> items = new ArrayList<ItemStack>();

            public void setUp() {
            final Location location = arena.getEggWave();
            final Random random = new Random();
            anInt = timer;
            eggTask = Bukkit.getScheduler().runTaskTimer(Farm.getPlugin(), new Runnable() {
                public void run() {
                    if(!(anInt >= 10)) {
                        int a = (int) location.getX();
                        int z = (int) location.getZ();
                        int aa = random.nextInt(10) + a;
                        int zz = random.nextInt(10) + z;
                        Location eggloc = new Location(location.getWorld(), aa, location.getY(), zz);
                        ItemStack egg = new ItemStack(Material.EGG);
                        ItemMeta meta = egg.getItemMeta();
                        meta.setDisplayName("" + anInt);
                        Item i = location.getWorld().dropItem(eggloc, egg);
                    } else {
            },0L ,20L);


        public void endEggTask() {
            for(ItemStack item : items) {
                if(item != null) {
                    item = null;
    Sorry for bad english
  2. Hi Daan!

    It seems that your are confused between two classes:

    - ItemStack: represents a held stack of items which can be placed into an inventory.
    - Item: a type of Entity, that floats around and hopes it will one day be picked up.

    Rather than storing the ItemStack in your ArrayList, add the result of the dropItem() method, which is an Item.

    Calling the .remove() method will then make it be removed from the ground.