Move DhApiEventRegister to API sub-project

This commit is contained in:
James Seibel
2022-09-05 21:41:32 -05:00
parent b5a05bfe21
commit dbae5a3b05
2 changed files with 0 additions and 0 deletions
@@ -0,0 +1,51 @@
package com.seibel.lod.core.api.external.methods.events;
import com.seibel.lod.core.api.implementation.interfaces.events.IDhApiEvent;
import com.seibel.lod.core.api.external.items.objects.DhApiResult;
import com.seibel.lod.core.handlers.dependencyInjection.DhApiEventInjector;
/**
* Handles adding/removing event handlers.
*
* @author James Seibel
* @version 2022-7-16
*/
public class DhApiEventRegister
{
/**
* Registers the given event handler. <Br>
* Only one eventHandler of a specific class can be registered at a time.
* If multiple of the same eventHandler are added DhApiResult will return
* the name of the already added handler and success = false.
*/
public static DhApiResult on(Class<? extends IDhApiEvent> eventInterface, IDhApiEvent eventHandlerImplementation)
{
try
{
DhApiEventInjector.INSTANCE.bind(eventInterface, eventHandlerImplementation);
return DhApiResult.createSuccess();
}
catch (IllegalStateException e)
{
return DhApiResult.createFail(e.getMessage());
}
}
/**
* Unregisters the given event handler for this event if one has been registered. <br>
* If no eventHandler of the given class has been registered the result will return
* success = false.
*/
public static DhApiResult off(Class<? extends IDhApiEvent> eventInterface, Class<IDhApiEvent> eventHandlerClass)
{
if (DhApiEventInjector.INSTANCE.unbind(eventInterface, eventHandlerClass))
{
return DhApiResult.createSuccess();
}
else
{
return DhApiResult.createFail("No event handler [" + eventHandlerClass.getSimpleName() + "] was bound for the event [" + eventInterface.getSimpleName() + "].");
}
}
}
@@ -0,0 +1,3 @@
The events api package holds objects and methods for listening to events fired by Distant Horizons'.
Each interface should only contain one method and that method should match the name of the file. This is done so Developers can mix and match what events they want their classes to handle.