Lightning code

Discussion in 'Plugin Development' started by Phaluh, Apr 24, 2014.

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

    Phaluh

    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?
     
  2. Offline

    BillyBobJoe168

    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.
     
  3. Offline

    coolguy4744

    There is also lore is you want that, if not just remove it.

    Code:java
    1. event.getPlayer().getInventory();
    2. ItemStack i = new ItemStack(Material.STONE_AXE);
    3. ItemMeta m = i.getItemMeta();
    4. m.setDisplayName(ChatColor.(Insert) + "[Thor's Hammar]");
    5. List<String> lore = new ArrayList();
    6. lore.add(ChatColor.(Insert) + "<text>");
    7. m.setLore(lore);
    8. i.setItemMeta(m);
    9. event.getPlayer().getInventory().addItem(new ItemStack[] { i });
    10. }
    11. }
    12.  
     
  4. Offline

    Deleted user

Thread Status:
Not open for further replies.

Share This Page