Skip to content

Commit dee76b1

Browse files
committed
Endermux: configure via system properties and use static instance
- Add paper.endermux.* system properties in PaperEndermux: enabled, maxConnections, and socketPath. - Rename earlyInstance to INSTANCE and align static config fields to uppercase. - Start Endermux in bootstrap only when enabled. - Remove per-server Endermux storage/use and call through PaperEndermux.INSTANCE. - Clear PaperEndermux.INSTANCE on close. - Set paper.endermux.enabled=true for run tasks in build.gradle.kts.
1 parent fe9ec7b commit dee76b1

4 files changed

Lines changed: 42 additions & 39 deletions

File tree

paper-server/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ fun TaskContainer.registerRunTask(
297297
"-XX:+AllowEnhancedClassRedefinition",
298298
"--enable-native-access=ALL-UNNAMED",
299299
)
300+
systemProperty("paper.endermux.enabled", true)
300301

301302
if (rootProject.childProjects["test-plugin"] != null) {
302303
val testPluginJar = rootProject.project(":test-plugin").tasks.jar.flatMap { it.archiveFile }

paper-server/patches/features/0032-Endermux-console-protocl-support.patch

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,10 @@ Subject: [PATCH] Endermux console protocl support
55

66

77
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
8-
index c2227d57ea2e2da537a313d4bfd2f8c7f776be64..be81ec43794001f7908c27bdad239b1f760c0913 100644
8+
index c2227d57ea2e2da537a313d4bfd2f8c7f776be64..4b677c2b0f2334e6c36ddd1891605e122f068e8a 100644
99
--- a/net/minecraft/server/MinecraftServer.java
1010
+++ b/net/minecraft/server/MinecraftServer.java
11-
@@ -306,6 +306,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
12-
public boolean isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
13-
private final Set<String> pluginsBlockingSleep = new java.util.HashSet<>(); // Paper - API to allow/disallow tick sleeping
14-
public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation
15-
+ public io.papermc.paper.console.endermux.PaperEndermux endermux;
16-
// Paper start - improve tick loop
17-
public final ca.spottedleaf.moonrise.common.time.TickData tickTimes1s = new ca.spottedleaf.moonrise.common.time.TickData(java.util.concurrent.TimeUnit.SECONDS.toNanos(1L));
18-
public final ca.spottedleaf.moonrise.common.time.TickData tickTimes5s = new ca.spottedleaf.moonrise.common.time.TickData(java.util.concurrent.TimeUnit.SECONDS.toNanos(5L));
19-
@@ -1086,11 +1087,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
11+
@@ -1086,11 +1086,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2012
// Paper end - rewrite chunk system
2113
// Paper start - Improved watchdog support - move final shutdown items here
2214
Util.shutdownExecutors();
@@ -28,15 +20,15 @@ index c2227d57ea2e2da537a313d4bfd2f8c7f776be64..be81ec43794001f7908c27bdad239b1f
2820
this.onServerExit();
2921
// Paper end - Improved watchdog support - move final shutdown items here
3022
}
31-
@@ -1115,6 +1111,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
23+
@@ -1115,6 +1110,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
3224
this.isRestarting = isRestarting;
3325
this.hasLoggedStop = true; // Paper - Debugging
3426
if (isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper - Debugging
35-
+ if (this.endermux != null) this.endermux.disableInteractivity();
27+
+ if (io.papermc.paper.console.endermux.PaperEndermux.INSTANCE != null) io.papermc.paper.console.endermux.PaperEndermux.INSTANCE.disableInteractivity();
3628
// Paper end
3729
this.running = false;
3830
if (waitForShutdown) {
39-
@@ -1992,7 +1989,23 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
31+
@@ -1992,7 +1988,23 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
4032

4133
@Override
4234
public void sendSystemMessage(Component message) {
@@ -62,36 +54,22 @@ index c2227d57ea2e2da537a313d4bfd2f8c7f776be64..be81ec43794001f7908c27bdad239b1f
6254

6355
public KeyPair getKeyPair() {
6456
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
65-
index eb06d8f012684845146429832e977e6c1ddcd62b..e7d1cda55fac1985a90e1f307a18b8caecdf5751 100644
57+
index eb06d8f012684845146429832e977e6c1ddcd62b..15db6bb08ec3b0ca5b2d417d97b670e80c6f77b8 100644
6658
--- a/net/minecraft/server/dedicated/DedicatedServer.java
6759
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
68-
@@ -166,6 +166,13 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
69-
70-
@Override
71-
public boolean initServer() throws IOException {
72-
+ if (io.papermc.paper.console.endermux.PaperEndermux.earlyInstance == null) {
73-
+ this.endermux = new io.papermc.paper.console.endermux.PaperEndermux(); // TODO config
74-
+ if (this.endermux != null) this.endermux.start(java.nio.file.Paths.get("console.sock"));
75-
+ } else {
76-
+ this.endermux = io.papermc.paper.console.endermux.PaperEndermux.earlyInstance;
77-
+ io.papermc.paper.console.endermux.PaperEndermux.earlyInstance = null;
78-
+ }
79-
int i = this.getProperties().managementServerPort;
80-
if (this.getProperties().managementServerEnabled) {
81-
String string = this.settings.getProperties().managementServerSecret;
82-
@@ -270,6 +277,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
60+
@@ -270,6 +270,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
8361
// Paper end - fix converting txt to json file
8462
org.spigotmc.WatchdogThread.doStart(org.spigotmc.SpigotConfig.timeoutTime, org.spigotmc.SpigotConfig.restartOnCrash); // Paper - start watchdog thread
8563
thread.start(); // Paper - Enhance console tab completions for brigadier commands; start console thread after MinecraftServer.console & PaperConfig are initialized
86-
+ if (this.endermux != null) this.endermux.enableInteractivity(this);
64+
+ if (io.papermc.paper.console.endermux.PaperEndermux.INSTANCE != null) io.papermc.paper.console.endermux.PaperEndermux.INSTANCE.enableInteractivity(this);
8765
io.papermc.paper.command.PaperCommands.registerCommands(this); // Paper - setup /paper command
8866
this.server.spark.registerCommandBeforePlugins(this.server); // Paper - spark
8967
com.destroystokyo.paper.Metrics.PaperMetrics.startMetrics(); // Paper - start metrics
90-
@@ -540,6 +548,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
68+
@@ -540,6 +541,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
9169
}
9270
}
9371

94-
+ if (this.endermux != null) this.endermux.close();
72+
+ if (io.papermc.paper.console.endermux.PaperEndermux.INSTANCE != null) io.papermc.paper.console.endermux.PaperEndermux.INSTANCE.close();
9573
+
9674
this.hasFullyShutdown = true; // Paper - Improved watchdog support
9775
System.exit(this.abnormalExit ? 70 : 0); // CraftBukkit // Paper - Improved watchdog support

paper-server/src/main/java/io/papermc/paper/PaperBootstrap.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.papermc.paper;
22

3-
import java.nio.file.Paths;
43
import java.util.List;
54
import io.papermc.paper.console.endermux.PaperEndermux;
65
import joptsimple.OptionSet;
@@ -18,8 +17,10 @@ private PaperBootstrap() {
1817
public static void boot(final OptionSet options) {
1918
SharedConstants.tryDetectVersion();
2019

21-
PaperEndermux.earlyInstance = new PaperEndermux();
22-
PaperEndermux.earlyInstance.start(Paths.get("console.sock"));
20+
if (PaperEndermux.ENABLED) {
21+
PaperEndermux.INSTANCE = new PaperEndermux();
22+
PaperEndermux.INSTANCE.start();
23+
}
2324

2425
getStartupVersionMessages().forEach(LOGGER::info);
2526

paper-server/src/main/java/io/papermc/paper/console/endermux/PaperEndermux.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.papermc.paper.console.endermux;
22

33
import java.nio.file.Path;
4+
import java.nio.file.Paths;
45
import java.util.Objects;
56
import net.minecraft.server.dedicated.DedicatedServer;
67
import org.jspecify.annotations.NullMarked;
@@ -13,16 +14,37 @@
1314
@NullMarked
1415
public final class PaperEndermux {
1516

16-
public static @Nullable PaperEndermux earlyInstance;
17+
private static final String PROPERTY_PREFIX = "paper.endermux.";
18+
private static final boolean DEFAULT_ENABLED = false;
19+
private static final int DEFAULT_MAX_CONNECTIONS = 5;
20+
private static final String DEFAULT_SOCKET_PATH = "console.sock";
21+
22+
public static final boolean ENABLED = Boolean.parseBoolean(System.getProperty(PROPERTY_PREFIX + "enabled", Boolean.toString(DEFAULT_ENABLED)));
23+
public static final int MAX_CONNECTIONS = readInt(PROPERTY_PREFIX + "maxConnections", DEFAULT_MAX_CONNECTIONS);
24+
public static final Path SOCKET_PATH = Paths.get(System.getProperty(PROPERTY_PREFIX + "socketPath", DEFAULT_SOCKET_PATH));
25+
26+
public static @Nullable PaperEndermux INSTANCE;
1727

1828
private @Nullable EndermuxServer endermuxServer;
1929

20-
public void start(final Path socketPath) {
30+
private static int readInt(final String key, final int defaultValue) {
31+
final String raw = System.getProperty(key);
32+
if (raw == null) {
33+
return defaultValue;
34+
}
35+
try {
36+
return Integer.parseInt(raw);
37+
} catch (final NumberFormatException ignored) {
38+
return defaultValue;
39+
}
40+
}
41+
42+
public void start() {
2143
Objects.requireNonNull(EndermuxForwardingAppender.INSTANCE);
2244
this.endermuxServer = new EndermuxServer(
2345
EndermuxForwardingAppender.INSTANCE.logLayout(),
24-
socketPath,
25-
5
46+
SOCKET_PATH,
47+
MAX_CONNECTIONS
2648
);
2749
EndermuxForwardingAppender.TARGET = new RemoteLogForwarder(this.endermuxServer);
2850
this.endermuxServer.start();
@@ -54,6 +76,7 @@ public void close() {
5476
}
5577

5678
EndermuxForwardingAppender.TARGET = null;
79+
INSTANCE = null;
5780
}
5881

5982
}

0 commit comments

Comments
 (0)