geforkt von Mirrors/Paper
Update TerminalConsoleAppender to 1.1.0
Fixes a race condition when using TerminalConsoleAppender that may result in IllegalStateExceptions or duplicate input prompts.
Dieser Commit ist enthalten in:
Ursprung
bc063a06e8
Commit
9cfd6ff449
@ -5,7 +5,7 @@ Subject: [PATCH] Load version history at server start
|
|||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||||
index 854455711..39a3d46ff 100644
|
index 18d32ab76..292291592 100644
|
||||||
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||||
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||||
@@ -0,0 +0,0 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
@@ -0,0 +0,0 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
||||||
|
@ -12,7 +12,7 @@ results in a separate line, even though it should not result in
|
|||||||
a line break. Log4j's implementation handles it correctly.
|
a line break. Log4j's implementation handles it correctly.
|
||||||
|
|
||||||
diff --git a/pom.xml b/pom.xml
|
diff --git a/pom.xml b/pom.xml
|
||||||
index 26775156b..adf79de70 100644
|
index 22b86c74a..acc4bdfa4 100644
|
||||||
--- a/pom.xml
|
--- a/pom.xml
|
||||||
+++ b/pom.xml
|
+++ b/pom.xml
|
||||||
@@ -0,0 +0,0 @@
|
@@ -0,0 +0,0 @@
|
||||||
@ -30,7 +30,7 @@ index 26775156b..adf79de70 100644
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||||
index b3f1aa999..854455711 100644
|
index 895ea0aad..18d32ab76 100644
|
||||||
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||||
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||||
@@ -0,0 +0,0 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
@@ -0,0 +0,0 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
||||||
|
@ -15,12 +15,11 @@ New features:
|
|||||||
IntelliJ IDEA
|
IntelliJ IDEA
|
||||||
|
|
||||||
Other changes:
|
Other changes:
|
||||||
- Update JLine to 3.3.1 (from 2.12.1)
|
|
||||||
- Server starts 1-2 seconds faster thanks to optimizations in Log4j
|
- Server starts 1-2 seconds faster thanks to optimizations in Log4j
|
||||||
configuration
|
configuration
|
||||||
|
|
||||||
diff --git a/pom.xml b/pom.xml
|
diff --git a/pom.xml b/pom.xml
|
||||||
index 9d273c6d9..26775156b 100644
|
index 9d273c6d9..13fa95891 100644
|
||||||
--- a/pom.xml
|
--- a/pom.xml
|
||||||
+++ b/pom.xml
|
+++ b/pom.xml
|
||||||
@@ -0,0 +0,0 @@
|
@@ -0,0 +0,0 @@
|
||||||
@ -44,12 +43,12 @@ index 9d273c6d9..26775156b 100644
|
|||||||
+ <dependency>
|
+ <dependency>
|
||||||
+ <groupId>net.minecrell</groupId>
|
+ <groupId>net.minecrell</groupId>
|
||||||
+ <artifactId>terminalconsoleappender</artifactId>
|
+ <artifactId>terminalconsoleappender</artifactId>
|
||||||
+ <version>1.0.0</version>
|
+ <version>1.1.0</version>
|
||||||
+ </dependency>
|
+ </dependency>
|
||||||
+ <dependency>
|
+ <dependency>
|
||||||
+ <groupId>net.java.dev.jna</groupId>
|
+ <groupId>net.java.dev.jna</groupId>
|
||||||
+ <artifactId>jna</artifactId>
|
+ <artifactId>jna</artifactId>
|
||||||
+ <version>4.4.0</version>
|
+ <version>4.5.2</version>
|
||||||
+ <scope>runtime</scope>
|
+ <scope>runtime</scope>
|
||||||
+ </dependency>
|
+ </dependency>
|
||||||
+
|
+
|
||||||
@ -88,6 +87,52 @@ index 9d273c6d9..26775156b 100644
|
|||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
diff --git a/src/main/java/com/destroystokyo/paper/console/PaperConsole.java b/src/main/java/com/destroystokyo/paper/console/PaperConsole.java
|
||||||
|
new file mode 100644
|
||||||
|
index 000000000..116d1b3bf
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/com/destroystokyo/paper/console/PaperConsole.java
|
||||||
|
@@ -0,0 +0,0 @@
|
||||||
|
+package com.destroystokyo.paper.console;
|
||||||
|
+
|
||||||
|
+import net.minecraft.server.DedicatedServer;
|
||||||
|
+import net.minecrell.terminalconsole.SimpleTerminalConsole;
|
||||||
|
+import org.bukkit.craftbukkit.command.ConsoleCommandCompleter;
|
||||||
|
+import org.jline.reader.LineReader;
|
||||||
|
+import org.jline.reader.LineReaderBuilder;
|
||||||
|
+
|
||||||
|
+public final class PaperConsole extends SimpleTerminalConsole {
|
||||||
|
+
|
||||||
|
+ private final DedicatedServer server;
|
||||||
|
+
|
||||||
|
+ public PaperConsole(DedicatedServer server) {
|
||||||
|
+ this.server = server;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ protected LineReader buildReader(LineReaderBuilder builder) {
|
||||||
|
+ return super.buildReader(builder
|
||||||
|
+ .appName("Paper")
|
||||||
|
+ .completer(new ConsoleCommandCompleter(this.server))
|
||||||
|
+ );
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ protected boolean isRunning() {
|
||||||
|
+ return !this.server.isStopped() && this.server.isRunning();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ protected void runCommand(String command) {
|
||||||
|
+ this.server.issueCommand(command, this.server);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ protected void shutdown() {
|
||||||
|
+ this.server.safeShutdown();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+}
|
||||||
diff --git a/src/main/java/com/destroystokyo/paper/console/TerminalConsoleCommandSender.java b/src/main/java/com/destroystokyo/paper/console/TerminalConsoleCommandSender.java
|
diff --git a/src/main/java/com/destroystokyo/paper/console/TerminalConsoleCommandSender.java b/src/main/java/com/destroystokyo/paper/console/TerminalConsoleCommandSender.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 000000000..685deaa0e
|
index 000000000..685deaa0e
|
||||||
@ -111,107 +156,29 @@ index 000000000..685deaa0e
|
|||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/com/destroystokyo/paper/console/TerminalHandler.java b/src/main/java/com/destroystokyo/paper/console/TerminalHandler.java
|
|
||||||
new file mode 100644
|
|
||||||
index 000000000..626bfeec8
|
|
||||||
--- /dev/null
|
|
||||||
+++ b/src/main/java/com/destroystokyo/paper/console/TerminalHandler.java
|
|
||||||
@@ -0,0 +0,0 @@
|
|
||||||
+package com.destroystokyo.paper.console;
|
|
||||||
+
|
|
||||||
+import net.minecraft.server.DedicatedServer;
|
|
||||||
+import net.minecrell.terminalconsole.TerminalConsoleAppender;
|
|
||||||
+import org.bukkit.craftbukkit.command.ConsoleCommandCompleter;
|
|
||||||
+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;
|
|
||||||
+
|
|
||||||
+public class TerminalHandler {
|
|
||||||
+
|
|
||||||
+ private TerminalHandler() {
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ public static boolean handleCommands(DedicatedServer server) {
|
|
||||||
+ final Terminal terminal = TerminalConsoleAppender.getTerminal();
|
|
||||||
+ if (terminal == null) {
|
|
||||||
+ return false;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ LineReader reader = LineReaderBuilder.builder()
|
|
||||||
+ .appName("Paper")
|
|
||||||
+ .terminal(terminal)
|
|
||||||
+ .completer(new ConsoleCommandCompleter(server))
|
|
||||||
+ .build();
|
|
||||||
+ reader.setOpt(LineReader.Option.DISABLE_EVENT_EXPANSION);
|
|
||||||
+ reader.unsetOpt(LineReader.Option.INSERT_TAB);
|
|
||||||
+
|
|
||||||
+ TerminalConsoleAppender.setReader(reader);
|
|
||||||
+
|
|
||||||
+ try {
|
|
||||||
+ String line;
|
|
||||||
+ while (!server.isStopped() && server.isRunning()) {
|
|
||||||
+ try {
|
|
||||||
+ line = reader.readLine("> ");
|
|
||||||
+ } catch (EndOfFileException ignored) {
|
|
||||||
+ // Continue reading after EOT
|
|
||||||
+ continue;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ if (line == null) {
|
|
||||||
+ break;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ line = line.trim();
|
|
||||||
+ if (!line.isEmpty()) {
|
|
||||||
+ server.issueCommand(line, server);
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ } catch (UserInterruptException e) {
|
|
||||||
+ server.safeShutdown();
|
|
||||||
+ } finally {
|
|
||||||
+ TerminalConsoleAppender.setReader(null);
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ return true;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+}
|
|
||||||
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||||
index 8f2afcc32..b3f1aa999 100644
|
index 8f2afcc32..895ea0aad 100644
|
||||||
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||||
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
||||||
@@ -0,0 +0,0 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
@@ -0,0 +0,0 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
||||||
if (!org.bukkit.craftbukkit.Main.useConsole) {
|
if (!org.bukkit.craftbukkit.Main.useConsole) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
- jline.console.ConsoleReader bufferedreader = reader;
|
+ // Paper start - Use TerminalConsoleAppender
|
||||||
+ // Paper start - Use TerminalConsoleAppender implementation
|
+ new com.destroystokyo.paper.console.PaperConsole(DedicatedServer.this).start();
|
||||||
+ if (com.destroystokyo.paper.console.TerminalHandler.handleCommands(DedicatedServer.this)) return;
|
+ /*
|
||||||
+ BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
|
jline.console.ConsoleReader bufferedreader = reader;
|
||||||
+ // Paper end
|
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
String s;
|
|
||||||
@@ -0,0 +0,0 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
@@ -0,0 +0,0 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
||||||
try {
|
DedicatedServer.LOGGER.error("Exception handling console input", ioexception);
|
||||||
// CraftBukkit start - JLine disabling compatibility
|
|
||||||
while (!isStopped() && isRunning()) {
|
|
||||||
+ // Paper start - code is not used for jline
|
|
||||||
+ /*
|
|
||||||
if (org.bukkit.craftbukkit.Main.useJline) {
|
|
||||||
s = bufferedreader.readLine(">", null);
|
|
||||||
} else {
|
|
||||||
s = bufferedreader.readLine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ */
|
+ */
|
||||||
+ s = bufferedreader.readLine();
|
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
+
|
|
||||||
if (s != null && s.trim().length() > 0) { // Trim to filter lines which are just spaces
|
|
||||||
issueCommand(s, DedicatedServer.this);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@@ -0,0 +0,0 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
@@ -0,0 +0,0 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
||||||
}
|
}
|
||||||
global.addHandler(new org.bukkit.craftbukkit.util.ForwardLogHandler());
|
global.addHandler(new org.bukkit.craftbukkit.util.ForwardLogHandler());
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren