@@ -63,32 +63,30 @@ public void onInitializeServer() {
63
63
var modifyConfig = Commands .literal ("modify_config" )
64
64
.requires (Commands .hasPermission (PERMISSION_LEVEL ));
65
65
66
- for (Field f : Payload .class .getDeclaredFields ()) {
67
- if (Modifier .isStatic (f .getModifiers ())) {
68
- continue ;
69
- }
70
- try {
71
- var wither = Payload .class .getMethod ("with" + Character .toUpperCase (f .getName ().charAt (0 )) + f .getName ().substring (1 ), boolean .class );
66
+ for (var m : Payload .class .getMethods ()) {
67
+ if (m .getParameterCount () != 1 ) continue ;
68
+ if (m .getParameterTypes ()[0 ] != boolean .class ) continue ;
69
+ if (Modifier .isStatic (m .getModifiers ())) continue ;
70
+ for (Field f : Payload .class .getDeclaredFields ()) {
71
+ if (m .getName ().contains (Character .toUpperCase (f .getName ().charAt (0 )) + f .getName ().substring (1 ))) {
72
+ modifyConfig .then (Commands .literal (f .getName ()).then (Commands .argument (f .getName (), BoolArgumentType .bool ()).executes (c -> {
73
+ if (options == null ) {
74
+ options = new Payload ();
75
+ }
76
+ try {
77
+ options = (Payload ) m .invoke (options , BoolArgumentType .getBool (c , f .getName ()));
78
+ } catch (IllegalAccessException | InvocationTargetException e ) {
79
+ throw new RuntimeException (e );
80
+ }
72
81
73
- modifyConfig .then (Commands .literal (f .getName ()).then (Commands .argument (f .getName (), BoolArgumentType .bool ()).executes (c -> {
74
- if (options == null ) {
75
- options = new Payload ();
76
- }
77
- try {
78
- options = (Payload ) wither .invoke (options , BoolArgumentType .getBool (c , f .getName ()));
79
- } catch (IllegalAccessException | InvocationTargetException e ) {
80
- throw new RuntimeException (e );
81
- }
82
-
83
- save ();
84
- reconfigure (c );
85
-
86
- return 0 ;
87
- })));
88
- } catch (NoSuchMethodException e ) {
89
- throw new RuntimeException (e );
82
+ save ();
83
+ reconfigure (c );
84
+ return 0 ;
85
+ })));
86
+ }
90
87
}
91
88
}
89
+
92
90
commandDispatcher .register (Commands .literal (AxolotlClientWaypointsCommon .MODID )
93
91
.then (Commands .literal ("reload" )
94
92
.requires (Commands .hasPermission (PERMISSION_LEVEL )).executes (c -> {
@@ -119,9 +117,8 @@ public void onInitializeServer() {
119
117
}
120
118
121
119
private void reconfigure (CommandContext <CommandSourceStack > c ) {
122
- c .getSource ().getServer ().getPlayerList ().getPlayers ().forEach (p -> {
123
- p .connection .send (new ClientboundCustomPayloadPacket (options ));
124
- });
120
+ c .getSource ().getServer ().getPlayerList ().getPlayers ().forEach (p ->
121
+ p .connection .send (new ClientboundCustomPayloadPacket (options )));
125
122
}
126
123
127
124
private void load () {
0 commit comments