mirror of https://github.com/Minestom/Minestom.git
chore: remove terminal
This commit is contained in:
parent
0114aaf4e7
commit
82a77fb2de
|
@ -75,9 +75,6 @@ dependencies {
|
||||||
implementation(libs.minestomData)
|
implementation(libs.minestomData)
|
||||||
implementation(libs.dependencyGetter)
|
implementation(libs.dependencyGetter)
|
||||||
|
|
||||||
// Libraries required for the terminal
|
|
||||||
implementation(libs.bundles.terminal)
|
|
||||||
|
|
||||||
// Performance/data structures
|
// Performance/data structures
|
||||||
implementation(libs.caffeine)
|
implementation(libs.caffeine)
|
||||||
api(libs.fastutil)
|
api(libs.fastutil)
|
||||||
|
|
|
@ -19,9 +19,6 @@ flare = "2.0.1"
|
||||||
gson = "2.10.1"
|
gson = "2.10.1"
|
||||||
jcTools = "4.0.1"
|
jcTools = "4.0.1"
|
||||||
|
|
||||||
# Terminal
|
|
||||||
jline = "3.21.0"
|
|
||||||
|
|
||||||
# Quality
|
# Quality
|
||||||
junit-jupiter = "5.9.3"
|
junit-jupiter = "5.9.3"
|
||||||
junit-platform = "1.9.3"
|
junit-platform = "1.9.3"
|
||||||
|
@ -70,10 +67,6 @@ flare-fastutil = { group = "space.vectrix.flare", name = "flare-fastutil", versi
|
||||||
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
|
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
|
||||||
jcTools = { group = "org.jctools", name = "jctools-core", version.ref = "jcTools" }
|
jcTools = { group = "org.jctools", name = "jctools-core", version.ref = "jcTools" }
|
||||||
|
|
||||||
# Terminal
|
|
||||||
jline = { group = "org.jline", name = "jline", version.ref = "jline" }
|
|
||||||
jline-jansi = { group = "org.jline", name = "jline-terminal-jansi", version.ref = "jline" }
|
|
||||||
|
|
||||||
# Code quality
|
# Code quality
|
||||||
junit-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit-jupiter" }
|
junit-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit-jupiter" }
|
||||||
junit-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit-jupiter" }
|
junit-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit-jupiter" }
|
||||||
|
@ -99,7 +92,6 @@ adventure = ["adventure-api", "adventure-serializer-gson", "adventure-serializer
|
||||||
junit = ["junit-api", "junit-engine", "junit-params", "junit-suite-api", "junit-suite-engine"]
|
junit = ["junit-api", "junit-engine", "junit-params", "junit-suite-api", "junit-suite-engine"]
|
||||||
hephaistos = ["hephaistos-common", "hephaistos-gson"]
|
hephaistos = ["hephaistos-common", "hephaistos-gson"]
|
||||||
logback = ["logback-core", "logback-classic"]
|
logback = ["logback-core", "logback-classic"]
|
||||||
terminal = ["jline", "jline-jansi"]
|
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,6 @@ public final class ServerFlag {
|
||||||
public static final @Nullable String STACKING_RULE = System.getProperty("minestom.stacking-rule");
|
public static final @Nullable String STACKING_RULE = System.getProperty("minestom.stacking-rule");
|
||||||
public static final int WORLD_BORDER_SIZE = Integer.getInteger("minestom.world-border-size", 29999984);
|
public static final int WORLD_BORDER_SIZE = Integer.getInteger("minestom.world-border-size", 29999984);
|
||||||
|
|
||||||
// Terminal
|
|
||||||
public static final boolean TERMINAL_ENABLED = System.getProperty("minestom.terminal.disabled") == null;
|
|
||||||
public static final boolean TERMINAL_SUPPORT_HEX_COLOR = PropertyUtils.getBoolean("minestom.terminal.support-hex-color", true);
|
|
||||||
public static final boolean TERMINAL_SUPPORT_COLOR = PropertyUtils.getBoolean("minestom.terminal.support-color", true);
|
|
||||||
|
|
||||||
// Extensions todo use enabled flag
|
// Extensions todo use enabled flag
|
||||||
public static final boolean EXTENSIONS_ENABLED = PropertyUtils.getBoolean("minestom.extension.enabled", false);
|
public static final boolean EXTENSIONS_ENABLED = PropertyUtils.getBoolean("minestom.extension.enabled", false);
|
||||||
public static final @NotNull String EXTENSIONS_FOLDER = System.getProperty("minestom.extension.folder", "extensions");
|
public static final @NotNull String EXTENSIONS_FOLDER = System.getProperty("minestom.extension.folder", "extensions");
|
||||||
|
|
|
@ -25,7 +25,6 @@ import net.minestom.server.network.socket.Server;
|
||||||
import net.minestom.server.recipe.RecipeManager;
|
import net.minestom.server.recipe.RecipeManager;
|
||||||
import net.minestom.server.scoreboard.TeamManager;
|
import net.minestom.server.scoreboard.TeamManager;
|
||||||
import net.minestom.server.snapshot.*;
|
import net.minestom.server.snapshot.*;
|
||||||
import net.minestom.server.terminal.MinestomTerminal;
|
|
||||||
import net.minestom.server.thread.Acquirable;
|
import net.minestom.server.thread.Acquirable;
|
||||||
import net.minestom.server.thread.ThreadDispatcher;
|
import net.minestom.server.thread.ThreadDispatcher;
|
||||||
import net.minestom.server.timer.SchedulerManager;
|
import net.minestom.server.timer.SchedulerManager;
|
||||||
|
@ -247,9 +246,6 @@ final class ServerProcessImpl implements ServerProcess {
|
||||||
|
|
||||||
LOGGER.info(MinecraftServer.getBrandName() + " server started successfully.");
|
LOGGER.info(MinecraftServer.getBrandName() + " server started successfully.");
|
||||||
|
|
||||||
if (ServerFlag.TERMINAL_ENABLED) {
|
|
||||||
MinestomTerminal.start();
|
|
||||||
}
|
|
||||||
// Stop the server on SIGINT
|
// Stop the server on SIGINT
|
||||||
if (SHUTDOWN_ON_SIGNAL) Runtime.getRuntime().addShutdownHook(new Thread(this::stop));
|
if (SHUTDOWN_ON_SIGNAL) Runtime.getRuntime().addShutdownHook(new Thread(this::stop));
|
||||||
}
|
}
|
||||||
|
@ -268,7 +264,6 @@ final class ServerProcessImpl implements ServerProcess {
|
||||||
server.stop();
|
server.stop();
|
||||||
LOGGER.info("Shutting down all thread pools.");
|
LOGGER.info("Shutting down all thread pools.");
|
||||||
benchmark.disable();
|
benchmark.disable();
|
||||||
MinestomTerminal.stop();
|
|
||||||
dispatcher.shutdown();
|
dispatcher.shutdown();
|
||||||
LOGGER.info(MinecraftServer.getBrandName() + " server stopped successfully.");
|
LOGGER.info(MinecraftServer.getBrandName() + " server stopped successfully.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,100 +0,0 @@
|
||||||
package net.minestom.server.terminal;
|
|
||||||
|
|
||||||
import net.minestom.server.MinecraftServer;
|
|
||||||
import net.minestom.server.command.builder.Command;
|
|
||||||
import net.minestom.server.command.builder.suggestion.Suggestion;
|
|
||||||
import net.minestom.server.command.builder.suggestion.SuggestionEntry;
|
|
||||||
import net.minestom.server.listener.TabCompleteListener;
|
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
import org.jline.reader.Candidate;
|
|
||||||
import org.jline.reader.Completer;
|
|
||||||
import org.jline.reader.EndOfFileException;
|
|
||||||
import org.jline.reader.LineReader;
|
|
||||||
import org.jline.reader.LineReaderBuilder;
|
|
||||||
import org.jline.reader.ParsedLine;
|
|
||||||
import org.jline.reader.UserInterruptException;
|
|
||||||
import org.jline.terminal.Terminal;
|
|
||||||
import org.jline.terminal.TerminalBuilder;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MinestomTerminal {
|
|
||||||
private static final String PROMPT = "> ";
|
|
||||||
private static volatile Terminal terminal;
|
|
||||||
static volatile LineReader reader;
|
|
||||||
private static volatile boolean running = false;
|
|
||||||
|
|
||||||
@ApiStatus.Internal
|
|
||||||
public static void start() {
|
|
||||||
final Thread thread = new Thread(null, () -> {
|
|
||||||
try {
|
|
||||||
terminal = TerminalBuilder.terminal();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
reader = LineReaderBuilder.builder()
|
|
||||||
.completer(new MinestomCompleter())
|
|
||||||
.terminal(terminal)
|
|
||||||
.build();
|
|
||||||
running = true;
|
|
||||||
|
|
||||||
while (running) {
|
|
||||||
String command;
|
|
||||||
try {
|
|
||||||
command = reader.readLine(PROMPT);
|
|
||||||
var commandManager = MinecraftServer.getCommandManager();
|
|
||||||
commandManager.execute(commandManager.getConsoleSender(), command);
|
|
||||||
} catch (UserInterruptException e) {
|
|
||||||
// Handle Ctrl + C
|
|
||||||
System.exit(0);
|
|
||||||
return;
|
|
||||||
} catch (EndOfFileException e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, "Jline");
|
|
||||||
thread.setDaemon(true);
|
|
||||||
thread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiStatus.Internal
|
|
||||||
public static void stop() {
|
|
||||||
running = false;
|
|
||||||
if (terminal != null) {
|
|
||||||
try {
|
|
||||||
terminal.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
reader = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class MinestomCompleter implements Completer {
|
|
||||||
@Override
|
|
||||||
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
|
|
||||||
final var commandManager = MinecraftServer.getCommandManager();
|
|
||||||
final var consoleSender = commandManager.getConsoleSender();
|
|
||||||
if (line.wordIndex() == 0) {
|
|
||||||
final String commandString = line.word().toLowerCase();
|
|
||||||
candidates.addAll(
|
|
||||||
commandManager.getDispatcher().getCommands().stream()
|
|
||||||
.map(Command::getName)
|
|
||||||
.filter(name -> commandString.isBlank() || name.toLowerCase().startsWith(commandString))
|
|
||||||
.map(Candidate::new)
|
|
||||||
.toList()
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
final String text = line.line();
|
|
||||||
final Suggestion suggestion = TabCompleteListener.getSuggestion(consoleSender, text);
|
|
||||||
if (suggestion != null) {
|
|
||||||
suggestion.getEntries().stream()
|
|
||||||
.map(SuggestionEntry::getEntry)
|
|
||||||
.map(Candidate::new)
|
|
||||||
.forEach(candidates::add);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,101 +0,0 @@
|
||||||
package net.minestom.server.terminal;
|
|
||||||
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
|
||||||
import net.minestom.server.ServerFlag;
|
|
||||||
import net.minestom.server.utils.PropertyUtils;
|
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A string converter to convert a string to an ansi-colored one.
|
|
||||||
*
|
|
||||||
* @see <a href="https://github.com/Minecrell/TerminalConsoleAppender/blob/master/src/main/java/net/minecrell/terminalconsole/MinecraftFormattingConverter.java">TerminalConsoleAppender</a>
|
|
||||||
* @see <a href="https://github.com/PaperMC/Paper/blob/41647af74caed955c1fd5b38d458ee59298ae5d4/patches/server/0591-Add-support-for-hex-color-codes-in-console.patch">Paper</a>
|
|
||||||
*/
|
|
||||||
final class TerminalColorConverter {
|
|
||||||
|
|
||||||
private static final String RGB_ANSI = "\u001B[38;2;%d;%d;%dm";
|
|
||||||
private static final String ANSI_RESET = "\u001B[m";
|
|
||||||
private static final String LOOKUP = "0123456789abcdefklmnor";
|
|
||||||
private static final String[] ANSI_CODES = new String[]{
|
|
||||||
getAnsiColor(NamedTextColor.BLACK, "\u001B[0;30m"), // Black §0
|
|
||||||
getAnsiColor(NamedTextColor.DARK_BLUE, "\u001B[0;34m"), // Dark Blue §1
|
|
||||||
getAnsiColor(NamedTextColor.DARK_GREEN, "\u001B[0;32m"), // Dark Green §2
|
|
||||||
getAnsiColor(NamedTextColor.DARK_AQUA, "\u001B[0;36m"), // Dark Aqua §3
|
|
||||||
getAnsiColor(NamedTextColor.DARK_RED, "\u001B[0;31m"), // Dark Red §4
|
|
||||||
getAnsiColor(NamedTextColor.DARK_PURPLE, "\u001B[0;35m"), // Dark Purple §5
|
|
||||||
getAnsiColor(NamedTextColor.GOLD, "\u001B[0;33m"), // Gold §6
|
|
||||||
getAnsiColor(NamedTextColor.GRAY, "\u001B[0;37m"), // Gray §7
|
|
||||||
getAnsiColor(NamedTextColor.DARK_GRAY, "\u001B[0;30;1m"), // Dark Gray §8
|
|
||||||
getAnsiColor(NamedTextColor.BLUE, "\u001B[0;34;1m"), // Blue §9
|
|
||||||
getAnsiColor(NamedTextColor.GREEN, "\u001B[0;32;1m"), // Green §a
|
|
||||||
getAnsiColor(NamedTextColor.AQUA, "\u001B[0;36;1m"), // Aqua §b
|
|
||||||
getAnsiColor(NamedTextColor.RED, "\u001B[0;31;1m"), // Red §c
|
|
||||||
getAnsiColor(NamedTextColor.LIGHT_PURPLE, "\u001B[0;35;1m"), // Light Purple §d
|
|
||||||
getAnsiColor(NamedTextColor.YELLOW, "\u001B[0;33;1m"), // Yellow §e
|
|
||||||
getAnsiColor(NamedTextColor.WHITE, "\u001B[0;37;1m"), // White §f
|
|
||||||
"\u001B[5m", // Obfuscated §k
|
|
||||||
"\u001B[1m", // Bold §l
|
|
||||||
"\u001B[9m", // Strikethrough §m
|
|
||||||
"\u001B[4m", // Underline §n
|
|
||||||
"\u001B[3m", // Italic §o
|
|
||||||
ANSI_RESET, // Reset §r
|
|
||||||
};
|
|
||||||
private static final Pattern RGB_PATTERN = Pattern.compile(LegacyComponentSerializer.SECTION_CHAR + "#([\\da-fA-F]{6})");
|
|
||||||
private static final Pattern NAMED_PATTERN = Pattern.compile(LegacyComponentSerializer.SECTION_CHAR + "([\\da-fk-orA-FK-OR])");
|
|
||||||
|
|
||||||
private TerminalColorConverter() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getAnsiColor(NamedTextColor color, String fallback) {
|
|
||||||
return getAnsiColorFromHexColor(color.value(), fallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getAnsiColorFromHexColor(int color, String fallback) {
|
|
||||||
return ServerFlag.TERMINAL_SUPPORT_HEX_COLOR ? String.format(RGB_ANSI, (color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF) : fallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getAnsiColorFromHexColor(int color) {
|
|
||||||
return getAnsiColorFromHexColor(color, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Format the colored string to an ansi-colored one.
|
|
||||||
*
|
|
||||||
* @param string the string to format
|
|
||||||
* @return the formatted string
|
|
||||||
*/
|
|
||||||
public static String format(String string) {
|
|
||||||
if (string.indexOf(LegacyComponentSerializer.SECTION_CHAR) == -1) {
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
|
|
||||||
string = RGB_PATTERN.matcher(string).replaceAll(match -> {
|
|
||||||
if (ServerFlag.TERMINAL_SUPPORT_COLOR) {
|
|
||||||
String hex = match.group(1);
|
|
||||||
return getAnsiColorFromHexColor(Integer.parseInt(hex, 16));
|
|
||||||
} else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Matcher matcher = NAMED_PATTERN.matcher(string);
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
while (matcher.find()) {
|
|
||||||
int format = LOOKUP.indexOf(Character.toLowerCase(matcher.group().charAt(1)));
|
|
||||||
if (format != -1) {
|
|
||||||
matcher.appendReplacement(builder, ServerFlag.TERMINAL_SUPPORT_COLOR ? ANSI_CODES[format] : "");
|
|
||||||
} else {
|
|
||||||
matcher.appendReplacement(builder, matcher.group());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
matcher.appendTail(builder);
|
|
||||||
|
|
||||||
if (ServerFlag.TERMINAL_SUPPORT_COLOR) {
|
|
||||||
builder.append(ANSI_RESET);
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue