Solved Shoot lightning at target block

Discussion in 'Plugin Help/Development/Requests' started by ChintziSecilMC, Jun 29, 2015.

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

    ChintziSecilMC

    I was wondering how to shoot lightning at the block a player is looking at cause i updated my plugin to 1.8 and it seems the way u do it has changed so i was wondering if anyone know how to strike lightning at the block a player is looking at?
     
  2. Offline

    ArmyArmy

    Code:
      @EventHandler
       public void playerInteract(PlayerInteractEvent e){
         Player player = e.getPlayer();
         if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
           if(player.getItemInHand().getType() == Material.BLAZE_ROD){
             Block block = player.getTargetBlock(null, 50);
             player.getWorld().strikeLightningEffect(block.getLocation());
           }
         }
       }
    
    Untested, but I remember it was done this way.
     
  3. Offline

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives.
     
  4. Offline

    ChintziSecilMC

    It undnerlines Block block = player.getTargetBlock(null, 50); in red
    @ArmyArmy
     
  5. Offline

    ArmyArmy

    What does it say if you hove over it with your mouse?
    What version of Bukkit are you using?
    Alsou do you have these imports?
    Code:
    import org.bukkit.entity.Player;
    import org.bukkit.block.Block;
    
     
  6. Offline

    ChintziSecilMC

    @ArmyArmy it says: reference to getTargetBlock is ambiguous, both metho getTargetBlock(<HashSet<byte>, int) in living LivingEntity and method getTargetBlock(<SetMaterial>, int) in LivingEntity match.

    idk what that means, and yeah i have those imports
     
  7. Offline

    ArmyArmy

    Try this then
    Code:
      @EventHandler
       public void playerInteract(PlayerInteractEvent e){
         Player player = e.getPlayer();
         if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
           if(player.getItemInHand().getType() == Material.BLAZE_ROD){
             Set<Material> transparent = new HashSet<Material>();
             transparent.add(Material.AIR);
             Block block = player.getTargetBlock(transparent, 50);
             player.getWorld().strikeLightningEffect(block.getLocation());
           }
         }
       }
    
     
  8. Offline

    ChintziSecilMC

    @ArmyArmy it worked, thank you very much for your help have been trying to work this out for 2 days now, thanks again :D
     
  9. Offline

    ArmyArmy

    You're welcome :)
     
Thread Status:
Not open for further replies.

Share This Page