Solved I want to open a gui with rightclick

Discussion in 'Spigot Plugin Development' started by MeneerEzra, Feb 4, 2020.

  1. Code (Java):
    package me.main;

    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.ClickType;
    import org.bukkit.event.inventory.InventoryClickEvent;

    public class AdminToolEvents implements Listener {
        public void onInventoryClick(InventoryClickEvent e) {
            ClickType clickType = e.getClick();
            if (clickType != ClickType.LEFT) {

            if (e.getCurrentItem() == null || e.getCurrentItem().getType() != Material.NETHER_STAR) {

            Player player = (Player) e.getWhoClicked();
  2. Right clicking a block? Why is it an inventory click event.
  3. SteelPhoenix


    And? You have not described your problem, shown any errors, shown your openGUI method etc.

  4. What exactly is your question?
    You can check for a rightclick with
    which will simply return true when the slot is right clicked.
  5. i just want to do rightclick with a netherstar and open a gui and i dont have a method because i dont know how
  6. i have never made a gui
  7. Do you want to open a gui when the player clicks a nether star that's in an inventory or when the player uses a nether star in their hand? If the latter, you should use the PlayerInteractEvent.
  8. Get the player from
    Player p = e.getPlayer();
    Then check p.getHand or p.getItemInHand (whatever it is), .equals(Material.NETHER_STAR), then open the GUI.
  9. i saw that on a forum ‍♂️
  10. Yes definitely use that and my solution.
  11. how do i open the gui i have never made one before
  12. You call HumanEntity#openInventory(Inventory).
  13. Create a gui method into another class like
    public void OpenGui(Player p){
    under this section you set up your GUI with items,names,lore ecc
    then create a class with InventoryClickEvent as DrConfig said previously and call the method from the other class to open your gui like
    if(p.getiteminhand == Material.Nether_Start){