2020import me .zero .client .api .event .defaults .ModuleStateEvent ;
2121import me .zero .client .api .exception .ActionNotSupportedException ;
2222import me .zero .client .api .manage .Node ;
23+ import me .zero .client .api .module .exception .ModuleInitException ;
2324import me .zero .client .api .util .ClientUtils ;
2425import me .zero .client .api .util .keybind .Keybind ;
26+ import org .lwjgl .input .Keyboard ;
2527
2628import java .util .ArrayList ;
2729import java .util .Arrays ;
4244 */
4345public abstract class Module extends Node implements IModule {
4446
47+ /**
48+ * Reference to self-class
49+ */
50+ private final Class <? extends Module > self = this .getClass ();
51+
4552 /**
4653 * The type/category of the module
4754 */
48- private final Class <?> type ;
55+ private Class <?> type ;
4956
5057 /**
5158 * The Keybind of this Module
@@ -68,19 +75,30 @@ public abstract class Module extends Node implements IModule {
6875 private ModuleMode mode ;
6976
7077 public Module () {
71- Class <? extends Module > c = this .getClass ();
72- if (c .isAnnotationPresent (Mod .class )) {
73- Mod data = c .getAnnotation (Mod .class );
78+ if (!self .isAnnotationPresent (Mod .class ))
79+ throw new ModuleInitException ("@Mod annotation must be present if required parameters aren't passed through constructor" );
7480
75- this .name = data .name ();
76- this .description = data .description ();
81+ Mod data = self .getAnnotation (Mod .class );
82+ setup (data .name (), data .description (), data .bind ());
83+ }
7784
78- this .bind = new Keybind (Keybind .Type .TOGGLE , data .bind (), type -> {
79- if (type == CLICK ) Module .this .toggle ();
80- });
81- }
85+ public Module (String name , String description ) {
86+ this (name , description , Keyboard .KEY_NONE );
87+ }
88+
89+ public Module (String name , String description , int bind ) {
90+ setup (name , description , bind );
91+ }
92+
93+ private void setup (String name , String description , int bind ) {
94+ this .name = name ;
95+ this .description = description ;
96+
97+ this .bind = new Keybind (Keybind .Type .TOGGLE , bind , type -> {
98+ if (type == CLICK ) Module .this .toggle ();
99+ });
82100
83- this .type = Arrays .stream (c .getInterfaces ())
101+ this .type = Arrays .stream (self .getInterfaces ())
84102 .filter (clazz -> clazz .isAnnotationPresent (Category .class ))
85103 .findFirst ().orElse (Category .Default .class );
86104
0 commit comments