diff --git a/proxy/build.gradle b/proxy/build.gradle index 32632575e..ec0a4f7e9 100644 --- a/proxy/build.gradle +++ b/proxy/build.gradle @@ -1,6 +1,7 @@ plugins { id 'java' id 'com.github.johnrengelman.shadow' version '2.0.4' + id 'de.sebastianboegl.shadow.transformer.log4j' version '2.1.1' } compileJava { @@ -21,17 +22,24 @@ jar { dependencies { compile project(':velocity-api') compile project(':velocity-native') + compile "io.netty:netty-codec:${nettyVersion}" compile "io.netty:netty-codec-http:${nettyVersion}" compile "io.netty:netty-handler:${nettyVersion}" compile "io.netty:netty-transport-native-epoll:${nettyVersion}" compile "io.netty:netty-transport-native-epoll:${nettyVersion}:linux-x86_64" + compile "org.apache.logging.log4j:log4j-api:${log4jVersion}" compile "org.apache.logging.log4j:log4j-core:${log4jVersion}" + + compile 'net.minecrell:terminalconsoleappender:1.1.1' + runtime 'net.java.dev.jna:jna:4.5.2' // Needed for JLine + runtime 'com.lmax:disruptor:3.4.2' // Async loggers + testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}" testCompile "org.junit.jupiter:junit-jupiter-engine:${junitVersion}" } artifacts { archives shadowJar -} \ No newline at end of file +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java b/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java index 7853d1639..6efd6a6c7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java @@ -1,12 +1,13 @@ package com.velocitypowered.proxy; +import com.velocitypowered.proxy.console.VelocityConsole; + public class Velocity { - public static void main(String... args) throws InterruptedException { + public static void main(String... args) { final VelocityServer server = VelocityServer.getServer(); server.start(); Runtime.getRuntime().addShutdownHook(new Thread(server::shutdown, "Shutdown thread")); - - Thread.currentThread().join(); + new VelocityConsole(server).start(); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 43c0365ec..672414629 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -56,8 +56,7 @@ public class VelocityServer implements ProxyServer { private final CommandInvoker consoleCommandInvoker = new CommandInvoker() { @Override public void sendMessage(@Nonnull Component component) { - // TODO: TerminalConsoleAppender - logger.info(ComponentSerializers.PLAIN.serialize(component)); + logger.info(ComponentSerializers.LEGACY.serialize(component)); } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java new file mode 100644 index 000000000..2ac760e3e --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java @@ -0,0 +1,39 @@ +package com.velocitypowered.proxy.console; + +import com.velocitypowered.proxy.VelocityServer; +import net.minecrell.terminalconsole.SimpleTerminalConsole; +import org.jline.reader.LineReader; +import org.jline.reader.LineReaderBuilder; + +public final class VelocityConsole extends SimpleTerminalConsole { + + private final VelocityServer server; + + public VelocityConsole(VelocityServer server) { + this.server = server; + } + + @Override + protected LineReader buildReader(LineReaderBuilder builder) { + return super.buildReader(builder + .appName("Velocity") + // TODO: Command completion + ); + } + + @Override + protected boolean isRunning() { + return !this.server.isShutdown(); + } + + @Override + protected void runCommand(String command) { + this.server.getCommandManager().execute(this.server.getConsoleCommandInvoker(), command); + } + + @Override + protected void shutdown() { + this.server.shutdown(); + } + +} diff --git a/proxy/src/main/resources/log4j2.component.properties b/proxy/src/main/resources/log4j2.component.properties new file mode 100644 index 000000000..6ed08f31f --- /dev/null +++ b/proxy/src/main/resources/log4j2.component.properties @@ -0,0 +1 @@ +log4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector diff --git a/proxy/src/main/resources/log4j2.xml b/proxy/src/main/resources/log4j2.xml index bddab2847..ddaefacb2 100644 --- a/proxy/src/main/resources/log4j2.xml +++ b/proxy/src/main/resources/log4j2.xml @@ -1,12 +1,12 @@ - - - + + + - + @@ -16,7 +16,7 @@ - +