Particles on chest containing items

Discussion in 'Plugin Requests' started by JustDJplease, Nov 6, 2015.

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


    Plugin category: General/Mechanics

    Suggested name: ParticleChests

    What I want: I would like a plugin that sets particles on chests containing items. The type of particles, the speed of the particles and the amount can be configured in a config, and there should only be particles on chests (not trapped) that contain items. Also, the particles should dissapear whenever the chest dissapears/ is broken.

    Ideas for commands: No commands needed for this plugin.

    Ideas for permissions: No permissions needed for this plugin

    When I'd like it by: I would love it if someone could make this within a week :).

    Screenshots to visualize what i mean:
    Image (open)

    I used /particle crit ~4 ~ ~ 0 0 0 0.5 100 with a redstone clock to simulate the particles on the chest in the screenshot

    Thanks in advance!
  2. Offline


    I like this idea! I hope someone code this!
  3. Offline


    I love the idea but I have no clue how to use particle effects.
  4. Offline


    I will code it.
    JustDJplease likes this.
  5. Offline



    Keep us posted. I hope you come up with something. Don't forget about minecart with chest too!
  6. Offline


    I am curious on how would you track the chests to determine if you would to play an effect on it, @iwuvbubbles.
  7. Offline


    @Chloe-chan I would probably use this:
        public void onInventoryOpenEvent(InventoryOpenEvent e){
            if (e.getInventory().getHolder() instanceof Chest || e.getInventory().getHolder() instanceof DoubleChest){
    I just have no idea how to create particle effects.
  8. Offline


    I see! I'll attempt to do this plugin if @iwuvbubbles can't do it.
  9. Offline


    @iwuvbubbles Thank you! I would love it if you could keep us updated on this! @madtomic I forgot about the minecartchests! Thank you for the remider!
  10. Offline


    To make this easier on some devs: Iterate through all the worlds' chunks, calling getTileEntities() on each one to get every tile entity, then just check if the material is a chest. If you find a chest, stick a BukkitRunnable on it that has a valid check (is a chest in a loaded chunkand has items), and plays the particle effect.

    You can also check the InventoryCloseEvent to see if the chest interacted with has items in it and, if so, add a particle effect to it.

    EDIT: If you plan to do a chest scan in your onEnable, be sure to set your plugin to load POSTWORLD in the plugin.yml

    Sidenote: Using getLoadedChunks() only returns loaded chunks so you may need to check chunks as they load for more chests
    MasterDoctor and JustDJplease like this.
  11. Offline


    This probably won't work because it would only run the code if someone opened the chest.
    And it would only show the effects to the player.
    So the particles would only show if you had opened that chest already.
  12. Offline


    @MasterDoctor I was saying to use this to register where the chest was and if it was filled or not. It would have to be tied to another event to send the effects
  13. Offline


    Here is an example of how to make the runnable for anyone who thinks that you can't loop this without events (*cough* @OkinawaBoss *cough*):
    Show Spoiler

    import org.bukkit.Material;
    import org.bukkit.block.Chest;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.scheduler.BukkitRunnable;
    public class TestChestParticles extends BukkitRunnable {
        private Chest chest;
        public TestChestParticles(Chest chest) {
            this.chest = chest;
        private boolean isValid() {
            if (!chest.getChunk().isLoaded()) return false; // The chunk is not loaded, do not use this
            if (chest.getBlock().getType() != Material.CHEST) return false;// The block changed and is no longer a chest
            for (ItemStack item : chest.getBlockInventory().getContents()) {
                if(item == null || item.getType() == Material.AIR) continue; // We only want to know if there is an item in it and use this check since the itemstack is a solid array of size Inventory#getSize()
                return true; // It has at least one item in it and is a chest, which makes it valid
            return false; // The chest is empty
        public void run() {
            if(!isValid()) {
                chest = null;
                // Stop everything immediately, we have no reason to continue without a chest
            // Play particle effects after the check

    And then you would just call it with this:
    new TestChestParticles(chest).runTaskTimer(plugin, 0, 2);
    // Where 'chest' is the chest object, 'plugin' is an instance of your main class, and 2 is the delay between particle effects in ticks
  14. Offline


    Oh, OK
  15. Offline


    @iwuvbubbles @Chloe-chan How is it going IwuvBubbles? Can you keep us updated, Cloe-Chan can you possibly take over the plugin coding, since Iwuvbubbles does not seem to respond anymore?

    Thanks in advance :p
  16. Offline


    So, anyone was able to do this yet? :rolleyes:
  17. Offline


    Apparently not @madtomic ..., but I really hope @Chloe-chan will consider it.
  18. Offline


    Hi, sorry for the delayed reply. Somehow I was not notified at all from your tags. I'll try my best to make this plugin, but no guarantees. I've got loads of school assignments to complete too.
    JustDJplease likes this.
  19. Offline


    @Chloe-chan Thank you very much and I wish you best of luck with your assignments!
  20. Offline


  21. Offline


    Some questions I would like to clarify. (I'll update this list when there are more)
    1. What version of the server are you running on ? Spigot 1.8.8 ?
  22. Offline



    Can you please add support for 1.7.10?
  23. Offline


    Well... the particles library available in the API is limited on Bukkit server. I'll try the NMS approach if necessary.
  24. Offline


    1) I am running the newest Spigot (currently 1.8.8)

  25. Offline


    I've finished the barebones of the plugin. I have not added a world scan for chests and a cleaner way to remove chests from the memory. It is also not very optimised yet, but it shouldn't cause a huge problem. This plugin is built on 1.7.9 Bukkit, and utilises @DarkBladee12's ParticleEffect Library.
    Download link here, hosted by Dropbox. <- will be updated when there is a new version

    Commands added:
    None as of yet.

    Permissions added:
    None as of yet.

    Files added:
    • config.yml - Configs for this plugin, including the particles to be used. (sorry for the lengthy config file!)
    • chest-location-list.dat - Save file for the list of chest locations. (serialised array list)

    Show Spoiler
    Built on:
    • Java 1.7
    • Bukkit 1.7.9
    Tested on:
    • Java 1.8
    • Spigot-1.8.8

    To-do list:
    This is not a compulsory list for me, and I can't guarantee I'll accomplish these tasks.
    Show Spoiler

    • Background world scan for chests to play the particles
    • Occasional checks if the list is credible (if the chests in the list still exists)
    • Commands to change particle effects

    How does this plugin work? (open)
    Apparently not explaining how does this plugin works internally will cause lots of discussion. So here's how this specific plugin keeps track of chests.

    During load
    At the start of the loading, I'm deserialising the save file to get the previously stored chest lists. I've then set up a scheduler task to loop through the list of chests and play particle effects. I've set around 5 seconds of delay before the task starts to reduce lag when server is still handling other plugins.

    On chest placed, BlockPlacedEvent with checks if the block is a chest, is set up to add that location into the list.

    On chest break, BlockBreakEvent with checks if the block is a chest, removes the location from the list.

    On chest open, InventoryOpenEvent with checks if the block is a chest, adds the location to the list.

    During the scheduler task attempts to play particles, it loops through the list and remove and location that did not have chests. It only play particles if there are at least one item in the chest.

    During disable
    Stops the scheduler task and proceeds to serialise the list, and store it.

    Why scan the world?
    What if, and obviously will be, this plugin is installed after the world is made ? What if there are chests that could mean a lot (such as the best loot in the mini-game) and requires it to be playing effects ? There are times where chests could have no events involving them for a really long time, but that doesn't mean it shouldn't have particles!
    Last edited: Nov 23, 2015
  26. Offline


    Why are you scanning the worlds for chests? There's much easier and less resource consuming ways to do it...
  27. Offline


    Why don't you tell me then ? What should I do ?
  28. Offline

    timtower Administrator Administrator Moderator

    Probably listening to chest placement right @Commander9292 ?
    But there are more ways, listen for chunk load and if not checked already: check if there are chests.
    Interact event on the chest itself.
  29. Offline


    @timtower @Chloe-chan

    I'd use InventoryCloseEvents, and here's how I would do it:

    Create a cache and listen for InventoryCloseEvent's, loop through the inventory that was closed, if it contains items create a Bukkit scheduler and a unique id for the task. Store the chest and the unique task id in a cache, on the next InventoryCloseEvent if the inventory is empty check if it is in the cache. If so cancel the task using the cached task id for this chest and remove it from the cache. In your onDisable() method loop through the cache and store all serialized locations of chests. In the onEnable() method you need to read in each of these locations and deserialize them, check if the chest still exists, and create a new unique scheduler id for it and store it back into the cache.

    We can guarantee that the chest location we're reading in has items in it if it still exists, because our cache only contained chests with items in it to begin with.

    Edit: Sorry for such a long explanation, and sounding slightly condescending.
    Edit 2: I can write this plugin up when I get home later if you would like to see.
    oceantheskatr likes this.
  30. Offline

    timtower Administrator Administrator Moderator

    oceantheskatr likes this.
Thread Status:
Not open for further replies.

Share This Page