Compare commits

..

3 Commits

Author SHA1 Message Date
990563fc68 initial commit 2024-12-19 23:29:24 -05:00
ed1d8f4e1d Merge remote-tracking branch 'gitea/main' 2024-12-19 23:28:11 -05:00
615354252f initial commit 2024-12-19 23:26:34 -05:00
12 changed files with 1093 additions and 0 deletions

29
.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/nscp.iml" filepath="$PROJECT_DIR$/nscp.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

11
nscp.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

114
src/Configuration.java Normal file
View File

@ -0,0 +1,114 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class Configuration {
private static final String CONFIG_FILE_NAME = "nscp/config.properties";
private final Properties properties = new Properties();
private final File configFile = new File("nscp/config.properties");
public Configuration() {
if (!this.configFile.exists()) {
this.saveDefaultConfig();
}
this.loadConfig();
}
private void loadConfig() {
try {
FileInputStream var1 = new FileInputStream(this.configFile);
try {
this.properties.load(var1);
} catch (Throwable var5) {
try {
var1.close();
} catch (Throwable var4) {
var5.addSuppressed(var4);
}
throw var5;
}
var1.close();
} catch (IOException var6) {
var6.printStackTrace();
}
}
private void saveConfig() {
try {
FileOutputStream var1 = new FileOutputStream(this.configFile);
try {
this.properties.store(var1, (String)null);
} catch (Throwable var5) {
try {
var1.close();
} catch (Throwable var4) {
var5.addSuppressed(var4);
}
throw var5;
}
var1.close();
} catch (IOException var6) {
var6.printStackTrace();
}
}
private void saveDefaultConfig() {
this.configFile.getParentFile().mkdirs();
try {
InputStream var1 = this.getClass().getResourceAsStream("/nscp/config.properties");
try {
if (var1 != null) {
this.properties.load(var1);
this.saveConfig();
} else {
System.err.println("[ERROR] Default configuration file not found in JAR!");
}
} catch (Throwable var5) {
if (var1 != null) {
try {
var1.close();
} catch (Throwable var4) {
var5.addSuppressed(var4);
}
}
throw var5;
}
if (var1 != null) {
var1.close();
}
} catch (IOException var6) {
var6.printStackTrace();
}
}
public String getString(String var1, String var2) {
return this.properties.getProperty(var1, var2);
}
public boolean getBoolean(String var1, boolean var2) {
String var3 = String.valueOf(var2);
return Boolean.parseBoolean(this.properties.getProperty(var1, var3));
}
public void setString(String var1, String var2) {
this.properties.setProperty(var1, var2);
this.saveConfig();
}
}

4
src/META-INF/MANIFEST.MF Normal file
View File

@ -0,0 +1,4 @@
Manifest-Version: 1.0
Main-Class: MinecraftServerControl
Created-By: 22.0.1 (Oracle Corporation)

View File

@ -0,0 +1,904 @@
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
public class MinecraftServerControl extends JFrame {
private ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
private JButton startButton;
private JButton stopButton;
private JButton restartButton;
private JTextPane consoleArea;
private Process serverProcess;
private JTextField commandField;
private JTextField connectionField;
boolean stopped = false;
private InputStream fallback;
public String version;
public static Configuration config;
public String user;
public BufferedImage img;
public String connection;
public MinecraftServerControl() throws IOException {
config = new Configuration();
config.setString("version", "1.6");
this.version = config.getString("version", "1.6");
this.user = config.getString("user", (String)null);
this.connection = this.getIP();
this.img = ImageIO.read(this.getClass().getResourceAsStream("/nscp/server-icon.png"));
if (!this.resources()) {
(new File("nscp")).mkdir();
}
try {
this.createGUI();
this.g();
this.addActionEvents();
this.setApplicationIcon();
this.setProperties();
this.stopButton.setVisible(false);
this.restartButton.setVisible(false);
this.startButton.setVisible(true);
} catch (Exception var2) {
PrintStream var10000 = System.out;
String var10001 = var2.getMessage();
var10000.println("ERROR\n" + var10001 + "\n" + String.valueOf(var2.getCause()));
System.exit(404);
}
this.checkFilesAndStartServer();
}
private void startPeriodicTask() {
this.executorService.scheduleAtFixedRate(this.loop(), 0L, 2L, TimeUnit.SECONDS);
}
private void checkFilesAndStartServer() {
try {
File var1 = new File(config.getString("jar", "server.jar"));
File var2 = new File("server.properties");
if (!var1.exists()) {
this.handleMissingFile(String.valueOf(var1), var1);
}
if (!var2.exists()) {
this.handleMissingFile("server.properties", var2);
} else {
this.sendToConsoleAlt2("Running Java version: " + System.getProperty("java.version"));
}
} catch (Exception var4) {
JOptionPane.showMessageDialog(this, "Server Control Panel Could not start.\n Error:" + var4.getMessage());
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
this.sendToConsole("Shutdown hook is running!");
this.performCleanup();
this.sendToConsoleAlt2("Cleanup completed successfully.");
}));
this.sendToConsole("Newt_00's Server Control Panel is running.");
try {
Thread.sleep(1000L);
} catch (InterruptedException var3) {
this.sendToConsoleAlt("Thread was interrupted: " + var3.getMessage());
}
}
private void handleMissingFile(String var1, File var2) throws IOException {
int var3 = JOptionPane.showConfirmDialog(this, "Error: The " + var1 + " file does not exist in the directory:\n" + System.getProperty("user.dir") + "/" + String.valueOf(var2) + "\n\nWould you like to close Newts Server Control Panel?", "NSCP Error", 0, 0);
if (var3 == 0) {
System.exit(0);
} else if (!var1.equals("server.properties")) {
int var4 = JOptionPane.showConfirmDialog(this, "Error: The server.properties file does not exist in the directory:\n" + System.getProperty("user.dir") + "/" + String.valueOf(var2) + "\n\nWould you like to close Newts Server Control Panel? \nIf NO you may start the server to regenerate a properties file and try again.", "NSCP Error", 0, 0);
if (var4 == 0) {
System.exit(0);
} else {
this.sendToConsoleAlt2("Running Java version: " + System.getProperty("java.version"));
this.sendToConsole("Attempting to generate necessary files with server start.");
if (var2.exists()) {
this.startServer();
} else {
this.sendToConsoleAlt("No " + config.getString("jar", "server.jar") + " found...\n referring to fallback 1.20.4-paper not enabled");
}
}
}
}
private void setApplicationIcon() {
if (this.img != null) {
ImageIcon var1 = new ImageIcon(this.img);
this.setIconImage(var1.getImage());
this.revalidate();
this.repaint();
this.log("Icon successfully set from static source");
this.sendToConsoleAlt2("Icon probably unsuccessfully set from static source");
} else {
this.log("Could not read icon image from stream: " + String.valueOf(this.img));
this.sendToConsoleAlt("Could not read icon image from stream");
}
}
public static void main(String[] var0) {
SwingUtilities.invokeLater(() -> {
MinecraftServerControl var0 = null;
try {
var0 = new MinecraftServerControl();
} catch (IOException var2) {
throw new RuntimeException(var2);
}
var0.setVisible(true);
});
}
private void createGUI() {
this.setTitle("Newt_00's Server Control Panel " + this.version);
this.setSize(600, 400);
this.setLocationRelativeTo((Component)null);
this.setDefaultCloseOperation(3);
this.setLayout(new BorderLayout(15, 15));
JPanel var1 = new JPanel(new FlowLayout());
this.startButton = new JButton(" Start ");
this.startButton.setForeground(Color.black);
this.startButton.setBackground(Color.GREEN);
this.startButton.setCursor(Cursor.getPredefinedCursor(12));
this.startButton.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
this.startButton.setBorder(BorderFactory.createBevelBorder(1, Color.BLACK, Color.WHITE));
this.startButton.setOpaque(true);
this.startButton.setBorderPainted(false);
this.startButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
this.stopButton = new JButton(" Stop ");
this.stopButton.setForeground(Color.BLACK);
this.stopButton.setBackground(Color.RED);
this.stopButton.setCursor(Cursor.getPredefinedCursor(12));
this.stopButton.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
this.stopButton.setBorder(BorderFactory.createBevelBorder(1, Color.BLACK, Color.WHITE));
this.stopButton.setOpaque(true);
this.stopButton.setBorderPainted(false);
this.restartButton = new JButton(" Restart ");
this.restartButton.setForeground(Color.BLACK);
this.restartButton.setBackground(Color.CYAN);
this.restartButton.setCursor(Cursor.getPredefinedCursor(12));
this.restartButton.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
this.restartButton.setBorder(BorderFactory.createBevelBorder(1, Color.BLACK, Color.WHITE));
this.restartButton.setOpaque(true);
this.restartButton.setBorderPainted(false);
this.connectionField = new JTextField(" " + this.connection);
this.connectionField.setForeground(Color.BLACK);
this.connectionField.setBackground(Color.PINK);
this.connectionField.setEditable(false);
this.connectionField.setCursor(Cursor.getPredefinedCursor(2));
this.connectionField.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
this.connectionField.setBorder(BorderFactory.createBevelBorder(1, Color.BLACK, Color.WHITE));
this.connectionField.setOpaque(true);
var1.add(this.startButton);
var1.add(this.stopButton);
var1.add(this.restartButton);
var1.add(this.connectionField);
this.consoleArea = new JTextPane();
this.consoleArea.setEditable(false);
this.consoleArea.setBackground(Color.DARK_GRAY);
float[] var2 = Color.RGBtoHSB(73, 153, 73, (float[])null);
Color var3 = Color.getHSBColor(var2[0], var2[1], var2[2]);
this.consoleArea.setForeground(var3);
this.consoleArea.setOpaque(true);
this.consoleArea.setAutoscrolls(true);
JScrollPane var4 = new JScrollPane(this.consoleArea);
this.add(var4, "Center");
this.commandField = new JTextField();
this.commandField.addActionListener((var1x) -> {
this.sendCommand(this.commandField.getText());
this.commandField.setText("");
});
this.commandField.setForeground(Color.WHITE);
this.commandField.setBackground(Color.GRAY);
this.add(this.commandField, "South");
this.add(this.consoleArea, "Center");
this.add(var1, "North");
}
public boolean fonts() {
InputStream var1 = this.getClass().getResourceAsStream("/nscp/minecraft.ttf");
return var1 != null;
}
public void log(String var1) {
PrintStream var10000 = System.out;
String var10001 = this.prefix();
var10000.println(var10001 + var1);
}
public boolean IPchange() {
return Objects.equals(this.connection, this.getIP());
}
private void g() {
if (!this.resources()) {
(new File("nscp")).mkdir();
}
if (!this.fonts()) {
this.log("successfully fetched font ttf, setting fonts to buttons, and console");
SwingUtilities.invokeLater(() -> {
this.visibility(false);
this.startButton.setFont(this.terminalFont().deriveFont(1, 16.0F));
this.stopButton.setFont(this.terminalFont().deriveFont(1, 16.0F));
this.restartButton.setFont(this.terminalFont().deriveFont(1, 16.0F));
this.consoleArea.setFont(this.terminalFont().deriveFont(1, 12.0F));
this.commandField.setFont(this.terminalFont().deriveFont(1, 12.0F));
this.connectionField.setFont(this.terminalFont().deriveFont(1, 16.0F));
this.visibility(true);
});
} else {
this.log("successfully fetched font ttf, setting fonts to buttons, and console");
SwingUtilities.invokeLater(() -> {
this.visibility(false);
this.startButton.setFont(this.terminalFont().deriveFont(1, 16.0F));
this.stopButton.setFont(this.terminalFont().deriveFont(1, 16.0F));
this.restartButton.setFont(this.terminalFont().deriveFont(1, 16.0F));
this.consoleArea.setFont(this.terminalFont().deriveFont(1, 12.0F));
this.commandField.setFont(this.terminalFont().deriveFont(1, 12.0F));
this.connectionField.setFont(this.terminalFont().deriveFont(1, 16.0F));
this.visibility(true);
});
}
}
private void addActionEvents() {
this.startButton.addActionListener((var1) -> {
this.startServer();
});
this.stopButton.addActionListener((var1) -> {
this.stopServer();
});
this.restartButton.addActionListener((var1) -> {
this.restartServer();
});
this.stopButton.setVisible(false);
this.restartButton.setVisible(false);
this.startButton.setVisible(true);
this.consoleArea.setVisible(true);
this.connectionField.setVisible(true);
this.appendColoredText(this.consoleArea, " ****************************\n", 16, Color.CYAN, true, false, false);
this.appendColoredText(this.consoleArea, " Author: Newt_00 \n", 16, Color.MAGENTA, true, false, false);
this.appendColoredText(this.consoleArea, " ****************************\n", 16, Color.CYAN, true, false, false);
}
private void setProperties() {
File var1 = new File("server-icon.png");
File var2 = new File("eula.txt");
File var3 = new File("plugins");
if (var3.exists()) {
try {
this.downloadResource("http://ycs.canvaswrite.com/resources/nscp/Vault.jar", "plugins/Vault.jar");
this.downloadResource("http://ycs.canvaswrite.com/resources/nscp/BetterEconomy-3.1.jar", "plugins/BetterEco.jar");
this.downloadResource("http://ycs.canvaswrite.com/resources/nscp/worldPoints-v1.6.12-2.jar", "plugins/Newts-Worldpoints.jar");
this.downloadResource("http://ycs.canvaswrite.com/resources/nscp/apocolypse-RC-6.jar", "plugins/Apocolypse.jar");
this.downloadResource("http://ycs.canvaswrite.com/resources/nscp/ColorKey-1.1.jar", "plugins/ColorKey.jar");
this.downloadResource("http://ycs.canvaswrite.com/resources/nscp/DoubleDoor-1.3R.jar", "plugins/BetterEco.jar");
this.downloadResource("http://ycs.canvaswrite.com/resources/nscp/LifeLine-v1.8-1.jar", "plugins/LifeLine.jar");
} catch (Exception var11) {
this.sendToConsoleAlt("failed to get Resources from sources");
}
}
if (!var1.exists()) {
try {
this.downloadResource("http://ycs.canvaswrite.com/resources/nscp/servericon-scp.png", "server-icon.png");
} catch (IOException var10) {
this.sendToConsoleAlt("Error downloading the server icon image: " + var10.getMessage());
}
}
StringBuilder var4 = new StringBuilder();
try {
Enumeration var5 = NetworkInterface.getNetworkInterfaces();
Iterator var6 = Collections.list(var5).iterator();
label56:
while(true) {
NetworkInterface var7;
do {
do {
if (!var6.hasNext()) {
this.appendColoredText(this.consoleArea, " IP: " + String.valueOf(var4) + "\n", 16, Color.MAGENTA, true, false, true);
break label56;
}
var7 = (NetworkInterface)var6.next();
} while(var7.isLoopback());
} while(!var7.isUp());
Enumeration var8 = var7.getInetAddresses();
while(var8.hasMoreElements()) {
InetAddress var9 = (InetAddress)var8.nextElement();
if (var9.getAddress().length == 4) {
var4.append(var9.getHostAddress());
}
}
}
} catch (SocketException var12) {
this.sendToConsoleAlt("Error getting network interfaces: " + var12.getMessage());
}
if (var2.exists()) {
editProperty("eula", "true", "eula.txt");
this.sendToConsoleAlt2("set eula to true");
}
editProperty("max-players", "5", "server.properties");
editProperty("server-ip", String.valueOf(var4), "server.properties");
editProperty("motd", "§d§l" + this.user + "§d's§b Test Server§r\n§aVersion:§e§l Server_Control_Panel-" + this.version, "server.properties");
}
public String getIP() {
StringBuilder var1 = new StringBuilder();
try {
Enumeration var2 = NetworkInterface.getNetworkInterfaces();
Iterator var3 = Collections.list(var2).iterator();
while(var3.hasNext()) {
NetworkInterface var4 = (NetworkInterface)var3.next();
if (!var4.isLoopback() && var4.isUp()) {
Enumeration var5 = var4.getInetAddresses();
while(var5.hasMoreElements()) {
InetAddress var6 = (InetAddress)var5.nextElement();
if (var6.getAddress().length == 4) {
var1.append(var6.getHostAddress());
}
}
}
}
} catch (SocketException var7) {
return "Error";
}
return String.valueOf(var1);
}
private void startServer() {
this.startPeriodicTask();
this.startButton.setVisible(false);
this.stopButton.setVisible(true);
this.restartButton.setVisible(true);
File var1 = new File(config.getString("jar", "server.jar"));
File var2 = new File("server.properties");
String var10001;
if (!var1.exists()) {
var10001 = String.valueOf(var1);
this.sendToConsoleAlt("Error: The " + var10001 + " file does not exist in the directory.\n" + System.getProperty("user.dir") + "/" + String.valueOf(var1));
this.startButton.setVisible(true);
this.stopButton.setVisible(false);
this.restartButton.setVisible(false);
} else {
if (!var2.exists()) {
var10001 = System.getProperty("user.dir");
this.sendToConsoleAlt("Error: The server.properties file does not exist in the directory.\n" + var10001 + "/" + String.valueOf(var1));
} else {
this.setProperties();
}
if (this.serverProcess != null && this.serverProcess.isAlive()) {
this.sendToConsole("Server is already running!");
} else {
try {
ProcessBuilder var3 = new ProcessBuilder(new String[]{"java", "-Xmx1024M", "-Xms1024M", "-jar", String.valueOf(var1), "nogui"});
var3.redirectErrorStream(true);
this.stopped = false;
this.connection = this.getIP();
this.serverProcess = var3.start();
this.sendToConsoleAlt2("Server started successfully!");
this.handleServerOutput(this.serverProcess.getInputStream());
this.monitorServerProcess();
} catch (IOException var4) {
this.sendToConsoleAlt("Error starting the server: " + var4.getMessage());
}
}
}
}
private void stopServer() {
this.sendCommand("kick @a NSCP Panel Host shut down. | NSCP version: " + this.version + " | Host: " + this.user);
this.startButton.setVisible(true);
this.stopButton.setVisible(false);
this.restartButton.setVisible(false);
this.stopped = true;
this.sendCommand("stop");
this.log(this.prefix() + "stopping server");
if (this.serverProcess != null) {
this.sendCommand("kick @a NSCP Panel Host shut down. | NSCP version: " + this.version + " | Host: " + this.user);
this.sendCommand("stop");
this.serverProcess.destroy();
this.log("Server stopped.");
} else {
this.log("Server is not running.");
}
}
private void restartServer() {
this.startButton.setVisible(false);
this.stopButton.setVisible(true);
this.restartButton.setVisible(true);
if (this.serverProcess != null && this.serverProcess.isAlive()) {
this.stopped = true;
this.stopServer();
this.setProperties();
this.startServer();
this.stopped = false;
} else {
this.sendToConsole("Server is not running. Starting now...");
this.startServer();
}
}
public String prefix() {
return " [NSCP] ";
}
private void appendColoredText(JTextPane var1, String var2, int var3, Color var4, boolean var5, boolean var6, boolean var7) {
StyledDocument var8 = var1.getStyledDocument();
Style var9 = var1.addStyle("ColorStyle", (Style)null);
StyleConstants.setForeground(var9, var4);
StyleConstants.setFontFamily(var9, this.terminalFont().getFamily());
StyleConstants.setFontSize(var9, var3);
StyleConstants.setBold(var9, var5);
StyleConstants.setUnderline(var9, var7);
StyleConstants.setItalic(var9, var6);
try {
var8.insertString(var8.getLength(), var2, var9);
} catch (BadLocationException var11) {
var11.printStackTrace();
}
}
private void handleServerOutput(InputStream var1) {
Thread var2 = new Thread(() -> {
try {
BufferedReader var2 = new BufferedReader(new InputStreamReader(var1));
try {
label76:
while(true) {
while(true) {
while(true) {
while(true) {
while(true) {
String var3;
if ((var3 = var2.readLine()) == null) {
break label76;
}
if (!var3.contains("plugin") && !var3.contains("WARN")) {
if (!var3.contains("ERROR") && !var3.contains("Disabling") && !var3.contains("Failed")) {
if (!var3.contains("Enabling") && !var3.contains("Enabled") && !var3.contains("UUID")) {
if (!var3.contains("logged in") && !var3.contains(" goal")) {
if (var3.contains(" challenge")) {
SwingUtilities.invokeLater(() -> {
this.sendToConsoleAlt4(" " + var3);
});
} else if (var3.contains(" advancement")) {
SwingUtilities.invokeLater(() -> {
this.sendToConsoleAlt5(" " + var3);
});
} else if (var3.contains("overloaded")) {
SwingUtilities.invokeLater(() -> {
this.sendToConsoleAlt(" " + var3);
});
} else {
SwingUtilities.invokeLater(() -> {
this.sendToConsoleLog(" " + var3);
});
}
} else {
SwingUtilities.invokeLater(() -> {
this.sendToConsoleAlt3(" " + var3);
});
}
} else {
SwingUtilities.invokeLater(() -> {
this.sendToConsoleAlt2(" " + var3);
});
}
} else {
SwingUtilities.invokeLater(() -> {
this.sendToConsoleAlt(" " + var3);
});
}
} else {
SwingUtilities.invokeLater(() -> {
this.sendToConsole(" " + var3);
});
}
}
}
}
}
}
} catch (Throwable var6) {
try {
var2.close();
} catch (Throwable var5) {
var6.addSuppressed(var5);
}
throw var6;
}
var2.close();
} catch (IOException var7) {
SwingUtilities.invokeLater(() -> {
this.sendToConsoleAlt("Error reading server output: " + var7.getMessage());
});
}
});
var2.start();
}
private void sendCommand(String var1) {
String var10001;
if (this.serverProcess != null && this.serverProcess.isAlive()) {
OutputStream var2 = this.serverProcess.getOutputStream();
PrintWriter var3 = new PrintWriter(var2, true);
var3.println(var1);
var10001 = this.prefix();
this.sendToConsole(var10001 + "Command sent: /" + var1);
} else {
var10001 = this.prefix();
this.sendToConsoleAlt(var10001 + "Server is not running. Command not sent: /" + var1);
}
}
public static void editProperty(String var0, String var1, String var2) {
Properties var3 = new Properties();
try {
FileInputStream var4 = new FileInputStream(var2);
try {
var3.load(var4);
} catch (Throwable var11) {
try {
var4.close();
} catch (Throwable var7) {
var11.addSuppressed(var7);
}
throw var11;
}
var4.close();
} catch (IOException var12) {
return;
}
var3.setProperty(var0, var1);
try {
FileOutputStream var13 = new FileOutputStream(var2);
try {
var3.store(var13, (String)null);
} catch (Throwable var9) {
try {
var13.close();
} catch (Throwable var8) {
var9.addSuppressed(var8);
}
throw var9;
}
var13.close();
} catch (IOException var10) {
}
}
private void downloadResource(String var1, String var2) throws IOException {
URL var3 = new URL(var1);
URLConnection var4 = var3.openConnection();
String var10001 = this.prefix();
this.log(var10001 + "attempting to download server Resource from " + var1 + "\n");
InputStream var5 = var4.getInputStream();
try {
FileOutputStream var6 = new FileOutputStream(var2);
try {
byte[] var7 = new byte[2048];
while(true) {
int var8;
if ((var8 = var5.read(var7)) == -1) {
this.log("Resource downloaded and saved as " + var2);
break;
}
var6.write(var7, 0, var8);
}
} catch (Throwable var11) {
try {
var6.close();
} catch (Throwable var10) {
var11.addSuppressed(var10);
}
throw var11;
}
var6.close();
} catch (Throwable var12) {
if (var5 != null) {
try {
var5.close();
} catch (Throwable var9) {
var12.addSuppressed(var9);
}
}
throw var12;
}
if (var5 != null) {
var5.close();
}
}
private void performCleanup() {
this.startButton.setVisible(false);
this.stopButton.setVisible(false);
this.restartButton.setVisible(false);
this.sendToConsole("Performing cleanup tasks...");
this.stopServer();
this.sendToConsoleAlt2("cleanup has completed, shutdown complete.");
}
private void monitorServerProcess() {
Thread var1 = new Thread(() -> {
try {
if (!this.stopped) {
int var1 = this.serverProcess.waitFor();
if (var1 != 143) {
this.sendToConsoleAlt("Server stopped with exit code " + var1 + ". Attempting to restart...");
this.restartServer();
}
}
} catch (InterruptedException var2) {
this.sendToConsoleAlt("Server monitoring interrupted: " + var2.getMessage());
}
});
var1.start();
}
private Font terminalFont() {
try {
Font var1 = null;
InputStream var2 = this.getClass().getResourceAsStream("/nscp/minecraft.ttf");
File var3 = new File("nscp/minecraft.ttf");
if (var2 != null) {
var1 = Font.createFont(0, var2);
} else if (var3.exists()) {
var1 = Font.createFont(0, var3);
} else {
var1 = new Font("SansSerif", 0, 1);
this.log("[ERROR] font file failed to be found!");
}
return var1.deriveFont(12.0F);
} catch (FontFormatException | IOException var4) {
this.sendToConsole("[ERROR] could not create custom font terminalFont\n " + var4.getMessage());
return new Font("SansSerif", 0, 12);
}
}
private boolean resources() {
return (new File("nscp")).exists();
}
private void sendToConsole(String var1) {
try {
this.appendColoredText(this.consoleArea, this.prefix() + var1 + "\n", 14, Color.ORANGE, false, false, false);
this.toLogFile(var1);
} catch (Exception var3) {
var3.printStackTrace();
}
}
private void sendToConsoleAlt(String var1) {
try {
this.appendColoredText(this.consoleArea, this.prefix() + var1 + "\n", 14, Color.RED, false, true, true);
this.toLogFile(var1);
} catch (Exception var3) {
var3.printStackTrace();
}
}
private void sendToConsoleAlt2(String var1) {
try {
this.appendColoredText(this.consoleArea, this.prefix() + var1 + "\n", 14, Color.GREEN, false, false, false);
this.toLogFile(var1);
} catch (Exception var3) {
var3.printStackTrace();
}
}
private void sendToConsoleAlt3(String var1) {
try {
this.appendColoredText(this.consoleArea, this.prefix() + var1 + "\n", 14, Color.CYAN, false, false, false);
this.toLogFile(var1);
} catch (Exception var3) {
var3.printStackTrace();
}
}
public Runnable loop() {
return new Runnable() {
public void run() {
if (!MinecraftServerControl.this.IPchange()) {
MinecraftServerControl.this.sendCommand("kick @a Host IP changed");
MinecraftServerControl.this.sendCommand("stop");
MinecraftServerControl.this.connection = MinecraftServerControl.this.getIP();
MinecraftServerControl.this.connectionField.setText(" " + MinecraftServerControl.this.connection);
}
}
};
}
private void sendToConsoleAlt4(String var1) {
try {
this.appendColoredText(this.consoleArea, this.prefix() + var1 + "\n", 14, Color.MAGENTA, false, false, true);
this.toLogFile(var1);
} catch (Exception var3) {
var3.printStackTrace();
}
}
private void sendToConsoleAlt5(String var1) {
try {
this.appendColoredText(this.consoleArea, this.prefix() + var1 + "\n", 14, Color.PINK, false, false, false);
this.toLogFile(var1);
} catch (Exception var3) {
var3.printStackTrace();
}
}
private void sendToConsoleLog(String var1) {
try {
this.appendColoredText(this.consoleArea, this.prefix() + var1 + "\n", 14, Color.LIGHT_GRAY, false, true, false);
this.toLogFile(var1);
} catch (Exception var3) {
var3.printStackTrace();
}
}
private void toLogFile(String var1) {
String var2 = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date());
String var3 = "nscp/log_" + var2 + ".log";
try {
BufferedWriter var4 = new BufferedWriter(new FileWriter(var3, true));
try {
var4.write(var1);
var4.newLine();
} catch (Throwable var8) {
try {
var4.close();
} catch (Throwable var7) {
var8.addSuppressed(var7);
}
throw var8;
}
var4.close();
} catch (IOException var9) {
var9.printStackTrace();
}
}
private void visibility(boolean var1) {
this.startButton.setVisible(var1);
this.stopButton.setVisible(var1);
this.restartButton.setVisible(var1);
this.consoleArea.setVisible(var1);
this.commandField.setVisible(var1);
this.consoleArea.setAutoscrolls(true);
this.connectionField.setVisible(var1);
JScrollPane var2 = new JScrollPane(this.consoleArea);
this.add(var2, "Center");
if (var1) {
this.startButton.repaint();
this.stopButton.repaint();
this.restartButton.repaint();
this.consoleArea.repaint();
this.commandField.repaint();
this.connectionField.repaint();
this.startButton.revalidate();
this.stopButton.revalidate();
this.restartButton.revalidate();
this.consoleArea.revalidate();
this.commandField.revalidate();
this.connectionField.revalidate();
this.stopButton.setVisible(false);
this.restartButton.setVisible(false);
this.startButton.setVisible(true);
this.consoleArea.setFont(this.terminalFont().deriveFont(0, 12.0F));
}
}
}

View File

@ -0,0 +1,8 @@
# NSCP properties file, only change these values IF you know what you are doing
version=v1.6
user=Undefined
jar=server.jar
EnableBot=false
botID=YOUR_BOT_ID
botChanel=BOT_CHANEL_ID
botLogging=BOT_LOGGING_CHANEL_ID

BIN
src/nscp/minecraft.ttf Normal file

Binary file not shown.

BIN
src/nscp/server-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB