This repository was archived by the owner on Feb 19, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-10
lines changed
src/main/java/clientapi/module Expand file tree Collapse file tree 2 files changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,9 @@ public final ModuleMode setMode(ModuleMode mode) {
159159 if (mode == null || mode .getParent () != this )
160160 return null ;
161161
162+ if (mode == this .mode )
163+ return mode ;
164+
162165 if (this .mode != null )
163166 this .mode .setState (false );
164167
Original file line number Diff line number Diff line change @@ -48,31 +48,35 @@ public class ModuleMode<T extends Module> extends ValueHolder implements IModule
4848 */
4949 private Keybind bind ;
5050
51+ /**
52+ * The state of the mode
53+ */
54+ private boolean state ;
55+
5156 public ModuleMode (T parent , String name , String description ) {
5257 this .parent = parent ;
5358 this .name = name ;
5459 this .description = description ;
5560
5661 this .bind = new Keybind (Keybind .Type .TOGGLE , 0 , type -> {
5762 if (type == Keybind .Action .CLICK ) {
58- this .toggle ();
63+ parent .setState (parent .getMode () != this || !parent .getState ());
64+ parent .setMode (this );
5965 }
6066 });
6167 }
6268
6369 @ Override
6470 public final void setState (boolean state ) {
65- parent .setState (state );
66-
67- if (parent .getMode () != this )
68- parent .setMode (this );
69-
71+ this .state = state ;
7072 if (state ) {
71- onEnable ();
72- ClientAPI .EVENT_BUS .subscribe (this );
73+ if (parent .getState ()) {
74+ this .onEnable ();
75+ ClientAPI .EVENT_BUS .subscribe (this );
76+ }
7377 } else {
7478 ClientAPI .EVENT_BUS .unsubscribe (this );
75- onDisable ();
79+ this . onDisable ();
7680 }
7781 }
7882
@@ -98,7 +102,7 @@ public final String getDescription() {
98102
99103 @ Override
100104 public final boolean getState () {
101- return this .parent . getState () && this . parent . getMode () == this ;
105+ return this .state ;
102106 }
103107
104108 @ Override
You can’t perform that action at this time.
0 commit comments