|
57 | 57 | import com.mojang.brigadier.builder.ArgumentBuilder; |
58 | 58 | import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
59 | 59 | import com.mojang.brigadier.builder.RequiredArgumentBuilder; |
| 60 | +import com.mojang.brigadier.context.ParsedCommandNode; |
| 61 | +import com.mojang.brigadier.context.StringRange; |
60 | 62 | import com.mojang.brigadier.suggestion.SuggestionProvider; |
61 | 63 | import com.mojang.brigadier.suggestion.Suggestions; |
62 | 64 | import com.mojang.brigadier.suggestion.SuggestionsBuilder; |
| 65 | +import com.mojang.brigadier.tree.CommandNode; |
63 | 66 | import com.mojang.brigadier.tree.LiteralCommandNode; |
64 | 67 | import io.leangen.geantyref.GenericTypeReflector; |
65 | 68 | import io.leangen.geantyref.TypeToken; |
| 69 | +import java.lang.reflect.Method; |
66 | 70 | import java.util.ArrayList; |
67 | 71 | import java.util.HashMap; |
68 | 72 | import java.util.List; |
@@ -617,7 +621,7 @@ public void registerDefaultArgumentTypeSupplier( |
617 | 621 | cloudSender, |
618 | 622 | this.commandManager |
619 | 623 | ); |
620 | | - command = command.substring(senderContext.getLastChild().getNodes().get(0).getRange().getStart()); |
| 624 | + command = command.substring(getNodes(senderContext.getLastChild()).get(0).getSecond().getStart()); |
621 | 625 | } |
622 | 626 |
|
623 | 627 | /* Remove namespace */ |
@@ -664,4 +668,32 @@ public void registerDefaultArgumentTypeSupplier( |
664 | 668 |
|
665 | 669 | return suggestionsBuilder.buildFuture(); |
666 | 670 | } |
| 671 | + |
| 672 | + /** |
| 673 | + * Return type changed at some point, but information is essentially the same. This code works for both versions of the |
| 674 | + * method. |
| 675 | + * |
| 676 | + * @param commandContext command context |
| 677 | + * @param <S> source type |
| 678 | + * @return parsed nodes |
| 679 | + */ |
| 680 | + private static <S> List<Pair<CommandNode<S>, StringRange>> getNodes(final com.mojang.brigadier.context.CommandContext<S> commandContext) { |
| 681 | + try { |
| 682 | + final Method getNodesMethod = commandContext.getClass().getDeclaredMethod("getNodes"); |
| 683 | + final Object nodes = getNodesMethod.invoke(commandContext); |
| 684 | + if (nodes instanceof List) { |
| 685 | + return ((List<ParsedCommandNode<S>>) nodes).stream() |
| 686 | + .map(n -> Pair.of(n.getNode(), n.getRange())) |
| 687 | + .collect(Collectors.toList()); |
| 688 | + } else if (nodes instanceof Map) { |
| 689 | + return ((Map<CommandNode<S>, StringRange>) nodes).entrySet().stream() |
| 690 | + .map(entry -> Pair.of(entry.getKey(), entry.getValue())) |
| 691 | + .collect(Collectors.toList()); |
| 692 | + } else { |
| 693 | + throw new IllegalStateException(); |
| 694 | + } |
| 695 | + } catch (final ReflectiveOperationException ex) { |
| 696 | + throw new RuntimeException(ex); |
| 697 | + } |
| 698 | + } |
667 | 699 | } |
0 commit comments