Solved Lightning strike on right click. I'm new writing minecraft plugin :/

Discussion in 'Plugin Development' started by ThemisH, May 29, 2020.

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

    ThemisH

    I'm very new to Java and writing a minecraft plugin. I don't know much in English. I wrote a code like this but it doesn't work. I did not understand where the problem is. I thank everyone who helped.

    PHP:
    package me.stick.pro;

    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;

    public class 
    StickPROListener implements Listener {
       
        @
    EventHandler
        
    public void Click(PlayerInteractEvent event){
            
    ItemStack strikestick = new ItemStack(Material.STICK);
            
    ItemStack fireballstick = new ItemStack(Material.STICK);
            
    ItemStack snowstick = new ItemStack(Material.STICK);
            
    ItemMeta strikemeta strikestick.getItemMeta();
            
    ItemMeta fireballmeta fireballstick.getItemMeta();
            
    ItemMeta snowmeta snowstick.getItemMeta();
            
    strikemeta.setDisplayName("§f§bStrike Stick");
            
    fireballmeta.setDisplayName("§f§bFireball Stick");
            
    snowmeta.setDisplayName("§f§bSnowball Stick");
            
    strikestick.setItemMeta(strikemeta);
            
    fireballstick.setItemMeta(fireballmeta);
            
    snowstick.setItemMeta(snowmeta);
            if(
    event.getItem().getType() == Material.STICK) {
                if(
    event.getItem().getItemMeta() == strikemeta) {
                    
    Player p event.getPlayer();
                    if(
    event.getAction() == Action.RIGHT_CLICK_AIR) {
                        
    p.getWorld().strikeLightning(p.getTargetBlock(null50).getLocation());
                    }
                }
            }
        }

    }
     
  2. Offline

    KarimAKL

    @ThemisH
    1. Compare ItemMeta with #equals(), not with ==.
    2. Use the ChatColor enum for colors, not '§'.
    3. You should create the items outside the event method, otherwise you'll create them everytime you click.
     
  3. Offline

    EpicGodMC

    you probably shouln't create itemstacks just to compare them and check if players are using the right item, instead you could do it by checking just the lore, or use nbt tags
     
  4. Offline

    ThemisH

    I thank you all. I solved the problem
     
Thread Status:
Not open for further replies.

Share This Page