Updated Bungeecord version
This commit is contained in:
parent
dbdf1eeb7c
commit
cda7ebadcc
@ -1,22 +1,25 @@
|
|||||||
package fr.pandacube.lib.cli;
|
package fr.pandacube.lib.cli;
|
||||||
|
|
||||||
|
import fr.pandacube.lib.cli.commands.CLIBrigadierDispatcher;
|
||||||
|
import fr.pandacube.lib.cli.log.CLILogger;
|
||||||
|
import fr.pandacube.lib.util.log.Log;
|
||||||
|
import org.jline.reader.EndOfFileException;
|
||||||
|
import org.jline.reader.LineReader;
|
||||||
|
import org.jline.reader.LineReaderBuilder;
|
||||||
|
import org.jline.reader.UserInterruptException;
|
||||||
|
import org.jline.terminal.Terminal;
|
||||||
|
import org.jline.terminal.TerminalBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import fr.pandacube.lib.cli.commands.CLIBrigadierDispatcher;
|
|
||||||
import fr.pandacube.lib.cli.log.CLILogger;
|
|
||||||
import jline.console.ConsoleReader;
|
|
||||||
import org.fusesource.jansi.AnsiConsole;
|
|
||||||
|
|
||||||
import fr.pandacube.lib.util.log.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to handle general standard IO operation for a CLI application. It uses Jline’s {@link ConsoleReader} for the
|
* Class to handle general standard IO operation for a CLI application. It uses Jline’s {@link LineReader} for the
|
||||||
* console rendering, a JUL {@link Logger} for logging, and Brigadier to handle commands.
|
* console rendering, a JUL {@link Logger} for logging, and Brigadier to handle commands.
|
||||||
*/
|
*/
|
||||||
public class CLI extends Thread {
|
public class CLI extends Thread {
|
||||||
|
|
||||||
private final ConsoleReader reader;
|
private final LineReader reader;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
|
|
||||||
@ -28,10 +31,11 @@ public class CLI extends Thread {
|
|||||||
super("Console Thread");
|
super("Console Thread");
|
||||||
setDaemon(true);
|
setDaemon(true);
|
||||||
|
|
||||||
AnsiConsole.systemInstall();
|
Terminal terminal = TerminalBuilder.builder().build();
|
||||||
reader = new ConsoleReader();
|
reader = LineReaderBuilder.builder().terminal(terminal)
|
||||||
reader.setPrompt(">");
|
.completer(CLIBrigadierDispatcher.instance)
|
||||||
reader.addCompleter(CLIBrigadierDispatcher.instance);
|
.build()
|
||||||
|
;
|
||||||
|
|
||||||
// configure logger's formatter
|
// configure logger's formatter
|
||||||
System.setProperty("net.md_5.bungee.log-date-format", "yyyy-MM-dd HH:mm:ss");
|
System.setProperty("net.md_5.bungee.log-date-format", "yyyy-MM-dd HH:mm:ss");
|
||||||
@ -40,10 +44,10 @@ public class CLI extends Thread {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the Jline {@link ConsoleReader} of this CLI instance.
|
* Gets the Jline {@link LineReader} of this CLI instance.
|
||||||
* @return the Jline {@link ConsoleReader} of this CLI instance.
|
* @return the Jline {@link LineReader} of this CLI instance.
|
||||||
*/
|
*/
|
||||||
public ConsoleReader getConsoleReader() {
|
public LineReader getConsoleReader() {
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,15 +69,14 @@ public class CLI extends Thread {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
String line;
|
String line;
|
||||||
try {
|
try {
|
||||||
while((line = reader.readLine()) != null) {
|
while((line = reader.readLine(">")) != null) {
|
||||||
if (line.trim().isEmpty())
|
if (line.trim().isEmpty())
|
||||||
continue;
|
continue;
|
||||||
String cmdLine = line;
|
String cmdLine = line;
|
||||||
new Thread(() -> CLIBrigadierDispatcher.instance.execute(cmdLine), "CLICmdThread #"+(i++)).start();
|
Thread.ofVirtual().name("CLICmdThread #"+(i++))
|
||||||
}
|
.start(() -> CLIBrigadierDispatcher.instance.execute(cmdLine));
|
||||||
} catch (IOException e) {
|
|
||||||
Log.severe(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (UserInterruptException | EndOfFileException ignore) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,11 @@ package fr.pandacube.lib.cli.commands;
|
|||||||
import com.mojang.brigadier.suggestion.Suggestion;
|
import com.mojang.brigadier.suggestion.Suggestion;
|
||||||
import com.mojang.brigadier.suggestion.Suggestions;
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
import fr.pandacube.lib.commands.BrigadierDispatcher;
|
import fr.pandacube.lib.commands.BrigadierDispatcher;
|
||||||
import jline.console.completer.Completer;
|
|
||||||
import net.kyori.adventure.text.ComponentLike;
|
import net.kyori.adventure.text.ComponentLike;
|
||||||
|
import org.jline.reader.Candidate;
|
||||||
|
import org.jline.reader.Completer;
|
||||||
|
import org.jline.reader.LineReader;
|
||||||
|
import org.jline.reader.ParsedLine;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -39,17 +42,15 @@ public class CLIBrigadierDispatcher extends BrigadierDispatcher<CLICommandSender
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
|
public void complete(LineReader lineReader, ParsedLine parsedLine, List<Candidate> candidates) {
|
||||||
|
String bufferBeforeCursor = parsedLine.line().substring(0, parsedLine.cursor());
|
||||||
String bufferBeforeCursor = buffer.substring(0, cursor);
|
|
||||||
|
|
||||||
Suggestions completeResult = getSuggestions(bufferBeforeCursor);
|
Suggestions completeResult = getSuggestions(bufferBeforeCursor);
|
||||||
|
|
||||||
completeResult.getList().stream()
|
completeResult.getList().stream()
|
||||||
.map(Suggestion::getText)
|
.map(Suggestion::getText)
|
||||||
|
.map(Candidate::new)
|
||||||
.forEach(candidates::add);
|
.forEach(candidates::add);
|
||||||
|
|
||||||
return completeResult.getRange().getStart();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
2
pom.xml
2
pom.xml
@ -55,7 +55,7 @@
|
|||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|
||||||
<bungeecord.version>1.21-R0.3-SNAPSHOT</bungeecord.version>
|
<bungeecord.version>1.21-R0.4-SNAPSHOT</bungeecord.version>
|
||||||
<paper.version>1.21.4-R0.1</paper.version>
|
<paper.version>1.21.4-R0.1</paper.version>
|
||||||
<mc.version>1.21.4</mc.version>
|
<mc.version>1.21.4</mc.version>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user