Need help with Lightning summoning code

Discussion in 'Plugin Development' started by gabe4356, Aug 31, 2014.

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

    gabe4356

    So, I made a simple plugin where the player is given a Diamond Axe if they type /thor and if they right click with the axe, it is supposed to spawn lightning where they right clicked, but I can't get it to work! Please help?
    This is my code:
    Code:
    package com.gabe.thor;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Thor extends JavaPlugin {
       
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onPlayerInteractBlock(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            if (player.getItemInHand().getType() == Material.DIAMOND_AXE) {
                player.getWorld().strikeLightning(player.getTargetBlock(null, 15).getLocation());
            }
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            Player player = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("ThoR")){
                player.sendMessage(ChatColor.DARK_AQUA+ "You have been given Thors hammer, right click to use it! MUST BE 15 BLOCKS AWAY FROM YOU!");
                player.getInventory().addItem(new ItemStack(Material.DIAMOND_AXE));
           
            }
            return true;
        }
               
                public void onDisable() {
                    //On Disable method stub
                }
     
                public void onEnable() {
                  //on Enable Method stub
                    {
            }
        }
     
    }
    
     
  2. Offline

    mine-care

    You haven't registered events onenable

    Also PLEASE read my signature about casting sender to player!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  3. Offline

    gabe4356

    Woops, thanks!
     
  4. Offline

    mine-care

Thread Status:
Not open for further replies.

Share This Page