CustomEvents

Discussion in 'Plugin Development' started by Gingerbreadman, Dec 18, 2014.

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

    Gingerbreadman

    Hello everyone, I am making a plugin that needs CustomEvents
    I just want to get to know CustomEvents more than I do now

    My questions are
    1. How would I make a replica of a LoginEvent
    2. How would I make a replica of a MoveEvent

    Thanks in advance!
     
  2. Offline

    Rocoty

    @Gingerbreadman i don't see what you're hoping to accomplish by replicating events? What is it you are trying to achieve in the end?
     
  3. Offline

    Gingerbreadman

    @Rocoty I am not sure how are the events called, when the player moves or joins
     
  4. Offline

    Rocoty

    @Gingerbreadman Replicating events sounds odd. Why would you need to create an exact copy of a type of event if it already exists? There is probably another, better way to accomplish what you are trying to do. Help me help you. Please answer my question.
     
    AdamQpzm likes this.
  5. Offline

    Gingerbreadman

    @Rocoty I want to make an exact copy of the event to understand it more
     
  6. Offline

    Rocoty

    @Gingerbreadman Well. Those two particular events are called internally from NMS. If you wanted to replicate those events exactly you'd have to use NMS to call them. If you wanted to call them without NMS you'd have to listen to the originals anyway in order to call your replicas. In both cases it would be redundant.

    I suggest you try to make your own custom events suitable to your needs instead. Say you were making a Kit plugin, you might want a PlayerAssumeKitEvent. And so on...
     
  7. Offline

    xize

    also note that some events are I think special called like in a abstract way or manner:

    see: https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/event/player/PlayerEvent.java this one is extended by PlayerLoginEvent, maybe that doesn't mather much but you cant never be to sure, on custom events I always add as much abstraction as possible.

    what you could do is making a extend of an already existed event (this does not replicate the event) by extending it and placing the exact data in the super constructor from e.g PlayerLoginEvent, however I believe the abstraction is there for a reason and I think its actually a bad practise doing these things on such fragile events connected to nms, but on the other hand it gives you the option to add more methods.
     
  8. Offline

    Rocoty

    @xize
    Not sure what you mean by "special called like in a abstract way or manner"

    Extending an existing event will not interfere with anything. Extending another event does not mean your new event will automatically get called. You still have to call it yourself. I would consider it good practice to extend an existing event if you would consider your new event to be a more specific version of the event you're extending.

    e.g My example event PlayerAssumeKitEvent would extend PlayerEvent
     
  9. Offline

    teej107

  10. Offline

    Rocoty

    @teej107 In making a framework or API/SPI it may really come in handy for the convenience of the user of your resource.
     
    teej107 likes this.
  11. Offline

    xize

    @Rocoty
    I actually ment making all extra fields final with the final keyword.
     
  12. Offline

    Rocoty

    @xize I'm still a bit confused about what you're saying.
     
    Totom3 likes this.
  13. Offline

    xize

    @Rocoty

    lets say you want to include your own method to your custom event which returns your own wrapper for something then I would do in the custom event:

    Code:
    public class CustomEvent extends PlayerLoginEvent {
          
          private final Wrapper wrap; //this is what I mean.
    
          public CustomEvent(PlayerLoginEvent e, Wrapper wrap) {
                 super(e.??, e.??);
                this.wrap = wrap;
          }
    
          public Wrapper getWrapper() {
                  return wrap;
          }
    }
    
    I actually completely said it wrong on my earlier topic its nothing 'special' or something working different, I actually ment that this abstraction is kinda better than having a chance people could overwrite things, I never tested it if it is possible but by seeing the code in existed Events it looks abstraction is very important.
     
  14. Offline

    Rocoty

    @xize Right....this looks like very basic Inheritance to me though
     
  15. Offline

    Gingerbreadman

    @xize @Rocoty @teej107 Thank you all for your help, I just realized the concept for custom events xD
     
Thread Status:
Not open for further replies.

Share This Page