mirror of
https://github.com/JonasunderscoreJones/BetterConsoleMC.git
synced 2025-10-25 22:49:17 +02:00
Compare commits
19 commits
0.0.1+alph
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| bafaa358d5 | |||
| 2395370a7b | |||
| 9f3750b52d | |||
| 261aa55568 | |||
| e9d1537d83 | |||
| 7c65b9c0ff | |||
| 95777078b0 | |||
| 1ed05887f8 | |||
| 06fc172a6b | |||
| 8b110345c4 | |||
| eb9464e60a | |||
| 5937c06074 | |||
| d287466669 | |||
| 01214a78e7 | |||
| f897d7630e | |||
| 2f759e2edf | |||
| a4d242b6ef | |||
| 3c73ed16a5 | |||
| f4c6c6d22a |
16 changed files with 183 additions and 112 deletions
41
.forgejo/workflows/java-build.yml
Normal file
41
.forgejo/workflows/java-build.yml
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
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
|
||||||
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
|
|
@ -12,7 +12,7 @@ jobs:
|
||||||
matrix:
|
matrix:
|
||||||
# Use these Java versions
|
# Use these Java versions
|
||||||
java: [
|
java: [
|
||||||
17, # Current Java LTS & minimum supported by Minecraft
|
21, # Current Java LTS
|
||||||
]
|
]
|
||||||
# and run on both Linux and Windows
|
# and run on both Linux and Windows
|
||||||
os: [ubuntu-22.04, windows-2022]
|
os: [ubuntu-22.04, windows-2022]
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,6 @@ 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!
|
5. Restart your Minecraft server and You're good to go!
|
||||||
|
|
||||||
# KNOWN ISSUES
|
# KNOWN ISSUES
|
||||||
- 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
|
||||||
- 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
|
- the console is spamed with debug messages
|
||||||
- threads are not closed after a task exits
|
- threads are not closed after a task exit
|
||||||
- and many more....
|
|
||||||
|
|
|
||||||
42
build.gradle
42
build.gradle
|
|
@ -1,15 +1,15 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'fabric-loom' version '1.0-SNAPSHOT'
|
id 'fabric-loom' version '1.10-SNAPSHOT'
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
|
||||||
|
|
||||||
archivesBaseName = project.archives_base_name
|
|
||||||
version = project.mod_version
|
version = project.mod_version
|
||||||
group = project.maven_group
|
group = project.maven_group
|
||||||
|
|
||||||
|
base {
|
||||||
|
archivesName = project.archives_base_name
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
// Add repositories to retrieve artifacts from in here.
|
// Add repositories to retrieve artifacts from in here.
|
||||||
// You should only use this when depending on other mods because
|
// You should only use this when depending on other mods because
|
||||||
|
|
@ -18,6 +18,18 @@ repositories {
|
||||||
// for more information about repositories.
|
// for more information about repositories.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loom {
|
||||||
|
splitEnvironmentSourceSets()
|
||||||
|
|
||||||
|
mods {
|
||||||
|
"modid" {
|
||||||
|
sourceSet sourceSets.main
|
||||||
|
sourceSet sourceSets.client
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// To change the versions see the gradle.properties file
|
// To change the versions see the gradle.properties file
|
||||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||||
|
|
@ -27,23 +39,21 @@ dependencies {
|
||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
|
|
||||||
// Uncomment the following line to enable the deprecated Fabric API modules.
|
compileOnly 'org.projectlombok:lombok:1.18.32'
|
||||||
// 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.
|
annotationProcessor 'org.projectlombok:lombok:1.18.32'
|
||||||
|
|
||||||
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property "version", project.version
|
inputs.property "version", project.version
|
||||||
|
|
||||||
filesMatching("fabric.mod.json") {
|
filesMatching("fabric.mod.json") {
|
||||||
expand "version": project.version
|
expand "version": inputs.properties.version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile).configureEach {
|
tasks.withType(JavaCompile).configureEach {
|
||||||
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
|
it.options.release = 21
|
||||||
it.options.release = 17
|
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
|
@ -51,18 +61,24 @@ java {
|
||||||
// if it is present.
|
// if it is present.
|
||||||
// If you remove this line, sources will not be generated.
|
// If you remove this line, sources will not be generated.
|
||||||
withSourcesJar()
|
withSourcesJar()
|
||||||
|
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_21
|
||||||
|
targetCompatibility = JavaVersion.VERSION_21
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
|
inputs.property "archivesName", project.base.archivesName
|
||||||
|
|
||||||
from("LICENSE") {
|
from("LICENSE") {
|
||||||
rename { "${it}_${project.archivesBaseName}"}
|
rename { "${it}_${inputs.properties.archivesName}"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure the maven publication
|
// configure the maven publication
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
mavenJava(MavenPublication) {
|
create("mavenJava", MavenPublication) {
|
||||||
|
artifactId = project.archives_base_name
|
||||||
from components.java
|
from components.java
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,15 @@ org.gradle.jvmargs=-Xmx1G
|
||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
|
|
||||||
# Fabric Properties;
|
# Fabric Properties;
|
||||||
minecraft_version=1.20.1
|
minecraft_version=1.21.5
|
||||||
yarn_mappings=1.20.1+build.10
|
yarn_mappings=1.21.5+build.1
|
||||||
loader_version=0.14.22
|
loader_version=0.16.14
|
||||||
|
loom_version=1.10-SNAPSHOT
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.0.1+alpha-build04
|
mod_version = 1.0.2
|
||||||
maven_group = me.jonasjones
|
maven_group = me.jonasjones
|
||||||
archives_base_name = betterconsolemc
|
archives_base_name = betterconsolemc
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
fabric_version=0.88.1+1.20.1
|
fabric_version=0.126.0+1.21.5
|
||||||
|
|
|
||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
|
|
@ -1,6 +1,7 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
|
||||||
33
gradlew
vendored
33
gradlew
vendored
|
|
@ -15,6 +15,8 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
|
|
@ -55,7 +57,7 @@
|
||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (3) This script is generated from the Groovy template
|
||||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
# within the Gradle project.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
|
@ -83,10 +85,8 @@ done
|
||||||
# This is normally unused
|
# This is normally unused
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
# 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
|
||||||
# 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.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
|
|
@ -133,10 +133,13 @@ location of your Java installation."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD=java
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
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.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
|
|
@ -144,7 +147,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
max*)
|
max*)
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
warn "Could not query maximum file descriptor limit"
|
warn "Could not query maximum file descriptor limit"
|
||||||
esac
|
esac
|
||||||
|
|
@ -152,7 +155,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
'' | soft) :;; #(
|
'' | soft) :;; #(
|
||||||
*)
|
*)
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
ulimit -n "$MAX_FD" ||
|
ulimit -n "$MAX_FD" ||
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
esac
|
esac
|
||||||
|
|
@ -197,11 +200,15 @@ if "$cygwin" || "$msys" ; then
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
# double quotes to make sure that they get re-expanded; and
|
|
||||||
# * put everything else in single quotes, so that it's not re-expanded.
|
# 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.
|
||||||
|
|
||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
|
|
||||||
22
gradlew.bat
vendored
22
gradlew.bat
vendored
|
|
@ -13,6 +13,8 @@
|
||||||
@rem See the License for the specific language governing permissions and
|
@rem See the License for the specific language governing permissions and
|
||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
|
|
@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if %ERRORLEVEL% equ 0 goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
|
|
@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,10 @@ public class CmdConfigHandler {
|
||||||
public static void getCommands(String path) throws IOException {
|
public static void getCommands(String path) throws IOException {
|
||||||
List<CommandPreRegistry> commands = new ArrayList<CommandPreRegistry>();
|
List<CommandPreRegistry> commands = new ArrayList<CommandPreRegistry>();
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(path));
|
BufferedReader reader = new BufferedReader(new FileReader(path));
|
||||||
int linecount = 0;
|
int linecount = 1;
|
||||||
String linecontent = reader.readLine();
|
String linecontent = reader.readLine();
|
||||||
while (linecontent != null) {
|
while (!linecontent.isEmpty()) {
|
||||||
if (!linecontent.startsWith("#") || linecontent.equals("")) {
|
if (!linecontent.startsWith("#") || linecontent.equals("\n")) {
|
||||||
System.out.println(linecontent);
|
|
||||||
try {
|
try {
|
||||||
commands.add(preRegisterCommands(linecontent));
|
commands.add(preRegisterCommands(linecontent));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -33,6 +32,9 @@ public class CmdConfigHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
linecontent = reader.readLine();
|
linecontent = reader.readLine();
|
||||||
|
if (linecontent == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
linecount++;
|
linecount++;
|
||||||
}
|
}
|
||||||
FULLREG = commands;
|
FULLREG = commands;
|
||||||
|
|
@ -43,12 +45,11 @@ public class CmdConfigHandler {
|
||||||
CmdMode commandMode = getCommandMode(configCommandDef);
|
CmdMode commandMode = getCommandMode(configCommandDef);
|
||||||
int permissionLevel = getPermissionLevel(configCommandDef);
|
int permissionLevel = getPermissionLevel(configCommandDef);
|
||||||
int execTimeout = getExecTimeout(configCommandDef);
|
int execTimeout = getExecTimeout(configCommandDef);
|
||||||
int execRerunTimeout = getExecRerunTiemout(configCommandDef);
|
|
||||||
boolean broadcastToOP = doBroadcastToOP(configCommandDef);
|
boolean broadcastToOP = doBroadcastToOP(configCommandDef);
|
||||||
String ingameCommand = getIngameCommand(configCommandDef);
|
String ingameCommand = getIngameCommand(configCommandDef);
|
||||||
String command = getCommand(configCommandDef);
|
String command = getCommand(configCommandDef);
|
||||||
|
|
||||||
preRegisteredCommand.init(commandMode, command, permissionLevel, execTimeout, ingameCommand, execRerunTimeout, broadcastToOP);
|
preRegisteredCommand.init(commandMode, command, permissionLevel, execTimeout, ingameCommand, broadcastToOP);
|
||||||
|
|
||||||
return preRegisteredCommand;
|
return preRegisteredCommand;
|
||||||
}
|
}
|
||||||
|
|
@ -80,21 +81,17 @@ public class CmdConfigHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getIngameCommand(String configCommandDef) {
|
private static String getIngameCommand(String configCommandDef) {
|
||||||
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, 4);
|
return getSplitCommandPartByIndex(configCommandDef, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getBroadcastToOP(String configCommandDef) throws BroadcastToOpNotBoolException {
|
||||||
|
return getSplitCommandPartByIndex(configCommandDef, 3);
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean doBroadcastToOP(String configCommandDef) throws BroadcastToOpNotBoolException {
|
private static boolean doBroadcastToOP(String configCommandDef) throws BroadcastToOpNotBoolException {
|
||||||
if (getSplitCommandPartByIndex(configCommandDef, 4).equals("true")) {
|
if (getSplitCommandPartByIndex(configCommandDef, 3).equals("true")) {
|
||||||
return true;
|
return true;
|
||||||
} else if (getSplitCommandPartByIndex(configCommandDef, 5).equals("false")) {
|
} else if (getSplitCommandPartByIndex(configCommandDef, 4).equals("false")) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
throw new BroadcastToOpNotBoolException();
|
throw new BroadcastToOpNotBoolException();
|
||||||
|
|
@ -102,7 +99,7 @@ public class CmdConfigHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getCommand(String configCommandDef) throws Exception {
|
private static String getCommand(String configCommandDef) throws Exception {
|
||||||
return configCommandDef.replaceFirst(getCommandMode(configCommandDef).name() + " " + getPermissionLevel(configCommandDef) + " " + getExecTimeout(configCommandDef) + " " + getExecRerunTiemout(configCommandDef) + " " + getBroadcastToOP(configCommandDef) + " " + getIngameCommand(configCommandDef) + " ", "")
|
return configCommandDef.replaceFirst(getCommandMode(configCommandDef).name() + " " + getPermissionLevel(configCommandDef) + " " + getExecTimeout(configCommandDef) + " " + getBroadcastToOP(configCommandDef) + " " + getIngameCommand(configCommandDef) + " ", "")
|
||||||
.replaceFirst("\"", "")
|
.replaceFirst("\"", "")
|
||||||
.replaceAll("\"$", "");
|
.replaceAll("\"$", "");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,12 @@ public class CmdConfigs {
|
||||||
private static void createConfigs() {
|
private static void createConfigs() {
|
||||||
cmdconfigs.addSingleLineComment("This is the command configuration file for BetterConsoleMC");
|
cmdconfigs.addSingleLineComment("This is the command configuration file for BetterConsoleMC");
|
||||||
if (ISWINDOWS) {
|
if (ISWINDOWS) {
|
||||||
cmdconfigs.addSingleLineComment("This message is there to remind you that the mod is running on a WINODWS machine");
|
cmdconfigs.addSingleLineComment("This message is there to remind you that the mod is running on a WINDOWS machine");
|
||||||
} else {
|
} else {
|
||||||
cmdconfigs.addSingleLineComment("This message is there to remind you that the mod is running on a UNIX-LIKE machine");
|
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("The general syntax of defining a command goes like this:");
|
||||||
cmdconfigs.addSingleLineComment("[Command Mode] [Permissione Level] [Execution Timeout] [Execution Block Timeout] [Broadcast to OP] [Ingame Command name] [command to execute]");
|
cmdconfigs.addSingleLineComment("[Command Mode] [Permission Level] [Execution Timeout] [Broadcast to OP] [In-game Command name] [command to execute]");
|
||||||
cmdconfigs.addSingleLineComment("Documentation and examples are available at the wiki of the repository");
|
cmdconfigs.addSingleLineComment("Documentation and examples are available at the wiki of the repository");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@ public class GameCommandHandler {
|
||||||
serverCommandSourceCommandDispatcher.register((CommandManager.literal(commandPreRegistry.getIngamecommand()).requires(source -> source.hasPermissionLevel(commandPreRegistry.getPermissionLevel()))
|
serverCommandSourceCommandDispatcher.register((CommandManager.literal(commandPreRegistry.getIngamecommand()).requires(source -> source.hasPermissionLevel(commandPreRegistry.getPermissionLevel()))
|
||||||
.executes((context -> {
|
.executes((context -> {
|
||||||
if (commandPreRegistry.getCommandmode() == Constants.CmdMode.RETURN) {
|
if (commandPreRegistry.getCommandmode() == Constants.CmdMode.RETURN) {
|
||||||
context.getSource().sendFeedback(() -> runCommand(commandPreRegistry, context), commandPreRegistry.doBroadcastToOp());
|
runCommand(commandPreRegistry, context);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
})))
|
})))
|
||||||
|
|
|
||||||
|
|
@ -62,8 +62,10 @@ public class SimpleConfig {
|
||||||
try {
|
try {
|
||||||
loadConfig();
|
loadConfig();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (!identifier.equals("Config 'betterconsolemc-commands_config'")) { // this is good code, I swear
|
||||||
LOGGER.error(identifier + " failed to load!");
|
LOGGER.error(identifier + " failed to load!");
|
||||||
LOGGER.trace(e);
|
LOGGER.trace(e);
|
||||||
|
}
|
||||||
broken = true;
|
broken = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import me.jonasjones.betterconsolemc.command.GameCommandHandler;
|
||||||
import me.jonasjones.betterconsolemc.modconfig.ModConfigs;
|
import me.jonasjones.betterconsolemc.modconfig.ModConfigs;
|
||||||
import me.jonasjones.betterconsolemc.util.CommandPreRegistry;
|
import me.jonasjones.betterconsolemc.util.CommandPreRegistry;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -27,16 +28,48 @@ public class ShellCommand {
|
||||||
|
|
||||||
Process process = processBuilder.start();
|
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 =
|
BufferedReader reader =
|
||||||
new BufferedReader(new InputStreamReader(process.getInputStream()));
|
new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
|
||||||
String line;
|
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) {
|
while ((line = reader.readLine()) != null) {
|
||||||
if (ModConfigs.LOG_CMD_OUTPUT) {
|
if (ModConfigs.LOG_CMD_OUTPUT) {
|
||||||
GameCommandHandler.returnCommandOutput(command.getCommand(), line, context);
|
GameCommandHandler.returnCommandOutput(command.getCommand(), line, context);
|
||||||
}
|
}
|
||||||
//get the ingame command name
|
//get the ingame command name
|
||||||
output.append("[").append(command.getIngamecommand()).append("]").append(line).append("\n");
|
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
|
// Read buffered reader line by line and append to output with prefix of command before each line
|
||||||
|
|
|
||||||
|
|
@ -1,49 +1,22 @@
|
||||||
package me.jonasjones.betterconsolemc.util;
|
package me.jonasjones.betterconsolemc.util;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class CommandPreRegistry { //TODO: Add timeout before command can be ran again (unixtimestamp)
|
public class CommandPreRegistry { //TODO: Add timeout before command can be ran again (unixtimestamp)
|
||||||
private Constants.CmdMode commandmode;
|
private Constants.CmdMode commandmode;
|
||||||
private String command;
|
private String command;
|
||||||
private int permissionLevel;
|
private int permissionLevel;
|
||||||
private int execTimeout;
|
private int execTimeout;
|
||||||
private String ingamecommand;
|
private String ingamecommand;
|
||||||
private int execRerunTimeout;
|
|
||||||
private boolean broadcastToOp;
|
private boolean broadcastToOp;
|
||||||
|
|
||||||
public void init(Constants.CmdMode commandmode, String command, int permissionLevel, int execTimeout, String ingamecommand, int execRerunTimeout, boolean broadcastToOp) {
|
public void init(Constants.CmdMode commandmode, String command, int permissionLevel, int execTimeout, String ingamecommand, boolean broadcastToOp) {
|
||||||
this.commandmode = commandmode;
|
this.commandmode = commandmode;
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.permissionLevel = permissionLevel;
|
this.permissionLevel = permissionLevel;
|
||||||
this.execTimeout = execTimeout;
|
this.execTimeout = execTimeout;
|
||||||
this.ingamecommand = ingamecommand;
|
this.ingamecommand = ingamecommand;
|
||||||
this.execRerunTimeout = execRerunTimeout;
|
|
||||||
this.broadcastToOp = broadcastToOp;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue