Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- JRL1004
- Here is an example of how to make the runnable for anyone who thinks that you can't loop this without events
- 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
- }
- @Override
- public void run() {
- if(!isValid()) {
- chest = null;
- cancel();
- return;
- // 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement