Comment out API/API test code so we can get everything compiling

This commit is contained in:
James Seibel
2022-09-07 07:37:07 -05:00
parent 53ded97714
commit 09ceab5c70
24 changed files with 623 additions and 545 deletions
@@ -19,7 +19,6 @@
package com.seibel.lod.api.enums;
import com.seibel.lod.core.api.external.items.enums.override.DhApiOverrideEnumAssembly;
import com.seibel.lod.api.items.enums.config.DhApiConfigEnumAssembly;
import com.seibel.lod.core.api.external.coreImplementations.enums.worldGeneration.DhApiWorldGenerationEnumAssembly;
@@ -35,7 +34,6 @@ public class DhApiEnumAssembly
// This is done so they can be found via reflection.
private static final DhApiWorldGenerationEnumAssembly worldGenerationAssembly = new DhApiWorldGenerationEnumAssembly();
private static final DhApiConfigEnumAssembly configAssembly = new DhApiConfigEnumAssembly();
private static final DhApiOverrideEnumAssembly overrideAssembly = new DhApiOverrideEnumAssembly();
/** All DH API enums should have this prefix */
public static final String API_ENUM_PREFIX = "EDhApi";
@@ -1,14 +1,16 @@
package com.seibel.lod.api.items.interfaces;
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.ICoreDhApiUnsafeWrapper;
/**
* The Distant Horizons' API objects can't cover
* every potential use case. Sometimes developers just need
* the base Minecraft Objects.
*
* @author James Seibel
* @version 2022-7-14
* @version 2022-9-6
*/
public interface IDhApiUnsafeWrapper
public interface IDhApiUnsafeWrapper extends ICoreDhApiUnsafeWrapper
{
/**
* Returns the Minecraft object this wrapper contains. <br>
@@ -20,6 +22,7 @@ public interface IDhApiUnsafeWrapper
* in order to determine what object this method returns for
* the specific version of Minecraft you are developing for.
*/
@Override
public Object getWrappedMcObject_UNSAFE();
}
@@ -1,8 +1,8 @@
package com.seibel.lod.api.items.interfaces.override;
import com.seibel.lod.core.api.external.coreImplementations.interfaces.override.ICoreDhApiOverrideable;
import com.seibel.lod.core.api.external.items.enums.override.EDhApiOverridePriority;
import com.seibel.lod.core.handlers.dependencyInjection.IBindable;
import com.seibel.lod.core.handlers.dependencyInjection.OverrideInjector;
/**
* Implemented by all DhApi objects that can be overridden.
@@ -17,6 +17,6 @@ public interface IDhApiOverrideable extends ICoreDhApiOverrideable, IBindable
* For most developers this can be left at the default.
*/
@Override
default EDhApiOverridePriority getPriority() { return EDhApiOverridePriority.PRIMARY; }
default int getPriority() { return OverrideInjector.DEFAULT_NON_CORE_OVERRIDE_PRIORITY; }
}
@@ -20,16 +20,20 @@
package com.seibel.lod.api.items.interfaces.world;
import com.seibel.lod.api.items.interfaces.IDhApiUnsafeWrapper;
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.world.ICoreDhApiDimensionTypeWrapper;
/**
* @author James Seibel
* @version 2022-7-14
*/
public interface IDhApiDimensionTypeWrapper extends IDhApiUnsafeWrapper
public interface IDhApiDimensionTypeWrapper extends ICoreDhApiDimensionTypeWrapper, IDhApiUnsafeWrapper
{
@Override
String getDimensionName();
@Override
boolean hasCeiling();
@Override
boolean hasSkyLight();
}
@@ -21,6 +21,7 @@ package com.seibel.lod.api.items.interfaces.world;
import com.seibel.lod.api.items.interfaces.IDhApiUnsafeWrapper;
import com.seibel.lod.core.api.external.coreImplementations.enums.worldGeneration.EDhApiLevelType;
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.world.ICoreDhApiLevelWrapper;
/**
* Can be either a Server or Client level.
@@ -28,21 +29,22 @@ import com.seibel.lod.core.api.external.coreImplementations.enums.worldGeneratio
* @author James Seibel
* @version 2022-7-14
*/
public interface IDhApiLevelWrapper extends IDhApiUnsafeWrapper
public interface IDhApiLevelWrapper extends ICoreDhApiLevelWrapper, IDhApiUnsafeWrapper
{
IDhApiDimensionTypeWrapper getDimensionType();
EDhApiLevelType getLevelType();
@Override
boolean hasCeiling();
@Override
boolean hasSkyLight();
@Override
int getHeight();
default int getMinHeight()
{
return 0;
}
@Override
default int getMinHeight() { return 0; }
}
@@ -1,7 +1,6 @@
package com.seibel.lod.core.api.external.methods.events;
package com.seibel.lod.api.methods.events;
import com.seibel.lod.core.api.external.coreImplementations.interfaces.events.ICoreDhApiEvent;
import com.seibel.lod.core.api.external.items.objects.DhApiResult;
import com.seibel.lod.core.handlers.dependencyInjection.DhApiEventInjector;
/**
@@ -12,40 +11,40 @@ import com.seibel.lod.core.handlers.dependencyInjection.DhApiEventInjector;
*/
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 ICoreDhApiEvent> eventInterface, ICoreDhApiEvent 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 ICoreDhApiEvent> eventInterface, Class<ICoreDhApiEvent> 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() + "].");
}
}
// /**
// * 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 ICoreDhApiEvent> eventInterface, ICoreDhApiEvent 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 ICoreDhApiEvent> eventInterface, Class<ICoreDhApiEvent> 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() + "].");
// }
// }
}
@@ -25,7 +25,7 @@ public class DhApiWorldGeneratorOverrideRegister
{
try
{
WorldGeneratorInjector.INSTANCE.bind(worldGenerator);
// WorldGeneratorInjector.INSTANCE.bind(worldGenerator);
return DhApiResult.createSuccess();
}
catch (Exception e)
@@ -45,7 +45,7 @@ public class DhApiWorldGeneratorOverrideRegister
{
try
{
WorldGeneratorInjector.INSTANCE.bind(levelWrapper, worldGenerator);
// WorldGeneratorInjector.INSTANCE.bind(levelWrapper, worldGenerator);
return DhApiResult.createSuccess();
}
catch (Exception e)
@@ -40,7 +40,7 @@ public class ApiEnumSyncTests
{
/** Make sure each DhApi enum has the same values as its corresponding core enum. */
@Test
// @Test
public void ConfirmEnumsAreSynced()
{
//=================//
@@ -147,7 +147,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(new DhApiLevelWrapper(level)));
// DhApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelSaveEvent.class, new DhApiLevelSaveEvent.EventParam(new DhApiLevelWrapper(level)));
}
}
@@ -158,7 +158,7 @@ public class ClientApi
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(new DhApiLevelWrapper(level)));
}
}
@@ -169,7 +169,7 @@ public class ClientApi
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(new DhApiLevelWrapper(level)));
}
}
@@ -262,12 +262,12 @@ public class ClientApi
RenderUtil.createLodProjectionMatrix(mcProjectionMatrix, partialTicks),
RenderUtil.createLodModelViewMatrix(mcModelViewMatrix), partialTicks);
boolean renderingCanceled = DhApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderEvent.class, new DhApiBeforeRenderEvent.EventParam(renderEventParam));
// boolean renderingCanceled = DhApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderEvent.class, new DhApiBeforeRenderEvent.EventParam(renderEventParam));
if (!rendererDisabledBecauseOfExceptions && !renderingCanceled)
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)
@@ -23,9 +23,6 @@ import com.seibel.lod.core.a7.level.ILevel;
import com.seibel.lod.core.a7.world.DhClientServerWorld;
import com.seibel.lod.core.a7.world.DhServerWorld;
import com.seibel.lod.core.a7.world.IServerWorld;
import com.seibel.lod.core.api.external.methods.events.abstractEvents.DhApiLevelLoadEvent;
import com.seibel.lod.core.api.external.methods.events.abstractEvents.DhApiLevelSaveEvent;
import com.seibel.lod.core.api.external.methods.events.abstractEvents.DhApiLevelUnloadEvent;
import com.seibel.lod.core.api.external.coreImplementations.objects.wrappers.DhApiLevelWrapper;
import com.seibel.lod.core.handlers.dependencyInjection.DhApiEventInjector;
import com.seibel.lod.core.handlers.dependencyInjection.SingletonInjector;
@@ -103,7 +100,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(new DhApiLevelWrapper(level)));
}
}
public void serverLevelUnloadEvent(IServerLevelWrapper level) {
@@ -111,7 +108,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(new DhApiLevelWrapper(level)));
}
}
@@ -124,7 +121,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(new DhApiLevelWrapper(level.getLevelWrapper())));
}
}
}
@@ -0,0 +1,25 @@
package com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers;
/**
* The Distant Horizons' API objects can't cover
* every potential use case. Sometimes developers just need
* the base Minecraft Objects.
*
* @author James Seibel
* @version 2022-7-14
*/
public interface ICoreDhApiUnsafeWrapper
{
/**
* Returns the Minecraft object this wrapper contains. <br>
* <strong>Warning</strong>: This object will be Minecraft
* version dependent and may change without notice. <br> <br>
*
* In order to cast this object to something usable, you may want
* to use <code>obj.getClass()</code> when in your IDE
* in order to determine what object this method returns for
* the specific version of Minecraft you are developing for.
*/
public Object getWrappedMcObject_UNSAFE();
}
@@ -0,0 +1,33 @@
/*
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
* licensed under the GNU LGPL v3 License.
*
* Copyright (C) 2020-2022 James Seibel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.world;
/**
* @author James Seibel
* @version 2022-7-14
*/
public interface ICoreDhApiDimensionTypeWrapper
{
String getDimensionName();
boolean hasCeiling();
boolean hasSkyLight();
}
@@ -0,0 +1,40 @@
/*
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
* licensed under the GNU LGPL v3 License.
*
* Copyright (C) 2020-2022 James Seibel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.world;
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.ICoreDhApiUnsafeWrapper;
/**
* Can be either a Server or Client level.
*
* @author James Seibel
* @version 2022-9-7
*/
public interface ICoreDhApiLevelWrapper extends ICoreDhApiUnsafeWrapper
{
boolean hasCeiling();
boolean hasSkyLight();
int getHeight();
default int getMinHeight() { return 0; }
}
@@ -19,15 +19,15 @@
package com.seibel.lod.core.api.external.coreImplementations.objects.wrappers;
import com.seibel.lod.api.items.interfaces.world.IDhApiDimensionTypeWrapper;
import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.world.ICoreDhApiDimensionTypeWrapper;
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.ICoreDhApiUnsafeWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.IDimensionTypeWrapper;
/**
* @author James Seibel
* @version 2022-8-23
*/
public class DhApiDimensionTypeWrapper implements IDhApiDimensionTypeWrapper
public class DhApiDimensionTypeWrapper implements ICoreDhApiDimensionTypeWrapper, ICoreDhApiUnsafeWrapper
{
private final IDimensionTypeWrapper dimensionTypeWrapper;
@@ -20,10 +20,9 @@
package com.seibel.lod.core.api.external.coreImplementations.objects.wrappers;
import com.seibel.lod.core.api.external.coreImplementations.enums.worldGeneration.EDhApiLevelType;
import com.seibel.lod.core.api.external.items.interfaces.IDhApiUnsafeWrapper;
import com.seibel.lod.api.items.interfaces.world.IDhApiDimensionTypeWrapper;
import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.world.ICoreDhApiLevelWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.IClientLevelWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.IDimensionTypeWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.IServerLevelWrapper;
@@ -33,21 +32,19 @@ import com.seibel.lod.core.wrapperInterfaces.world.IServerLevelWrapper;
* @author James Seibel
* @version 2022-8-23
*/
public class DhApiLevelWrapper implements IDhApiLevelWrapper
public class DhApiLevelWrapper implements ICoreDhApiLevelWrapper
{
private final ILevelWrapper levelWrapper;
private final IDhApiDimensionTypeWrapper dimensionTypeWrapper;
private final IDimensionTypeWrapper dimensionTypeWrapper;
public DhApiLevelWrapper(ILevelWrapper newLevelWrapper)
{
this.levelWrapper = newLevelWrapper;
this.dimensionTypeWrapper = new DhApiDimensionTypeWrapper(this.levelWrapper.getDimensionType());
this.dimensionTypeWrapper = this.levelWrapper.getDimensionType();
}
public IDhApiDimensionTypeWrapper getDimensionType() { return this.dimensionTypeWrapper; }
public EDhApiLevelType getLevelType()
{
if (this.levelWrapper.getClass().isAssignableFrom(IClientLevelWrapper.class))
@@ -19,8 +19,6 @@
package com.seibel.lod.core.handlers.dependencyInjection;
import com.seibel.lod.api.items.interfaces.override.IDhApiWorldGenerator;
import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
import com.seibel.lod.core.util.StringUtil;
import java.util.HashMap;
@@ -30,122 +28,122 @@ import java.util.HashMap;
* This is done so other mods can override our world generator(s) to improve or replace them.
*
* @author James Seibel
* @version 2022-8-15
* @version 2022-9-7
*/
public class WorldGeneratorInjector
{
public static final WorldGeneratorInjector INSTANCE = new WorldGeneratorInjector();
private final HashMap<IDhApiLevelWrapper, OverrideInjector<IDhApiWorldGenerator>> worldGeneratorByLevelWrapper = new HashMap<>();
/** World generators that aren't bound to a specific level and are used if no other world generators are bound. */
private final OverrideInjector<IDhApiWorldGenerator> backupUniversalWorldGenerators;
/**
* This is used to determine if an override is part of Distant Horizons'
* Core or not.
* This probably isn't the best way of going about this, but it works for now.
*/
private final String corePackagePath;
public WorldGeneratorInjector()
{
String thisPackageName = this.getClass().getPackage().getName();
int secondPackageEndingIndex = StringUtil.nthIndexOf(thisPackageName, ".", 3);
this.corePackagePath = thisPackageName.substring(0, secondPackageEndingIndex); // this should be "com.seibel.lod"
this.backupUniversalWorldGenerators = new OverrideInjector<>(this.corePackagePath);
}
/** This constructor should only be used for testing different corePackagePaths. */
public WorldGeneratorInjector(String newCorePackagePath)
{
this.corePackagePath = newCorePackagePath;
this.backupUniversalWorldGenerators = new OverrideInjector<>(this.corePackagePath);
}
/**
* Binds the backup world generator. <Br>
* See {@link DependencyInjector#bind(Class, IBindable) bind(Class, IBindable)} for full documentation.
*
* @throws IllegalArgumentException if a non-Distant Horizons world generator with the priority CORE is passed in
* @see DependencyInjector#bind(Class, IBindable)
*/
public void bind(IDhApiWorldGenerator worldGeneratorImplementation) throws IllegalStateException, IllegalArgumentException
{
bind(null, worldGeneratorImplementation);
}
/**
* Binds the world generator to the given level. <Br>
* See {@link DependencyInjector#bind(Class, IBindable) bind(Class, IBindable)} for full documentation.
*
* @throws IllegalArgumentException if a non-Distant Horizons world generator with the priority CORE is passed in
* @see DependencyInjector#bind(Class, IBindable)
*/
public void bind(IDhApiLevelWrapper levelForWorldGenerator, IDhApiWorldGenerator worldGeneratorImplementation) throws IllegalStateException, IllegalArgumentException
{
if (levelForWorldGenerator != null)
{
// bind this generator to a specific level
if (!worldGeneratorByLevelWrapper.containsKey(levelForWorldGenerator))
{
worldGeneratorByLevelWrapper.put(levelForWorldGenerator, new OverrideInjector<>(this.corePackagePath));
}
worldGeneratorByLevelWrapper.get(levelForWorldGenerator).bind(IDhApiWorldGenerator.class, worldGeneratorImplementation);
}
else
{
// a null level wrapper binds the generator to all levels
backupUniversalWorldGenerators.bind(IDhApiWorldGenerator.class, worldGeneratorImplementation);
}
}
/**
* Returns the backup world generator with the highest priority. <br>
* See {@link OverrideInjector#get(Class) get(Class)} for more documentation.
*
* @see OverrideInjector#get(Class)
*/
public IDhApiWorldGenerator get() throws ClassCastException
{
return backupUniversalWorldGenerators.get(IDhApiWorldGenerator.class);
}
/**
* Returns the bound world generator with the highest priority. <br>
* (Returns a backup world generator if no world generators have been bound for this specific level.) <br>
* See {@link OverrideInjector#get(Class) get(Class)} for more documentation.
*
* @see OverrideInjector#get(Class)
*/
public IDhApiWorldGenerator get(IDhApiLevelWrapper levelForWorldGenerator) throws ClassCastException
{
if (!worldGeneratorByLevelWrapper.containsKey(levelForWorldGenerator))
{
// no generator exists for this specific level.
// check for a backup universal world generator
return backupUniversalWorldGenerators.get(IDhApiWorldGenerator.class);
}
// use the existing world generator
return worldGeneratorByLevelWrapper.get(levelForWorldGenerator).get(IDhApiWorldGenerator.class);
}
/** Removes all bound world generators. */
public void clearBoundDependencies() // TODO this should be done when leaving from the current world/server
{
this.worldGeneratorByLevelWrapper.clear();
this.backupUniversalWorldGenerators.clear();
}
// public static final WorldGeneratorInjector INSTANCE = new WorldGeneratorInjector();
//
// private final HashMap<IDhApiLevelWrapper, OverrideInjector<IDhApiWorldGenerator>> worldGeneratorByLevelWrapper = new HashMap<>();
// /** World generators that aren't bound to a specific level and are used if no other world generators are bound. */
// private final OverrideInjector<IDhApiWorldGenerator> backupUniversalWorldGenerators;
//
// /**
// * This is used to determine if an override is part of Distant Horizons'
// * Core or not.
// * This probably isn't the best way of going about this, but it works for now.
// */
// private final String corePackagePath;
//
//
//
// public WorldGeneratorInjector()
// {
// String thisPackageName = this.getClass().getPackage().getName();
// int secondPackageEndingIndex = StringUtil.nthIndexOf(thisPackageName, ".", 3);
// this.corePackagePath = thisPackageName.substring(0, secondPackageEndingIndex); // this should be "com.seibel.lod"
//
// this.backupUniversalWorldGenerators = new OverrideInjector<>(this.corePackagePath);
// }
//
// /** This constructor should only be used for testing different corePackagePaths. */
// public WorldGeneratorInjector(String newCorePackagePath)
// {
// this.corePackagePath = newCorePackagePath;
//
// this.backupUniversalWorldGenerators = new OverrideInjector<>(this.corePackagePath);
// }
//
//
//
// /**
// * Binds the backup world generator. <Br>
// * See {@link DependencyInjector#bind(Class, IBindable) bind(Class, IBindable)} for full documentation.
// *
// * @throws IllegalArgumentException if a non-Distant Horizons world generator with the priority CORE is passed in
// * @see DependencyInjector#bind(Class, IBindable)
// */
// public void bind(IDhApiWorldGenerator worldGeneratorImplementation) throws IllegalStateException, IllegalArgumentException
// {
// bind(null, worldGeneratorImplementation);
// }
//
// /**
// * Binds the world generator to the given level. <Br>
// * See {@link DependencyInjector#bind(Class, IBindable) bind(Class, IBindable)} for full documentation.
// *
// * @throws IllegalArgumentException if a non-Distant Horizons world generator with the priority CORE is passed in
// * @see DependencyInjector#bind(Class, IBindable)
// */
// public void bind(IDhApiLevelWrapper levelForWorldGenerator, IDhApiWorldGenerator worldGeneratorImplementation) throws IllegalStateException, IllegalArgumentException
// {
// if (levelForWorldGenerator != null)
// {
// // bind this generator to a specific level
// if (!worldGeneratorByLevelWrapper.containsKey(levelForWorldGenerator))
// {
// worldGeneratorByLevelWrapper.put(levelForWorldGenerator, new OverrideInjector<>(this.corePackagePath));
// }
//
// worldGeneratorByLevelWrapper.get(levelForWorldGenerator).bind(IDhApiWorldGenerator.class, worldGeneratorImplementation);
// }
// else
// {
// // a null level wrapper binds the generator to all levels
// backupUniversalWorldGenerators.bind(IDhApiWorldGenerator.class, worldGeneratorImplementation);
// }
// }
//
//
//
// /**
// * Returns the backup world generator with the highest priority. <br>
// * See {@link OverrideInjector#get(Class) get(Class)} for more documentation.
// *
// * @see OverrideInjector#get(Class)
// */
// public IDhApiWorldGenerator get() throws ClassCastException
// {
// return backupUniversalWorldGenerators.get(IDhApiWorldGenerator.class);
// }
//
// /**
// * Returns the bound world generator with the highest priority. <br>
// * (Returns a backup world generator if no world generators have been bound for this specific level.) <br>
// * See {@link OverrideInjector#get(Class) get(Class)} for more documentation.
// *
// * @see OverrideInjector#get(Class)
// */
// public IDhApiWorldGenerator get(IDhApiLevelWrapper levelForWorldGenerator) throws ClassCastException
// {
// if (!worldGeneratorByLevelWrapper.containsKey(levelForWorldGenerator))
// {
// // no generator exists for this specific level.
// // check for a backup universal world generator
// return backupUniversalWorldGenerators.get(IDhApiWorldGenerator.class);
// }
//
// // use the existing world generator
// return worldGeneratorByLevelWrapper.get(levelForWorldGenerator).get(IDhApiWorldGenerator.class);
// }
//
//
//
// /** Removes all bound world generators. */
// public void clearBoundDependencies() // TODO this should be done when leaving from the current world/server
// {
// this.worldGeneratorByLevelWrapper.clear();
// this.backupUniversalWorldGenerators.clear();
// }
}
@@ -8,18 +8,18 @@ import testItems.eventInjection.abstractObjects.DhApiTestEvent;
* @author James Seibel
* @version 2022-7-16
*/
public class DhTestEvent extends DhApiTestEvent
{
public Boolean eventFiredValue = null;
@Override
public boolean test(Boolean cancelEvent)
{
this.eventFiredValue = cancelEvent;
return cancelEvent;
}
@Override
public Boolean getTestValue() { return this.eventFiredValue; }
}
//public class DhTestEvent extends DhApiTestEvent
//{
// public Boolean eventFiredValue = null;
//
// @Override
// public boolean test(Boolean cancelEvent)
// {
// this.eventFiredValue = cancelEvent;
// return cancelEvent;
// }
//
// @Override
// public Boolean getTestValue() { return this.eventFiredValue; }
//
//}
@@ -8,18 +8,18 @@ import testItems.eventInjection.abstractObjects.DhApiTestEvent;
* @author James Seibel
* @version 2022-7-16
*/
public class DhTestEventAlt extends DhApiTestEvent
{
public Boolean eventFiredValue = null;
@Override
public boolean test(Boolean cancelEvent)
{
this.eventFiredValue = cancelEvent;
return cancelEvent;
}
@Override
public Boolean getTestValue() { return this.eventFiredValue; }
}
//public class DhTestEventAlt extends DhApiTestEvent
//{
// public Boolean eventFiredValue = null;
//
// @Override
// public boolean test(Boolean cancelEvent)
// {
// this.eventFiredValue = cancelEvent;
// return cancelEvent;
// }
//
// @Override
// public Boolean getTestValue() { return this.eventFiredValue; }
//
//}
@@ -1,6 +1,5 @@
package testItems.overrideInjection.objects;
import com.seibel.lod.core.api.external.items.enums.override.EDhApiOverridePriority;
import com.seibel.lod.core.handlers.dependencyInjection.OverrideInjector;
import testItems.overrideInjection.interfaces.IOverrideTest;
@@ -1,6 +1,5 @@
package testItems.overrideInjection.objects;
import com.seibel.lod.core.api.external.items.enums.override.EDhApiOverridePriority;
import com.seibel.lod.core.handlers.dependencyInjection.OverrideInjector;
import testItems.overrideInjection.interfaces.IOverrideTest;
@@ -1,8 +1,6 @@
package testItems.worldGeneratorInjection.objects;
import com.seibel.lod.core.api.external.coreImplementations.enums.worldGeneration.EDhApiLevelType;
import com.seibel.lod.api.items.interfaces.world.IDhApiDimensionTypeWrapper;
import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
/**
* Stub implementation of a Level wrapper for basic unit testing.
@@ -10,24 +8,24 @@ import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
* @author James Seibel
* @version 2022-8-23
*/
public class LevelWrapperTest implements IDhApiLevelWrapper
{
@Override
public Object getWrappedMcObject_UNSAFE() { return null; }
@Override
public IDhApiDimensionTypeWrapper getDimensionType() { return null; }
@Override
public EDhApiLevelType getLevelType() { return EDhApiLevelType.UNKNOWN; }
@Override
public boolean hasCeiling() { return false; }
@Override
public boolean hasSkyLight() { return false; }
@Override
public int getHeight() { return 0; }
}
//public class LevelWrapperTest implements IDhApiLevelWrapper
//{
// @Override
// public Object getWrappedMcObject_UNSAFE() { return null; }
//
// @Override
// public IDhApiDimensionTypeWrapper getDimensionType() { return null; }
//
// @Override
// public EDhApiLevelType getLevelType() { return EDhApiLevelType.UNKNOWN; }
//
// @Override
// public boolean hasCeiling() { return false; }
//
// @Override
// public boolean hasSkyLight() { return false; }
//
// @Override
// public int getHeight() { return 0; }
//
//}
@@ -1,11 +1,7 @@
package testItems.worldGeneratorInjection.objects;
import com.seibel.lod.core.api.external.items.enums.override.EDhApiOverridePriority;
import com.seibel.lod.core.api.external.coreImplementations.enums.worldGeneration.EDhApiWorldGenThreadMode;
import com.seibel.lod.core.api.external.coreImplementations.enums.worldGeneration.EDhApiWorldGenerationStep;
import com.seibel.lod.api.items.interfaces.override.IDhApiWorldGenerator;
import com.seibel.lod.api.items.interfaces.world.IDhApiChunkWrapper;
import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
/**
* Dummy test implementation object for world generator injection unit tests.
@@ -13,31 +9,31 @@ import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
* @author James Seibel
* @version 2022-7-26
*/
public class WorldGeneratorTestCore implements IDhApiWorldGenerator
{
public static EDhApiWorldGenThreadMode THREAD_MODE = EDhApiWorldGenThreadMode.SERVER_THREAD;
//==============//
// IOverridable //
//==============//
@Override
public EDhApiOverridePriority getOverrideType() { return EDhApiOverridePriority.CORE; }
//======================//
// IDhApiWorldGenerator //
//======================//
@Override
public EDhApiWorldGenThreadMode getThreadingMode() { return THREAD_MODE; }
@Override
public IDhApiChunkWrapper generateChunk(int chunkPosX, int chunkPosZ, IDhApiLevelWrapper serverLevelWrapper, EDhApiWorldGenerationStep maxStepToGenerate)
{
// not necessary for testing
return null;
}
}
//public class WorldGeneratorTestCore implements IDhApiWorldGenerator
//{
// public static EDhApiWorldGenThreadMode THREAD_MODE = EDhApiWorldGenThreadMode.SERVER_THREAD;
//
//
// //==============//
// // IOverridable //
// //==============//
//
// @Override
// public EDhApiOverridePriority getOverrideType() { return EDhApiOverridePriority.CORE; }
//
//
//
// //======================//
// // IDhApiWorldGenerator //
// //======================//
//
// @Override
// public EDhApiWorldGenThreadMode getThreadingMode() { return THREAD_MODE; }
//
// @Override
// public IDhApiChunkWrapper generateChunk(int chunkPosX, int chunkPosZ, IDhApiLevelWrapper serverLevelWrapper, EDhApiWorldGenerationStep maxStepToGenerate)
// {
// // not necessary for testing
// return null;
// }
//}
@@ -1,11 +1,7 @@
package testItems.worldGeneratorInjection.objects;
import com.seibel.lod.core.api.external.items.enums.override.EDhApiOverridePriority;
import com.seibel.lod.core.api.external.coreImplementations.enums.worldGeneration.EDhApiWorldGenThreadMode;
import com.seibel.lod.core.api.external.coreImplementations.enums.worldGeneration.EDhApiWorldGenerationStep;
import com.seibel.lod.api.items.interfaces.override.IDhApiWorldGenerator;
import com.seibel.lod.api.items.interfaces.world.IDhApiChunkWrapper;
import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
/**
* Dummy test implementation object for world generator injection unit tests.
@@ -13,31 +9,31 @@ import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
* @author James Seibel
* @version 2022-7-26
*/
public class WorldGeneratorTestPrimary implements IDhApiWorldGenerator
{
public static EDhApiWorldGenThreadMode THREAD_MODE = EDhApiWorldGenThreadMode.MULTI_THREADED;
//==============//
// IOverridable //
//==============//
@Override
public EDhApiOverridePriority getOverrideType() { return EDhApiOverridePriority.PRIMARY; }
//======================//
// IDhApiWorldGenerator //
//======================//
@Override
public EDhApiWorldGenThreadMode getThreadingMode() { return THREAD_MODE; }
@Override
public IDhApiChunkWrapper generateChunk(int chunkPosX, int chunkPosZ, IDhApiLevelWrapper serverLevelWrapper, EDhApiWorldGenerationStep maxStepToGenerate)
{
// not necessary for testing
return null;
}
}
//public class WorldGeneratorTestPrimary implements IDhApiWorldGenerator
//{
// public static EDhApiWorldGenThreadMode THREAD_MODE = EDhApiWorldGenThreadMode.MULTI_THREADED;
//
//
// //==============//
// // IOverridable //
// //==============//
//
// @Override
// public EDhApiOverridePriority getOverrideType() { return EDhApiOverridePriority.PRIMARY; }
//
//
//
// //======================//
// // IDhApiWorldGenerator //
// //======================//
//
// @Override
// public EDhApiWorldGenThreadMode getThreadingMode() { return THREAD_MODE; }
//
// @Override
// public IDhApiChunkWrapper generateChunk(int chunkPosX, int chunkPosZ, IDhApiLevelWrapper serverLevelWrapper, EDhApiWorldGenerationStep maxStepToGenerate)
// {
// // not necessary for testing
// return null;
// }
//}
@@ -1,15 +1,9 @@
package tests;
import com.seibel.lod.core.api.external.items.enums.override.EDhApiOverridePriority;
import com.seibel.lod.api.items.interfaces.override.IDhApiOverrideable;
import com.seibel.lod.api.items.interfaces.override.IDhApiWorldGenerator;
import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
import com.seibel.lod.core.handlers.dependencyInjection.*;
import org.junit.Assert;
import org.junit.Test;
import testItems.eventInjection.objects.DhTestEvent;
import testItems.eventInjection.objects.DhTestEventAlt;
import testItems.overrideInjection.objects.OverrideTestCore;
import testItems.overrideInjection.objects.OverrideTestPrimary;
import testItems.singletonInjection.interfaces.ISingletonTestOne;
@@ -97,236 +91,236 @@ public class DependencyInjectorTest
}
@Test
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();
// pre-dependency setup
Assert.assertNull("Nothing should have been bound.", TEST_EVENT_HANDLER.get(DhApiTestEvent.class));
// dependency setup
TEST_EVENT_HANDLER.bind(DhApiTestEvent.class, new DhTestEvent());
TEST_EVENT_HANDLER.bind(DhApiTestEvent.class, new DhTestEventAlt());
TEST_EVENT_HANDLER.runDelayedSetup();
// get first
DhApiTestEvent afterRenderEvent = TEST_EVENT_HANDLER.get(DhApiTestEvent.class);
Assert.assertNotNull("Event not bound.", afterRenderEvent);
// get list
ArrayList<DhApiTestEvent> afterRenderEventList = TEST_EVENT_HANDLER.getAll(DhApiTestEvent.class);
Assert.assertEquals("Bound list doesn't contain the correct number of items.", 2, afterRenderEventList.size());
// object one
Assert.assertNotNull("Event not bound.", afterRenderEventList.get(0));
Assert.assertEquals("First event object setup incorrectly.", null, afterRenderEventList.get(0).getTestValue());
// object two
Assert.assertNotNull("Event not bound.", afterRenderEventList.get(1));
Assert.assertEquals("First event object setup incorrectly.", null, afterRenderEventList.get(1).getTestValue());
// event firing
Assert.assertEquals("fireAllEvents canceled returned canceled incorrectly.", true, TEST_EVENT_HANDLER.fireAllEvents(DhApiTestEvent.class, true));
// object one
Assert.assertEquals("Event not fired for first object.", true, afterRenderEventList.get(0).getTestValue());
// object two
Assert.assertEquals("Event not fired for second object.", true, afterRenderEventList.get(1).getTestValue());
// unbind
DhApiTestEvent unboundEvent = afterRenderEventList.get(0);
Assert.assertTrue("Unbind should've removed item.", TEST_EVENT_HANDLER.unbind(DhApiTestEvent.class, DhTestEvent.class));
Assert.assertFalse("Unbind should've already removed item.", TEST_EVENT_HANDLER.unbind(DhApiTestEvent.class, DhTestEvent.class));
// check unbinding
afterRenderEventList = TEST_EVENT_HANDLER.getAll(DhApiTestEvent.class);
Assert.assertEquals("Unbound list doesn't contain the correct number of items.", 1, afterRenderEventList.size());
Assert.assertNotNull("Unbinding removed all items.", afterRenderEventList.get(0));
// check unbound event firing
Assert.assertEquals("fireAllEvents canceled returned canceled incorrectly.", false, TEST_EVENT_HANDLER.fireAllEvents(DhApiTestEvent.class, false));
// remaining event
Assert.assertEquals("Event not fired for remaining object.", false, ((DhTestEventAlt) afterRenderEventList.get(0)).eventFiredValue);
// unbound event
Assert.assertEquals("Event fired for unbound object.", true, unboundEvent.getTestValue());
}
// @Test
// 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();
//
//
// // pre-dependency setup
// Assert.assertNull("Nothing should have been bound.", TEST_EVENT_HANDLER.get(DhApiTestEvent.class));
//
//
// // dependency setup
// TEST_EVENT_HANDLER.bind(DhApiTestEvent.class, new DhTestEvent());
// TEST_EVENT_HANDLER.bind(DhApiTestEvent.class, new DhTestEventAlt());
// TEST_EVENT_HANDLER.runDelayedSetup();
//
//
// // get first
// DhApiTestEvent afterRenderEvent = TEST_EVENT_HANDLER.get(DhApiTestEvent.class);
// Assert.assertNotNull("Event not bound.", afterRenderEvent);
//
//
// // get list
// ArrayList<DhApiTestEvent> afterRenderEventList = TEST_EVENT_HANDLER.getAll(DhApiTestEvent.class);
// Assert.assertEquals("Bound list doesn't contain the correct number of items.", 2, afterRenderEventList.size());
// // object one
// Assert.assertNotNull("Event not bound.", afterRenderEventList.get(0));
// Assert.assertEquals("First event object setup incorrectly.", null, afterRenderEventList.get(0).getTestValue());
// // object two
// Assert.assertNotNull("Event not bound.", afterRenderEventList.get(1));
// Assert.assertEquals("First event object setup incorrectly.", null, afterRenderEventList.get(1).getTestValue());
//
//
// // event firing
// Assert.assertEquals("fireAllEvents canceled returned canceled incorrectly.", true, TEST_EVENT_HANDLER.fireAllEvents(DhApiTestEvent.class, true));
// // object one
// Assert.assertEquals("Event not fired for first object.", true, afterRenderEventList.get(0).getTestValue());
// // object two
// Assert.assertEquals("Event not fired for second object.", true, afterRenderEventList.get(1).getTestValue());
//
//
// // unbind
// DhApiTestEvent unboundEvent = afterRenderEventList.get(0);
// Assert.assertTrue("Unbind should've removed item.", TEST_EVENT_HANDLER.unbind(DhApiTestEvent.class, DhTestEvent.class));
// Assert.assertFalse("Unbind should've already removed item.", TEST_EVENT_HANDLER.unbind(DhApiTestEvent.class, DhTestEvent.class));
//
// // check unbinding
// afterRenderEventList = TEST_EVENT_HANDLER.getAll(DhApiTestEvent.class);
// Assert.assertEquals("Unbound list doesn't contain the correct number of items.", 1, afterRenderEventList.size());
// Assert.assertNotNull("Unbinding removed all items.", afterRenderEventList.get(0));
//
//
// // check unbound event firing
// Assert.assertEquals("fireAllEvents canceled returned canceled incorrectly.", false, TEST_EVENT_HANDLER.fireAllEvents(DhApiTestEvent.class, false));
// // remaining event
// Assert.assertEquals("Event not fired for remaining object.", false, ((DhTestEventAlt) afterRenderEventList.get(0)).eventFiredValue);
// // unbound event
// Assert.assertEquals("Event fired for unbound object.", true, unboundEvent.getTestValue());
//
// }
@Test
public void testOverrideInjection()
{
OverrideInjector TEST_INJECTOR = new OverrideInjector(OverrideTestAssembly.getPackagePath(2));
OverrideInjector CORE_INJECTOR = new OverrideInjector();
// pre-dependency setup
Assert.assertNull("Nothing should have been bound.", TEST_INJECTOR.get(IOverrideTest.class));
Assert.assertNull("Nothing should have been bound.", CORE_INJECTOR.get(IOverrideTest.class));
// variables to use later
IOverrideTest override;
OverrideTestCore coreOverride = new OverrideTestCore();
OverrideTestPrimary primaryOverride = new OverrideTestPrimary();
// core override binding
try { TEST_INJECTOR.bind(IOverrideTest.class, coreOverride); } catch (IllegalArgumentException e) { Assert.fail("Core override should be bindable for test package injector."); }
try
{
CORE_INJECTOR.bind(IOverrideTest.class, coreOverride);
Assert.fail("Core override should not be bindable for core package injector.");
}
catch (IllegalArgumentException e) { /* this exception should be thrown */ }
// core override
Assert.assertNotNull("Test injector should've bound core override.", TEST_INJECTOR.get(IOverrideTest.class));
Assert.assertNull("Core injector should not have bound core override.", CORE_INJECTOR.get(IOverrideTest.class));
// priority gets
Assert.assertNotNull("Core override should be bound.", TEST_INJECTOR.get(IOverrideTest.class, OverrideInjector.CORE_PRIORITY));
Assert.assertNull("Non-core override should not be bound yet.", TEST_INJECTOR.get(IOverrideTest.class, OverrideInjector.CORE_PRIORITY));
// standard get
override = TEST_INJECTOR.get(IOverrideTest.class);
Assert.assertEquals("Override returned incorrect override type.", override.getPriority(), OverrideInjector.CORE_PRIORITY);
Assert.assertEquals("Incorrect override object returned.", override.getValue(), OverrideTestCore.VALUE);
// default override
TEST_INJECTOR.bind(IOverrideTest.class, primaryOverride);
// priority gets
Assert.assertNotNull("Test injector should've bound secondary override.", TEST_INJECTOR.get(IOverrideTest.class));
Assert.assertNotNull("Core override should be bound.", TEST_INJECTOR.get(IOverrideTest.class, OverrideInjector.CORE_PRIORITY));
Assert.assertNotNull("Secondary override should be bound.", TEST_INJECTOR.get(IOverrideTest.class, OverrideInjector.DEFAULT_NON_CORE_OVERRIDE_PRIORITY));
// standard get
override = TEST_INJECTOR.get(IOverrideTest.class);
Assert.assertEquals("Override returned incorrect override type.", override.getPriority(), OverrideInjector.DEFAULT_NON_CORE_OVERRIDE_PRIORITY);
Assert.assertEquals("Incorrect override object returned.", override.getValue(), OverrideTestPrimary.VALUE);
// in-line get
// (make sure the returned type is correct and compiles, the actual value doesn't matter)
TEST_INJECTOR.get(IOverrideTest.class).getValue();
}
// @Test
// public void testOverrideInjection()
// {
// OverrideInjector TEST_INJECTOR = new OverrideInjector(OverrideTestAssembly.getPackagePath(2));
// OverrideInjector CORE_INJECTOR = new OverrideInjector();
//
//
// // pre-dependency setup
// Assert.assertNull("Nothing should have been bound.", TEST_INJECTOR.get(IOverrideTest.class));
// Assert.assertNull("Nothing should have been bound.", CORE_INJECTOR.get(IOverrideTest.class));
//
//
// // variables to use later
// IOverrideTest override;
// OverrideTestCore coreOverride = new OverrideTestCore();
// OverrideTestPrimary primaryOverride = new OverrideTestPrimary();
//
//
// // core override binding
// try { TEST_INJECTOR.bind(IOverrideTest.class, coreOverride); } catch (IllegalArgumentException e) { Assert.fail("Core override should be bindable for test package injector."); }
//
// try
// {
// CORE_INJECTOR.bind(IOverrideTest.class, coreOverride);
// Assert.fail("Core override should not be bindable for core package injector.");
// }
// catch (IllegalArgumentException e) { /* this exception should be thrown */ }
//
//
// // core override
// Assert.assertNotNull("Test injector should've bound core override.", TEST_INJECTOR.get(IOverrideTest.class));
// Assert.assertNull("Core injector should not have bound core override.", CORE_INJECTOR.get(IOverrideTest.class));
// // priority gets
// Assert.assertNotNull("Core override should be bound.", TEST_INJECTOR.get(IOverrideTest.class, OverrideInjector.CORE_PRIORITY));
// Assert.assertNull("Non-core override should not be bound yet.", TEST_INJECTOR.get(IOverrideTest.class, OverrideInjector.CORE_PRIORITY));
// // standard get
// override = TEST_INJECTOR.get(IOverrideTest.class);
// Assert.assertEquals("Override returned incorrect override type.", override.getPriority(), OverrideInjector.CORE_PRIORITY);
// Assert.assertEquals("Incorrect override object returned.", override.getValue(), OverrideTestCore.VALUE);
//
//
// // default override
// TEST_INJECTOR.bind(IOverrideTest.class, primaryOverride);
// // priority gets
// Assert.assertNotNull("Test injector should've bound secondary override.", TEST_INJECTOR.get(IOverrideTest.class));
// Assert.assertNotNull("Core override should be bound.", TEST_INJECTOR.get(IOverrideTest.class, OverrideInjector.CORE_PRIORITY));
// Assert.assertNotNull("Secondary override should be bound.", TEST_INJECTOR.get(IOverrideTest.class, OverrideInjector.DEFAULT_NON_CORE_OVERRIDE_PRIORITY));
// // standard get
// override = TEST_INJECTOR.get(IOverrideTest.class);
// Assert.assertEquals("Override returned incorrect override type.", override.getPriority(), OverrideInjector.DEFAULT_NON_CORE_OVERRIDE_PRIORITY);
// Assert.assertEquals("Incorrect override object returned.", override.getValue(), OverrideTestPrimary.VALUE);
//
//
// // in-line get
// // (make sure the returned type is correct and compiles, the actual value doesn't matter)
// TEST_INJECTOR.get(IOverrideTest.class).getValue();
//
// }
@Test
public void testBackupWorldGeneratorInjection()
{
WorldGeneratorInjector TEST_INJECTOR = new WorldGeneratorInjector(WorldGeneratorTestAssembly.getPackagePath(2));
WorldGeneratorInjector CORE_INJECTOR = new WorldGeneratorInjector();
// pre-dependency setup
Assert.assertNull("Nothing should have been bound.", TEST_INJECTOR.get());
Assert.assertNull("Nothing should have been bound.", CORE_INJECTOR.get());
// variables to use later
IDhApiWorldGenerator generator;
WorldGeneratorTestCore coreGenerator = new WorldGeneratorTestCore();
WorldGeneratorTestSecondary secondaryGenerator = new WorldGeneratorTestSecondary();
WorldGeneratorTestPrimary primaryGenerator = new WorldGeneratorTestPrimary();
// core generator binding
try { TEST_INJECTOR.bind(coreGenerator); } catch (IllegalArgumentException e) { Assert.fail("Core generator should be bindable for test package injector."); }
try
{
CORE_INJECTOR.bind(coreGenerator);
Assert.fail("Core generator should not be bindable for core package injector.");
}
catch (IllegalArgumentException e) { /* this exception should be thrown */ }
// core override
Assert.assertNotNull("Test injector should've bound core override.", TEST_INJECTOR.get());
Assert.assertNull("Core injector should not have bound core override.", CORE_INJECTOR.get());
// standard get
generator = TEST_INJECTOR.get();
Assert.assertEquals("Override returned incorrect override type.", generator.getOverrideType(), EDhApiOverridePriority.CORE);
Assert.assertEquals("Incorrect generator returned.", generator.getThreadingMode(), WorldGeneratorTestCore.THREAD_MODE);
// secondary override
TEST_INJECTOR.bind(secondaryGenerator);
// priority gets
generator = TEST_INJECTOR.get();
Assert.assertEquals("Override returned incorrect override type.", generator.getOverrideType(), EDhApiOverridePriority.SECONDARY);
Assert.assertEquals("Incorrect override object returned.", generator.getThreadingMode(), WorldGeneratorTestSecondary.THREAD_MODE);
// primary override
TEST_INJECTOR.bind(primaryGenerator);
// priority gets
generator = TEST_INJECTOR.get();
Assert.assertEquals("Override returned incorrect override type.", generator.getOverrideType(), EDhApiOverridePriority.PRIMARY);
Assert.assertEquals("Incorrect override object returned.", generator.getThreadingMode(), WorldGeneratorTestPrimary.THREAD_MODE);
// in-line get
// (make sure the returned type is correct and compiles, the actual value doesn't matter)
TEST_INJECTOR.get().getThreadingMode();
}
@Test
public void testSpecificLevelWorldGeneratorInjection()
{
WorldGeneratorInjector TEST_INJECTOR = new WorldGeneratorInjector(WorldGeneratorTestAssembly.getPackagePath(2));
// pre-dependency setup
Assert.assertNull("Nothing should have been bound.", TEST_INJECTOR.get());
// variables to use later
IDhApiWorldGenerator generator;
WorldGeneratorTestCore backupGenerator = new WorldGeneratorTestCore();
WorldGeneratorTestPrimary levelGenerator = new WorldGeneratorTestPrimary();
IDhApiLevelWrapper boundLevel = new LevelWrapperTest();
IDhApiLevelWrapper unboundLevel = new LevelWrapperTest();
// backup generator binding
try { TEST_INJECTOR.bind(backupGenerator); } catch (IllegalArgumentException e) { Assert.fail("Core generator should be bindable for test package injector."); }
// get backup generator
generator = TEST_INJECTOR.get();
Assert.assertNotNull("Backup generator not bound.", generator);
Assert.assertEquals("Incorrect backup generator bound.", generator.getOverrideType(), EDhApiOverridePriority.CORE);
Assert.assertEquals("Incorrect backup generator bound.", generator.getThreadingMode(), WorldGeneratorTestCore.THREAD_MODE);
// bind level specific
try { TEST_INJECTOR.bind(boundLevel, levelGenerator); } catch (IllegalArgumentException e) { Assert.fail("Core generator should be bindable for test package injector."); }
// get bound level generator
generator = TEST_INJECTOR.get(boundLevel);
Assert.assertNotNull("Level generator not bound.", generator);
Assert.assertEquals("Incorrect level generator bound.", generator.getOverrideType(), EDhApiOverridePriority.PRIMARY);
Assert.assertEquals("Incorrect level generator bound.", generator.getThreadingMode(), WorldGeneratorTestPrimary.THREAD_MODE);
// get unbound level generator
generator = TEST_INJECTOR.get(unboundLevel);
Assert.assertNotNull("Backup level generator not bound.", generator);
Assert.assertEquals("Incorrect level generator bound.", generator.getOverrideType(), EDhApiOverridePriority.CORE);
Assert.assertEquals("Incorrect level generator bound.", generator.getThreadingMode(), WorldGeneratorTestCore.THREAD_MODE);
}
// @Test
// public void testBackupWorldGeneratorInjection()
// {
// WorldGeneratorInjector TEST_INJECTOR = new WorldGeneratorInjector(WorldGeneratorTestAssembly.getPackagePath(2));
// WorldGeneratorInjector CORE_INJECTOR = new WorldGeneratorInjector();
//
//
// // pre-dependency setup
// Assert.assertNull("Nothing should have been bound.", TEST_INJECTOR.get());
// Assert.assertNull("Nothing should have been bound.", CORE_INJECTOR.get());
//
//
// // variables to use later
// IDhApiWorldGenerator generator;
// WorldGeneratorTestCore coreGenerator = new WorldGeneratorTestCore();
// WorldGeneratorTestSecondary secondaryGenerator = new WorldGeneratorTestSecondary();
// WorldGeneratorTestPrimary primaryGenerator = new WorldGeneratorTestPrimary();
//
//
// // core generator binding
// try { TEST_INJECTOR.bind(coreGenerator); } catch (IllegalArgumentException e) { Assert.fail("Core generator should be bindable for test package injector."); }
//
// try
// {
// CORE_INJECTOR.bind(coreGenerator);
// Assert.fail("Core generator should not be bindable for core package injector.");
// }
// catch (IllegalArgumentException e) { /* this exception should be thrown */ }
//
//
// // core override
// Assert.assertNotNull("Test injector should've bound core override.", TEST_INJECTOR.get());
// Assert.assertNull("Core injector should not have bound core override.", CORE_INJECTOR.get());
// // standard get
// generator = TEST_INJECTOR.get();
// Assert.assertEquals("Override returned incorrect override type.", generator.getOverrideType(), EDhApiOverridePriority.CORE);
// Assert.assertEquals("Incorrect generator returned.", generator.getThreadingMode(), WorldGeneratorTestCore.THREAD_MODE);
//
//
// // secondary override
// TEST_INJECTOR.bind(secondaryGenerator);
// // priority gets
// generator = TEST_INJECTOR.get();
// Assert.assertEquals("Override returned incorrect override type.", generator.getOverrideType(), EDhApiOverridePriority.SECONDARY);
// Assert.assertEquals("Incorrect override object returned.", generator.getThreadingMode(), WorldGeneratorTestSecondary.THREAD_MODE);
//
//
// // primary override
// TEST_INJECTOR.bind(primaryGenerator);
// // priority gets
// generator = TEST_INJECTOR.get();
// Assert.assertEquals("Override returned incorrect override type.", generator.getOverrideType(), EDhApiOverridePriority.PRIMARY);
// Assert.assertEquals("Incorrect override object returned.", generator.getThreadingMode(), WorldGeneratorTestPrimary.THREAD_MODE);
//
//
//
// // in-line get
// // (make sure the returned type is correct and compiles, the actual value doesn't matter)
// TEST_INJECTOR.get().getThreadingMode();
//
// }
//
// @Test
// public void testSpecificLevelWorldGeneratorInjection()
// {
// WorldGeneratorInjector TEST_INJECTOR = new WorldGeneratorInjector(WorldGeneratorTestAssembly.getPackagePath(2));
//
//
// // pre-dependency setup
// Assert.assertNull("Nothing should have been bound.", TEST_INJECTOR.get());
//
//
// // variables to use later
// IDhApiWorldGenerator generator;
// WorldGeneratorTestCore backupGenerator = new WorldGeneratorTestCore();
// WorldGeneratorTestPrimary levelGenerator = new WorldGeneratorTestPrimary();
//
// IDhApiLevelWrapper boundLevel = new LevelWrapperTest();
// IDhApiLevelWrapper unboundLevel = new LevelWrapperTest();
//
//
//
// // backup generator binding
// try { TEST_INJECTOR.bind(backupGenerator); } catch (IllegalArgumentException e) { Assert.fail("Core generator should be bindable for test package injector."); }
//
//
// // get backup generator
// generator = TEST_INJECTOR.get();
// Assert.assertNotNull("Backup generator not bound.", generator);
// Assert.assertEquals("Incorrect backup generator bound.", generator.getOverrideType(), EDhApiOverridePriority.CORE);
// Assert.assertEquals("Incorrect backup generator bound.", generator.getThreadingMode(), WorldGeneratorTestCore.THREAD_MODE);
//
//
// // bind level specific
// try { TEST_INJECTOR.bind(boundLevel, levelGenerator); } catch (IllegalArgumentException e) { Assert.fail("Core generator should be bindable for test package injector."); }
//
//
// // get bound level generator
// generator = TEST_INJECTOR.get(boundLevel);
// Assert.assertNotNull("Level generator not bound.", generator);
// Assert.assertEquals("Incorrect level generator bound.", generator.getOverrideType(), EDhApiOverridePriority.PRIMARY);
// Assert.assertEquals("Incorrect level generator bound.", generator.getThreadingMode(), WorldGeneratorTestPrimary.THREAD_MODE);
//
// // get unbound level generator
// generator = TEST_INJECTOR.get(unboundLevel);
// Assert.assertNotNull("Backup level generator not bound.", generator);
// Assert.assertEquals("Incorrect level generator bound.", generator.getOverrideType(), EDhApiOverridePriority.CORE);
// Assert.assertEquals("Incorrect level generator bound.", generator.getThreadingMode(), WorldGeneratorTestCore.THREAD_MODE);
//
// }
}