FountainMC / FountainAPI

A 'simple but beautiful' Minecraft Server Plugin API
https://fountainmc.org/
MIT License
5 stars 5 forks source link

Switch the events to interfaces #22

Closed jamierocks closed 8 years ago

jamierocks commented 8 years ago

Forge already has some events, so we will need to make them interfaces (might be an idea to look at Sponge's way of handling this).

We should probably also make the actual EventBus an interface too.

phase commented 8 years ago

I think classes are easier to work with on the plugin side. If I want to fire an arbitrary event, all I have to do is instantiate an object. Implementing an interface seems like a lot more work.

For Forge, instead of having the existing events implement ours, you could fire both at the same time. It might not be ideal, but it saves us from creating 30 interface events and 30 class events that only implement those.

The EventBus is in Event4J. We'd have to recreate that if we wanted to change it to an interface

jamierocks commented 8 years ago

Sponge's solution involves having a factory for constructing events. infact they event have a generator for the event factory

edit: https://github.com/SpongePowered/event-impl-gen

phase commented 8 years ago

That's a lot of complexity to add when we can just use objects. One extra object is better than a generator for factories that create interfaces.

jamierocks commented 8 years ago

One extra object + passing things in between the two events buses

wgaylord commented 8 years ago

We could just take a forge dev environment for making additions to forge and add our API into it... then not much needs to be done.

jamierocks commented 8 years ago

Thats a horrible idea :|

Techcable commented 8 years ago

Interfaces are fine, since plugins shouldn't be constructing events in the first place. This makes it much much easier for a forge implementation, or a bukkit compatibility wrapper. As for ease of creation, we can just add factory methods to that returns a default implementation:

public static BlockBreakEvent create(BlockPosition position, BlockState state) {
    return new BlockBreakEvent() {
        public BlockPosition getPosition() {
            return position;
        }

        public BlockPosition getState() {
            return state;
        }
    }
}

Since its anonymous, plugins won't be able to access it but its just as easy to create as a new class. We don't need to have some crazy factory manager thingy with auto-generated implementations. This is the easiest way to be compatible with alternate event systems without over-complicating the main implementation.

minecrafter commented 8 years ago

@Techcable what about plugins using the event system to plug in their own events, such as Votifier?

phase commented 8 years ago

@minecrafter Plugins can still fire their events using the EventManager, and all they need to do is create a class that implements Event or an Event subinterface.