Solved Do something for each block of a type placed?

Discussion in 'Plugin Development' started by JigokuSaru, May 6, 2015.

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

    JigokuSaru

    Ok, so i want to do something like when a, um.... for each ... redstone block is placed it does something for each i have it in a blockplaceevent as well but not sure how to get it for each
     
  2. Offline

    Signatured

    I'm not quite sure what you're asking.
     
  3. Offline

    JigokuSaru

    @Signatured um im trying to figure out how to say it. so ill give u my code here
    Code:
    @EventHandler
       public void onBlockPlace(BlockPlaceEvent e){
         loc = (Location) e.getBlock().getLocation().add(0.5,1,0.5);
         if(e.getBlock().getType() != null){
           if(e.getBlock().getType() == Material.ANVIL){
             
              id = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
               public void run(){
                 PE = new ParticleEffect(ParticleEffect.ParticleType.HEART, .5,1,0);
                 PE.sendToLocation(loc);
               }           
             }, 0, 20);
    
    Ok so this is a thing to give a particle effect to a block, the anvil, and i dont know how to make it so when i place a new anvil... the old anvil keeps its effects, the new anvil gets both its effect plus the old one.
     
  4. Offline

    mine-care

    @JigokuSaru so you want each anvil placed to have its own effects displayed?
    First let me sugest avoiding the creation of scheduled tasks in event handlers especially with an event fiery g so many times, instead have a repeating task onEnable and an arraylist holding all the locations where an anvil was recently placed to display the effect
     
  5. Offline

    mythbusterma

    @mine-care

    Why not? This makes more sense to me.
     
  6. Offline

    Corndogoz

    Mine-care is correct, you only want one loop, with a for loop like this: for(String s:list){
     
  7. Offline

    mine-care

    @mythbusterma err firstly because the sheduler 's I'd is stored in a class variable (see Id = ...) and if someone decides to build an anvil house for example the schedulers will be a load for the server
    The other solution has flaws too since it runs all time but with some optimization it can be made efficient.
    :D
     
Thread Status:
Not open for further replies.

Share This Page