diff --git a/.forgejo/workflows/java-build.yml b/.forgejo/workflows/java-build.yml deleted file mode 100644 index fc4be96..0000000 --- a/.forgejo/workflows/java-build.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: build-java -on: [ push, pull_request ] - -jobs: - build: - runs-on: docker - steps: - - name: checkout repository - uses: https://code.forgejo.org/actions/checkout@v4 - - name: setup jdk - uses: https://github.com/actions/setup-java@v4 - with: - java-version: | - 8 - 21 - distribution: temurin - - name: restore cached dependencies - uses: https://code.forgejo.org/actions/cache/restore@v4 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-Gradle - - name: build - run: ./gradlew build --no-daemon --warning-mode=all - - name: capture build artifacts - uses: https://code.forgejo.org/forgejo/upload-artifact@v4 - with: - name: build-artifacts.zip - path: | - build/libs - !build/libs/*-all.jar - if-no-files-found: error - - name: cache downloaded dependencies - if: ${{ github.ref_name == github.event.repository.default_branch }} - uses: https://code.forgejo.org/actions/cache/save@v4 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-Gradle diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2c1e08c..e2fa68a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: matrix: # Use these Java versions java: [ - 21, # Current Java LTS + 17, # Current Java LTS & minimum supported by Minecraft ] # and run on both Linux and Windows os: [ubuntu-22.04, windows-2022] diff --git a/README.md b/README.md index c7ab260..ffac7f9 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,9 @@ Beware that anyone who has write access to the MC server's files is able to edit 5. Restart your Minecraft server and You're good to go! # KNOWN ISSUES -- Execution Timeout and Execution block Timeout have no effect on the command at this point +- It is only possible to define a single command at this point - subject to change once I figure out how to do things +- Execution Timeout and Execution block Timeout have no effect on the command at this point. +- The command mode has no effect on the command feedback itself. in any case, the output will be sent in chat - the console is spamed with debug messages -- threads are not closed after a task exit +- threads are not closed after a task exits +- and many more.... diff --git a/build.gradle b/build.gradle index d17038a..6d30805 100644 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,15 @@ plugins { - id 'fabric-loom' version '1.10-SNAPSHOT' + id 'fabric-loom' version '1.0-SNAPSHOT' id 'maven-publish' } +sourceCompatibility = JavaVersion.VERSION_17 +targetCompatibility = JavaVersion.VERSION_17 + +archivesBaseName = project.archives_base_name version = project.mod_version group = project.maven_group -base { - archivesName = project.archives_base_name -} - repositories { // Add repositories to retrieve artifacts from in here. // You should only use this when depending on other mods because @@ -18,18 +18,6 @@ repositories { // for more information about repositories. } -loom { - splitEnvironmentSourceSets() - - mods { - "modid" { - sourceSet sourceSets.main - sourceSet sourceSets.client - } - } - -} - dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" @@ -39,21 +27,23 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - compileOnly 'org.projectlombok:lombok:1.18.32' - annotationProcessor 'org.projectlombok:lombok:1.18.32' - + // Uncomment the following line to enable the deprecated Fabric API modules. + // These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. + + // modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}" } processResources { inputs.property "version", project.version filesMatching("fabric.mod.json") { - expand "version": inputs.properties.version + expand "version": project.version } } tasks.withType(JavaCompile).configureEach { - it.options.release = 21 + // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. + it.options.release = 17 } java { @@ -61,24 +51,18 @@ java { // if it is present. // If you remove this line, sources will not be generated. withSourcesJar() - - sourceCompatibility = JavaVersion.VERSION_21 - targetCompatibility = JavaVersion.VERSION_21 } jar { - inputs.property "archivesName", project.base.archivesName - from("LICENSE") { - rename { "${it}_${inputs.properties.archivesName}"} + rename { "${it}_${project.archivesBaseName}"} } } // configure the maven publication publishing { publications { - create("mavenJava", MavenPublication) { - artifactId = project.archives_base_name + mavenJava(MavenPublication) { from components.java } } @@ -90,4 +74,4 @@ publishing { // The repositories here will be used for publishing your artifact, not for // retrieving dependencies. } -} \ No newline at end of file +} diff --git a/gradle.properties b/gradle.properties index fe91f33..45660da 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,15 +3,14 @@ org.gradle.jvmargs=-Xmx1G org.gradle.parallel=true # Fabric Properties; -minecraft_version=1.21.5 -yarn_mappings=1.21.5+build.1 -loader_version=0.16.14 -loom_version=1.10-SNAPSHOT +minecraft_version=1.20.1 +yarn_mappings=1.20.1+build.10 +loader_version=0.14.22 # Mod Properties -mod_version = 1.0.2 +mod_version = 0.0.1+alpha-build04 maven_group = me.jonasjones archives_base_name = betterconsolemc # Dependencies -fabric_version=0.126.0+1.21.5 +fabric_version=0.88.1+1.20.1 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index a4b76b9..943f0cb 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e18bc25..f398c33 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip networkTimeout=10000 -validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index f3b75f3..65dcd68 100755 --- a/gradlew +++ b/gradlew @@ -15,8 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# SPDX-License-Identifier: Apache-2.0 -# ############################################################################## # @@ -57,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -85,8 +83,10 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,13 +133,10 @@ location of your Java installation." fi else JAVACMD=java - if ! command -v java >/dev/null 2>&1 - then - die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi fi # Increase the maximum file descriptors if we can. @@ -147,7 +144,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -155,7 +152,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -200,15 +197,11 @@ if "$cygwin" || "$msys" ; then done fi - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, -# and any embedded shellness will be escaped. -# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be -# treated as '${Hostname}' itself on the command line. +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/gradlew.bat b/gradlew.bat index 9d21a21..93e3f59 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,6 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem -@rem SPDX-License-Identifier: Apache-2.0 -@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -45,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. 1>&2 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. goto fail @@ -59,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. 1>&2 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. goto fail diff --git a/settings.gradle b/settings.gradle index 75c4d72..b02216b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,10 +1,10 @@ pluginManagement { - repositories { - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' - } - mavenCentral() - gradlePluginPortal() - } -} \ No newline at end of file + repositories { + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + mavenCentral() + gradlePluginPortal() + } +} diff --git a/src/main/java/me/jonasjones/betterconsolemc/cmdconfig/CmdConfigHandler.java b/src/main/java/me/jonasjones/betterconsolemc/cmdconfig/CmdConfigHandler.java index 95b95cd..15da5a0 100644 --- a/src/main/java/me/jonasjones/betterconsolemc/cmdconfig/CmdConfigHandler.java +++ b/src/main/java/me/jonasjones/betterconsolemc/cmdconfig/CmdConfigHandler.java @@ -20,10 +20,11 @@ public class CmdConfigHandler { public static void getCommands(String path) throws IOException { List commands = new ArrayList(); BufferedReader reader = new BufferedReader(new FileReader(path)); - int linecount = 1; + int linecount = 0; String linecontent = reader.readLine(); - while (!linecontent.isEmpty()) { - if (!linecontent.startsWith("#") || linecontent.equals("\n")) { + while (linecontent != null) { + if (!linecontent.startsWith("#") || linecontent.equals("")) { + System.out.println(linecontent); try { commands.add(preRegisterCommands(linecontent)); } catch (Exception e) { @@ -32,9 +33,6 @@ public class CmdConfigHandler { } } linecontent = reader.readLine(); - if (linecontent == null) { - break; - } linecount++; } FULLREG = commands; @@ -45,11 +43,12 @@ public class CmdConfigHandler { CmdMode commandMode = getCommandMode(configCommandDef); int permissionLevel = getPermissionLevel(configCommandDef); int execTimeout = getExecTimeout(configCommandDef); + int execRerunTimeout = getExecRerunTiemout(configCommandDef); boolean broadcastToOP = doBroadcastToOP(configCommandDef); String ingameCommand = getIngameCommand(configCommandDef); String command = getCommand(configCommandDef); - preRegisteredCommand.init(commandMode, command, permissionLevel, execTimeout, ingameCommand, broadcastToOP); + preRegisteredCommand.init(commandMode, command, permissionLevel, execTimeout, ingameCommand, execRerunTimeout, broadcastToOP); return preRegisteredCommand; } @@ -81,17 +80,21 @@ public class CmdConfigHandler { } private static String getIngameCommand(String configCommandDef) { - return getSplitCommandPartByIndex(configCommandDef, 4); + return getSplitCommandPartByIndex(configCommandDef, 5); + } + + private static int getExecRerunTiemout(String configCommandDef) { + return Integer.parseInt(getSplitCommandPartByIndex(configCommandDef, 3)); } private static String getBroadcastToOP(String configCommandDef) throws BroadcastToOpNotBoolException { - return getSplitCommandPartByIndex(configCommandDef, 3); + return getSplitCommandPartByIndex(configCommandDef, 4); } private static boolean doBroadcastToOP(String configCommandDef) throws BroadcastToOpNotBoolException { - if (getSplitCommandPartByIndex(configCommandDef, 3).equals("true")) { + if (getSplitCommandPartByIndex(configCommandDef, 4).equals("true")) { return true; - } else if (getSplitCommandPartByIndex(configCommandDef, 4).equals("false")) { + } else if (getSplitCommandPartByIndex(configCommandDef, 5).equals("false")) { return false; } else { throw new BroadcastToOpNotBoolException(); @@ -99,7 +102,7 @@ public class CmdConfigHandler { } private static String getCommand(String configCommandDef) throws Exception { - return configCommandDef.replaceFirst(getCommandMode(configCommandDef).name() + " " + getPermissionLevel(configCommandDef) + " " + getExecTimeout(configCommandDef) + " " + getBroadcastToOP(configCommandDef) + " " + getIngameCommand(configCommandDef) + " ", "") + return configCommandDef.replaceFirst(getCommandMode(configCommandDef).name() + " " + getPermissionLevel(configCommandDef) + " " + getExecTimeout(configCommandDef) + " " + getExecRerunTiemout(configCommandDef) + " " + getBroadcastToOP(configCommandDef) + " " + getIngameCommand(configCommandDef) + " ", "") .replaceFirst("\"", "") .replaceAll("\"$", ""); } diff --git a/src/main/java/me/jonasjones/betterconsolemc/cmdconfig/CmdConfigs.java b/src/main/java/me/jonasjones/betterconsolemc/cmdconfig/CmdConfigs.java index 3451835..ed238c6 100644 --- a/src/main/java/me/jonasjones/betterconsolemc/cmdconfig/CmdConfigs.java +++ b/src/main/java/me/jonasjones/betterconsolemc/cmdconfig/CmdConfigs.java @@ -22,12 +22,12 @@ public class CmdConfigs { private static void createConfigs() { cmdconfigs.addSingleLineComment("This is the command configuration file for BetterConsoleMC"); if (ISWINDOWS) { - cmdconfigs.addSingleLineComment("This message is there to remind you that the mod is running on a WINDOWS machine"); + cmdconfigs.addSingleLineComment("This message is there to remind you that the mod is running on a WINODWS machine"); } else { cmdconfigs.addSingleLineComment("This message is there to remind you that the mod is running on a UNIX-LIKE machine"); } cmdconfigs.addSingleLineComment("The general syntax of defining a command goes like this:"); - cmdconfigs.addSingleLineComment("[Command Mode] [Permission Level] [Execution Timeout] [Broadcast to OP] [In-game Command name] [command to execute]"); + cmdconfigs.addSingleLineComment("[Command Mode] [Permissione Level] [Execution Timeout] [Execution Block Timeout] [Broadcast to OP] [Ingame Command name] [command to execute]"); cmdconfigs.addSingleLineComment("Documentation and examples are available at the wiki of the repository"); } diff --git a/src/main/java/me/jonasjones/betterconsolemc/command/GameCommandHandler.java b/src/main/java/me/jonasjones/betterconsolemc/command/GameCommandHandler.java index b596029..897c9b5 100644 --- a/src/main/java/me/jonasjones/betterconsolemc/command/GameCommandHandler.java +++ b/src/main/java/me/jonasjones/betterconsolemc/command/GameCommandHandler.java @@ -31,8 +31,7 @@ public class GameCommandHandler { serverCommandSourceCommandDispatcher.register((CommandManager.literal(commandPreRegistry.getIngamecommand()).requires(source -> source.hasPermissionLevel(commandPreRegistry.getPermissionLevel())) .executes((context -> { if (commandPreRegistry.getCommandmode() == Constants.CmdMode.RETURN) { - runCommand(commandPreRegistry, context); - return 1; + context.getSource().sendFeedback(() -> runCommand(commandPreRegistry, context), commandPreRegistry.doBroadcastToOp()); } return 1; }))) diff --git a/src/main/java/me/jonasjones/betterconsolemc/modconfig/SimpleConfig.java b/src/main/java/me/jonasjones/betterconsolemc/modconfig/SimpleConfig.java index d72767b..993e461 100644 --- a/src/main/java/me/jonasjones/betterconsolemc/modconfig/SimpleConfig.java +++ b/src/main/java/me/jonasjones/betterconsolemc/modconfig/SimpleConfig.java @@ -62,10 +62,8 @@ public class SimpleConfig { try { loadConfig(); } catch (Exception e) { - if (!identifier.equals("Config 'betterconsolemc-commands_config'")) { // this is good code, I swear - LOGGER.error(identifier + " failed to load!"); - LOGGER.trace(e); - } + LOGGER.error(identifier + " failed to load!"); + LOGGER.trace(e); broken = true; } } diff --git a/src/main/java/me/jonasjones/betterconsolemc/system/ShellCommand.java b/src/main/java/me/jonasjones/betterconsolemc/system/ShellCommand.java index 6f30739..1a5285f 100644 --- a/src/main/java/me/jonasjones/betterconsolemc/system/ShellCommand.java +++ b/src/main/java/me/jonasjones/betterconsolemc/system/ShellCommand.java @@ -6,7 +6,6 @@ import me.jonasjones.betterconsolemc.command.GameCommandHandler; import me.jonasjones.betterconsolemc.modconfig.ModConfigs; import me.jonasjones.betterconsolemc.util.CommandPreRegistry; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; import java.io.BufferedReader; import java.io.IOException; @@ -28,48 +27,16 @@ public class ShellCommand { Process process = processBuilder.start(); - //set timeout - long timeout = System.currentTimeMillis()/1000L + command.getExecTimeout(); - //if timeout is 0, set it to not have a timeout - if (command.getExecTimeout() == 0) { - timeout = Long.MAX_VALUE; - } - BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; - // WIP - //System.out.println("TIMEOUT: " + timeout); - //System.out.println("TIME: " + System.currentTimeMillis()/1000L); - - long finalTimeout = timeout; - new Thread(() -> { - while (System.currentTimeMillis()/1000L < finalTimeout) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - if (process.isAlive()) { - process.destroy(); - } - }).start(); - while ((line = reader.readLine()) != null) { if (ModConfigs.LOG_CMD_OUTPUT) { GameCommandHandler.returnCommandOutput(command.getCommand(), line, context); } //get the ingame command name output.append("[").append(command.getIngamecommand()).append("]").append(line).append("\n"); - String finalLine = line; - context.getSource().sendFeedback(() -> Text.of("[" + command.getIngamecommand() + "] " + finalLine), command.isBroadcastToOp()); - } - - //quit the process if it's still running - if (process.isAlive()) { - process.destroy(); } // Read buffered reader line by line and append to output with prefix of command before each line diff --git a/src/main/java/me/jonasjones/betterconsolemc/util/CommandPreRegistry.java b/src/main/java/me/jonasjones/betterconsolemc/util/CommandPreRegistry.java index 4bbb280..65fc042 100644 --- a/src/main/java/me/jonasjones/betterconsolemc/util/CommandPreRegistry.java +++ b/src/main/java/me/jonasjones/betterconsolemc/util/CommandPreRegistry.java @@ -1,22 +1,49 @@ package me.jonasjones.betterconsolemc.util; -import lombok.Getter; - -@Getter public class CommandPreRegistry { //TODO: Add timeout before command can be ran again (unixtimestamp) private Constants.CmdMode commandmode; private String command; private int permissionLevel; private int execTimeout; private String ingamecommand; + private int execRerunTimeout; private boolean broadcastToOp; - public void init(Constants.CmdMode commandmode, String command, int permissionLevel, int execTimeout, String ingamecommand, boolean broadcastToOp) { + public void init(Constants.CmdMode commandmode, String command, int permissionLevel, int execTimeout, String ingamecommand, int execRerunTimeout, boolean broadcastToOp) { this.commandmode = commandmode; this.command = command; this.permissionLevel = permissionLevel; this.execTimeout = execTimeout; this.ingamecommand = ingamecommand; + this.execRerunTimeout = execRerunTimeout; this.broadcastToOp = broadcastToOp; } + + public Constants.CmdMode getCommandmode() { + return this.commandmode; + } + + public String getCommand() { + return this.command; + } + + public int getPermissionLevel() { + return this.permissionLevel; + } + + public int getExecTimeout() { + return this.execTimeout; + } + + public String getIngamecommand() { + return this.ingamecommand; + } + + public int getExecRerunTimeout() { + return this.execRerunTimeout; + } + + public boolean doBroadcastToOp() { + return this.broadcastToOp; + } }