@@ -63,32 +63,30 @@ public void onInitializeServer() {
6363 var modifyConfig = Commands .literal ("modify_config" )
6464 .requires (Commands .hasPermission (PERMISSION_LEVEL ));
6565
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+ }
7281
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+ }
9087 }
9188 }
89+
9290 commandDispatcher .register (Commands .literal (AxolotlClientWaypointsCommon .MODID )
9391 .then (Commands .literal ("reload" )
9492 .requires (Commands .hasPermission (PERMISSION_LEVEL )).executes (c -> {
@@ -119,9 +117,8 @@ public void onInitializeServer() {
119117 }
120118
121119 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 )));
125122 }
126123
127124 private void load () {
0 commit comments