mirror of
https://code.chipmunk.land/Parker2991/NitoriBot/
synced 2026-11-29 13:45:38 -05:00
Compare commits
15
Commits
java-rewrite
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b480b992f | ||
|
|
5a0bb98789 | ||
|
|
9633837c0c | ||
|
|
41aae90916 | ||
|
|
0dd8610bb3 | ||
|
|
3c2837dac7 | ||
|
|
24f9c4fa45 | ||
|
|
baf210f369 | ||
|
|
a331466d9e | ||
|
|
4fb7099c0f | ||
|
|
89dbac9974 | ||
|
|
dc03b5157f | ||
|
|
4e2d737f9d | ||
|
|
16c92b075d | ||
|
|
6a26617c83 |
+8
-2
@@ -10,5 +10,11 @@ build
|
||||
# Ignore the bin folder vscode keeps creating
|
||||
bin
|
||||
|
||||
# Ignore the config
|
||||
config.yaml
|
||||
# proxies
|
||||
proxies.txt
|
||||
|
||||
# ignore the config
|
||||
config.yml
|
||||
|
||||
# ignore chat attestation
|
||||
chatattestation
|
||||
|
||||
Generated
+1
@@ -0,0 +1 @@
|
||||
NitoriBot
|
||||
Generated
+5
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default copy" />
|
||||
</state>
|
||||
</component>
|
||||
Generated
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="PROJECT_FILES" />
|
||||
<option name="description" value="" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
-1
@@ -5,7 +5,6 @@
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="25" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,java.lang.foreign.Arena,ofAuto,java.lang.foreign.Arena,global,java.net.http.HttpClient.Builder,build,java.lang.ClassLoader,getResourceAsStream" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
||||
Generated
+27
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JsonSchemaMappingsProjectConfiguration">
|
||||
<state>
|
||||
<map>
|
||||
<entry key="No JSON schema">
|
||||
<value>
|
||||
<SchemaInfo>
|
||||
<option name="ignoredFile" value="true" />
|
||||
<option name="name" value="No JSON schema" />
|
||||
<option name="relativePathToSchema" value="" />
|
||||
<option name="applicationDefined" value="true" />
|
||||
<option name="patterns">
|
||||
<list>
|
||||
<Item>
|
||||
<option name="path" value="file://$PROJECT_DIR$/src/main/resources/info.json" />
|
||||
</Item>
|
||||
</list>
|
||||
</option>
|
||||
<option name="isIgnoredFile" value="true" />
|
||||
</SchemaInfo>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</state>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+4
-1
@@ -1,5 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="25 (4)" project-jdk-type="JavaSDK" />
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="25 (3)" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
+71
-48
@@ -1,62 +1,85 @@
|
||||
version = "v9.0.0"
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.ZoneId
|
||||
import java.time.ZonedDateTime
|
||||
|
||||
version = "v9.0.0-alpha"
|
||||
group = "nitoribot"
|
||||
description = "NitoriBot"
|
||||
plugins {
|
||||
id("com.gradleup.shadow") version "9.2.2"
|
||||
kotlin("jvm") version "2.3.10"
|
||||
id("maven-publish")
|
||||
application
|
||||
kotlin("jvm") version "2.3.10"
|
||||
id("maven-publish")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(25)
|
||||
jvmToolchain(25)
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
||||
mavenCentral()
|
||||
|
||||
maven("https://repo.opencollab.dev/maven-releases/")
|
||||
|
||||
maven("https://repo.opencollab.dev/maven-snapshots/")
|
||||
|
||||
maven("https://jitpack.io/")
|
||||
|
||||
maven("https://repo.opencollab.dev/main/")
|
||||
|
||||
maven("https://maven.maxhenkel.de/repository/public/")
|
||||
|
||||
// maven("https://libraries.minecraft.net")
|
||||
|
||||
/* maven("https://code.optmstc.dev/api/packages/kso/maven") {
|
||||
content {
|
||||
includeGroupAndSubgroups("land.chipmunk.code")
|
||||
}
|
||||
}*/
|
||||
|
||||
//maven("https://libraries.minecraft.net")
|
||||
|
||||
maven("https://code.chipmunk.land/api/packages/kaboomstandardsorganization/maven/")
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.opencollab.dev/maven-releases/")
|
||||
maven("https://repo.opencollab.dev/maven-snapshots/")
|
||||
maven("https://jitpack.io/")
|
||||
maven("https://repo.opencollab.dev/main/")
|
||||
maven("https://maven.maxhenkel.de/repository/public/")
|
||||
maven("https://central.sonatype.com/repository/maven-snapshots")
|
||||
maven("https://code.chipmunk.land/api/packages/kaboomstandardsorganization/maven/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.geysermc.mcprotocollib:protocol:26.2-SNAPSHOT")
|
||||
implementation("org.slf4j:slf4j-api:2.0.13")
|
||||
implementation("org.tinylog:slf4j-tinylog:2.7.0")
|
||||
implementation("org.tinylog:tinylog-impl:2.7.0")
|
||||
implementation("org.yaml:snakeyaml:2.2")
|
||||
implementation("net.kyori:adventure-text-serializer-ansi:4.26.1")
|
||||
implementation("net.kyori:adventure-text-serializer-plain:4.26.1")
|
||||
implementation("net.kyori:adventure-text-serializer-legacy:4.26.1")
|
||||
implementation("net.kyori:adventure-text-serializer-gson:4.26.1")
|
||||
implementation("net.dv8tion:JDA:6.4.1")
|
||||
implementation("de.connect2x.trixnity:trixnity-client:5.0.0")
|
||||
implementation("org.pircbotx:pircbotx:2.1")
|
||||
implementation("org.jline:jline:4.1.0")
|
||||
implementation("land.chipmunk.code.kaboomstandardsorganization.messaginglib:mcprotocollib:3.1.2")
|
||||
implementation("org.geysermc.mcprotocollib:protocol:26.3-SNAPSHOT")
|
||||
implementation("ch.qos.logback:logback-classic:1.6.6")
|
||||
implementation("org.slf4j:slf4j-api:2.0.20")
|
||||
implementation("org.yaml:snakeyaml:2.7")
|
||||
implementation("net.kyori:adventure-text-serializer-ansi:5.2.0")
|
||||
implementation("net.kyori:adventure-text-serializer-plain:5.2.0")
|
||||
implementation("net.kyori:adventure-text-serializer-legacy:5.2.0")
|
||||
implementation("net.kyori:adventure-text-serializer-gson:5.2.0")
|
||||
implementation("net.kyori:adventure-text-minimessage:5.2.0")
|
||||
implementation("net.lenni0451:LambdaEvents:2.4.2")
|
||||
implementation("org.jline:jline:4.4.7")
|
||||
implementation("com.github.oshi:oshi-core:7.7.1")
|
||||
implementation("net.kyori:adventure-nbt:5.2.0")
|
||||
implementation("org.bouncycastle:bcprov-jdk18on:1.84")
|
||||
implementation("net.jodah:expiringmap:0.5.11")
|
||||
implementation("org.apache.commons:commons-compress:1.28.0")
|
||||
implementation("io.github.wasabithumb:jtoml-configurate:1.5.1")
|
||||
implementation("com.github.luben:zstd-jni:1.5.6-9")
|
||||
implementation("land.chipmunk.code.kaboomstandardsorganization.messaginglib:mcprotocollib:3.1.2")
|
||||
implementation("com.google.guava:guava:33.6.0-jre")
|
||||
implementation("net.dv8tion:JDA:6.7.0")
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set("land.chipmunk.parker2991.nitoribot.Main")
|
||||
}
|
||||
tasks.jar {
|
||||
val timeZone = ZoneId.of("America/Chicago");
|
||||
val zoneDate = ZonedDateTime.now(timeZone);
|
||||
val dateTimeFormatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy hh:mm:ss a")
|
||||
val dateTimeInfo = zoneDate.toLocalDateTime();
|
||||
|
||||
manifest {
|
||||
attributes["Main-Class"] = "land.chipmunk.parker2991.nitoribot.nightofnights.Main"
|
||||
attributes("Build-Time" to dateTimeFormatter.format(dateTimeInfo))
|
||||
attributes("Enable-Native-Access" to "ALL-UNNAMED")
|
||||
}
|
||||
|
||||
archiveClassifier.set("all")
|
||||
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
|
||||
from(sourceSets.main.get().output)
|
||||
|
||||
dependsOn(configurations.runtimeClasspath)
|
||||
|
||||
from(
|
||||
{
|
||||
exclude("META-INF/*.SF")
|
||||
exclude("META-INF/*.RSA")
|
||||
exclude("META-INF/*.DSA")
|
||||
configurations.runtimeClasspath.get().filter {
|
||||
it.name.endsWith("jar")
|
||||
}.map {
|
||||
zipTree(it)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<code_scheme name="Default copy" version="173">
|
||||
<JavaCodeStyleSettings>
|
||||
<option name="DO_NOT_WRAP_AFTER_SINGLE_ANNOTATION" value="true" />
|
||||
<option name="ANNOTATION_PARAMETER_WRAP" value="5" />
|
||||
<option name="ENUM_FIELD_ANNOTATION_WRAP" value="5" />
|
||||
<option name="NEW_LINE_AFTER_LPAREN_IN_ANNOTATION" value="true" />
|
||||
<option name="RPAREN_ON_NEW_LINE_IN_ANNOTATION" value="true" />
|
||||
<option name="RECORD_COMPONENTS_WRAP" value="5" />
|
||||
<option name="NEW_LINE_AFTER_LPAREN_IN_RECORD_HEADER" value="true" />
|
||||
<option name="RPAREN_ON_NEW_LINE_IN_RECORD_HEADER" value="true" />
|
||||
<option name="DECONSTRUCTION_LIST_WRAP" value="5" />
|
||||
<option name="SPACE_BEFORE_DECONSTRUCTION_LIST" value="true" />
|
||||
<option name="MULTI_CATCH_TYPES_WRAP" value="5" />
|
||||
<option name="ALIGN_TYPES_IN_MULTI_CATCH" value="false" />
|
||||
</JavaCodeStyleSettings>
|
||||
<codeStyleSettings language="JAVA">
|
||||
<option name="KEEP_LINE_BREAKS" value="false" />
|
||||
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
|
||||
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
|
||||
<option name="ALIGN_MULTILINE_RESOURCES" value="false" />
|
||||
<option name="ALIGN_MULTILINE_FOR" value="false" />
|
||||
<option name="SPACE_BEFORE_METHOD_PARENTHESES" value="true" />
|
||||
<option name="CALL_PARAMETERS_WRAP" value="5" />
|
||||
<option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="METHOD_PARAMETERS_WRAP" value="5" />
|
||||
<option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="RESOURCE_LIST_LPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="RESOURCE_LIST_RPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
|
||||
<option name="TERNARY_OPERATION_WRAP" value="5" />
|
||||
<option name="FOR_STATEMENT_LPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="FOR_STATEMENT_RPAREN_ON_NEXT_LINE" value="true" />
|
||||
<option name="ARRAY_INITIALIZER_WRAP" value="5" />
|
||||
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
|
||||
<option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
|
||||
<option name="SWITCH_EXPRESSIONS_WRAP" value="5" />
|
||||
<option name="CLASS_ANNOTATION_WRAP" value="5" />
|
||||
<option name="FIELD_ANNOTATION_WRAP" value="5" />
|
||||
<option name="PARAMETER_ANNOTATION_WRAP" value="5" />
|
||||
<option name="VARIABLE_ANNOTATION_WRAP" value="5" />
|
||||
<option name="ENUM_CONSTANTS_WRAP" value="5" />
|
||||
<option name="WRAP_ON_TYPING" value="0" />
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
Vendored
BIN
Binary file not shown.
+3
-1
@@ -1,7 +1,9 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.0-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.0-bin.zip
|
||||
networkTimeout=10000
|
||||
retries=0
|
||||
retryBackOffMs=500
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
# gradlew start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
@@ -29,7 +29,7 @@
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
# ksh gradlew
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
@@ -57,7 +57,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/b631911858264c0b6e4d6603d677ff5218766cee/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
|
||||
Vendored
+52
-33
@@ -19,12 +19,39 @@
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem gradlew startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
@rem Set local scope for the variables, and ensure extensions are enabled
|
||||
setlocal EnableExtensions
|
||||
|
||||
@rem Catch executions from older scripts and ensure they exit cleanly.
|
||||
@rem This can be removed once we can be reasonably confident that few people
|
||||
@rem will be migrating directly to this new wrapper.
|
||||
goto afterSafetyNet
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
goto exitWithErrorLevel
|
||||
:afterSafetyNet
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@@ -45,13 +72,14 @@ set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
1>&2 echo.
|
||||
1>&2 echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
1>&2 echo.
|
||||
1>&2 echo Please set the JAVA_HOME variable in your environment to match the
|
||||
1>&2 echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
"%COMSPEC%" /c exit 1
|
||||
goto exitWithErrorLevel
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
@@ -59,35 +87,26 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
1>&2 echo.
|
||||
1>&2 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
1>&2 echo.
|
||||
1>&2 echo Please set the JAVA_HOME variable in your environment to match the
|
||||
1>&2 echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
"%COMSPEC%" /c exit 1
|
||||
goto exitWithErrorLevel
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
@rem Execute gradlew
|
||||
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
|
||||
@rem which allows us to clear the local environment before executing the java command
|
||||
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel & goto exitWithErrorLevel
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@rem This label must not be changed. We rely on old scripts being able to jump to this point.
|
||||
:exitWithErrorLevel
|
||||
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
|
||||
"%COMSPEC%" /c exit %ERRORLEVEL%
|
||||
|
||||
@@ -1,232 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.logger.Logger;
|
||||
import land.chipmunk.parker2991.nitoribot.modules.*;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.*;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import org.geysermc.mcprotocollib.network.ProxyInfo;
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectingEvent;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectedEvent;
|
||||
import org.geysermc.mcprotocollib.network.event.session.PacketErrorEvent;
|
||||
import org.geysermc.mcprotocollib.network.event.session.SessionAdapter;
|
||||
import org.geysermc.mcprotocollib.network.session.ClientNetworkSession;
|
||||
import org.geysermc.mcprotocollib.network.factory.ClientNetworkSessionFactory;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.auth.GameProfile;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundPlayerLoadedPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.login.clientbound.ClientboundLoginFinishedPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundPlayerLoadedPacket;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.Scanner;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
|
||||
public class Bot extends SessionAdapter {
|
||||
public final ListenerManager listenerManager = new ListenerManager();
|
||||
|
||||
public boolean loggedIn = false;
|
||||
|
||||
public int entityId;
|
||||
|
||||
public final ScheduledExecutorService executor = Main.executor;
|
||||
|
||||
public final ExecutorService executorService = Main.executorService;
|
||||
|
||||
public ClientNetworkSession session;
|
||||
|
||||
public GameProfile profile;
|
||||
|
||||
public Config config;
|
||||
|
||||
public Config.Options options;
|
||||
|
||||
public List<Bot> bots;
|
||||
|
||||
public ChatModule chat;
|
||||
|
||||
public ConsoleModule console;
|
||||
|
||||
public SelfcareModule selfcare;
|
||||
|
||||
public PositionModule position;
|
||||
|
||||
public CommandCoreModule core;
|
||||
|
||||
public PlayerListModule players;
|
||||
|
||||
public RegistryModule registry;
|
||||
|
||||
public CommandManagerModule commandManager;
|
||||
|
||||
public ExtrasMessagingModule extrasMessaging;
|
||||
|
||||
public MCServerModule mcServer;
|
||||
|
||||
public ProxyInfo randomProxyIp () throws IOException {
|
||||
String result = null; // stub
|
||||
|
||||
Path proxiesPath = Paths.get("proxies.txt");
|
||||
|
||||
int countLines = Math.round(
|
||||
Files.lines(proxiesPath).count()
|
||||
);
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
int randomIndex = random.nextInt(countLines);
|
||||
|
||||
String[] getIp = Files.lines(proxiesPath)
|
||||
.skip(randomIndex)
|
||||
.findAny()
|
||||
.get()
|
||||
.split(":");
|
||||
|
||||
String ip = getIp[0];
|
||||
int port = new Integer(getIp[1]);
|
||||
|
||||
return new ProxyInfo(
|
||||
ProxyInfo.Type.SOCKS5,
|
||||
new InetSocketAddress(ip, port)
|
||||
);
|
||||
}
|
||||
|
||||
public void loadModules () {
|
||||
try {
|
||||
this.chat = new ChatModule(this);
|
||||
this.selfcare = new SelfcareModule(this);
|
||||
this.position = new PositionModule(this);
|
||||
this.core = new CommandCoreModule(this);
|
||||
this.registry = new RegistryModule(this);
|
||||
this.players = new PlayerListModule(this);
|
||||
new LoggingModule(this);
|
||||
new ChatCommandHandlerModule(this);
|
||||
this.commandManager = new CommandManagerModule(this);
|
||||
this.extrasMessaging = new ExtrasMessagingModule(this);
|
||||
new TextDisplayModule(this);
|
||||
this.mcServer = new MCServerModule(this);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
public Bot (Config.Options options, List<Bot> bots, Config config) {
|
||||
this.options = options;
|
||||
this.bots = bots;
|
||||
this.config = config;
|
||||
|
||||
try {
|
||||
connect();
|
||||
} catch (Exception e) {}
|
||||
};
|
||||
|
||||
public void connect () throws IOException {
|
||||
final MinecraftProtocol protocol = new MinecraftProtocol(options.username);
|
||||
|
||||
if (options.useProxy) session = ClientNetworkSessionFactory.factory()
|
||||
.setAddress(
|
||||
options.host,
|
||||
options.port
|
||||
)
|
||||
.setProxy(randomProxyIp())
|
||||
.setProtocol(protocol)
|
||||
.create();
|
||||
|
||||
else session = ClientNetworkSessionFactory.factory()
|
||||
.setAddress(
|
||||
options.host,
|
||||
options.port
|
||||
)
|
||||
.setProtocol(protocol)
|
||||
.create();
|
||||
session.addListener(this);
|
||||
loadModules();
|
||||
session.connect(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnecting (DisconnectingEvent event) {
|
||||
String reason = event + "";
|
||||
session.disconnect(reason);
|
||||
}
|
||||
|
||||
// ServerboundPlayerLoadedPacket
|
||||
|
||||
@Override
|
||||
public void packetSent (Session session, Packet packet) {
|
||||
for (Listener listener : listenerManager.listeners) {
|
||||
listener.packetSent(session, packet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetError (PacketErrorEvent error) {
|
||||
error.setSuppress(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
try {
|
||||
if (packet instanceof ClientboundLoginPacket) this.session.send(
|
||||
ServerboundPlayerLoadedPacket.INSTANCE
|
||||
);
|
||||
|
||||
if (packet instanceof ServerboundPlayerLoadedPacket) {
|
||||
System.out.println(packet);
|
||||
}
|
||||
|
||||
for (Listener listener : listenerManager.listeners) {
|
||||
listener.packetReceived(session, packet);
|
||||
}
|
||||
|
||||
if (packet instanceof ClientboundLoginFinishedPacket) getProfile((ClientboundLoginFinishedPacket) packet);
|
||||
else if (packet instanceof ClientboundLoginPacket) getEntityId((ClientboundLoginPacket) packet);
|
||||
} catch (Exception e) { }
|
||||
}
|
||||
|
||||
|
||||
public void getProfile (ClientboundLoginFinishedPacket packet) {
|
||||
profile = packet.getProfile();
|
||||
|
||||
loggedIn = true;
|
||||
}
|
||||
|
||||
public void getEntityId (ClientboundLoginPacket packet) {
|
||||
entityId = packet.getEntityId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected (DisconnectedEvent event) {
|
||||
listenerManager.clearListener();
|
||||
|
||||
loggedIn = false;
|
||||
|
||||
Component component = event.getReason();
|
||||
|
||||
String reason = ComponentUtil.componentToAnsi(component);
|
||||
|
||||
int reconnectDelay = options.reconnectDelay;
|
||||
|
||||
Logger.RECONNECT(this, reason);
|
||||
|
||||
executor.schedule(() -> {
|
||||
try {
|
||||
connect();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}, reconnectDelay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Config {
|
||||
public List<String> prefixes;
|
||||
|
||||
public static class Core {
|
||||
public Area area = new Area();
|
||||
public String coreName;
|
||||
}
|
||||
|
||||
public static class Area {
|
||||
public Position start = new Position();
|
||||
public Position end = new Position();
|
||||
}
|
||||
|
||||
public static class Position {
|
||||
public int x = 0;
|
||||
public int y = 0;
|
||||
public int z = 0;
|
||||
}
|
||||
|
||||
public static class CommandColors {
|
||||
public String primary = "blue";
|
||||
public String secondary = "aqua";
|
||||
public String tertiary = "dark_aqua";
|
||||
}
|
||||
|
||||
public static class HelpCommandColors {
|
||||
public String Public = "blue";
|
||||
public String trusted = "dark_aqua";
|
||||
public String admin = "aqua";
|
||||
public String owner = "light_purple";
|
||||
public String console = "dark_purple";
|
||||
}
|
||||
|
||||
public static class Console {
|
||||
public String prefix = "c.";
|
||||
}
|
||||
|
||||
public static class Colors {
|
||||
public String integer = "gold";
|
||||
public CommandColors commands = new CommandColors();
|
||||
public HelpCommandColors help = new HelpCommandColors();
|
||||
}
|
||||
|
||||
public Colors colors = new Colors();
|
||||
|
||||
public Core core = new Core();
|
||||
|
||||
public Console console = new Console();
|
||||
|
||||
public Options[] bots = new Options[]{};
|
||||
|
||||
public static class Options {
|
||||
public String host;
|
||||
public int port;
|
||||
public boolean useProxy;
|
||||
public String serverName;
|
||||
public String username;
|
||||
public int reconnectDelay;
|
||||
public int selfcareInterval;
|
||||
};
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.modules.ConsoleModule;
|
||||
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.LoaderOptions;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
public class Main {
|
||||
public final Object obj = new Object();
|
||||
|
||||
public static final ExecutorService executorService = Executors.newFixedThreadPool(
|
||||
Runtime.getRuntime().availableProcessors()
|
||||
);
|
||||
|
||||
public static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(
|
||||
Runtime.getRuntime().availableProcessors()
|
||||
);
|
||||
|
||||
public static Config config;
|
||||
|
||||
public static final List<Bot> Bots = new ArrayList<>();
|
||||
|
||||
public Config loadConfig() throws IOException {
|
||||
final Constructor yamlConfig = new Constructor(Config.class, new LoaderOptions());
|
||||
final Yaml yaml = new Yaml(yamlConfig);
|
||||
final Path configPath = Path.of("config.yaml");
|
||||
if (!Files.exists(configPath)) {
|
||||
|
||||
//LoggerManager.INFO(null, "config not found making config now");
|
||||
|
||||
InputStream defaultConfig = Main.class.getClassLoader().getResourceAsStream("default_config.yaml");
|
||||
Files.copy(defaultConfig, Paths.get("config.yaml"));
|
||||
}
|
||||
|
||||
InputStream configFile = Files.newInputStream(configPath);
|
||||
|
||||
config = yaml.load(configFile);
|
||||
return config;
|
||||
}
|
||||
|
||||
public static ConsoleModule console;
|
||||
|
||||
public void main(String[] args) {
|
||||
try {
|
||||
config = loadConfig();
|
||||
Config.Options[] bots = config.bots;
|
||||
|
||||
console = new ConsoleModule(config);
|
||||
for (Config.Options options : bots) {
|
||||
final Bot bot = new Bot(options, Bots, config);
|
||||
Bots.add(bot);
|
||||
}
|
||||
|
||||
synchronized(obj) {
|
||||
obj.wait();
|
||||
};
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.chatparsers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.data.chat.*;
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PlayerProfileData;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
|
||||
public class KaboomChatParser implements ParseChatData {
|
||||
private Bot bot;
|
||||
private static Component SEPERATOR_COLON = Component.text(":");
|
||||
private static Component SEPERATOR_COLON_RACCOON = Component.text("\u00a7f:"); // https://github.com/raccoonserver/extras/commit/315f704075db2f00e3e1bfbf55f858469c22880f
|
||||
private static Component SEPERATOR_SPACE = Component.space();
|
||||
|
||||
public KaboomChatParser (Bot bot) {
|
||||
this.bot = bot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerMessageData parse (Component message) {
|
||||
if (message instanceof TextComponent) return parse((TextComponent) message);
|
||||
return null;
|
||||
}
|
||||
|
||||
public PlayerMessageData parse (TextComponent message) {
|
||||
List<Component> children = message.children();
|
||||
|
||||
if (!message.content().equals("") || !message.style().isEmpty() || children == null || children.size() < 3) return null;
|
||||
|
||||
final Component prefix = children.get(0);
|
||||
Component displayName = Component.empty();
|
||||
Component contents = Component.empty();
|
||||
|
||||
if (isSeperatorAt(children, 1)) { // Missing/blank display name
|
||||
if (children.size() > 3) contents = children.get(3);
|
||||
} else if (isSeperatorAt(children, 2)) {
|
||||
displayName = children.get(1);
|
||||
if (children.size() > 4) contents = children.get(4);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
PlayerProfileData sender = bot.players.getDisplayName(Component.empty().append(prefix).append(displayName));//getSender());
|
||||
return new PlayerMessageData(sender, contents, "minecraft:chat", displayName);
|
||||
}
|
||||
|
||||
private boolean isSeperatorAt (List<Component> children, int start) {
|
||||
return (children.get(start).equals(SEPERATOR_COLON) || children.get(start).equals(SEPERATOR_COLON_RACCOON)) && children.get(start + 1).equals(SEPERATOR_SPACE);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.command;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
|
||||
public class CommandContext {
|
||||
public Bot bot;
|
||||
|
||||
public String[] args;
|
||||
|
||||
public CommandSource source;
|
||||
|
||||
public CommandInfo commandData;
|
||||
|
||||
public CommandContext (Bot bot, String[] args, CommandSource source, CommandInfo commandData) {
|
||||
this.bot = bot;
|
||||
this.args = args;
|
||||
this.source = source;
|
||||
this.commandData = commandData;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.command;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class CommandError extends Exception {
|
||||
public String name = "CommandError";
|
||||
public Component message;
|
||||
|
||||
public CommandError (Component message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Component message () {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.command;
|
||||
|
||||
public abstract class CommandInfo {
|
||||
public String name;
|
||||
public CommandTrustLevels trustlevel;
|
||||
public String[] aliases;
|
||||
public String description;
|
||||
|
||||
public CommandInfo (String name, CommandTrustLevels trustlevel, String[] aliases, String description) {
|
||||
this.name = name;
|
||||
this.trustlevel = trustlevel;
|
||||
this.aliases = aliases;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public abstract void execute (CommandContext context);
|
||||
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.command;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
|
||||
public class CommandSource {
|
||||
private Bot bot;
|
||||
|
||||
public PlayerProfileData sender;
|
||||
|
||||
public boolean inGame;
|
||||
|
||||
public CommandSource (Bot bot, PlayerProfileData sender) {
|
||||
this.bot = bot;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
|
||||
public void sendFeedback (Component message) {
|
||||
String convertToJson = ComponentUtil.componentToJSON(message);
|
||||
Vector3d playerPos = sender.position.position();
|
||||
|
||||
String formatCommand = String.format(
|
||||
"minecraft:summon text_display %s %s %s {tag:[%s], text:%s}",
|
||||
playerPos.getX(),
|
||||
playerPos.getY(),
|
||||
playerPos.getZ(),
|
||||
"NitoriBot",
|
||||
convertToJson
|
||||
);
|
||||
|
||||
String selector = String.format(
|
||||
"@p[nbt={UUID:%s}]",
|
||||
sender.entityUUID
|
||||
);
|
||||
|
||||
bot.chat.tellraw(selector, message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.command;
|
||||
|
||||
public enum CommandTrustLevels {
|
||||
PUBLIC,
|
||||
TRUSTED,
|
||||
ADMIN,
|
||||
OWNER,
|
||||
CONSOLE,
|
||||
DISABLED
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandTrustLevels;
|
||||
|
||||
public class EchoCommand extends CommandInfo {
|
||||
public EchoCommand () {
|
||||
super(
|
||||
"echo",
|
||||
CommandTrustLevels.PUBLIC,
|
||||
new String[] { "say" },
|
||||
"make the bot say a message"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandContext context) {
|
||||
Bot bot = context.bot;
|
||||
String args = String.join(" ", context.args);
|
||||
if (args.startsWith("/")) {
|
||||
bot.chat.command(args.substring("/".length()));
|
||||
} else {
|
||||
bot.chat.message(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.Config;
|
||||
import land.chipmunk.parker2991.nitoribot.command.*;
|
||||
import land.chipmunk.parker2991.nitoribot.util.TranslationsUtil;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class HelpCommand extends CommandInfo {
|
||||
public HelpCommand () {
|
||||
super(
|
||||
"help",
|
||||
CommandTrustLevels.PUBLIC,
|
||||
new String[] { "heko", "hell", "?", "cmds"},
|
||||
"see the list of commands"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public Component getCommands (Bot bot) {
|
||||
List<Component> commandlist = new ArrayList<>();
|
||||
List<Component> Public = new ArrayList<>();
|
||||
List<Component> Trusted = new ArrayList<>();
|
||||
List<Component> Admin = new ArrayList<>();
|
||||
List<Component> Owner = new ArrayList<>();
|
||||
|
||||
for (CommandInfo commands : bot.commandManager.commands) {
|
||||
switch (commands.trustlevel) {
|
||||
case CommandTrustLevels.PUBLIC:
|
||||
Public.add(
|
||||
Component.text(commands.name + " ").color(NamedTextColor.BLUE)
|
||||
);
|
||||
break;
|
||||
case CommandTrustLevels.TRUSTED:
|
||||
Trusted.add(
|
||||
Component.text(commands.name + " ").color(NamedTextColor.DARK_AQUA)
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Component component = Component.empty()
|
||||
.append(Public)
|
||||
.append(Component.text("\n"))
|
||||
.append(Trusted);
|
||||
// .append(Component.text("\n"));
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
private Component getCommand (Bot bot, String[] command) {
|
||||
List<Component> list = new ArrayList<>();
|
||||
|
||||
Component component = null;
|
||||
|
||||
for (CommandInfo commands : bot.commandManager.commands) {
|
||||
if (commands.name.equals(command[0])) component = Component.empty()
|
||||
.append(
|
||||
TranslationsUtil.customTranslations(
|
||||
"command.help.info.layout",
|
||||
List.of(
|
||||
TranslationsUtil.customTranslations("command.help.info.command", null).color(NamedTextColor.BLUE),
|
||||
Component.text(commands.name).color(NamedTextColor.AQUA)
|
||||
)
|
||||
)
|
||||
)
|
||||
.append(
|
||||
TranslationsUtil.customTranslations(
|
||||
"command.help.info.layout",
|
||||
List.of(
|
||||
TranslationsUtil.customTranslations("command.help.info.aliases", null).color(NamedTextColor.BLUE),
|
||||
Component.text(Arrays.toString(commands.aliases)).color(NamedTextColor.AQUA)
|
||||
)
|
||||
)
|
||||
)
|
||||
.append(
|
||||
TranslationsUtil.customTranslations(
|
||||
"command.help.info.layout",
|
||||
List.of(
|
||||
TranslationsUtil.customTranslations("command.help.info.description", null).color(NamedTextColor.BLUE),
|
||||
Component.text(commands.description).color(NamedTextColor.AQUA)
|
||||
)
|
||||
)
|
||||
)
|
||||
.append(
|
||||
TranslationsUtil.customTranslations(
|
||||
"command.help.info.layout",
|
||||
List.of(
|
||||
TranslationsUtil.customTranslations("command.help.info.trust_level", null).color(NamedTextColor.BLUE),
|
||||
Component.text(commands.trustlevel + "").color(NamedTextColor.AQUA)
|
||||
)
|
||||
)
|
||||
)
|
||||
.append(
|
||||
TranslationsUtil.customTranslations(
|
||||
"command.help.info.layout",
|
||||
List.of(
|
||||
TranslationsUtil.customTranslations("command.help.info.usages", null).color(NamedTextColor.BLUE),
|
||||
Component.text("DUMMY String").color(NamedTextColor.AQUA)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute (CommandContext context) {
|
||||
Bot bot = context.bot;
|
||||
String[] args = context.args;
|
||||
CommandSource source = context.source;
|
||||
Config config = bot.config;
|
||||
Config.Colors colors = config.colors;
|
||||
List<Component> list = new ArrayList<>();
|
||||
|
||||
if (args.length != 0) {
|
||||
source.sendFeedback(getCommand(bot, args));
|
||||
//return null;
|
||||
}
|
||||
|
||||
list = List.of(
|
||||
Component.text("Commands").color(NamedTextColor.NAMES.value(colors.commands.primary)),
|
||||
Component.text(bot.commandManager.commands.size()).color(NamedTextColor.NAMES.value(colors.integer)),
|
||||
TranslationsUtil.customTranslations("command.help.trust_level.public", null).color(NamedTextColor.NAMES.value(colors.help.Public)),
|
||||
TranslationsUtil.customTranslations("command.help.trust_level.trusted", null).color(NamedTextColor.NAMES.value(colors.help.trusted)),
|
||||
TranslationsUtil.customTranslations("command.help.trust_level.admin", null).color(NamedTextColor.NAMES.value(colors.help.admin)),
|
||||
TranslationsUtil.customTranslations("command.help.trust_level.owner", null).color(NamedTextColor.NAMES.value(colors.help.owner))
|
||||
);
|
||||
|
||||
Component helpLayout = TranslationsUtil.customTranslations(
|
||||
"command.help.layout",
|
||||
list
|
||||
);
|
||||
|
||||
Component component = Component.empty()
|
||||
.append(helpLayout)
|
||||
.append(Component.join(JoinConfiguration.separator(Component.space()), getCommands(bot)));
|
||||
|
||||
source.sendFeedback(component);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandTrustLevels;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
public class MCServerCommand extends CommandInfo {
|
||||
public MCServerCommand () {
|
||||
super(
|
||||
"mcserver",
|
||||
CommandTrustLevels.PUBLIC,
|
||||
new String[] { "minecraftserver" },
|
||||
"ping a minecraft server"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute (CommandContext context) {
|
||||
var bot = context.bot;
|
||||
var source = context.source;
|
||||
String args = String.join(" ", context.args);
|
||||
|
||||
var ip = args.split(":");
|
||||
|
||||
var info = bot.mcServer.pingServer(ip);
|
||||
|
||||
System.out.println(info);
|
||||
|
||||
/*source.sendFeedback(
|
||||
Component.translatable(
|
||||
"%s: (%s / %s)",
|
||||
Component.text("Players").color(NamedTextColor.BLUE),
|
||||
Component.text(info.playersOnline()).color(NamedTextColor.GOLD),
|
||||
Component.text(info.maxPlayers()).color(NamedTextColor.GOLD)
|
||||
)
|
||||
);*/
|
||||
|
||||
/*source.sendFeedback(
|
||||
Component.translatable(
|
||||
"Server Version %s %s %s",
|
||||
Component.text(":").color(NamedTextColor.GRAY),
|
||||
Component.text(info.versionName()),
|
||||
Component.text(info.protocolVersion())
|
||||
)
|
||||
);*/
|
||||
|
||||
//source.sendFeedback(info.description());
|
||||
}
|
||||
}
|
||||
/*
|
||||
[logs] [System Chat] Ip: kaboom.pw:25565
|
||||
Players: 8/0
|
||||
Server Version: Paper 26.2
|
||||
Welcome to Kaboom!
|
||||
> Free OP - Anarchy - Creative
|
||||
*/
|
||||
@@ -1,30 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandTrustLevels;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
public class RCCommand extends CommandInfo {
|
||||
public RCCommand () {
|
||||
super(
|
||||
"rc",
|
||||
CommandTrustLevels.PUBLIC,
|
||||
new String[] { "refill", "refillcore" },
|
||||
"refill the bot's core"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute (CommandContext context) {
|
||||
Bot bot = context.bot;
|
||||
CommandSource source = context.source;
|
||||
|
||||
bot.core.move();
|
||||
|
||||
source.sendFeedback(Component.text("Refilling core").color(NamedTextColor.BLUE));
|
||||
}
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.commands.trusted;
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.command.*;
|
||||
|
||||
public class ReconnectCommand extends CommandInfo {
|
||||
public ReconnectCommand () {
|
||||
super(
|
||||
"reconnect",
|
||||
CommandTrustLevels.TRUSTED,
|
||||
new String[] { },
|
||||
"reconnect the bot"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute (CommandContext context) {
|
||||
Bot bot = context.bot;
|
||||
|
||||
bot.session.disconnect("Reconnect Command");
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.data;
|
||||
import org.cloudburstmc.math.vector.Vector3i;
|
||||
|
||||
public class CommandCoreAreaData {
|
||||
public Vector3i start;
|
||||
public Vector3i end;
|
||||
|
||||
public CommandCoreAreaData (Vector3i start, Vector3i end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.data;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public record PingServerData (
|
||||
//String ip,
|
||||
//int port,
|
||||
String versionName,
|
||||
long protocolVersion,
|
||||
int playersOnline,
|
||||
int maxPlayers,
|
||||
Component description
|
||||
//long latency
|
||||
) {
|
||||
public void latency (long pingTime) { System.out.println(versionName); }
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.data;
|
||||
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
|
||||
public record PlayerPositionData (float pitch, float yaw, Vector3d position) {}
|
||||
@@ -1,44 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.data;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.util.UUIDUtil;
|
||||
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
|
||||
import org.geysermc.mcprotocollib.auth.GameProfile;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerProfileData {
|
||||
public UUID uuid;
|
||||
public String entityUUID;
|
||||
public final GameProfile profile;
|
||||
public boolean listed;
|
||||
public int latency;
|
||||
public GameMode gameMode;
|
||||
public Component displayName;
|
||||
public boolean showHat;
|
||||
public int listOrder;
|
||||
public PlayerPositionData position;
|
||||
public int entityId;
|
||||
public String dimension;
|
||||
|
||||
public PlayerProfileData (
|
||||
UUID uuid,
|
||||
GameProfile profile,
|
||||
boolean listed,
|
||||
int latency,
|
||||
GameMode gameMode,
|
||||
Component displayName
|
||||
) {
|
||||
this.uuid = uuid;
|
||||
this.entityUUID = UUIDUtil.snbt(uuid);
|
||||
this.profile = profile;
|
||||
this.listed = listed;
|
||||
this.latency = latency;
|
||||
this.gameMode = gameMode;
|
||||
this.displayName = displayName;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.data;
|
||||
|
||||
public record PositionData (int x, int y, int z) {}
|
||||
@@ -1,13 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.data.chat;
|
||||
|
||||
//import land.chipmunk.parker2991.nitoribot.data.PlayerProfileData;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
//import org.geysermc.mcprotocollib.protocol.data.game.PlayerListEntry;
|
||||
|
||||
public interface ParseChatData {
|
||||
PlayerMessageData parse (Component message);
|
||||
|
||||
// PlayerProfileData parse (PlayerMessageData data);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.data.chat;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.data.PlayerProfileData;
|
||||
|
||||
public class PlayerMessageData {
|
||||
public PlayerProfileData sender;
|
||||
public Component contents;
|
||||
public String chatType;
|
||||
public Component senderName;
|
||||
|
||||
public PlayerMessageData(PlayerProfileData sender, Component contents, String chatType, Component senderName) {
|
||||
this.sender = sender;
|
||||
this.contents = contents;
|
||||
this.chatType = chatType;
|
||||
this.senderName = senderName;
|
||||
// return this;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.listeners;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.MCProtocolLibMessenger;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.data.chat.PlayerMessageData;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Listener {
|
||||
public void packetSent (Session session, Packet packet) {}
|
||||
|
||||
public void packetReceived (Session session, Packet packet) {}
|
||||
|
||||
public void extrasMessagingReceived (MCProtocolLibMessenger messenger) {}
|
||||
|
||||
public void chatAttestationMessageReceived () {}
|
||||
|
||||
public void playerChatReceived (Component message) {}
|
||||
|
||||
public void disguisedChatReceived (Component message) {}
|
||||
|
||||
public void systemChatReceived (Component message) {}
|
||||
|
||||
public void parsedMessage (Component message, PlayerMessageData data) {}
|
||||
|
||||
public void botMoved () {}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.listeners;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class ListenerManager {
|
||||
public final List<Listener> listeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
public void addListener (Listener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener (Listener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
public void clearListener () {
|
||||
listeners.clear();
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.logger;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.Main;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class Logger {
|
||||
private final DateTimeFormatter formatTime = DateTimeFormatter.ofPattern("hh:mm:ss");
|
||||
|
||||
private final DateTimeFormatter formatDate = DateTimeFormatter.ofPattern("MM/dd/yyyy");
|
||||
|
||||
public Component getLoggerType (LoggerType type) {
|
||||
Component logType = null;
|
||||
switch (type) {
|
||||
case LoggerType.LOG -> logType = Component.text("LOG").color(NamedTextColor.GOLD);
|
||||
case LoggerType.COMMAND -> logType = Component.text("COMMAND").color(NamedTextColor.GREEN);
|
||||
case LoggerType.ERROR -> logType = Component.text("ERROR").color(NamedTextColor.DARK_RED);
|
||||
case LoggerType.WARN -> logType = Component.text("WARN").color(NamedTextColor.YELLOW);
|
||||
case LoggerType.INFO -> logType = Component.text("INFO").color(NamedTextColor.DARK_GREEN);
|
||||
case LoggerType.RECONNECT -> logType = Component.text("RECONNECT").color(NamedTextColor.AQUA);
|
||||
case LoggerType.DEBUG -> logType = Component.text("DEBUG").color(NamedTextColor.GOLD);
|
||||
}
|
||||
|
||||
|
||||
return logType;
|
||||
}
|
||||
|
||||
private void prefix (LoggerType loggerType, Bot bot, String message) {
|
||||
Component component = null;
|
||||
Component host = null;
|
||||
|
||||
ZoneId timezone = ZoneId.of("America/Chicago");
|
||||
ZonedDateTime zoneDate = ZonedDateTime.now(timezone);
|
||||
LocalDate date = zoneDate.toLocalDate();
|
||||
LocalTime time = zoneDate.toLocalTime();
|
||||
|
||||
Component type = getLoggerType(loggerType);
|
||||
|
||||
if (bot == null) host = Component.text("NitoriBot Jar").color(NamedTextColor.BLUE);
|
||||
host = Component.text(bot.options.host + ":" + bot.options.port).color(NamedTextColor.BLUE);
|
||||
|
||||
component = Component.translatable(
|
||||
"[%s %s %s] [%s] [%s] %s",
|
||||
Component.translatable(formatTime.format(time)).color(NamedTextColor.BLUE),
|
||||
Component.translatable(formatDate.format(date)).color(NamedTextColor.BLUE),
|
||||
type,
|
||||
Component.translatable(Thread.currentThread().getName()).color(NamedTextColor.BLUE),
|
||||
host,
|
||||
Component.translatable(message).color(NamedTextColor.WHITE)
|
||||
).color(NamedTextColor.DARK_BLUE);
|
||||
|
||||
String log = ComponentUtil.componentToAnsi(component);
|
||||
|
||||
if (bot == null) System.out.println(log);
|
||||
else Main.console.reader.printAbove(log);
|
||||
}
|
||||
|
||||
public static void LOG (Bot bot, String message) {
|
||||
new Logger().prefix(
|
||||
LoggerType.LOG,
|
||||
bot,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public static void DEBUG (Bot bot, String message) {
|
||||
new Logger().prefix(
|
||||
LoggerType.DEBUG,
|
||||
bot,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public static void ERROR (Bot bot, String message) {
|
||||
new Logger().prefix(
|
||||
LoggerType.ERROR,
|
||||
bot,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public static void WARN (Bot bot, String message) {
|
||||
new Logger().prefix(
|
||||
LoggerType.WARN,
|
||||
bot,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public static void COMMAND (Bot bot, String message) {
|
||||
new Logger().prefix(
|
||||
LoggerType.COMMAND,
|
||||
bot,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public static void RECONNECT (Bot bot, String message) {
|
||||
new Logger().prefix(
|
||||
LoggerType.RECONNECT,
|
||||
bot,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public static void INFO (Bot bot, String message) {
|
||||
new Logger().prefix(
|
||||
LoggerType.INFO,
|
||||
bot,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public Logger () {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.logger;
|
||||
|
||||
public enum LoggerType {
|
||||
LOG,
|
||||
DEBUG,
|
||||
INFO,
|
||||
COMMAND,
|
||||
WARN,
|
||||
ERROR,
|
||||
RECONNECT,
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.Config;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.data.chat.PlayerMessageData;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.*;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ChatCommandHandlerModule extends Listener {
|
||||
private Bot bot;
|
||||
|
||||
@Override
|
||||
public void parsedMessage (Component message, PlayerMessageData data) {
|
||||
if (data.chatType != "minecraft:chat") return;
|
||||
|
||||
List<String> prefixes = bot.config.prefixes;
|
||||
|
||||
for (String prefix : prefixes) {
|
||||
String plainMessage = ComponentUtil.componentToString(data.contents);
|
||||
|
||||
if (!plainMessage.startsWith(prefix)) return;
|
||||
|
||||
String command = plainMessage.substring(prefix.length());
|
||||
|
||||
CommandSource source = new CommandSource(bot, data.sender);
|
||||
|
||||
bot.commandManager.executeString(source, command);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public ChatCommandHandlerModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.*;
|
||||
import land.chipmunk.parker2991.nitoribot.chatparsers.*;
|
||||
import land.chipmunk.parker2991.nitoribot.data.chat.*;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PlayerProfileData;
|
||||
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundDisguisedChatPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundPlayerChatPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundChatPacket;
|
||||
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.time.Instant;
|
||||
import java.util.BitSet;
|
||||
|
||||
public class ChatModule extends Listener {
|
||||
private Bot bot;
|
||||
|
||||
public final List<ParseChatData> chatParsers = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundSystemChatPacket) systemChat((ClientboundSystemChatPacket) packet);
|
||||
else if (packet instanceof ClientboundPlayerChatPacket) playerChat((ClientboundPlayerChatPacket) packet);
|
||||
else if (packet instanceof ClientboundDisguisedChatPacket) diguisedChat((ClientboundDisguisedChatPacket) packet);
|
||||
}
|
||||
|
||||
public String parseChatTypes (int chatType) {
|
||||
String getTranslation = bot.registry.chatTypes.get(chatType);
|
||||
|
||||
return getTranslation;
|
||||
}
|
||||
|
||||
public void systemChat (ClientboundSystemChatPacket packet) {
|
||||
final Component message = packet.getContent();
|
||||
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.systemChatReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void diguisedChat (ClientboundDisguisedChatPacket packet) {
|
||||
Component getMessage = packet.getMessage();
|
||||
Component targetUsername = packet.getName();
|
||||
Component message;
|
||||
|
||||
final String parseChatTypes = parseChatTypes(packet.getChatType().id());
|
||||
|
||||
if (packet.getChatType().id() == 4) {
|
||||
message = getMessage;
|
||||
} else {
|
||||
message = Component.translatable(
|
||||
parseChatTypes,
|
||||
targetUsername,
|
||||
getMessage
|
||||
);
|
||||
}
|
||||
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.disguisedChatReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void playerChat (ClientboundPlayerChatPacket packet) {
|
||||
final Component unsignedContent = packet.getUnsignedContent();
|
||||
final Component content = Component.text(packet.getContent());
|
||||
|
||||
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.playerChatReceived(unsignedContent);
|
||||
}
|
||||
|
||||
parseMessage(
|
||||
unsignedContent,
|
||||
new PlayerMessageData(
|
||||
bot.players.getPlayerUUID(packet.getSender()),
|
||||
content,
|
||||
"minecraft:chat",
|
||||
bot.players.getPlayerUUID(packet.getSender()).displayName
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void parseMessage (Component message, PlayerMessageData data) {
|
||||
try {
|
||||
PlayerMessageData parsed = null;
|
||||
|
||||
for (ParseChatData parser : chatParsers) {
|
||||
parsed = parser.parse(message);
|
||||
if (parsed != null) break;
|
||||
};
|
||||
|
||||
if (parsed == null) return;
|
||||
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.parsedMessage(message, data);
|
||||
}
|
||||
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
|
||||
public void message (String message) {
|
||||
bot.session.send(
|
||||
new ServerboundChatPacket(
|
||||
message,
|
||||
Instant.now().toEpochMilli(),
|
||||
0,
|
||||
null,
|
||||
0,
|
||||
new BitSet(),
|
||||
0
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void command (String command) {
|
||||
bot.session.send(
|
||||
new ServerboundChatCommandPacket(
|
||||
command
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void send (String message) {
|
||||
if (message.startsWith("/")) bot.chat.command(message.substring(1));
|
||||
|
||||
else bot.chat.message(message);
|
||||
}
|
||||
|
||||
public void tellraw (String selector, Component message) {
|
||||
bot.core.run("minecraft:tellraw " + selector + " " + GsonComponentSerializer.gson().serialize(message));
|
||||
}
|
||||
|
||||
public ChatModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
chatParsers.add(new KaboomChatParser(bot));
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
};
|
||||
}
|
||||
@@ -1,275 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.logger.Logger;
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
import org.cloudburstmc.math.vector.Vector3i;
|
||||
|
||||
import org.cloudburstmc.nbt.NbtMap;
|
||||
import org.cloudburstmc.nbt.NbtType;
|
||||
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityType;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PlayerAction;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponent;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.TypedEntityData;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.TypedEntityData.TypedEntityDataBuilder;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.level.block.CommandBlockMode;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundSetCommandBlockPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundUseItemOnPacket;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.data.CommandCoreAreaData;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PositionData;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.Listener;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
|
||||
public class CommandCoreModule extends Listener {
|
||||
private Bot bot;
|
||||
|
||||
public CommandCoreAreaData area;
|
||||
|
||||
@Override
|
||||
public void botMoved () {
|
||||
move();
|
||||
}
|
||||
|
||||
public Vector3i position;
|
||||
|
||||
public Vector3i itemPosition;
|
||||
|
||||
public void move () {
|
||||
Vector3d botPos = bot.position.positionAsVector;
|
||||
position = Vector3i.from(
|
||||
Math.floor(botPos.getX() / 16) * 16,
|
||||
0,
|
||||
Math.floor(botPos.getZ() / 16) * 16
|
||||
);
|
||||
|
||||
itemPosition = Vector3i.from(
|
||||
botPos.getX(),
|
||||
botPos.getY() - 1,
|
||||
botPos.getZ()
|
||||
);
|
||||
|
||||
itemRefill();
|
||||
};
|
||||
|
||||
public void chatRefill () {
|
||||
Vector3i pos = position;
|
||||
CommandCoreAreaData coreArea = area;
|
||||
|
||||
int startPosX = pos.getX() - coreArea.start.getX();
|
||||
int startPosY = pos.getY() - coreArea.start.getY();
|
||||
int startPosZ = pos.getZ() - coreArea.start.getZ();
|
||||
int endPosX = pos.getX() - coreArea.end.getX();
|
||||
int endPosY = pos.getY() - coreArea.end.getY();
|
||||
int endPosZ = pos.getZ() - coreArea.end.getZ();
|
||||
|
||||
String command = String.format(
|
||||
"minecraft:fill %s %s %s %s %s %s command_block{CustomName:%s}",
|
||||
startPosX,
|
||||
startPosY,
|
||||
startPosZ,
|
||||
endPosX,
|
||||
endPosY,
|
||||
endPosZ,
|
||||
bot.config.core.coreName
|
||||
);
|
||||
|
||||
bot.chat.command(command);
|
||||
}
|
||||
|
||||
public void itemRefill () {
|
||||
final NbtMapBuilder blockEntityTagBuilder = NbtMap.builder();
|
||||
|
||||
Vector3i pos = position;
|
||||
CommandCoreAreaData coreArea = area;
|
||||
|
||||
int startPosX = pos.getX() - coreArea.start.getX();
|
||||
int startPosY = pos.getY() - coreArea.start.getY();
|
||||
int startPosZ = pos.getZ() - coreArea.start.getZ();
|
||||
int endPosX = pos.getX() - coreArea.end.getX();
|
||||
int endPosY = pos.getY() - coreArea.end.getY();
|
||||
int endPosZ = pos.getZ() - coreArea.end.getZ();
|
||||
|
||||
String command = String.format(
|
||||
"minecraft:fill %s %s %s %s %s %s command_block{CustomName:%s} replace",
|
||||
startPosX,
|
||||
startPosY,
|
||||
startPosZ,
|
||||
endPosX,
|
||||
endPosY,
|
||||
endPosZ,
|
||||
bot.config.core.coreName
|
||||
);
|
||||
|
||||
blockEntityTagBuilder.putString("Command", command)
|
||||
.putByte("auto", (byte) 1)
|
||||
.putByte("TrackOutput", (byte) 1);
|
||||
|
||||
final NbtMap blockEntityTag = blockEntityTagBuilder.build();
|
||||
|
||||
final Map<DataComponentType<?>, DataComponent<?, ?>> map = new HashMap<>();
|
||||
|
||||
map.put(
|
||||
DataComponentTypes.BLOCK_ENTITY_DATA,
|
||||
DataComponentTypes.BLOCK_ENTITY_DATA
|
||||
.getDataComponentFactory()
|
||||
.create(
|
||||
DataComponentTypes.BLOCK_ENTITY_DATA,
|
||||
TypedEntityData.<BlockEntityType>builder()
|
||||
.type(BlockEntityType.COMMAND_BLOCK)
|
||||
.tag(blockEntityTag)
|
||||
.build()
|
||||
)
|
||||
);
|
||||
|
||||
map.put(
|
||||
DataComponentTypes.ITEM_NAME,
|
||||
DataComponentTypes.ITEM_NAME
|
||||
.getDataComponentFactory()
|
||||
.create(
|
||||
DataComponentTypes.ITEM_NAME,
|
||||
ComponentUtil.componentFromJSON(bot.config.core.coreName)
|
||||
)
|
||||
);
|
||||
|
||||
map.put(
|
||||
DataComponentTypes.CUSTOM_NAME,
|
||||
DataComponentTypes.CUSTOM_NAME
|
||||
.getDataComponentFactory()
|
||||
.create(
|
||||
DataComponentTypes.CUSTOM_NAME,
|
||||
ComponentUtil.componentFromJSON(bot.config.core.coreName)
|
||||
)
|
||||
);
|
||||
|
||||
final DataComponents dataComponents = new DataComponents(map);
|
||||
|
||||
bot.session.send(
|
||||
new ServerboundSetCreativeModeSlotPacket(
|
||||
(short) 36,
|
||||
new ItemStack(
|
||||
482,
|
||||
64,
|
||||
dataComponents
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
bot.session.send(
|
||||
new ServerboundPlayerActionPacket(
|
||||
PlayerAction.START_DIGGING,
|
||||
itemPosition,
|
||||
Direction.NORTH,
|
||||
0
|
||||
)
|
||||
);
|
||||
|
||||
bot.session.send(
|
||||
new ServerboundUseItemOnPacket(
|
||||
itemPosition,
|
||||
Direction.NORTH,
|
||||
Hand.MAIN_HAND,
|
||||
0.5f,
|
||||
0.5f,
|
||||
0.5f,
|
||||
false,
|
||||
false,
|
||||
1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public Vector3i currentBlockRelative = Vector3i.from(0, 0, 0);
|
||||
|
||||
public PositionData currentBlock () {
|
||||
Vector3i relativePosition = currentBlockRelative;
|
||||
Vector3i corePosition = position;
|
||||
|
||||
return new PositionData(
|
||||
relativePosition.getX() + corePosition.getX(),
|
||||
relativePosition.getY() + corePosition.getY(),
|
||||
relativePosition.getZ() + corePosition.getZ()
|
||||
);
|
||||
}
|
||||
|
||||
public void incrementCurrentBlock () {
|
||||
Vector3i relativePosition = currentBlockRelative;
|
||||
CommandCoreAreaData coreArea = area;
|
||||
|
||||
int posX = relativePosition.getX();
|
||||
int posY = relativePosition.getY();
|
||||
int posZ = relativePosition.getZ();
|
||||
|
||||
posX++;
|
||||
|
||||
if (posX > coreArea.end.getX()) {
|
||||
posX = coreArea.start.getX();
|
||||
posZ++;
|
||||
}
|
||||
|
||||
if (posZ > coreArea.end.getZ()) {
|
||||
posZ = coreArea.start.getZ();
|
||||
posY++;
|
||||
}
|
||||
|
||||
if (posY > coreArea.end.getY()) {
|
||||
posX = coreArea.start.getX();
|
||||
posY = coreArea.start.getY();
|
||||
posZ = coreArea.start.getZ();
|
||||
}
|
||||
}
|
||||
|
||||
public void commandBlock (String command, boolean doesTrackOutput, boolean conditional, boolean automatic) {
|
||||
if (command.length() > 32767) return;
|
||||
bot.session.send(
|
||||
new ServerboundSetCommandBlockPacket(
|
||||
position,
|
||||
command,
|
||||
CommandBlockMode.AUTO,
|
||||
doesTrackOutput,
|
||||
conditional,
|
||||
automatic
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void run (String command) {
|
||||
commandBlock(command, true, false, true);
|
||||
|
||||
incrementCurrentBlock();
|
||||
}
|
||||
|
||||
public CommandCoreModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
this.area = new CommandCoreAreaData(
|
||||
Vector3i.from(
|
||||
bot.config.core.area.start.x,
|
||||
bot.config.core.area.start.y,
|
||||
bot.config.core.area.start.z
|
||||
),
|
||||
Vector3i.from(
|
||||
bot.config.core.area.end.x,
|
||||
bot.config.core.area.end.y,
|
||||
bot.config.core.area.end.z
|
||||
)
|
||||
);
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandError;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.commands.Public.*;
|
||||
import land.chipmunk.parker2991.nitoribot.commands.trusted.ReconnectCommand;
|
||||
import land.chipmunk.parker2991.nitoribot.logger.Logger;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ErrorToString;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
public class CommandManagerModule {
|
||||
private Bot bot;
|
||||
|
||||
public List<CommandInfo> commands = new ArrayList<>();
|
||||
|
||||
public void registerCommand (CommandInfo command) {
|
||||
commands.add(command);
|
||||
}
|
||||
|
||||
public CommandInfo getCommand (String getCommand) {
|
||||
for (CommandInfo command : commands) {
|
||||
for (String aliases : command.aliases) {
|
||||
if (getCommand.equals(aliases)) return command;
|
||||
}
|
||||
if (getCommand.equals(command.name)) return command;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void execute (CommandSource source, String commandName, String[] args) {
|
||||
try {
|
||||
CommandInfo command = getCommand(commandName.toLowerCase());
|
||||
|
||||
if (command == null) throw new CommandError(
|
||||
Component.translatable(
|
||||
"%s%s%s %s",
|
||||
Component.translatable("command.unknown.command"),
|
||||
Component.text("\n"),
|
||||
Component.text(commandName).color(NamedTextColor.GRAY),
|
||||
Component.translatable("command.context.here")
|
||||
).color(NamedTextColor.RED)
|
||||
);
|
||||
|
||||
CommandContext context = new CommandContext(bot, args, source, command);
|
||||
|
||||
command.execute(context);
|
||||
|
||||
} catch (CommandError error) {
|
||||
source.sendFeedback(error.message());
|
||||
} catch (Exception error) {
|
||||
source.sendFeedback(
|
||||
Component.translatable("command.failed").color(NamedTextColor.DARK_RED)
|
||||
);
|
||||
String Error = ErrorToString.errorToString(error);
|
||||
Logger.ERROR(bot, Error);
|
||||
}
|
||||
}
|
||||
|
||||
public void executeString (CommandSource source, String command) {
|
||||
String[] splitArguments = command.split(" ");
|
||||
String commandName = splitArguments[0];
|
||||
final String[] args = Arrays.copyOfRange(splitArguments, 1, splitArguments.length);
|
||||
|
||||
this.execute(source, commandName, args);
|
||||
}
|
||||
|
||||
public CommandManagerModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
registerCommand(new EchoCommand());
|
||||
registerCommand(new HelpCommand());
|
||||
registerCommand(new ReconnectCommand());
|
||||
registerCommand(new RCCommand());
|
||||
registerCommand(new MCServerCommand());
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
|
||||
//import org.jline
|
||||
import land.chipmunk.parker2991.nitoribot.Config;
|
||||
import land.chipmunk.parker2991.nitoribot.Main;
|
||||
import org.jline.reader.*;
|
||||
import org.jline.terminal.*;
|
||||
|
||||
import javax.sound.sampled.Line;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class ConsoleModule implements Completer {
|
||||
private static final List<Bot> servers = Main.Bots;
|
||||
|
||||
public LineReader reader;
|
||||
|
||||
public String server = "all";
|
||||
|
||||
@Override
|
||||
public void complete (LineReader reader, ParsedLine line, List<Candidate> candidates) {
|
||||
|
||||
}
|
||||
|
||||
private void handleLine (String line) {
|
||||
for (Bot bot : servers) {
|
||||
if (line.equals("c.kill")) System.exit(0);
|
||||
bot.chat.send(line);
|
||||
}
|
||||
}
|
||||
|
||||
public ConsoleModule (Config config) {
|
||||
this.reader = LineReaderBuilder.builder()
|
||||
.completer(this)
|
||||
.build();
|
||||
|
||||
Main.executorService.submit(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
String line = null;
|
||||
|
||||
line = reader.readLine(String.format("[%s] > ", this.server));
|
||||
|
||||
handleLine(line);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}, "Console Thread");
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
/*
|
||||
i will work on this module some other time,
|
||||
i have been messing with it and trying to get it to work for 3 days straight
|
||||
so this is currently stubbed
|
||||
*/
|
||||
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.MCProtocolLibMessenger;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.*;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ExtrasMessagingModule extends Listener {
|
||||
private Bot bot;
|
||||
|
||||
public final List<String> channels = new ArrayList<>();
|
||||
|
||||
public static final String TEST_CHANNEL = "test";
|
||||
|
||||
public void register (String channel) {
|
||||
|
||||
}
|
||||
|
||||
public void unregister (String channel) {
|
||||
|
||||
}
|
||||
|
||||
public void sendMessage (MCProtocolLibMessenger messenger, String channel, String message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extrasMessagingReceived (MCProtocolLibMessenger message) {
|
||||
/*var findPlayer = bot.players.getPlayerUUID(player).profile.getName();
|
||||
bot.chat.tellraw("@a[tag=nitoribot_debug]",
|
||||
Component.text(
|
||||
"Recieved: " + message + "\n" +
|
||||
"From: " + findPlayer + "\n" +
|
||||
"Channel: " + channel
|
||||
)
|
||||
);*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetSent(Session session, Packet packet) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
messenger.receivePayloads(
|
||||
TEST_CHANNEL,
|
||||
(_, _, payload) -> {
|
||||
Logger.info(
|
||||
"Received {}",
|
||||
payload.toString(StandardCharsets.UTF_8)
|
||||
);
|
||||
messenger.sendMessage(TEST_CHANNEL, payload);
|
||||
}
|
||||
);
|
||||
|
||||
messenger.sendMessage(
|
||||
TEST_CHANNEL,
|
||||
wrappedBuffer("echo".getBytes(StandardCharsets.UTF_8))
|
||||
);
|
||||
*/
|
||||
|
||||
public ExtrasMessagingModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.logger.Logger;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.*;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class LoggingModule extends Listener {
|
||||
private Bot bot;
|
||||
|
||||
@Override
|
||||
public void playerChatReceived (Component message) {
|
||||
handleMessages(message);
|
||||
};
|
||||
|
||||
@Override
|
||||
public void disguisedChatReceived (Component message) {
|
||||
handleMessages(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void systemChatReceived (Component message) {
|
||||
handleMessages(message);
|
||||
}
|
||||
|
||||
public void handleMessages (Component _message) {
|
||||
final String host = bot.options.host;
|
||||
|
||||
final int port = bot.options.port;
|
||||
|
||||
String message = ComponentUtil.componentToAnsi(_message);
|
||||
//if (host.equals("kaboom.pw")) return;
|
||||
// Logger.LOG(bot, message);
|
||||
}
|
||||
|
||||
public LoggingModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PingServerData;
|
||||
import org.geysermc.mcprotocollib.auth.SessionService;
|
||||
import org.geysermc.mcprotocollib.network.ClientSession;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.factory.ClientNetworkSessionFactory;
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftConstants;
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.HandPreference;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.setting.ChatVisibility;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.setting.ParticleStatus;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.setting.SkinPart;
|
||||
import org.geysermc.mcprotocollib.protocol.data.status.ServerStatusInfo;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.common.serverbound.ServerboundClientInformationPacket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class MCServerModule {
|
||||
private Bot bot;
|
||||
|
||||
public ClientSession client;
|
||||
|
||||
public final SessionService sessionService = new SessionService();
|
||||
|
||||
public final MinecraftProtocol protocol = new MinecraftProtocol();
|
||||
|
||||
private final List<SkinPart> skinParts = new ArrayList<>();
|
||||
|
||||
public PingServerData pingServer (String[] host) {
|
||||
AtomicReference<PingServerData> serverData = new AtomicReference<>();
|
||||
|
||||
client = ClientNetworkSessionFactory.factory()
|
||||
.setAddress("kaboom.pw", 25565)
|
||||
//.setAddress(host[0], Integer.parseInt(host[1]))
|
||||
.setProtocol(protocol)
|
||||
.create();
|
||||
|
||||
client.send(
|
||||
new ServerboundClientInformationPacket(
|
||||
"en_us",
|
||||
1,
|
||||
ChatVisibility.FULL,
|
||||
true,
|
||||
skinParts,
|
||||
HandPreference.RIGHT_HAND,
|
||||
false,
|
||||
true,
|
||||
ParticleStatus.ALL
|
||||
)
|
||||
);
|
||||
|
||||
client.setFlag(MinecraftConstants.SESSION_SERVICE_KEY, sessionService);
|
||||
|
||||
client.setFlag(MinecraftConstants.SERVER_INFO_HANDLER_KEY, (Session session, ServerStatusInfo info) -> {
|
||||
//System.out.println(info.getVersionInfo().getVersionName());
|
||||
//System.out.println(info.getPlayerInfo().getOnlinePlayers());
|
||||
//assert info.getVersionInfo() != null;
|
||||
//assert info.getPlayerInfo() != null;
|
||||
/*
|
||||
String versionName,
|
||||
long protocolVersion,
|
||||
int playersOnline,
|
||||
int maxPlayers,
|
||||
Component description
|
||||
*/
|
||||
assert info.getVersionInfo() != null;
|
||||
assert info.getPlayerInfo() != null;
|
||||
|
||||
serverData.set(new PingServerData(
|
||||
info.getVersionInfo().getVersionName(),
|
||||
info.getVersionInfo().getProtocolVersion(),
|
||||
info.getPlayerInfo().getOnlinePlayers(),
|
||||
info.getPlayerInfo().getMaxPlayers(),
|
||||
info.getDescription()
|
||||
));
|
||||
});
|
||||
|
||||
System.out.println(serverData);
|
||||
|
||||
client.setFlag(MinecraftConstants.SERVER_PING_TIME_HANDLER_KEY, (session, pingTime) ->
|
||||
serverData.get().latency(pingTime)
|
||||
);
|
||||
bot.executor.submit(() -> {
|
||||
client.connect();
|
||||
});
|
||||
|
||||
return serverData.get();
|
||||
}
|
||||
|
||||
public MCServerModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.PlayerListEntry;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.PlayerListEntryAction;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundPlayerInfoRemovePacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundPlayerInfoUpdatePacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundMoveEntityPosPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundMoveEntityPosRotPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundAddEntityPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundRemoveEntitiesPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundTeleportEntityPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundRotateHeadPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundEntityPositionSyncPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundEntityTagQuery;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.ClientboundTagQueryPacket;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PlayerPositionData;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.Listener;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class PlayerListModule extends Listener {
|
||||
private Bot bot;
|
||||
|
||||
public final List<PlayerProfileData> list = new ArrayList<>();
|
||||
|
||||
public int transactionId = 0;
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundPlayerInfoUpdatePacket) playerInfo((ClientboundPlayerInfoUpdatePacket) packet);
|
||||
else if (packet instanceof ClientboundPlayerInfoRemovePacket) playerRemove((ClientboundPlayerInfoRemovePacket) packet);
|
||||
else if (packet instanceof ClientboundAddEntityPacket) getPlayerPosition((ClientboundAddEntityPacket) packet);
|
||||
else if (packet instanceof ClientboundTagQueryPacket) queryPlayerData((ClientboundTagQueryPacket) packet);
|
||||
}
|
||||
|
||||
public void playerInfo (ClientboundPlayerInfoUpdatePacket packet) {
|
||||
EnumSet<PlayerListEntryAction> actions = packet.getActions();
|
||||
|
||||
for (PlayerListEntryAction action : actions) {
|
||||
for (PlayerListEntry entry : packet.getEntries()) {
|
||||
switch (action) {
|
||||
case PlayerListEntryAction.UPDATE_LIST_ORDER,
|
||||
PlayerListEntryAction.UPDATE_HAT,
|
||||
PlayerListEntryAction.INITIALIZE_CHAT,
|
||||
PlayerListEntryAction.ADD_PLAYER -> addPlayer(entry);
|
||||
case PlayerListEntryAction.UPDATE_LISTED -> updateListed(entry);
|
||||
case PlayerListEntryAction.UPDATE_GAME_MODE -> updateGamemode(entry);
|
||||
case PlayerListEntryAction.UPDATE_LATENCY -> updateLatency(entry);
|
||||
case PlayerListEntryAction.UPDATE_DISPLAY_NAME -> updateDisplayName(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void queryPlayerData (ClientboundTagQueryPacket packet) {
|
||||
|
||||
}
|
||||
|
||||
public void getPlayerPosition (ClientboundAddEntityPacket packet) {
|
||||
if (packet.getType() == EntityType.PLAYER) {
|
||||
UUID uuid = packet.getUuid();
|
||||
|
||||
int entityId = packet.getEntityId();
|
||||
|
||||
Vector3d playerPosition = Vector3d.from(packet.getX(), packet.getY(), packet.getZ());
|
||||
|
||||
float yaw = packet.getYaw();
|
||||
|
||||
float pitch = packet.getPitch();
|
||||
|
||||
PlayerProfileData player = getPlayerUUID(uuid);
|
||||
|
||||
player.entityId = entityId;
|
||||
|
||||
player.position = new PlayerPositionData(pitch, yaw, playerPosition);
|
||||
|
||||
// bot.session.send(
|
||||
// new Server
|
||||
//)
|
||||
}
|
||||
}
|
||||
|
||||
public final PlayerProfileData getPlayerByEntityID (int entityId) {
|
||||
for (PlayerProfileData player : list) {
|
||||
if (player.entityId == entityId) {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public final PlayerProfileData getPlayerUUID (UUID uuid) {
|
||||
PlayerProfileData playerInfo = null;
|
||||
|
||||
for (PlayerProfileData player : list) {
|
||||
if (player.profile.getId().equals(uuid)) {
|
||||
playerInfo = player;
|
||||
}
|
||||
};
|
||||
|
||||
if (playerInfo == null) {};
|
||||
|
||||
return playerInfo;
|
||||
}
|
||||
|
||||
public final PlayerProfileData getDisplayName (Component displayName) {
|
||||
for (PlayerProfileData candidate : list) {
|
||||
if (candidate.displayName != null && candidate.displayName.equals(displayName)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void updateListed (PlayerListEntry player) {
|
||||
PlayerProfileData getPlayer = getPlayerUUID(player.getProfileId());
|
||||
|
||||
if (getPlayer == null) return;
|
||||
|
||||
getPlayer.listed = player.isListed();
|
||||
}
|
||||
|
||||
public void updateGamemode (PlayerListEntry player) {
|
||||
PlayerProfileData getPlayer = getPlayerUUID(player.getProfileId());
|
||||
|
||||
if (getPlayer == null) return;
|
||||
|
||||
getPlayer.gameMode = player.getGameMode();
|
||||
}
|
||||
|
||||
public void updateLatency (PlayerListEntry player) {
|
||||
PlayerProfileData getPlayer = getPlayerUUID(player.getProfileId());
|
||||
|
||||
if (getPlayer == null) return;
|
||||
|
||||
getPlayer.latency = player.getLatency();
|
||||
}
|
||||
|
||||
public void updateDisplayName (PlayerListEntry player) {
|
||||
PlayerProfileData getPlayer = getPlayerUUID(player.getProfileId());
|
||||
|
||||
if (getPlayer == null) return;
|
||||
|
||||
getPlayer.displayName = player.getDisplayName();
|
||||
}
|
||||
|
||||
public void addPlayer (PlayerListEntry player) {
|
||||
PlayerProfileData findDuplicatePlayer = getPlayerUUID(player.getProfileId());
|
||||
|
||||
if (findDuplicatePlayer != null) list.remove(findDuplicatePlayer);
|
||||
|
||||
PlayerProfileData formatPlayerData = new PlayerProfileData(
|
||||
player.getProfileId(),
|
||||
player.getProfile(),
|
||||
player.isListed(),
|
||||
player.getLatency(),
|
||||
player.getGameMode(),
|
||||
player.getDisplayName()
|
||||
);
|
||||
|
||||
list.add(formatPlayerData);
|
||||
}
|
||||
|
||||
public void playerRemove (ClientboundPlayerInfoRemovePacket packet) {
|
||||
for (UUID uuid : packet.getProfileIds()) {
|
||||
PlayerProfileData getPlayer = getPlayerUUID(uuid);
|
||||
list.remove(getPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerListModule (Bot bot) {
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.data.PositionData;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.*;
|
||||
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerPositionPacket;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
|
||||
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
|
||||
public class PositionModule extends Listener {
|
||||
private Bot bot;
|
||||
|
||||
public Vector3d positionAsVector = null;
|
||||
|
||||
public PositionData positionAsInteger;
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundPlayerPositionPacket) packetReceived((ClientboundPlayerPositionPacket) packet);
|
||||
}
|
||||
|
||||
public void packetReceived (ClientboundPlayerPositionPacket packet) {
|
||||
Vector3d getPosition = packet.getPosition();
|
||||
|
||||
int x = (int) Math.round(getPosition.getX());
|
||||
int y = (int) Math.round(getPosition.getY());
|
||||
int z = (int) Math.round(getPosition.getZ());
|
||||
|
||||
positionAsInteger = new PositionData(x, y, z);
|
||||
positionAsVector = getPosition;
|
||||
|
||||
bot.session.send(
|
||||
new ServerboundAcceptTeleportationPacket(
|
||||
packet.getId()
|
||||
)
|
||||
);
|
||||
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.botMoved();
|
||||
}
|
||||
}
|
||||
|
||||
public PositionModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.*;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.configuration.clientbound.ClientboundRegistryDataPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.RegistryEntry;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RegistryModule extends Listener {
|
||||
public final List<String> chatTypes = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundRegistryDataPacket) packetReceived((ClientboundRegistryDataPacket) packet);
|
||||
}
|
||||
|
||||
public void packetReceived (ClientboundRegistryDataPacket packet) {
|
||||
String getRegistry = packet.getRegistry().asString();
|
||||
for (RegistryEntry entry : packet.getEntries()) {
|
||||
if (getRegistry.equals("minecraft:chat_type"))
|
||||
chatTypes.add(entry.getData().getCompound("chat").getString("translation_key"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public RegistryModule (Bot bot) {
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.selfcare.entity.*;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.*;
|
||||
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundChangeGameModePacket;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.login.clientbound.ClientboundLoginFinishedPacket;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectedEvent;
|
||||
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SelfcareModule extends Listener {
|
||||
public ScheduledFuture<?> timer;
|
||||
|
||||
private Bot bot;
|
||||
|
||||
public PermissionSelfcare permission;
|
||||
|
||||
public GamemodeSelfcare gamemode;
|
||||
|
||||
public int entityId;
|
||||
|
||||
public void loadSelfcare () {
|
||||
this.permission = new PermissionSelfcare(bot);
|
||||
this.gamemode = new GamemodeSelfcare(bot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundLoginFinishedPacket) login((ClientboundLoginFinishedPacket) packet);
|
||||
}
|
||||
|
||||
public void login (ClientboundLoginFinishedPacket packet) {
|
||||
timer = bot.executor.scheduleAtFixedRate(() -> {
|
||||
if (permission.level < 2 && bot.loggedIn == true) bot.chat.command("minecraft:op @s[type=player]");
|
||||
else if (gamemode.gamemode != 1) bot.session.send(
|
||||
new ServerboundChangeGameModePacket(
|
||||
GameMode.CREATIVE
|
||||
)
|
||||
);
|
||||
}, 0, bot.options.selfcareInterval, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public void disconnect (DisconnectedEvent event) {
|
||||
timer.cancel(true);
|
||||
}
|
||||
|
||||
public SelfcareModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.listenerManager.addListener(this);
|
||||
loadSelfcare();
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.listeners.*;
|
||||
import land.chipmunk.parker2991.nitoribot.util.ComponentUtil;
|
||||
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataTypes;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.ByteMetadataType;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundAddEntityPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundSetEntityDataPacket;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TextDisplayModule extends Listener {
|
||||
private Bot bot;
|
||||
|
||||
private static final int TEXT_DISPLAY_ENTITY_ID = 32;
|
||||
|
||||
private int entityId;
|
||||
|
||||
@Override
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
if (packet instanceof ClientboundSetEntityDataPacket) getTextDisplay((ClientboundSetEntityDataPacket) packet);
|
||||
}
|
||||
|
||||
private void getTextDisplay (ClientboundSetEntityDataPacket packet) {
|
||||
for (EntityMetadata<?, ?> metaData : packet.getMetadata()) {
|
||||
if (metaData.getId() == TEXT_DISPLAY_ENTITY_ID) {
|
||||
Component value = (Component) metaData.getValue();
|
||||
System.out.println(ComponentUtil.componentToAnsi(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TextDisplayModule (Bot bot) {
|
||||
this.bot = bot;
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights;
|
||||
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.*;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.boot.GetProxiesList;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.modules.*;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.lenni0451.lambdaevents.EventHandler;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectedEvent;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectingEvent;
|
||||
import org.geysermc.mcprotocollib.network.event.session.PacketErrorEvent;
|
||||
import org.geysermc.mcprotocollib.network.factory.ClientNetworkSessionFactory;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundPlayerLoadedPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.login.clientbound.ClientboundLoginFinishedPacket;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public @NullMarked class Client extends NitoriBot {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Client.class);
|
||||
|
||||
public Client (
|
||||
Config.Options options,
|
||||
List<NitoriBot> bots,
|
||||
Config config
|
||||
) throws Exception {
|
||||
this.options = options;
|
||||
this.bots = bots;
|
||||
this.config = config;
|
||||
this.modules = List.of(
|
||||
this.discord = new DiscordModule(this),
|
||||
this.chat = new ChatModule(this),
|
||||
new SelfcareModule(this),
|
||||
this.position = new PositionModule(this),
|
||||
this.core = new CommandCoreModule(this),
|
||||
this.registry = new RegistryModule(this),
|
||||
this.players = new PlayerListModule(this),
|
||||
new LoggingModule(this),
|
||||
new ChatCommandHandlerModule(this),
|
||||
this.commandManager = new CommandManagerModule(this),
|
||||
new TextDisplayModule(this),
|
||||
this.mcServer = new MCServerModule(this),
|
||||
new CommandSpyModule(this),
|
||||
this.world = new WorldModule(this),
|
||||
this.tabComplete = new TabCompleteModule(this),
|
||||
this.extrasMessaging = new ExtrasMessagingModule(this),
|
||||
this.validation = new ValidationModule(this)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnecting (
|
||||
DisconnectingEvent event
|
||||
) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetSent (
|
||||
Session session,
|
||||
Packet packet
|
||||
) {
|
||||
for (Listener listener : listenerManager.listeners) {
|
||||
listener.packetSent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetError (
|
||||
PacketErrorEvent error
|
||||
) {
|
||||
error.setSuppress(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (
|
||||
Session session,
|
||||
Packet packet
|
||||
) {
|
||||
try {
|
||||
if (packet instanceof ClientboundLoginPacket)
|
||||
this.session.send(ServerboundPlayerLoadedPacket.INSTANCE);
|
||||
|
||||
for (Listener listener : listenerManager.listeners) {
|
||||
listener.packetReceived(packet);
|
||||
}
|
||||
|
||||
switch (packet) {
|
||||
case ClientboundLoginFinishedPacket p -> getProfile(p);
|
||||
case ClientboundLoginPacket p -> getEntityId(p);
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
} catch (Exception _) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void getProfile (
|
||||
ClientboundLoginFinishedPacket packet
|
||||
) {
|
||||
profile = packet.getProfile();
|
||||
|
||||
loggedIn = true;
|
||||
}
|
||||
|
||||
private void getEntityId (
|
||||
ClientboundLoginPacket packet
|
||||
) {
|
||||
entityId = packet.getEntityId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected (
|
||||
DisconnectedEvent event
|
||||
) {
|
||||
listenerManager.clearListener();
|
||||
loggedIn = false;
|
||||
|
||||
Component host = Component
|
||||
.text(String.format(
|
||||
"[%s:%s] ",
|
||||
options.host,
|
||||
options.port
|
||||
))
|
||||
.color(NamedTextColor.BLUE);
|
||||
Component reason = Component
|
||||
.empty()
|
||||
.append(host)
|
||||
.append(event.getReason());
|
||||
|
||||
logger.reconnect(ComponentUtil.componentToAnsi(reason));
|
||||
|
||||
scheduler.schedule(
|
||||
() -> {
|
||||
try {
|
||||
connect();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(
|
||||
"{}",
|
||||
NitoriBot.class,
|
||||
e
|
||||
);
|
||||
}
|
||||
},
|
||||
options.reconnectDelay,
|
||||
TimeUnit.MILLISECONDS
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Config {
|
||||
public final Colors colors = new Colors();
|
||||
public final Core core = new Core();
|
||||
public final Console console = new Console();
|
||||
public final Options[] bots = new Options[]{};
|
||||
public List<String> prefixes;
|
||||
public final Keys keys = new Keys();
|
||||
public final Discord discord = new Discord();
|
||||
|
||||
public static class DiscordRoles {
|
||||
public String trusted;
|
||||
public String admin;
|
||||
public String owner;
|
||||
}
|
||||
|
||||
public static class Discord {
|
||||
public String token;
|
||||
public boolean enabled;
|
||||
public String prefix;
|
||||
public String invite;
|
||||
public final DiscordRoles roles = new DiscordRoles();
|
||||
}
|
||||
|
||||
public static class Keys {
|
||||
public String trusted;
|
||||
public String admin;
|
||||
public String owner;
|
||||
}
|
||||
|
||||
public static class Core {
|
||||
public boolean itemRefill;
|
||||
public final Area area = new Area();
|
||||
public String coreName;
|
||||
}
|
||||
|
||||
public static class Area {
|
||||
public final Position start = new Position();
|
||||
public final Position end = new Position();
|
||||
}
|
||||
|
||||
public static class Position {
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
}
|
||||
|
||||
public static class CommandColors {
|
||||
public String primary;
|
||||
public String secondary;
|
||||
public String tertiary;
|
||||
}
|
||||
|
||||
public static class HelpCommandColors {
|
||||
public String Public;
|
||||
public String trusted;
|
||||
public String admin;
|
||||
public String owner;
|
||||
public String console;
|
||||
}
|
||||
|
||||
public static class Console {
|
||||
public String prefix;
|
||||
}
|
||||
|
||||
public static class Colors {
|
||||
public final CommandColors commands = new CommandColors();
|
||||
public final HelpCommandColors help = new HelpCommandColors();
|
||||
public String integer;
|
||||
}
|
||||
|
||||
public static class Options {
|
||||
public String host;
|
||||
public int port;
|
||||
public boolean useProxy;
|
||||
public String serverName;
|
||||
public boolean isPrivate;
|
||||
public String username;
|
||||
public String discordChannelId;
|
||||
public int reconnectDelay;
|
||||
public int selfcareInterval;
|
||||
public String mode;
|
||||
public boolean useMiniMessage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.boot.GetBotBuildInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.boot.GetRepoInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.boot.LoadConfig;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.console.CreateConsole;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.blocks.BlockRegistries;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.BotBuildInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.RepoCommitInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.discord.MessageLogger;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
public class Main {
|
||||
private static final Gson GSON = new Gson();
|
||||
public static final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
public static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||
public static final List<NitoriBot> Bots = new ArrayList<>();
|
||||
public static RepoCommitInfo repoCommitInfo = null;
|
||||
public static BotBuildInfo botBuildInfo = null;
|
||||
public static CreateConsole console;
|
||||
public Config config;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
|
||||
public static final List<BlockRegistries> blocks = new ArrayList<>();
|
||||
|
||||
public static JDA discordClient;
|
||||
|
||||
static {
|
||||
final List<BlockRegistries> registries = new ArrayList<>();
|
||||
final List<BlockRegistries> blockRegistries = new ArrayList<>();
|
||||
final Reader blockRegistryReader = new InputStreamReader(Main.class.getResourceAsStream("/blocks" + ".json"));
|
||||
final Reader registriesReader = new InputStreamReader(Main.class.getResourceAsStream("/registries" + ".json"));
|
||||
final Map<?, ?> map = GSON.fromJson(
|
||||
blockRegistryReader,
|
||||
Map.class
|
||||
);
|
||||
|
||||
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||
String json = GSON.toJson(entry.getValue());
|
||||
final BlockRegistries parsed = GSON.fromJson(
|
||||
json,
|
||||
BlockRegistries.class
|
||||
);
|
||||
parsed.block = entry
|
||||
.getKey()
|
||||
.toString();
|
||||
registries.add(parsed);
|
||||
}
|
||||
final JsonElement parseRegistries = JsonParser.parseReader(registriesReader);
|
||||
final JsonElement itemArray = parseRegistries
|
||||
.getAsJsonObject()
|
||||
.get("minecraft:item")
|
||||
.getAsJsonObject()
|
||||
.get("entries");
|
||||
final JsonElement blockArray = parseRegistries
|
||||
.getAsJsonObject()
|
||||
.get("minecraft:block")
|
||||
.getAsJsonObject()
|
||||
.get("entries");
|
||||
final Map<?, ?> blockEntrySet = GSON.fromJson(
|
||||
blockArray,
|
||||
Map.class
|
||||
);
|
||||
final Map<?, ?> itemEntrySet = GSON.fromJson(
|
||||
itemArray,
|
||||
Map.class
|
||||
);
|
||||
|
||||
for (Map.Entry<?, ?> entry : blockEntrySet.entrySet()) {
|
||||
String key = entry
|
||||
.getKey()
|
||||
.toString();
|
||||
for (BlockRegistries block : registries) {
|
||||
final Pattern pattern = Pattern.compile("\\{protocol_id=(\\d+(?:\\.\\d+)?)\\}");
|
||||
final Matcher matcher = pattern.matcher(entry
|
||||
.getValue()
|
||||
.toString());
|
||||
if (matcher.find()) {
|
||||
if (block.block.equals(key)) {
|
||||
block.blockId = (int) Float.parseFloat(matcher.group(1));
|
||||
blockRegistries.add(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<?, ?> entry : itemEntrySet.entrySet()) {
|
||||
final String key = entry
|
||||
.getKey()
|
||||
.toString();
|
||||
for (BlockRegistries block : blockRegistries) {
|
||||
final Pattern pattern = Pattern.compile("\\{protocol_id=(\\d+(?:\\.\\d+)?)\\}");
|
||||
final Matcher matcher = pattern.matcher(entry
|
||||
.getValue()
|
||||
.toString());
|
||||
|
||||
if (matcher.find()) {
|
||||
if (block.block.equals(key)) {
|
||||
block.itemId = (int) Float.parseFloat(matcher.group(1));
|
||||
blocks.add(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main () {
|
||||
try {
|
||||
botBuildInfo = new GetBotBuildInfo().getBuildInfo();
|
||||
System.out.println("Starting NitoriBot " + ComponentUtil.componentToAnsi(GsonComponentSerializer
|
||||
.gson()
|
||||
.deserialize(botBuildInfo.buildstring.codename.toString())));
|
||||
config = new LoadConfig().loadConfig();
|
||||
Config.Options[] bots = config.bots;
|
||||
console = new CreateConsole();
|
||||
repoCommitInfo = new GetRepoInfo().getRepoInfo();
|
||||
|
||||
if (config.discord.enabled) {
|
||||
JDABuilder builder = JDABuilder.createDefault(config.discord.token);
|
||||
builder.enableIntents(
|
||||
GatewayIntent.MESSAGE_CONTENT,
|
||||
GatewayIntent.DIRECT_MESSAGES,
|
||||
GatewayIntent.GUILD_MEMBERS
|
||||
);
|
||||
|
||||
discordClient = builder.build();
|
||||
discordClient.addEventListener(new MessageLogger(discordClient));
|
||||
discordClient.awaitReady();
|
||||
}
|
||||
|
||||
for (Config.Options options : bots) {
|
||||
final NitoriBot bot = new Client(
|
||||
options,
|
||||
Bots,
|
||||
config
|
||||
);
|
||||
Bots.add(bot);
|
||||
bot.connect();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(
|
||||
"{}",
|
||||
Main.class,
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights;
|
||||
|
||||
import jdk.jshell.JShell;
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.Injector;
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.MCProtocolLibMessagingEntrypoint;
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.MCProtocolLibMessenger;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.boot.GetProxiesList;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.ChatAttestation;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.console.logger.LoggerManager;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.BotBuildInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.RepoCommitInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.ListenerManager;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.modules.*;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.lenni0451.lambdaevents.AHandler;
|
||||
import net.lenni0451.lambdaevents.EventHandler;
|
||||
import net.lenni0451.lambdaevents.IGenerator;
|
||||
import net.lenni0451.lambdaevents.LambdaManager;
|
||||
import net.lenni0451.lambdaevents.generator.LambdaMetaFactoryGenerator;
|
||||
import net.lenni0451.lambdaevents.generator.ReflectionGenerator;
|
||||
import org.geysermc.mcprotocollib.auth.GameProfile;
|
||||
import org.geysermc.mcprotocollib.network.event.session.SessionAdapter;
|
||||
import org.geysermc.mcprotocollib.network.factory.ClientNetworkSessionFactory;
|
||||
import org.geysermc.mcprotocollib.network.netty.DefaultPacketHandlerExecutor;
|
||||
import org.geysermc.mcprotocollib.network.session.ClientNetworkSession;
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
public class NitoriBot extends SessionAdapter implements MCProtocolLibMessagingEntrypoint {
|
||||
public final LoggerManager logger = new LoggerManager();
|
||||
public final ListenerManager listenerManager = new ListenerManager();
|
||||
public final ScheduledExecutorService scheduler = Main.scheduler;
|
||||
public final BotBuildInfo botBuildInfo = Main.botBuildInfo;
|
||||
public final RepoCommitInfo repoCommitInfo = Main.repoCommitInfo;
|
||||
public Config config;
|
||||
public Config.Options options;
|
||||
public List<NitoriBot> bots;
|
||||
public ChatModule chat;
|
||||
public PositionModule position;
|
||||
public CommandCoreModule core;
|
||||
public PlayerListModule players;
|
||||
public RegistryModule registry;
|
||||
public ValidationModule validation;
|
||||
public boolean loggedIn = false;
|
||||
public int entityId;
|
||||
public ClientNetworkSession session;
|
||||
public GameProfile profile;
|
||||
public CommandManagerModule commandManager;
|
||||
public MCServerModule mcServer;
|
||||
public WorldModule world;
|
||||
public TabCompleteModule tabComplete;
|
||||
public ExtrasMessagingModule extrasMessaging;
|
||||
public List<?> modules;
|
||||
public DiscordModule discord;
|
||||
public final Map<Object, JShell> evalStorage = new HashMap<>();
|
||||
|
||||
public void addServer (String host, int port, String discordChannelId, String username, boolean useProxy) {
|
||||
// this function is here for shits and giggles
|
||||
Config.Options botOptions = new Config.Options();
|
||||
botOptions.host = host;
|
||||
botOptions.port = port;
|
||||
botOptions.username = username;
|
||||
botOptions.discordChannelId = discordChannelId;
|
||||
botOptions.isPrivate = false;
|
||||
botOptions.reconnectDelay = 6000;
|
||||
botOptions.serverName = "test";
|
||||
botOptions.useProxy = useProxy;
|
||||
botOptions.useMiniMessage = false;
|
||||
|
||||
try {
|
||||
NitoriBot client = new Client(
|
||||
botOptions,
|
||||
bots,
|
||||
config
|
||||
);
|
||||
|
||||
// Main.Bots.add(client);
|
||||
|
||||
client.connect();
|
||||
} catch (Exception ignore) {}
|
||||
|
||||
}
|
||||
//public final ChatAttestation chatAttestation = new ChatAttestation();
|
||||
|
||||
public void connect () throws IOException {
|
||||
final MinecraftProtocol protocol = new MinecraftProtocol(options.username);
|
||||
|
||||
if (options.useProxy)
|
||||
session = ClientNetworkSessionFactory
|
||||
.factory()
|
||||
.setAddress(
|
||||
options.host,
|
||||
options.port
|
||||
)
|
||||
.setProxy(new GetProxiesList().randomProxyIp())
|
||||
.setProtocol(protocol)
|
||||
.create();
|
||||
|
||||
else
|
||||
session = ClientNetworkSessionFactory
|
||||
.factory()
|
||||
.setAddress(
|
||||
options.host,
|
||||
options.port
|
||||
)
|
||||
.setProtocol(protocol)
|
||||
.create();
|
||||
Injector.inject(
|
||||
session,
|
||||
this
|
||||
);
|
||||
ChatAttestation.inject(session);
|
||||
session.addListener(this);
|
||||
session.connect(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegistrationAvailable (MCProtocolLibMessenger messenger) {
|
||||
// stub
|
||||
}
|
||||
|
||||
public NitoriBot () {
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.boot;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.BotBuildInfo;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.util.Objects;
|
||||
|
||||
public class GetBotBuildInfo {
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
public BotBuildInfo getBuildInfo () {
|
||||
Reader reader = new InputStreamReader(Objects.requireNonNull(Main.class.getResourceAsStream("/info.json")));
|
||||
|
||||
return GSON.fromJson(
|
||||
reader,
|
||||
BotBuildInfo.class
|
||||
);
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.boot;
|
||||
|
||||
import org.geysermc.mcprotocollib.network.ProxyInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class GetProxiesList {
|
||||
public ProxyInfo randomProxyIp () throws IOException {
|
||||
Path proxiesPath = Paths.get("proxies.txt");
|
||||
|
||||
int countLines = Math.round(Files
|
||||
.lines(proxiesPath)
|
||||
.count());
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
int randomIndex = random.nextInt(countLines);
|
||||
|
||||
List<String> lines = Files
|
||||
.lines(proxiesPath)
|
||||
.toList();
|
||||
|
||||
String[] ip = lines
|
||||
.stream()
|
||||
.skip(randomIndex)
|
||||
.findAny()
|
||||
.get()
|
||||
.split(":");
|
||||
|
||||
InetSocketAddress address = new InetSocketAddress(
|
||||
ip[0],
|
||||
Integer.parseInt(ip[1])
|
||||
);
|
||||
|
||||
return new ProxyInfo(
|
||||
ProxyInfo.Type.SOCKS5,
|
||||
address
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.boot;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.RepoCommitInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
public class GetRepoInfo {
|
||||
private static final Gson GSON = new Gson();
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GetRepoInfo.class);
|
||||
|
||||
public RepoCommitInfo getRepoInfo () {
|
||||
final String repo = "https://code.chipmunk.land/api/v1/repos/Parker2991/NitoriBot/commits?sha=main";
|
||||
HttpClient client = HttpClient
|
||||
.newBuilder()
|
||||
.followRedirects(HttpClient.Redirect.NORMAL)
|
||||
.connectTimeout(Duration.ofSeconds(20))
|
||||
.build();
|
||||
|
||||
HttpRequest request = HttpRequest
|
||||
.newBuilder()
|
||||
.uri(URI.create(repo))
|
||||
.timeout(Duration.ofMillis(20))
|
||||
.header(
|
||||
"accept",
|
||||
"application/json"
|
||||
)
|
||||
.build();
|
||||
|
||||
RepoCommitInfo info = null;
|
||||
try {
|
||||
HttpResponse<String> response = client.send(
|
||||
request,
|
||||
HttpResponse.BodyHandlers.ofString()
|
||||
);
|
||||
JsonElement json = JsonParser.parseString(response.body());
|
||||
|
||||
info = GSON.fromJson(
|
||||
json
|
||||
.getAsJsonArray()
|
||||
.get(0),
|
||||
RepoCommitInfo.class
|
||||
);
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(
|
||||
"{}",
|
||||
GetRepoInfo.class,
|
||||
e
|
||||
);
|
||||
ZoneId timezone = ZoneId.of("America/Chicago");
|
||||
String zoneDate = String.valueOf(ZonedDateTime.now(timezone));
|
||||
//ce.printStackTrace(System.err);
|
||||
info = new RepoCommitInfo();
|
||||
info.created = zoneDate;
|
||||
info.commits = 0;
|
||||
info.sha = "N/A";
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.boot;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Config;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.yaml.snakeyaml.LoaderOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class LoadConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LoadConfig.class);
|
||||
|
||||
public Config loadConfig () throws IOException {
|
||||
final Constructor yamlConfig = new Constructor(
|
||||
Config.class,
|
||||
new LoaderOptions()
|
||||
);
|
||||
final Yaml yaml = new Yaml(yamlConfig);
|
||||
final Path configPath = Path.of("config.yml");
|
||||
if (!Files.exists(configPath)) {
|
||||
LOGGER.info("config not found making config now");
|
||||
|
||||
InputStream defaultConfig = Main.class
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("default_config.yml");
|
||||
Files.copy(
|
||||
defaultConfig,
|
||||
configPath
|
||||
);
|
||||
}
|
||||
|
||||
InputStream configFile = Files.newInputStream(configPath);
|
||||
|
||||
return yaml.load(configFile);
|
||||
}
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.Injector;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto.SigningManager;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.SigningResult;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.Util;
|
||||
import org.geysermc.mcprotocollib.network.ClientSession;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto.SigningManager.createHash;
|
||||
|
||||
public class ChatAttestation {
|
||||
private static final UUID NIL_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
|
||||
|
||||
public static SigningResult getSigningStatus (
|
||||
String message,
|
||||
UUID senderUuid,
|
||||
String senderNick
|
||||
) {
|
||||
final byte[] pyl;
|
||||
final var wrapped = new SigningManager.WrappedByteArray(createHash(message.getBytes(StandardCharsets.UTF_8)));
|
||||
final ByteBuf payload;
|
||||
payload = senderUuid == NIL_UUID ?
|
||||
MessagingEntrypointImpl.RECENT_PAYLOADS.remove(wrapped) :
|
||||
MessagingEntrypointImpl.ATTRIBUTED_PAYLOADS
|
||||
.getOrDefault(
|
||||
senderUuid,
|
||||
Collections.emptyMap()
|
||||
)
|
||||
.remove(wrapped);
|
||||
|
||||
if (payload == null) {
|
||||
pyl = null;
|
||||
} else {
|
||||
try {
|
||||
pyl = new byte[payload.readableBytes()];
|
||||
payload.readBytes(pyl);
|
||||
} finally {
|
||||
if (senderUuid != NIL_UUID)
|
||||
MessagingEntrypointImpl.RECENT_PAYLOADS.remove(wrapped);
|
||||
payload.release();
|
||||
}
|
||||
}
|
||||
return Signing.getSigningStatus(
|
||||
senderNick,
|
||||
message,
|
||||
pyl
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static MessagingEntrypointImpl inject (ClientSession clientNetworkSession) {
|
||||
MessagingEntrypointImpl messagingEntrypointImpl = new MessagingEntrypointImpl();
|
||||
Injector.inject(
|
||||
clientNetworkSession,
|
||||
messagingEntrypointImpl
|
||||
);
|
||||
return messagingEntrypointImpl;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public record KeyManifest(@SerializedName("key_to_claims") Map<String, Set<String>> keyToClaims) {
|
||||
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto.SigningManager;
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.*;
|
||||
/*import dev.pthepro777.messaging_lib.MCProtocolLibMessagingEntrypoint;
|
||||
import dev.pthepro777.messaging_lib.MCProtocolLibMessenger;
|
||||
import dev.pthepro777.messaging_lib.MCProtocolLibPayloadReceiver;*/
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.jodah.expiringmap.ExpirationPolicy;
|
||||
import net.jodah.expiringmap.ExpiringMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class MessagingEntrypointImpl implements MCProtocolLibMessagingEntrypoint, MCProtocolLibPayloadReceiver {
|
||||
public static final String CHANNEL_NAME = "chat-attestation/v1:stream";
|
||||
public final Map<StreamCacheKey, ByteBuf> PAYLOAD_MAP = ExpiringMap
|
||||
.builder()
|
||||
.maxSize(1024)
|
||||
.expiration(
|
||||
1,
|
||||
TimeUnit.MINUTES
|
||||
)
|
||||
.build();
|
||||
public static final Map<SigningManager.WrappedByteArray, ByteBuf> RECENT_PAYLOADS = ExpiringMap
|
||||
.builder()
|
||||
.maxSize(1024)
|
||||
.expiration(
|
||||
1,
|
||||
TimeUnit.MINUTES
|
||||
)
|
||||
.asyncExpirationListener(MessagingEntrypointImpl::onExpire)
|
||||
.build();
|
||||
public static final Map<UUID, Map<SigningManager.WrappedByteArray, ByteBuf>> ATTRIBUTED_PAYLOADS = ExpiringMap
|
||||
.builder()
|
||||
.maxSize(256)
|
||||
.expiration(
|
||||
5,
|
||||
TimeUnit.MINUTES
|
||||
)
|
||||
.expirationPolicy(ExpirationPolicy.ACCESSED)
|
||||
.build();
|
||||
public static volatile MCProtocolLibMessenger MESSENGER_INSTANCE;
|
||||
|
||||
public static void onExpire (
|
||||
SigningManager.WrappedByteArray byteArray,
|
||||
ByteBuf buf
|
||||
) {
|
||||
buf.release();
|
||||
}
|
||||
|
||||
|
||||
private static Map<SigningManager.WrappedByteArray, ByteBuf> getAttributionMap (UUID sender) {
|
||||
return ATTRIBUTED_PAYLOADS.computeIfAbsent(
|
||||
sender,
|
||||
_ -> ExpiringMap
|
||||
.builder()
|
||||
.maxSize(16)
|
||||
.expiration(
|
||||
1,
|
||||
TimeUnit.MINUTES
|
||||
)
|
||||
.asyncExpirationListener(MessagingEntrypointImpl::onExpire)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegistrationAvailable (@NotNull MCProtocolLibMessenger messenger) {
|
||||
MESSENGER_INSTANCE = messenger;
|
||||
|
||||
MESSENGER_INSTANCE.receivePayloads(
|
||||
CHANNEL_NAME,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeregister () {
|
||||
MESSENGER_INSTANCE = null;
|
||||
PAYLOAD_MAP.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivePayload (
|
||||
@NotNull String channelName,
|
||||
@NotNull UUID sender,
|
||||
@NotNull ByteBuf payload
|
||||
) {
|
||||
final byte[] contentHash = new byte[16];
|
||||
payload.readBytes(contentHash);
|
||||
|
||||
final var wrapper = new SigningManager.WrappedByteArray(contentHash);
|
||||
RECENT_PAYLOADS.put(
|
||||
wrapper,
|
||||
payload.copy()
|
||||
);
|
||||
getAttributionMap(sender).put(
|
||||
wrapper,
|
||||
payload.copy()
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: This won't work very well with vanished players.
|
||||
public record StreamCacheKey(
|
||||
SigningManager.WrappedByteArray contentHash,
|
||||
UUID sender
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto.Payload.withAdditionalData;
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.Constants.LOGGER;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Collection;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto.Payload;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto.SigningManager;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.enums.SigningStatus;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.SigningResult;
|
||||
|
||||
|
||||
public class Signing {
|
||||
public static SigningResult getSigningStatus (
|
||||
String nick,
|
||||
String msg,
|
||||
byte[] pyl
|
||||
) {
|
||||
if (pyl == null) {
|
||||
return SigningResult.of(SigningManager.INSTANCE.doesNickRequireSignature(nick) ?
|
||||
SigningStatus.NEEDS_SIGNATURE :
|
||||
SigningStatus.NO_PAYLOAD);
|
||||
}
|
||||
|
||||
final Payload decodedPayload;
|
||||
try {
|
||||
decodedPayload = Payload.read(
|
||||
msg.getBytes(StandardCharsets.UTF_8),
|
||||
new DataInputStream(new ByteArrayInputStream(pyl))
|
||||
);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(
|
||||
"{}",
|
||||
Signing.class,
|
||||
e
|
||||
);
|
||||
return SigningResult.of(SigningStatus.NO_PAYLOAD);
|
||||
}
|
||||
|
||||
final var response = SigningManager.INSTANCE.verifyClaim(
|
||||
withAdditionalData(
|
||||
decodedPayload.msg(),
|
||||
decodedPayload.nonce(),
|
||||
decodedPayload.exp()
|
||||
),
|
||||
decodedPayload.signature(),
|
||||
decodedPayload.key(),
|
||||
decodedPayload.exp()
|
||||
);
|
||||
|
||||
return switch (response) {
|
||||
case SigningManager.Response.InvalidSignature __ -> SigningResult.of(SigningStatus.INVALID_SIGNATURE);
|
||||
case SigningManager.Response.NoSuchKey __ -> SigningResult.of(SigningStatus.NO_SUCH_KEY);
|
||||
case SigningManager.Response.ReusedSignature __ -> SigningResult.of(SigningStatus.REUSED_SIGNATURE);
|
||||
case SigningManager.Response.SignatureValid valid -> {
|
||||
final boolean authenticated = valid
|
||||
.key()
|
||||
.manifestUrlToClaims()
|
||||
.values()
|
||||
.stream()
|
||||
.flatMap(Collection::stream)
|
||||
.anyMatch(claim -> claim.equalsIgnoreCase(nick));
|
||||
|
||||
final String encodedKey = Base64
|
||||
.getEncoder()
|
||||
.encodeToString(valid
|
||||
.key()
|
||||
.bc()
|
||||
.getEncoded());
|
||||
|
||||
yield new SigningResult(
|
||||
authenticated ?
|
||||
SigningStatus.VERIFIED :
|
||||
SigningStatus.VALID_UNVERIFIED,
|
||||
encodedKey
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.config;
|
||||
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ConfigSerializable public final class Configuration {
|
||||
private static final String DEFAULT_MANIFEST = "https://optmstc.dev/key-manifest-v1.json";
|
||||
|
||||
public volatile List<String> keyManifestUrls = List.of(DEFAULT_MANIFEST);
|
||||
|
||||
public volatile boolean toggleForSelf = true;
|
||||
public volatile boolean forceFallback = false;
|
||||
public volatile boolean disableFallback = true;
|
||||
public volatile boolean forceCompress = false;
|
||||
public volatile boolean ignoreCspyLike = true;
|
||||
public volatile int chatMsgTrunc = 2048;
|
||||
public volatile int maxCompressedPayload = this.chatMsgTrunc * 4;
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.config;
|
||||
|
||||
import io.github.wasabithumb.jtoml.configurate.TomlConfigurationLoader;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.loader.HeaderMode;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.Constants.storageDir;
|
||||
|
||||
|
||||
public final class ConfigurationManager {
|
||||
public static final ConfigurationManager INSTANCE = new ConfigurationManager();
|
||||
public final Configuration config;
|
||||
private final CommentedConfigurationNode node;
|
||||
private final TomlConfigurationLoader loader;
|
||||
|
||||
private ConfigurationManager () {
|
||||
try {
|
||||
this.loader = TomlConfigurationLoader
|
||||
.builder()
|
||||
.defaultOptions(opts -> opts.shouldCopyDefaults(true))
|
||||
.headerMode(HeaderMode.PRESERVE)
|
||||
.path(storageDir.resolve("chatattestation" + ".toml"))
|
||||
.build();
|
||||
|
||||
this.node = this.loader.load();
|
||||
this.config = Objects.requireNonNull(this.node.get(Configuration.class));
|
||||
save();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(
|
||||
"Configuration error",
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void save () {
|
||||
try {
|
||||
this.node.set(
|
||||
Configuration.class,
|
||||
this.config
|
||||
);
|
||||
this.loader.save(this.node);
|
||||
} catch (ConfigurateException e) {
|
||||
throw new IllegalStateException(
|
||||
"Failed to save config",
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto;
|
||||
|
||||
import com.google.common.primitives.Longs;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.config.ConfigurationManager;
|
||||
import org.apache.commons.compress.compressors.zstandard.ZstdCompressorInputStream;
|
||||
import org.apache.commons.compress.compressors.zstandard.ZstdCompressorOutputStream;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto.SigningManager.PERIOD;
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.Constants.LOGGER;
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.Constants.MESSAGE_LIMIT;
|
||||
|
||||
public record Payload(
|
||||
byte[] msg,
|
||||
byte[] signature,
|
||||
byte[] key,
|
||||
byte[] nonce,
|
||||
long exp,
|
||||
boolean compressedMsg
|
||||
) {
|
||||
private static final int ORIGINAL_MSG_BUDGET = (MESSAGE_LIMIT - 4) - 64 - 16 - 8 - 2 - 1; // 64 for signature size, 16 for key hash, 8 for exp, 2 for nonce, 1 for payload header
|
||||
|
||||
public static Payload read (
|
||||
byte[] msg,
|
||||
DataInputStream input
|
||||
) throws IOException {
|
||||
final int replacementMsgBytes = input.readUnsignedByte();
|
||||
final boolean isCompressed = replacementMsgBytes != 0;
|
||||
if (isCompressed) {
|
||||
msg = new byte[replacementMsgBytes];
|
||||
input.readFully(msg);
|
||||
}
|
||||
final byte[] signature = new byte[64];
|
||||
input.readFully(signature);
|
||||
final byte[] keyHash = new byte[16];
|
||||
input.readFully(keyHash);
|
||||
final byte[] nonce = new byte[2];
|
||||
input.readFully(nonce);
|
||||
return new Payload(
|
||||
msg,
|
||||
signature,
|
||||
keyHash,
|
||||
nonce,
|
||||
input.readLong(),
|
||||
isCompressed
|
||||
);
|
||||
}
|
||||
|
||||
public static byte[] withAdditionalData (
|
||||
byte[] msg,
|
||||
byte[] nonce,
|
||||
long exp
|
||||
) {
|
||||
final byte[] msgWithNonceAndExp = new byte[msg.length + 2 + 8];
|
||||
System.arraycopy(
|
||||
nonce,
|
||||
0,
|
||||
msgWithNonceAndExp,
|
||||
0,
|
||||
2
|
||||
);
|
||||
System.arraycopy(
|
||||
Longs.toByteArray(exp),
|
||||
0,
|
||||
msgWithNonceAndExp,
|
||||
2,
|
||||
8
|
||||
);
|
||||
System.arraycopy(
|
||||
msg,
|
||||
0,
|
||||
msgWithNonceAndExp,
|
||||
2 + 8,
|
||||
msg.length
|
||||
);
|
||||
return msgWithNonceAndExp;
|
||||
}
|
||||
|
||||
public static boolean write (
|
||||
byte[] msg,
|
||||
DataOutput output
|
||||
) throws IOException {
|
||||
final boolean compressed = msg.length > ORIGINAL_MSG_BUDGET || ConfigurationManager.INSTANCE.config.forceCompress;
|
||||
|
||||
if (compressed) {
|
||||
final var out = new ByteArrayOutputStream();
|
||||
final var cmp = new ZstdCompressorOutputStream(out);
|
||||
cmp.write(msg);
|
||||
cmp.flush();
|
||||
cmp.close();
|
||||
msg = out.toByteArray();
|
||||
}
|
||||
|
||||
output.writeByte(compressed ?
|
||||
msg.length :
|
||||
0);
|
||||
if (compressed)
|
||||
output.write(msg);
|
||||
final byte[] nonce = new byte[2];
|
||||
ThreadLocalRandom
|
||||
.current()
|
||||
.nextBytes(nonce);
|
||||
final long exp = System.currentTimeMillis() + PERIOD;
|
||||
msg = withAdditionalData(
|
||||
msg,
|
||||
nonce,
|
||||
exp
|
||||
);
|
||||
final var signature = SigningManager.INSTANCE.createSignature(msg);
|
||||
output.write(signature);
|
||||
output.write(SigningManager.INSTANCE.selfHash);
|
||||
output.write(nonce);
|
||||
output.writeLong(exp);
|
||||
return compressed;
|
||||
}
|
||||
|
||||
public String getReplacementMsg () throws IOException {
|
||||
if (!this.compressedMsg)
|
||||
return new String(
|
||||
this.msg,
|
||||
StandardCharsets.UTF_8
|
||||
);
|
||||
@SuppressWarnings("resource")
|
||||
final var in = new ZstdCompressorInputStream(new ByteArrayInputStream(this.msg));
|
||||
final var out = new ByteArrayOutputStream();
|
||||
|
||||
final byte[] buf = new byte[8192];
|
||||
int read;
|
||||
while ((read = in.read(buf)) != -1) {
|
||||
if (out.size() >= ConfigurationManager.INSTANCE.config.maxCompressedPayload)
|
||||
return new String(
|
||||
this.msg,
|
||||
StandardCharsets.UTF_8
|
||||
);
|
||||
|
||||
out.write(
|
||||
buf,
|
||||
0,
|
||||
read
|
||||
);
|
||||
}
|
||||
return out.toString(StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
+455
@@ -0,0 +1,455 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.KeyManifest;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.config.ConfigurationManager;
|
||||
import net.jodah.expiringmap.ExpiringMap;
|
||||
import org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters;
|
||||
import org.bouncycastle.crypto.params.Ed25519PublicKeyParameters;
|
||||
import org.bouncycastle.crypto.util.PrivateKeyFactory;
|
||||
import org.bouncycastle.crypto.util.PrivateKeyInfoFactory;
|
||||
import org.bouncycastle.math.ec.rfc8032.Ed25519;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.locks.StampedLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.Constants.*;
|
||||
|
||||
public final class SigningManager {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(SigningManager.class);
|
||||
public static final SigningManager INSTANCE = new SigningManager();
|
||||
public static final long PERIOD = 10_000L;
|
||||
public final byte[] selfHash;
|
||||
private final ExecutorService requestExecutor = Executors.newCachedThreadPool();
|
||||
private final StampedLock lock = new StampedLock();
|
||||
private final Map<String, KeyManifest> manifests;
|
||||
private final Set<String> nicks = new HashSet<>();
|
||||
private final Map<WrappedByteArray, LoadedKey> hashToKey = new HashMap<>();
|
||||
private final Map<Long, Set<WrappedByteArray>> usedSignatureMap = ExpiringMap
|
||||
.builder()
|
||||
.expiration(
|
||||
PERIOD,
|
||||
TimeUnit.MILLISECONDS
|
||||
)
|
||||
.build();
|
||||
private final Ed25519PrivateKeyParameters selfKey;
|
||||
private final Path cachePath;
|
||||
|
||||
public SigningManager () {
|
||||
this.cachePath = storageDir
|
||||
.resolve("data")
|
||||
.resolve("chatattestation-cache.json");
|
||||
|
||||
final var cacheParent = this.cachePath.getParent();
|
||||
final boolean orphan = Files.notExists(cacheParent);
|
||||
|
||||
try {
|
||||
if (orphan) {
|
||||
LOGGER.info("Creating Chat Attestation folder");
|
||||
Files.createDirectories(cacheParent);
|
||||
}
|
||||
|
||||
if (orphan || Files.notExists(this.cachePath)) {
|
||||
this.manifests = new HashMap<>();
|
||||
} else {
|
||||
this.manifests = GSON.fromJson(
|
||||
Files.newBufferedReader(this.cachePath),
|
||||
new TypeToken<>() {
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(
|
||||
"Failed to initialize cache",
|
||||
e
|
||||
);
|
||||
}
|
||||
|
||||
final var legacyKeyPath = storageDir.resolve("chatattestation.key");
|
||||
final var keyPath = storageDir.resolve("chatattestation.priv.key");
|
||||
|
||||
if (Files.exists(legacyKeyPath)) {
|
||||
try {
|
||||
Files.move(
|
||||
legacyKeyPath,
|
||||
keyPath
|
||||
);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Failed to rename legacy key path");
|
||||
}
|
||||
}
|
||||
|
||||
if (Files.notExists(keyPath)) {
|
||||
try {
|
||||
this.selfKey = new Ed25519PrivateKeyParameters(SecureRandom.getInstanceStrong());
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new IllegalArgumentException(
|
||||
"JVM does not provide strong secure random impl",
|
||||
e
|
||||
);
|
||||
}
|
||||
|
||||
this.savePrivateKey(keyPath);
|
||||
} else {
|
||||
final byte[] keyData;
|
||||
|
||||
try {
|
||||
keyData = Files.readAllBytes(keyPath);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(
|
||||
"Failed to load stored private key",
|
||||
e
|
||||
);
|
||||
}
|
||||
if (keyData.length == 32) {
|
||||
this.selfKey = new Ed25519PrivateKeyParameters(keyData);
|
||||
this.savePrivateKey(keyPath);
|
||||
} else {
|
||||
final var extractedData = Base64
|
||||
.getDecoder()
|
||||
.decode(new String(
|
||||
keyData,
|
||||
StandardCharsets.UTF_8
|
||||
)
|
||||
.lines()
|
||||
.filter(l -> !l.startsWith("-"))
|
||||
.map(String::trim)
|
||||
.collect(Collectors.joining()));
|
||||
|
||||
try {
|
||||
this.selfKey = (Ed25519PrivateKeyParameters) PrivateKeyFactory.createKey(extractedData);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid private key",
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
/* LOGGER.info(
|
||||
"Encoded public key: {}",
|
||||
Base64.getEncoder().encodeToString(this.selfKey.generatePublicKey().getEncoded())
|
||||
);*/
|
||||
}
|
||||
|
||||
final var encodedPublicKey = this.selfKey
|
||||
.generatePublicKey()
|
||||
.getEncoded();
|
||||
this.selfHash = createHash(encodedPublicKey);
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
final var scheduler = Executors.newSingleThreadScheduledExecutor(DAEMON_THREAD_FACTORY);
|
||||
scheduler.scheduleAtFixedRate(
|
||||
this::refetchKeys,
|
||||
0,
|
||||
1,
|
||||
TimeUnit.MINUTES
|
||||
);
|
||||
}
|
||||
|
||||
public static void init () {
|
||||
|
||||
}
|
||||
|
||||
public static byte[] createHash (byte[] input) {
|
||||
final MessageDigest messageDigest;
|
||||
try {
|
||||
messageDigest = MessageDigest.getInstance("SHA3-224");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new IllegalStateException(
|
||||
"JVM does not have SHA3-224 support",
|
||||
e
|
||||
);
|
||||
}
|
||||
|
||||
return Arrays.copyOfRange(
|
||||
messageDigest.digest(input),
|
||||
0,
|
||||
16
|
||||
);
|
||||
}
|
||||
|
||||
private static long getCurrentPeriod () {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void savePrivateKey (Path keyPath) {
|
||||
try (final var out = Files.newBufferedWriter(keyPath)) {
|
||||
out.write("-----BEGIN PRIVATE KEY-----\n");
|
||||
|
||||
final var encoded = Base64
|
||||
.getEncoder()
|
||||
.encodeToString(PrivateKeyInfoFactory
|
||||
.createPrivateKeyInfo(this.selfKey)
|
||||
.getEncoded());
|
||||
out.write(encoded);
|
||||
out.write("\n-----END PRIVATE KEY-----");
|
||||
out.flush();
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(
|
||||
"Failed to save private key",
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private CompletableFuture<KeyManifest> refetchManifest (String url) {
|
||||
return CompletableFuture.supplyAsync(
|
||||
() -> {
|
||||
try (
|
||||
final var client = HttpClient
|
||||
.newBuilder()
|
||||
.connectTimeout(Duration.ofSeconds(30))
|
||||
.build()
|
||||
) {
|
||||
final var request = client.send(
|
||||
HttpRequest
|
||||
.newBuilder(URI.create(url))
|
||||
.GET()
|
||||
.build(),
|
||||
HttpResponse.BodyHandlers.ofString()
|
||||
);
|
||||
|
||||
return GSON.fromJson(
|
||||
request.body(),
|
||||
KeyManifest.class
|
||||
);
|
||||
} catch (Exception e) {
|
||||
throw new CompletionException(
|
||||
"Failed to fetch manifest",
|
||||
e
|
||||
);
|
||||
}
|
||||
},
|
||||
this.requestExecutor
|
||||
);
|
||||
}
|
||||
|
||||
public void refetchKeys () {
|
||||
final var futures = ConfigurationManager.INSTANCE.config.keyManifestUrls
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
url -> url,
|
||||
this::refetchManifest
|
||||
));
|
||||
|
||||
for (final var futureEntry : futures.entrySet()) {
|
||||
final String manifest = futureEntry.getKey();
|
||||
|
||||
try {
|
||||
this.manifests.put(
|
||||
manifest,
|
||||
futureEntry
|
||||
.getValue()
|
||||
.join()
|
||||
);
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn(
|
||||
"Fetching {} failed, cache will be used if present",
|
||||
manifest,
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
try (final var writer = Files.newBufferedWriter(this.cachePath)) {
|
||||
GSON.toJson(
|
||||
this.manifests,
|
||||
writer
|
||||
);
|
||||
writer.flush();
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn(
|
||||
"Failed to save manifest cache",
|
||||
e
|
||||
);
|
||||
}
|
||||
|
||||
this.reloadKeys();
|
||||
}
|
||||
|
||||
private void reloadKeys () {
|
||||
final long writeLock = this.lock.writeLock();
|
||||
|
||||
try {
|
||||
this.hashToKey.clear();
|
||||
this.nicks.clear();
|
||||
|
||||
for (final var entry : this.manifests.entrySet()) {
|
||||
final var manifestUrl = entry.getKey();
|
||||
|
||||
for (final var keyToClaim : entry
|
||||
.getValue()
|
||||
.keyToClaims()
|
||||
.entrySet()) {
|
||||
final var rawKey = Base64
|
||||
.getDecoder()
|
||||
.decode(keyToClaim.getKey());
|
||||
final var loadedKey = this.hashToKey.computeIfAbsent(
|
||||
new WrappedByteArray(createHash(rawKey)),
|
||||
k -> new LoadedKey(
|
||||
new Ed25519PublicKeyParameters(rawKey),
|
||||
new HashMap<>()
|
||||
)
|
||||
);
|
||||
|
||||
final var keyClaims = keyToClaim.getValue();
|
||||
final var claims = loadedKey.manifestUrlToClaims.computeIfAbsent(
|
||||
manifestUrl,
|
||||
k -> new HashSet<>()
|
||||
);
|
||||
claims.addAll(keyClaims);
|
||||
|
||||
for (final var claim : keyClaims)
|
||||
this.nicks.add(claim.toLowerCase());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
this.lock.unlockWrite(writeLock);
|
||||
}
|
||||
}
|
||||
|
||||
public Response verifyClaim (
|
||||
byte[] msg,
|
||||
byte[] sig,
|
||||
byte[] key,
|
||||
long exp
|
||||
) {
|
||||
if (System.currentTimeMillis() > exp)
|
||||
return Response.ReusedSignature.INSTANCE;
|
||||
|
||||
final long readLock = this.lock.readLock();
|
||||
|
||||
try {
|
||||
final var usedSignatures = this.usedSignatureMap.computeIfAbsent(
|
||||
getCurrentPeriod(),
|
||||
k -> new HashSet<>()
|
||||
);
|
||||
final var wrappedSig = new WrappedByteArray(sig);
|
||||
if (usedSignatures.contains(wrappedSig))
|
||||
return Response.ReusedSignature.INSTANCE;
|
||||
final var wrappedKey = new WrappedByteArray(key);
|
||||
final var loadedKey = this.hashToKey.get(wrappedKey);
|
||||
if (loadedKey == null)
|
||||
return Response.NoSuchKey.INSTANCE;
|
||||
|
||||
if (!loadedKey.bc.verify(
|
||||
Ed25519.Algorithm.Ed25519,
|
||||
null,
|
||||
msg,
|
||||
0,
|
||||
msg.length,
|
||||
sig,
|
||||
0
|
||||
))
|
||||
return Response.InvalidSignature.INSTANCE;
|
||||
|
||||
usedSignatures.add(wrappedSig);
|
||||
return new Response.SignatureValid(loadedKey);
|
||||
} finally {
|
||||
this.lock.unlockRead(readLock);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean doesNickRequireSignature (String nick) {
|
||||
return this.nicks.contains(nick.toLowerCase());
|
||||
}
|
||||
|
||||
public byte[] createSignature (byte[] msg) {
|
||||
final byte[] signature = new byte[64];
|
||||
this.selfKey.sign(
|
||||
Ed25519.Algorithm.Ed25519,
|
||||
null,
|
||||
msg,
|
||||
0,
|
||||
msg.length,
|
||||
signature,
|
||||
0
|
||||
);
|
||||
return signature;
|
||||
}
|
||||
|
||||
public sealed interface Response {
|
||||
final class NoSuchKey implements Response {
|
||||
public static final NoSuchKey INSTANCE = new NoSuchKey();
|
||||
|
||||
private NoSuchKey () {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
final class InvalidSignature implements Response {
|
||||
public static final InvalidSignature INSTANCE = new InvalidSignature();
|
||||
|
||||
private InvalidSignature () {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
final class ReusedSignature implements Response {
|
||||
public static final ReusedSignature INSTANCE = new ReusedSignature();
|
||||
|
||||
private ReusedSignature () {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
record SignatureValid(LoadedKey key) implements Response {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static final class WrappedByteArray {
|
||||
private final byte[] arr;
|
||||
|
||||
public WrappedByteArray (byte @Unmodifiable [] arr) {
|
||||
this.arr = arr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString () {
|
||||
return HexFormat
|
||||
.of()
|
||||
.formatHex(this.arr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode () {
|
||||
return Arrays.hashCode(this.arr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals (Object obj) {
|
||||
return obj instanceof final WrappedByteArray wrappedByteArray && Arrays.equals(
|
||||
wrappedByteArray.arr,
|
||||
this.arr
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public record LoadedKey(
|
||||
Ed25519PublicKeyParameters bc,
|
||||
Map<String, Set<String>> manifestUrlToClaims
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.enums;
|
||||
|
||||
public enum SigningStatus {
|
||||
NO_PAYLOAD,
|
||||
NEEDS_SIGNATURE,
|
||||
INVALID_SIGNATURE,
|
||||
NO_SUCH_KEY,
|
||||
REUSED_SIGNATURE,
|
||||
VERIFIED, // authenticated via manifest
|
||||
VALID_UNVERIFIED // valid sig, but key not authorized for nick
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public final class ChatEncoding {
|
||||
public static final int[] ENCODING;
|
||||
public static final int[] DECODING;
|
||||
|
||||
static {
|
||||
ENCODING = IntStream
|
||||
.concat(
|
||||
IntStream.range(
|
||||
0x21,
|
||||
0x7E
|
||||
),
|
||||
IntStream.range(
|
||||
0xA1,
|
||||
0x010000
|
||||
)
|
||||
)
|
||||
.filter(c -> c != '&' && c != '§')
|
||||
.limit(256)
|
||||
.toArray();
|
||||
|
||||
final int max = Arrays
|
||||
.stream(ENCODING)
|
||||
.max()
|
||||
.orElseThrow();
|
||||
DECODING = new int[max + 1];
|
||||
Arrays.fill(
|
||||
DECODING,
|
||||
-1
|
||||
);
|
||||
|
||||
for (int i = 0; i < ENCODING.length; i++) {
|
||||
DECODING[ENCODING[i]] = i;
|
||||
}
|
||||
}
|
||||
|
||||
public static String encode (byte[] input) {
|
||||
final var builder = new StringBuilder(input.length);
|
||||
|
||||
for (final byte b : input) {
|
||||
builder.appendCodePoint(ENCODING[(int) b & 0xFF]);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static byte @Nullable [] decode (String input) {
|
||||
final var out = new ByteArrayOutputStream();
|
||||
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
final var ch = input.codePointAt(i);
|
||||
if (ch < 0 || ch >= DECODING.length)
|
||||
return null;
|
||||
final int b = DECODING[ch];
|
||||
if (b == -1)
|
||||
return null;
|
||||
out.write(b);
|
||||
}
|
||||
|
||||
return out.toByteArray();
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class Constants {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("chatattestation");
|
||||
public static final Gson GSON = new GsonBuilder()
|
||||
.setPrettyPrinting()
|
||||
.create();
|
||||
public static final Pattern SIGNED_MESSAGE_PATTERN = Pattern.compile("\\$\\$(.*)\\$\\$(.*)$");
|
||||
public static final ThreadFactory DAEMON_THREAD_FACTORY = r -> {
|
||||
final var t = new Thread(r);
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
};
|
||||
public static final int MESSAGE_LIMIT = 256;
|
||||
public static final ExecutorService SIGN_EXECUTOR = Executors.newSingleThreadExecutor();
|
||||
public static final Path storageDir = Path.of("chatattestation");
|
||||
|
||||
private Constants () {
|
||||
|
||||
}
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util;
|
||||
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class ListeningList<T> implements List<T> {
|
||||
private final Consumer<T> listener;
|
||||
private final List<T> handle;
|
||||
|
||||
public ListeningList (
|
||||
Consumer<T> listener,
|
||||
List<T> handle
|
||||
) {
|
||||
this.listener = listener;
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size () {
|
||||
return this.handle.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty () {
|
||||
return this.handle.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains (Object o) {
|
||||
return this.handle.contains(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Iterator<T> iterator () {
|
||||
return this.handle.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Object @NonNull [] toArray () {
|
||||
return this.handle.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull <T1> T1 @NonNull [] toArray (@NonNull T1 @NonNull [] a) {
|
||||
return this.handle.toArray(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add (T t) {
|
||||
this.listener.accept(t);
|
||||
return this.handle.add(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove (Object o) {
|
||||
return this.handle.remove(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll (@NonNull Collection<?> c) {
|
||||
//noinspection SlowListContainsAll
|
||||
return this.handle.containsAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll (@NonNull Collection<? extends T> c) {
|
||||
c.forEach(this.listener);
|
||||
return this.handle.addAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll (
|
||||
int index,
|
||||
@NonNull Collection<? extends T> c
|
||||
) {
|
||||
c.forEach(this.listener);
|
||||
return this.handle.addAll(
|
||||
index,
|
||||
c
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll (@NonNull Collection<?> c) {
|
||||
return this.handle.removeAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll (@NonNull Collection<?> c) {
|
||||
return this.handle.retainAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear () {
|
||||
this.handle.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get (int index) {
|
||||
return this.handle.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T set (
|
||||
int index,
|
||||
T element
|
||||
) {
|
||||
this.listener.accept(element);
|
||||
return this.handle.set(
|
||||
index,
|
||||
element
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add (
|
||||
int index,
|
||||
T element
|
||||
) {
|
||||
this.listener.accept(element);
|
||||
this.handle.add(
|
||||
index,
|
||||
element
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove (int index) {
|
||||
return this.handle.remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf (Object o) {
|
||||
return this.handle.indexOf(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf (Object o) {
|
||||
return this.handle.lastIndexOf(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ListIterator<T> listIterator () {
|
||||
return this.handle.listIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ListIterator<T> listIterator (int index) {
|
||||
return this.handle.listIterator(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<T> subList (
|
||||
int fromIndex,
|
||||
int toIndex
|
||||
) {
|
||||
return this.handle.subList(
|
||||
fromIndex,
|
||||
toIndex
|
||||
);
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.Normalizer;
|
||||
import java.util.Arrays;
|
||||
import java.util.HexFormat;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class NormalizationUtil {
|
||||
private static final int[] CONFUSABLES;
|
||||
|
||||
static {
|
||||
int[] confusables = new int[0];
|
||||
final String read;
|
||||
final var resourceStream = Objects.requireNonNull(NormalizationUtil.class
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("confusables.txt"));
|
||||
|
||||
try {
|
||||
read = new String(
|
||||
resourceStream.readAllBytes(),
|
||||
StandardCharsets.UTF_8
|
||||
);
|
||||
resourceStream.close();
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Failed to read confusables list",
|
||||
e
|
||||
);
|
||||
}
|
||||
|
||||
final var hexFormat = HexFormat.of();
|
||||
final var lines = read
|
||||
.lines()
|
||||
.iterator();
|
||||
while (lines.hasNext()) {
|
||||
var line = lines.next();
|
||||
if (line.startsWith("#"))
|
||||
continue;
|
||||
final var split = line.split(";");
|
||||
if (split.length < 2)
|
||||
continue;
|
||||
final int confusable = intFromByteArrayWithPadding(hexFormat.parseHex(padHex(split[0].trim())));
|
||||
if (confusable <= 127)
|
||||
continue;
|
||||
final var replacement = split[1].trim();
|
||||
if (replacement.split(" ").length != 1)
|
||||
continue;
|
||||
final int replacementCodepoint = intFromByteArrayWithPadding(hexFormat.parseHex(padHex(replacement)));
|
||||
if (replacementCodepoint > 127)
|
||||
continue;
|
||||
if (confusables.length <= confusable) {
|
||||
int[] newConfusables = new int[confusable + 1];
|
||||
Arrays.fill(
|
||||
newConfusables,
|
||||
Integer.MIN_VALUE
|
||||
);
|
||||
System.arraycopy(
|
||||
confusables,
|
||||
0,
|
||||
newConfusables,
|
||||
0,
|
||||
confusables.length
|
||||
);
|
||||
confusables = newConfusables;
|
||||
}
|
||||
|
||||
confusables[confusable] = replacementCodepoint;
|
||||
}
|
||||
|
||||
CONFUSABLES = confusables;
|
||||
}
|
||||
|
||||
private static String padHex (String input) {
|
||||
if (input.length() % 2 != 0)
|
||||
return "0" + input;
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
private static int intFromByteArrayWithPadding (byte[] buf) {
|
||||
if (buf.length != 4) {
|
||||
final byte[] intermediate = new byte[4];
|
||||
System.arraycopy(
|
||||
buf,
|
||||
0,
|
||||
intermediate,
|
||||
4 - buf.length,
|
||||
buf.length
|
||||
);
|
||||
buf = intermediate;
|
||||
}
|
||||
|
||||
return Ints.fromByteArray(buf);
|
||||
}
|
||||
|
||||
public static String normalizeString (String input) {
|
||||
input = Normalizer.normalize(
|
||||
input,
|
||||
Normalizer.Form.NFKC
|
||||
);
|
||||
final var output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
final int codepoint = input.codePointAt(i);
|
||||
final int replacement;
|
||||
if (CONFUSABLES.length <= codepoint || (replacement = CONFUSABLES[codepoint]) == Integer.MIN_VALUE)
|
||||
output.appendCodePoint(codepoint);
|
||||
else {
|
||||
output.appendCodePoint(replacement);
|
||||
}
|
||||
}
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.enums.SigningStatus;
|
||||
|
||||
public record SigningResult(
|
||||
SigningStatus status,
|
||||
String encodedKey
|
||||
) {
|
||||
public static SigningResult of (SigningStatus status) {
|
||||
return new SigningResult(
|
||||
status,
|
||||
null
|
||||
);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.config.ConfigurationManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class Util {
|
||||
private static final Pattern EXTRACTOR = Pattern.compile("^<?([^:<>]*)[>:] (.*)$");
|
||||
private static final Pattern CHIPMUNK_EXTRACTOR = Pattern.compile("^\\[.*] ([^›]*) › (.*)$");
|
||||
|
||||
private Util () {
|
||||
|
||||
}
|
||||
|
||||
public static @Nullable String extractDisguisedContent (String fullMsg) {
|
||||
final var matcher = EXTRACTOR.matcher(fullMsg);
|
||||
return matcher.matches() ?
|
||||
matcher.group(2) :
|
||||
null;
|
||||
}
|
||||
|
||||
public static @Nullable SystemExtraction extractSystemContent (String msg) {
|
||||
final var chipmunkMatcher = CHIPMUNK_EXTRACTOR.matcher(msg);
|
||||
if (chipmunkMatcher.matches()) {
|
||||
return new SystemExtraction(
|
||||
chipmunkMatcher.group(1),
|
||||
chipmunkMatcher.group(2)
|
||||
);
|
||||
} else {
|
||||
final var regularExtractor = EXTRACTOR.matcher(msg);
|
||||
if (!regularExtractor.matches())
|
||||
return null;
|
||||
// TODO: Handle spaces in names.
|
||||
final var sender = regularExtractor
|
||||
.group(1)
|
||||
.split(" ");
|
||||
if (sender.length == 1 && ConfigurationManager.INSTANCE.config.ignoreCspyLike)
|
||||
return null;
|
||||
return new SystemExtraction(
|
||||
sender[sender.length - 1],
|
||||
regularExtractor.group(2)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public record SystemExtraction(
|
||||
String sender,
|
||||
String content
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatparsers;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.ChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.ParseChatData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.PlayerMessageData;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class KaboomChatParser implements ParseChatData {
|
||||
private static final Component SEPERATOR_COLON = Component.text(":");
|
||||
private static final Component SEPERATOR_COLON_RACCOON = Component.text("§f:"); // https://github.com/raccoonserver/extras/commit/315f704075db2f00e3e1bfbf55f858469c22880f
|
||||
private static final Component SEPERATOR_SPACE = Component.space();
|
||||
private final NitoriBot bot;
|
||||
|
||||
public KaboomChatParser (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerMessageData parse (
|
||||
ChatType chatType,
|
||||
Component message
|
||||
) {
|
||||
if (message instanceof TextComponent)
|
||||
return parse(
|
||||
chatType,
|
||||
(TextComponent) message
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
public PlayerMessageData parse (
|
||||
ChatType chatType,
|
||||
TextComponent message
|
||||
) {
|
||||
List<Component> children = message.children();
|
||||
|
||||
if (!message
|
||||
.content()
|
||||
.isEmpty() || !message
|
||||
.style()
|
||||
.isEmpty() || children.size() < 3)
|
||||
return null;
|
||||
|
||||
final Component prefix = children.getFirst();
|
||||
Component displayName = Component.empty();
|
||||
Component contents = Component.empty();
|
||||
|
||||
if (isSeperatorAt(
|
||||
children,
|
||||
1
|
||||
)) { // Missing/blank display name
|
||||
if (children.size() > 3)
|
||||
contents = children.get(3);
|
||||
} else if (isSeperatorAt(
|
||||
children,
|
||||
2
|
||||
)) {
|
||||
displayName = children.get(1);
|
||||
if (children.size() > 4)
|
||||
contents = children.get(4);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
PlayerProfileData sender = bot.players.getDisplayName(Component
|
||||
.empty()
|
||||
.append(prefix)
|
||||
.append(displayName));
|
||||
return new PlayerMessageData(
|
||||
sender,
|
||||
contents,
|
||||
chatType,
|
||||
displayName
|
||||
);
|
||||
}
|
||||
|
||||
private boolean isSeperatorAt (
|
||||
List<Component> children,
|
||||
int start
|
||||
) {
|
||||
return (
|
||||
children
|
||||
.get(start)
|
||||
.equals(SEPERATOR_COLON) || children
|
||||
.get(start)
|
||||
.equals(SEPERATOR_COLON_RACCOON)
|
||||
) && children
|
||||
.get(start + 1)
|
||||
.equals(SEPERATOR_SPACE);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.command;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
|
||||
public record CommandContext(
|
||||
NitoriBot bot,
|
||||
String[] args,
|
||||
CommandSource source
|
||||
) {
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.command;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class CommandError extends Exception {
|
||||
public final Component message;
|
||||
|
||||
public CommandError (Component message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Component message () {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.command;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CommandInfo {
|
||||
CommandTrustLevels getTrustLevel ();
|
||||
|
||||
List<String> getAliases ();
|
||||
|
||||
String getDescription ();
|
||||
|
||||
List<String> getUsages ();
|
||||
|
||||
Component execute (CommandContext context) throws CommandError;
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.command;
|
||||
|
||||
public enum CommandMessageSource {
|
||||
DISCORD,
|
||||
CONSOLE,
|
||||
INGAME
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.command;
|
||||
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.ChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.ParsedChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.componentToAnsi;
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public record CommandSource(
|
||||
PlayerProfileData sender,
|
||||
MessageReceivedEvent discordEvent,
|
||||
CommandMessageSource source,
|
||||
ChatType chatType,
|
||||
ParsedChatType parsedChatType
|
||||
) {
|
||||
public void sendFeedback (
|
||||
NitoriBot bot,
|
||||
Component component
|
||||
) {
|
||||
switch (source) {
|
||||
case CommandMessageSource.INGAME -> {
|
||||
final String selector = String.format(
|
||||
"@p[nbt={UUID:uuid(\"%s\")}]",
|
||||
sender.uuid
|
||||
);
|
||||
|
||||
if (parsedChatType() == ParsedChatType.COMMANDSPY)
|
||||
bot.chat.tellraw(
|
||||
selector,
|
||||
component
|
||||
);
|
||||
else
|
||||
bot.chat.tellraw(
|
||||
"@a",
|
||||
component
|
||||
);
|
||||
}
|
||||
case CommandMessageSource.DISCORD -> {
|
||||
final String message = "```ansi\n" + componentToAnsi(component) + "\n```";
|
||||
discordEvent
|
||||
.getMessage()
|
||||
.reply(message)
|
||||
.queue();
|
||||
}
|
||||
case CommandMessageSource.CONSOLE -> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.command;
|
||||
|
||||
public enum CommandTrustLevels {
|
||||
PUBLIC(0),
|
||||
TRUSTED(1),
|
||||
ADMIN(2),
|
||||
OWNER(3),
|
||||
CONSOLE(4),
|
||||
DISABLED(-1);
|
||||
|
||||
private final int level;
|
||||
|
||||
private CommandTrustLevels (int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public int level () {
|
||||
return level;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
private final int level;
|
||||
|
||||
private Level(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public int level() {
|
||||
return level;
|
||||
}
|
||||
*/
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandTrustLevels;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class CoreCommand implements CommandInfo {
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of(
|
||||
"core",
|
||||
"cb",
|
||||
"corerun"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "run commands in the bots core";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return List.of("<command>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) {
|
||||
NitoriBot bot = context.bot();
|
||||
CommandSource source = context.source();
|
||||
String message = String.join(
|
||||
" ",
|
||||
context.args()
|
||||
);
|
||||
|
||||
|
||||
if (message.contains("@username") || message.contains("@uuid")) {
|
||||
for (PlayerProfileData player : bot.players.list) {
|
||||
|
||||
bot.core
|
||||
.runTrackedWithPacket(message
|
||||
.replaceAll(
|
||||
"\\s+@username",
|
||||
" " + player.profile.getName()
|
||||
)
|
||||
.replaceAll(
|
||||
"\\s+@uuid",
|
||||
" " + player.profile.getIdAsString()
|
||||
))
|
||||
.thenAccept(reply -> {
|
||||
if (reply == null)
|
||||
return;
|
||||
source.sendFeedback(
|
||||
bot,
|
||||
reply
|
||||
);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
bot.core
|
||||
.runTrackedWithPacket(message)
|
||||
.thenAccept(reply -> {
|
||||
if (reply == null)
|
||||
return;
|
||||
source.sendFeedback(
|
||||
bot,
|
||||
reply
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandTrustLevels;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EchoCommand implements CommandInfo {
|
||||
public EchoCommand () {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of(
|
||||
"echo",
|
||||
"say"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "make the bot say something";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return List.of("<message>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) {
|
||||
NitoriBot bot = context.bot();
|
||||
String args = String.join(
|
||||
" ",
|
||||
context.args()
|
||||
);
|
||||
if (args.startsWith("/")) {
|
||||
bot.chat.command(args.substring("/".length()));
|
||||
} else {
|
||||
bot.chat.message(args);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandTrustLevels;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
|
||||
|
||||
public class HelpCommand implements CommandInfo {
|
||||
public HelpCommand () {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of(
|
||||
"help",
|
||||
"hell",
|
||||
"?",
|
||||
"heko",
|
||||
"cmds",
|
||||
"commands"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "see the list of commands the bot has";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return List.of("<command>");
|
||||
}
|
||||
|
||||
public Component getCommands (NitoriBot bot) {
|
||||
List<Component> Public = new ArrayList<>();
|
||||
List<Component> Trusted = new ArrayList<>();
|
||||
List<Component> Admin = new ArrayList<>();
|
||||
List<Component> Owner = new ArrayList<>();
|
||||
|
||||
for (CommandInfo commands : bot.commandManager.commands) {
|
||||
switch (commands.getTrustLevel()) {
|
||||
case CommandTrustLevels.PUBLIC -> Public.add(Component
|
||||
.text(commands
|
||||
.getAliases()
|
||||
.getFirst() + " ")
|
||||
.color(convertColorString(bot.config.colors.help.Public)));
|
||||
case CommandTrustLevels.TRUSTED -> Trusted.add(Component
|
||||
.text(commands
|
||||
.getAliases()
|
||||
.getFirst() + " ")
|
||||
.color(convertColorString(bot.config.colors.help.trusted)));
|
||||
case CommandTrustLevels.ADMIN -> Admin.add(Component.text(commands
|
||||
.getAliases()
|
||||
.getFirst() + " ").color(convertColorString(bot.config.colors.help.admin)));
|
||||
case CommandTrustLevels.OWNER -> Owner.add(Component
|
||||
.text(commands
|
||||
.getAliases()
|
||||
.getFirst() + " ")
|
||||
.color(convertColorString(bot.config.colors.help.owner)));
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Component
|
||||
.empty()
|
||||
.append(Public)
|
||||
.append(Component.text("\n"))
|
||||
.append(Trusted)
|
||||
.append(Component.text("\n"))
|
||||
.append(Owner);
|
||||
}
|
||||
|
||||
private Component getUsages (
|
||||
NitoriBot bot,
|
||||
List<String> usages
|
||||
) {
|
||||
Component component = null;
|
||||
if (usages == null)
|
||||
component = Component
|
||||
.empty()
|
||||
.append(Component
|
||||
.text("N/A")
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)));
|
||||
|
||||
else
|
||||
component = Component
|
||||
.empty()
|
||||
.append(Component
|
||||
.text(usages.toString())
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)))
|
||||
.color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
private Component getCommand (
|
||||
NitoriBot bot,
|
||||
String[] command
|
||||
) {
|
||||
Component component = null;
|
||||
|
||||
for (CommandInfo commands : bot.commandManager.commands) {
|
||||
for (String aliases : commands.getAliases()) {
|
||||
if (aliases.equals(command[0]))
|
||||
component = Component
|
||||
.translatable(
|
||||
"%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s",
|
||||
Component
|
||||
.text("Command")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(commands
|
||||
.getAliases()
|
||||
.getFirst())
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("Aliases")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(commands
|
||||
.getAliases()
|
||||
.toString())
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("Description")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(commands.getDescription())
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("Trust Level")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(commands
|
||||
.getTrustLevel()
|
||||
.toString())
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("Usages")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
getUsages(
|
||||
bot,
|
||||
commands.getUsages()
|
||||
)
|
||||
)
|
||||
.color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
}
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) {
|
||||
NitoriBot bot = context.bot();
|
||||
String[] args = context.args();
|
||||
CommandSource source = context.source();
|
||||
|
||||
if (args.length != 0) {
|
||||
// source.sendFeedback(bot, getCommand(bot, args));
|
||||
return getCommand(
|
||||
bot,
|
||||
args
|
||||
);
|
||||
}
|
||||
|
||||
Component helpLayout = Component.translatable(
|
||||
"%s: (%s) (%s | %s | %s | %s) ›\n",
|
||||
Component
|
||||
.text("Commands")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(String.valueOf(bot.commandManager.commands.size()))
|
||||
.color(convertColorString(bot.config.colors.integer)),
|
||||
Component
|
||||
.text("Public")
|
||||
.color(convertColorString(bot.config.colors.help.Public)),
|
||||
Component
|
||||
.text("Trusted")
|
||||
.color(convertColorString(bot.config.colors.help.trusted)),
|
||||
Component
|
||||
.text("Admin")
|
||||
.color(convertColorString(bot.config.colors.help.admin)),
|
||||
Component
|
||||
.text("Owner")
|
||||
.color(convertColorString(bot.config.colors.help.owner))
|
||||
);
|
||||
|
||||
Component component = Component
|
||||
.empty()
|
||||
.append(helpLayout)
|
||||
.append(Component.join(
|
||||
JoinConfiguration.separator(Component.space()),
|
||||
getCommands(bot)
|
||||
))
|
||||
.color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
|
||||
return component;
|
||||
}
|
||||
}
|
||||
+417
@@ -0,0 +1,417 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandError;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandTrustLevels;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.BotBuildInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.RepoCommitInfo;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.FormatTimeUtil.format;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import oshi.hardware.CentralProcessor;
|
||||
import oshi.hardware.HardwareAbstractionLayer;
|
||||
import oshi.spi.SystemInfoFactory;
|
||||
import oshi.spi.SystemInfoProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.MemoryUsage;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
|
||||
|
||||
public class InfoCommand implements CommandInfo {
|
||||
private final Enumeration<URL> resources = InfoCommand.class
|
||||
.getClassLoader()
|
||||
.getResources("META-INF/MANIFEST.MF");
|
||||
private final Manifest manifest = new Manifest(resources
|
||||
.nextElement()
|
||||
.openStream());
|
||||
private final Attributes attributes = manifest.getMainAttributes();
|
||||
private final String buildTime = attributes.getValue("Build-Time");
|
||||
private final String classPath = attributes.getValue("Main-Class");
|
||||
|
||||
public InfoCommand () throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of(
|
||||
"info",
|
||||
"information"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "see the bots info";
|
||||
}
|
||||
|
||||
public List<String> getUsages () {
|
||||
return List.of(
|
||||
"version",
|
||||
"loaded",
|
||||
"server",
|
||||
"about",
|
||||
"config",
|
||||
"credits",
|
||||
"contributors",
|
||||
"uptime"
|
||||
);
|
||||
}
|
||||
|
||||
private final SystemInfoProvider si = SystemInfoFactory.create();
|
||||
|
||||
private final long totalMemory = si
|
||||
.getHardware()
|
||||
.getMemory()
|
||||
.getTotal() / 1024 / 1024;
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) throws CommandError {
|
||||
var bot = context.bot();
|
||||
|
||||
final BotBuildInfo info = bot.botBuildInfo;
|
||||
|
||||
var args = context.args();
|
||||
|
||||
Component component = null;
|
||||
|
||||
GsonComponentSerializer gson = GsonComponentSerializer.gson();
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "discord" -> component = Component
|
||||
.empty()
|
||||
.append(Component.text("The discord invite is "))
|
||||
.append(Component
|
||||
.text(bot.config.discord.invite)
|
||||
.hoverEvent(HoverEvent.showText(Component
|
||||
.text("click here to join the discord server")
|
||||
.color(convertColorString(bot.config.colors.commands.primary))))
|
||||
.clickEvent(ClickEvent.openUrl(bot.config.discord.invite)))
|
||||
.color(convertColorString(bot.config.colors.commands.primary));
|
||||
|
||||
case "uptime" -> {
|
||||
final long uptime = ManagementFactory
|
||||
.getRuntimeMXBean()
|
||||
.getUptime() / 1000L;
|
||||
component = Component
|
||||
.text(format(uptime))
|
||||
.color(convertColorString(bot.config.colors.commands.primary));
|
||||
}
|
||||
|
||||
case "credits",
|
||||
"contributors" -> {
|
||||
List<Component> infoComponent = new ArrayList<>();
|
||||
|
||||
for (BotBuildInfo.Contributors contributors : bot.botBuildInfo.contributors) {
|
||||
infoComponent.add(Component
|
||||
.empty()
|
||||
.append(Component.translatable(
|
||||
"%s - %s",
|
||||
Component
|
||||
.text(contributors.name)
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(contributors.reason)
|
||||
.color(convertColorString(bot.config.colors.commands.secondary))
|
||||
))
|
||||
.color(convertColorString(bot.config.colors.commands.tertiary))
|
||||
.append(Component.newline()));
|
||||
}
|
||||
|
||||
component = Component
|
||||
.empty()
|
||||
.append(Component.translatable(
|
||||
"%s - %s",
|
||||
Component
|
||||
.text(bot.botBuildInfo.owner)
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text("Owner")
|
||||
.color(convertColorString(bot.config.colors.commands.secondary))
|
||||
))
|
||||
.append(Component.newline())
|
||||
.append(infoComponent)
|
||||
.color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
}
|
||||
|
||||
case "usage" -> {
|
||||
final Runtime runtime = Runtime.getRuntime();
|
||||
final long heapUsage = ManagementFactory
|
||||
.getMemoryMXBean()
|
||||
.getHeapMemoryUsage()
|
||||
.getUsed() / 1024 / 1024;
|
||||
final long heapMax = ManagementFactory
|
||||
.getMemoryMXBean()
|
||||
.getHeapMemoryUsage()
|
||||
.getMax() / 1024 / 1024;
|
||||
final long freeJVMMemory = runtime.freeMemory() / 1024 / 1024;
|
||||
final long maxJVMMemory = runtime.maxMemory() / 1024 / 1024;
|
||||
final long allocatedJVMMemory = runtime.totalMemory() / 1024 / 1024;
|
||||
final long usedJVMMemory = allocatedJVMMemory - freeJVMMemory;
|
||||
|
||||
component = Component
|
||||
.empty()
|
||||
.append(Component
|
||||
.text("Memory Usage: ")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)))
|
||||
.append(Component.translatable(
|
||||
"%s MB / %s MB",
|
||||
Component
|
||||
.text(usedJVMMemory)
|
||||
.color(convertColorString(bot.config.colors.integer)),
|
||||
Component
|
||||
.text(maxJVMMemory)
|
||||
.color(convertColorString(bot.config.colors.integer))
|
||||
))
|
||||
.color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
}
|
||||
|
||||
case "config" -> component = Component
|
||||
.empty()
|
||||
.append(Component.translatable(
|
||||
"%s: %s:%s",
|
||||
Component
|
||||
.text("Server")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(bot.options.host)
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text(bot.options.port)
|
||||
.color(convertColorString(bot.config.colors.commands.secondary))
|
||||
))
|
||||
.append(Component.newline())
|
||||
.append(Component.translatable(
|
||||
"%s: %s",
|
||||
Component
|
||||
.text("Server Name")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(bot.options.serverName)
|
||||
.color(convertColorString(bot.config.colors.commands.secondary))
|
||||
))
|
||||
.append(Component.newline())
|
||||
.append(Component.translatable(
|
||||
"%s: %s",
|
||||
Component
|
||||
.text("Minecraft Username")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(bot.options.username)
|
||||
.color(convertColorString(bot.config.colors.commands.secondary))
|
||||
))
|
||||
.append(Component.newline())
|
||||
.append(Component.translatable(
|
||||
"%s: %s",
|
||||
Component
|
||||
.text("Server Count")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(bot.bots.size())
|
||||
.color(convertColorString(bot.config.colors.integer))
|
||||
))
|
||||
.append(Component.newline())
|
||||
.append(Component.translatable(
|
||||
"%s: %s",
|
||||
Component
|
||||
.text("Prefixes")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(bot.config.prefixes.toString())
|
||||
.color(convertColorString(bot.config.colors.commands.secondary))
|
||||
))
|
||||
.color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
|
||||
|
||||
case "loaded" -> component = Component.translatable(
|
||||
"%s: %s\n%s: %s\n%s: %s",
|
||||
Component
|
||||
.text("Modules")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(bot.modules.size())
|
||||
.color(convertColorString(bot.config.colors.integer)),
|
||||
Component
|
||||
.text("Commands")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(bot.commandManager.commands.size())
|
||||
.color(convertColorString(bot.config.colors.integer)),
|
||||
Component
|
||||
.text("Chat Parsers")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(bot.chat.chatParsers.size())
|
||||
.color(convertColorString(bot.config.colors.integer))
|
||||
);
|
||||
|
||||
case "version" -> {
|
||||
RepoCommitInfo repoCommitInfo = bot.repoCommitInfo;
|
||||
|
||||
ZonedDateTime dateTime = ZonedDateTime.parse(repoCommitInfo.created);
|
||||
|
||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy hh:mm:ss a");
|
||||
|
||||
component = Component
|
||||
.translatable(
|
||||
"%s-%s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s",
|
||||
gson.deserialize(info.buildstring.botName.toString()),
|
||||
// Component.text(info.buildstring.version).color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
gson.deserialize(info.buildstring.codename.toString()),
|
||||
Component
|
||||
.text("Build")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(info.buildstring.build)
|
||||
.color(convertColorString(bot.config.colors.integer)),
|
||||
Component
|
||||
.text("Commit")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(repoCommitInfo.sha)
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("Version release Date")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(dateTime.format(dateTimeFormatter))
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("Initial Bot Release")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(info.buildstring.initialBotRelease)
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("Jar Compile Date")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(buildTime)
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("Main Class Path")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(classPath)
|
||||
.color(convertColorString(bot.config.colors.commands.secondary))
|
||||
)
|
||||
.color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
}
|
||||
|
||||
case "server" -> {
|
||||
try {
|
||||
final String osInfo = si
|
||||
.getOperatingSystem()
|
||||
.toString();
|
||||
final HardwareAbstractionLayer hardware = si.getHardware();
|
||||
final CentralProcessor cpuInfo = hardware.getProcessor();
|
||||
final String cpuName = cpuInfo
|
||||
.getProcessorIdentifier()
|
||||
.getName();
|
||||
final int cpuCores = cpuInfo.getPhysicalProcessorCount();
|
||||
final int processes = si
|
||||
.getOperatingSystem()
|
||||
.getProcessCount();
|
||||
|
||||
component = Component
|
||||
.translatable(
|
||||
"%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s",
|
||||
Component
|
||||
.text("Hostname")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(InetAddress
|
||||
.getLocalHost()
|
||||
.getHostName())
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("Username")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(System.getProperty("user.name"))
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("Directory")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(System.getProperty("user.dir"))
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("CPU Arch")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(System.getProperty("os.arch"))
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("OS")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(osInfo)
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("CPU")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(cpuName)
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("CPU Cores")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(cpuCores)
|
||||
.color(convertColorString(bot.config.colors.integer)),
|
||||
Component
|
||||
.text("Processes")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(processes)
|
||||
.color(convertColorString(bot.config.colors.integer)),
|
||||
Component
|
||||
.text("Java Version")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(System.getProperty("java.version"))
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("Total Memory")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(totalMemory + " MB")
|
||||
.color(convertColorString(bot.config.colors.commands.secondary))
|
||||
)
|
||||
.color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
case "about" -> component = Component
|
||||
.text(info.about)
|
||||
.color(convertColorString(bot.config.colors.commands.primary));
|
||||
|
||||
default -> throw new CommandError(Component.text("Unknown Argument"));
|
||||
}
|
||||
|
||||
return component;
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandTrustLevels;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
|
||||
|
||||
public class ListCommand implements CommandInfo {
|
||||
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of(
|
||||
"list",
|
||||
"pl",
|
||||
"playerlist"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "see the list of players";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) {
|
||||
NitoriBot bot = context.bot();
|
||||
CommandSource source = context.source();
|
||||
Component component = null;
|
||||
Component playerComponent = null;
|
||||
List<Component> playersComponent = new ArrayList<>();
|
||||
|
||||
playerComponent = Component
|
||||
.translatable(
|
||||
"%s: (%s)\n",
|
||||
Component
|
||||
.text("Players")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(bot.players.list.size())
|
||||
.color(convertColorString(bot.config.colors.integer))
|
||||
)
|
||||
.color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
|
||||
|
||||
for (PlayerProfileData player : bot.players.list) {
|
||||
//TranslatableComponent displayName = (TranslatableComponent) player.displayName();
|
||||
playersComponent.add(Component
|
||||
.translatable(
|
||||
"%s › %s",
|
||||
player.displayName.color(NamedTextColor.WHITE),
|
||||
Component
|
||||
.text(player.uuid.toString())
|
||||
.color(convertColorString(bot.config.colors.commands.secondary))
|
||||
)
|
||||
.color(convertColorString(bot.config.colors.commands.tertiary)));
|
||||
}
|
||||
|
||||
component = Component
|
||||
.empty()
|
||||
.append(playerComponent)
|
||||
.append(Component.join(
|
||||
JoinConfiguration.newlines(),
|
||||
playersComponent
|
||||
));
|
||||
|
||||
return Component
|
||||
.empty()
|
||||
.append(component);
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandTrustLevels;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PingServerData;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MCServerCommand implements CommandInfo {
|
||||
public MCServerCommand () {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of("mcserver");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "ping minecraft servers";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return List.of("<ip>:<port>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) {
|
||||
var bot = context.bot();
|
||||
var source = context.source();
|
||||
String args = String.join(
|
||||
" ",
|
||||
context.args()
|
||||
);
|
||||
Component component = null;
|
||||
|
||||
var ip = args.split(":");
|
||||
|
||||
List<PingServerData> infoList = bot.mcServer.pingServer(ip);
|
||||
|
||||
PingServerData info = infoList.getFirst();
|
||||
|
||||
component = Component
|
||||
.empty()
|
||||
.append(Component.translatable(
|
||||
"%s: %s:%s\n",
|
||||
Component
|
||||
.text("Server Ip")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(ip[0])
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text(ip[1])
|
||||
.color(convertColorString(bot.config.colors.commands.secondary))
|
||||
))
|
||||
.append(Component.translatable(
|
||||
"%s: %s/%s\n",
|
||||
Component
|
||||
.text("Players")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(info.playersOnline())
|
||||
.color(convertColorString(bot.config.colors.integer)),
|
||||
Component
|
||||
.text(info.maxPlayers())
|
||||
.color(convertColorString(bot.config.colors.integer))
|
||||
))
|
||||
.append(Component.translatable(
|
||||
"%s: %s\n",
|
||||
Component
|
||||
.text("Server Version")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(info.versionName())
|
||||
.color(convertColorString(bot.config.colors.commands.secondary))
|
||||
))
|
||||
.append(Component.translatable(
|
||||
"%s: %s\n",
|
||||
Component
|
||||
.text("Protocol Version")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(info.protocolVersion())
|
||||
.color(convertColorString(bot.config.colors.integer))
|
||||
))
|
||||
.append(Component.translatable(
|
||||
"%s: \n%s",
|
||||
Component
|
||||
.text("Description")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
info.description()
|
||||
))
|
||||
|
||||
.color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
|
||||
return component;
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.*;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NetmsgCommand implements CommandInfo {
|
||||
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of(
|
||||
"netmsg",
|
||||
"networkmessage"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "send a message to the servers the bot is connected to";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return List.of("<message>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) throws CommandError {
|
||||
final NitoriBot bot = context.bot();
|
||||
final String message = String
|
||||
.join(
|
||||
" ",
|
||||
context.args()
|
||||
)
|
||||
.replaceAll(
|
||||
".*nigger.*",
|
||||
"I love faggots, I love the gays"
|
||||
)
|
||||
.replaceAll(
|
||||
".*skid.*",
|
||||
"im a no life retarded piece of shit!"
|
||||
)
|
||||
.replaceAll(
|
||||
".*meow.*",
|
||||
":3"
|
||||
);
|
||||
final CommandSource source = context.source();
|
||||
|
||||
for (NitoriBot eachBot : bot.bots) {
|
||||
Component component = null;
|
||||
if (eachBot.options.isPrivate)
|
||||
component = Component
|
||||
.translatable(
|
||||
"[%s] %s › %s",
|
||||
Component
|
||||
.text(eachBot.options.serverName)
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
source.sender().displayName,
|
||||
Component.text(message)
|
||||
)
|
||||
.color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
|
||||
else
|
||||
component = Component
|
||||
.translatable(
|
||||
"[%s:%s] %s › %s",
|
||||
Component
|
||||
.text(bot.options.host)
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(bot.options.port)
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
source.sender().displayName,
|
||||
Component.text(message)
|
||||
)
|
||||
.color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
|
||||
eachBot.chat.tellraw(
|
||||
"@a",
|
||||
component
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandTrustLevels;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
|
||||
|
||||
public class PlayerInfoCommand implements CommandInfo {
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of(
|
||||
"playerinfo",
|
||||
"getplayer"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "get the info of a player";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return List.of(
|
||||
"<username>",
|
||||
"<uuid>"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) {
|
||||
NitoriBot bot = context.bot();
|
||||
String[] args = context.args();
|
||||
CommandSource source = context.source();
|
||||
Component component = null;
|
||||
|
||||
for (PlayerProfileData player : bot.players.list) {
|
||||
if (player.profile
|
||||
.getName()
|
||||
.equals(args[0]))
|
||||
component = Component
|
||||
.translatable(
|
||||
"%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s",
|
||||
Component
|
||||
.text("Player")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
player.displayName,
|
||||
Component
|
||||
.text("UUID")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(player.uuid.toString())
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("Position")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(player.position.toString())
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("Latency")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(player.latency + "ms")
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text("GameMode")
|
||||
.color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component
|
||||
.text(player.gameMode.toString())
|
||||
.color(convertColorString(bot.config.colors.commands.secondary))
|
||||
)
|
||||
.color(convertColorString(bot.config.colors.commands.tertiary));
|
||||
}
|
||||
|
||||
return component;
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandTrustLevels;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
|
||||
|
||||
public class RCCommand implements CommandInfo {
|
||||
public RCCommand () {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of(
|
||||
"rc",
|
||||
"refillcore"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "refill the bots core";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) {
|
||||
NitoriBot bot = context.bot();
|
||||
CommandSource source = context.source();
|
||||
|
||||
bot.core.move();
|
||||
|
||||
return Component
|
||||
.text("Refilling core")
|
||||
.color(convertColorString(bot.config.colors.commands.primary));
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.*;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.BetweenUtil.between;
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RTPCommand implements CommandInfo {
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of(
|
||||
"rtp",
|
||||
"tpr",
|
||||
"randomteleport"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "teleport to a random location";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) throws CommandError {
|
||||
final NitoriBot bot = context.bot();
|
||||
final CommandSource source = context.source();
|
||||
final double posX = between(
|
||||
-1_000_000,
|
||||
1_000_000
|
||||
);
|
||||
final double posY = between(
|
||||
-1_000_000,
|
||||
1_000_000
|
||||
);
|
||||
final double posZ = between(
|
||||
-1_000_000,
|
||||
1_000_000
|
||||
);
|
||||
|
||||
bot.core.run(String.format(
|
||||
"essentials:tp %s %s %s %s",
|
||||
source.sender().profile.getName(),
|
||||
posX,
|
||||
posY,
|
||||
posZ
|
||||
));
|
||||
|
||||
final Component component = Component
|
||||
.translatable(
|
||||
"teleporting %s to %s %s %s",
|
||||
Component
|
||||
.text(source.sender().profile.getName())
|
||||
.color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component
|
||||
.text(posX)
|
||||
.color(convertColorString(bot.config.colors.integer)),
|
||||
Component
|
||||
.text(posY)
|
||||
.color(convertColorString(bot.config.colors.integer)),
|
||||
Component
|
||||
.text(posZ)
|
||||
.color(convertColorString(bot.config.colors.integer))
|
||||
)
|
||||
.color(convertColorString(bot.config.colors.commands.primary));
|
||||
|
||||
return component;
|
||||
}
|
||||
}
|
||||
/*
|
||||
const x = between(-1_000_000, 1_000_000);
|
||||
const y = 100;
|
||||
const z = between(-1_000_000, 1_000_000);
|
||||
*/
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandTrustLevels;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.cloudburstmc.math.vector.Vector3i;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/*
|
||||
Adventure Minimessage is very fucking weird.....
|
||||
the fact it uses an HTML style with strings instead of components is very weird
|
||||
it also makes the JSON so fucking big especially with gradients
|
||||
this does remind me of how i did component.push shit in the JS build of my bot aka v8.0.0-Reignite
|
||||
*/
|
||||
public class TestCommand implements CommandInfo {
|
||||
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
|
||||
|
||||
public TestCommand () {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of("test");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "test cmd";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) {
|
||||
var bot = context.bot();
|
||||
String[] args = context.args();
|
||||
|
||||
var source = context.source();
|
||||
|
||||
Component component = Component.text(
|
||||
bot.registry.getBlockRegistry(
|
||||
String.join(
|
||||
" ",
|
||||
args
|
||||
)
|
||||
).toString()
|
||||
);
|
||||
return component;
|
||||
|
||||
// bot.world.getBlock(Vector3i.from(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2])));
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.admin;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandError;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandTrustLevels;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NetcmdCommand implements CommandInfo {
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.ADMIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of("netcmd");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "run a command within the bot on another server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) throws CommandError {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.owner;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.*;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class KillCommand implements CommandInfo {
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.OWNER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of(
|
||||
"kill",
|
||||
"kys",
|
||||
"stop"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "kills the bot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) throws CommandError {
|
||||
NitoriBot bot = context.bot();
|
||||
CommandSource source = context.source();
|
||||
|
||||
source.sendFeedback(
|
||||
bot,
|
||||
Component
|
||||
.text("Killing Bot Process")
|
||||
.color(convertColorString(bot.config.colors.commands.primary))
|
||||
);
|
||||
|
||||
System.exit(1);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.owner;
|
||||
|
||||
import jdk.jshell.*;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.*;
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.convertColorString;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ServerEvalCommand implements CommandInfo {
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.OWNER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of(
|
||||
"servereval",
|
||||
"se"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "eval code unisolated";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return List.of("<code>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) throws CommandError {
|
||||
final NitoriBot bot = context.bot();
|
||||
final CommandSource source = context.source();
|
||||
Component component = null;
|
||||
final String args = String.join(
|
||||
" ",
|
||||
context.args()
|
||||
);
|
||||
|
||||
final JShell jShell = JShell
|
||||
.builder()
|
||||
.executionEngine("local")
|
||||
.build();
|
||||
|
||||
var ee = new ArrayList<>();
|
||||
|
||||
final int idx = ee.indexOf(bot);
|
||||
|
||||
if (bot.evalStorage.isEmpty()) {
|
||||
bot.evalStorage.put(
|
||||
"servereval",
|
||||
jShell
|
||||
);
|
||||
var shell = bot.evalStorage.get("servereval");
|
||||
|
||||
shell.eval("import land.chipmunk.parker2991.nitoribot.nightofnights.Main; ");
|
||||
shell.eval("import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot; ");
|
||||
shell.eval("import net.kyori.adventure.text.Component; ");
|
||||
|
||||
shell.eval("final NitoriBot bot = Main.Bots.get(" + idx + "); ");
|
||||
}
|
||||
|
||||
var shell = bot.evalStorage.get("servereval");
|
||||
|
||||
if (args.equalsIgnoreCase("reset")) {
|
||||
bot.evalStorage.clear();
|
||||
component =
|
||||
Component.text("Resetting the eval").color(convertColorString(bot.config.colors.commands.primary));
|
||||
} else {
|
||||
|
||||
List<SnippetEvent> events = shell.eval(args);
|
||||
|
||||
for (SnippetEvent event : events) {
|
||||
final Snippet.Status status = event.status();
|
||||
|
||||
switch (event.status()) {
|
||||
case VALID -> {
|
||||
String value = event.value();
|
||||
JShellException exception = event.exception();
|
||||
|
||||
if (exception != null) {
|
||||
if (exception instanceof EvalException eval) {
|
||||
|
||||
try {
|
||||
if (eval.getCause() != null) {
|
||||
component = Component.text(
|
||||
exception.getCause().getLocalizedMessage()
|
||||
).color(NamedTextColor.RED);
|
||||
} else {
|
||||
component = Component.text(
|
||||
exception.getMessage()
|
||||
).color(NamedTextColor.RED);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
component =
|
||||
Component.text(eval.toString()).color(convertColorString(bot.config.colors.commands.primary));
|
||||
}
|
||||
}
|
||||
} else if (value == null) {
|
||||
component =
|
||||
Component.text("Ran successfully").color(convertColorString(bot.config.colors.commands.primary));
|
||||
} else {
|
||||
component =
|
||||
Component.text(value).color(convertColorString(bot.config.colors.commands.primary));
|
||||
|
||||
}
|
||||
bot.evalStorage.put(
|
||||
args,
|
||||
shell
|
||||
);
|
||||
}
|
||||
case REJECTED -> {
|
||||
shell
|
||||
.diagnostics(event.snippet())
|
||||
.forEach(diagnostic -> {
|
||||
String msg = diagnostic.getMessage(Locale.US);
|
||||
source.sendFeedback(
|
||||
bot,
|
||||
Component
|
||||
.text(msg.split("\n")[0])
|
||||
.color(NamedTextColor.RED)
|
||||
.hoverEvent(Component
|
||||
.text(msg)
|
||||
.color(NamedTextColor.RED))
|
||||
);
|
||||
});
|
||||
}
|
||||
case OVERWRITTEN -> {
|
||||
component = Component.translatable(
|
||||
"Value %s overridden",
|
||||
Component.text(event.snippet().source())
|
||||
).color(convertColorString(bot.config.colors.commands.primary));
|
||||
}
|
||||
case DROPPED -> {
|
||||
component =
|
||||
Component.text("Explicitly dropped").color(convertColorString(bot.config.colors.commands.primary));
|
||||
}
|
||||
default -> {
|
||||
component =
|
||||
Component.translatable("Status %s", Component.text(event.status().toString())).color(convertColorString(bot.config.colors.commands.primary));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return component;
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.trusted;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandTrustLevels;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ReconnectCommand implements CommandInfo {
|
||||
public ReconnectCommand () {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTrustLevels getTrustLevel () {
|
||||
return CommandTrustLevels.TRUSTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of(
|
||||
"reconnect",
|
||||
"end"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsages () {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription () {
|
||||
return "reconnect the bot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute (CommandContext context) {
|
||||
NitoriBot bot = context.bot();
|
||||
|
||||
bot.session.disconnect("Reconnect Command");
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user