Solved On right click open GUI

Discussion in 'Plugin Development' started by Gladiator, Jun 13, 2022.

  1. Offline

    Gladiator

    I want to open a GUI after right clicked a netherite ingot that has a custom name and lore.
    Why doesn't this work?

    My code so far:
    Code:
    package me.gladiator.betraysmp.events;import net.md_5.bungee.api.ChatColor;import org.bukkit.Bukkit;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.Inventory;import org.bukkit.inventory.ItemStack;import org.bukkit.inventory.meta.ItemMeta;import java.util.Arrays;public class OnIngotClickOpenGUI implements Listener {
    
    @EventHandler
    public void BetrayGUI(PlayerInteractEvent event)
    {
    
    System.out.println("At least started");
    ItemStack BetrayIngot = new ItemStack(Material.NETHERITE_INGOT);
    ItemMeta meta =
    BetrayIngot.getItemMeta();meta.setDisplayName(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Betray Ingot");
    
    meta.setLore(Arrays.asList("The Betray Ingot.", "Use 4 of these to craft a Ban Token."));
    
    BetrayIngot.setItemMeta(meta);
    if(event.getAction() == (Action.RIGHT_CLICK_AIR) || event.getAction() == (Action.RIGHT_CLICK_BLOCK))
    {
    
    if (event.getPlayer().getInventory().getItemInMainHand().getType().equals(BetrayIngot))
    {
    System.out.println("passed the ingot check");
    
    Player player = event.getPlayer();
    
    Inventory gui = Bukkit.getServer().createInventory(player, 27, ChatColor.GOLD + "" + ChatColor.BOLD + "Betray Ingot Craft");
    
    ItemStack shell = new ItemStack(Material.NAUTILUS_SHELL);
    
    ItemStack sea = new ItemStack(Material.HEART_OF_THE_SEA);
    gui.setItem(11, shell);
    gui.setItem(15, sea);
    player.openInventory(gui);}
    }
    
    }
    
    }
    }
     
    Last edited: Jun 13, 2022
  2. Offline

    timtower Administrator Administrator Moderator

    @Gladiator Can you fix the code block so there are enters in it?
     
  3. Offline

    Gladiator

    done
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Gladiator Type of an itemstack will never be equal to an itemstack.
     
  5. Offline

    Gladiator

    Oh ok so then what should I call?
     
  6. Offline

    Gladiator

    So what function should I call?
     
  7. Offline

    timtower Administrator Administrator Moderator

    @Gladiator How about some patience and not making multiple posts?
    Check the lore and itemname.
     
  8. Offline

    Gladiator

    Sry but should I do,
    event.getPlayer().getInventory().getItemInMainHand().getItemMeta().equals(BetrayIngot))
     
  9. Offline

    timtower Administrator Administrator Moderator

  10. Offline

    Gladiator

    Thank you so much!
     

Share This Page