Solved Drops will not remove in unloaded chunks

Discussion in 'Plugin Development' started by WiseHollow, Jan 4, 2015.

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

    WiseHollow

    I have a chestshop system where there is a display item above each chest. Every 60 seconds, they chests refresh; meaning the item on top, gets removed and a new one spawns.

    Code:
    public Boolean loadShop()
        {
            if (this.location.getBlock().getType() != Material.CHEST && this.location.getBlock().getType() != Material.TRAPPED_CHEST) { this.deleteChestShop(); return false; }
            if (!this.location.getChunk().isLoaded()) { return false; }
            this.displayItem = new DisplayItem(this.getItemStack(1), this);
            return true;
        }
       
        public void unloadShop()
        {
            if (this.displayItem == null || this.displayItem.getItem() == null || this.displayItem.getItem().isDead()) { return; }
            this.displayItem.getItem().remove();
        }
    
    And here is my timer...
    Code:
    public static void startChestShopRefreshTimer()
        {
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(ProjectTowns.getPlugin(), 
                    new Runnable() 
                    {
                        @Override
                        public void run() 
                        {
                            int count = 0;
                            for (ChestShop shop : ChestShop.getAllChestShops())
                            {
                                shop.unloadShop();
                                if (shop.loadShop() == true)
                                {
                                    count++;
                                }
                            }
                            Output.logOutputWarning("Chests Refreshed: " + count);
                        }  
                    } , 1200L, 1200L);
        }
    
    Why is it that, when the chunk is unloaded, the display item does not despawn? I login, and see duplicates of the item on top of each other. Is there a way to fix this?
     
  2. Offline

    MisterErwin

    @WiseHollow
    I'm just guessing that an Item in an unloaded chunk makes your plugin "return" -
    And my guess is, that it is this part.

    You might want to debug this (or remove it)
     
  3. Offline

    WiseHollow

    @MisterErwin I removed that line of code and still suffer from the problem.
     
  4. Offline

    MisterErwin

  5. Offline

    WiseHollow

    @MisterErwin Okay. I changed it to this..

    Code:
    public void unloadShop()
        {
            if (this.displayItem == null || this.displayItem.getItem() == null) { return; }
            if (!this.location.getChunk().isLoaded()) { location.getWorld().loadChunk(this.location.getChunk()); }
            this.displayItem.getItem().remove();
        }
    
    And now I get a NPE for this line of code
    Code:
    this.displayItem.getItem().remove();
    
    I got it solved.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 31, 2016
  6. Offline

    MisterErwin

    @WiseHollow And don't forget to mark the thread as Solved ;)

    And sorry I couln't help - I was kinda tired ;)
     
    WiseHollow likes this.
Thread Status:
Not open for further replies.

Share This Page