Solved InventoryClickEvent not getting called

Discussion in 'Plugin Development' started by Arago, Jan 23, 2022.

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

    Arago

    Im making a GUI, but when someone clicks the InventoryClickEvent does not get called, but im am pretty sure everything is registered correctly.

    CODE:

    InventoryClickListener.java
    Code:
    package nl.thypa.qolplus.listeners;
    
    import nl.thypa.qolplus.Main;
    import nl.thypa.qolplus.UIs.HomeOverwriteUI;
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    
    public class InventoryClickListener implements Listener {
        private final Main main;
    
        public InventoryClickListener(Main main){
            this.main = main;
    
            Bukkit.getPluginManager().registerEvents(this, main);
            main.getLogger().info("Registered InventoryClickListener");
        }
    
        public void onClick(InventoryClickEvent event){
            main.getLogger().info("Someone Clicked!");
            String title = event.getView().getTitle();
            if(title.equals(HomeOverwriteUI.inv_name)){
                event.setCancelled(true);
                System.out.println("cancelled event");
                if(event.getCurrentItem() == null){
                    return;
                }
                if(title.equals(HomeOverwriteUI.inv_name)){
                    HomeOverwriteUI.clicked((Player) event.getWhoClicked(), event.getSlot(), event.getCurrentItem(), event.getInventory());
                }
            }
        }
    }
    

    Main.java
    Code:
    package nl.thypa.qolplus;
    
    import nl.thypa.qolplus.UIs.HomeOverwriteUI;
    import nl.thypa.qolplus.commands.CatCommand;
    import nl.thypa.qolplus.commands.ClearCommand;
    import nl.thypa.qolplus.commands.DiscordCommand;
    import nl.thypa.qolplus.commands.SetHomeCommand;
    import nl.thypa.qolplus.listeners.InventoryClickListener;
    import nl.thypa.qolplus.listeners.JoinListener;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import java.util.HashMap;
    import java.util.UUID;
    
    public final class Main extends JavaPlugin {
    
        public FileConfiguration config = getConfig();
    
        private HashMap<UUID, Location> homes;
    
        @Override
        public void onEnable() {
            // Plugin startup logic
            config.options().copyDefaults(true);
    
            new JoinListener(this, config);
            new InventoryClickListener(this);
            getServer().getLogger().info("InvClick Loaded");
            HomeOverwriteUI.initialize();
    
    
    
            this.homes = new HashMap<>();
    
            Bukkit.getLogger().info("Enabled QOL Plus!");
    
            getServer().getPluginCommand("clear").setExecutor(new ClearCommand(this, config));
            getServer().getPluginCommand("discord").setExecutor(new DiscordCommand(this, config));
            getServer().getPluginCommand("cat").setExecutor(new CatCommand(this, config));
            getServer().getPluginCommand("sethome").setExecutor(new SetHomeCommand(this, config));
        }
    
        @Override
        public void onDisable() {
            // Plugin shutdown logic
        }
    
        public void addHome(UUID id, Location location){
            this.homes.put(id, location);
        }
    
        public Location getHome(UUID id){
            return this.homes.get(id);
        }
    
        public boolean hasHome(UUID id){
            return this.homes.containsKey(id);
        }
    }
    
     
    Last edited by a moderator: Jan 23, 2022
  2. Offline

    timtower Administrator Administrator Moderator

    @Arago What gets printed in the terminal then?
     
  3. Offline

    Arago

    FIXED - i forgot to put @EventHandler before the lkistener!

    Now everything does, but thanks for replying!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 23, 2022
Thread Status:
Not open for further replies.

Share This Page