Inventory Event not firing!

Discussion in 'Plugin Development' started by StarFruitYT, Apr 9, 2020.

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

    StarFruitYT

  2. Offline

    KarimAKL

    @StarFruitYT Does it output "fired!"? Is the plugin listed as green when you use the "/plugins" command?
     
    StarFruitYT likes this.
  3. Offline

    StarFruitYT

    Yes. I have fixed the firing my removing the constructor, but now
    if(open.getName().equals(bc.bangui.getName())) {
    p.sendMessage("fired!");
    }
    doesnt work

    the only plugins that i have are: LuckPerms, StarGaze (Custom), Vault, Multiverse-Core, ChatEx, and Essentials

    Does anybody else know. I really need to get this fixed ASAP!

    Hello? @KarimAKL

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 9, 2020
  4. Offline

    KarimAKL

    That's because 'bc' points to a new instance of BanCommand, not the registered instance, you need to pass it the instance from the constructor.

    This is a forum, i posted the above question before i went to sleep.
     
  5. Offline

    StarFruitYT

    So sorry!


    Code:
    @EventHandler
        public void onMenuClick(InventoryClickEvent e) {
            Player p = (Player) e.getWhoClicked();
            ItemStack item = e.getCurrentItem();
            if (BanCommand.bangui != null) {
                if (e.getClickedInventory().equals(BanCommand.bangui)) {
                    p.sendMessage("clicked: " + BanCommand.bangui.getName());
                    if(item != null) {
                        Player pban = Bukkit.getPlayer(item.getItemMeta().getDisplayName());
                        BanCommand.openBanConfirm(p, pban);
                    }
                }
            }
        }
    this is what i have now, the sendmessage still isnt firing
    Im not to sure what you mean by get the registered one?
     
  6. Offline

    KarimAKL

    @StarFruitYT You have the BanCommand class, you create an instance of this class at line 27 in your Main class, then at line 21 in your BanEvents class you assign a new instance of that class to 'bc'.

    You need to assign the instance from the Main class to a field, then pass the instance assigned to that field into the constructor of your BanEvents class, and then set 'bc' to that instance.
     
  7. Offline

    StarFruitYT

    Like this?


    Code:
    public BanEvents be = new BanEvents(this);
        public BanCommand bc;
    
        @SuppressWarnings("unused")
        @Override
        public void onEnable() {
            registerCommands();
            registerListeners();
            BukkitTask keepDay = new TimeListener(this).runTaskTimer(this, 0L, 100L);
        }
     
        public void registerListeners() {
            getServer().getPluginManager().registerEvents(be, this);
            getServer().getPluginManager().registerEvents(new WeatherListener(), this);
        }
     
        public void registerCommands() {
            bc = new BanCommand(this);
            new VanishCommand(this);
        }
        
    Code:
    public Main plugin;
    
        public BanEvents(Main pl) {
            plugin = pl;
        }
     
        public BanCommand bc = plugin.bc;
    
        @EventHandler
        public void onMenuClick(InventoryClickEvent e) {
            Player p = (Player) e.getWhoClicked();
            ItemStack item = e.getCurrentItem();
            p.sendMessage("clicked: " + e.getClickedInventory().getTitle());
            if (e.getClickedInventory().getTitle().equalsIgnoreCase(bc.banName)) {
                p.sendMessage("clicked: " + bc.banName);
                if (item != null) {
                    Player pban = Bukkit.getPlayer(item.getItemMeta().getDisplayName());
                    bc.openBanConfirm(p, pban);
                }
            }
        }
    

    I'm very sorry if this is frustrating, im new to this and i really want to expand my knowledge!
     
  8. Offline

    KarimAKL

    @StarFruitYT Yes, you're now only creating one instance of the BanCommand class.
     
  9. Offline

    StarFruitYT

    My ban command is no longer registering...
     
  10. Offline

    KarimAKL

    @StarFruitYT Sounds weird, you should be registering it at line 30 in your BanCommand class.

    Could you post your current code for the 3 classes in pastebin?
     
  11. Offline

    StarFruitYT

    what about my main class?
    is this ok?
    bc = new BanCommand(this);

    Actually in fact, the whole plugin doesnt register anymore

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 10, 2020
  12. Offline

    KarimAKL

    As in the plugin isn't shown when you use the command "/plugins"?

    Post your full server log after stopping and starting the server. (Please use pastebin)
     
  13. Offline

    StarFruitYT

  14. Offline

    KarimAKL

    @StarFruitYT Do you know how to read a stacktrace? If not, read this.

    Anyway, line 21 of the BanEvents class is throwing a NullPointerException, could you post your whole BanEvents.java file on pastebin?
     
  15. Offline

    StarFruitYT

  16. Offline

    KarimAKL

  17. Offline

    caderapee

    @StarFruitYT
    Register your ban command in the constructor and it will work. Fields are initialized before constructor, it's why it's null
     
    KarimAKL likes this.
  18. Offline

    StarFruitYT

    Alright, so the plugin is now registered again (thanks)! Although the GUI doesnt do anything when i click, is it because im formatting the displayname of the player head in the GUI?
     
    Last edited: Apr 11, 2020
  19. Offline

    StarFruitYT

  20. Offline

    KarimAKL

    @StarFruitYT Did you try debugging? If so, could you give us the results as well as the code you tried?
     
  21. Offline

    StarFruitYT

    I FIGURED IT OUT! So sorry for not responding, I just now saw this. So long story short, they removed the getTitle() method. I have to use e.getView().getTitle(). Works fine! Thank you so much for your help (and sorry for being annoying xD). You guys are the best! @KarimAKL @caderapee
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page