-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change how components are added and created
- Loading branch information
Showing
4 changed files
with
53 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/com/gtnewhorizons/mutecore/api/registry/ComponentContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.gtnewhorizons.mutecore.api.registry; | ||
|
||
import java.lang.reflect.Constructor; | ||
|
||
import com.gtnewhorizons.mutecore.MuTECore; | ||
|
||
public class ComponentContainer { | ||
|
||
private final Class<?> clazz; | ||
private final Object[] constructorArgs; | ||
|
||
public ComponentContainer(Class<?> clazz, Object... constructorArgs) { | ||
this.clazz = clazz; | ||
this.constructorArgs = constructorArgs; | ||
} | ||
|
||
public Object create() { | ||
try { | ||
Class<?>[] argTypes = new Class<?>[constructorArgs.length]; | ||
for (int i = 0; i < constructorArgs.length; i++) { | ||
argTypes[i] = constructorArgs[i].getClass(); | ||
} | ||
Constructor<?> constructor = clazz.getDeclaredConstructor(argTypes); | ||
return constructor.newInstance(constructorArgs); | ||
} catch (Exception e) { | ||
MuTECore.LOG.error(e.getMessage()); | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters