Solved Inventory Click

Discussion in 'Spigot Plugin Development' started by chochoco4777, Jul 27, 2021.

Thread Status:
Not open for further replies.
  1. I ran into a problem while fixing this plugin to support bug fix 1.17. Clicking on inventory doesn't work. There is no console error.

    Shop.java
    Code (Text):
        private String name;
        private boolean enabled;
        private Inventory inv;
        private List<CustomItem> ci;
       
        public Shop(String name, boolean enabled, int rows) {
            this.name = name;
            this.enabled = enabled;
            this.inv = Bukkit.createInventory(null, rows*9, ChatColor.translateAlternateColorCodes('&', name));
            this.ci = new ArrayList<>();
        }
    Inventory Click.java
    Code (Text):
        @EventHandler
        public void onClick(InventoryClickEvent e) {
            if(e.getInventory() == null) return;
            if(e.getCurrentItem() == null) return;
            if(e.getClickedInventory() == null) return;
           
            Player p = (Player)e.getWhoClicked();
            CustomPlayer cp = main.getPlayerManager().getPlayer(p);
           
            for(Shop s : main.getShopManager().getShops().values()) {
                Inventory inventoryName = s.getInventory();
                if(e.getView().getTitle().equalsIgnoreCase(inventoryName.toString())) {
     
  2. First things first, did you register your listener?
     
  3. Yes.
     
  4. Did you try adding some debug statements to see how far it gets?
     
  5. I did debug. Nothing was displayed.
     
  6. this is your error, you're calling toString() on an object that didn't redefine it, so you're getting something like "Lorg/bukkit/inventory/[email protected]" instead of the inventory name. I guess you want to use
    Code (Java):
    if(e.getView().getTitle().equalsIgnoreCase(s.getName())) {
    instead
     
  7. doesn't work no console error.
     
  8. Then try to debug adding outputs, something like this
    Code (Java):
    @EventHandler
    public void onClick(InventoryClickEvent e) {
        if(e.getInventory() == null) return;
        if(e.getCurrentItem() == null) return;
        if(e.getClickedInventory() == null) return;
     
        Player p = (Player)e.getWhoClicked();
        CustomPlayer cp = main.getPlayerManager().getPlayer(p);
        String title = e.getView().getTitle();
        Bukkit.broadcastMessage("View title: " + title);
        for(Shop s : main.getShopManager().getShops().values()) {
            Inventory inventoryName = s.getInventory();
            Bukkit.broadcastMessage("Checking against " + s.getName());
            if(title.equalsIgnoreCase(s.getName())) {
                Bukkit.broadcastMessage("OK");
            }
        }
    }
     
  9. Your class name has a space in it.
     
    #9 rossf_, Jul 28, 2021
    Last edited: Jul 28, 2021
Thread Status:
Not open for further replies.