Advertisement
Guest User

Untitled

a guest
Nov 24th, 2015
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. JRL1004
  2. Here is an example of how to make the runnable for anyone who thinks that you can't loop this without events
  3.  
  4. import org.bukkit.Material;
  5. import org.bukkit.block.Chest;
  6. import org.bukkit.inventory.ItemStack;
  7. import org.bukkit.scheduler.BukkitRunnable;
  8.  
  9. public class TestChestParticles extends BukkitRunnable {
  10.  
  11. private Chest chest;
  12.  
  13. public TestChestParticles(Chest chest) {
  14. this.chest = chest;
  15. }
  16.  
  17. private boolean isValid() {
  18. if (!chest.getChunk().isLoaded()) return false; // The chunk is not loaded, do not use this
  19. if (chest.getBlock().getType() != Material.CHEST) return false;// The block changed and is no longer a chest
  20. for (ItemStack item : chest.getBlockInventory().getContents()) {
  21. 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()
  22. return true; // It has at least one item in it and is a chest, which makes it valid
  23. }
  24. return false; // The chest is empty
  25. }
  26.  
  27. @Override
  28. public void run() {
  29. if(!isValid()) {
  30. chest = null;
  31. cancel();
  32. return;
  33. // Stop everything immediately, we have no reason to continue without a chest
  34. }
  35. // Play particle effects after the check
  36. }
  37.  
  38. }
  39.  
  40.  
  41. And then you would just call it with this:
  42.  
  43. new TestChestParticles(chest).runTaskTimer(plugin, 0, 2);
  44. // 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