Event Class

Discussion in 'Plugin Development' started by Chr0mosom3, Apr 17, 2021.

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

    Chr0mosom3

    This isn't really a question about code or a bug but just how I should go around creating event classes and how other people do it.

    1) If I have custom armor in my plugin, and when the player takes damage it halves the damage if the player is wearing the armor piece, would you call the event class:
    A: PlayerTakingDamageEvent
    B: ArmorProtectEvent

    2) If I have custom armor in my plugin and custom projectiles, and when the player gets hit by the projectile the projectile pushes the player back, and when the player takes damage it halves the damage if the player is wearing the armor piece, would you:
    A: Have them both as seperate methods in the same class called PlayerTakingDamageEvent
    B: Have two seperate classes called CustomProjectileHitEvent and armorProtectEvent with a single method each

    Thank you for your input,
     
  2. Offline

    davidclue

    I would go with B for both, couldn't you have used a poll?
     
  3. Offline

    Newdel

    1. I would put the event in the class that creates the armor. 1 event in a class seems unnecessary to me
    2. A. Hard to say how you should call it. Anything that describes what's going on there so in your example:
    I those are your only two events (maybe +1,2...) make one class that's called CustomEvents (choose a nicer name pls lmao)
     
  4. Offline

    Chr0mosom3

    Bro, you're a genius. Never thought of doing that
    Can't use a poll for two questions, and I think a discussion is better
    So if there are more than 5 events in a plugin, you would have a separate class for each one of them?
     
  5. Offline

    Newdel

    Lmao. I got big brain moment for this

    Well, if you have something like your armor event, I would put it in the armor file, if you have several events for one part of your plugin (like an inventory GUI), I would put them together in one file and if your event have nothing in common with bigger parts of your code, I would just put them in one class for every event (if there aren't 1000 events in your plugin)
     
Thread Status:
Not open for further replies.

Share This Page