Are custom events worth it?

Discussion in 'Spigot Plugin Development' started by Mentol, May 28, 2018.

  1. Hello! So, I'm asking this because I ran a timings a while ago with my ac, and a single interact event used up 0.25% of the tick, will making custom events with protocollib be lighter?
  2. I don't think that a custom packet listener will help you in this case. It might make your performance even worse because the interact event is triggered any way.
  3. Okay, I rewrote it like 2x since, I always recode my base when I'm bored. I tought it would be lighter but ok then.
  4. Just custom events alone will not improve performance. In the end, an event handler is nothing but a function being called. Whether you have everything dumped in one big handler or separate it across multiple (custom) event handlers, that wouldn't make a difference in terms of performance. Custom events may help keeping your code cleaner and may even be provided to other people as a form of API. If your anti cheat does seriously lagging stuff, you may consider doing it asynchronous. Get some info of the player (an interact event for example), save it somewhere temporarily (for example, save a collection of events) then check those events asynchronously every 1 minute for every player. Then, fire a custom event (async or sync) indicating that you detected a cheat. Just an example of how you may improve performance. However, this goes more into the cheat detection category rather than the anti cheat. This may or may not be what you want, but you'll have to decide that for yourself.
    • Agree Agree x 1
  5. Well okay. The other thing I tought about is that, I have one event for every check category, Combat (EntityDamageByEntity), Movement (PlayerMove), Exploit(Idk, Movement/Combat), Other(Variable), and I fire every check on one event for every player so there is only 1 event getting used? My english is probably awful, but will this make a difference?
  6. As I said earlier, custom event, no matter how much (unless you have a bunch of external plugin handlers doing stuff with it) won't make any difference to performance. If you're doing a lot of checks which causes lag, the idea I suggested earlier might be what you're looking for.
    • Agree Agree x 1