Skip to content

Commit

Permalink
Add reflection to initialize gameplay handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
OldSerpskiStalker committed Sep 17, 2024
1 parent 0dab0f2 commit 6daafcd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraftforge.fml.common.event.FMLServerStoppedEvent;

import org.imesense.dynamicspawncontrol.debug.CheckDebugger;
import org.imesense.dynamicspawncontrol.gameplay.EventGameplayManager;
import org.imesense.dynamicspawncontrol.gameplay.events.OnUpdateTorchLogic;
import org.imesense.dynamicspawncontrol.technical.configs.IConfig;
import org.imesense.dynamicspawncontrol.technical.configs.SettingsLogFile;
Expand Down Expand Up @@ -99,6 +100,7 @@ public static File getGlobalPathToConfigs()
*/
public DynamicSpawnControl()
{
/* */
Instance = this;
}

Expand All @@ -110,13 +112,18 @@ public DynamicSpawnControl()
@EventHandler
public synchronized void preInit(FMLPreInitializationEvent event)
{
/* */
checkDebugger = new CheckDebugger();

/* */
globalDirectory = event.getModConfigurationDirectory();

/* */
Log.createLogFile(globalDirectory.getPath() + File.separator + NAME_DIRECTORY);
Log.writeDataToLogFile(Log.TypeLog[0], "Check debugger -> " + checkDebugger.IsRunDebugger);

MinecraftForge.EVENT_BUS.register(new OnUpdateTorchLogic("OnUpdateTorchLogic"));
/* */
EventGameplayManager.registerClasses();

Proxy.preInit(event);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.imesense.dynamicspawncontrol.gameplay;

import net.minecraftforge.common.MinecraftForge;
import org.imesense.dynamicspawncontrol.gameplay.events.OnUpdateTorchLogic;
import org.imesense.dynamicspawncontrol.technical.customlibrary.Log;

public final class EventGameplayManager
{
private static final Class<?>[] EVENT_CLASSES =
{
OnUpdateTorchLogic.class
};

public EventGameplayManager()
{

}

public static void registerClasses()
{
for (Class<?> eventClass : EVENT_CLASSES)
{
try
{
Object eventInstance = eventClass.getConstructor(String.class).newInstance(eventClass.getSimpleName());
MinecraftForge.EVENT_BUS.register(eventInstance);
}
catch (Exception exception)
{
Log.writeDataToLogFile(Log.TypeLog[2], "Exception in class: " + eventClass.getName() + " - " + exception.getMessage());
}
}
}
}

0 comments on commit 6daafcd

Please sign in to comment.