@@ -2,42 +2,48 @@ import com.mojang.brigadier.context.CommandContext;
22import java.lang.reflect.Field;
33
44{
5- var ictx = (ICommandContext<CommandSourceStack>) ctx;
6-
7- // == replacement == //
8-
9- Field F_arguments;
10-
11- try {
12- F_arguments = CommandContext.class.getDeclaredField("arguments");
13- F_arguments.setAccessible(true);
14- } catch (NoSuchFieldException e) {
15- throw new RuntimeException("AvoidLib failed to reflectively retrieve CommandContext#arguments", e);
16- }
5+ public class CommandsMixin {
6+ public class CommandsMixin {
7+ private static Field _getArgField() {
8+ Field F_arguments;
9+
10+ try {
11+ F_arguments = CommandContext.class.getDeclaredField("arguments");
12+ F_arguments.setAccessible(true);
13+ } catch (NoSuchFieldException e) {
14+ throw new RuntimeException("AvoidLib failed to reflectively retrieve CommandContext#arguments", e);
15+ }
16+
17+ return F_arguments;
18+ }
19+
20+ private static Map<String, ParsedArgument<CommandSourceStack, ?>> _getArgs(CommandContext<CommandSourceStack> ctx) {
21+ Map<String, ParsedArgument<CommandSourceStack, ?>> argsraw;
22+
23+ try {
24+ argsraw = (Map<String, ParsedArgument<CommandSourceStack, ?>>) _getArgField().get(ctx);
25+ } catch (IllegalAccessException e) {
26+ throw new RuntimeException("AvoidLib failed to reflectively get CommandContext#arguments", e);
27+ }
28+
29+ return argsraw;
30+ }
31+
32+ private static void _setArgs(CommandContext<CommandSourceStack> ctx, Map<String, ParsedArgument<CommandSourceStack, ?>> rekeyed) {
33+ try {
34+ _getArgField().set(ctx, rekeyed);
35+ } catch (IllegalAccessException ex) {
36+ throw new RuntimeException("AvoidLib failed to reflectively set CommandContext#arguments", ex);
37+ }
38+ }
1739}
1840
1941{
20- var argsraw = ictx.avoid$arguments();
21-
22- // == replacement == //
23-
24- Map<String, ParsedArgument<CommandSourceStack, ?>> argsraw;
25-
26- try {
27- argsraw = (Map<String, ParsedArgument<CommandSourceStack, ?>>) F_arguments.get(ctx);
28- } catch (IllegalAccessException e) {
29- throw new RuntimeException("AvoidLib failed to reflectively get CommandContext#arguments", e);
30- }
42+ ((ICommandContext<CommandSourceStack>) ctx).avoid$arguments()
43+ _getArgs(ctx)
3144}
3245
3346{
34- ictx.avoid$arguments(rekeyed);
35-
36- // == replacement == //
37-
38- try {
39- F_arguments.set(ctx, rekeyed);
40- } catch (IllegalAccessException ex) {
41- throw new RuntimeException("AvoidLib failed to reflectively set CommandContext#arguments", ex);
42- }
47+ ((ICommandContext<CommandSourceStack>) ctx).avoid$arguments(
48+ _setArgs(ctx,
4349}
0 commit comments