Move some API objects into the DhApiMain object
This commit is contained in:
@@ -1,42 +1,48 @@
|
||||
package com.seibel.lod.api;
|
||||
|
||||
import com.seibel.lod.api.items.interfaces.config.IDhApiConfig;
|
||||
import com.seibel.lod.core.DependencyInjection.DhApiEventInjector;
|
||||
import com.seibel.lod.core.ModInfo;
|
||||
import com.seibel.lod.core.interfaces.dependencyInjection.IDhApiEventInjector;
|
||||
|
||||
/**
|
||||
* This holds API methods related to version numbers and other unchanging endpoints.
|
||||
* This shouldn't change between API versions.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-4-27
|
||||
* @version 2022-9-16
|
||||
*/
|
||||
public class DhApiMain
|
||||
{
|
||||
// only available after core initialization //
|
||||
|
||||
/**
|
||||
* <strong>WARNING:</strong> will be null until after DH initializes for the first time. <br><br>
|
||||
*
|
||||
* Use a {@link com.seibel.lod.api.methods.events.abstractEvents.DhApiAfterDhInitEvent DhApiAfterDhInitEvent}
|
||||
* along with the {@link DhApiMain#events ApiCoreInjectors.events} to be notified when this can
|
||||
* be safely used.
|
||||
*/
|
||||
public static IDhApiConfig configs;
|
||||
|
||||
|
||||
// always available //
|
||||
|
||||
/** Used to bind/unbind DH Api events. */
|
||||
public static final IDhApiEventInjector events = DhApiEventInjector.INSTANCE;
|
||||
|
||||
|
||||
/** This version should only be updated when breaking changes are introduced to the DH API */
|
||||
public static int getApiMajorVersion()
|
||||
{
|
||||
return ModInfo.API_MAJOR_VERSION;
|
||||
}
|
||||
public static int getApiMajorVersion() { return ModInfo.API_MAJOR_VERSION; }
|
||||
/** This version should be updated whenever new methods are added to the DH API */
|
||||
public static int getApiMinorVersion()
|
||||
{
|
||||
return ModInfo.API_MINOR_VERSION;
|
||||
}
|
||||
public static int getApiMinorVersion() { return ModInfo.API_MINOR_VERSION; }
|
||||
|
||||
/** Returns the mod's version number in the format: Major.Minor.Patch */
|
||||
public static String getModVersion()
|
||||
{
|
||||
return ModInfo.VERSION;
|
||||
}
|
||||
public static String getModVersion() { return ModInfo.VERSION; }
|
||||
/** Returns true if the mod is a development version, false if it is a release version. */
|
||||
public static boolean getIsDevVersion()
|
||||
{
|
||||
return ModInfo.IS_DEV_BUILD;
|
||||
}
|
||||
public static boolean getIsDevVersion() { return ModInfo.IS_DEV_BUILD; }
|
||||
|
||||
/** Returns the network protocol version. */
|
||||
public static int getNetworkProtocolVersion()
|
||||
{
|
||||
return ModInfo.PROTOCOL_VERSION;
|
||||
}
|
||||
public static int getNetworkProtocolVersion() { return ModInfo.PROTOCOL_VERSION; }
|
||||
|
||||
}
|
||||
|
||||
@@ -2,19 +2,18 @@ package com.seibel.lod.api.methods.events;
|
||||
|
||||
import com.seibel.lod.api.items.objects.DhApiResult;
|
||||
import com.seibel.lod.api.methods.events.interfaces.IDhApiEvent;
|
||||
import com.seibel.lod.core.interfaces.dependencyInjection.ApiCoreInjectors;
|
||||
import com.seibel.lod.api.DhApiMain;
|
||||
import com.seibel.lod.core.DependencyInjection.DhApiEventInjector;
|
||||
import com.seibel.lod.core.interfaces.dependencyInjection.IDhApiEventInjector;
|
||||
|
||||
/**
|
||||
* Handles adding/removing event handlers.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-9-13
|
||||
* @version 2022-9-16
|
||||
*/
|
||||
public class DhApiEventRegister
|
||||
{
|
||||
private static final IDhApiEventInjector EVENT_INJECTOR = ApiCoreInjectors.getInstance().events;
|
||||
|
||||
/**
|
||||
* Registers the given event handler. <Br>
|
||||
* Only one eventHandler of a specific class can be registered at a time.
|
||||
@@ -25,7 +24,7 @@ public class DhApiEventRegister
|
||||
{
|
||||
try
|
||||
{
|
||||
EVENT_INJECTOR.bind(eventInterface, eventHandlerImplementation);
|
||||
DhApiEventInjector.INSTANCE.bind(eventInterface, eventHandlerImplementation);
|
||||
return DhApiResult.createSuccess();
|
||||
}
|
||||
catch (IllegalStateException e)
|
||||
@@ -41,7 +40,7 @@ public class DhApiEventRegister
|
||||
*/
|
||||
public static DhApiResult off(Class<? extends IDhApiEvent> eventInterface, Class<IDhApiEvent> eventHandlerClass)
|
||||
{
|
||||
if (EVENT_INJECTOR.unbind(eventInterface, eventHandlerClass))
|
||||
if (DhApiEventInjector.INSTANCE.unbind(eventInterface, eventHandlerClass))
|
||||
{
|
||||
return DhApiResult.createSuccess();
|
||||
}
|
||||
|
||||
@@ -41,10 +41,7 @@ public class DhApiEventInjector extends DependencyInjector<IDhApiEvent> implemen
|
||||
|
||||
|
||||
|
||||
public DhApiEventInjector()
|
||||
{
|
||||
super(IDhApiEvent.class, true);
|
||||
}
|
||||
private DhApiEventInjector() { super(IDhApiEvent.class, true); }
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package com.seibel.lod.core.interfaces.dependencyInjection;
|
||||
|
||||
import com.seibel.lod.api.items.interfaces.config.IDhApiConfig;
|
||||
import com.seibel.lod.core.DependencyInjection.DhApiEventInjector;
|
||||
|
||||
/**
|
||||
* This singleton holds the dependency injectors used
|
||||
* between Core and the API.
|
||||
* IE: this is how Core and the API talk to each other.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-9-15
|
||||
*/
|
||||
public class ApiCoreInjectors
|
||||
{
|
||||
private static ApiCoreInjectors INSTANCE;
|
||||
|
||||
|
||||
|
||||
public final IDhApiEventInjector events = new DhApiEventInjector();
|
||||
|
||||
/**
|
||||
* <strong>WARNING:</strong> will be null until after DH initializes for the first time. <br><br>
|
||||
*
|
||||
* Use a {@link com.seibel.lod.api.methods.events.abstractEvents.DhApiAfterDhInitEvent DhApiAfterDhInitEvent}
|
||||
* along with the {@link ApiCoreInjectors#events ApiCoreInjectors.events} to be notified when this can
|
||||
* be safely used.
|
||||
*/
|
||||
public IDhApiConfig configs;
|
||||
|
||||
|
||||
public static ApiCoreInjectors getInstance()
|
||||
{
|
||||
if (INSTANCE == null)
|
||||
{
|
||||
INSTANCE = new ApiCoreInjectors();
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+5
-3
@@ -27,7 +27,7 @@ import com.seibel.lod.api.methods.events.interfaces.IDhApiEvent;
|
||||
* @author James Seibel
|
||||
* @version 2022-9-13
|
||||
*/
|
||||
public interface IDhApiEventInjector extends IDependencyInjector<IDhApiEvent> // Note to self: Don't try adding a generic type to IDhApiEvent, the consturctor won't accept it
|
||||
public interface IDhApiEventInjector
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -36,7 +36,9 @@ public interface IDhApiEventInjector extends IDependencyInjector<IDhApiEvent> //
|
||||
* @throws IllegalArgumentException if the implementation object doesn't implement the interface
|
||||
* @return true if the handler was unbound, false if the handler wasn't bound.
|
||||
*/
|
||||
public boolean unbind(Class<? extends IDhApiEvent> dependencyInterface, Class<? extends IDhApiEvent> dependencyClassToRemove) throws IllegalArgumentException;
|
||||
// Note to self: Don't try adding a generic type to IDhApiEvent, the consturctor won't accept it
|
||||
boolean unbind(Class<? extends IDhApiEvent> dependencyInterface, Class<? extends IDhApiEvent> dependencyClassToRemove) throws IllegalArgumentException;
|
||||
|
||||
|
||||
/**
|
||||
* Fires all bound events of the given type (does nothing if no events are bound).
|
||||
@@ -46,6 +48,6 @@ public interface IDhApiEventInjector extends IDependencyInjector<IDhApiEvent> //
|
||||
* @return if any of the events returned that this event should be canceled.
|
||||
* @param <T> the parameter type taken by the event handlers.
|
||||
*/
|
||||
public <T, U extends IDhApiEvent<T>> boolean fireAllEvents(Class<U> dependencyInterface, T eventParameterObject);
|
||||
<T, U extends IDhApiEvent<T>> boolean fireAllEvents(Class<U> dependencyInterface, T eventParameterObject);
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class EventInjectorTest
|
||||
public void testEventDependencies() // this also tests list dependencies since there can be more than one event handler bound per event
|
||||
{
|
||||
// Injector setup
|
||||
DhApiEventInjector TEST_EVENT_HANDLER = new DhApiEventInjector();
|
||||
DhApiEventInjector TEST_EVENT_HANDLER = DhApiEventInjector.INSTANCE;
|
||||
|
||||
|
||||
// pre-dependency setup
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.seibel.lod.core.api.external.methods.config.DhApiConfig;
|
||||
import com.seibel.lod.core.datatype.column.ColumnRenderLoader;
|
||||
import com.seibel.lod.core.datatype.full.FullDataLoader;
|
||||
import com.seibel.lod.core.datatype.full.SparseDataLoader;
|
||||
import com.seibel.lod.core.interfaces.dependencyInjection.ApiCoreInjectors;
|
||||
import com.seibel.lod.api.DhApiMain;
|
||||
|
||||
/**
|
||||
* Handles first time Core setup.
|
||||
@@ -22,7 +22,7 @@ public class Initializer
|
||||
|
||||
|
||||
// link Core's config to the API
|
||||
ApiCoreInjectors.getInstance().configs = DhApiConfig.INSTANCE;
|
||||
DhApiMain.configs = DhApiConfig.INSTANCE;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user