mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-21 15:41:38 +01:00
hollow-cube/no-logger-no-terminal
Signed-off-by: mworzala <mattheworzala@gmail.com> make some loggers private (cherry picked from commit 03ff6dca3493646098bf194ebd19aadf90ecf800) add slf4j dep to codegen module (cherry picked from commit b9136e3e579e98a0567e7ecf838c72ff5c159858) add back slf4j dep (cherry picked from commit 174c5b8b6a3223310e250fb5dad48b179b101fe5) remove tinylog and MinestomTerminal (cherry picked from commit 352161c326fe2dbb5989e5a45571c76795407ff5)
This commit is contained in:
parent
d40e85dedb
commit
52dccf793f
@ -7,3 +7,5 @@ Some of these are pending, some deserve PRs, others are just minor tweaks
|
||||
* **breaking** Add cursor position to block place and neighbor updates (`Moulberry/Minestom` @ `block_placement_rewrite_2`)
|
||||
* Change `Entity#getInstance` to @UnknownNullability
|
||||
* Support custom component translator for serverside translation
|
||||
* **breaking** Replace permission system with a simple user pluggable alternative
|
||||
* **breaking** Remove tinylog and MinestomTerminal implementation
|
@ -63,12 +63,6 @@ dependencies {
|
||||
// Only here to ensure J9 module support for extensions and our classloaders
|
||||
testCompileOnly(libs.mockito.core)
|
||||
|
||||
|
||||
// Logging
|
||||
implementation(libs.bundles.logging)
|
||||
// Libraries required for the terminal
|
||||
implementation(libs.bundles.terminal)
|
||||
|
||||
// Performance improving libraries
|
||||
implementation(libs.caffeine)
|
||||
api(libs.fastutil)
|
||||
@ -79,6 +73,7 @@ dependencies {
|
||||
implementation(libs.jcTools)
|
||||
// Path finding
|
||||
api(libs.hydrazine)
|
||||
implementation("org.slf4j:slf4j-api:2.0.6")
|
||||
|
||||
// Adventure, for user-interface
|
||||
api(libs.bundles.adventure)
|
||||
@ -86,9 +81,6 @@ dependencies {
|
||||
// Kotlin Libraries
|
||||
api(libs.bundles.kotlin)
|
||||
|
||||
// Extension Management System dependency handler.
|
||||
api(libs.dependencyGetter)
|
||||
|
||||
// Minestom Data (From MinestomDataGenerator)
|
||||
implementation(libs.minestomData)
|
||||
|
||||
|
@ -11,10 +11,10 @@ dependencies {
|
||||
implementation(libs.gson)
|
||||
implementation(libs.jetbrainsAnnotations)
|
||||
implementation(libs.javaPoet)
|
||||
// Logging
|
||||
implementation(libs.bundles.logging)
|
||||
// Contains the json files
|
||||
implementation(libs.minestomData)
|
||||
|
||||
implementation("org.slf4j:slf4j-api:2.0.6")
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
@ -33,7 +33,7 @@ public class FindCommand extends Command {
|
||||
for (Entity entity : entities) {
|
||||
player.sendMessage(" " + entity.getEntityType() + ": ");
|
||||
player.sendMessage(" Meta: " + entity.getEntityMeta());
|
||||
player.sendMessage(" Permissions: " + entity.getAllPermissions());
|
||||
// player.sendMessage(" Permissions: " + entity.getAllPermissions());
|
||||
player.sendMessage(" Position: " + entity.getPosition());
|
||||
}
|
||||
|
||||
|
@ -6,15 +6,10 @@ metadata.format.version = "1.1"
|
||||
adventure = "4.12.0"
|
||||
kotlin = "1.7.22"
|
||||
hydrazine = "1.7.2"
|
||||
dependencyGetter = "v1.0.1"
|
||||
minestomData = "53e0da5be1"
|
||||
hephaistos = "2.5.3"
|
||||
jetbrainsAnnotations = "23.0.0"
|
||||
|
||||
# Terminal / Logging
|
||||
tinylog = "2.5.0"
|
||||
jline = "3.21.0"
|
||||
|
||||
# Performance / Data Structures
|
||||
caffeine = "3.1.2"
|
||||
fastutil = "8.5.9"
|
||||
@ -58,19 +53,9 @@ kotlin-stdlib-jdk8 = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk
|
||||
|
||||
# Miscellaneous
|
||||
hydrazine = { group = "com.github.MadMartian", name = "hydrazine-path-finding", version.ref = "hydrazine" }
|
||||
dependencyGetter = { group = "com.github.Minestom", name = "DependencyGetter", version.ref = "dependencyGetter" }
|
||||
minestomData = { group = "com.github.Minestom", name = "MinestomDataGenerator", version.ref = "minestomData" }
|
||||
jetbrainsAnnotations = { group = "org.jetbrains", name = "annotations", version.ref = "jetbrainsAnnotations" }
|
||||
|
||||
# Logging
|
||||
tinylog-api = { group = "org.tinylog", name = "tinylog-api", version.ref = "tinylog" }
|
||||
tinylog-impl = { group = "org.tinylog", name = "tinylog-impl", version.ref = "tinylog" }
|
||||
tinylog-slf4j = { group = "org.tinylog", name = "slf4j-tinylog", version.ref = "tinylog" }
|
||||
|
||||
# Terminal
|
||||
jline = { group = "org.jline", name = "jline", version.ref = "jline" }
|
||||
jline-jansi = { group = "org.jline", name = "jline-terminal-jansi", version.ref = "jline" }
|
||||
|
||||
# Performance / Data Structures
|
||||
caffeine = { group = "com.github.ben-manes.caffeine", name = "caffeine", version.ref = "caffeine" }
|
||||
fastutil = { group = "it.unimi.dsi", name = "fastutil", version.ref = "fastutil" }
|
||||
@ -105,8 +90,6 @@ jcstress-core = { group = "org.openjdk.jcstress", name = "jcstress-core", versio
|
||||
kotlin = ["kotlin-stdlib-jdk8", "kotlin-reflect"]
|
||||
flare = ["flare", "flare-fastutil"]
|
||||
adventure = ["adventure-api", "adventure-serializer-gson", "adventure-serializer-legacy", "adventure-serializer-plain", "adventure-text-logger-slf4j"]
|
||||
logging = ["tinylog-api", "tinylog-impl", "tinylog-slf4j"]
|
||||
terminal = ["jline", "jline-jansi"]
|
||||
|
||||
[plugins]
|
||||
|
||||
|
@ -23,7 +23,6 @@ import net.minestom.server.network.socket.Server;
|
||||
import net.minestom.server.recipe.RecipeManager;
|
||||
import net.minestom.server.scoreboard.TeamManager;
|
||||
import net.minestom.server.snapshot.*;
|
||||
import net.minestom.server.terminal.MinestomTerminal;
|
||||
import net.minestom.server.thread.Acquirable;
|
||||
import net.minestom.server.thread.ThreadDispatcher;
|
||||
import net.minestom.server.timer.SchedulerManager;
|
||||
@ -215,9 +214,6 @@ final class ServerProcessImpl implements ServerProcess {
|
||||
|
||||
LOGGER.info(MinecraftServer.getBrandName() + " server started successfully.");
|
||||
|
||||
if (MinecraftServer.isTerminalEnabled()) {
|
||||
MinestomTerminal.start();
|
||||
}
|
||||
// Stop the server on SIGINT
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(this::stop));
|
||||
}
|
||||
@ -232,7 +228,6 @@ final class ServerProcessImpl implements ServerProcess {
|
||||
server.stop();
|
||||
LOGGER.info("Shutting down all thread pools.");
|
||||
benchmark.disable();
|
||||
MinestomTerminal.stop();
|
||||
dispatcher.shutdown();
|
||||
LOGGER.info(MinecraftServer.getBrandName() + " server stopped successfully.");
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ import java.util.stream.Stream;
|
||||
*/
|
||||
public class Command {
|
||||
|
||||
public final static Logger LOGGER = LoggerFactory.getLogger(Command.class);
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(Command.class);
|
||||
|
||||
private final String name;
|
||||
private final String[] aliases;
|
||||
|
@ -17,7 +17,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public final class PacketListenerManager {
|
||||
|
||||
public final static Logger LOGGER = LoggerFactory.getLogger(PacketListenerManager.class);
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(PacketListenerManager.class);
|
||||
private final ServerProcess serverProcess;
|
||||
|
||||
private final Map<Class<? extends ClientPacket>, PacketListenerConsumer> listeners = new ConcurrentHashMap<>();
|
||||
|
@ -1,36 +0,0 @@
|
||||
package net.minestom.server.terminal;
|
||||
|
||||
import org.fusesource.jansi.AnsiConsole;
|
||||
import org.tinylog.core.LogEntry;
|
||||
import org.tinylog.writers.AbstractFormatPatternWriter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static net.minestom.server.terminal.MinestomTerminal.reader;
|
||||
|
||||
public final class MinestomConsoleWriter extends AbstractFormatPatternWriter {
|
||||
public MinestomConsoleWriter(Map<String, String> properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(LogEntry logEntry) throws Exception {
|
||||
String rendered = render(logEntry);
|
||||
String formatted = TerminalColorConverter.format(rendered);
|
||||
if (reader != null) {
|
||||
reader.printAbove(formatted);
|
||||
} else {
|
||||
AnsiConsole.out().print(formatted);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
// EMPTY
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// EMPTY
|
||||
}
|
||||
}
|
@ -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,102 +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.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 boolean SUPPORT_HEX_COLOR = PropertyUtils.getBoolean("minestom.terminal.support-hex-color", true);
|
||||
private static final boolean SUPPORT_COLOR = PropertyUtils.getBoolean("minestom.terminal.support-color", true);
|
||||
|
||||
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 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 (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, SUPPORT_COLOR ? ANSI_CODES[format] : "");
|
||||
} else {
|
||||
matcher.appendReplacement(builder, matcher.group());
|
||||
}
|
||||
}
|
||||
matcher.appendTail(builder);
|
||||
|
||||
if (SUPPORT_COLOR) {
|
||||
builder.append(ANSI_RESET);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ import org.slf4j.LoggerFactory;
|
||||
public final class DebugUtils {
|
||||
public static boolean INSIDE_TEST = PropertyUtils.getBoolean("minestom.inside-test", false);
|
||||
|
||||
public final static Logger LOGGER = LoggerFactory.getLogger(DebugUtils.class);
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(DebugUtils.class);
|
||||
|
||||
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
|
||||
|
||||
|
@ -1,8 +0,0 @@
|
||||
net.minestom.server.terminal.MinestomConsoleWriter
|
||||
org.tinylog.writers.ConsoleWriter
|
||||
org.tinylog.writers.FileWriter
|
||||
org.tinylog.writers.JdbcWriter
|
||||
org.tinylog.writers.LogcatWriter
|
||||
org.tinylog.writers.RollingFileWriter
|
||||
org.tinylog.writers.SharedFileWriter
|
||||
org.tinylog.writers.JsonWriter
|
@ -1,4 +0,0 @@
|
||||
autoshutdown=true
|
||||
writer=minestom console
|
||||
writer.level=info
|
||||
writer.format=[{thread}] [{date: HH:mm:ss}] ({class-name}.{method}) - {level} - {message}
|
@ -7,11 +7,11 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class PlayerSkinTest {
|
||||
|
||||
@Test
|
||||
public void validName() {
|
||||
var skin = PlayerSkin.fromUsername("jeb_");
|
||||
assertNotNull(skin);
|
||||
}
|
||||
// @Test
|
||||
// public void validName() {
|
||||
// var skin = PlayerSkin.fromUsername("jeb_");
|
||||
// assertNotNull(skin);
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void invalidName() {
|
||||
|
@ -1,27 +0,0 @@
|
||||
package net.minestom.server.terminal;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class TerminalColorConverterTest {
|
||||
@Test
|
||||
void testFormat() {
|
||||
String input = "§c§lHello §r§b§lWorld";
|
||||
String expected = "\u001B[38;2;255;85;85m\u001B[1mHello \u001B[m\u001B[38;2;85;255;255m\u001B[1mWorld\u001B[m";
|
||||
String actual = TerminalColorConverter.format(input);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testComponentFormat() {
|
||||
Component input = Component.text("Hello World").color(NamedTextColor.RED).decorate(TextDecoration.BOLD);
|
||||
String expected = "\u001B[38;2;255;85;85m\u001B[1mHello World\u001B[m";
|
||||
String actual = TerminalColorConverter.format(LegacyComponentSerializer.legacySection().serialize(input));
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user