I have been looking everywhere for a working lightning code for my plugin. i want to to strike lightning on the target block but dont know how. i am kind of new to this. this is my code which i found but doesn't do as i want it to. Code: @EventHandler public void onPlayerInteract(PlayerInteractEvent event){ Player player = event.getPlayer(); if(event.getAction().equals(Action.RIGHT_CLICK_AIR) && player.getItemInHand().getType() == Material.STONE_AXE){ Player[] pl = event.getPlayer().getServer().getOnlinePlayers(); Vector p_vec = event.getPlayer().getLocation().toVector(); for(int i = 0; i<pl.length;i++){ if(p_vec.distance(pl[i].getLocation().toVector())<15D){ event.getPlayer().getWorld().strikeLightning(pl[i].getLocation()); } } } } I also need help on naming items so say i wanted to name a stone axe [Thor's Hammer] how would i do that?
Can I ask how you got line 5? You might want to learn about event handling. For renaming items, you change the display name which is an item meta of an item. You can also change the lore. You might want to check out a very cool website called google.
There is also lore is you want that, if not just remove it. Code:java event.getPlayer().getInventory(); ItemStack i = new ItemStack(Material.STONE_AXE); ItemMeta m = i.getItemMeta(); m.setDisplayName(ChatColor.(Insert) + "[Thor's Hammar]"); List<String> lore = new ArrayList(); lore.add(ChatColor.(Insert) + "<text>"); m.setLore(lore); i.setItemMeta(m); event.getPlayer().getInventory().addItem(new ItemStack[] { i }); } }