Question Lightning on right-click?

Discussion in 'Plugin Help/Development/Requests' started by Exellanix, Jan 23, 2016.

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

    Exellanix

    I'm new to developing plugins and I decided to make a kit pvp plugin for my server. I want a Zeus kit. I want it so the if you right-click a diamond axe it would strike lightning at the player or the ground where you're looking. Can someone help me with the code?

    Here is the Zeus class:

    Code:
    package me.exellanix.kitpvp.commands;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    
    public class Zeus implements CommandExecutor {
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (label.equalsIgnoreCase("zeus"))
                if (!(sender instanceof Player)) {
                    sender.sendMessage("You must be a player to execute this command!");
    
                    return false;
                }
    
            Player player = (Player) sender;
            PlayerInventory inv = player.getInventory();
            // clears player inv
            inv.clear();
    
            ItemStack diamondAxe = new ItemStack(Material.DIAMOND_AXE);
            ItemStack mushroomStew = new ItemStack(Material.MUSHROOM_SOUP, 35);
            ItemStack ironHelmet = new ItemStack(Material.DIAMOND_SWORD);
            ItemStack ironChestplate = new ItemStack(Material.DIAMOND_SWORD);
            ItemStack ironLeggings = new ItemStack(Material.DIAMOND_SWORD);
            ItemStack ironBoots = new ItemStack(Material.DIAMOND_SWORD);
    
            diamondAxe.addEnchantment(Enchantment.DAMAGE_ALL, 2);
    
            inv.addItem(diamondAxe, mushroomStew);
            inv.setHelmet(ironHelmet);
            inv.setChestplate(ironChestplate);
            inv.setLeggings(ironLeggings);
            inv.setBoots(ironBoots);
    
            player.sendMessage(ChatColor.GOLD + "You have chosen the kit " + ChatColor.YELLOW + "Zeus");
    
            return true;
    
        }
    }
     
  2. Offline

    MrTigreroux

    Here you are the event of right clicking with a diamond axe:
    Code:
    @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            if(p.getItemInHand().getType() == Material.DIAMOND_AXE && (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR)) {
                int MaxRange = 25;
                for(Block b : p.getLineOfSight((HashSet<Byte>) null, MaxRange)) {
                    if(b.getType() != Material.AIR) {
                        p.getWorld().strikeLightning(b.getLocation());
                        return;
                    }
                }
            }
    }
     
    Last edited: Jan 29, 2016
  3. Offline

    Exellanix

    Thank you so much!
    But now how can I add a cool down of like 20 seconds?
     
  4. Offline

    MrTigreroux

Thread Status:
Not open for further replies.

Share This Page