Search code examples
javaminecraftbukkit

Minecraft Bukkit - Custom GUI when right click on a villager


I'm making a [Bed Wars][1] plugin for my Minecraft server. Actually I have to make a custom villager shop.

I have made my GUI (with implements InventoryHolder). It's working with a commands. I have searched all over the Internet, but I have not found anything on a system that makes, when you right click on a villager (I know how to spawn it) it's is showing my GUI. What would be an idea for that?

edit : I tried to use PlayerInteractAtEntityEvent, i maked a class, register it and make this code :

    @EventHandler
    public void interactAtEntity(PlayerInteractAtEntityEvent e) {
        if (e.getRightClicked() == ShopVillager.villager1) {
            System.out.println("UwU");
            Player player = e.getPlayer();
            FastShop shop = new FastShop(player);
            player.openInventory(shop.getInventory());
            e.setCancelled(true);
            return;
        }
    }

It show the gui like 0.2sec but after i close it and show the original trade gui, and i got the uwu in my console.


Solution

  • I just go on github and i have explore a lot of bedwars plugin code, and i find !!!

    I just need to use : PlayerInteractEntityEvent

    Thats it