Solved Summoning a lighting bolt.

Discussion in 'Plugin Development' started by RauRogers, Jul 24, 2014.

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

    RauRogers

    Hello. I am trying to make a silly feature to my server where you right click with an axe with a certain item meta and it spawns a lighting bolt. Here is my code to spawn in the axe :


    Code:
    ArrayList<String> zeusLore = new ArrayList<String>();
            ItemStack zeusStaff = new ItemStack(Material.GOLD_AXE);
            ItemMeta zeusMeta = zeusStaff.getItemMeta();
            zeusMeta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "Zeus's Axe");
            zeusLore.add(ChatColor.YELLOW + "" + ChatColor.ITALIC + "Left Click to summon Lighting!");
            zeusMeta.setLore(zeusLore);
            zeusStaff.setItemMeta(zeusMeta);
            zeusStaff.addEnchantment(Enchantment.getById(17), 5);
           
                if (sender instanceof Player) {
                    Player player = (Player) sender;
        @SuppressWarnings("deprecation")
                if (command.getLabel().equalsIgnoreCase("Zeus")) {
                        player.sendMessage(ChatColor.YELLOW + "You have been given the power of " + ChatColor.BOLD + "Zeus.");
                        player.getInventory().addItem(zeusStaff);
                    }
    and here is my Event for when you left click the air:
    Code:
    @SuppressWarnings("deprecation")
            public void onClickZEUS(final PlayerInteractEvent e) {
               
                ArrayList<String> zeusLore = new ArrayList<String>();
                ItemStack zeusStaff = new ItemStack(Material.GOLD_AXE);
                ItemMeta zeusMeta = zeusStaff.getItemMeta();
                zeusMeta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "Zeus's Axe");
                zeusLore.add(ChatColor.YELLOW + "" + ChatColor.ITALIC + "Left Click to summon Lighting!");
                zeusMeta.setLore(zeusLore);
                zeusStaff.setItemMeta(zeusMeta);
                zeusStaff.addEnchantment(Enchantment.getById(17), 5);
               
                Player p = e.getPlayer();
                if (e.getAction() == Action.LEFT_CLICK_AIR) {
                    if (p.hasPermission("hc.gm")) {
                    if (e.getPlayer().getItemInHand() == zeusStaff) {
                    //this is where I don't know how to summon the lighting bolt
     
                    }
                }
                }
            }
    thanks in advance
     
  2. Offline

    Garris0n

    You could try a simple Google search...
     
  3. Offline

    RauRogers

    garrison I did. Only came up with other plugins.
     
  4. Offline

    xXRobbie21Xx

    Iv seen a plugin tutorial on youtube about this, im sure you can quickly find it. (Sorry i forgot it and dont know myself). Good luck!
     
  5. Offline

    Garris0n

  6. Offline

    JBoss925

  7. Offline

    Ozeir

    You should use:
    Playerinteractevent
    and how to strike a lightning bolt?
    location.getWorld().strikeLightning(loc);
    EDIT: Didn't see your posts sorry ;0
     
  8. Offline

    MCForger

    RauRogers
    Also you should really just have one instance of a Zeus ItemStack and just get it through a static/non-static method.
     
  9. Offline

    RauRogers

    JBoss925 Ozeir thanks for the response. Here is what I have now and still doesn't work.
    Code:java
    1. Player p = e.getPlayer();
    2. World world = p.getWorld();
    3. if (e.getAction() == Action.LEFT_CLICK_AIR) {
    4. if (p.hasPermission("hc.gm")) {
    5. if (e.getPlayer().getItemInHand() == zeusStaff) {
    6. Location location = p.getLocation();
    7. world.strikeLightning(location);
    8.  
    9. }
    10. }
    11. }


    MCForger wow I didn't even think of that hahaha thanks so much

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

    JBoss925

    Hmmmm…can we see the whole class?
    EDIT: Nvm got it.
    You should be checking in this instance the material of the zeus staff as well as the item meta.
     
  11. Offline

    RauRogers

    JBoss925 the whole class or just this?:
    Code:java
    1. @SuppressWarnings("deprecation")
    2. public void onClickZEUS(final PlayerInteractEvent e) {
    3.  
    4. ArrayList<String> zeusLore = new ArrayList<String>();
    5. ItemStack zeusStaff = new ItemStack(Material.GOLD_AXE);
    6. ItemMeta zeusMeta = zeusStaff.getItemMeta();
    7. zeusMeta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "Zeus's Axe");
    8. zeusLore.add(ChatColor.YELLOW + "" + ChatColor.ITALIC + "Left Click to summon Lighting!");
    9. zeusMeta.setLore(zeusLore);
    10. zeusStaff.setItemMeta(zeusMeta);
    11. zeusStaff.addEnchantment(Enchantment.getById(17), 5);
    12. Player p = e.getPlayer();
    13. World world = p.getWorld();
    14. if (e.getAction() == Action.LEFT_CLICK_AIR) {
    15. if (p.hasPermission("hc.gm")) {
    16. if (e.getPlayer().getItemInHand() == zeusStaff) {
    17. Location location = p.getLocation();
    18. world.strikeLightning(location);
    19.  
    20. }
    21. }
    22. }
    23. }
     
  12. Offline

    JBoss925

    It's fine, try this and tell us what it prints out in the server.
    Code:java
    1. @SuppressWarnings("deprecation")
    2. public void onClickZEUS(final PlayerInteractEvent e) {
    3.  
    4. ArrayList<String> zeusLore = new ArrayList<String>();
    5. Bukkit.broadcastMessage("1");
    6. ItemStack zeusStaff = new ItemStack(Material.GOLD_AXE);
    7. Bukkit.broadcastMessage("2");
    8. ItemMeta zeusMeta = zeusStaff.getItemMeta();
    9. Bukkit.broadcastMessage("3");
    10. zeusMeta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "Zeus's Axe");
    11. Bukkit.broadcastMessage("4");
    12. zeusLore.add(ChatColor.YELLOW + "" + ChatColor.ITALIC + "Left Click to summon Lighting!");
    13. Bukkit.broadcastMessage("5");
    14. zeusMeta.setLore(zeusLore);
    15. Bukkit.broadcastMessage("6");
    16. zeusStaff.setItemMeta(zeusMeta);
    17. Bukkit.broadcastMessage("7");
    18. zeusStaff.addEnchantment(Enchantment.getById(17), 5);
    19. Bukkit.broadcastMessage("8");
    20.  
    21. Player p = e.getPlayer();
    22. Bukkit.broadcastMessage("9");
    23. if (e.getAction() == Action.LEFT_CLICK_AIR) {
    24. Bukkit.broadcastMessage("10");
    25. if (p.hasPermission("hc.gm")) {
    26. Bukkit.broadcastMessage("11");
    27. if (e.getPlayer().getItemInHand() == zeusStaff) {
    28. Bukkit.broadcastMessage("12");
    29. //this is where I don't know how to summon the lighting bolt
    30.  
    31. }
    32. }
    33. }
    34. }
     
  13. Offline

    Ozeir

    RauRogers
    Try this:
    Code:java
    1. @EventHandler
    2. public void onPlayerInteractBlock(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4.  
    5. if (player.getItemInHand()getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.YELLOW + "" + ChatColor.BOLD + "Zeus's Axe")) {
    6. player.getWorld().strikeLightning(player.getTargetBlock(null, 200).getLocation());
    7. }
    8. }
     
  14. Offline

    RauRogers

    JBoss925 was something supposed to happen? nothing did.
     
  15. Offline

    Ozeir

    RauRogers
    Did you add the lightning in his code?

    And try mine if it didn't work..
     
  16. Offline

    RauRogers

    @Ozeir JBoss925 AH THANKS! Works great!​
     
    JBoss925 likes this.
  17. Offline

    Ozeir

    Glad I could help :)
     
Thread Status:
Not open for further replies.

Share This Page