Skip to content

Commit

Permalink
Use JLine console API
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSlimeDiamond committed Oct 27, 2023
1 parent c6a1f9a commit 2d24ddf
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ dependencies {
implementation("net.java.dev.jna:jna:5.12.1")
implementation("com.google.guava:guava:32.0.1-jre")
implementation("com.google.inject:guice:7.0.0")
implementation("org.jline:jline:3.12.1")
implementation("net.minecrell:terminalconsoleappender:1.3.0")

// GalliumLib
implementation(project(":lib"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@
import org.galliumpowered.plugin.PluginContainer;
import org.galliumpowered.plugin.metadata.PluginMetadataLoader;

@Plugin(
@Plugin( // Gallium start: Minecraft plugin
name = "Minecraft",
id = "minecraft",
description = "Minecraft",
authors = "Mojang",
version = "1.17.1"
) // Gallium
) // Gallium end
public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTask> implements SnooperPopulator, CommandSource, AutoCloseable {
protected Logger logger; // Gallium
protected static final Logger LOGGER = LogManager.getLogger("minecraft"); // Gallium
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
import net.minecraft.world.level.storage.LevelStorageSource;
import net.minecraft.world.level.storage.WorldData;
import org.galliumpowered.Gallium;
import org.galliumpowered.GalliumConsole;
import org.galliumpowered.Mod;
import org.galliumpowered.event.system.ServerStartEvent;
import org.apache.logging.log4j.LogManager;
import org.galliumpowered.plugin.PluginLifecycleState;
Expand Down Expand Up @@ -98,16 +100,21 @@ public DedicatedServer(Thread thread, RegistryAccess.RegistryHolder registryHold
public boolean initServer() throws IOException {
Thread thread = new Thread("Server console handler") {
public void run() {
/*
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
String string;
try {
while(!DedicatedServer.this.isStopped() && DedicatedServer.this.isRunning() && (string = bufferedReader.readLine()) != null) {
DedicatedServer.this.handleConsoleInput(string, DedicatedServer.this.createCommandSourceStack());
}
} catch (IOException var4) {
logger.error("Exception handling console input", var4);
}
*/

new GalliumConsole().start(); // Gallium

}
};
Expand Down
21 changes: 21 additions & 0 deletions server/src/main/java/org/galliumpowered/GalliumConsole.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.galliumpowered;

import net.minecraft.server.Main;
import net.minecrell.terminalconsole.SimpleTerminalConsole;

public class GalliumConsole extends SimpleTerminalConsole {
@Override
protected boolean isRunning() {
return Mod.getMinecraftServer().isRunning();
}

@Override
protected void runCommand(String command) {
Main.dedicatedServer.handleConsoleInput(command, Main.dedicatedServer.createCommandSourceStack());
}

@Override
protected void shutdown() {
Mod.getMinecraftServer().halt(false);
}
}
1 change: 1 addition & 0 deletions server/src/main/java/org/galliumpowered/Mod.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.galliumpowered;

import net.minecraft.server.MinecraftServer;
import net.minecraft.server.dedicated.DedicatedServer;
import org.galliumpowered.bridge.BridgeImpl;
import org.galliumpowered.command.CommandManager;
import org.galliumpowered.database.Database;
Expand Down

0 comments on commit 2d24ddf

Please sign in to comment.