-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can now run basic commands without parameters
- Loading branch information
Showing
6 changed files
with
102 additions
and
16 deletions.
There are no files selected for viewing
9 changes: 8 additions & 1 deletion
9
src/main/java/fr/zcraft/quartzlib/components/commands/internal/CommandEndpoint.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
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
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
27 changes: 27 additions & 0 deletions
27
src/main/java/fr/zcraft/quartzlib/components/commands/internal/DiscoveryUtils.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,27 @@ | ||
package fr.zcraft.quartzlib.components.commands.internal; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Modifier; | ||
import java.util.Arrays; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Stream; | ||
|
||
abstract class DiscoveryUtils { | ||
public static Stream<CommandMethod> getCommandMethods(Class<?> commandGroupClass) { | ||
return Arrays.stream(commandGroupClass.getDeclaredMethods()) | ||
.filter(m -> Modifier.isPublic(m.getModifiers()) && !Modifier.isStatic(m.getModifiers())) | ||
.map(CommandMethod::new); | ||
} | ||
|
||
public static Supplier<?> getClassConstructorSupplier (Class<?> commandGroupClass) { | ||
Constructor<?> constructor = commandGroupClass.getDeclaredConstructors()[0]; | ||
return () -> { | ||
try { | ||
return constructor.newInstance(); | ||
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) { | ||
throw new RuntimeException(e); // TODO | ||
} | ||
}; | ||
} | ||
} |
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