Same parameter, two diferent event types

Discussion in 'Plugin Development' started by lecreep, Nov 8, 2022.

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

    lecreep

    something like this is possible?

    Code:
       @EventHandler
        public void onInventoryCreativeEvent(InventoryCreativeEvent event) {
            inventoryClick(event);
        }
       
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            inventoryClick(event);
        }
       
        private void inventoryClick(¿events? event) {
            event.setCancelled(true);
        }
     
  2. Offline

    Strahan

    You could, you could pass it to the method as InventoryEvent or even just a generic object but what I'd really do is just pass the data I'm going to need.
     
    lecreep likes this.
  3. Offline

    Kars

    @lecreep InventoryCreativeEvent extends InventoryClickEvent so just pass InventoryClickEvent in and it will accept the creative event aswell.
     
    lecreep and Strahan like this.
  4. Offline

    lecreep

    it's how I have it right now, and it actually works, but I have the same chunk of code in both functions and I'm trying to put some effort into refactoring and keeping the code clean.

    So when one object extends another...
    good to know


    Thanks for your time dudes.
     
Thread Status:
Not open for further replies.

Share This Page