Solved The lightning bolt event does'nt occur!

Discussion in 'Plugin Development' started by TheMintyMate, Mar 24, 2014.

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

    TheMintyMate

    I am having issues with the following event not occurring:
    Code:java
    1. package com.-----------------------------;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.player.PlayerInteractEvent;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public final class Main extends JavaPlugin {
    10. @Override
    11. public void onEnable(){
    12. getLogger().info("Rod lightning has been Enabled!");
    13.  
    14. }
    15. @Override
    16. public void onDisable(){
    17. getLogger().info("Rod lightning has been Disabled!");
    18. }
    19. @SuppressWarnings("deprecation")
    20. @EventHandler
    21. public void onPlayerInteractBlock(PlayerInteractEvent event) {
    22. Player player = event.getPlayer();
    23. if (player.getItemInHand().getType() == Material.FISHING_ROD) {
    24. // Creates a bolt of lightning at a given location.
    25. // Can only create lightning up to 200 blocks away.
    26. player.getWorld().strikeLightning(player.getTargetBlock(null, 200).getLocation());
    27. }
    28. }
    29. }
    30.  

    When I compile the code no errors occur, and the plugin loads up fine in the console. However when it comes to testing the code, no lightning appears. What am I doing wrong? Thank-you in advance :)
    Note: "getTargetBlock" is in deprecation, what can I do about this?
     
  2. Offline

    rfsantos1996

    "getServer().getPluginManager().registerEvents(this, this);" on onEnable

    and "extends JavaPlugin implements Listener"

    And maybe, check if the block is null or not. I belive if the player looks up, it'll throw an exception
     
    TheMintyMate likes this.
  3. Offline

    TheMintyMate

    Thank-you :) Il attempt with your suggestion.

    I have updated the code, and Im happy to say it now works. Thank-you for your comment about the player looking up, your correct :)

    I Wanted to ask, is it possible to disable the noise of the bolt, or at least lower the volume?

    I just wanted to check a few last things ( Im new to Bukkit coding):

    •How do I add a cool down before the lightning strike can be used again?
    •And Is there anything I can do to deal with the deprecation?
    •Can the Bolt volume be lowered?

    Thank-you for your time,
    Minty :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page