geforkt von Mirrors/Paper
Fix console completer/highlighter having invalid source stack (#8346)
Dieser Commit ist enthalten in:
Ursprung
328360359a
Commit
d1129b0ded
@ -20,7 +20,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
- );
|
||||
+ .option(LineReader.Option.COMPLETE_IN_WORD, true);
|
||||
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().console.enableBrigadierHighlighting) {
|
||||
+ builder.highlighter(new io.papermc.paper.console.BrigadierCommandHighlighter(this.server, this.server.createCommandSourceStack()));
|
||||
+ builder.highlighter(new io.papermc.paper.console.BrigadierCommandHighlighter(this.server));
|
||||
+ }
|
||||
+ return super.buildReader(builder);
|
||||
}
|
||||
@ -35,11 +35,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+package io.papermc.paper.console;
|
||||
+
|
||||
+import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent.Completion;
|
||||
+import com.google.common.base.Suppliers;
|
||||
+import com.mojang.brigadier.CommandDispatcher;
|
||||
+import com.mojang.brigadier.ParseResults;
|
||||
+import com.mojang.brigadier.StringReader;
|
||||
+import com.mojang.brigadier.suggestion.Suggestion;
|
||||
+import io.papermc.paper.adventure.PaperAdventure;
|
||||
+import java.util.ArrayList;
|
||||
+import java.util.Collections;
|
||||
+import java.util.List;
|
||||
+import java.util.function.Supplier;
|
||||
+import net.minecraft.commands.CommandSourceStack;
|
||||
+import net.minecraft.network.chat.ComponentUtils;
|
||||
+import net.minecraft.server.dedicated.DedicatedServer;
|
||||
@ -48,28 +53,27 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import org.jline.reader.LineReader;
|
||||
+import org.jline.reader.ParsedLine;
|
||||
+
|
||||
+import java.util.ArrayList;
|
||||
+import java.util.Collections;
|
||||
+import java.util.List;
|
||||
+
|
||||
+import static com.destroystokyo.paper.event.server.AsyncTabCompleteEvent.Completion.completion;
|
||||
+
|
||||
+public final class BrigadierCommandCompleter {
|
||||
+ private final CommandSourceStack commandSourceStack;
|
||||
+ private final Supplier<CommandSourceStack> commandSourceStack;
|
||||
+ private final DedicatedServer server;
|
||||
+
|
||||
+ public BrigadierCommandCompleter(final @NonNull DedicatedServer server, final @NonNull CommandSourceStack commandSourceStack) {
|
||||
+ public BrigadierCommandCompleter(final @NonNull DedicatedServer server) {
|
||||
+ this.server = server;
|
||||
+ this.commandSourceStack = commandSourceStack;
|
||||
+ this.commandSourceStack = Suppliers.memoize(this.server::createCommandSourceStack);
|
||||
+ }
|
||||
+
|
||||
+ public void complete(final @NonNull LineReader reader, final @NonNull ParsedLine line, final @NonNull List<Candidate> candidates, final @NonNull List<Completion> existing) {
|
||||
+ if (!io.papermc.paper.configuration.GlobalConfiguration.get().console.enableBrigadierCompletions) {
|
||||
+ //noinspection ConstantConditions
|
||||
+ if (this.server.overworld() == null) { // check if overworld is null, as worlds haven't been loaded yet
|
||||
+ return;
|
||||
+ } else if (!io.papermc.paper.configuration.GlobalConfiguration.get().console.enableBrigadierCompletions) {
|
||||
+ this.addCandidates(candidates, Collections.emptyList(), existing);
|
||||
+ return;
|
||||
+ }
|
||||
+ final CommandDispatcher<CommandSourceStack> dispatcher = this.server.getCommands().getDispatcher();
|
||||
+ final ParseResults<CommandSourceStack> results = dispatcher.parse(prepareStringReader(line.line()), this.commandSourceStack);
|
||||
+ final ParseResults<CommandSourceStack> results = dispatcher.parse(prepareStringReader(line.line()), this.commandSourceStack.get());
|
||||
+ this.addCandidates(
|
||||
+ candidates,
|
||||
+ dispatcher.getCompletionSuggestions(results, line.cursor()).join().getList(),
|
||||
@ -135,9 +139,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.console;
|
||||
+
|
||||
+import com.google.common.base.Suppliers;
|
||||
+import com.mojang.brigadier.ParseResults;
|
||||
+import com.mojang.brigadier.context.ParsedCommandNode;
|
||||
+import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
+import java.util.function.Supplier;
|
||||
+import java.util.regex.Pattern;
|
||||
+import net.minecraft.commands.CommandSourceStack;
|
||||
+import net.minecraft.server.dedicated.DedicatedServer;
|
||||
@ -150,18 +156,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+public final class BrigadierCommandHighlighter implements Highlighter {
|
||||
+ private static final int[] COLORS = {AttributedStyle.CYAN, AttributedStyle.YELLOW, AttributedStyle.GREEN, AttributedStyle.MAGENTA, /* Client uses GOLD here, not BLUE, however there is no GOLD AttributedStyle. */ AttributedStyle.BLUE};
|
||||
+ private final CommandSourceStack commandSourceStack;
|
||||
+ private final Supplier<CommandSourceStack> commandSourceStack;
|
||||
+ private final DedicatedServer server;
|
||||
+
|
||||
+ public BrigadierCommandHighlighter(final @NonNull DedicatedServer server, final @NonNull CommandSourceStack commandSourceStack) {
|
||||
+ public BrigadierCommandHighlighter(final @NonNull DedicatedServer server) {
|
||||
+ this.server = server;
|
||||
+ this.commandSourceStack = commandSourceStack;
|
||||
+ this.commandSourceStack = Suppliers.memoize(this.server::createCommandSourceStack);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public AttributedString highlight(final @NonNull LineReader reader, final @NonNull String buffer) {
|
||||
+ //noinspection ConstantConditions
|
||||
+ if (this.server.overworld() == null) { // check if overworld is null, as worlds haven't been loaded yet
|
||||
+ return new AttributedString(buffer, AttributedStyle.DEFAULT.foreground(AttributedStyle.RED));
|
||||
+ }
|
||||
+ final AttributedStringBuilder builder = new AttributedStringBuilder();
|
||||
+ final ParseResults<CommandSourceStack> results = this.server.getCommands().getDispatcher().parse(BrigadierCommandCompleter.prepareStringReader(buffer), this.commandSourceStack);
|
||||
+ final ParseResults<CommandSourceStack> results = this.server.getCommands().getDispatcher().parse(BrigadierCommandCompleter.prepareStringReader(buffer), this.commandSourceStack.get());
|
||||
+ int pos = 0;
|
||||
+ if (buffer.startsWith("/")) {
|
||||
+ builder.append("/", AttributedStyle.DEFAULT);
|
||||
@ -230,7 +240,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
|
||||
public ConsoleCommandCompleter(DedicatedServer server) { // Paper - CraftServer -> DedicatedServer
|
||||
this.server = server;
|
||||
+ this.brigadierCompleter = new io.papermc.paper.console.BrigadierCommandCompleter(this.server, this.server.createCommandSourceStack()); // Paper
|
||||
+ this.brigadierCompleter = new io.papermc.paper.console.BrigadierCommandCompleter(this.server); // Paper
|
||||
}
|
||||
|
||||
// Paper start - Change method signature for JLine update
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren