Solved Best way to use listener class?

Discussion in 'Plugin Development' started by voltywolty, Jan 3, 2024.

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

    voltywolty

    I have an item manager that loads item stacks from a config. I give those items functionality by using listeners. However, I feel like the listener classes would be thousands of lines long with the items functionality. So, I was wondering if there was a better way to use listeners. I was just gonna break it into multiple listener classes for each class in the plugin, but I wonder if there is a better way.
     
  2. Offline

    timtower Administrator Administrator Moderator

    How many different events do you use?
    How many paths are there (based on items etc)
    Can you do checks and then call functions instead of doing it in the event handler?
     
  3. Offline

    voltywolty

    I think I could do checks and then call a function in the event handler rather than making an entire function in the event handler itself.

    As of right now I have three different listener classes, one of them just uses one event right now, along with another.
     
  4. Offline

    timtower Administrator Administrator Moderator

    That is not what I was asking.
    How many events do you use?
    Having a function that is 1000 lines long is never good.
     
  5. Offline

    voltywolty

    In my listener using the custom items, it's one event (PlayerInteractEvent), but it plans to grow into more events. The PlayerInteractEvent also plans to use a lot more functions because of left clicking said item.

    In my server listener, 34 events. However, it's probably going to decrease as some of them I do not need anymore.
     
  6. Offline

    timtower Administrator Administrator Moderator

    @voltywolty 34 events sounds like a lot of duplicates there.
     
  7. Offline

    voltywolty

    Yeah, I know... I'm trying to find a better way to go about this.
     
  8. Offline

    timtower Administrator Administrator Moderator

    Only 1 of each needs an @EventListener, the rest can have checks to see if you need to call that function.
     
Thread Status:
Not open for further replies.

Share This Page