From bdcef6c3881e10b3660e7aa50e032bdae1da4e79 Mon Sep 17 00:00:00 2001 From: alujjdnd Date: Thu, 16 Jun 2022 21:53:22 +0800 Subject: [PATCH 1/9] Updated to match branch name --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3064323..c775f03 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Ngrok LAN Banner](https://github.com/Alujjdnd/Ngrok-LAN/blob/main/docs/assets/banner.png?raw=true) +![Ngrok LAN Banner](https://github.com/Alujjdnd/Ngrok-LAN/blob/1.18.2/docs/assets/banner.png?raw=true)

Ngrok LAN @@ -11,7 +11,7 @@ GitHub commit activity
- + ## Help Needed! @@ -26,7 +26,7 @@ after you click on "Open Public Server". For more on how Ngrok-LAN works, check out [What is Ngrok](#what-is-ngrok).
- Network Diagram + Network Diagram
# Installation/Quick Start @@ -129,7 +129,7 @@ friends to connect to our server. This doesn't require any other configuration o internet, and an Ngrok account, you can host your singleplayer world to your friends across the globe.
-Network Diagram +Network Diagram
## Ngrok Account Requirements From 364e425dbf09a14b80affa813cd6dd82159043e0 Mon Sep 17 00:00:00 2001 From: Mikolaj Date: Mon, 11 Jul 2022 21:18:01 +0200 Subject: [PATCH 2/9] Get the mod working on quilt --- .editorconfig | 34 +++ .gitignore | 24 +- build.gradle | 84 +++---- gradle.properties | 20 +- gradle/gradle | 234 ------------------ gradle/libs.versions.toml | 22 ++ gradle/wrapper/gradle-wrapper.jar | Bin 59536 -> 59821 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 10 +- settings.gradle | 20 +- .../java/alujjdnd/ngrok/lan/NgrokLan.java | 9 +- .../ngrok/lan/NgrokServerInitialiser.java | 10 +- .../ngrok/lan/command/LanDeopCommand.java | 6 +- .../ngrok/lan/command/LanOpCommand.java | 6 +- .../lan/command/LanWhitelistCommand.java | 24 +- .../lan/command/ReloadJsonListsCommand.java | 6 +- .../ngrok/lan/mixin/OpenToLanScreenMixin.java | 30 +-- src/main/resources/fabric.mod.json | 47 ---- src/main/resources/quilt.mod.json | 51 ++++ 19 files changed, 227 insertions(+), 412 deletions(-) create mode 100644 .editorconfig delete mode 100644 gradle/gradle create mode 100644 gradle/libs.versions.toml mode change 100644 => 100755 gradlew delete mode 100644 src/main/resources/fabric.mod.json create mode 100644 src/main/resources/quilt.mod.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0908154 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,34 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +tab_width = 4 +trim_trailing_whitespace = true + +[*.gradle] +indent_style = tab + +[*.java] +indent_style = tab + +[*.json] +indent_style = space +indent_size = 2 + +[quilt.mod.json] +indent_style = tab +tab_width = 2 + +[*.toml] +indent_style = tab +tab_width = 2 + +[*.properties] +indent_style = space +indent_size = 2 + +[.editorconfig] +indent_style = space +indent_size = 4 diff --git a/.gitignore b/.gitignore index 6234ac5..3819565 100644 --- a/.gitignore +++ b/.gitignore @@ -1,36 +1,30 @@ -# gradle - +# Gradle .gradle/ build/ out/ classes/ -# eclipse +# Quilt Loom +run/ +# Eclipse *.launch -# idea - +# IntelliJ Idea .idea/ *.iml *.ipr *.iws -# vscode - +# Visual Studio Code .settings/ .vscode/ bin/ .classpath .project -# macos +# Eclipse JDT LS +workspace/ +# macOS *.DS_Store - -# fabric - -run/ - -# enviroment -.env diff --git a/build.gradle b/build.gradle index f088c9d..396a9d8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,12 @@ plugins { - id 'fabric-loom' version '0.11-SNAPSHOT' id 'maven-publish' + alias(libs.plugins.quilt.loom) id 'com.github.johnrengelman.shadow' version '7.1.2' - id 'java' id "com.modrinth.minotaur" version "2.+" - //id 'net.minecraftforge.gradle.forge' version '2.0.2' - //id 'com.matthewprenger.cursegradle' version '1.4.0' } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 - archivesBaseName = project.archives_base_name -version = project.mod_version +version = project.version group = project.maven_group repositories { @@ -23,65 +17,74 @@ repositories { // for more information about repositories. maven { url "https://maven.shedaniel.me/" } - maven { url "https://maven.terraformersmc.com/" } + maven { url "https://maven.terraformersmc.com/" } } +// All the dependencies are declared at gradle/libs.version.toml and referenced with "libs." +// See https://docs.gradle.org/current/userguide/platforms.html for information on how version catalogs work. dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + minecraft libs.minecraft + mappings loom.layered { + addLayer quiltMappings.mappings("org.quiltmc:quilt-mappings:${libs.versions.quilt.mappings.get()}:v2") + // officialMojangMappings() // Uncomment if you want to use Mojang mappings as your primary mappings, falling back on QM for parameters and Javadocs + } + modImplementation libs.quilt.loader - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + // QSL is not a complete API; You will need Quilted Fabric API to fill in the gaps. + // Quilted Fabric API will automatically pull in the correct QSL version. + modImplementation libs.quilted.fabric.api + // modImplementation libs.bundles.quilted.fabric.api // If you wish to use Fabric API's deprecated modules, you can replace the above line with this one //Java-Ngrok, a wrapper for the Ngrok service by providing a handy Java API to call it. - modImplementation(include("com.github.alexdlaird:java-ngrok:1.5.6")) + modImplementation(include("com.github.alexdlaird:java-ngrok:1.5.6")) - modImplementation(include("org.yaml:snakeyaml:1.8")) + modImplementation(include("org.yaml:snakeyaml:1.30")) - modApi("me.shedaniel.cloth:cloth-config-fabric:4.11.14") { - exclude(group: "net.fabricmc.fabric-api") - } + modApi("me.shedaniel.cloth:cloth-config-fabric:7.0.72") { + exclude(group: "net.fabricmc.fabric-api") + } modImplementation(include("blue.endless:jankson:1.2.1")) - modImplementation(include("com.terraformersmc:modmenu:3.1.0")) + modImplementation(include("com.terraformersmc:modmenu:4.0.0")) } processResources { - inputs.property "version", project.version + inputs.property "version", version - filesMatching("fabric.mod.json") { - expand "version": project.version + filesMatching('quilt.mod.json') { + expand "version": version } } tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. it.options.release = 17 } java { - // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task - // if it is present. + // Still required by IDEs such as Eclipse and Visual Studio Code + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task if it is present. // If you remove this line, sources will not be generated. withSourcesJar() + + // If this mod is going to be a library, then it should also generate Javadocs in order to aid with development. + // Uncomment this line to generate them. + // withJavadocJar() } +// If you plan to use a different file for the license, don't forget to change the file name here! jar { from("LICENSE") { - rename { "${it}_${project.archivesBaseName}"} + rename { "${it}_${archivesBaseName}" } } } -shadowJar { - manifest { - attributes 'Main-Class': 'com.example.ApplicationKt' - } -} - -// configure the maven publication +// Configure the maven publication publishing { publications { mavenJava(MavenPublication) { @@ -102,21 +105,12 @@ import com.modrinth.minotaur.dependencies.ModDependency modrinth { token = System.getenv("MODRINTH_TOKEN") // This is the default. Remember to have the MODRINTH_TOKEN environment variable set or else this will fail, or set it to whatever you want - just make sure it stays private! projectId = "oTa1qz6R" - versionNumber = project.mod_version // You don't need to set this manually. Will fail if Modrinth has this version already + versionNumber = version // You don't need to set this manually. Will fail if Modrinth has this version already versionType = "release" // This is the default uploadFile = remapJar // With Fabric Loom or Architectury Loom, this MUST be set to `remapJar` instead of `jar`! - gameVersions = [project.minecraft_version] // Must be an array, even with only one version + gameVersions = [libs.versions.minecraft] // Must be an array, even with only one version loaders = ["fabric"] // Must also be an array - no need to specify this if you're using Fabric Loom or ForgeGradle dependencies = [ new ModDependency("mOgUt4GM", "required") ] } - -//curseforge { -// apiKey = System.getenv("CURSEFORGE_TOKEN") // This should really be in a gradle.properties file -// project { -// id = '602252' -// changelog = 'Added content and fixed bugs' // A file can also be set using: changelog = file('changelog.txt') -// releaseType = 'release' -// } -//} diff --git a/gradle.properties b/gradle.properties index 0cc1696..ff0a6b9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,16 +1,10 @@ -# Done to increase the memory available to gradle. -org.gradle.jvmargs=-Xmx1G - -# Fabric Properties - # check these on https://fabricmc.net/develop - minecraft_version=1.18.2 - yarn_mappings=1.18.2+build.3 - loader_version=0.13.3 +# Gradle Properties +org.gradle.jvmargs = -Xmx1G +org.gradle.parallel = true # Mod Properties - mod_version = 1.4.4 - maven_group = alujjdnd.ngrok.lan - archives_base_name = ngrok-lan-expose-mod +version = 1.4.5 +maven_group = alujjdnd.ngrok.lan +archives_base_name = ngrok-lan-expose-mod -# Dependencies - fabric_version=0.51.0+1.18.2 +# Dependencies are managed at gradle/libs.versions.toml diff --git a/gradle/gradle b/gradle/gradle deleted file mode 100644 index 5fe3082..0000000 --- a/gradle/gradle +++ /dev/null @@ -1,234 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/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/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -APP_HOME=$( cd "${APP_HOME:-./}.." && pwd -P ) || exit - -APP_NAME="Gradle" -APP_BASE_NAME=${0##*/} - -# 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 - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/lib/gradle-launcher-7.4.1.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - 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. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - -# 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" \ - -classpath "$CLASSPATH" \ - org.gradle.launcher.GradleMain \ - "$@" - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..a9687a5 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,22 @@ +[versions] +# The latest versions are available at https://lambdaurora.dev/tools/import_quilt.html +minecraft = "1.19" +quilt_mappings = "1.19+build.1" +quilt_loader = "0.17.0" + +quilted_fabric_api = "2.0.0-beta.5+0.57.0-1.19" + +[libraries] +minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" } +quilt_mappings = { module = "org.quiltmc:quilt-mappings", version.ref = "quilt_mappings" } +quilt_loader = { module = "org.quiltmc:quilt-loader", version.ref = "quilt_loader" } + +quilted_fabric_api = { module = "org.quiltmc.quilted-fabric-api:quilted-fabric-api", version.ref = "quilted_fabric_api" } +quilted_fabric_api_deprecated = { module = "org.quiltmc.quilted-fabric-api:quilted-fabric-api-deprecated", version.ref = "quilted_fabric_api" } + +# If you have multiple similar dependencies, you can declare a dependency bundle and reference it on the build script with "libs.bundles.example". +[bundles] +quilted_fabric_api = ["quilted_fabric_api", "quilted_fabric_api_deprecated"] + +[plugins] +quilt_loom = { id = "org.quiltmc.loom", version = "0.12.+" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180f2ae8848c63b8b4dea2cb829da983f2fa..41d9927a4d4fb3f96a785543079b8df6723c946b 100644 GIT binary patch delta 8958 zcmY+KWl$VIlZIh&f(Hri?gR<$?iyT!TL`X;1^2~W7YVSq1qtqM!JWlDxLm%}UESUM zndj}Uny%^UnjhVhFb!8V3s(a#fIy>`VW15{5nuy;_V&a5O#0S&!a4dSkUMz_VHu3S zGA@p9Q$T|Sj}tYGWdjH;Mpp8m&yu&YURcrt{K;R|kM~(*{v%QwrBJIUF+K1kX5ZmF zty3i{d`y0;DgE+de>vN@yYqFPe1Ud{!&G*Q?iUc^V=|H%4~2|N zW+DM)W!`b&V2mQ0Y4u_)uB=P@-2`v|Wm{>CxER1P^ z>c}ZPZ)xxdOCDu59{X^~2id7+6l6x)U}C4Em?H~F`uOxS1?}xMxTV|5@}PlN%Cg$( zwY6c}r60=z5ZA1L zTMe;84rLtYvcm?M(H~ZqU;6F7Evo{P7!LGcdwO|qf1w+)MsnvK5^c@Uzj<{ zUoej1>95tuSvDJ|5K6k%&UF*uE6kBn47QJw^yE&#G;u^Z9oYWrK(+oL97hBsUMc_^ z;-lmxebwlB`Er_kXp2$`&o+rPJAN<`WX3ws2K{q@qUp}XTfV{t%KrsZ5vM!Q#4{V& zq>iO$MCiLq#%wXj%`W$_%FRg_WR*quv65TdHhdpV&jlq<=K^K`&!Kl5mA6p4n~p3u zWE{20^hYpn1M}}VmSHBXl1*-)2MP=0_k)EPr#>EoZukiXFD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oyaSKJ~T{Gx}7ONLA)D5k(%%`WswrDyzX*rn}i}}TB4^y#@mAwPzoC)`?rYv zHgx|trUN#mu*VzUV~8TnJM2Qh*ZM5B{x&y>5An`(M7=Z*Q>TdiH@j*2=moNuOtvpz z+G`@~-`%~+AgPKgke@XiRPgndh@bp*-HRsh;HTtz@-y_uhb%7ylVOTqG0#u?Vn5c5 zEp*XRo|8hcgG^$#{$O9CJ&NE;TrfRpSnLmes&MO{m=N%zc`}gb!eQ7odl$oy1%PI} z#AIxx%oRVy&{O~9xnK4$EY>(eQj}!HKIV$Fz*H=-=Kn)N0D6u`(;iO|VraI4fu_W` z;b5{7;Lyx4za}DU#+U7}=H0dAS#YJJ&g2!P@Htu-AL&w=-)*%P9h2{wR|@?Ff9~)b z^+e_3Hetq7W%ls{!?<6&Y$Z;NNB41pvrv)|MET6AZXFXJeFqbFW5@i5WGzl?bP+~? z*&_puH;wKv2)9T_d+P`bLvJFqX#j&xa*-;0nGBbQf0DC>o~=J_Wmtf*2SZQr?{i~X z9-IbRH8{iy?<0v9Ir1?$66+igy|yDQ5J~A9sFX@Pe<*kCY8+MwH?I z`P}zfQ6l^AO8ehZ=l^ZR;R%uu4;BK*=?W9t|0{+-at(MQZ(CtG=EJFNaFMlKCMXu30(gJUqj5+ z`GM|!keqcj;FKTa_qq;{*dHRXAq157hlB@kL#8%yAm2AgfU|*rDKX@FLlp=HL8ddv zAWLCHe@DcDeB2}fl7#=0+#<05c3=VqM*O3bkr@9X4nO|)q0hU;Gye{L8ZN*NH8Id@mP-u;Fmb8YuorjLrW&ndip8CN%_qp982r w1WEnz9^$&s1hkp_3#lPJQ~!HI7WYYjA7>z!`?f%npAh2%rB@vD|Lau$2O)#1n*aa+ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb87..aa991fc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 index c53aefa..1b6c787 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -32,10 +32,10 @@ # Busybox and similar reduced shells will NOT work, because this script # requires all of these POSIX shell features: # * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». # # Important for patching: # diff --git a/settings.gradle b/settings.gradle index b02216b..d969e34 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,10 +1,14 @@ pluginManagement { - repositories { - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' - } - mavenCentral() - gradlePluginPortal() - } + repositories { + maven { + name = 'Quilt' + url = 'https://maven.quiltmc.org/repository/release' + } + // Currently needed for Intermediary and other temporary dependencies + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() + } } diff --git a/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java b/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java index bbcde24..a25f955 100644 --- a/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java +++ b/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java @@ -5,8 +5,9 @@ import alujjdnd.ngrok.lan.command.LanWhitelistCommand; import alujjdnd.ngrok.lan.command.ReloadJsonListsCommand; import com.github.alexdlaird.ngrok.NgrokClient; -import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import org.quiltmc.loader.api.ModContainer; +import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,7 +32,7 @@ public class NgrokLan implements ModInitializer { public static boolean serverOpen = false; @Override - public void onInitialize() { + public void onInitialize(ModContainer mod) { // This code runs as soon as Minecraft is in a mod-load-ready state. // However, some things (like resources) may still be uninitialized. // Proceed with mild caution. @@ -40,7 +41,7 @@ public void onInitialize() { AutoConfig.register(NLanConfig.class, JanksonConfigSerializer::new); //register commands - CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, dedicated) -> { LanOpCommand.register(dispatcher); LanDeopCommand.register(dispatcher); diff --git a/src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java b/src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java index f592d44..be0d934 100644 --- a/src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java +++ b/src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java @@ -5,10 +5,12 @@ import alujjdnd.ngrok.lan.command.LanOpCommand; import alujjdnd.ngrok.lan.command.LanWhitelistCommand; import alujjdnd.ngrok.lan.command.ReloadJsonListsCommand; -import net.fabricmc.api.DedicatedServerModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.minecraft.server.dedicated.DedicatedServer; +import org.quiltmc.loader.api.ModContainer; +import org.quiltmc.qsl.base.api.entrypoint.server.DedicatedServerModInitializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,12 +22,12 @@ public class NgrokServerInitialiser implements DedicatedServerModInitializer @Override // Initialize the differents parts of the mod when lauched on server - public void onInitializeServer() + public void onInitializeServer(ModContainer mod) { LOGGER.info("World is Open to LAN with Ngrok LAN"); //register commands - CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, dedicated) -> { LanOpCommand.register(dispatcher); LanDeopCommand.register(dispatcher); diff --git a/src/main/java/alujjdnd/ngrok/lan/command/LanDeopCommand.java b/src/main/java/alujjdnd/ngrok/lan/command/LanDeopCommand.java index 1310123..dcb17b0 100644 --- a/src/main/java/alujjdnd/ngrok/lan/command/LanDeopCommand.java +++ b/src/main/java/alujjdnd/ngrok/lan/command/LanDeopCommand.java @@ -10,12 +10,12 @@ import net.minecraft.server.PlayerManager; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.TranslatableText; +import net.minecraft.text.Text; import java.util.Collection; public class LanDeopCommand { - private static final SimpleCommandExceptionType ALREADY_DEOPPED_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.deop.failed")); + private static final SimpleCommandExceptionType ALREADY_DEOPPED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.deop.failed")); public LanDeopCommand() { } @@ -38,7 +38,7 @@ private static int deop(ServerCommandSource source, Collection targ if (playerManager.isOperator(gameProfile)) { playerManager.removeFromOperators(gameProfile); ++i; - source.sendFeedback(new TranslatableText("commands.deop.success", targets.iterator().next().getName()), true); + source.sendFeedback(Text.translatable("commands.deop.success", targets.iterator().next().getName()), true); } } diff --git a/src/main/java/alujjdnd/ngrok/lan/command/LanOpCommand.java b/src/main/java/alujjdnd/ngrok/lan/command/LanOpCommand.java index aab6d92..4d743f3 100644 --- a/src/main/java/alujjdnd/ngrok/lan/command/LanOpCommand.java +++ b/src/main/java/alujjdnd/ngrok/lan/command/LanOpCommand.java @@ -10,12 +10,12 @@ import net.minecraft.server.PlayerManager; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.TranslatableText; +import net.minecraft.text.Text; import java.util.Collection; public class LanOpCommand { - private static final SimpleCommandExceptionType ALREADY_OPPED_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.op.failed")); + private static final SimpleCommandExceptionType ALREADY_OPPED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.op.failed")); public LanOpCommand() { } @@ -43,7 +43,7 @@ private static int op(ServerCommandSource source, Collection target if (!playerManager.isOperator(gameProfile)) { playerManager.addToOperators(gameProfile); ++i; - source.sendFeedback(new TranslatableText("commands.op.success", targets.iterator().next().getName()), true); + source.sendFeedback(Text.translatable("commands.op.success", targets.iterator().next().getName()), true); } } diff --git a/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java b/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java index 3e20064..9b8de63 100644 --- a/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java +++ b/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java @@ -12,16 +12,16 @@ import net.minecraft.server.WhitelistEntry; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.Text; import net.minecraft.text.Texts; -import net.minecraft.text.TranslatableText; import java.util.Collection; public class LanWhitelistCommand { - private static final SimpleCommandExceptionType ALREADY_ON_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.whitelist.alreadyOn")); - private static final SimpleCommandExceptionType ALREADY_OFF_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.whitelist.alreadyOff")); - private static final SimpleCommandExceptionType ADD_FAILED_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.whitelist.add.failed")); - private static final SimpleCommandExceptionType REMOVE_FAILED_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.whitelist.remove.failed")); + private static final SimpleCommandExceptionType ALREADY_ON_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.alreadyOn")); + private static final SimpleCommandExceptionType ALREADY_OFF_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.alreadyOff")); + private static final SimpleCommandExceptionType ADD_FAILED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.add.failed")); + private static final SimpleCommandExceptionType REMOVE_FAILED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.remove.failed")); public LanWhitelistCommand() { } @@ -55,7 +55,7 @@ public static void register(CommandDispatcher dispatcher) { private static int executeReload(ServerCommandSource source) { source.getServer().getPlayerManager().reloadWhitelist(); - source.sendFeedback(new TranslatableText("commands.whitelist.reloaded"), true); + source.sendFeedback(Text.translatable("commands.whitelist.reloaded"), true); source.getServer().kickNonWhitelistedPlayers(source); return 1; } @@ -68,7 +68,7 @@ private static int executeAdd(ServerCommandSource source, Collection serverCommandSou throw LOAD_JSON_EXCEPTION.create(); } else{ - MinecraftClient.getInstance().inGameHud.getChatHud().addMessage( new TranslatableText("text.info.ngroklan.reload.success")); + MinecraftClient.getInstance().inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.reload.success")); } return 1; diff --git a/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java b/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java index b489f9a..afd9c30 100644 --- a/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java +++ b/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java @@ -45,7 +45,7 @@ protected OpenToLanScreenMixin(Text title) { private void initWidgets(CallbackInfo info) { if (config.enabledCheckBox) { //if mod enabled in mod menu - this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height - 58, 150, 20, new TranslatableText("text.UI.ngroklan.LanButton"), (button) -> { + this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height - 58, 150, 20, Text.translatable("text.UI.ngroklan.LanButton"), (button) -> { int localPort = NetworkUtils.findLocalPort(); // part of the minecraft Networkutils class, finds an available local port (this was from the openToLan class) this.client.setScreen(null); // Removed all elements from the screen (this closes all menu windows) switch (config.regionSelect) { @@ -70,14 +70,14 @@ private void ngrokInit(int port, Region region) { { if (config.authToken.equals("AuthToken")) { // Check if authToken field has actually been changed, if not, print this text in chat - mc.inGameHud.getChatHud().addMessage(new TranslatableText("text.error.ngroklan.AuthTokenError")); - mc.inGameHud.getChatHud().addMessage(new TranslatableText("text.error.ngroklan.AuthTokenError").formatted(Formatting.RED)); + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.error.ngroklan.AuthTokenError")); + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.error.ngroklan.AuthTokenError").formatted(Formatting.RED)); //\u00a7c } else { try { NgrokLan.LOGGER.info("Launched Lan!"); - mc.inGameHud.getChatHud().addMessage(new TranslatableText("text.info.ngroklan.startMessage").formatted(Formatting.YELLOW)); + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.startMessage").formatted(Formatting.YELLOW)); // Java-ngrok wrapper code, to initiate the tunnel, with the authoken, region @@ -102,22 +102,22 @@ private void ngrokInit(int port, Region region) { var ngrok_url = tunnel.getPublicUrl().substring(6); // Print in chat the status of the tunnel, and the details copied to the clipboard - mc.inGameHud.getChatHud().addMessage(new TranslatableText("text.info.ngroklan.success").formatted(Formatting.GREEN)); + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.success").formatted(Formatting.GREEN)); - Text copyText = Texts.bracketed((new LiteralText(ngrok_url)).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, ngrok_url)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableText("chat.copy.click"))).withInsertion(ngrok_url))); - mc.inGameHud.getChatHud().addMessage( new TranslatableText("text.info.ngroklan.ip", copyText)); + Text copyText = Texts.bracketed((Text.literal(ngrok_url)).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, ngrok_url)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("chat.copy.click"))).withInsertion(ngrok_url))); + mc.inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.ip", copyText)); mc.keyboard.setClipboard(ngrok_url); // This starts the LAN server and greys out the open to lan button - TranslatableText text; + Text text; if (this.client.getServer().openToLan(this.gameMode, this.allowCommands, port)) { mc.getServer().setOnlineMode(config.onlineCheckBox); - text = new TranslatableText("commands.publish.started", port); + text = Text.translatable("commands.publish.started", port); NgrokLan.serverOpen = true; //TODO: make sure this works, I make a new thread that reads the json files to update the oplist and whitelist in the playermanager @@ -127,12 +127,12 @@ private void ngrokInit(int port, Region region) { boolean result = loadJson(); if(!result){ - Text commandText = Texts.bracketed((new TranslatableText("text.info.ngroklan.reload.prompt")).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reloadngroklanlists")).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableText("text.info.ngroklan.reload.prompt"))))); - mc.inGameHud.getChatHud().addMessage( new TranslatableText("text.info.ngroklan.reload.message")); + Text commandText = Texts.bracketed((Text.translatable("text.info.ngroklan.reload.prompt")).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reloadngroklanlists")).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("text.info.ngroklan.reload.prompt"))))); + mc.inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.reload.message")); mc.inGameHud.getChatHud().addMessage(commandText); } else{ - mc.inGameHud.getChatHud().addMessage( new TranslatableText("text.info.ngroklan.reload.success")); + mc.inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.reload.success")); } }); @@ -140,7 +140,7 @@ private void ngrokInit(int port, Region region) { thread2.start(); } else { - text = new TranslatableText("commands.publish.failed"); + text = Text.translatable("commands.publish.failed"); NgrokLan.serverOpen = false; } this.client.inGameHud.getChatHud().addMessage(text); @@ -148,8 +148,8 @@ private void ngrokInit(int port, Region region) { } catch (Exception error) { error.printStackTrace(); - mc.inGameHud.getChatHud().addMessage(new LiteralText(error.getMessage())); - mc.inGameHud.getChatHud().addMessage(new TranslatableText("text.error.ngroklan.fail").formatted(Formatting.RED)); + mc.inGameHud.getChatHud().addMessage(Text.literal(error.getMessage())); + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.error.ngroklan.fail").formatted(Formatting.RED)); //ngrokInitiated = false; throw new RuntimeException("Ngrok Service Failed to Start" + error.getMessage()); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json deleted file mode 100644 index a85fd71..0000000 --- a/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "schemaVersion": 1, - "id": "ngroklan", - "version": "${version}", - - "name": "Ngrok LAN", - "description": "Exposes your local LAN server to the internet with Ngrok.", - "authors": [ - "Peter Zhang (alujjdnd)", - "Flooflez" - ], - "contact": { - "homepage": "https://github.com/Alujjdnd/Ngrok-LAN", - "sources": "https://github.com/Alujjdnd/Ngrok-LAN", - "issues": "https://github.com/Alujjdnd/Ngrok-LAN/issues" - }, - - "license": "MIT", - "icon": "assets/ngroklan/icon.png", - - "environment": "*", - "entrypoints": { - "main": [ - "alujjdnd.ngrok.lan.NgrokLan" - ], - "server": [ - "alujjdnd.ngrok.lan.NgrokServerInitialiser" - ], - "modmenu": [ - "alujjdnd.ngrok.lan.config.ModMenuIntegration" - ] - }, - - "mixins": [ - "ngroklan.mixins.json" - ], - - "depends": { - "fabricloader": ">=0.13.3", - "fabric": "*", - "minecraft": "1.18.x", - "java": ">=17" - }, - "suggests": { - "another-mod": "*" - } -} diff --git a/src/main/resources/quilt.mod.json b/src/main/resources/quilt.mod.json new file mode 100644 index 0000000..c6558fc --- /dev/null +++ b/src/main/resources/quilt.mod.json @@ -0,0 +1,51 @@ +{ + "schema_version": 1, + "quilt_loader": { + "group": "alujjdnd.ngrok.lan", + "id": "ngroklan", + "version": "${version}", + "metadata": { + "name": "Ngrok LAN", + "description": "Exposes your local LAN server to the internet with Ngrok.", + "authors": [ + "Peter Zhang (alujjdnd)", + "Flooflez" + ], + "contact": { + "homepage": "https://github.com/Alujjdnd/Ngrok-LAN", + "sources": "https://github.com/Alujjdnd/Ngrok-LAN", + "issues": "https://github.com/Alujjdnd/Ngrok-LAN/issues" + }, + + "license": "MIT", + "icon": "assets/ngroklan/icon.png" + }, + "intermediate_mappings": "net.fabricmc:intermediary", + "entrypoints": { + "init": [ + "alujjdnd.ngrok.lan.NgrokLan" + ], + "server": [ + "alujjdnd.ngrok.lan.NgrokServerInitialiser" + ], + "modmenu": [ + "alujjdnd.ngrok.lan.config.ModMenuIntegration" + ] + }, + "depends": [ + { + "id": "quilt_loader", + "versions": ">=0.17.0-" + }, + { + "id": "quilted_fabric_api", + "versions": ">=2.0.0-" + }, + { + "id": "minecraft", + "versions": ">=1.19" + } + ] + }, + "mixin": "ngroklan.mixins.json" +} From eedd6a8ffd002eb2e64c9f702bcfa67edc77c5dc Mon Sep 17 00:00:00 2001 From: Mikolaj Date: Mon, 11 Jul 2022 21:33:08 +0200 Subject: [PATCH 3/9] Update buildscripts and dependencies --- build.gradle | 27 ++++++++++++++------------- gradle/libs.versions.toml | 7 ++++++- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 396a9d8..e1fe95d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,8 @@ plugins { - id 'maven-publish' alias(libs.plugins.quilt.loom) + id 'maven-publish' id 'com.github.johnrengelman.shadow' version '7.1.2' + id 'java' id "com.modrinth.minotaur" version "2.+" } @@ -33,20 +34,15 @@ dependencies { // QSL is not a complete API; You will need Quilted Fabric API to fill in the gaps. // Quilted Fabric API will automatically pull in the correct QSL version. modImplementation libs.quilted.fabric.api - // modImplementation libs.bundles.quilted.fabric.api // If you wish to use Fabric API's deprecated modules, you can replace the above line with this one - - //Java-Ngrok, a wrapper for the Ngrok service by providing a handy Java API to call it. - modImplementation(include("com.github.alexdlaird:java-ngrok:1.5.6")) - modImplementation(include("org.yaml:snakeyaml:1.30")) - - modApi("me.shedaniel.cloth:cloth-config-fabric:7.0.72") { + // Java-Ngrok, a wrapper for the Ngrok service by providing a handy Java API to call it. + modImplementation(include("com.github.alexdlaird:java-ngrok:${libs.versions.java.ngrok.get()}")) + // Cloth config + modApi("me.shedaniel.cloth:cloth-config-fabric:${libs.versions.cloth.config.get()}") { exclude(group: "net.fabricmc.fabric-api") } - - modImplementation(include("blue.endless:jankson:1.2.1")) - - modImplementation(include("com.terraformersmc:modmenu:4.0.0")) + // Mod menu + modImplementation(include("com.terraformersmc:modmenu:${libs.versions.modmenu.get()}")) } processResources { @@ -59,7 +55,6 @@ processResources { tasks.withType(JavaCompile).configureEach { it.options.encoding = "UTF-8" - // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. it.options.release = 17 } @@ -84,6 +79,12 @@ jar { } } +shadowJar { + manifest { + attributes 'Main-Class': 'com.example.ApplicationKt' + } +} + // Configure the maven publication publishing { publications { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a9687a5..5352d4a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,10 +2,15 @@ # The latest versions are available at https://lambdaurora.dev/tools/import_quilt.html minecraft = "1.19" quilt_mappings = "1.19+build.1" -quilt_loader = "0.17.0" +quilt_loader = "0.17.1-beta.6" quilted_fabric_api = "2.0.0-beta.5+0.57.0-1.19" +# Dependencies +java_ngrok = "1.5.6" +cloth_config = "7.0.72" +modmenu = "4.0.0" + [libraries] minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" } quilt_mappings = { module = "org.quiltmc:quilt-mappings", version.ref = "quilt_mappings" } From 293ad1a251086d323b2dff9f2d9b9fff09774b08 Mon Sep 17 00:00:00 2001 From: Mikolaj Date: Mon, 11 Jul 2022 22:25:34 +0200 Subject: [PATCH 4/9] Small refactors and updates --- .../java/alujjdnd/ngrok/lan/NgrokLan.java | 23 +- .../ngrok/lan/NgrokLanServerInitializer.java | 26 ++ .../ngrok/lan/NgrokServerInitialiser.java | 39 --- .../ngrok/lan/command/LanDeopCommand.java | 24 +- .../ngrok/lan/command/LanOpCommand.java | 33 +- .../lan/command/LanWhitelistCommand.java | 254 +++++++------- .../lan/command/ReloadJsonListsCommand.java | 77 ++--- .../ngrok/lan/config/ModMenuIntegration.java | 3 +- .../ngrok/lan/mixin/CloseTunnelMixin.java | 5 +- .../ngrok/lan/mixin/OpenToLanScreenMixin.java | 318 ++++++++---------- .../ngrok/lan/mixin/PlayerManagerMixin.java | 11 - .../ngrok/lan/mixin/SpawnProtectionMixin.java | 17 +- .../ngrok/lan/mixin/WindowTitleMixin.java | 8 +- .../resources/assets/ngroklan/lang/en_us.json | 4 +- src/main/resources/ngroklan.mixins.json | 1 + src/main/resources/quilt.mod.json | 2 +- 16 files changed, 380 insertions(+), 465 deletions(-) create mode 100644 src/main/java/alujjdnd/ngrok/lan/NgrokLanServerInitializer.java delete mode 100644 src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java diff --git a/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java b/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java index a25f955..b3d8029 100644 --- a/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java +++ b/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java @@ -5,50 +5,33 @@ import alujjdnd.ngrok.lan.command.LanWhitelistCommand; import alujjdnd.ngrok.lan.command.ReloadJsonListsCommand; import com.github.alexdlaird.ngrok.NgrokClient; -import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import org.quiltmc.loader.api.ModContainer; import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; +import org.quiltmc.qsl.command.api.CommandRegistrationCallback; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import alujjdnd.ngrok.lan.config.NLanConfig; import me.shedaniel.autoconfig.AutoConfig; import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer; - - - public class NgrokLan implements ModInitializer { - // This logger is used to write text to the console and the log file. - // It is considered best practice to use your mod id as the logger's name. - // That way, it's clear which mod wrote info, warnings, and errors. - public static final String MODID = "ngroklan"; - public static final Logger LOGGER = LoggerFactory.getLogger(MODID); public static NgrokClient ngrokClient; - public static boolean serverOpen = false; @Override public void onInitialize(ModContainer mod) { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - LOGGER.info("Minecraft started with Ngrok LAN"); AutoConfig.register(NLanConfig.class, JanksonConfigSerializer::new); - //register commands - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, dedicated) -> - { + //Register commands + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, dedicated) -> { LanOpCommand.register(dispatcher); LanDeopCommand.register(dispatcher); LanWhitelistCommand.register(dispatcher); ReloadJsonListsCommand.register(dispatcher); }); } - - } diff --git a/src/main/java/alujjdnd/ngrok/lan/NgrokLanServerInitializer.java b/src/main/java/alujjdnd/ngrok/lan/NgrokLanServerInitializer.java new file mode 100644 index 0000000..9be207a --- /dev/null +++ b/src/main/java/alujjdnd/ngrok/lan/NgrokLanServerInitializer.java @@ -0,0 +1,26 @@ +package alujjdnd.ngrok.lan; + +import alujjdnd.ngrok.lan.command.LanDeopCommand; +import alujjdnd.ngrok.lan.command.LanOpCommand; +import alujjdnd.ngrok.lan.command.LanWhitelistCommand; +import alujjdnd.ngrok.lan.command.ReloadJsonListsCommand; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import org.quiltmc.loader.api.ModContainer; +import org.quiltmc.qsl.base.api.entrypoint.server.DedicatedServerModInitializer; +import org.quiltmc.qsl.command.api.CommandRegistrationCallback; + +@Environment(EnvType.SERVER) +public class NgrokLanServerInitializer implements DedicatedServerModInitializer { + @Override + // Initialize the different parts of the mod when launched on server + public void onInitializeServer(ModContainer mod) { + NgrokLan.LOGGER.info("World is Open to LAN with Ngrok LAN"); + + // Initialize the different parts of the mod when launched on server + CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> LanOpCommand.register(dispatcher))); + CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> LanDeopCommand.register(dispatcher))); + CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> LanWhitelistCommand.register(dispatcher))); + CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> ReloadJsonListsCommand.register(dispatcher))); + } +} diff --git a/src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java b/src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java deleted file mode 100644 index be0d934..0000000 --- a/src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java +++ /dev/null @@ -1,39 +0,0 @@ -package alujjdnd.ngrok.lan; - - -import alujjdnd.ngrok.lan.command.LanDeopCommand; -import alujjdnd.ngrok.lan.command.LanOpCommand; -import alujjdnd.ngrok.lan.command.LanWhitelistCommand; -import alujjdnd.ngrok.lan.command.ReloadJsonListsCommand; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; -import net.minecraft.server.dedicated.DedicatedServer; -import org.quiltmc.loader.api.ModContainer; -import org.quiltmc.qsl.base.api.entrypoint.server.DedicatedServerModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Environment(EnvType.SERVER) -public class NgrokServerInitialiser implements DedicatedServerModInitializer -{ - - public static final Logger LOGGER = LoggerFactory.getLogger(NgrokLan.MODID); - - @Override - // Initialize the differents parts of the mod when lauched on server - public void onInitializeServer(ModContainer mod) - { - LOGGER.info("World is Open to LAN with Ngrok LAN"); - - //register commands - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, dedicated) -> - { - LanOpCommand.register(dispatcher); - LanDeopCommand.register(dispatcher); - LanWhitelistCommand.register(dispatcher); - ReloadJsonListsCommand.register(dispatcher); - }); - } - -} diff --git a/src/main/java/alujjdnd/ngrok/lan/command/LanDeopCommand.java b/src/main/java/alujjdnd/ngrok/lan/command/LanDeopCommand.java index dcb17b0..3e524d6 100644 --- a/src/main/java/alujjdnd/ngrok/lan/command/LanDeopCommand.java +++ b/src/main/java/alujjdnd/ngrok/lan/command/LanDeopCommand.java @@ -2,7 +2,6 @@ import com.mojang.authlib.GameProfile; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.minecraft.command.CommandSource; @@ -17,17 +16,14 @@ public class LanDeopCommand { private static final SimpleCommandExceptionType ALREADY_DEOPPED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.deop.failed")); - public LanDeopCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder) CommandManager.literal("deop").requires((source) -> { - return source.hasPermissionLevel(3); - })).then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { - return CommandSource.suggestMatching((context.getSource()).getServer().getPlayerManager().getOpNames(), builder); - }).executes((context) -> { - return deop(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))); + public static void register(CommandDispatcher dispatcher) { + dispatcher.register((CommandManager.literal("deop").requires((source) -> + source.hasPermissionLevel(3) + )).then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> + CommandSource.suggestMatching((context.getSource()).getServer().getPlayerManager().getOpNames(), builder) + ).executes((context) -> + deop(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")) + ))); } private static int deop(ServerCommandSource source, Collection targets) throws CommandSyntaxException { @@ -42,9 +38,9 @@ private static int deop(ServerCommandSource source, Collection targ } } - if (i == 0) { + if (i == 0) throw ALREADY_DEOPPED_EXCEPTION.create(); - } else { + else { source.getServer().kickNonWhitelistedPlayers(source); return i; } diff --git a/src/main/java/alujjdnd/ngrok/lan/command/LanOpCommand.java b/src/main/java/alujjdnd/ngrok/lan/command/LanOpCommand.java index 4d743f3..559572b 100644 --- a/src/main/java/alujjdnd/ngrok/lan/command/LanOpCommand.java +++ b/src/main/java/alujjdnd/ngrok/lan/command/LanOpCommand.java @@ -2,7 +2,6 @@ import com.mojang.authlib.GameProfile; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.minecraft.command.CommandSource; @@ -17,22 +16,19 @@ public class LanOpCommand { private static final SimpleCommandExceptionType ALREADY_OPPED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.op.failed")); - public LanOpCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder) CommandManager.literal("op").requires((source) -> { - return source.hasPermissionLevel(3); - })).then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { + public static void register(CommandDispatcher dispatcher) { + dispatcher.register((CommandManager.literal("op").requires((source) -> + source.hasPermissionLevel(3) + )).then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { PlayerManager playerManager = (context.getSource()).getServer().getPlayerManager(); - return CommandSource.suggestMatching(playerManager.getPlayerList().stream().filter((player) -> { - return !playerManager.isOperator(player.getGameProfile()); - }).map((player) -> { - return player.getGameProfile().getName(); - }), builder); - }).executes((context) -> { - return op(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))); + return CommandSource.suggestMatching(playerManager.getPlayerList().stream().filter((player) -> + !playerManager.isOperator(player.getGameProfile()) + ).map((player) -> + player.getGameProfile().getName() + ), builder); + }).executes((context) -> + op(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")) + ))); } private static int op(ServerCommandSource source, Collection targets) throws CommandSyntaxException { @@ -47,10 +43,9 @@ private static int op(ServerCommandSource source, Collection target } } - if (i == 0) { + if (i == 0) throw ALREADY_OPPED_EXCEPTION.create(); - } else { + else return i; - } } } diff --git a/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java b/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java index 9b8de63..9fecf3e 100644 --- a/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java +++ b/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java @@ -1,8 +1,8 @@ package alujjdnd.ngrok.lan.command; +import com.google.common.collect.Lists; import com.mojang.authlib.GameProfile; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.minecraft.command.CommandSource; @@ -12,126 +12,146 @@ import net.minecraft.server.WhitelistEntry; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import net.minecraft.text.Texts; import java.util.Collection; +import java.util.List; public class LanWhitelistCommand { - private static final SimpleCommandExceptionType ALREADY_ON_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.alreadyOn")); - private static final SimpleCommandExceptionType ALREADY_OFF_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.alreadyOff")); - private static final SimpleCommandExceptionType ADD_FAILED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.add.failed")); - private static final SimpleCommandExceptionType REMOVE_FAILED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.remove.failed")); - - public LanWhitelistCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) CommandManager.literal("whitelist").requires((source) -> { - return source.hasPermissionLevel(3); - })).then(CommandManager.literal("on").executes((context) -> { - return executeOn(context.getSource()); - })).then(CommandManager.literal("off").executes((context) -> { - return executeOff(context.getSource()); - })).then(CommandManager.literal("list").executes((context) -> { - return executeList(context.getSource()); - })).then(CommandManager.literal("add").then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { - PlayerManager playerManager = context.getSource().getServer().getPlayerManager(); - return CommandSource.suggestMatching(playerManager.getPlayerList().stream().filter((player) -> { - return !playerManager.getWhitelist().isAllowed(player.getGameProfile()); - }).map((player) -> { - return player.getGameProfile().getName(); - }), builder); - }).executes((context) -> { - return executeAdd(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))).then(CommandManager.literal("remove").then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { - return CommandSource.suggestMatching(context.getSource().getServer().getPlayerManager().getWhitelistedNames(), builder); - }).executes((context) -> { - return executeRemove(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))).then(CommandManager.literal("reload").executes((context) -> { - return executeReload(context.getSource()); - }))); - } - - private static int executeReload(ServerCommandSource source) { - source.getServer().getPlayerManager().reloadWhitelist(); - source.sendFeedback(Text.translatable("commands.whitelist.reloaded"), true); - source.getServer().kickNonWhitelistedPlayers(source); - return 1; - } - - private static int executeAdd(ServerCommandSource source, Collection targets) throws CommandSyntaxException { - Whitelist whitelist = source.getServer().getPlayerManager().getWhitelist(); - int i = 0; - - for (GameProfile gameProfile : targets) { - if (!whitelist.isAllowed(gameProfile)) { - WhitelistEntry whitelistEntry = new WhitelistEntry(gameProfile); - whitelist.add(whitelistEntry); - source.sendFeedback(Text.translatable("commands.whitelist.add.success", Texts.toText(gameProfile)), true); - ++i; - } - } - - if (i == 0) { - throw ADD_FAILED_EXCEPTION.create(); - } else { - return i; - } - } - - private static int executeRemove(ServerCommandSource source, Collection targets) throws CommandSyntaxException { - Whitelist whitelist = source.getServer().getPlayerManager().getWhitelist(); - int i = 0; - - for (GameProfile gameProfile : targets) { - if (whitelist.isAllowed(gameProfile)) { - WhitelistEntry whitelistEntry = new WhitelistEntry(gameProfile); - whitelist.remove(whitelistEntry); - source.sendFeedback(Text.translatable("commands.whitelist.remove.success", Texts.toText(gameProfile)), true); - ++i; - } - } - - if (i == 0) { - throw REMOVE_FAILED_EXCEPTION.create(); - } else { - source.getServer().kickNonWhitelistedPlayers(source); - return i; - } - } - - private static int executeOn(ServerCommandSource source) throws CommandSyntaxException { - PlayerManager playerManager = source.getServer().getPlayerManager(); - if (playerManager.isWhitelistEnabled()) { - throw ALREADY_ON_EXCEPTION.create(); - } else { - playerManager.setWhitelistEnabled(true); - source.sendFeedback(Text.translatable("commands.whitelist.enabled"), true); - source.getServer().kickNonWhitelistedPlayers(source); - return 1; - } - } - - private static int executeOff(ServerCommandSource source) throws CommandSyntaxException { - PlayerManager playerManager = source.getServer().getPlayerManager(); - if (!playerManager.isWhitelistEnabled()) { - throw ALREADY_OFF_EXCEPTION.create(); - } else { - playerManager.setWhitelistEnabled(false); - source.sendFeedback(Text.translatable("commands.whitelist.disabled"), true); - return 1; - } - } - - private static int executeList(ServerCommandSource source) { - String[] strings = source.getServer().getPlayerManager().getWhitelistedNames(); - if (strings.length == 0) { - source.sendFeedback(Text.translatable("commands.whitelist.none"), false); - } else { - source.sendFeedback(Text.translatable("commands.whitelist.list", strings.length, String.join(", ", strings)), false); - } - - return strings.length; - } + private static final SimpleCommandExceptionType ALREADY_ON_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.alreadyOn")); + private static final SimpleCommandExceptionType ALREADY_OFF_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.alreadyOff")); + private static final SimpleCommandExceptionType ADD_FAILED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.add.failed")); + private static final SimpleCommandExceptionType REMOVE_FAILED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.remove.failed")); + + public static void register(CommandDispatcher dispatcher) { + dispatcher.register((CommandManager.literal("whitelist").requires((source) -> + source.hasPermissionLevel(3) + )).then(CommandManager.literal("on").executes((context) -> + executeOn(context.getSource()) + )).then(CommandManager.literal("off").executes((context) -> + executeOff(context.getSource()) + )).then(CommandManager.literal("list").executes((context) -> + executeList(context.getSource()) + )).then(CommandManager.literal("add").then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { + PlayerManager playerManager = context.getSource().getServer().getPlayerManager(); + return CommandSource.suggestMatching(playerManager.getPlayerList().stream().filter((player) -> + !playerManager.getWhitelist().isAllowed(player.getGameProfile()) + ).map((player) -> + player.getGameProfile().getName() + ), builder); + }).executes((context) -> + executeAdd(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")) + ))).then(CommandManager.literal("remove").then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> + CommandSource.suggestMatching(context.getSource().getServer().getPlayerManager().getWhitelistedNames(), builder) + ).executes((context) -> + executeRemove(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")) + ))).then(CommandManager.literal("reload").executes((context) -> + executeReload(context.getSource()) + ))); + } + + private static int executeReload(ServerCommandSource source) { + source.getServer().getPlayerManager().reloadWhitelist(); + source.sendFeedback(Text.translatable("commands.whitelist.reloaded"), true); + kickNonWhitelistedPlayers(source); + + return 1; + } + + private static int executeAdd(ServerCommandSource source, Collection targets) throws CommandSyntaxException { + Whitelist whitelist = source.getServer().getPlayerManager().getWhitelist(); + int i = 0; + + for (GameProfile gameProfile : targets) { + if (!whitelist.isAllowed(gameProfile)) { + WhitelistEntry whitelistEntry = new WhitelistEntry(gameProfile); + whitelist.add(whitelistEntry); + source.sendFeedback(Text.translatable("commands.whitelist.add.success", Texts.toText(gameProfile)), true); + ++i; + } + } + + if (i == 0) + throw ADD_FAILED_EXCEPTION.create(); + else + return i; + } + + private static int executeRemove(ServerCommandSource source, Collection targets) throws CommandSyntaxException { + Whitelist whitelist = source.getServer().getPlayerManager().getWhitelist(); + int i = 0; + + for (GameProfile gameProfile : targets) { + if (whitelist.isAllowed(gameProfile)) { + WhitelistEntry whitelistEntry = new WhitelistEntry(gameProfile); + whitelist.remove(whitelistEntry); + source.sendFeedback(Text.translatable("commands.whitelist.remove.success", Texts.toText(gameProfile)), true); + ++i; + } + } + + if (i == 0) + throw REMOVE_FAILED_EXCEPTION.create(); + else { + kickNonWhitelistedPlayers(source); + return i; + } + } + + private static int executeOn(ServerCommandSource source) throws CommandSyntaxException { + PlayerManager playerManager = source.getServer().getPlayerManager(); + + if (playerManager.isWhitelistEnabled()) + throw ALREADY_ON_EXCEPTION.create(); + else { + playerManager.setWhitelistEnabled(true); + source.sendFeedback(Text.translatable("commands.whitelist.enabled"), true); + kickNonWhitelistedPlayers(source); + + return 1; + } + } + + private static int executeOff(ServerCommandSource source) throws CommandSyntaxException { + PlayerManager playerManager = source.getServer().getPlayerManager(); + + if (!playerManager.isWhitelistEnabled()) + throw ALREADY_OFF_EXCEPTION.create(); + else { + playerManager.setWhitelistEnabled(false); + source.sendFeedback(Text.translatable("commands.whitelist.disabled"), true); + + return 1; + } + } + + private static int executeList(ServerCommandSource source) { + String[] strings = source.getServer().getPlayerManager().getWhitelistedNames(); + + if (strings.length == 0) + source.sendFeedback(Text.translatable("commands.whitelist.none"), false); + else + source.sendFeedback(Text.translatable("commands.whitelist.list", strings.length, String.join(", ", strings)), false); + + return strings.length; + } + private static void kickNonWhitelistedPlayers(ServerCommandSource source){ + PlayerManager playerManager = source.getServer().getPlayerManager(); + + if (playerManager.isWhitelistEnabled()) { + Whitelist whitelist = playerManager.getWhitelist(); + List list = Lists.newArrayList(playerManager.getPlayerList()); + + for (ServerPlayerEntity serverPlayerEntity : list) { + GameProfile profile = serverPlayerEntity.getGameProfile(); + + if(!source.getServer().isHost(profile)){ + if (!whitelist.isAllowed(profile) && !playerManager.isOperator(profile)) + serverPlayerEntity.networkHandler.disconnect(Text.translatable("multiplayer.disconnect.not_whitelisted")); + } + } + } + } } diff --git a/src/main/java/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java b/src/main/java/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java index 43dfd35..ddb2a34 100644 --- a/src/main/java/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java +++ b/src/main/java/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java @@ -1,63 +1,40 @@ package alujjdnd.ngrok.lan.command; -import alujjdnd.ngrok.lan.NgrokLan; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.minecraft.client.MinecraftClient; -import net.minecraft.command.CommandSource; -import net.minecraft.command.argument.GameProfileArgumentType; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.ServerConfigHandler; +import net.minecraft.server.*; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; public class ReloadJsonListsCommand { - - //check if player has permission (same permission level as /op and /deop) - //run loadJson(); - //get source.getServer() from command - - private static final SimpleCommandExceptionType LOAD_JSON_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("text.info.ngroklan.reload.message")); - - public ReloadJsonListsCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register(CommandManager.literal("reloadngroklanlists") - .requires(source -> source.hasPermissionLevel(3)) - .executes(ReloadJsonListsCommand::loadJson)); - } - - private static int loadJson(CommandContext serverCommandSourceCommandContext) throws CommandSyntaxException { - MinecraftServer server = serverCommandSourceCommandContext.getSource().getServer(); - - boolean bl3 = ServerConfigHandler.convertOperators(server); - - boolean bl4 = ServerConfigHandler.convertWhitelist(server); - - - if(! (bl3 && bl4) ){ - throw LOAD_JSON_EXCEPTION.create(); - } - else{ - MinecraftClient.getInstance().inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.reload.success")); - } - - return 1; - } - - - - - private static void sleepFiveSeconds() { - try { - Thread.sleep(5000L); - } catch (InterruptedException ignored) { - } - } + private static final SimpleCommandExceptionType LOAD_JSON_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("text.info.ngroklan.reload.message")); + + public static void register(CommandDispatcher dispatcher) { + dispatcher.register(CommandManager.literal("reloadngroklanlists") + .requires(source -> source.hasPermissionLevel(3)) + .executes(ReloadJsonListsCommand::loadJson)); + } + + private static int loadJson(CommandContext serverCommandSourceCommandContext) throws CommandSyntaxException { + PlayerManager playerManager = serverCommandSourceCommandContext.getSource().getServer().getPlayerManager(); + Whitelist whitelist = playerManager.getWhitelist(); + OperatorList opList = playerManager.getOpList(); + + try { + whitelist.load(); + opList.load(); + + MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.reload.success").styled(style -> style.withColor(Formatting.GREEN) )); + } + catch (Exception e) { + throw LOAD_JSON_EXCEPTION.create(); + } + + return 1; + } } diff --git a/src/main/java/alujjdnd/ngrok/lan/config/ModMenuIntegration.java b/src/main/java/alujjdnd/ngrok/lan/config/ModMenuIntegration.java index 0bf988d..7691fed 100644 --- a/src/main/java/alujjdnd/ngrok/lan/config/ModMenuIntegration.java +++ b/src/main/java/alujjdnd/ngrok/lan/config/ModMenuIntegration.java @@ -4,8 +4,7 @@ import com.terraformersmc.modmenu.api.ModMenuApi; import me.shedaniel.autoconfig.AutoConfig; -public class ModMenuIntegration implements ModMenuApi -{ +public class ModMenuIntegration implements ModMenuApi { @Override public ConfigScreenFactory getModConfigScreenFactory() { return parent -> AutoConfig.getConfigScreen(NLanConfig.class, parent).get(); diff --git a/src/main/java/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java b/src/main/java/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java index 0437b3f..7da7a53 100644 --- a/src/main/java/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java +++ b/src/main/java/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java @@ -1,6 +1,5 @@ package alujjdnd.ngrok.lan.mixin; - import alujjdnd.ngrok.lan.NgrokLan; import net.minecraft.server.MinecraftServer; import org.spongepowered.asm.mixin.Mixin; @@ -12,12 +11,10 @@ public abstract class CloseTunnelMixin { @Inject(at = @At("TAIL"), method = "shutdown") private void afterShutdownServer(CallbackInfo info) { - if(NgrokLan.serverOpen){ + if(NgrokLan.serverOpen) { NgrokLan.LOGGER.info("Closing Ngrok LAN!"); NgrokLan.ngrokClient.kill(); NgrokLan.serverOpen = false; } - } - } diff --git a/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java b/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java index afd9c30..cd67ebf 100644 --- a/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java +++ b/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java @@ -1,6 +1,5 @@ package alujjdnd.ngrok.lan.mixin; - import alujjdnd.ngrok.lan.NgrokLan; import alujjdnd.ngrok.lan.config.NLanConfig; import com.github.alexdlaird.ngrok.NgrokClient; @@ -15,8 +14,14 @@ import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.NetworkUtils; -import net.minecraft.server.ServerConfigHandler; -import net.minecraft.text.*; +import net.minecraft.server.OperatorList; +import net.minecraft.server.PlayerManager; +import net.minecraft.server.Whitelist; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.HoverEvent; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import net.minecraft.text.Texts; import net.minecraft.util.Formatting; import net.minecraft.world.GameMode; import org.spongepowered.asm.mixin.Mixin; @@ -25,178 +30,147 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.Objects; + @Mixin(OpenToLanScreen.class) public class OpenToLanScreenMixin extends Screen { + final NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); + final MinecraftClient mc = MinecraftClient.getInstance(); + + @Shadow + private GameMode gameMode; + @Shadow + private boolean allowCommands; + + protected OpenToLanScreenMixin(Text title) { + super(title); + } + + @Inject(method = "init", at = @At("HEAD")) + private void initWidgets(CallbackInfo info) { + if (config.enabledCheckBox) { //if mod enabled in mod menu + this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height - 58, 150, 20, Text.translatable("text.UI.ngroklan.LanButton"), (button) -> { + int localPort = NetworkUtils.findLocalPort(); // part of the minecraft NetworkUtils class, finds an available local port (this was from the openToLan class) + mc.setScreen(null); // Removed all elements from the screen (this closes all menu windows) + + switch (config.regionSelect) { + case EU -> ngrokInit(localPort, Region.EU); + case AP -> ngrokInit(localPort, Region.AP); + case AU -> ngrokInit(localPort, Region.AU); + case SA -> ngrokInit(localPort, Region.SA); + case JP -> ngrokInit(localPort, Region.JP); + case IN -> ngrokInit(localPort, Region.IN); + default -> ngrokInit(localPort, Region.US); //US bundled here + } + })); + } + } + + + private void ngrokInit(int port, Region region) { + //Defines a new threaded function to open the Ngrok tunnel, so that the "Open to LAN" button does not hitch - this thread runs in a separate process from the main game loop + Thread thread = new Thread(() -> { + if (config.authToken.equals("AuthToken")) { + // Check if authToken field has actually been changed, if not, print this text in chat + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.error.ngroklan.AuthTokenError").formatted(Formatting.RED)); + NgrokLan.LOGGER.error("Launched Lan UNSUCCESSFUL"); + } + else { + try { + NgrokLan.LOGGER.info("Launched Lan!"); + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.startMessage").formatted(Formatting.YELLOW)); + + + // Java-ngrok wrapper code, to initiate the tunnel, with the auth token, region + final JavaNgrokConfig javaNgrokConfig = new JavaNgrokConfig.Builder() + .withAuthToken(config.authToken) + .withRegion(region) + .build(); + + NgrokLan.ngrokClient = new NgrokClient.Builder() + .withJavaNgrokConfig(javaNgrokConfig) + .build(); + + final CreateTunnel createTunnel = new CreateTunnel.Builder() + .withProto(Proto.TCP) + .withAddr(port) + .build(); + + final Tunnel tunnel = NgrokLan.ngrokClient.connect(createTunnel); + + NgrokLan.LOGGER.info(tunnel.getPublicUrl()); + + var ngrok_url = tunnel.getPublicUrl().substring(6); + + // Print in chat the status of the tunnel, and the details copied to the clipboard + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.success").formatted(Formatting.GREEN)); + Text copyText = Texts.bracketed((Text.translatable(ngrok_url)).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, ngrok_url)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("chat.copy.click"))).withInsertion(ngrok_url))); + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.ip", copyText)); + mc.keyboard.setClipboard(ngrok_url); + + + + // This starts the LAN server and greys out the open to lan button + MutableText textStart; + if (mc.getServer() != null && mc.getServer().openToLan(this.gameMode, this.allowCommands, port)) { + mc.getServer().setOnlineMode(config.onlineCheckBox); + textStart = Text.translatable("commands.publish.started", port); + NgrokLan.serverOpen = true; + + //I made a new thread that reads the json files to update the op list and whitelist in the PlayerManager + Thread thread2 = new Thread(() -> { + boolean loaded = loadJson(); + if(loaded) { + MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.reload.success").styled(style -> style.withColor(Formatting.GREEN) )); + } + else { + Text commandText = Texts.bracketed((Text.translatable("text.info.ngroklan.reload.prompt")).styled((style) -> style.withColor(Formatting.RED).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reloadngroklanlists")).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("text.info.ngroklan.reload.prompt"))))); + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.reload.message")); + mc.inGameHud.getChatHud().addMessage(commandText); + } + }); + + thread2.start(); + + } + else { + textStart = Text.translatable("commands.publish.failed"); + NgrokLan.serverOpen = false; + } + + mc.inGameHud.getChatHud().addMessage(textStart); + mc.updateWindowTitle(); + } + catch (Exception error) { + error.printStackTrace(); + mc.inGameHud.getChatHud().addMessage(Text.literal(error.getMessage())); + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.error.ngroklan.fail").formatted(Formatting.RED)); + throw new RuntimeException("Ngrok Service Failed to Start" + error.getMessage()); + } + } + }); + + // This starts the thread defined above + thread.start(); + } + + private boolean loadJson() { + PlayerManager playerManager = Objects.requireNonNull(mc.getServer()).getPlayerManager(); + + Whitelist whitelist = playerManager.getWhitelist(); + OperatorList opList = playerManager.getOpList(); + + try { + whitelist.load(); + opList.load(); + } + catch (Exception e) { + return false; + } + + return true; + } - NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); - MinecraftClient mc = MinecraftClient.getInstance(); - - @Shadow - private GameMode gameMode; - - @Shadow - private boolean allowCommands; - - protected OpenToLanScreenMixin(Text title) { - super(title); - } - - @Inject(method = "init", at = @At("HEAD")) - private void initWidgets(CallbackInfo info) { - - if (config.enabledCheckBox) { //if mod enabled in mod menu - this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height - 58, 150, 20, Text.translatable("text.UI.ngroklan.LanButton"), (button) -> { - int localPort = NetworkUtils.findLocalPort(); // part of the minecraft Networkutils class, finds an available local port (this was from the openToLan class) - this.client.setScreen(null); // Removed all elements from the screen (this closes all menu windows) - switch (config.regionSelect) { - case EU -> ngrokInit(localPort, Region.EU); - case AP -> ngrokInit(localPort, Region.AP); - case AU -> ngrokInit(localPort, Region.AU); - case SA -> ngrokInit(localPort, Region.SA); - case JP -> ngrokInit(localPort, Region.JP); - case IN -> ngrokInit(localPort, Region.IN); - default -> ngrokInit(localPort, Region.US); //US bundled here - } - })); - - } - } - - - private void ngrokInit(int port, Region region) { - - //Defines a new threaded function to oepn the Ngrok tunnel, so that the "Open to LAN" button does not hitch - this thread runs in a seperate process from the main game loop - Thread thread = new Thread(() -> - { - if (config.authToken.equals("AuthToken")) { - // Check if authToken field has actually been changed, if not, print this text in chat - mc.inGameHud.getChatHud().addMessage(Text.translatable("text.error.ngroklan.AuthTokenError")); - mc.inGameHud.getChatHud().addMessage(Text.translatable("text.error.ngroklan.AuthTokenError").formatted(Formatting.RED)); - //\u00a7c - } else { - try { - NgrokLan.LOGGER.info("Launched Lan!"); - - mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.startMessage").formatted(Formatting.YELLOW)); - - - // Java-ngrok wrapper code, to initiate the tunnel, with the authoken, region - final JavaNgrokConfig javaNgrokConfig = new JavaNgrokConfig.Builder() - .withAuthToken(config.authToken) - .withRegion(region) - .build(); - - NgrokLan.ngrokClient = new NgrokClient.Builder() - .withJavaNgrokConfig(javaNgrokConfig) - .build(); - - final CreateTunnel createTunnel = new CreateTunnel.Builder() - .withProto(Proto.TCP) - .withAddr(port) - .build(); - - final Tunnel tunnel = NgrokLan.ngrokClient.connect(createTunnel); - - NgrokLan.LOGGER.info(tunnel.getPublicUrl()); - - var ngrok_url = tunnel.getPublicUrl().substring(6); - - // Print in chat the status of the tunnel, and the details copied to the clipboard - mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.success").formatted(Formatting.GREEN)); - - Text copyText = Texts.bracketed((Text.literal(ngrok_url)).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, ngrok_url)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("chat.copy.click"))).withInsertion(ngrok_url))); - mc.inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.ip", copyText)); - - mc.keyboard.setClipboard(ngrok_url); - - - - // This starts the LAN server and greys out the open to lan button - Text text; - - - if (this.client.getServer().openToLan(this.gameMode, this.allowCommands, port)) { - mc.getServer().setOnlineMode(config.onlineCheckBox); - text = Text.translatable("commands.publish.started", port); - NgrokLan.serverOpen = true; - - //TODO: make sure this works, I make a new thread that reads the json files to update the oplist and whitelist in the playermanager - Thread thread2 = new Thread(() -> { - - NgrokLan.LOGGER.info("debug THREAD2 STARTED"); - - boolean result = loadJson(); - if(!result){ - Text commandText = Texts.bracketed((Text.translatable("text.info.ngroklan.reload.prompt")).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reloadngroklanlists")).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("text.info.ngroklan.reload.prompt"))))); - mc.inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.reload.message")); - mc.inGameHud.getChatHud().addMessage(commandText); - } - else{ - mc.inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.reload.success")); - } - }); - - NgrokLan.LOGGER.info("debug THREAD2 STARTING"); - thread2.start(); - - } else { - text = Text.translatable("commands.publish.failed"); - NgrokLan.serverOpen = false; - } - this.client.inGameHud.getChatHud().addMessage(text); - this.client.updateWindowTitle(); - - } catch (Exception error) { - error.printStackTrace(); - mc.inGameHud.getChatHud().addMessage(Text.literal(error.getMessage())); - mc.inGameHud.getChatHud().addMessage(Text.translatable("text.error.ngroklan.fail").formatted(Formatting.RED)); - //ngrokInitiated = false; - throw new RuntimeException("Ngrok Service Failed to Start" + error.getMessage()); - } - } - }); - - // This starts the thread defined above - thread.start(); - - } - - private boolean loadJson(){ - NgrokLan.LOGGER.info("debug LOADING JSON"); - - int i; - boolean bl3 = false; - - for(i = 0; !bl3 && i <= 2; ++i) { - if (i > 0) { - NgrokLan.LOGGER.warn("Encountered a problem while converting the op list, retrying in a few seconds"); - this.sleepFiveSeconds(); - } - - bl3 = ServerConfigHandler.convertOperators(this.client.getServer()); - //fail is false - } - - boolean bl4 = false; - - for(i = 0; !bl4 && i <= 2; ++i) { - if (i > 0) { - NgrokLan.LOGGER.warn("Encountered a problem while converting the whitelist, retrying in a few seconds"); - this.sleepFiveSeconds(); - } - - bl4 = ServerConfigHandler.convertWhitelist(this.client.getServer()); - //fail is false - } - - return bl3 && bl4; - } - private void sleepFiveSeconds() { - try { - Thread.sleep(5000L); - } catch (InterruptedException var2) { - } - } } diff --git a/src/main/java/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java b/src/main/java/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java index b6bcd87..53c75ce 100644 --- a/src/main/java/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java +++ b/src/main/java/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java @@ -1,18 +1,10 @@ package alujjdnd.ngrok.lan.mixin; import alujjdnd.ngrok.lan.NgrokLan; -import alujjdnd.ngrok.lan.config.NLanConfig; import com.mojang.authlib.GameProfile; -import me.shedaniel.autoconfig.AutoConfig; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.MinecraftServer; import net.minecraft.server.PlayerManager; import net.minecraft.server.Whitelist; -import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -24,8 +16,6 @@ @Mixin(PlayerManager.class) public class PlayerManagerMixin { - NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); - @Final @Shadow private Whitelist whitelist; @@ -33,6 +23,5 @@ public class PlayerManagerMixin { @Inject(at = @At("HEAD"), method = "checkCanJoin") public void isSpawnProtected(SocketAddress address, GameProfile profile, CallbackInfoReturnable cir) { NgrokLan.LOGGER.info("Whitelist? " + whitelist.getFile().getAbsolutePath()); - } } diff --git a/src/main/java/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java b/src/main/java/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java index 6f1be6c..e68cc18 100644 --- a/src/main/java/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java +++ b/src/main/java/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java @@ -18,29 +18,30 @@ @Mixin(MinecraftServer.class) public class SpawnProtectionMixin { - - NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); + final NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); @Shadow private PlayerManager playerManager; @Inject(at = @At("HEAD"), method = "isSpawnProtected", cancellable = true) public void isSpawnProtected(ServerWorld world, BlockPos pos, PlayerEntity player, CallbackInfoReturnable cir) { - - if(!NgrokLan.serverOpen){ + if(!NgrokLan.serverOpen) { cir.setReturnValue(false); cir.cancel(); - } else if (config.spawnProtectionRadius <= 0) { + } + else if (config.spawnProtectionRadius <= 0) { cir.setReturnValue(false); cir.cancel(); } else if (world.getRegistryKey() != World.OVERWORLD) { cir.setReturnValue(false); cir.cancel(); - } else if (playerManager.isOperator(player.getGameProfile())) { + } + else if (playerManager.isOperator(player.getGameProfile())) { cir.setReturnValue(false); cir.cancel(); - } else { + } + else { BlockPos blockPos = world.getSpawnPos(); int i = MathHelper.abs(pos.getX() - blockPos.getX()); int j = MathHelper.abs(pos.getZ() - blockPos.getZ()); @@ -48,7 +49,7 @@ else if (world.getRegistryKey() != World.OVERWORLD) { cir.setReturnValue(k <= config.spawnProtectionRadius); cir.cancel(); } - //there's a small diff from vanilla check that checks if Oplist is empty. Since the host + //there's a small diff from vanilla check that checks if op list is empty. Since the host //is an "admin" (more control than op idk the technical term) by default they are not in //the op list, so this check does not work. } diff --git a/src/main/java/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java b/src/main/java/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java index ba7bcd5..98a314b 100644 --- a/src/main/java/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java +++ b/src/main/java/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java @@ -14,11 +14,7 @@ public abstract class WindowTitleMixin { private void injected(CallbackInfoReturnable cir) { StringBuilder stringBuilder2 = new StringBuilder(I18n.translate("text.title.ngroklan.window")); - if(NgrokLan.serverOpen){ + if(NgrokLan.serverOpen) cir.setReturnValue(stringBuilder2.toString()); - } - - } - -} \ No newline at end of file +} diff --git a/src/main/resources/assets/ngroklan/lang/en_us.json b/src/main/resources/assets/ngroklan/lang/en_us.json index 97201b8..0448f9a 100644 --- a/src/main/resources/assets/ngroklan/lang/en_us.json +++ b/src/main/resources/assets/ngroklan/lang/en_us.json @@ -13,9 +13,9 @@ "text.info.ngroklan.success" : "Ngrok Service Initiated Successfully!", "text.info.ngroklan.ip" : "Your server IP is - %s - (Copied to Clipboard)", "text.error.ngroklan.fail" : "Ngrok Service Initiation Failed!", - "text.title.ngroklan.window" : "Minecraft* 1.18.2 - Multiplayer (Ngrok-LAN)", + "text.title.ngroklan.window" : "Minecraft* 1.19 - Multiplayer (Ngrok-LAN)", "text.info.ngroklan.click.reload" : "Click to reload whitelist and op list", "text.info.ngroklan.reload.prompt" : "Click here to reload", "text.info.ngroklan.reload.message" : "An error occurred loading the whitelist and op list", "text.info.ngroklan.reload.success" : "The whitelist and op list were successfully loaded" -} \ No newline at end of file +} diff --git a/src/main/resources/ngroklan.mixins.json b/src/main/resources/ngroklan.mixins.json index 623a154..6e5b07d 100644 --- a/src/main/resources/ngroklan.mixins.json +++ b/src/main/resources/ngroklan.mixins.json @@ -5,6 +5,7 @@ "compatibilityLevel": "JAVA_17", "mixins": [ "PlayerManagerMixin", + "SpawnProtectionMixin", "WindowTitleMixin" ], "client": [ diff --git a/src/main/resources/quilt.mod.json b/src/main/resources/quilt.mod.json index c6558fc..68d0337 100644 --- a/src/main/resources/quilt.mod.json +++ b/src/main/resources/quilt.mod.json @@ -26,7 +26,7 @@ "alujjdnd.ngrok.lan.NgrokLan" ], "server": [ - "alujjdnd.ngrok.lan.NgrokServerInitialiser" + "alujjdnd.ngrok.lan.NgrokLanServerInitializer" ], "modmenu": [ "alujjdnd.ngrok.lan.config.ModMenuIntegration" From 59cc97b529efd805e4e77a5594a0e515e347e1a1 Mon Sep 17 00:00:00 2001 From: alujjdnd Date: Thu, 16 Jun 2022 21:53:22 +0800 Subject: [PATCH 5/9] Updated to match branch name --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3064323..c775f03 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Ngrok LAN Banner](https://github.com/Alujjdnd/Ngrok-LAN/blob/main/docs/assets/banner.png?raw=true) +![Ngrok LAN Banner](https://github.com/Alujjdnd/Ngrok-LAN/blob/1.18.2/docs/assets/banner.png?raw=true)

Ngrok LAN @@ -11,7 +11,7 @@ GitHub commit activity
- + ## Help Needed! @@ -26,7 +26,7 @@ after you click on "Open Public Server". For more on how Ngrok-LAN works, check out [What is Ngrok](#what-is-ngrok).
- Network Diagram + Network Diagram
# Installation/Quick Start @@ -129,7 +129,7 @@ friends to connect to our server. This doesn't require any other configuration o internet, and an Ngrok account, you can host your singleplayer world to your friends across the globe.
-Network Diagram +Network Diagram
## Ngrok Account Requirements From 007aba3b7ec638da021b005aa8f8f8c726abb9ad Mon Sep 17 00:00:00 2001 From: Mikolaj Date: Mon, 11 Jul 2022 21:18:01 +0200 Subject: [PATCH 6/9] Get the mod working on quilt --- .editorconfig | 34 +++ .gitignore | 24 +- build.gradle | 80 +++--- gradle.properties | 20 +- gradle/gradle | 234 ------------------ gradle/libs.versions.toml | 22 ++ gradle/wrapper/gradle-wrapper.jar | Bin 59536 -> 59821 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 10 +- settings.gradle | 20 +- .../java/alujjdnd/ngrok/lan/NgrokLan.java | 7 +- .../ngrok/lan/NgrokServerInitialiser.java | 22 +- .../lan/command/LanWhitelistCommand.java | 30 +-- .../lan/command/ReloadJsonListsCommand.java | 38 ++- .../ngrok/lan/mixin/OpenToLanScreenMixin.java | 74 +++--- src/main/resources/fabric.mod.json | 47 ---- src/main/resources/quilt.mod.json | 51 ++++ 17 files changed, 274 insertions(+), 441 deletions(-) create mode 100644 .editorconfig delete mode 100644 gradle/gradle create mode 100644 gradle/libs.versions.toml mode change 100644 => 100755 gradlew delete mode 100644 src/main/resources/fabric.mod.json create mode 100644 src/main/resources/quilt.mod.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0908154 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,34 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +tab_width = 4 +trim_trailing_whitespace = true + +[*.gradle] +indent_style = tab + +[*.java] +indent_style = tab + +[*.json] +indent_style = space +indent_size = 2 + +[quilt.mod.json] +indent_style = tab +tab_width = 2 + +[*.toml] +indent_style = tab +tab_width = 2 + +[*.properties] +indent_style = space +indent_size = 2 + +[.editorconfig] +indent_style = space +indent_size = 4 diff --git a/.gitignore b/.gitignore index 6234ac5..3819565 100644 --- a/.gitignore +++ b/.gitignore @@ -1,36 +1,30 @@ -# gradle - +# Gradle .gradle/ build/ out/ classes/ -# eclipse +# Quilt Loom +run/ +# Eclipse *.launch -# idea - +# IntelliJ Idea .idea/ *.iml *.ipr *.iws -# vscode - +# Visual Studio Code .settings/ .vscode/ bin/ .classpath .project -# macos +# Eclipse JDT LS +workspace/ +# macOS *.DS_Store - -# fabric - -run/ - -# enviroment -.env diff --git a/build.gradle b/build.gradle index 792a3b8..396a9d8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,12 @@ plugins { - id 'fabric-loom' version '0.12-SNAPSHOT' id 'maven-publish' + alias(libs.plugins.quilt.loom) id 'com.github.johnrengelman.shadow' version '7.1.2' - id 'java' id "com.modrinth.minotaur" version "2.+" - //id 'net.minecraftforge.gradle.forge' version '2.0.2' - //id 'com.matthewprenger.cursegradle' version '1.4.0' } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 - archivesBaseName = project.archives_base_name -version = project.mod_version +version = project.version group = project.maven_group repositories { @@ -23,26 +17,32 @@ repositories { // for more information about repositories. maven { url "https://maven.shedaniel.me/" } - maven { url "https://maven.terraformersmc.com/" } + maven { url "https://maven.terraformersmc.com/" } } +// All the dependencies are declared at gradle/libs.version.toml and referenced with "libs." +// See https://docs.gradle.org/current/userguide/platforms.html for information on how version catalogs work. dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + minecraft libs.minecraft + mappings loom.layered { + addLayer quiltMappings.mappings("org.quiltmc:quilt-mappings:${libs.versions.quilt.mappings.get()}:v2") + // officialMojangMappings() // Uncomment if you want to use Mojang mappings as your primary mappings, falling back on QM for parameters and Javadocs + } + modImplementation libs.quilt.loader - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + // QSL is not a complete API; You will need Quilted Fabric API to fill in the gaps. + // Quilted Fabric API will automatically pull in the correct QSL version. + modImplementation libs.quilted.fabric.api + // modImplementation libs.bundles.quilted.fabric.api // If you wish to use Fabric API's deprecated modules, you can replace the above line with this one //Java-Ngrok, a wrapper for the Ngrok service by providing a handy Java API to call it. - modImplementation(include("com.github.alexdlaird:java-ngrok:1.5.6")) + modImplementation(include("com.github.alexdlaird:java-ngrok:1.5.6")) - modImplementation(include("org.yaml:snakeyaml:1.8")) + modImplementation(include("org.yaml:snakeyaml:1.30")) modApi("me.shedaniel.cloth:cloth-config-fabric:7.0.72") { - exclude(group: "net.fabricmc.fabric-api") - } + exclude(group: "net.fabricmc.fabric-api") + } modImplementation(include("blue.endless:jankson:1.2.1")) @@ -50,38 +50,41 @@ dependencies { } processResources { - inputs.property "version", project.version + inputs.property "version", version - filesMatching("fabric.mod.json") { - expand "version": project.version + filesMatching('quilt.mod.json') { + expand "version": version } } tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. it.options.release = 17 } java { - // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task - // if it is present. + // Still required by IDEs such as Eclipse and Visual Studio Code + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task if it is present. // If you remove this line, sources will not be generated. withSourcesJar() + + // If this mod is going to be a library, then it should also generate Javadocs in order to aid with development. + // Uncomment this line to generate them. + // withJavadocJar() } +// If you plan to use a different file for the license, don't forget to change the file name here! jar { from("LICENSE") { - rename { "${it}_${project.archivesBaseName}"} + rename { "${it}_${archivesBaseName}" } } } -shadowJar { - manifest { - attributes 'Main-Class': 'com.example.ApplicationKt' - } -} - -// configure the maven publication +// Configure the maven publication publishing { publications { mavenJava(MavenPublication) { @@ -102,21 +105,12 @@ import com.modrinth.minotaur.dependencies.ModDependency modrinth { token = System.getenv("MODRINTH_TOKEN") // This is the default. Remember to have the MODRINTH_TOKEN environment variable set or else this will fail, or set it to whatever you want - just make sure it stays private! projectId = "oTa1qz6R" - versionNumber = project.mod_version // You don't need to set this manually. Will fail if Modrinth has this version already + versionNumber = version // You don't need to set this manually. Will fail if Modrinth has this version already versionType = "release" // This is the default uploadFile = remapJar // With Fabric Loom or Architectury Loom, this MUST be set to `remapJar` instead of `jar`! - gameVersions = [project.minecraft_version] // Must be an array, even with only one version + gameVersions = [libs.versions.minecraft] // Must be an array, even with only one version loaders = ["fabric"] // Must also be an array - no need to specify this if you're using Fabric Loom or ForgeGradle dependencies = [ new ModDependency("mOgUt4GM", "required") ] } - -//curseforge { -// apiKey = System.getenv("CURSEFORGE_TOKEN") // This should really be in a gradle.properties file -// project { -// id = '602252' -// changelog = 'Added content and fixed bugs' // A file can also be set using: changelog = file('changelog.txt') -// releaseType = 'release' -// } -//} diff --git a/gradle.properties b/gradle.properties index b61ffc0..ff0a6b9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,16 +1,10 @@ -# Done to increase the memory available to gradle. -org.gradle.jvmargs=-Xmx1G - -# Fabric Properties - # check these on https://fabricmc.net/develop - minecraft_version=1.19 - yarn_mappings=1.19+build.4 - loader_version=0.14.8 +# Gradle Properties +org.gradle.jvmargs = -Xmx1G +org.gradle.parallel = true # Mod Properties - mod_version = 1.4.4-1.19 - maven_group = alujjdnd.ngrok.lan - archives_base_name = ngrok-lan-expose-mod +version = 1.4.5 +maven_group = alujjdnd.ngrok.lan +archives_base_name = ngrok-lan-expose-mod -# Dependencies - fabric_version=0.56.3+1.19 +# Dependencies are managed at gradle/libs.versions.toml diff --git a/gradle/gradle b/gradle/gradle deleted file mode 100644 index 5fe3082..0000000 --- a/gradle/gradle +++ /dev/null @@ -1,234 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/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/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -APP_HOME=$( cd "${APP_HOME:-./}.." && pwd -P ) || exit - -APP_NAME="Gradle" -APP_BASE_NAME=${0##*/} - -# 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 - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/lib/gradle-launcher-7.4.1.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - 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. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - -# 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" \ - -classpath "$CLASSPATH" \ - org.gradle.launcher.GradleMain \ - "$@" - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..a9687a5 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,22 @@ +[versions] +# The latest versions are available at https://lambdaurora.dev/tools/import_quilt.html +minecraft = "1.19" +quilt_mappings = "1.19+build.1" +quilt_loader = "0.17.0" + +quilted_fabric_api = "2.0.0-beta.5+0.57.0-1.19" + +[libraries] +minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" } +quilt_mappings = { module = "org.quiltmc:quilt-mappings", version.ref = "quilt_mappings" } +quilt_loader = { module = "org.quiltmc:quilt-loader", version.ref = "quilt_loader" } + +quilted_fabric_api = { module = "org.quiltmc.quilted-fabric-api:quilted-fabric-api", version.ref = "quilted_fabric_api" } +quilted_fabric_api_deprecated = { module = "org.quiltmc.quilted-fabric-api:quilted-fabric-api-deprecated", version.ref = "quilted_fabric_api" } + +# If you have multiple similar dependencies, you can declare a dependency bundle and reference it on the build script with "libs.bundles.example". +[bundles] +quilted_fabric_api = ["quilted_fabric_api", "quilted_fabric_api_deprecated"] + +[plugins] +quilt_loom = { id = "org.quiltmc.loom", version = "0.12.+" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180f2ae8848c63b8b4dea2cb829da983f2fa..41d9927a4d4fb3f96a785543079b8df6723c946b 100644 GIT binary patch delta 8958 zcmY+KWl$VIlZIh&f(Hri?gR<$?iyT!TL`X;1^2~W7YVSq1qtqM!JWlDxLm%}UESUM zndj}Uny%^UnjhVhFb!8V3s(a#fIy>`VW15{5nuy;_V&a5O#0S&!a4dSkUMz_VHu3S zGA@p9Q$T|Sj}tYGWdjH;Mpp8m&yu&YURcrt{K;R|kM~(*{v%QwrBJIUF+K1kX5ZmF zty3i{d`y0;DgE+de>vN@yYqFPe1Ud{!&G*Q?iUc^V=|H%4~2|N zW+DM)W!`b&V2mQ0Y4u_)uB=P@-2`v|Wm{>CxER1P^ z>c}ZPZ)xxdOCDu59{X^~2id7+6l6x)U}C4Em?H~F`uOxS1?}xMxTV|5@}PlN%Cg$( zwY6c}r60=z5ZA1L zTMe;84rLtYvcm?M(H~ZqU;6F7Evo{P7!LGcdwO|qf1w+)MsnvK5^c@Uzj<{ zUoej1>95tuSvDJ|5K6k%&UF*uE6kBn47QJw^yE&#G;u^Z9oYWrK(+oL97hBsUMc_^ z;-lmxebwlB`Er_kXp2$`&o+rPJAN<`WX3ws2K{q@qUp}XTfV{t%KrsZ5vM!Q#4{V& zq>iO$MCiLq#%wXj%`W$_%FRg_WR*quv65TdHhdpV&jlq<=K^K`&!Kl5mA6p4n~p3u zWE{20^hYpn1M}}VmSHBXl1*-)2MP=0_k)EPr#>EoZukiXFDz?Di1I>2@Z^P$pvaF+ zN+qUy63jek2m59;YG)`r^F3-O)0RDIXPhf)XOOdk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rYv zHgx|trUN#mu*VzUV~8TnJM2Qh*ZM5B{x&y>5An`(M7=Z*Q>TdiH@j*2=moNuOtvpz z+G`@~-`%~+AgPKgke@XiRPgndh@bp*-HRsh;HTtz@-y_uhb%7ylVOTqG0#u?Vn5c5 zEp*XRo|8hcgG^$#{$O9CJ&NE;TrfRpSnLmes&MO{m=N%zc`}gb!eQ7odl$oy1%PI} z#AIxx%oRVy&{O~9xnK4$EY>(eQj}!HKIV$Fz*H=-=Kn)N0D6u`(;iO|VraI4fu_W` z;b5{7;Lyx4za}DU#+U7}=H0dAS#YJJ&g2!P@Htu-AL&w=-)*%P9h2{wR|@?Ff9~)b z^+e_3Hetq7W%ls{!?<6&Y$Z;NNB41pvrv)|MET6AZXFXJeFqbFW5@i5WGzl?bP+~? z*&_puH;wKv2)9T_d+P`bLvJFqX#j&xa*-;0nGBbQf0DC>o~=J_Wmtf*2SZQr?{i~X z9-IbRH8{iy?<0v9Ir1?$66+igy|yDQ5J~A9sFX@Pe<*kCY8+MwH?I z`P}zfQ6l^AO8ehZ=l^ZR;R%uu4;BK*=?W9t|0{+-at(MQZ(CtG=EJFNaFMlKCMXu30(gJUqj5+ z`GM|!keqcj;FKTa_qq;{*dHRXAq157hlB@kL#8%yAm2AgfU|*rDKX@FLlp=HL8ddv zAWLCHe@DcDeB2}fl7#=0+#<05c3=VqM*O3bkr@9X4nO|)q0hU;Gye{L8ZN*NH8Id@mP-u;Fmb8YuorjLrW&ndip8CN%_qp982r w1WEnz9^$&s1hkp_3#lPJQ~!HI7WYYjA7>z!`?f%npAh2%rB@vD|Lau$2O)#1n*aa+ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb87..aa991fc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 index c53aefa..1b6c787 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -32,10 +32,10 @@ # Busybox and similar reduced shells will NOT work, because this script # requires all of these POSIX shell features: # * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». # # Important for patching: # diff --git a/settings.gradle b/settings.gradle index b02216b..d969e34 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,10 +1,14 @@ pluginManagement { - repositories { - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' - } - mavenCentral() - gradlePluginPortal() - } + repositories { + maven { + name = 'Quilt' + url = 'https://maven.quiltmc.org/repository/release' + } + // Currently needed for Intermediary and other temporary dependencies + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() + } } diff --git a/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java b/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java index efde24c..a25f955 100644 --- a/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java +++ b/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java @@ -5,8 +5,9 @@ import alujjdnd.ngrok.lan.command.LanWhitelistCommand; import alujjdnd.ngrok.lan.command.ReloadJsonListsCommand; import com.github.alexdlaird.ngrok.NgrokClient; -import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import org.quiltmc.loader.api.ModContainer; +import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,7 +32,7 @@ public class NgrokLan implements ModInitializer { public static boolean serverOpen = false; @Override - public void onInitialize() { + public void onInitialize(ModContainer mod) { // This code runs as soon as Minecraft is in a mod-load-ready state. // However, some things (like resources) may still be uninitialized. // Proceed with mild caution. @@ -40,7 +41,7 @@ public void onInitialize() { AutoConfig.register(NLanConfig.class, JanksonConfigSerializer::new); //register commands - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, dedicated) -> { LanOpCommand.register(dispatcher); LanDeopCommand.register(dispatcher); diff --git a/src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java b/src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java index a204e89..be0d934 100644 --- a/src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java +++ b/src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java @@ -5,10 +5,12 @@ import alujjdnd.ngrok.lan.command.LanOpCommand; import alujjdnd.ngrok.lan.command.LanWhitelistCommand; import alujjdnd.ngrok.lan.command.ReloadJsonListsCommand; -import net.fabricmc.api.DedicatedServerModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.minecraft.server.dedicated.DedicatedServer; +import org.quiltmc.loader.api.ModContainer; +import org.quiltmc.qsl.base.api.entrypoint.server.DedicatedServerModInitializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,15 +21,19 @@ public class NgrokServerInitialiser implements DedicatedServerModInitializer public static final Logger LOGGER = LoggerFactory.getLogger(NgrokLan.MODID); @Override - public void onInitializeServer() { - + // Initialize the differents parts of the mod when lauched on server + public void onInitializeServer(ModContainer mod) + { LOGGER.info("World is Open to LAN with Ngrok LAN"); - // Initialize the differents parts of the mod when lauched on server - CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> LanOpCommand.register(dispatcher))); - CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> LanDeopCommand.register(dispatcher))); - CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> LanWhitelistCommand.register(dispatcher))); - CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> ReloadJsonListsCommand.register(dispatcher))); + //register commands + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, dedicated) -> + { + LanOpCommand.register(dispatcher); + LanDeopCommand.register(dispatcher); + LanWhitelistCommand.register(dispatcher); + ReloadJsonListsCommand.register(dispatcher); + }); } } diff --git a/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java b/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java index 4804f94..9b8de63 100644 --- a/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java +++ b/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java @@ -1,6 +1,5 @@ package alujjdnd.ngrok.lan.command; -import com.google.common.collect.Lists; import com.mojang.authlib.GameProfile; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; @@ -13,13 +12,10 @@ import net.minecraft.server.WhitelistEntry; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Texts; import net.minecraft.text.Text; +import net.minecraft.text.Texts; import java.util.Collection; -import java.util.Iterator; -import java.util.List; public class LanWhitelistCommand { private static final SimpleCommandExceptionType ALREADY_ON_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.alreadyOn")); @@ -60,7 +56,7 @@ public static void register(CommandDispatcher dispatcher) { private static int executeReload(ServerCommandSource source) { source.getServer().getPlayerManager().reloadWhitelist(); source.sendFeedback(Text.translatable("commands.whitelist.reloaded"), true); - kickNonWhitelistedPlayers(source); + source.getServer().kickNonWhitelistedPlayers(source); return 1; } @@ -100,7 +96,7 @@ private static int executeRemove(ServerCommandSource source, Collection list = Lists.newArrayList(playerManager.getPlayerList()); - - for (ServerPlayerEntity serverPlayerEntity : list) { - GameProfile profile = serverPlayerEntity.getGameProfile(); - if(!source.getServer().isHost(profile)){ - if (!whitelist.isAllowed(profile) && !playerManager.isOperator(profile)) { - serverPlayerEntity.networkHandler.disconnect(Text.translatable("multiplayer.disconnect.not_whitelisted")); - } - } - - } - - } - } } diff --git a/src/main/java/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java b/src/main/java/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java index 777523e..43dfd35 100644 --- a/src/main/java/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java +++ b/src/main/java/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java @@ -1,18 +1,27 @@ package alujjdnd.ngrok.lan.command; +import alujjdnd.ngrok.lan.NgrokLan; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.minecraft.client.MinecraftClient; -import net.minecraft.server.*; +import net.minecraft.command.CommandSource; +import net.minecraft.command.argument.GameProfileArgumentType; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.PlayerManager; +import net.minecraft.server.ServerConfigHandler; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; public class ReloadJsonListsCommand { + //check if player has permission (same permission level as /op and /deop) + //run loadJson(); + //get source.getServer() from command + private static final SimpleCommandExceptionType LOAD_JSON_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("text.info.ngroklan.reload.message")); public ReloadJsonListsCommand() { @@ -25,21 +34,30 @@ public static void register(CommandDispatcher dispatcher) { } private static int loadJson(CommandContext serverCommandSourceCommandContext) throws CommandSyntaxException { - PlayerManager playerManager = serverCommandSourceCommandContext.getSource().getServer().getPlayerManager(); + MinecraftServer server = serverCommandSourceCommandContext.getSource().getServer(); - Whitelist whitelist = playerManager.getWhitelist(); - OperatorList opList = playerManager.getOpList(); + boolean bl3 = ServerConfigHandler.convertOperators(server); + + boolean bl4 = ServerConfigHandler.convertWhitelist(server); - try { - whitelist.load(); - opList.load(); - MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.reload.success").styled(style -> style.withColor(Formatting.GREEN) )); - } catch (Exception e) { + if(! (bl3 && bl4) ){ throw LOAD_JSON_EXCEPTION.create(); } + else{ + MinecraftClient.getInstance().inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.reload.success")); + } return 1; } + + + + private static void sleepFiveSeconds() { + try { + Thread.sleep(5000L); + } catch (InterruptedException ignored) { + } + } } diff --git a/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java b/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java index 079f38f..afd9c30 100644 --- a/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java +++ b/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java @@ -15,13 +15,9 @@ import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.NetworkUtils; -import net.minecraft.server.OperatorList; -import net.minecraft.server.PlayerManager; import net.minecraft.server.ServerConfigHandler; -import net.minecraft.server.Whitelist; import net.minecraft.text.*; import net.minecraft.util.Formatting; -import net.minecraft.util.TranslatableOption; import net.minecraft.world.GameMode; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -74,12 +70,13 @@ private void ngrokInit(int port, Region region) { { if (config.authToken.equals("AuthToken")) { // Check if authToken field has actually been changed, if not, print this text in chat + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.error.ngroklan.AuthTokenError")); mc.inGameHud.getChatHud().addMessage(Text.translatable("text.error.ngroklan.AuthTokenError").formatted(Formatting.RED)); //\u00a7c - NgrokLan.LOGGER.error("Launched Lan UNSUCCESSFUL"); } else { try { NgrokLan.LOGGER.info("Launched Lan!"); + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.startMessage").formatted(Formatting.YELLOW)); @@ -107,43 +104,46 @@ private void ngrokInit(int port, Region region) { // Print in chat the status of the tunnel, and the details copied to the clipboard mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.success").formatted(Formatting.GREEN)); - Text copyText = Texts.bracketed((Text.translatable(ngrok_url)).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, ngrok_url)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("chat.copy.click"))).withInsertion(ngrok_url))); - mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.ip", copyText)); + Text copyText = Texts.bracketed((Text.literal(ngrok_url)).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, ngrok_url)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("chat.copy.click"))).withInsertion(ngrok_url))); + mc.inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.ip", copyText)); mc.keyboard.setClipboard(ngrok_url); // This starts the LAN server and greys out the open to lan button - MutableText textStart; + Text text; + if (this.client.getServer().openToLan(this.gameMode, this.allowCommands, port)) { mc.getServer().setOnlineMode(config.onlineCheckBox); - textStart = Text.translatable("commands.publish.started", port); + text = Text.translatable("commands.publish.started", port); NgrokLan.serverOpen = true; - //I made a new thread that reads the json files to update the oplist and whitelist in the playermanager + //TODO: make sure this works, I make a new thread that reads the json files to update the oplist and whitelist in the playermanager Thread thread2 = new Thread(() -> { + NgrokLan.LOGGER.info("debug THREAD2 STARTED"); - boolean loaded = loadJson(); - if(loaded){ - MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.reload.success").styled(style -> style.withColor(Formatting.GREEN) )); + boolean result = loadJson(); + if(!result){ + Text commandText = Texts.bracketed((Text.translatable("text.info.ngroklan.reload.prompt")).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reloadngroklanlists")).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("text.info.ngroklan.reload.prompt"))))); + mc.inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.reload.message")); + mc.inGameHud.getChatHud().addMessage(commandText); } else{ - Text commandText = Texts.bracketed((Text.translatable("text.info.ngroklan.reload.prompt")).styled((style) -> style.withColor(Formatting.RED).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reloadngroklanlists")).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("text.info.ngroklan.reload.prompt"))))); - mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.reload.message")); - mc.inGameHud.getChatHud().addMessage(commandText); + mc.inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.reload.success")); } }); + NgrokLan.LOGGER.info("debug THREAD2 STARTING"); thread2.start(); } else { - textStart = Text.translatable("commands.publish.failed"); + text = Text.translatable("commands.publish.failed"); NgrokLan.serverOpen = false; } - this.client.inGameHud.getChatHud().addMessage(textStart); + this.client.inGameHud.getChatHud().addMessage(text); this.client.updateWindowTitle(); } catch (Exception error) { @@ -162,23 +162,41 @@ private void ngrokInit(int port, Region region) { } private boolean loadJson(){ - PlayerManager playerManager = this.client.getServer().getPlayerManager(); + NgrokLan.LOGGER.info("debug LOADING JSON"); - Whitelist whitelist = playerManager.getWhitelist(); - OperatorList opList = playerManager.getOpList(); + int i; + boolean bl3 = false; - try { - whitelist.load(); - opList.load(); + for(i = 0; !bl3 && i <= 2; ++i) { + if (i > 0) { + NgrokLan.LOGGER.warn("Encountered a problem while converting the op list, retrying in a few seconds"); + this.sleepFiveSeconds(); + } + + bl3 = ServerConfigHandler.convertOperators(this.client.getServer()); + //fail is false + } + + boolean bl4 = false; + for(i = 0; !bl4 && i <= 2; ++i) { + if (i > 0) { + NgrokLan.LOGGER.warn("Encountered a problem while converting the whitelist, retrying in a few seconds"); + this.sleepFiveSeconds(); + } - } catch (Exception e) { - return false; + bl4 = ServerConfigHandler.convertWhitelist(this.client.getServer()); + //fail is false } - return true; + return bl3 && bl4; } - + private void sleepFiveSeconds() { + try { + Thread.sleep(5000L); + } catch (InterruptedException var2) { + } + } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json deleted file mode 100644 index 52ee59d..0000000 --- a/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "schemaVersion": 1, - "id": "ngroklan", - "version": "${version}", - - "name": "Ngrok LAN", - "description": "Exposes your local LAN server to the internet with Ngrok.", - "authors": [ - "Peter Zhang (alujjdnd)", - "Flooflez" - ], - "contact": { - "homepage": "https://github.com/Alujjdnd/Ngrok-LAN", - "sources": "https://github.com/Alujjdnd/Ngrok-LAN", - "issues": "https://github.com/Alujjdnd/Ngrok-LAN/issues" - }, - - "license": "MIT", - "icon": "assets/ngroklan/icon.png", - - "environment": "*", - "entrypoints": { - "main": [ - "alujjdnd.ngrok.lan.NgrokLan" - ], - "server": [ - "alujjdnd.ngrok.lan.NgrokServerInitialiser" - ], - "modmenu": [ - "alujjdnd.ngrok.lan.config.ModMenuIntegration" - ] - }, - - "mixins": [ - "ngroklan.mixins.json" - ], - - "depends": { - "fabricloader": ">=0.14.6", - "fabric": "*", - "minecraft": "~1.19", - "java": ">=17" - }, - "suggests": { - "another-mod": "*" - } -} diff --git a/src/main/resources/quilt.mod.json b/src/main/resources/quilt.mod.json new file mode 100644 index 0000000..c6558fc --- /dev/null +++ b/src/main/resources/quilt.mod.json @@ -0,0 +1,51 @@ +{ + "schema_version": 1, + "quilt_loader": { + "group": "alujjdnd.ngrok.lan", + "id": "ngroklan", + "version": "${version}", + "metadata": { + "name": "Ngrok LAN", + "description": "Exposes your local LAN server to the internet with Ngrok.", + "authors": [ + "Peter Zhang (alujjdnd)", + "Flooflez" + ], + "contact": { + "homepage": "https://github.com/Alujjdnd/Ngrok-LAN", + "sources": "https://github.com/Alujjdnd/Ngrok-LAN", + "issues": "https://github.com/Alujjdnd/Ngrok-LAN/issues" + }, + + "license": "MIT", + "icon": "assets/ngroklan/icon.png" + }, + "intermediate_mappings": "net.fabricmc:intermediary", + "entrypoints": { + "init": [ + "alujjdnd.ngrok.lan.NgrokLan" + ], + "server": [ + "alujjdnd.ngrok.lan.NgrokServerInitialiser" + ], + "modmenu": [ + "alujjdnd.ngrok.lan.config.ModMenuIntegration" + ] + }, + "depends": [ + { + "id": "quilt_loader", + "versions": ">=0.17.0-" + }, + { + "id": "quilted_fabric_api", + "versions": ">=2.0.0-" + }, + { + "id": "minecraft", + "versions": ">=1.19" + } + ] + }, + "mixin": "ngroklan.mixins.json" +} From bdddb74582aa690ca3271ee615fd3abd3778b4bb Mon Sep 17 00:00:00 2001 From: Mikolaj Date: Mon, 11 Jul 2022 21:33:08 +0200 Subject: [PATCH 7/9] Update buildscripts and dependencies --- build.gradle | 27 ++++++++++++++------------- gradle/libs.versions.toml | 7 ++++++- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 396a9d8..e1fe95d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,8 @@ plugins { - id 'maven-publish' alias(libs.plugins.quilt.loom) + id 'maven-publish' id 'com.github.johnrengelman.shadow' version '7.1.2' + id 'java' id "com.modrinth.minotaur" version "2.+" } @@ -33,20 +34,15 @@ dependencies { // QSL is not a complete API; You will need Quilted Fabric API to fill in the gaps. // Quilted Fabric API will automatically pull in the correct QSL version. modImplementation libs.quilted.fabric.api - // modImplementation libs.bundles.quilted.fabric.api // If you wish to use Fabric API's deprecated modules, you can replace the above line with this one - - //Java-Ngrok, a wrapper for the Ngrok service by providing a handy Java API to call it. - modImplementation(include("com.github.alexdlaird:java-ngrok:1.5.6")) - modImplementation(include("org.yaml:snakeyaml:1.30")) - - modApi("me.shedaniel.cloth:cloth-config-fabric:7.0.72") { + // Java-Ngrok, a wrapper for the Ngrok service by providing a handy Java API to call it. + modImplementation(include("com.github.alexdlaird:java-ngrok:${libs.versions.java.ngrok.get()}")) + // Cloth config + modApi("me.shedaniel.cloth:cloth-config-fabric:${libs.versions.cloth.config.get()}") { exclude(group: "net.fabricmc.fabric-api") } - - modImplementation(include("blue.endless:jankson:1.2.1")) - - modImplementation(include("com.terraformersmc:modmenu:4.0.0")) + // Mod menu + modImplementation(include("com.terraformersmc:modmenu:${libs.versions.modmenu.get()}")) } processResources { @@ -59,7 +55,6 @@ processResources { tasks.withType(JavaCompile).configureEach { it.options.encoding = "UTF-8" - // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. it.options.release = 17 } @@ -84,6 +79,12 @@ jar { } } +shadowJar { + manifest { + attributes 'Main-Class': 'com.example.ApplicationKt' + } +} + // Configure the maven publication publishing { publications { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a9687a5..5352d4a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,10 +2,15 @@ # The latest versions are available at https://lambdaurora.dev/tools/import_quilt.html minecraft = "1.19" quilt_mappings = "1.19+build.1" -quilt_loader = "0.17.0" +quilt_loader = "0.17.1-beta.6" quilted_fabric_api = "2.0.0-beta.5+0.57.0-1.19" +# Dependencies +java_ngrok = "1.5.6" +cloth_config = "7.0.72" +modmenu = "4.0.0" + [libraries] minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" } quilt_mappings = { module = "org.quiltmc:quilt-mappings", version.ref = "quilt_mappings" } From 6ee786b2d779026e42071cf6b0f936dd97043771 Mon Sep 17 00:00:00 2001 From: Mikolaj Date: Mon, 11 Jul 2022 22:25:34 +0200 Subject: [PATCH 8/9] Small refactors and updates --- .../java/alujjdnd/ngrok/lan/NgrokLan.java | 23 +- .../ngrok/lan/NgrokLanServerInitializer.java | 26 ++ .../ngrok/lan/NgrokServerInitialiser.java | 39 --- .../ngrok/lan/command/LanDeopCommand.java | 24 +- .../ngrok/lan/command/LanOpCommand.java | 33 +- .../lan/command/LanWhitelistCommand.java | 254 +++++++------- .../lan/command/ReloadJsonListsCommand.java | 77 ++--- .../ngrok/lan/config/ModMenuIntegration.java | 3 +- .../ngrok/lan/mixin/CloseTunnelMixin.java | 5 +- .../ngrok/lan/mixin/OpenToLanScreenMixin.java | 318 ++++++++---------- .../ngrok/lan/mixin/PlayerManagerMixin.java | 11 - .../ngrok/lan/mixin/SpawnProtectionMixin.java | 17 +- .../ngrok/lan/mixin/WindowTitleMixin.java | 8 +- .../resources/assets/ngroklan/lang/en_us.json | 2 +- src/main/resources/ngroklan.mixins.json | 1 + src/main/resources/quilt.mod.json | 2 +- 16 files changed, 379 insertions(+), 464 deletions(-) create mode 100644 src/main/java/alujjdnd/ngrok/lan/NgrokLanServerInitializer.java delete mode 100644 src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java diff --git a/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java b/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java index a25f955..b3d8029 100644 --- a/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java +++ b/src/main/java/alujjdnd/ngrok/lan/NgrokLan.java @@ -5,50 +5,33 @@ import alujjdnd.ngrok.lan.command.LanWhitelistCommand; import alujjdnd.ngrok.lan.command.ReloadJsonListsCommand; import com.github.alexdlaird.ngrok.NgrokClient; -import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import org.quiltmc.loader.api.ModContainer; import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; +import org.quiltmc.qsl.command.api.CommandRegistrationCallback; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import alujjdnd.ngrok.lan.config.NLanConfig; import me.shedaniel.autoconfig.AutoConfig; import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer; - - - public class NgrokLan implements ModInitializer { - // This logger is used to write text to the console and the log file. - // It is considered best practice to use your mod id as the logger's name. - // That way, it's clear which mod wrote info, warnings, and errors. - public static final String MODID = "ngroklan"; - public static final Logger LOGGER = LoggerFactory.getLogger(MODID); public static NgrokClient ngrokClient; - public static boolean serverOpen = false; @Override public void onInitialize(ModContainer mod) { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - LOGGER.info("Minecraft started with Ngrok LAN"); AutoConfig.register(NLanConfig.class, JanksonConfigSerializer::new); - //register commands - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, dedicated) -> - { + //Register commands + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, dedicated) -> { LanOpCommand.register(dispatcher); LanDeopCommand.register(dispatcher); LanWhitelistCommand.register(dispatcher); ReloadJsonListsCommand.register(dispatcher); }); } - - } diff --git a/src/main/java/alujjdnd/ngrok/lan/NgrokLanServerInitializer.java b/src/main/java/alujjdnd/ngrok/lan/NgrokLanServerInitializer.java new file mode 100644 index 0000000..9be207a --- /dev/null +++ b/src/main/java/alujjdnd/ngrok/lan/NgrokLanServerInitializer.java @@ -0,0 +1,26 @@ +package alujjdnd.ngrok.lan; + +import alujjdnd.ngrok.lan.command.LanDeopCommand; +import alujjdnd.ngrok.lan.command.LanOpCommand; +import alujjdnd.ngrok.lan.command.LanWhitelistCommand; +import alujjdnd.ngrok.lan.command.ReloadJsonListsCommand; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import org.quiltmc.loader.api.ModContainer; +import org.quiltmc.qsl.base.api.entrypoint.server.DedicatedServerModInitializer; +import org.quiltmc.qsl.command.api.CommandRegistrationCallback; + +@Environment(EnvType.SERVER) +public class NgrokLanServerInitializer implements DedicatedServerModInitializer { + @Override + // Initialize the different parts of the mod when launched on server + public void onInitializeServer(ModContainer mod) { + NgrokLan.LOGGER.info("World is Open to LAN with Ngrok LAN"); + + // Initialize the different parts of the mod when launched on server + CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> LanOpCommand.register(dispatcher))); + CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> LanDeopCommand.register(dispatcher))); + CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> LanWhitelistCommand.register(dispatcher))); + CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> ReloadJsonListsCommand.register(dispatcher))); + } +} diff --git a/src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java b/src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java deleted file mode 100644 index be0d934..0000000 --- a/src/main/java/alujjdnd/ngrok/lan/NgrokServerInitialiser.java +++ /dev/null @@ -1,39 +0,0 @@ -package alujjdnd.ngrok.lan; - - -import alujjdnd.ngrok.lan.command.LanDeopCommand; -import alujjdnd.ngrok.lan.command.LanOpCommand; -import alujjdnd.ngrok.lan.command.LanWhitelistCommand; -import alujjdnd.ngrok.lan.command.ReloadJsonListsCommand; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; -import net.minecraft.server.dedicated.DedicatedServer; -import org.quiltmc.loader.api.ModContainer; -import org.quiltmc.qsl.base.api.entrypoint.server.DedicatedServerModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Environment(EnvType.SERVER) -public class NgrokServerInitialiser implements DedicatedServerModInitializer -{ - - public static final Logger LOGGER = LoggerFactory.getLogger(NgrokLan.MODID); - - @Override - // Initialize the differents parts of the mod when lauched on server - public void onInitializeServer(ModContainer mod) - { - LOGGER.info("World is Open to LAN with Ngrok LAN"); - - //register commands - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, dedicated) -> - { - LanOpCommand.register(dispatcher); - LanDeopCommand.register(dispatcher); - LanWhitelistCommand.register(dispatcher); - ReloadJsonListsCommand.register(dispatcher); - }); - } - -} diff --git a/src/main/java/alujjdnd/ngrok/lan/command/LanDeopCommand.java b/src/main/java/alujjdnd/ngrok/lan/command/LanDeopCommand.java index dcb17b0..3e524d6 100644 --- a/src/main/java/alujjdnd/ngrok/lan/command/LanDeopCommand.java +++ b/src/main/java/alujjdnd/ngrok/lan/command/LanDeopCommand.java @@ -2,7 +2,6 @@ import com.mojang.authlib.GameProfile; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.minecraft.command.CommandSource; @@ -17,17 +16,14 @@ public class LanDeopCommand { private static final SimpleCommandExceptionType ALREADY_DEOPPED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.deop.failed")); - public LanDeopCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder) CommandManager.literal("deop").requires((source) -> { - return source.hasPermissionLevel(3); - })).then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { - return CommandSource.suggestMatching((context.getSource()).getServer().getPlayerManager().getOpNames(), builder); - }).executes((context) -> { - return deop(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))); + public static void register(CommandDispatcher dispatcher) { + dispatcher.register((CommandManager.literal("deop").requires((source) -> + source.hasPermissionLevel(3) + )).then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> + CommandSource.suggestMatching((context.getSource()).getServer().getPlayerManager().getOpNames(), builder) + ).executes((context) -> + deop(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")) + ))); } private static int deop(ServerCommandSource source, Collection targets) throws CommandSyntaxException { @@ -42,9 +38,9 @@ private static int deop(ServerCommandSource source, Collection targ } } - if (i == 0) { + if (i == 0) throw ALREADY_DEOPPED_EXCEPTION.create(); - } else { + else { source.getServer().kickNonWhitelistedPlayers(source); return i; } diff --git a/src/main/java/alujjdnd/ngrok/lan/command/LanOpCommand.java b/src/main/java/alujjdnd/ngrok/lan/command/LanOpCommand.java index 4d743f3..559572b 100644 --- a/src/main/java/alujjdnd/ngrok/lan/command/LanOpCommand.java +++ b/src/main/java/alujjdnd/ngrok/lan/command/LanOpCommand.java @@ -2,7 +2,6 @@ import com.mojang.authlib.GameProfile; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.minecraft.command.CommandSource; @@ -17,22 +16,19 @@ public class LanOpCommand { private static final SimpleCommandExceptionType ALREADY_OPPED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.op.failed")); - public LanOpCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder) CommandManager.literal("op").requires((source) -> { - return source.hasPermissionLevel(3); - })).then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { + public static void register(CommandDispatcher dispatcher) { + dispatcher.register((CommandManager.literal("op").requires((source) -> + source.hasPermissionLevel(3) + )).then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { PlayerManager playerManager = (context.getSource()).getServer().getPlayerManager(); - return CommandSource.suggestMatching(playerManager.getPlayerList().stream().filter((player) -> { - return !playerManager.isOperator(player.getGameProfile()); - }).map((player) -> { - return player.getGameProfile().getName(); - }), builder); - }).executes((context) -> { - return op(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))); + return CommandSource.suggestMatching(playerManager.getPlayerList().stream().filter((player) -> + !playerManager.isOperator(player.getGameProfile()) + ).map((player) -> + player.getGameProfile().getName() + ), builder); + }).executes((context) -> + op(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")) + ))); } private static int op(ServerCommandSource source, Collection targets) throws CommandSyntaxException { @@ -47,10 +43,9 @@ private static int op(ServerCommandSource source, Collection target } } - if (i == 0) { + if (i == 0) throw ALREADY_OPPED_EXCEPTION.create(); - } else { + else return i; - } } } diff --git a/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java b/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java index 9b8de63..9fecf3e 100644 --- a/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java +++ b/src/main/java/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java @@ -1,8 +1,8 @@ package alujjdnd.ngrok.lan.command; +import com.google.common.collect.Lists; import com.mojang.authlib.GameProfile; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.minecraft.command.CommandSource; @@ -12,126 +12,146 @@ import net.minecraft.server.WhitelistEntry; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import net.minecraft.text.Texts; import java.util.Collection; +import java.util.List; public class LanWhitelistCommand { - private static final SimpleCommandExceptionType ALREADY_ON_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.alreadyOn")); - private static final SimpleCommandExceptionType ALREADY_OFF_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.alreadyOff")); - private static final SimpleCommandExceptionType ADD_FAILED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.add.failed")); - private static final SimpleCommandExceptionType REMOVE_FAILED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.remove.failed")); - - public LanWhitelistCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) CommandManager.literal("whitelist").requires((source) -> { - return source.hasPermissionLevel(3); - })).then(CommandManager.literal("on").executes((context) -> { - return executeOn(context.getSource()); - })).then(CommandManager.literal("off").executes((context) -> { - return executeOff(context.getSource()); - })).then(CommandManager.literal("list").executes((context) -> { - return executeList(context.getSource()); - })).then(CommandManager.literal("add").then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { - PlayerManager playerManager = context.getSource().getServer().getPlayerManager(); - return CommandSource.suggestMatching(playerManager.getPlayerList().stream().filter((player) -> { - return !playerManager.getWhitelist().isAllowed(player.getGameProfile()); - }).map((player) -> { - return player.getGameProfile().getName(); - }), builder); - }).executes((context) -> { - return executeAdd(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))).then(CommandManager.literal("remove").then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { - return CommandSource.suggestMatching(context.getSource().getServer().getPlayerManager().getWhitelistedNames(), builder); - }).executes((context) -> { - return executeRemove(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))).then(CommandManager.literal("reload").executes((context) -> { - return executeReload(context.getSource()); - }))); - } - - private static int executeReload(ServerCommandSource source) { - source.getServer().getPlayerManager().reloadWhitelist(); - source.sendFeedback(Text.translatable("commands.whitelist.reloaded"), true); - source.getServer().kickNonWhitelistedPlayers(source); - return 1; - } - - private static int executeAdd(ServerCommandSource source, Collection targets) throws CommandSyntaxException { - Whitelist whitelist = source.getServer().getPlayerManager().getWhitelist(); - int i = 0; - - for (GameProfile gameProfile : targets) { - if (!whitelist.isAllowed(gameProfile)) { - WhitelistEntry whitelistEntry = new WhitelistEntry(gameProfile); - whitelist.add(whitelistEntry); - source.sendFeedback(Text.translatable("commands.whitelist.add.success", Texts.toText(gameProfile)), true); - ++i; - } - } - - if (i == 0) { - throw ADD_FAILED_EXCEPTION.create(); - } else { - return i; - } - } - - private static int executeRemove(ServerCommandSource source, Collection targets) throws CommandSyntaxException { - Whitelist whitelist = source.getServer().getPlayerManager().getWhitelist(); - int i = 0; - - for (GameProfile gameProfile : targets) { - if (whitelist.isAllowed(gameProfile)) { - WhitelistEntry whitelistEntry = new WhitelistEntry(gameProfile); - whitelist.remove(whitelistEntry); - source.sendFeedback(Text.translatable("commands.whitelist.remove.success", Texts.toText(gameProfile)), true); - ++i; - } - } - - if (i == 0) { - throw REMOVE_FAILED_EXCEPTION.create(); - } else { - source.getServer().kickNonWhitelistedPlayers(source); - return i; - } - } - - private static int executeOn(ServerCommandSource source) throws CommandSyntaxException { - PlayerManager playerManager = source.getServer().getPlayerManager(); - if (playerManager.isWhitelistEnabled()) { - throw ALREADY_ON_EXCEPTION.create(); - } else { - playerManager.setWhitelistEnabled(true); - source.sendFeedback(Text.translatable("commands.whitelist.enabled"), true); - source.getServer().kickNonWhitelistedPlayers(source); - return 1; - } - } - - private static int executeOff(ServerCommandSource source) throws CommandSyntaxException { - PlayerManager playerManager = source.getServer().getPlayerManager(); - if (!playerManager.isWhitelistEnabled()) { - throw ALREADY_OFF_EXCEPTION.create(); - } else { - playerManager.setWhitelistEnabled(false); - source.sendFeedback(Text.translatable("commands.whitelist.disabled"), true); - return 1; - } - } - - private static int executeList(ServerCommandSource source) { - String[] strings = source.getServer().getPlayerManager().getWhitelistedNames(); - if (strings.length == 0) { - source.sendFeedback(Text.translatable("commands.whitelist.none"), false); - } else { - source.sendFeedback(Text.translatable("commands.whitelist.list", strings.length, String.join(", ", strings)), false); - } - - return strings.length; - } + private static final SimpleCommandExceptionType ALREADY_ON_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.alreadyOn")); + private static final SimpleCommandExceptionType ALREADY_OFF_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.alreadyOff")); + private static final SimpleCommandExceptionType ADD_FAILED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.add.failed")); + private static final SimpleCommandExceptionType REMOVE_FAILED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.whitelist.remove.failed")); + + public static void register(CommandDispatcher dispatcher) { + dispatcher.register((CommandManager.literal("whitelist").requires((source) -> + source.hasPermissionLevel(3) + )).then(CommandManager.literal("on").executes((context) -> + executeOn(context.getSource()) + )).then(CommandManager.literal("off").executes((context) -> + executeOff(context.getSource()) + )).then(CommandManager.literal("list").executes((context) -> + executeList(context.getSource()) + )).then(CommandManager.literal("add").then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { + PlayerManager playerManager = context.getSource().getServer().getPlayerManager(); + return CommandSource.suggestMatching(playerManager.getPlayerList().stream().filter((player) -> + !playerManager.getWhitelist().isAllowed(player.getGameProfile()) + ).map((player) -> + player.getGameProfile().getName() + ), builder); + }).executes((context) -> + executeAdd(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")) + ))).then(CommandManager.literal("remove").then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> + CommandSource.suggestMatching(context.getSource().getServer().getPlayerManager().getWhitelistedNames(), builder) + ).executes((context) -> + executeRemove(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")) + ))).then(CommandManager.literal("reload").executes((context) -> + executeReload(context.getSource()) + ))); + } + + private static int executeReload(ServerCommandSource source) { + source.getServer().getPlayerManager().reloadWhitelist(); + source.sendFeedback(Text.translatable("commands.whitelist.reloaded"), true); + kickNonWhitelistedPlayers(source); + + return 1; + } + + private static int executeAdd(ServerCommandSource source, Collection targets) throws CommandSyntaxException { + Whitelist whitelist = source.getServer().getPlayerManager().getWhitelist(); + int i = 0; + + for (GameProfile gameProfile : targets) { + if (!whitelist.isAllowed(gameProfile)) { + WhitelistEntry whitelistEntry = new WhitelistEntry(gameProfile); + whitelist.add(whitelistEntry); + source.sendFeedback(Text.translatable("commands.whitelist.add.success", Texts.toText(gameProfile)), true); + ++i; + } + } + + if (i == 0) + throw ADD_FAILED_EXCEPTION.create(); + else + return i; + } + + private static int executeRemove(ServerCommandSource source, Collection targets) throws CommandSyntaxException { + Whitelist whitelist = source.getServer().getPlayerManager().getWhitelist(); + int i = 0; + + for (GameProfile gameProfile : targets) { + if (whitelist.isAllowed(gameProfile)) { + WhitelistEntry whitelistEntry = new WhitelistEntry(gameProfile); + whitelist.remove(whitelistEntry); + source.sendFeedback(Text.translatable("commands.whitelist.remove.success", Texts.toText(gameProfile)), true); + ++i; + } + } + + if (i == 0) + throw REMOVE_FAILED_EXCEPTION.create(); + else { + kickNonWhitelistedPlayers(source); + return i; + } + } + + private static int executeOn(ServerCommandSource source) throws CommandSyntaxException { + PlayerManager playerManager = source.getServer().getPlayerManager(); + + if (playerManager.isWhitelistEnabled()) + throw ALREADY_ON_EXCEPTION.create(); + else { + playerManager.setWhitelistEnabled(true); + source.sendFeedback(Text.translatable("commands.whitelist.enabled"), true); + kickNonWhitelistedPlayers(source); + + return 1; + } + } + + private static int executeOff(ServerCommandSource source) throws CommandSyntaxException { + PlayerManager playerManager = source.getServer().getPlayerManager(); + + if (!playerManager.isWhitelistEnabled()) + throw ALREADY_OFF_EXCEPTION.create(); + else { + playerManager.setWhitelistEnabled(false); + source.sendFeedback(Text.translatable("commands.whitelist.disabled"), true); + + return 1; + } + } + + private static int executeList(ServerCommandSource source) { + String[] strings = source.getServer().getPlayerManager().getWhitelistedNames(); + + if (strings.length == 0) + source.sendFeedback(Text.translatable("commands.whitelist.none"), false); + else + source.sendFeedback(Text.translatable("commands.whitelist.list", strings.length, String.join(", ", strings)), false); + + return strings.length; + } + private static void kickNonWhitelistedPlayers(ServerCommandSource source){ + PlayerManager playerManager = source.getServer().getPlayerManager(); + + if (playerManager.isWhitelistEnabled()) { + Whitelist whitelist = playerManager.getWhitelist(); + List list = Lists.newArrayList(playerManager.getPlayerList()); + + for (ServerPlayerEntity serverPlayerEntity : list) { + GameProfile profile = serverPlayerEntity.getGameProfile(); + + if(!source.getServer().isHost(profile)){ + if (!whitelist.isAllowed(profile) && !playerManager.isOperator(profile)) + serverPlayerEntity.networkHandler.disconnect(Text.translatable("multiplayer.disconnect.not_whitelisted")); + } + } + } + } } diff --git a/src/main/java/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java b/src/main/java/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java index 43dfd35..ddb2a34 100644 --- a/src/main/java/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java +++ b/src/main/java/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java @@ -1,63 +1,40 @@ package alujjdnd.ngrok.lan.command; -import alujjdnd.ngrok.lan.NgrokLan; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.minecraft.client.MinecraftClient; -import net.minecraft.command.CommandSource; -import net.minecraft.command.argument.GameProfileArgumentType; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.ServerConfigHandler; +import net.minecraft.server.*; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; public class ReloadJsonListsCommand { - - //check if player has permission (same permission level as /op and /deop) - //run loadJson(); - //get source.getServer() from command - - private static final SimpleCommandExceptionType LOAD_JSON_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("text.info.ngroklan.reload.message")); - - public ReloadJsonListsCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register(CommandManager.literal("reloadngroklanlists") - .requires(source -> source.hasPermissionLevel(3)) - .executes(ReloadJsonListsCommand::loadJson)); - } - - private static int loadJson(CommandContext serverCommandSourceCommandContext) throws CommandSyntaxException { - MinecraftServer server = serverCommandSourceCommandContext.getSource().getServer(); - - boolean bl3 = ServerConfigHandler.convertOperators(server); - - boolean bl4 = ServerConfigHandler.convertWhitelist(server); - - - if(! (bl3 && bl4) ){ - throw LOAD_JSON_EXCEPTION.create(); - } - else{ - MinecraftClient.getInstance().inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.reload.success")); - } - - return 1; - } - - - - - private static void sleepFiveSeconds() { - try { - Thread.sleep(5000L); - } catch (InterruptedException ignored) { - } - } + private static final SimpleCommandExceptionType LOAD_JSON_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("text.info.ngroklan.reload.message")); + + public static void register(CommandDispatcher dispatcher) { + dispatcher.register(CommandManager.literal("reloadngroklanlists") + .requires(source -> source.hasPermissionLevel(3)) + .executes(ReloadJsonListsCommand::loadJson)); + } + + private static int loadJson(CommandContext serverCommandSourceCommandContext) throws CommandSyntaxException { + PlayerManager playerManager = serverCommandSourceCommandContext.getSource().getServer().getPlayerManager(); + Whitelist whitelist = playerManager.getWhitelist(); + OperatorList opList = playerManager.getOpList(); + + try { + whitelist.load(); + opList.load(); + + MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.reload.success").styled(style -> style.withColor(Formatting.GREEN) )); + } + catch (Exception e) { + throw LOAD_JSON_EXCEPTION.create(); + } + + return 1; + } } diff --git a/src/main/java/alujjdnd/ngrok/lan/config/ModMenuIntegration.java b/src/main/java/alujjdnd/ngrok/lan/config/ModMenuIntegration.java index 0bf988d..7691fed 100644 --- a/src/main/java/alujjdnd/ngrok/lan/config/ModMenuIntegration.java +++ b/src/main/java/alujjdnd/ngrok/lan/config/ModMenuIntegration.java @@ -4,8 +4,7 @@ import com.terraformersmc.modmenu.api.ModMenuApi; import me.shedaniel.autoconfig.AutoConfig; -public class ModMenuIntegration implements ModMenuApi -{ +public class ModMenuIntegration implements ModMenuApi { @Override public ConfigScreenFactory getModConfigScreenFactory() { return parent -> AutoConfig.getConfigScreen(NLanConfig.class, parent).get(); diff --git a/src/main/java/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java b/src/main/java/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java index 0437b3f..7da7a53 100644 --- a/src/main/java/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java +++ b/src/main/java/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java @@ -1,6 +1,5 @@ package alujjdnd.ngrok.lan.mixin; - import alujjdnd.ngrok.lan.NgrokLan; import net.minecraft.server.MinecraftServer; import org.spongepowered.asm.mixin.Mixin; @@ -12,12 +11,10 @@ public abstract class CloseTunnelMixin { @Inject(at = @At("TAIL"), method = "shutdown") private void afterShutdownServer(CallbackInfo info) { - if(NgrokLan.serverOpen){ + if(NgrokLan.serverOpen) { NgrokLan.LOGGER.info("Closing Ngrok LAN!"); NgrokLan.ngrokClient.kill(); NgrokLan.serverOpen = false; } - } - } diff --git a/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java b/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java index afd9c30..cd67ebf 100644 --- a/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java +++ b/src/main/java/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java @@ -1,6 +1,5 @@ package alujjdnd.ngrok.lan.mixin; - import alujjdnd.ngrok.lan.NgrokLan; import alujjdnd.ngrok.lan.config.NLanConfig; import com.github.alexdlaird.ngrok.NgrokClient; @@ -15,8 +14,14 @@ import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.NetworkUtils; -import net.minecraft.server.ServerConfigHandler; -import net.minecraft.text.*; +import net.minecraft.server.OperatorList; +import net.minecraft.server.PlayerManager; +import net.minecraft.server.Whitelist; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.HoverEvent; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import net.minecraft.text.Texts; import net.minecraft.util.Formatting; import net.minecraft.world.GameMode; import org.spongepowered.asm.mixin.Mixin; @@ -25,178 +30,147 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.Objects; + @Mixin(OpenToLanScreen.class) public class OpenToLanScreenMixin extends Screen { + final NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); + final MinecraftClient mc = MinecraftClient.getInstance(); + + @Shadow + private GameMode gameMode; + @Shadow + private boolean allowCommands; + + protected OpenToLanScreenMixin(Text title) { + super(title); + } + + @Inject(method = "init", at = @At("HEAD")) + private void initWidgets(CallbackInfo info) { + if (config.enabledCheckBox) { //if mod enabled in mod menu + this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height - 58, 150, 20, Text.translatable("text.UI.ngroklan.LanButton"), (button) -> { + int localPort = NetworkUtils.findLocalPort(); // part of the minecraft NetworkUtils class, finds an available local port (this was from the openToLan class) + mc.setScreen(null); // Removed all elements from the screen (this closes all menu windows) + + switch (config.regionSelect) { + case EU -> ngrokInit(localPort, Region.EU); + case AP -> ngrokInit(localPort, Region.AP); + case AU -> ngrokInit(localPort, Region.AU); + case SA -> ngrokInit(localPort, Region.SA); + case JP -> ngrokInit(localPort, Region.JP); + case IN -> ngrokInit(localPort, Region.IN); + default -> ngrokInit(localPort, Region.US); //US bundled here + } + })); + } + } + + + private void ngrokInit(int port, Region region) { + //Defines a new threaded function to open the Ngrok tunnel, so that the "Open to LAN" button does not hitch - this thread runs in a separate process from the main game loop + Thread thread = new Thread(() -> { + if (config.authToken.equals("AuthToken")) { + // Check if authToken field has actually been changed, if not, print this text in chat + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.error.ngroklan.AuthTokenError").formatted(Formatting.RED)); + NgrokLan.LOGGER.error("Launched Lan UNSUCCESSFUL"); + } + else { + try { + NgrokLan.LOGGER.info("Launched Lan!"); + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.startMessage").formatted(Formatting.YELLOW)); + + + // Java-ngrok wrapper code, to initiate the tunnel, with the auth token, region + final JavaNgrokConfig javaNgrokConfig = new JavaNgrokConfig.Builder() + .withAuthToken(config.authToken) + .withRegion(region) + .build(); + + NgrokLan.ngrokClient = new NgrokClient.Builder() + .withJavaNgrokConfig(javaNgrokConfig) + .build(); + + final CreateTunnel createTunnel = new CreateTunnel.Builder() + .withProto(Proto.TCP) + .withAddr(port) + .build(); + + final Tunnel tunnel = NgrokLan.ngrokClient.connect(createTunnel); + + NgrokLan.LOGGER.info(tunnel.getPublicUrl()); + + var ngrok_url = tunnel.getPublicUrl().substring(6); + + // Print in chat the status of the tunnel, and the details copied to the clipboard + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.success").formatted(Formatting.GREEN)); + Text copyText = Texts.bracketed((Text.translatable(ngrok_url)).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, ngrok_url)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("chat.copy.click"))).withInsertion(ngrok_url))); + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.ip", copyText)); + mc.keyboard.setClipboard(ngrok_url); + + + + // This starts the LAN server and greys out the open to lan button + MutableText textStart; + if (mc.getServer() != null && mc.getServer().openToLan(this.gameMode, this.allowCommands, port)) { + mc.getServer().setOnlineMode(config.onlineCheckBox); + textStart = Text.translatable("commands.publish.started", port); + NgrokLan.serverOpen = true; + + //I made a new thread that reads the json files to update the op list and whitelist in the PlayerManager + Thread thread2 = new Thread(() -> { + boolean loaded = loadJson(); + if(loaded) { + MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.reload.success").styled(style -> style.withColor(Formatting.GREEN) )); + } + else { + Text commandText = Texts.bracketed((Text.translatable("text.info.ngroklan.reload.prompt")).styled((style) -> style.withColor(Formatting.RED).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reloadngroklanlists")).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("text.info.ngroklan.reload.prompt"))))); + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.reload.message")); + mc.inGameHud.getChatHud().addMessage(commandText); + } + }); + + thread2.start(); + + } + else { + textStart = Text.translatable("commands.publish.failed"); + NgrokLan.serverOpen = false; + } + + mc.inGameHud.getChatHud().addMessage(textStart); + mc.updateWindowTitle(); + } + catch (Exception error) { + error.printStackTrace(); + mc.inGameHud.getChatHud().addMessage(Text.literal(error.getMessage())); + mc.inGameHud.getChatHud().addMessage(Text.translatable("text.error.ngroklan.fail").formatted(Formatting.RED)); + throw new RuntimeException("Ngrok Service Failed to Start" + error.getMessage()); + } + } + }); + + // This starts the thread defined above + thread.start(); + } + + private boolean loadJson() { + PlayerManager playerManager = Objects.requireNonNull(mc.getServer()).getPlayerManager(); + + Whitelist whitelist = playerManager.getWhitelist(); + OperatorList opList = playerManager.getOpList(); + + try { + whitelist.load(); + opList.load(); + } + catch (Exception e) { + return false; + } + + return true; + } - NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); - MinecraftClient mc = MinecraftClient.getInstance(); - - @Shadow - private GameMode gameMode; - - @Shadow - private boolean allowCommands; - - protected OpenToLanScreenMixin(Text title) { - super(title); - } - - @Inject(method = "init", at = @At("HEAD")) - private void initWidgets(CallbackInfo info) { - - if (config.enabledCheckBox) { //if mod enabled in mod menu - this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height - 58, 150, 20, Text.translatable("text.UI.ngroklan.LanButton"), (button) -> { - int localPort = NetworkUtils.findLocalPort(); // part of the minecraft Networkutils class, finds an available local port (this was from the openToLan class) - this.client.setScreen(null); // Removed all elements from the screen (this closes all menu windows) - switch (config.regionSelect) { - case EU -> ngrokInit(localPort, Region.EU); - case AP -> ngrokInit(localPort, Region.AP); - case AU -> ngrokInit(localPort, Region.AU); - case SA -> ngrokInit(localPort, Region.SA); - case JP -> ngrokInit(localPort, Region.JP); - case IN -> ngrokInit(localPort, Region.IN); - default -> ngrokInit(localPort, Region.US); //US bundled here - } - })); - - } - } - - - private void ngrokInit(int port, Region region) { - - //Defines a new threaded function to oepn the Ngrok tunnel, so that the "Open to LAN" button does not hitch - this thread runs in a seperate process from the main game loop - Thread thread = new Thread(() -> - { - if (config.authToken.equals("AuthToken")) { - // Check if authToken field has actually been changed, if not, print this text in chat - mc.inGameHud.getChatHud().addMessage(Text.translatable("text.error.ngroklan.AuthTokenError")); - mc.inGameHud.getChatHud().addMessage(Text.translatable("text.error.ngroklan.AuthTokenError").formatted(Formatting.RED)); - //\u00a7c - } else { - try { - NgrokLan.LOGGER.info("Launched Lan!"); - - mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.startMessage").formatted(Formatting.YELLOW)); - - - // Java-ngrok wrapper code, to initiate the tunnel, with the authoken, region - final JavaNgrokConfig javaNgrokConfig = new JavaNgrokConfig.Builder() - .withAuthToken(config.authToken) - .withRegion(region) - .build(); - - NgrokLan.ngrokClient = new NgrokClient.Builder() - .withJavaNgrokConfig(javaNgrokConfig) - .build(); - - final CreateTunnel createTunnel = new CreateTunnel.Builder() - .withProto(Proto.TCP) - .withAddr(port) - .build(); - - final Tunnel tunnel = NgrokLan.ngrokClient.connect(createTunnel); - - NgrokLan.LOGGER.info(tunnel.getPublicUrl()); - - var ngrok_url = tunnel.getPublicUrl().substring(6); - - // Print in chat the status of the tunnel, and the details copied to the clipboard - mc.inGameHud.getChatHud().addMessage(Text.translatable("text.info.ngroklan.success").formatted(Formatting.GREEN)); - - Text copyText = Texts.bracketed((Text.literal(ngrok_url)).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, ngrok_url)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("chat.copy.click"))).withInsertion(ngrok_url))); - mc.inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.ip", copyText)); - - mc.keyboard.setClipboard(ngrok_url); - - - - // This starts the LAN server and greys out the open to lan button - Text text; - - - if (this.client.getServer().openToLan(this.gameMode, this.allowCommands, port)) { - mc.getServer().setOnlineMode(config.onlineCheckBox); - text = Text.translatable("commands.publish.started", port); - NgrokLan.serverOpen = true; - - //TODO: make sure this works, I make a new thread that reads the json files to update the oplist and whitelist in the playermanager - Thread thread2 = new Thread(() -> { - - NgrokLan.LOGGER.info("debug THREAD2 STARTED"); - - boolean result = loadJson(); - if(!result){ - Text commandText = Texts.bracketed((Text.translatable("text.info.ngroklan.reload.prompt")).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reloadngroklanlists")).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("text.info.ngroklan.reload.prompt"))))); - mc.inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.reload.message")); - mc.inGameHud.getChatHud().addMessage(commandText); - } - else{ - mc.inGameHud.getChatHud().addMessage( Text.translatable("text.info.ngroklan.reload.success")); - } - }); - - NgrokLan.LOGGER.info("debug THREAD2 STARTING"); - thread2.start(); - - } else { - text = Text.translatable("commands.publish.failed"); - NgrokLan.serverOpen = false; - } - this.client.inGameHud.getChatHud().addMessage(text); - this.client.updateWindowTitle(); - - } catch (Exception error) { - error.printStackTrace(); - mc.inGameHud.getChatHud().addMessage(Text.literal(error.getMessage())); - mc.inGameHud.getChatHud().addMessage(Text.translatable("text.error.ngroklan.fail").formatted(Formatting.RED)); - //ngrokInitiated = false; - throw new RuntimeException("Ngrok Service Failed to Start" + error.getMessage()); - } - } - }); - - // This starts the thread defined above - thread.start(); - - } - - private boolean loadJson(){ - NgrokLan.LOGGER.info("debug LOADING JSON"); - - int i; - boolean bl3 = false; - - for(i = 0; !bl3 && i <= 2; ++i) { - if (i > 0) { - NgrokLan.LOGGER.warn("Encountered a problem while converting the op list, retrying in a few seconds"); - this.sleepFiveSeconds(); - } - - bl3 = ServerConfigHandler.convertOperators(this.client.getServer()); - //fail is false - } - - boolean bl4 = false; - - for(i = 0; !bl4 && i <= 2; ++i) { - if (i > 0) { - NgrokLan.LOGGER.warn("Encountered a problem while converting the whitelist, retrying in a few seconds"); - this.sleepFiveSeconds(); - } - - bl4 = ServerConfigHandler.convertWhitelist(this.client.getServer()); - //fail is false - } - - return bl3 && bl4; - } - private void sleepFiveSeconds() { - try { - Thread.sleep(5000L); - } catch (InterruptedException var2) { - } - } } diff --git a/src/main/java/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java b/src/main/java/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java index b6bcd87..53c75ce 100644 --- a/src/main/java/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java +++ b/src/main/java/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java @@ -1,18 +1,10 @@ package alujjdnd.ngrok.lan.mixin; import alujjdnd.ngrok.lan.NgrokLan; -import alujjdnd.ngrok.lan.config.NLanConfig; import com.mojang.authlib.GameProfile; -import me.shedaniel.autoconfig.AutoConfig; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.MinecraftServer; import net.minecraft.server.PlayerManager; import net.minecraft.server.Whitelist; -import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -24,8 +16,6 @@ @Mixin(PlayerManager.class) public class PlayerManagerMixin { - NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); - @Final @Shadow private Whitelist whitelist; @@ -33,6 +23,5 @@ public class PlayerManagerMixin { @Inject(at = @At("HEAD"), method = "checkCanJoin") public void isSpawnProtected(SocketAddress address, GameProfile profile, CallbackInfoReturnable cir) { NgrokLan.LOGGER.info("Whitelist? " + whitelist.getFile().getAbsolutePath()); - } } diff --git a/src/main/java/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java b/src/main/java/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java index 6f1be6c..e68cc18 100644 --- a/src/main/java/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java +++ b/src/main/java/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java @@ -18,29 +18,30 @@ @Mixin(MinecraftServer.class) public class SpawnProtectionMixin { - - NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); + final NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); @Shadow private PlayerManager playerManager; @Inject(at = @At("HEAD"), method = "isSpawnProtected", cancellable = true) public void isSpawnProtected(ServerWorld world, BlockPos pos, PlayerEntity player, CallbackInfoReturnable cir) { - - if(!NgrokLan.serverOpen){ + if(!NgrokLan.serverOpen) { cir.setReturnValue(false); cir.cancel(); - } else if (config.spawnProtectionRadius <= 0) { + } + else if (config.spawnProtectionRadius <= 0) { cir.setReturnValue(false); cir.cancel(); } else if (world.getRegistryKey() != World.OVERWORLD) { cir.setReturnValue(false); cir.cancel(); - } else if (playerManager.isOperator(player.getGameProfile())) { + } + else if (playerManager.isOperator(player.getGameProfile())) { cir.setReturnValue(false); cir.cancel(); - } else { + } + else { BlockPos blockPos = world.getSpawnPos(); int i = MathHelper.abs(pos.getX() - blockPos.getX()); int j = MathHelper.abs(pos.getZ() - blockPos.getZ()); @@ -48,7 +49,7 @@ else if (world.getRegistryKey() != World.OVERWORLD) { cir.setReturnValue(k <= config.spawnProtectionRadius); cir.cancel(); } - //there's a small diff from vanilla check that checks if Oplist is empty. Since the host + //there's a small diff from vanilla check that checks if op list is empty. Since the host //is an "admin" (more control than op idk the technical term) by default they are not in //the op list, so this check does not work. } diff --git a/src/main/java/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java b/src/main/java/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java index ba7bcd5..98a314b 100644 --- a/src/main/java/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java +++ b/src/main/java/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java @@ -14,11 +14,7 @@ public abstract class WindowTitleMixin { private void injected(CallbackInfoReturnable cir) { StringBuilder stringBuilder2 = new StringBuilder(I18n.translate("text.title.ngroklan.window")); - if(NgrokLan.serverOpen){ + if(NgrokLan.serverOpen) cir.setReturnValue(stringBuilder2.toString()); - } - - } - -} \ No newline at end of file +} diff --git a/src/main/resources/assets/ngroklan/lang/en_us.json b/src/main/resources/assets/ngroklan/lang/en_us.json index 00abc97..0448f9a 100644 --- a/src/main/resources/assets/ngroklan/lang/en_us.json +++ b/src/main/resources/assets/ngroklan/lang/en_us.json @@ -18,4 +18,4 @@ "text.info.ngroklan.reload.prompt" : "Click here to reload", "text.info.ngroklan.reload.message" : "An error occurred loading the whitelist and op list", "text.info.ngroklan.reload.success" : "The whitelist and op list were successfully loaded" -} \ No newline at end of file +} diff --git a/src/main/resources/ngroklan.mixins.json b/src/main/resources/ngroklan.mixins.json index 623a154..6e5b07d 100644 --- a/src/main/resources/ngroklan.mixins.json +++ b/src/main/resources/ngroklan.mixins.json @@ -5,6 +5,7 @@ "compatibilityLevel": "JAVA_17", "mixins": [ "PlayerManagerMixin", + "SpawnProtectionMixin", "WindowTitleMixin" ], "client": [ diff --git a/src/main/resources/quilt.mod.json b/src/main/resources/quilt.mod.json index c6558fc..68d0337 100644 --- a/src/main/resources/quilt.mod.json +++ b/src/main/resources/quilt.mod.json @@ -26,7 +26,7 @@ "alujjdnd.ngrok.lan.NgrokLan" ], "server": [ - "alujjdnd.ngrok.lan.NgrokServerInitialiser" + "alujjdnd.ngrok.lan.NgrokLanServerInitializer" ], "modmenu": [ "alujjdnd.ngrok.lan.config.ModMenuIntegration" From ecc0ef1def9a145e9b326c4618b3f43e5fc35a5e Mon Sep 17 00:00:00 2001 From: Mikolaj Date: Mon, 11 Jul 2022 23:01:47 +0200 Subject: [PATCH 9/9] Remove srcNEW and remappedSrc --- remappedSrc/alujjdnd/ngrok/lan/NgrokLan.java | 53 ----- .../ngrok/lan/NgrokServerInitialiser.java | 37 ---- .../ngrok/lan/command/LanDeopCommand.java | 52 ----- .../ngrok/lan/command/LanOpCommand.java | 56 ----- .../lan/command/LanWhitelistCommand.java | 137 ------------ .../lan/command/ReloadJsonListsCommand.java | 63 ------ .../ngrok/lan/config/ModMenuIntegration.java | 13 -- .../alujjdnd/ngrok/lan/config/NLanConfig.java | 22 -- .../ngrok/lan/mixin/CloseTunnelMixin.java | 23 -- .../ngrok/lan/mixin/OpenToLanScreenMixin.java | 202 ------------------ .../ngrok/lan/mixin/PlayerManagerMixin.java | 38 ---- .../ngrok/lan/mixin/SpawnProtectionMixin.java | 57 ----- .../ngrok/lan/mixin/WindowTitleMixin.java | 24 --- srcNEW/alujjdnd/ngrok/lan/NgrokLan.java | 53 ----- .../ngrok/lan/NgrokServerInitialiser.java | 37 ---- .../ngrok/lan/command/LanDeopCommand.java | 52 ----- .../ngrok/lan/command/LanOpCommand.java | 56 ----- .../lan/command/LanWhitelistCommand.java | 137 ------------ .../lan/command/ReloadJsonListsCommand.java | 63 ------ .../ngrok/lan/config/ModMenuIntegration.java | 13 -- .../alujjdnd/ngrok/lan/config/NLanConfig.java | 22 -- .../ngrok/lan/mixin/CloseTunnelMixin.java | 23 -- .../ngrok/lan/mixin/OpenToLanScreenMixin.java | 202 ------------------ .../ngrok/lan/mixin/PlayerManagerMixin.java | 38 ---- .../ngrok/lan/mixin/SpawnProtectionMixin.java | 57 ----- .../ngrok/lan/mixin/WindowTitleMixin.java | 24 --- 26 files changed, 1554 deletions(-) delete mode 100644 remappedSrc/alujjdnd/ngrok/lan/NgrokLan.java delete mode 100644 remappedSrc/alujjdnd/ngrok/lan/NgrokServerInitialiser.java delete mode 100644 remappedSrc/alujjdnd/ngrok/lan/command/LanDeopCommand.java delete mode 100644 remappedSrc/alujjdnd/ngrok/lan/command/LanOpCommand.java delete mode 100644 remappedSrc/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java delete mode 100644 remappedSrc/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java delete mode 100644 remappedSrc/alujjdnd/ngrok/lan/config/ModMenuIntegration.java delete mode 100644 remappedSrc/alujjdnd/ngrok/lan/config/NLanConfig.java delete mode 100644 remappedSrc/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java delete mode 100644 remappedSrc/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java delete mode 100644 remappedSrc/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java delete mode 100644 remappedSrc/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java delete mode 100644 remappedSrc/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java delete mode 100644 srcNEW/alujjdnd/ngrok/lan/NgrokLan.java delete mode 100644 srcNEW/alujjdnd/ngrok/lan/NgrokServerInitialiser.java delete mode 100644 srcNEW/alujjdnd/ngrok/lan/command/LanDeopCommand.java delete mode 100644 srcNEW/alujjdnd/ngrok/lan/command/LanOpCommand.java delete mode 100644 srcNEW/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java delete mode 100644 srcNEW/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java delete mode 100644 srcNEW/alujjdnd/ngrok/lan/config/ModMenuIntegration.java delete mode 100644 srcNEW/alujjdnd/ngrok/lan/config/NLanConfig.java delete mode 100644 srcNEW/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java delete mode 100644 srcNEW/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java delete mode 100644 srcNEW/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java delete mode 100644 srcNEW/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java delete mode 100644 srcNEW/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java diff --git a/remappedSrc/alujjdnd/ngrok/lan/NgrokLan.java b/remappedSrc/alujjdnd/ngrok/lan/NgrokLan.java deleted file mode 100644 index bbcde24..0000000 --- a/remappedSrc/alujjdnd/ngrok/lan/NgrokLan.java +++ /dev/null @@ -1,53 +0,0 @@ -package alujjdnd.ngrok.lan; - -import alujjdnd.ngrok.lan.command.LanDeopCommand; -import alujjdnd.ngrok.lan.command.LanOpCommand; -import alujjdnd.ngrok.lan.command.LanWhitelistCommand; -import alujjdnd.ngrok.lan.command.ReloadJsonListsCommand; -import com.github.alexdlaird.ngrok.NgrokClient; -import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import alujjdnd.ngrok.lan.config.NLanConfig; -import me.shedaniel.autoconfig.AutoConfig; -import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer; - - - - -public class NgrokLan implements ModInitializer { - // This logger is used to write text to the console and the log file. - // It is considered best practice to use your mod id as the logger's name. - // That way, it's clear which mod wrote info, warnings, and errors. - - public static final String MODID = "ngroklan"; - - public static final Logger LOGGER = LoggerFactory.getLogger(MODID); - - public static NgrokClient ngrokClient; - - public static boolean serverOpen = false; - - @Override - public void onInitialize() { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - - LOGGER.info("Minecraft started with Ngrok LAN"); - AutoConfig.register(NLanConfig.class, JanksonConfigSerializer::new); - - //register commands - CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> - { - LanOpCommand.register(dispatcher); - LanDeopCommand.register(dispatcher); - LanWhitelistCommand.register(dispatcher); - ReloadJsonListsCommand.register(dispatcher); - }); - } - - -} diff --git a/remappedSrc/alujjdnd/ngrok/lan/NgrokServerInitialiser.java b/remappedSrc/alujjdnd/ngrok/lan/NgrokServerInitialiser.java deleted file mode 100644 index f592d44..0000000 --- a/remappedSrc/alujjdnd/ngrok/lan/NgrokServerInitialiser.java +++ /dev/null @@ -1,37 +0,0 @@ -package alujjdnd.ngrok.lan; - - -import alujjdnd.ngrok.lan.command.LanDeopCommand; -import alujjdnd.ngrok.lan.command.LanOpCommand; -import alujjdnd.ngrok.lan.command.LanWhitelistCommand; -import alujjdnd.ngrok.lan.command.ReloadJsonListsCommand; -import net.fabricmc.api.DedicatedServerModInitializer; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Environment(EnvType.SERVER) -public class NgrokServerInitialiser implements DedicatedServerModInitializer -{ - - public static final Logger LOGGER = LoggerFactory.getLogger(NgrokLan.MODID); - - @Override - // Initialize the differents parts of the mod when lauched on server - public void onInitializeServer() - { - LOGGER.info("World is Open to LAN with Ngrok LAN"); - - //register commands - CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> - { - LanOpCommand.register(dispatcher); - LanDeopCommand.register(dispatcher); - LanWhitelistCommand.register(dispatcher); - ReloadJsonListsCommand.register(dispatcher); - }); - } - -} diff --git a/remappedSrc/alujjdnd/ngrok/lan/command/LanDeopCommand.java b/remappedSrc/alujjdnd/ngrok/lan/command/LanDeopCommand.java deleted file mode 100644 index 8edeeaf..0000000 --- a/remappedSrc/alujjdnd/ngrok/lan/command/LanDeopCommand.java +++ /dev/null @@ -1,52 +0,0 @@ -package alujjdnd.ngrok.lan.command; - -import com.mojang.authlib.GameProfile; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.command.CommandSource; -import net.minecraft.command.argument.GameProfileArgumentType; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; - -import java.util.Collection; - -public class LanDeopCommand { - private static final SimpleCommandExceptionType ALREADY_DEOPPED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.deop.failed")); - - public LanDeopCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder) CommandManager.literal("deop").requires((source) -> { - return source.hasPermissionLevel(3); - })).then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { - return CommandSource.suggestMatching((context.getSource()).getServer().getPlayerManager().getOpNames(), builder); - }).executes((context) -> { - return deop(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))); - } - - private static int deop(ServerCommandSource source, Collection targets) throws CommandSyntaxException { - PlayerManager playerManager = source.getServer().getPlayerManager(); - int i = 0; - - for (GameProfile gameProfile : targets) { - if (playerManager.isOperator(gameProfile)) { - playerManager.removeFromOperators(gameProfile); - ++i; - source.sendFeedback(new TranslatableText("commands.deop.success", targets.iterator().next().getName()), true); - } - } - - if (i == 0) { - throw ALREADY_DEOPPED_EXCEPTION.create(); - } else { - source.getServer().kickNonWhitelistedPlayers(source); - return i; - } - } -} diff --git a/remappedSrc/alujjdnd/ngrok/lan/command/LanOpCommand.java b/remappedSrc/alujjdnd/ngrok/lan/command/LanOpCommand.java deleted file mode 100644 index aab6d92..0000000 --- a/remappedSrc/alujjdnd/ngrok/lan/command/LanOpCommand.java +++ /dev/null @@ -1,56 +0,0 @@ -package alujjdnd.ngrok.lan.command; - -import com.mojang.authlib.GameProfile; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.command.CommandSource; -import net.minecraft.command.argument.GameProfileArgumentType; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.TranslatableText; - -import java.util.Collection; - -public class LanOpCommand { - private static final SimpleCommandExceptionType ALREADY_OPPED_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.op.failed")); - - public LanOpCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder) CommandManager.literal("op").requires((source) -> { - return source.hasPermissionLevel(3); - })).then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { - PlayerManager playerManager = (context.getSource()).getServer().getPlayerManager(); - return CommandSource.suggestMatching(playerManager.getPlayerList().stream().filter((player) -> { - return !playerManager.isOperator(player.getGameProfile()); - }).map((player) -> { - return player.getGameProfile().getName(); - }), builder); - }).executes((context) -> { - return op(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))); - } - - private static int op(ServerCommandSource source, Collection targets) throws CommandSyntaxException { - PlayerManager playerManager = source.getServer().getPlayerManager(); - int i = 0; - - for (GameProfile gameProfile : targets) { - if (!playerManager.isOperator(gameProfile)) { - playerManager.addToOperators(gameProfile); - ++i; - source.sendFeedback(new TranslatableText("commands.op.success", targets.iterator().next().getName()), true); - } - } - - if (i == 0) { - throw ALREADY_OPPED_EXCEPTION.create(); - } else { - return i; - } - } -} diff --git a/remappedSrc/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java b/remappedSrc/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java deleted file mode 100644 index 3e20064..0000000 --- a/remappedSrc/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java +++ /dev/null @@ -1,137 +0,0 @@ -package alujjdnd.ngrok.lan.command; - -import com.mojang.authlib.GameProfile; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.command.CommandSource; -import net.minecraft.command.argument.GameProfileArgumentType; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.Whitelist; -import net.minecraft.server.WhitelistEntry; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Texts; -import net.minecraft.text.TranslatableText; - -import java.util.Collection; - -public class LanWhitelistCommand { - private static final SimpleCommandExceptionType ALREADY_ON_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.whitelist.alreadyOn")); - private static final SimpleCommandExceptionType ALREADY_OFF_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.whitelist.alreadyOff")); - private static final SimpleCommandExceptionType ADD_FAILED_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.whitelist.add.failed")); - private static final SimpleCommandExceptionType REMOVE_FAILED_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.whitelist.remove.failed")); - - public LanWhitelistCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) CommandManager.literal("whitelist").requires((source) -> { - return source.hasPermissionLevel(3); - })).then(CommandManager.literal("on").executes((context) -> { - return executeOn(context.getSource()); - })).then(CommandManager.literal("off").executes((context) -> { - return executeOff(context.getSource()); - })).then(CommandManager.literal("list").executes((context) -> { - return executeList(context.getSource()); - })).then(CommandManager.literal("add").then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { - PlayerManager playerManager = context.getSource().getServer().getPlayerManager(); - return CommandSource.suggestMatching(playerManager.getPlayerList().stream().filter((player) -> { - return !playerManager.getWhitelist().isAllowed(player.getGameProfile()); - }).map((player) -> { - return player.getGameProfile().getName(); - }), builder); - }).executes((context) -> { - return executeAdd(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))).then(CommandManager.literal("remove").then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { - return CommandSource.suggestMatching(context.getSource().getServer().getPlayerManager().getWhitelistedNames(), builder); - }).executes((context) -> { - return executeRemove(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))).then(CommandManager.literal("reload").executes((context) -> { - return executeReload(context.getSource()); - }))); - } - - private static int executeReload(ServerCommandSource source) { - source.getServer().getPlayerManager().reloadWhitelist(); - source.sendFeedback(new TranslatableText("commands.whitelist.reloaded"), true); - source.getServer().kickNonWhitelistedPlayers(source); - return 1; - } - - private static int executeAdd(ServerCommandSource source, Collection targets) throws CommandSyntaxException { - Whitelist whitelist = source.getServer().getPlayerManager().getWhitelist(); - int i = 0; - - for (GameProfile gameProfile : targets) { - if (!whitelist.isAllowed(gameProfile)) { - WhitelistEntry whitelistEntry = new WhitelistEntry(gameProfile); - whitelist.add(whitelistEntry); - source.sendFeedback(new TranslatableText("commands.whitelist.add.success", Texts.toText(gameProfile)), true); - ++i; - } - } - - if (i == 0) { - throw ADD_FAILED_EXCEPTION.create(); - } else { - return i; - } - } - - private static int executeRemove(ServerCommandSource source, Collection targets) throws CommandSyntaxException { - Whitelist whitelist = source.getServer().getPlayerManager().getWhitelist(); - int i = 0; - - for (GameProfile gameProfile : targets) { - if (whitelist.isAllowed(gameProfile)) { - WhitelistEntry whitelistEntry = new WhitelistEntry(gameProfile); - whitelist.remove(whitelistEntry); - source.sendFeedback(new TranslatableText("commands.whitelist.remove.success", Texts.toText(gameProfile)), true); - ++i; - } - } - - if (i == 0) { - throw REMOVE_FAILED_EXCEPTION.create(); - } else { - source.getServer().kickNonWhitelistedPlayers(source); - return i; - } - } - - private static int executeOn(ServerCommandSource source) throws CommandSyntaxException { - PlayerManager playerManager = source.getServer().getPlayerManager(); - if (playerManager.isWhitelistEnabled()) { - throw ALREADY_ON_EXCEPTION.create(); - } else { - playerManager.setWhitelistEnabled(true); - source.sendFeedback(new TranslatableText("commands.whitelist.enabled"), true); - source.getServer().kickNonWhitelistedPlayers(source); - return 1; - } - } - - private static int executeOff(ServerCommandSource source) throws CommandSyntaxException { - PlayerManager playerManager = source.getServer().getPlayerManager(); - if (!playerManager.isWhitelistEnabled()) { - throw ALREADY_OFF_EXCEPTION.create(); - } else { - playerManager.setWhitelistEnabled(false); - source.sendFeedback(new TranslatableText("commands.whitelist.disabled"), true); - return 1; - } - } - - private static int executeList(ServerCommandSource source) { - String[] strings = source.getServer().getPlayerManager().getWhitelistedNames(); - if (strings.length == 0) { - source.sendFeedback(new TranslatableText("commands.whitelist.none"), false); - } else { - source.sendFeedback(new TranslatableText("commands.whitelist.list", strings.length, String.join(", ", strings)), false); - } - - return strings.length; - } -} diff --git a/remappedSrc/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java b/remappedSrc/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java deleted file mode 100644 index 423dc0c..0000000 --- a/remappedSrc/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java +++ /dev/null @@ -1,63 +0,0 @@ -package alujjdnd.ngrok.lan.command; - -import alujjdnd.ngrok.lan.NgrokLan; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.client.MinecraftClient; -import net.minecraft.command.CommandSource; -import net.minecraft.command.argument.GameProfileArgumentType; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.ServerConfigHandler; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.TranslatableText; - -public class ReloadJsonListsCommand { - - //check if player has permission (same permission level as /op and /deop) - //run loadJson(); - //get source.getServer() from command - - private static final SimpleCommandExceptionType LOAD_JSON_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("text.info.ngroklan.reload.message")); - - public ReloadJsonListsCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register(CommandManager.literal("reloadngroklanlists") - .requires(source -> source.hasPermissionLevel(3)) - .executes(ReloadJsonListsCommand::loadJson)); - } - - private static int loadJson(CommandContext serverCommandSourceCommandContext) throws CommandSyntaxException { - MinecraftServer server = serverCommandSourceCommandContext.getSource().getServer(); - - boolean bl3 = ServerConfigHandler.convertOperators(server); - - boolean bl4 = ServerConfigHandler.convertWhitelist(server); - - - if(! (bl3 && bl4) ){ - throw LOAD_JSON_EXCEPTION.create(); - } - else{ - MinecraftClient.getInstance().inGameHud.getChatHud().addMessage( new TranslatableText("text.info.ngroklan.reload.success")); - } - - return 1; - } - - - - - private static void sleepFiveSeconds() { - try { - Thread.sleep(5000L); - } catch (InterruptedException ignored) { - } - } -} diff --git a/remappedSrc/alujjdnd/ngrok/lan/config/ModMenuIntegration.java b/remappedSrc/alujjdnd/ngrok/lan/config/ModMenuIntegration.java deleted file mode 100644 index 0bf988d..0000000 --- a/remappedSrc/alujjdnd/ngrok/lan/config/ModMenuIntegration.java +++ /dev/null @@ -1,13 +0,0 @@ -package alujjdnd.ngrok.lan.config; - -import com.terraformersmc.modmenu.api.ConfigScreenFactory; -import com.terraformersmc.modmenu.api.ModMenuApi; -import me.shedaniel.autoconfig.AutoConfig; - -public class ModMenuIntegration implements ModMenuApi -{ - @Override - public ConfigScreenFactory getModConfigScreenFactory() { - return parent -> AutoConfig.getConfigScreen(NLanConfig.class, parent).get(); - } -} diff --git a/remappedSrc/alujjdnd/ngrok/lan/config/NLanConfig.java b/remappedSrc/alujjdnd/ngrok/lan/config/NLanConfig.java deleted file mode 100644 index 14ada5c..0000000 --- a/remappedSrc/alujjdnd/ngrok/lan/config/NLanConfig.java +++ /dev/null @@ -1,22 +0,0 @@ -package alujjdnd.ngrok.lan.config; - -import me.shedaniel.autoconfig.ConfigData; -import me.shedaniel.autoconfig.annotation.Config; - -@Config(name = "ngroklan") -public class NLanConfig implements ConfigData -{ - public boolean enabledCheckBox = true; - public String authToken = "AuthToken"; - - public enum regionSelectEnum { - US, EU, AP, AU, SA, JP, IN - } - - public regionSelectEnum regionSelect = regionSelectEnum.US; - - public boolean onlineCheckBox = true; - - public int spawnProtectionRadius = 16; - -} \ No newline at end of file diff --git a/remappedSrc/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java b/remappedSrc/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java deleted file mode 100644 index 0437b3f..0000000 --- a/remappedSrc/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package alujjdnd.ngrok.lan.mixin; - - -import alujjdnd.ngrok.lan.NgrokLan; -import net.minecraft.server.MinecraftServer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(MinecraftServer.class) -public abstract class CloseTunnelMixin { - @Inject(at = @At("TAIL"), method = "shutdown") - private void afterShutdownServer(CallbackInfo info) { - if(NgrokLan.serverOpen){ - NgrokLan.LOGGER.info("Closing Ngrok LAN!"); - NgrokLan.ngrokClient.kill(); - NgrokLan.serverOpen = false; - } - - } - -} diff --git a/remappedSrc/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java b/remappedSrc/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java deleted file mode 100644 index b489f9a..0000000 --- a/remappedSrc/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java +++ /dev/null @@ -1,202 +0,0 @@ -package alujjdnd.ngrok.lan.mixin; - - -import alujjdnd.ngrok.lan.NgrokLan; -import alujjdnd.ngrok.lan.config.NLanConfig; -import com.github.alexdlaird.ngrok.NgrokClient; -import com.github.alexdlaird.ngrok.conf.JavaNgrokConfig; -import com.github.alexdlaird.ngrok.protocol.CreateTunnel; -import com.github.alexdlaird.ngrok.protocol.Proto; -import com.github.alexdlaird.ngrok.protocol.Region; -import com.github.alexdlaird.ngrok.protocol.Tunnel; -import me.shedaniel.autoconfig.AutoConfig; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.OpenToLanScreen; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.util.NetworkUtils; -import net.minecraft.server.ServerConfigHandler; -import net.minecraft.text.*; -import net.minecraft.util.Formatting; -import net.minecraft.world.GameMode; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(OpenToLanScreen.class) -public class OpenToLanScreenMixin extends Screen { - - NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); - MinecraftClient mc = MinecraftClient.getInstance(); - - @Shadow - private GameMode gameMode; - - @Shadow - private boolean allowCommands; - - protected OpenToLanScreenMixin(Text title) { - super(title); - } - - @Inject(method = "init", at = @At("HEAD")) - private void initWidgets(CallbackInfo info) { - - if (config.enabledCheckBox) { //if mod enabled in mod menu - this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height - 58, 150, 20, new TranslatableText("text.UI.ngroklan.LanButton"), (button) -> { - int localPort = NetworkUtils.findLocalPort(); // part of the minecraft Networkutils class, finds an available local port (this was from the openToLan class) - this.client.setScreen(null); // Removed all elements from the screen (this closes all menu windows) - switch (config.regionSelect) { - case EU -> ngrokInit(localPort, Region.EU); - case AP -> ngrokInit(localPort, Region.AP); - case AU -> ngrokInit(localPort, Region.AU); - case SA -> ngrokInit(localPort, Region.SA); - case JP -> ngrokInit(localPort, Region.JP); - case IN -> ngrokInit(localPort, Region.IN); - default -> ngrokInit(localPort, Region.US); //US bundled here - } - })); - - } - } - - - private void ngrokInit(int port, Region region) { - - //Defines a new threaded function to oepn the Ngrok tunnel, so that the "Open to LAN" button does not hitch - this thread runs in a seperate process from the main game loop - Thread thread = new Thread(() -> - { - if (config.authToken.equals("AuthToken")) { - // Check if authToken field has actually been changed, if not, print this text in chat - mc.inGameHud.getChatHud().addMessage(new TranslatableText("text.error.ngroklan.AuthTokenError")); - mc.inGameHud.getChatHud().addMessage(new TranslatableText("text.error.ngroklan.AuthTokenError").formatted(Formatting.RED)); - //\u00a7c - } else { - try { - NgrokLan.LOGGER.info("Launched Lan!"); - - mc.inGameHud.getChatHud().addMessage(new TranslatableText("text.info.ngroklan.startMessage").formatted(Formatting.YELLOW)); - - - // Java-ngrok wrapper code, to initiate the tunnel, with the authoken, region - final JavaNgrokConfig javaNgrokConfig = new JavaNgrokConfig.Builder() - .withAuthToken(config.authToken) - .withRegion(region) - .build(); - - NgrokLan.ngrokClient = new NgrokClient.Builder() - .withJavaNgrokConfig(javaNgrokConfig) - .build(); - - final CreateTunnel createTunnel = new CreateTunnel.Builder() - .withProto(Proto.TCP) - .withAddr(port) - .build(); - - final Tunnel tunnel = NgrokLan.ngrokClient.connect(createTunnel); - - NgrokLan.LOGGER.info(tunnel.getPublicUrl()); - - var ngrok_url = tunnel.getPublicUrl().substring(6); - - // Print in chat the status of the tunnel, and the details copied to the clipboard - mc.inGameHud.getChatHud().addMessage(new TranslatableText("text.info.ngroklan.success").formatted(Formatting.GREEN)); - - Text copyText = Texts.bracketed((new LiteralText(ngrok_url)).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, ngrok_url)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableText("chat.copy.click"))).withInsertion(ngrok_url))); - mc.inGameHud.getChatHud().addMessage( new TranslatableText("text.info.ngroklan.ip", copyText)); - - mc.keyboard.setClipboard(ngrok_url); - - - - // This starts the LAN server and greys out the open to lan button - TranslatableText text; - - - if (this.client.getServer().openToLan(this.gameMode, this.allowCommands, port)) { - mc.getServer().setOnlineMode(config.onlineCheckBox); - text = new TranslatableText("commands.publish.started", port); - NgrokLan.serverOpen = true; - - //TODO: make sure this works, I make a new thread that reads the json files to update the oplist and whitelist in the playermanager - Thread thread2 = new Thread(() -> { - - NgrokLan.LOGGER.info("debug THREAD2 STARTED"); - - boolean result = loadJson(); - if(!result){ - Text commandText = Texts.bracketed((new TranslatableText("text.info.ngroklan.reload.prompt")).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reloadngroklanlists")).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableText("text.info.ngroklan.reload.prompt"))))); - mc.inGameHud.getChatHud().addMessage( new TranslatableText("text.info.ngroklan.reload.message")); - mc.inGameHud.getChatHud().addMessage(commandText); - } - else{ - mc.inGameHud.getChatHud().addMessage( new TranslatableText("text.info.ngroklan.reload.success")); - } - }); - - NgrokLan.LOGGER.info("debug THREAD2 STARTING"); - thread2.start(); - - } else { - text = new TranslatableText("commands.publish.failed"); - NgrokLan.serverOpen = false; - } - this.client.inGameHud.getChatHud().addMessage(text); - this.client.updateWindowTitle(); - - } catch (Exception error) { - error.printStackTrace(); - mc.inGameHud.getChatHud().addMessage(new LiteralText(error.getMessage())); - mc.inGameHud.getChatHud().addMessage(new TranslatableText("text.error.ngroklan.fail").formatted(Formatting.RED)); - //ngrokInitiated = false; - throw new RuntimeException("Ngrok Service Failed to Start" + error.getMessage()); - } - } - }); - - // This starts the thread defined above - thread.start(); - - } - - private boolean loadJson(){ - NgrokLan.LOGGER.info("debug LOADING JSON"); - - int i; - boolean bl3 = false; - - for(i = 0; !bl3 && i <= 2; ++i) { - if (i > 0) { - NgrokLan.LOGGER.warn("Encountered a problem while converting the op list, retrying in a few seconds"); - this.sleepFiveSeconds(); - } - - bl3 = ServerConfigHandler.convertOperators(this.client.getServer()); - //fail is false - } - - boolean bl4 = false; - - for(i = 0; !bl4 && i <= 2; ++i) { - if (i > 0) { - NgrokLan.LOGGER.warn("Encountered a problem while converting the whitelist, retrying in a few seconds"); - this.sleepFiveSeconds(); - } - - bl4 = ServerConfigHandler.convertWhitelist(this.client.getServer()); - //fail is false - } - - return bl3 && bl4; - } - - private void sleepFiveSeconds() { - try { - Thread.sleep(5000L); - } catch (InterruptedException var2) { - } - } - -} diff --git a/remappedSrc/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java b/remappedSrc/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java deleted file mode 100644 index b6bcd87..0000000 --- a/remappedSrc/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java +++ /dev/null @@ -1,38 +0,0 @@ -package alujjdnd.ngrok.lan.mixin; - -import alujjdnd.ngrok.lan.NgrokLan; -import alujjdnd.ngrok.lan.config.NLanConfig; -import com.mojang.authlib.GameProfile; -import me.shedaniel.autoconfig.AutoConfig; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.Whitelist; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.Text; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.net.SocketAddress; - -@Mixin(PlayerManager.class) -public class PlayerManagerMixin { - NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); - - @Final - @Shadow - private Whitelist whitelist; - - @Inject(at = @At("HEAD"), method = "checkCanJoin") - public void isSpawnProtected(SocketAddress address, GameProfile profile, CallbackInfoReturnable cir) { - NgrokLan.LOGGER.info("Whitelist? " + whitelist.getFile().getAbsolutePath()); - - } -} diff --git a/remappedSrc/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java b/remappedSrc/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java deleted file mode 100644 index 6f1be6c..0000000 --- a/remappedSrc/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java +++ /dev/null @@ -1,57 +0,0 @@ -package alujjdnd.ngrok.lan.mixin; - -import alujjdnd.ngrok.lan.NgrokLan; -import alujjdnd.ngrok.lan.config.NLanConfig; -import me.shedaniel.autoconfig.AutoConfig; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(MinecraftServer.class) -public class SpawnProtectionMixin { - - NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); - - @Shadow - private PlayerManager playerManager; - - @Inject(at = @At("HEAD"), method = "isSpawnProtected", cancellable = true) - public void isSpawnProtected(ServerWorld world, BlockPos pos, PlayerEntity player, CallbackInfoReturnable cir) { - - if(!NgrokLan.serverOpen){ - cir.setReturnValue(false); - cir.cancel(); - } else if (config.spawnProtectionRadius <= 0) { - cir.setReturnValue(false); - cir.cancel(); - } - else if (world.getRegistryKey() != World.OVERWORLD) { - cir.setReturnValue(false); - cir.cancel(); - } else if (playerManager.isOperator(player.getGameProfile())) { - cir.setReturnValue(false); - cir.cancel(); - } else { - BlockPos blockPos = world.getSpawnPos(); - int i = MathHelper.abs(pos.getX() - blockPos.getX()); - int j = MathHelper.abs(pos.getZ() - blockPos.getZ()); - int k = Math.max(i, j); - cir.setReturnValue(k <= config.spawnProtectionRadius); - cir.cancel(); - } - //there's a small diff from vanilla check that checks if Oplist is empty. Since the host - //is an "admin" (more control than op idk the technical term) by default they are not in - //the op list, so this check does not work. - } - - -} diff --git a/remappedSrc/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java b/remappedSrc/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java deleted file mode 100644 index ba7bcd5..0000000 --- a/remappedSrc/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package alujjdnd.ngrok.lan.mixin; - -import alujjdnd.ngrok.lan.NgrokLan; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.resource.language.I18n; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(MinecraftClient.class) -public abstract class WindowTitleMixin { - @Inject(method = "getWindowTitle", at = @At("HEAD"), cancellable = true) - private void injected(CallbackInfoReturnable cir) { - StringBuilder stringBuilder2 = new StringBuilder(I18n.translate("text.title.ngroklan.window")); - - if(NgrokLan.serverOpen){ - cir.setReturnValue(stringBuilder2.toString()); - } - - - } - -} \ No newline at end of file diff --git a/srcNEW/alujjdnd/ngrok/lan/NgrokLan.java b/srcNEW/alujjdnd/ngrok/lan/NgrokLan.java deleted file mode 100644 index bbcde24..0000000 --- a/srcNEW/alujjdnd/ngrok/lan/NgrokLan.java +++ /dev/null @@ -1,53 +0,0 @@ -package alujjdnd.ngrok.lan; - -import alujjdnd.ngrok.lan.command.LanDeopCommand; -import alujjdnd.ngrok.lan.command.LanOpCommand; -import alujjdnd.ngrok.lan.command.LanWhitelistCommand; -import alujjdnd.ngrok.lan.command.ReloadJsonListsCommand; -import com.github.alexdlaird.ngrok.NgrokClient; -import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import alujjdnd.ngrok.lan.config.NLanConfig; -import me.shedaniel.autoconfig.AutoConfig; -import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer; - - - - -public class NgrokLan implements ModInitializer { - // This logger is used to write text to the console and the log file. - // It is considered best practice to use your mod id as the logger's name. - // That way, it's clear which mod wrote info, warnings, and errors. - - public static final String MODID = "ngroklan"; - - public static final Logger LOGGER = LoggerFactory.getLogger(MODID); - - public static NgrokClient ngrokClient; - - public static boolean serverOpen = false; - - @Override - public void onInitialize() { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - - LOGGER.info("Minecraft started with Ngrok LAN"); - AutoConfig.register(NLanConfig.class, JanksonConfigSerializer::new); - - //register commands - CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> - { - LanOpCommand.register(dispatcher); - LanDeopCommand.register(dispatcher); - LanWhitelistCommand.register(dispatcher); - ReloadJsonListsCommand.register(dispatcher); - }); - } - - -} diff --git a/srcNEW/alujjdnd/ngrok/lan/NgrokServerInitialiser.java b/srcNEW/alujjdnd/ngrok/lan/NgrokServerInitialiser.java deleted file mode 100644 index f592d44..0000000 --- a/srcNEW/alujjdnd/ngrok/lan/NgrokServerInitialiser.java +++ /dev/null @@ -1,37 +0,0 @@ -package alujjdnd.ngrok.lan; - - -import alujjdnd.ngrok.lan.command.LanDeopCommand; -import alujjdnd.ngrok.lan.command.LanOpCommand; -import alujjdnd.ngrok.lan.command.LanWhitelistCommand; -import alujjdnd.ngrok.lan.command.ReloadJsonListsCommand; -import net.fabricmc.api.DedicatedServerModInitializer; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Environment(EnvType.SERVER) -public class NgrokServerInitialiser implements DedicatedServerModInitializer -{ - - public static final Logger LOGGER = LoggerFactory.getLogger(NgrokLan.MODID); - - @Override - // Initialize the differents parts of the mod when lauched on server - public void onInitializeServer() - { - LOGGER.info("World is Open to LAN with Ngrok LAN"); - - //register commands - CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> - { - LanOpCommand.register(dispatcher); - LanDeopCommand.register(dispatcher); - LanWhitelistCommand.register(dispatcher); - ReloadJsonListsCommand.register(dispatcher); - }); - } - -} diff --git a/srcNEW/alujjdnd/ngrok/lan/command/LanDeopCommand.java b/srcNEW/alujjdnd/ngrok/lan/command/LanDeopCommand.java deleted file mode 100644 index d01bf85..0000000 --- a/srcNEW/alujjdnd/ngrok/lan/command/LanDeopCommand.java +++ /dev/null @@ -1,52 +0,0 @@ -package alujjdnd.ngrok.lan.command; - -import com.mojang.authlib.GameProfile; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.command.CommandSource; -import net.minecraft.command.argument.GameProfileArgumentType; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.TranslatableText; - -import java.util.Collection; - -public class LanDeopCommand { - private static final SimpleCommandExceptionType ALREADY_DEOPPED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.deop.failed")); - - public LanDeopCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder) CommandManager.literal("deop").requires((source) -> { - return source.hasPermissionLevel(3); - })).then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { - return CommandSource.suggestMatching((context.getSource()).getServer().getPlayerManager().getOpNames(), builder); - }).executes((context) -> { - return deop(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))); - } - - private static int deop(ServerCommandSource source, Collection targets) throws CommandSyntaxException { - PlayerManager playerManager = source.getServer().getPlayerManager(); - int i = 0; - - for (GameProfile gameProfile : targets) { - if (playerManager.isOperator(gameProfile)) { - playerManager.removeFromOperators(gameProfile); - ++i; - source.sendFeedback(new TranslatableText("commands.deop.success", targets.iterator().next().getName()), true); - } - } - - if (i == 0) { - throw ALREADY_DEOPPED_EXCEPTION.create(); - } else { - source.getServer().kickNonWhitelistedPlayers(source); - return i; - } - } -} diff --git a/srcNEW/alujjdnd/ngrok/lan/command/LanOpCommand.java b/srcNEW/alujjdnd/ngrok/lan/command/LanOpCommand.java deleted file mode 100644 index aab6d92..0000000 --- a/srcNEW/alujjdnd/ngrok/lan/command/LanOpCommand.java +++ /dev/null @@ -1,56 +0,0 @@ -package alujjdnd.ngrok.lan.command; - -import com.mojang.authlib.GameProfile; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.command.CommandSource; -import net.minecraft.command.argument.GameProfileArgumentType; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.TranslatableText; - -import java.util.Collection; - -public class LanOpCommand { - private static final SimpleCommandExceptionType ALREADY_OPPED_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.op.failed")); - - public LanOpCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder) CommandManager.literal("op").requires((source) -> { - return source.hasPermissionLevel(3); - })).then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { - PlayerManager playerManager = (context.getSource()).getServer().getPlayerManager(); - return CommandSource.suggestMatching(playerManager.getPlayerList().stream().filter((player) -> { - return !playerManager.isOperator(player.getGameProfile()); - }).map((player) -> { - return player.getGameProfile().getName(); - }), builder); - }).executes((context) -> { - return op(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))); - } - - private static int op(ServerCommandSource source, Collection targets) throws CommandSyntaxException { - PlayerManager playerManager = source.getServer().getPlayerManager(); - int i = 0; - - for (GameProfile gameProfile : targets) { - if (!playerManager.isOperator(gameProfile)) { - playerManager.addToOperators(gameProfile); - ++i; - source.sendFeedback(new TranslatableText("commands.op.success", targets.iterator().next().getName()), true); - } - } - - if (i == 0) { - throw ALREADY_OPPED_EXCEPTION.create(); - } else { - return i; - } - } -} diff --git a/srcNEW/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java b/srcNEW/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java deleted file mode 100644 index 3e20064..0000000 --- a/srcNEW/alujjdnd/ngrok/lan/command/LanWhitelistCommand.java +++ /dev/null @@ -1,137 +0,0 @@ -package alujjdnd.ngrok.lan.command; - -import com.mojang.authlib.GameProfile; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.command.CommandSource; -import net.minecraft.command.argument.GameProfileArgumentType; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.Whitelist; -import net.minecraft.server.WhitelistEntry; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Texts; -import net.minecraft.text.TranslatableText; - -import java.util.Collection; - -public class LanWhitelistCommand { - private static final SimpleCommandExceptionType ALREADY_ON_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.whitelist.alreadyOn")); - private static final SimpleCommandExceptionType ALREADY_OFF_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.whitelist.alreadyOff")); - private static final SimpleCommandExceptionType ADD_FAILED_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.whitelist.add.failed")); - private static final SimpleCommandExceptionType REMOVE_FAILED_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.whitelist.remove.failed")); - - public LanWhitelistCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) CommandManager.literal("whitelist").requires((source) -> { - return source.hasPermissionLevel(3); - })).then(CommandManager.literal("on").executes((context) -> { - return executeOn(context.getSource()); - })).then(CommandManager.literal("off").executes((context) -> { - return executeOff(context.getSource()); - })).then(CommandManager.literal("list").executes((context) -> { - return executeList(context.getSource()); - })).then(CommandManager.literal("add").then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { - PlayerManager playerManager = context.getSource().getServer().getPlayerManager(); - return CommandSource.suggestMatching(playerManager.getPlayerList().stream().filter((player) -> { - return !playerManager.getWhitelist().isAllowed(player.getGameProfile()); - }).map((player) -> { - return player.getGameProfile().getName(); - }), builder); - }).executes((context) -> { - return executeAdd(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))).then(CommandManager.literal("remove").then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()).suggests((context, builder) -> { - return CommandSource.suggestMatching(context.getSource().getServer().getPlayerManager().getWhitelistedNames(), builder); - }).executes((context) -> { - return executeRemove(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")); - }))).then(CommandManager.literal("reload").executes((context) -> { - return executeReload(context.getSource()); - }))); - } - - private static int executeReload(ServerCommandSource source) { - source.getServer().getPlayerManager().reloadWhitelist(); - source.sendFeedback(new TranslatableText("commands.whitelist.reloaded"), true); - source.getServer().kickNonWhitelistedPlayers(source); - return 1; - } - - private static int executeAdd(ServerCommandSource source, Collection targets) throws CommandSyntaxException { - Whitelist whitelist = source.getServer().getPlayerManager().getWhitelist(); - int i = 0; - - for (GameProfile gameProfile : targets) { - if (!whitelist.isAllowed(gameProfile)) { - WhitelistEntry whitelistEntry = new WhitelistEntry(gameProfile); - whitelist.add(whitelistEntry); - source.sendFeedback(new TranslatableText("commands.whitelist.add.success", Texts.toText(gameProfile)), true); - ++i; - } - } - - if (i == 0) { - throw ADD_FAILED_EXCEPTION.create(); - } else { - return i; - } - } - - private static int executeRemove(ServerCommandSource source, Collection targets) throws CommandSyntaxException { - Whitelist whitelist = source.getServer().getPlayerManager().getWhitelist(); - int i = 0; - - for (GameProfile gameProfile : targets) { - if (whitelist.isAllowed(gameProfile)) { - WhitelistEntry whitelistEntry = new WhitelistEntry(gameProfile); - whitelist.remove(whitelistEntry); - source.sendFeedback(new TranslatableText("commands.whitelist.remove.success", Texts.toText(gameProfile)), true); - ++i; - } - } - - if (i == 0) { - throw REMOVE_FAILED_EXCEPTION.create(); - } else { - source.getServer().kickNonWhitelistedPlayers(source); - return i; - } - } - - private static int executeOn(ServerCommandSource source) throws CommandSyntaxException { - PlayerManager playerManager = source.getServer().getPlayerManager(); - if (playerManager.isWhitelistEnabled()) { - throw ALREADY_ON_EXCEPTION.create(); - } else { - playerManager.setWhitelistEnabled(true); - source.sendFeedback(new TranslatableText("commands.whitelist.enabled"), true); - source.getServer().kickNonWhitelistedPlayers(source); - return 1; - } - } - - private static int executeOff(ServerCommandSource source) throws CommandSyntaxException { - PlayerManager playerManager = source.getServer().getPlayerManager(); - if (!playerManager.isWhitelistEnabled()) { - throw ALREADY_OFF_EXCEPTION.create(); - } else { - playerManager.setWhitelistEnabled(false); - source.sendFeedback(new TranslatableText("commands.whitelist.disabled"), true); - return 1; - } - } - - private static int executeList(ServerCommandSource source) { - String[] strings = source.getServer().getPlayerManager().getWhitelistedNames(); - if (strings.length == 0) { - source.sendFeedback(new TranslatableText("commands.whitelist.none"), false); - } else { - source.sendFeedback(new TranslatableText("commands.whitelist.list", strings.length, String.join(", ", strings)), false); - } - - return strings.length; - } -} diff --git a/srcNEW/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java b/srcNEW/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java deleted file mode 100644 index 423dc0c..0000000 --- a/srcNEW/alujjdnd/ngrok/lan/command/ReloadJsonListsCommand.java +++ /dev/null @@ -1,63 +0,0 @@ -package alujjdnd.ngrok.lan.command; - -import alujjdnd.ngrok.lan.NgrokLan; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.client.MinecraftClient; -import net.minecraft.command.CommandSource; -import net.minecraft.command.argument.GameProfileArgumentType; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.ServerConfigHandler; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.TranslatableText; - -public class ReloadJsonListsCommand { - - //check if player has permission (same permission level as /op and /deop) - //run loadJson(); - //get source.getServer() from command - - private static final SimpleCommandExceptionType LOAD_JSON_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("text.info.ngroklan.reload.message")); - - public ReloadJsonListsCommand() { - } - - public static void register(CommandDispatcher dispatcher) { - dispatcher.register(CommandManager.literal("reloadngroklanlists") - .requires(source -> source.hasPermissionLevel(3)) - .executes(ReloadJsonListsCommand::loadJson)); - } - - private static int loadJson(CommandContext serverCommandSourceCommandContext) throws CommandSyntaxException { - MinecraftServer server = serverCommandSourceCommandContext.getSource().getServer(); - - boolean bl3 = ServerConfigHandler.convertOperators(server); - - boolean bl4 = ServerConfigHandler.convertWhitelist(server); - - - if(! (bl3 && bl4) ){ - throw LOAD_JSON_EXCEPTION.create(); - } - else{ - MinecraftClient.getInstance().inGameHud.getChatHud().addMessage( new TranslatableText("text.info.ngroklan.reload.success")); - } - - return 1; - } - - - - - private static void sleepFiveSeconds() { - try { - Thread.sleep(5000L); - } catch (InterruptedException ignored) { - } - } -} diff --git a/srcNEW/alujjdnd/ngrok/lan/config/ModMenuIntegration.java b/srcNEW/alujjdnd/ngrok/lan/config/ModMenuIntegration.java deleted file mode 100644 index 0bf988d..0000000 --- a/srcNEW/alujjdnd/ngrok/lan/config/ModMenuIntegration.java +++ /dev/null @@ -1,13 +0,0 @@ -package alujjdnd.ngrok.lan.config; - -import com.terraformersmc.modmenu.api.ConfigScreenFactory; -import com.terraformersmc.modmenu.api.ModMenuApi; -import me.shedaniel.autoconfig.AutoConfig; - -public class ModMenuIntegration implements ModMenuApi -{ - @Override - public ConfigScreenFactory getModConfigScreenFactory() { - return parent -> AutoConfig.getConfigScreen(NLanConfig.class, parent).get(); - } -} diff --git a/srcNEW/alujjdnd/ngrok/lan/config/NLanConfig.java b/srcNEW/alujjdnd/ngrok/lan/config/NLanConfig.java deleted file mode 100644 index 14ada5c..0000000 --- a/srcNEW/alujjdnd/ngrok/lan/config/NLanConfig.java +++ /dev/null @@ -1,22 +0,0 @@ -package alujjdnd.ngrok.lan.config; - -import me.shedaniel.autoconfig.ConfigData; -import me.shedaniel.autoconfig.annotation.Config; - -@Config(name = "ngroklan") -public class NLanConfig implements ConfigData -{ - public boolean enabledCheckBox = true; - public String authToken = "AuthToken"; - - public enum regionSelectEnum { - US, EU, AP, AU, SA, JP, IN - } - - public regionSelectEnum regionSelect = regionSelectEnum.US; - - public boolean onlineCheckBox = true; - - public int spawnProtectionRadius = 16; - -} \ No newline at end of file diff --git a/srcNEW/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java b/srcNEW/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java deleted file mode 100644 index 0437b3f..0000000 --- a/srcNEW/alujjdnd/ngrok/lan/mixin/CloseTunnelMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package alujjdnd.ngrok.lan.mixin; - - -import alujjdnd.ngrok.lan.NgrokLan; -import net.minecraft.server.MinecraftServer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(MinecraftServer.class) -public abstract class CloseTunnelMixin { - @Inject(at = @At("TAIL"), method = "shutdown") - private void afterShutdownServer(CallbackInfo info) { - if(NgrokLan.serverOpen){ - NgrokLan.LOGGER.info("Closing Ngrok LAN!"); - NgrokLan.ngrokClient.kill(); - NgrokLan.serverOpen = false; - } - - } - -} diff --git a/srcNEW/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java b/srcNEW/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java deleted file mode 100644 index b489f9a..0000000 --- a/srcNEW/alujjdnd/ngrok/lan/mixin/OpenToLanScreenMixin.java +++ /dev/null @@ -1,202 +0,0 @@ -package alujjdnd.ngrok.lan.mixin; - - -import alujjdnd.ngrok.lan.NgrokLan; -import alujjdnd.ngrok.lan.config.NLanConfig; -import com.github.alexdlaird.ngrok.NgrokClient; -import com.github.alexdlaird.ngrok.conf.JavaNgrokConfig; -import com.github.alexdlaird.ngrok.protocol.CreateTunnel; -import com.github.alexdlaird.ngrok.protocol.Proto; -import com.github.alexdlaird.ngrok.protocol.Region; -import com.github.alexdlaird.ngrok.protocol.Tunnel; -import me.shedaniel.autoconfig.AutoConfig; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.OpenToLanScreen; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.util.NetworkUtils; -import net.minecraft.server.ServerConfigHandler; -import net.minecraft.text.*; -import net.minecraft.util.Formatting; -import net.minecraft.world.GameMode; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(OpenToLanScreen.class) -public class OpenToLanScreenMixin extends Screen { - - NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); - MinecraftClient mc = MinecraftClient.getInstance(); - - @Shadow - private GameMode gameMode; - - @Shadow - private boolean allowCommands; - - protected OpenToLanScreenMixin(Text title) { - super(title); - } - - @Inject(method = "init", at = @At("HEAD")) - private void initWidgets(CallbackInfo info) { - - if (config.enabledCheckBox) { //if mod enabled in mod menu - this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height - 58, 150, 20, new TranslatableText("text.UI.ngroklan.LanButton"), (button) -> { - int localPort = NetworkUtils.findLocalPort(); // part of the minecraft Networkutils class, finds an available local port (this was from the openToLan class) - this.client.setScreen(null); // Removed all elements from the screen (this closes all menu windows) - switch (config.regionSelect) { - case EU -> ngrokInit(localPort, Region.EU); - case AP -> ngrokInit(localPort, Region.AP); - case AU -> ngrokInit(localPort, Region.AU); - case SA -> ngrokInit(localPort, Region.SA); - case JP -> ngrokInit(localPort, Region.JP); - case IN -> ngrokInit(localPort, Region.IN); - default -> ngrokInit(localPort, Region.US); //US bundled here - } - })); - - } - } - - - private void ngrokInit(int port, Region region) { - - //Defines a new threaded function to oepn the Ngrok tunnel, so that the "Open to LAN" button does not hitch - this thread runs in a seperate process from the main game loop - Thread thread = new Thread(() -> - { - if (config.authToken.equals("AuthToken")) { - // Check if authToken field has actually been changed, if not, print this text in chat - mc.inGameHud.getChatHud().addMessage(new TranslatableText("text.error.ngroklan.AuthTokenError")); - mc.inGameHud.getChatHud().addMessage(new TranslatableText("text.error.ngroklan.AuthTokenError").formatted(Formatting.RED)); - //\u00a7c - } else { - try { - NgrokLan.LOGGER.info("Launched Lan!"); - - mc.inGameHud.getChatHud().addMessage(new TranslatableText("text.info.ngroklan.startMessage").formatted(Formatting.YELLOW)); - - - // Java-ngrok wrapper code, to initiate the tunnel, with the authoken, region - final JavaNgrokConfig javaNgrokConfig = new JavaNgrokConfig.Builder() - .withAuthToken(config.authToken) - .withRegion(region) - .build(); - - NgrokLan.ngrokClient = new NgrokClient.Builder() - .withJavaNgrokConfig(javaNgrokConfig) - .build(); - - final CreateTunnel createTunnel = new CreateTunnel.Builder() - .withProto(Proto.TCP) - .withAddr(port) - .build(); - - final Tunnel tunnel = NgrokLan.ngrokClient.connect(createTunnel); - - NgrokLan.LOGGER.info(tunnel.getPublicUrl()); - - var ngrok_url = tunnel.getPublicUrl().substring(6); - - // Print in chat the status of the tunnel, and the details copied to the clipboard - mc.inGameHud.getChatHud().addMessage(new TranslatableText("text.info.ngroklan.success").formatted(Formatting.GREEN)); - - Text copyText = Texts.bracketed((new LiteralText(ngrok_url)).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, ngrok_url)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableText("chat.copy.click"))).withInsertion(ngrok_url))); - mc.inGameHud.getChatHud().addMessage( new TranslatableText("text.info.ngroklan.ip", copyText)); - - mc.keyboard.setClipboard(ngrok_url); - - - - // This starts the LAN server and greys out the open to lan button - TranslatableText text; - - - if (this.client.getServer().openToLan(this.gameMode, this.allowCommands, port)) { - mc.getServer().setOnlineMode(config.onlineCheckBox); - text = new TranslatableText("commands.publish.started", port); - NgrokLan.serverOpen = true; - - //TODO: make sure this works, I make a new thread that reads the json files to update the oplist and whitelist in the playermanager - Thread thread2 = new Thread(() -> { - - NgrokLan.LOGGER.info("debug THREAD2 STARTED"); - - boolean result = loadJson(); - if(!result){ - Text commandText = Texts.bracketed((new TranslatableText("text.info.ngroklan.reload.prompt")).styled((style) -> style.withColor(Formatting.YELLOW).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reloadngroklanlists")).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableText("text.info.ngroklan.reload.prompt"))))); - mc.inGameHud.getChatHud().addMessage( new TranslatableText("text.info.ngroklan.reload.message")); - mc.inGameHud.getChatHud().addMessage(commandText); - } - else{ - mc.inGameHud.getChatHud().addMessage( new TranslatableText("text.info.ngroklan.reload.success")); - } - }); - - NgrokLan.LOGGER.info("debug THREAD2 STARTING"); - thread2.start(); - - } else { - text = new TranslatableText("commands.publish.failed"); - NgrokLan.serverOpen = false; - } - this.client.inGameHud.getChatHud().addMessage(text); - this.client.updateWindowTitle(); - - } catch (Exception error) { - error.printStackTrace(); - mc.inGameHud.getChatHud().addMessage(new LiteralText(error.getMessage())); - mc.inGameHud.getChatHud().addMessage(new TranslatableText("text.error.ngroklan.fail").formatted(Formatting.RED)); - //ngrokInitiated = false; - throw new RuntimeException("Ngrok Service Failed to Start" + error.getMessage()); - } - } - }); - - // This starts the thread defined above - thread.start(); - - } - - private boolean loadJson(){ - NgrokLan.LOGGER.info("debug LOADING JSON"); - - int i; - boolean bl3 = false; - - for(i = 0; !bl3 && i <= 2; ++i) { - if (i > 0) { - NgrokLan.LOGGER.warn("Encountered a problem while converting the op list, retrying in a few seconds"); - this.sleepFiveSeconds(); - } - - bl3 = ServerConfigHandler.convertOperators(this.client.getServer()); - //fail is false - } - - boolean bl4 = false; - - for(i = 0; !bl4 && i <= 2; ++i) { - if (i > 0) { - NgrokLan.LOGGER.warn("Encountered a problem while converting the whitelist, retrying in a few seconds"); - this.sleepFiveSeconds(); - } - - bl4 = ServerConfigHandler.convertWhitelist(this.client.getServer()); - //fail is false - } - - return bl3 && bl4; - } - - private void sleepFiveSeconds() { - try { - Thread.sleep(5000L); - } catch (InterruptedException var2) { - } - } - -} diff --git a/srcNEW/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java b/srcNEW/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java deleted file mode 100644 index b6bcd87..0000000 --- a/srcNEW/alujjdnd/ngrok/lan/mixin/PlayerManagerMixin.java +++ /dev/null @@ -1,38 +0,0 @@ -package alujjdnd.ngrok.lan.mixin; - -import alujjdnd.ngrok.lan.NgrokLan; -import alujjdnd.ngrok.lan.config.NLanConfig; -import com.mojang.authlib.GameProfile; -import me.shedaniel.autoconfig.AutoConfig; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.Whitelist; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.Text; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.net.SocketAddress; - -@Mixin(PlayerManager.class) -public class PlayerManagerMixin { - NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); - - @Final - @Shadow - private Whitelist whitelist; - - @Inject(at = @At("HEAD"), method = "checkCanJoin") - public void isSpawnProtected(SocketAddress address, GameProfile profile, CallbackInfoReturnable cir) { - NgrokLan.LOGGER.info("Whitelist? " + whitelist.getFile().getAbsolutePath()); - - } -} diff --git a/srcNEW/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java b/srcNEW/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java deleted file mode 100644 index 6f1be6c..0000000 --- a/srcNEW/alujjdnd/ngrok/lan/mixin/SpawnProtectionMixin.java +++ /dev/null @@ -1,57 +0,0 @@ -package alujjdnd.ngrok.lan.mixin; - -import alujjdnd.ngrok.lan.NgrokLan; -import alujjdnd.ngrok.lan.config.NLanConfig; -import me.shedaniel.autoconfig.AutoConfig; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(MinecraftServer.class) -public class SpawnProtectionMixin { - - NLanConfig config = AutoConfig.getConfigHolder(NLanConfig.class).getConfig(); - - @Shadow - private PlayerManager playerManager; - - @Inject(at = @At("HEAD"), method = "isSpawnProtected", cancellable = true) - public void isSpawnProtected(ServerWorld world, BlockPos pos, PlayerEntity player, CallbackInfoReturnable cir) { - - if(!NgrokLan.serverOpen){ - cir.setReturnValue(false); - cir.cancel(); - } else if (config.spawnProtectionRadius <= 0) { - cir.setReturnValue(false); - cir.cancel(); - } - else if (world.getRegistryKey() != World.OVERWORLD) { - cir.setReturnValue(false); - cir.cancel(); - } else if (playerManager.isOperator(player.getGameProfile())) { - cir.setReturnValue(false); - cir.cancel(); - } else { - BlockPos blockPos = world.getSpawnPos(); - int i = MathHelper.abs(pos.getX() - blockPos.getX()); - int j = MathHelper.abs(pos.getZ() - blockPos.getZ()); - int k = Math.max(i, j); - cir.setReturnValue(k <= config.spawnProtectionRadius); - cir.cancel(); - } - //there's a small diff from vanilla check that checks if Oplist is empty. Since the host - //is an "admin" (more control than op idk the technical term) by default they are not in - //the op list, so this check does not work. - } - - -} diff --git a/srcNEW/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java b/srcNEW/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java deleted file mode 100644 index ba7bcd5..0000000 --- a/srcNEW/alujjdnd/ngrok/lan/mixin/WindowTitleMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package alujjdnd.ngrok.lan.mixin; - -import alujjdnd.ngrok.lan.NgrokLan; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.resource.language.I18n; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(MinecraftClient.class) -public abstract class WindowTitleMixin { - @Inject(method = "getWindowTitle", at = @At("HEAD"), cancellable = true) - private void injected(CallbackInfoReturnable cir) { - StringBuilder stringBuilder2 = new StringBuilder(I18n.translate("text.title.ngroklan.window")); - - if(NgrokLan.serverOpen){ - cir.setReturnValue(stringBuilder2.toString()); - } - - - } - -} \ No newline at end of file