Hook up the API events (some are missing parameter objects)
This commit is contained in:
@@ -2,15 +2,19 @@ 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.core.interfaces.dependencyInjection.IDhApiEventInjector;
|
||||
|
||||
/**
|
||||
* Handles adding/removing event handlers.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-9-8
|
||||
* @version 2022-9-13
|
||||
*/
|
||||
public class DhApiEventRegister
|
||||
{
|
||||
private static final IDhApiEventInjector EVENT_INJECTOR = ApiCoreInjectors.getInstance().eventInjector;
|
||||
|
||||
/**
|
||||
* Registers the given event handler. <Br>
|
||||
* Only one eventHandler of a specific class can be registered at a time.
|
||||
@@ -21,7 +25,7 @@ public class DhApiEventRegister
|
||||
{
|
||||
try
|
||||
{
|
||||
// DhApiEventInjector.INSTANCE.bind(eventInterface, eventHandlerImplementation);
|
||||
EVENT_INJECTOR.bind(eventInterface, eventHandlerImplementation);
|
||||
return DhApiResult.createSuccess();
|
||||
}
|
||||
catch (IllegalStateException e)
|
||||
@@ -37,14 +41,14 @@ public class DhApiEventRegister
|
||||
*/
|
||||
public static DhApiResult off(Class<? extends IDhApiEvent> eventInterface, Class<IDhApiEvent> eventHandlerClass)
|
||||
{
|
||||
// if (DhApiEventInjector.INSTANCE.unbind(eventInterface, eventHandlerClass))
|
||||
// {
|
||||
// return DhApiResult.createSuccess();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
if (EVENT_INJECTOR.unbind(eventInterface, eventHandlerClass))
|
||||
{
|
||||
return DhApiResult.createSuccess();
|
||||
}
|
||||
else
|
||||
{
|
||||
return DhApiResult.createFail("No event handler [" + eventHandlerClass.getSimpleName() + "] was bound for the event [" + eventInterface.getSimpleName() + "].");
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.seibel.lod.core.interfaces.dependencyInjection;
|
||||
|
||||
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-13
|
||||
*/
|
||||
public class ApiCoreInjectors
|
||||
{
|
||||
private static ApiCoreInjectors INSTANCE;
|
||||
|
||||
|
||||
public final IDhApiEventInjector eventInjector = new DhApiEventInjector();
|
||||
|
||||
|
||||
|
||||
public static ApiCoreInjectors getInstance()
|
||||
{
|
||||
if (INSTANCE == null)
|
||||
{
|
||||
INSTANCE = new ApiCoreInjectors();
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class EventInjectorTest
|
||||
{
|
||||
|
||||
|
||||
// //@Test
|
||||
// public void testEventDependencies() // this also tests list dependencies since there can be more than one event handler bound per event
|
||||
// {
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
|
||||
package com.seibel.lod.core.api.internal;
|
||||
|
||||
import com.seibel.lod.api.methods.events.abstractEvents.*;
|
||||
import com.seibel.lod.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||
import com.seibel.lod.core.DependencyInjection.DhApiEventInjector;
|
||||
import com.seibel.lod.core.level.IClientLevel;
|
||||
import com.seibel.lod.core.config.Config;
|
||||
import com.seibel.lod.core.ModInfo;
|
||||
@@ -153,7 +155,7 @@ public class ClientApi
|
||||
//TODO: Implement
|
||||
|
||||
// TODO: potentially add a list of chunks that were updated during the save
|
||||
// DhApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelSaveEvent.class, new DhApiLevelSaveEvent.EventParam(level));
|
||||
DhApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelSaveEvent.class, new DhApiLevelSaveEvent.EventParam(null)); // TODO create a wrapper object to pass back
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +166,7 @@ public class ClientApi
|
||||
if (SharedApi.currentWorld != null)
|
||||
{
|
||||
SharedApi.currentWorld.unloadLevel(level);
|
||||
// DhApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelUnloadEvent.class, new DhApiLevelUnloadEvent.EventParam(level));
|
||||
DhApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelUnloadEvent.class, new DhApiLevelUnloadEvent.EventParam(null)); // TODO create a wrapper object to pass back
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +177,7 @@ public class ClientApi
|
||||
if (SharedApi.currentWorld != null)
|
||||
{
|
||||
SharedApi.currentWorld.getOrLoadLevel(level);
|
||||
// DhApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelLoadEvent.class, new DhApiLevelLoadEvent.EventParam(level));
|
||||
DhApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelLoadEvent.class, new DhApiLevelLoadEvent.EventParam(null)); // TODO create a wrapper object to pass back
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,11 +270,11 @@ public class ClientApi
|
||||
RenderUtil.createLodProjectionMatrix(mcProjectionMatrix, partialTicks),
|
||||
RenderUtil.createLodModelViewMatrix(mcModelViewMatrix), partialTicks);
|
||||
|
||||
// boolean renderingCanceled = DhApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderEvent.class, new DhApiBeforeRenderEvent.EventParam(renderEventParam));
|
||||
if (!rendererDisabledBecauseOfExceptions)// && !renderingCanceled)
|
||||
boolean renderingCanceled = DhApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderEvent.class, new DhApiBeforeRenderEvent.EventParam(renderEventParam));
|
||||
if (!rendererDisabledBecauseOfExceptions && !renderingCanceled)
|
||||
{
|
||||
level.render(mcModelViewMatrix, mcProjectionMatrix, partialTicks, profiler);
|
||||
// DhApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterRenderEvent.class, new DhApiAfterRenderEvent.EventParam(renderEventParam));
|
||||
DhApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterRenderEvent.class, new DhApiAfterRenderEvent.EventParam(renderEventParam));
|
||||
}
|
||||
}
|
||||
else if (Config.Client.Advanced.Debugging.rendererMode.get() == ERendererMode.DEBUG)
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
|
||||
package com.seibel.lod.core.api.internal;
|
||||
|
||||
import com.seibel.lod.api.methods.events.abstractEvents.DhApiLevelLoadEvent;
|
||||
import com.seibel.lod.api.methods.events.abstractEvents.DhApiLevelSaveEvent;
|
||||
import com.seibel.lod.api.methods.events.abstractEvents.DhApiLevelUnloadEvent;
|
||||
import com.seibel.lod.core.DependencyInjection.DhApiEventInjector;
|
||||
import com.seibel.lod.core.level.ILevel;
|
||||
import com.seibel.lod.core.world.DhClientServerWorld;
|
||||
import com.seibel.lod.core.world.DhServerWorld;
|
||||
@@ -98,7 +102,7 @@ public class ServerApi
|
||||
if (SharedApi.currentWorld != null)
|
||||
{
|
||||
SharedApi.currentWorld.getOrLoadLevel(level);
|
||||
// DhApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelLoadEvent.class, new DhApiLevelLoadEvent.EventParam(new DhApiLevelWrapper(level)));
|
||||
DhApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelLoadEvent.class, new DhApiLevelLoadEvent.EventParam(null)); // TODO create a wrapper object to pass back
|
||||
}
|
||||
}
|
||||
public void serverLevelUnloadEvent(IServerLevelWrapper level) {
|
||||
@@ -106,7 +110,7 @@ public class ServerApi
|
||||
if (SharedApi.currentWorld != null)
|
||||
{
|
||||
SharedApi.currentWorld.unloadLevel(level);
|
||||
// DhApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelUnloadEvent.class, new DhApiLevelUnloadEvent.EventParam(new DhApiLevelWrapper(level)));
|
||||
DhApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelUnloadEvent.class, new DhApiLevelUnloadEvent.EventParam(null)); // TODO create a wrapper object to pass back
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +123,7 @@ public class ServerApi
|
||||
|
||||
for (ILevel level : SharedApi.currentWorld.getAllLoadedLevels())
|
||||
{
|
||||
// DhApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelSaveEvent.class, new DhApiLevelSaveEvent.EventParam(new DhApiLevelWrapper(level.getLevelWrapper())));
|
||||
DhApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelSaveEvent.class, new DhApiLevelSaveEvent.EventParam(null)); // TODO create a wrapper object to pass back
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user