Hook up DhApiWorldGeneratorOverrideRegister
set up Dependency Injectors for clearing their bound items. add simplified constructors for DhApiResult
This commit is contained in:
+11
-2
@@ -4,7 +4,7 @@ package com.seibel.lod.core.api.external.items.objects;
|
||||
* Allows for more descriptive non-critical failure states.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-7-11
|
||||
* @version 2022-8-15
|
||||
*/
|
||||
public class DhApiResult
|
||||
{
|
||||
@@ -15,9 +15,18 @@ public class DhApiResult
|
||||
public final String errorMessage;
|
||||
|
||||
|
||||
public DhApiResult(boolean newSuccess, String newErrorMessage)
|
||||
private DhApiResult(boolean newSuccess, String newErrorMessage)
|
||||
{
|
||||
this.success = newSuccess;
|
||||
this.errorMessage = newErrorMessage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static DhApiResult createSuccess() { return new DhApiResult(true, ""); }
|
||||
public static DhApiResult createSuccess(String message) { return new DhApiResult(true, message); }
|
||||
|
||||
public static DhApiResult createFail() { return new DhApiResult(false, ""); }
|
||||
public static DhApiResult createFail(String message) { return new DhApiResult(false, message); }
|
||||
|
||||
}
|
||||
|
||||
+21
-4
@@ -3,12 +3,13 @@ package com.seibel.lod.core.api.external.methods.override;
|
||||
import com.seibel.lod.core.api.external.items.interfaces.override.IDhApiWorldGenerator;
|
||||
import com.seibel.lod.core.api.external.items.interfaces.world.IDhApiLevelWrapper;
|
||||
import com.seibel.lod.core.api.external.items.objects.DhApiResult;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.WorldGeneratorInjector;
|
||||
|
||||
/**
|
||||
* Handles adding/removing world generator overrides.
|
||||
* Handles adding world generator overrides.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-7-15
|
||||
* @version 2022-8-15
|
||||
*/
|
||||
public class DhApiWorldGeneratorOverrideRegister
|
||||
{
|
||||
@@ -22,7 +23,15 @@ public class DhApiWorldGeneratorOverrideRegister
|
||||
*/
|
||||
public static DhApiResult registerWorldGeneratorOverride(IDhApiWorldGenerator worldGenerator)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
try
|
||||
{
|
||||
WorldGeneratorInjector.INSTANCE.bind(worldGenerator);
|
||||
return DhApiResult.createSuccess();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return DhApiResult.createFail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,7 +43,15 @@ public class DhApiWorldGeneratorOverrideRegister
|
||||
*/
|
||||
public static DhApiResult registerWorldGeneratorOverride(IDhApiLevelWrapper levelWrapper, IDhApiWorldGenerator worldGenerator)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
try
|
||||
{
|
||||
WorldGeneratorInjector.INSTANCE.bind(levelWrapper, worldGenerator);
|
||||
return DhApiResult.createSuccess();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return DhApiResult.createFail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+9
-1
@@ -28,7 +28,7 @@ import java.util.Map;
|
||||
*
|
||||
* @param <BindableType> extends IBindable and defines what interfaces this dependency handler can deal with.
|
||||
* @author James Seibel
|
||||
* @version 2022-7-21
|
||||
* @version 2022-8-15
|
||||
*/
|
||||
public class DependencyInjector<BindableType extends IBindable>
|
||||
{
|
||||
@@ -221,6 +221,14 @@ public class DependencyInjector<BindableType extends IBindable>
|
||||
|
||||
|
||||
|
||||
/** Removes all bound dependencies. */
|
||||
public void clear()
|
||||
{
|
||||
this.dependencies.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Runs delayed setup for any dependencies that require it. */
|
||||
public void runDelayedSetup()
|
||||
{
|
||||
|
||||
+15
-1
@@ -30,7 +30,7 @@ import com.seibel.lod.core.util.StringUtil;
|
||||
* This is done so other mods can override our methods to improve features down the line.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-7-26
|
||||
* @version 2022-8-15
|
||||
*/
|
||||
public class OverrideInjector<BindableType extends IDhApiOverrideable>
|
||||
{
|
||||
@@ -146,6 +146,20 @@ public class OverrideInjector<BindableType extends IDhApiOverrideable>
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Removes all bound overrides. */
|
||||
public void clear()
|
||||
{
|
||||
this.primaryInjector.clear();
|
||||
this.secondaryInjector.clear();
|
||||
this.coreInjector.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** Small helper method so we don't have to use DhApi enums. */
|
||||
private EOverridePriority getCorePriorityEnum(IDhApiOverrideable override)
|
||||
{
|
||||
|
||||
+9
-1
@@ -30,7 +30,7 @@ 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-7-27
|
||||
* @version 2022-8-15
|
||||
*/
|
||||
public class WorldGeneratorInjector
|
||||
{
|
||||
@@ -140,4 +140,12 @@ public class WorldGeneratorInjector
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user