mirror of
https://github.com/plexusorg/Module-BukkitTelnet.git
synced 2024-09-28 18:38:14 +00:00
Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
58322f8138 | |||
911be08241 | |||
5e5ce15828 | |||
c6fcb1b58e | |||
01caef2f75 | |||
c9b7dfa8de | |||
80b8badaa5 | |||
ed1faf9f96 | |||
0b5f61f28c | |||
65549b2912 | |||
b297c7019c | |||
|
12a6cd4f7c | ||
|
da6343368e | ||
|
4d3873cb1f | ||
|
950cf97ff6 | ||
f2dba7bb6b | |||
44469d91ec | |||
46ad9c7c8c | |||
28ce3ce8da | |||
316b0a4159 | |||
629919673a | |||
5002f4bc4c | |||
f8e65c179b |
18
.github/workflows/gradle.yml
vendored
Normal file
18
.github/workflows/gradle.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
name: Gradle
|
||||||
|
|
||||||
|
on: [ push ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up JDK 17
|
||||||
|
uses: actions/setup-java@v2
|
||||||
|
with:
|
||||||
|
distribution: temurin
|
||||||
|
java-version: 17
|
||||||
|
cache: gradle
|
||||||
|
- name: Build with Gradle
|
||||||
|
run: chmod a+x gradlew && ./gradlew build --no-daemon
|
49
.idea/codeStyles/Plexus_Code_Style.xml
Normal file
49
.idea/codeStyles/Plexus_Code_Style.xml
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<code_scheme name="Plexus Code Style" version="1">
|
||||||
|
<JavaCodeStyleSettings>
|
||||||
|
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="20" />
|
||||||
|
<option name="IMPORT_LAYOUT_TABLE">
|
||||||
|
<value>
|
||||||
|
<package name="" withSubpackages="true" static="false" />
|
||||||
|
<package name="" withSubpackages="true" static="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
</JavaCodeStyleSettings>
|
||||||
|
<JetCodeStyleSettings>
|
||||||
|
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||||
|
<value>
|
||||||
|
<package name="java.util" alias="false" withSubpackages="false" />
|
||||||
|
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
|
||||||
|
<package name="io.ktor" alias="false" withSubpackages="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="PACKAGES_IMPORT_LAYOUT">
|
||||||
|
<value>
|
||||||
|
<package name="" alias="false" withSubpackages="true" />
|
||||||
|
<package name="java" alias="false" withSubpackages="true" />
|
||||||
|
<package name="javax" alias="false" withSubpackages="true" />
|
||||||
|
<package name="kotlin" alias="false" withSubpackages="true" />
|
||||||
|
<package name="" alias="true" withSubpackages="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
</JetCodeStyleSettings>
|
||||||
|
<codeStyleSettings language="JAVA">
|
||||||
|
<option name="BRACE_STYLE" value="2" />
|
||||||
|
<option name="CLASS_BRACE_STYLE" value="2" />
|
||||||
|
<option name="METHOD_BRACE_STYLE" value="2" />
|
||||||
|
<option name="LAMBDA_BRACE_STYLE" value="2" />
|
||||||
|
<option name="ELSE_ON_NEW_LINE" value="true" />
|
||||||
|
<option name="WHILE_ON_NEW_LINE" value="true" />
|
||||||
|
<option name="CATCH_ON_NEW_LINE" value="true" />
|
||||||
|
<option name="FINALLY_ON_NEW_LINE" value="true" />
|
||||||
|
<option name="SPACE_AFTER_TYPE_CAST" value="true" />
|
||||||
|
<option name="IF_BRACE_FORCE" value="3" />
|
||||||
|
<option name="DOWHILE_BRACE_FORCE" value="3" />
|
||||||
|
<option name="WHILE_BRACE_FORCE" value="3" />
|
||||||
|
<option name="FOR_BRACE_FORCE" value="3" />
|
||||||
|
<option name="BLANK_LINES_AFTER_CLASS_HEADER" value="0" />
|
||||||
|
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
|
||||||
|
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
|
||||||
|
</codeStyleSettings>
|
||||||
|
</code_scheme>
|
||||||
|
</component>
|
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Plexus Code Style" />
|
||||||
|
</state>
|
||||||
|
</component>
|
24
CONTRIBUTING.md
Normal file
24
CONTRIBUTING.md
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
For those who are wanting to contribute, we fully encourage doing so. There are a few rules we require following when contributing however.
|
||||||
|
|
||||||
|
## Steps
|
||||||
|
1. Make an issue and get feedback. It's important to know if your idea will be accepted before writing any code.
|
||||||
|
- If it is a feature request, describe the feature and be extremely specific.
|
||||||
|
- If it is a bug report, ensure you include how to reproduce the bug and the expected outcome
|
||||||
|
- If it is an enhancement, describe your proposed changes. Ensure you are extremely specific.
|
||||||
|
2. Fork this project
|
||||||
|
3. Create a new branch that describes the new feature, enhancement, or bug fix. For example, this is good: `feature/add-xyz`. This is bad: `fix-this-lol`.
|
||||||
|
4. Write the code that addresses your change.
|
||||||
|
- Keep in mind that it **must** be formatted correctly. If you are using IntelliJ, there is a `codeStyle.xml` file that tells IntelliJ how to format your code. Check this link for information on how to use the file: https://www.jetbrains.com/help/idea/configuring-code-style.html#import-export-schemes
|
||||||
|
- If you are not using IntelliJ, that is fine. We use the Plexus Code Style (which is almost the same as Allman) so please format your code accordingly.
|
||||||
|
6. Push your changes to your new branch and make a PR based off of that branch.
|
||||||
|
|
||||||
|
## Requirements for a PR
|
||||||
|
- The issue must be marked as approved
|
||||||
|
- It must only address each specific issue. Don't make one PR for multiple issues.
|
||||||
|
- Your PR must compile and work. If it does not compile or work, your PR will most likely be rejected.
|
||||||
|
|
||||||
|
## Code requirements
|
||||||
|
- Most importantly, your code must be efficient. Your pull request may be rejected if your code is deemed inefficient or sloppy.
|
||||||
|
- Do not repeat yourself. Create functions as needed if you're using large blocks of code over and over again.
|
||||||
|
- Do not use an excessive amount of commits when making your PR. It makes the master branch look messy.
|
||||||
|
- Your code must be consistent with Plex's codebase. If a function already exists, use it.
|
@ -1,2 +1,2 @@
|
|||||||
# Module-BukkitTelnet
|
# Module-BukkitTelnet [![Build Status](https://ci.plex.us.org/job/Module-BukkitTelnet/badge/icon)](https://ci.plex.us.org/job/Module-BukkitTelnet/)
|
||||||
The BukkitTelnet module for Plex
|
The BukkitTelnet module for Plex
|
||||||
|
@ -4,50 +4,50 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "dev.plex"
|
group = "dev.plex"
|
||||||
version = "1.0"
|
version = "1.3"
|
||||||
description = "Module-BukkitTelnet"
|
description = "Module-BukkitTelnet"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven {
|
maven {
|
||||||
url = uri("https://papermc.io/repo/repository/maven-public/")
|
url = uri("https://repo.papermc.io/repository/maven-public/")
|
||||||
}
|
}
|
||||||
|
|
||||||
maven {
|
maven {
|
||||||
url = uri("https://nexus.telesphoreo.me/repository/plex-snapshots/")
|
url = uri("https://nexus.telesphoreo.me/repository/plex/")
|
||||||
}
|
}
|
||||||
|
|
||||||
maven {
|
|
||||||
url = uri("https://nexus.telesphoreo.me/repository/totalfreedom/")
|
|
||||||
}
|
|
||||||
maven {
|
maven {
|
||||||
url = uri("https://jitpack.io")
|
url = uri("https://jitpack.io")
|
||||||
|
content {
|
||||||
|
includeGroup("com.github.plexusorg")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("org.projectlombok:lombok:1.18.22")
|
compileOnly("org.projectlombok:lombok:1.18.28")
|
||||||
annotationProcessor("org.projectlombok:lombok:1.18.22")
|
annotationProcessor("org.projectlombok:lombok:1.18.28")
|
||||||
compileOnly("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT")
|
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
|
||||||
compileOnly("dev.plex:Plex:1.0.1-SNAPSHOT")
|
compileOnly("dev.plex:server:1.3")
|
||||||
compileOnly("me.totalfreedom:BukkitTelnet:4.8") {
|
compileOnly("com.github.plexusorg:BukkitTelnet:6908ff201f") {
|
||||||
exclude("org.spigotmc", "spigot-api")
|
exclude("org.papermc.paper", "paper-api")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||||
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
compileJava {
|
compileJava {
|
||||||
options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything
|
options.encoding = Charsets.UTF_8.name()
|
||||||
|
|
||||||
// Set the release flag. This configures what version bytecode the compiler will emit, as well as what JDK APIs are usable.
|
|
||||||
// See https://openjdk.java.net/jeps/247 for more information.
|
|
||||||
options.release.set(17)
|
|
||||||
}
|
}
|
||||||
javadoc {
|
javadoc {
|
||||||
options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything
|
options.encoding = Charsets.UTF_8.name()
|
||||||
}
|
}
|
||||||
processResources {
|
processResources {
|
||||||
filteringCharset = Charsets.UTF_8.name() // We want UTF-8 for everything
|
filteringCharset = Charsets.UTF_8.name()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
18
gradlew
vendored
18
gradlew
vendored
@ -55,7 +55,7 @@
|
|||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (3) This script is generated from the Groovy template
|
||||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
# within the Gradle project.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
@ -80,10 +80,10 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
APP_NAME="Gradle"
|
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# 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"'
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
@ -143,12 +143,16 @@ fi
|
|||||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
max*)
|
max*)
|
||||||
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC3045
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
warn "Could not query maximum file descriptor limit"
|
warn "Could not query maximum file descriptor limit"
|
||||||
esac
|
esac
|
||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
'' | soft) :;; #(
|
'' | soft) :;; #(
|
||||||
*)
|
*)
|
||||||
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC3045
|
||||||
ulimit -n "$MAX_FD" ||
|
ulimit -n "$MAX_FD" ||
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
esac
|
esac
|
||||||
@ -205,6 +209,12 @@ set -- \
|
|||||||
org.gradle.wrapper.GradleWrapperMain \
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
# Use "xargs" to parse quoted args.
|
# Use "xargs" to parse quoted args.
|
||||||
#
|
#
|
||||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
15
gradlew.bat
vendored
15
gradlew.bat
vendored
@ -14,7 +14,7 @@
|
|||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%" == "" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@rem
|
@rem
|
||||||
@rem Gradle startup script for Windows
|
@rem Gradle startup script for Windows
|
||||||
@ -25,7 +25,8 @@
|
|||||||
if "%OS%"=="Windows_NT" setlocal
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
|||||||
|
|
||||||
set JAVA_EXE=java.exe
|
set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if "%ERRORLEVEL%" == "0" goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
:fail
|
:fail
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
rem the _cmd.exe /c_ return code!
|
rem the _cmd.exe /c_ return code!
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
exit /b 1
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
:mainEnd
|
:mainEnd
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
@ -1,16 +1,20 @@
|
|||||||
package dev.plex;
|
package dev.plex;
|
||||||
|
|
||||||
|
import dev.plex.automation.PatchedTelnetCompiler;
|
||||||
import dev.plex.listener.BukkitTelnetListener;
|
import dev.plex.listener.BukkitTelnetListener;
|
||||||
import dev.plex.module.PlexModule;
|
import dev.plex.module.PlexModule;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.totalfreedom.bukkittelnet.BukkitTelnet;
|
import me.totalfreedom.bukkittelnet.BukkitTelnet;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class BukkitTelnetModule extends PlexModule
|
public class BukkitTelnetModule extends PlexModule
|
||||||
{
|
{
|
||||||
@Getter
|
@Getter
|
||||||
private static BukkitTelnetModule module;
|
private static BukkitTelnetModule module;
|
||||||
|
boolean failed = false;
|
||||||
private BukkitTelnet bukkitTelnet;
|
private BukkitTelnet bukkitTelnet;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -24,7 +28,54 @@ public class BukkitTelnetModule extends PlexModule
|
|||||||
{
|
{
|
||||||
if (getPlex().getSystem().equalsIgnoreCase("permissions") && !Bukkit.getPluginManager().isPluginEnabled("Vault"))
|
if (getPlex().getSystem().equalsIgnoreCase("permissions") && !Bukkit.getPluginManager().isPluginEnabled("Vault"))
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Plex-BukkitTelnet requires the 'Vault' plugin as well as a Permissions plugin that hooks into 'Vault.' We recommend LuckPerms!");
|
failed = true;
|
||||||
|
PlexLog.error("Plex-BukkitTelnet requires the 'Vault' plugin as well as a Permissions plugin that hooks into 'Vault.' We recommend LuckPerms!");
|
||||||
|
module.disable();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Bukkit.getPluginManager().isPluginEnabled("BukkitTelnet"))
|
||||||
|
{
|
||||||
|
failed = true;
|
||||||
|
PlexLog.warn("The Plex-BukkitTelnet module requires the BukkitTelnet plugin to work. I am automatically compiling BukkitTelnet plugin for you, however if something fails, please download it from: https://github.com/plexusorg/BukkitTelnet/releases");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PatchedTelnetCompiler.execute();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
PlexLog.error("Failed to compile patched telnet.");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
module.disable();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
failed = true;
|
||||||
|
Class<?> clazz = Class.forName("me.totalfreedom.bukkittelnet.BukkitTelnet");
|
||||||
|
Method method = clazz.getDeclaredMethod("getPlugin");
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException | NoSuchMethodException ignored)
|
||||||
|
{
|
||||||
|
PlexLog.warn("You are using an older version of BukkitTelnet that does not support Plex. I am automatically compiling a build that does work for you, however if something fails, please download a version that does from: https://ci.plex.us.org/job/Plex-BukkitTelnet");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PatchedTelnetCompiler.execute();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
PlexLog.error("Failed to compile patched telnet.");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
module.disable();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.registerListener(new BukkitTelnetListener());
|
this.registerListener(new BukkitTelnetListener());
|
||||||
@ -34,5 +85,9 @@ public class BukkitTelnetModule extends PlexModule
|
|||||||
@Override
|
@Override
|
||||||
public void disable()
|
public void disable()
|
||||||
{
|
{
|
||||||
|
if (failed)
|
||||||
|
{
|
||||||
|
PlexLog.error("Disabling Module-BukkitTelnet. Please resolve the above error.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
224
src/main/java/dev/plex/automation/PatchedTelnetCompiler.java
Normal file
224
src/main/java/dev/plex/automation/PatchedTelnetCompiler.java
Normal file
@ -0,0 +1,224 @@
|
|||||||
|
package dev.plex.automation;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import dev.plex.BukkitTelnetModule;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
|
public class PatchedTelnetCompiler
|
||||||
|
{
|
||||||
|
private static final PluginManager PLUGIN_MANAGER = Bukkit.getPluginManager();
|
||||||
|
private static final URI CODE_ARCHIVE = URI.create("https://github.com/plexusorg/BukkitTelnet/archive/refs/heads/master.zip");
|
||||||
|
private static final Path PLUGIN_DIRECTORY = Bukkit.getServer().getPluginsFolder().toPath();
|
||||||
|
private static final File TARGET_PLUGIN = PLUGIN_DIRECTORY.resolve("BukkitTelnet.jar").toFile();
|
||||||
|
private static final Path WORKING_DIRECTORY = Path.of(System.getProperty("user.dir"));
|
||||||
|
private static final Path HIDDEN_GRADLE = WORKING_DIRECTORY.resolve(".gradle");
|
||||||
|
private static final Path ROOT_PATH = WORKING_DIRECTORY.resolve("build");
|
||||||
|
private static final Path EXTRACT_TARGET = ROOT_PATH.resolve("extract");
|
||||||
|
private static final Path EXTRACT_SUBDIR = EXTRACT_TARGET.resolve("BukkitTelnet-master");
|
||||||
|
private static final Path BINARIES_PATH = EXTRACT_SUBDIR.resolve("build").resolve("libs");
|
||||||
|
private static final String DOWNLOADED_ARCHIVE_PATH = String.valueOf(ROOT_PATH.resolve("BukkitTelnet-master.zip"));
|
||||||
|
private static final HttpClient HTTP_CLIENT = HttpClient.newHttpClient();
|
||||||
|
|
||||||
|
public static void execute() throws Exception
|
||||||
|
{
|
||||||
|
// Create directories
|
||||||
|
final List<Path> directories = ImmutableList.of(ROOT_PATH, EXTRACT_TARGET);
|
||||||
|
|
||||||
|
for (Path directory : directories)
|
||||||
|
{
|
||||||
|
PlexLog.debug("Checking if {0} exists...", String.valueOf(directory));
|
||||||
|
if (Files.notExists(directory))
|
||||||
|
{
|
||||||
|
PlexLog.debug("It doesn't! Creating directory...");
|
||||||
|
Files.createDirectory(directory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadArchive();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void downloadArchive() throws Exception
|
||||||
|
{
|
||||||
|
PlexLog.log("Downloading archive...");
|
||||||
|
// Create the request
|
||||||
|
final HttpRequest request = HttpRequest.newBuilder()
|
||||||
|
.GET()
|
||||||
|
// GitHub may block blank/generic user agents in the future, so we're spoofing one
|
||||||
|
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36")
|
||||||
|
.uri(CODE_ARCHIVE)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
final HttpResponse<String> response = HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
|
|
||||||
|
// Get the redirect
|
||||||
|
final URI redirect = URI.create(response.headers().firstValue("location").orElseThrow());
|
||||||
|
|
||||||
|
// Download the file from the redirect
|
||||||
|
final HttpRequest downloadRequest = HttpRequest.newBuilder()
|
||||||
|
.GET()
|
||||||
|
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36")
|
||||||
|
.uri(redirect)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HTTP_CLIENT.send(downloadRequest, HttpResponse.BodyHandlers.ofFileDownload(ROOT_PATH, StandardOpenOption.CREATE, StandardOpenOption.WRITE));
|
||||||
|
|
||||||
|
extractArchive();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void extractArchive() throws Exception
|
||||||
|
{
|
||||||
|
PlexLog.log("Extracting archive...");
|
||||||
|
final ZipInputStream inputStream = new ZipInputStream(new FileInputStream(DOWNLOADED_ARCHIVE_PATH));
|
||||||
|
ZipEntry entry = inputStream.getNextEntry();
|
||||||
|
|
||||||
|
while (entry != null)
|
||||||
|
{
|
||||||
|
final Path outputDestination = EXTRACT_TARGET.resolve(entry.getName());
|
||||||
|
|
||||||
|
if (entry.isDirectory())
|
||||||
|
{
|
||||||
|
if (Files.notExists(outputDestination))
|
||||||
|
{
|
||||||
|
PlexLog.debug("{0} doesn't exist, creating it!", String.valueOf(outputDestination));
|
||||||
|
Files.createDirectory(outputDestination);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
final FileOutputStream outputStream = new FileOutputStream(String.valueOf(outputDestination));
|
||||||
|
int read = 0;
|
||||||
|
while ((read = inputStream.read()) != -1)
|
||||||
|
{
|
||||||
|
outputStream.write(read);
|
||||||
|
}
|
||||||
|
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
inputStream.closeEntry();
|
||||||
|
entry = inputStream.getNextEntry();
|
||||||
|
}
|
||||||
|
|
||||||
|
executeGradleTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void executeGradleTarget() throws Exception
|
||||||
|
{
|
||||||
|
PlexLog.log("Executing gradle target...");
|
||||||
|
boolean nix = !System.getProperty("os.name").toLowerCase().contains("win"); // Assume Windows if name contains win
|
||||||
|
|
||||||
|
String gradlew = String.valueOf(nix ? EXTRACT_SUBDIR.resolve("gradlew") : EXTRACT_SUBDIR.resolve("gradlew.bat"));
|
||||||
|
if (nix)
|
||||||
|
{
|
||||||
|
final ProcessBuilder chmodBuilder = new ProcessBuilder("chmod", "+x", gradlew);
|
||||||
|
Process chmodProcess = chmodBuilder.start();
|
||||||
|
chmodProcess.waitFor();
|
||||||
|
}
|
||||||
|
|
||||||
|
final ProcessBuilder builder = new ProcessBuilder(gradlew, "--no-daemon", "clean", "build");
|
||||||
|
builder.directory(new File(String.valueOf(EXTRACT_SUBDIR)));
|
||||||
|
PlexLog.debug("Executing compile command: {0}", builder.command());
|
||||||
|
|
||||||
|
//builder.redirectErrorStream(true);
|
||||||
|
//builder.redirectOutput(ProcessBuilder.Redirect.PIPE);
|
||||||
|
builder.inheritIO();
|
||||||
|
|
||||||
|
final Process process = builder.start();
|
||||||
|
process.waitFor();
|
||||||
|
PlexLog.debug("Compilation command ended with status code {0}", process.exitValue());
|
||||||
|
copyBinary();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void copyBinary() throws Exception
|
||||||
|
{
|
||||||
|
PlexLog.log("Copying binaries...");
|
||||||
|
final File binaryDirectory = new File(String.valueOf(BINARIES_PATH));
|
||||||
|
final File[] files = binaryDirectory.listFiles();
|
||||||
|
|
||||||
|
if (files == null)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException("Didn't manage to compile jars!");
|
||||||
|
}
|
||||||
|
else if (files.length == 0)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException("Didn't manage to compile jars!");
|
||||||
|
}
|
||||||
|
|
||||||
|
Files.copy(BINARIES_PATH.resolve("BukkitTelnet.jar"), TARGET_PLUGIN.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
Files.walk(ROOT_PATH)
|
||||||
|
.sorted(Comparator.reverseOrder())
|
||||||
|
.map(Path::toFile)
|
||||||
|
.forEach(File::delete);
|
||||||
|
|
||||||
|
if (Files.exists(HIDDEN_GRADLE))
|
||||||
|
{
|
||||||
|
Files.walk(HIDDEN_GRADLE)
|
||||||
|
.sorted(Comparator.reverseOrder())
|
||||||
|
.map(Path::toFile)
|
||||||
|
.forEach(File::delete);
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer timer = new Timer();
|
||||||
|
Plugin plugin = null;
|
||||||
|
|
||||||
|
// Check if incorrect BukkitTelnet plugin is present
|
||||||
|
if (PLUGIN_MANAGER.isPluginEnabled("BukkitTelnet"))
|
||||||
|
{
|
||||||
|
PlexLog.warn("Stopping server since unpatched BukkitTelnet was already loaded, please restart and it should work!");
|
||||||
|
// Running stop doesn't seem to work...
|
||||||
|
|
||||||
|
Bukkit.savePlayers();
|
||||||
|
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
onlinePlayer.kick(Component.text("Server is restarting due to a plugin upgrade, please wait!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (World world : Bukkit.getWorlds())
|
||||||
|
{
|
||||||
|
Bukkit.unloadWorld(world, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Runtime.getRuntime().halt(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plugin = PLUGIN_MANAGER.loadPlugin(TARGET_PLUGIN);
|
||||||
|
}
|
||||||
|
if (plugin == null) throw new IllegalStateException("BukkitTelnet cannot be null after successful compile!");
|
||||||
|
|
||||||
|
plugin.onLoad();
|
||||||
|
PLUGIN_MANAGER.enablePlugin(plugin);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void done()
|
||||||
|
{
|
||||||
|
BukkitTelnetModule.getModule().enable();
|
||||||
|
}
|
||||||
|
}
|
@ -5,10 +5,7 @@ import dev.plex.player.PlexPlayer;
|
|||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import me.totalfreedom.bukkittelnet.BukkitTelnet;
|
import me.totalfreedom.bukkittelnet.BukkitTelnet;
|
||||||
import me.totalfreedom.bukkittelnet.api.TelnetCommandEvent;
|
|
||||||
import me.totalfreedom.bukkittelnet.api.TelnetPreLoginEvent;
|
import me.totalfreedom.bukkittelnet.api.TelnetPreLoginEvent;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
|
||||||
public class BukkitTelnetListener extends PlexListener
|
public class BukkitTelnetListener extends PlexListener
|
||||||
@ -18,7 +15,10 @@ public class BukkitTelnetListener extends PlexListener
|
|||||||
{
|
{
|
||||||
final String ip = event.getIp();
|
final String ip = event.getIp();
|
||||||
final PlexPlayer player = DataUtils.getPlayerByIP(ip);
|
final PlexPlayer player = DataUtils.getPlayerByIP(ip);
|
||||||
if (player == null) return;
|
if (player == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||||
{
|
{
|
||||||
PlexLog.debug("Plex-BukkitTelnet using ranks check");
|
PlexLog.debug("Plex-BukkitTelnet using ranks check");
|
||||||
@ -27,7 +27,8 @@ public class BukkitTelnetListener extends PlexListener
|
|||||||
event.setBypassPassword(true);
|
event.setBypassPassword(true);
|
||||||
event.setName(player.getName());
|
event.setName(player.getName());
|
||||||
}
|
}
|
||||||
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
}
|
||||||
|
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
||||||
{
|
{
|
||||||
PlexLog.debug("Plex-BukkitTelnet using permissions check");
|
PlexLog.debug("Plex-BukkitTelnet using permissions check");
|
||||||
if (BukkitTelnet.getPlugin().handler.hasPermission(player.getName(), "plex.telnet.autoconnect"))
|
if (BukkitTelnet.getPlugin().handler.hasPermission(player.getName(), "plex.telnet.autoconnect"))
|
||||||
@ -38,5 +39,4 @@ public class BukkitTelnetListener extends PlexListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
name: Plex-BukkitTelnet
|
name: Module-BukkitTelnet
|
||||||
main: dev.plex.BukkitTelnetModule
|
main: dev.plex.BukkitTelnetModule
|
||||||
description: The Plex module for BukkitTelnet
|
description: The Plex module for BukkitTelnet
|
||||||
version: 1.0
|
version: 1.3
|
Loading…
Reference in New Issue
Block a user