Mac changes everything...
parent
2040001323
commit
44c181d9b2
|
@ -1,22 +1,22 @@
|
|||
# eclipse
|
||||
bin
|
||||
*.launch
|
||||
.settings
|
||||
.metadata
|
||||
.classpath
|
||||
.project
|
||||
|
||||
# idea
|
||||
out
|
||||
*.ipr
|
||||
*.iws
|
||||
*.iml
|
||||
.idea
|
||||
|
||||
# gradle
|
||||
build
|
||||
.gradle
|
||||
|
||||
# other
|
||||
eclipse
|
||||
run
|
||||
# eclipse
|
||||
bin
|
||||
*.launch
|
||||
.settings
|
||||
.metadata
|
||||
.classpath
|
||||
.project
|
||||
|
||||
# idea
|
||||
out
|
||||
*.ipr
|
||||
*.iws
|
||||
*.iml
|
||||
.idea
|
||||
|
||||
# gradle
|
||||
build
|
||||
.gradle
|
||||
|
||||
# other
|
||||
eclipse
|
||||
run
|
||||
|
|
126
CHANGELOG.md
126
CHANGELOG.md
|
@ -1,64 +1,64 @@
|
|||
# Changelog
|
||||
|
||||
## 1.0.0 - Out of Alpha!
|
||||
![RELEASE](https://media.giphy.com/media/duGmnxv5TZDy/giphy.gif)
|
||||
- Improved the `!tps` response text
|
||||
- Switched to asynchronous sending messages to Discord
|
||||
|
||||
### 0.6.0
|
||||
- Added ability for message when detecting server crashing
|
||||
- Added support for other Discord formatting for `_Italic_`
|
||||
- Improved handling of `!unstuck` command
|
||||
|
||||
#### 0.5.1
|
||||
- Fix color of Discord usernames
|
||||
- Added `usernameColor` to Minecraft chat config
|
||||
- Fix missing characters after MC => Discord mention in Discord message
|
||||
|
||||
### 0.5.0
|
||||
- Added ability for command aliases
|
||||
- Added `!unstuck <player>` command to send a player to spawn
|
||||
- Works for both online and offline players
|
||||
- Will kick online players, as the client doesn't always update location
|
||||
- Changed the way all messages are handled
|
||||
- Now supports some of Discord's formatting (`**Bold**`, `*Italic*` and `__Underline__`)
|
||||
- Removes formatting from `~~Line through~~` and ``` `code` ```
|
||||
- Mention a Discord user by clicking the name
|
||||
|
||||
### 0.4.0
|
||||
- Added max length on relayed Discord messages (Default -1, meaning disabled)
|
||||
- Added limit of commands to roles (by role name)
|
||||
- Improved Discord user mentions (Prevents wrong mention in case of both `User1` and `User1_`)
|
||||
- Replaced placeholders in strings (**BREAKS ALL CURRENT CONFIGS**)
|
||||
- `%USER%` Name of user (Chat, Death, Achievement, Join, Leave)
|
||||
- `%MESSAGE%` Message (Chat, Death)
|
||||
- `%ACHIEVEMENT%` Name of achievement (Achievement)
|
||||
- Returned player names from `!online` is now packed in like `this`
|
||||
- Remove Minecraft formatting (1 character prefixed with §) from `/say` and chat messages
|
||||
|
||||
### 0.3.0
|
||||
- Added `!tps` command for Discord
|
||||
- Highlight player's name in Discord messages
|
||||
- Highlight `@everyone` (Only from people with permission to mention everyone)
|
||||
|
||||
### 0.2.0
|
||||
- Added command
|
||||
- If ChikachiLib is detected, `/chikachi discord`
|
||||
- Otherwise, `/discord`
|
||||
- Broadcast messages (`/say`) is now also relayed
|
||||
- Made Discord mentions case-insensitive
|
||||
|
||||
#### 0.1.3
|
||||
- Fix NullPointerException on startup
|
||||
- Added experimental fake players (CAN FILL YOUR SERVER UP WITH FAKE PLAYERS)
|
||||
![Example](https://ss.chikachi.net/2016-05-05_03-10-13_7109d217-ef20-4979-a5a4-0baa8c8a46c4.png)
|
||||
- Call proper shutdown of Discord connection
|
||||
|
||||
#### 0.1.2
|
||||
- Improve Discord mentioning
|
||||
|
||||
#### 0.1.1
|
||||
- Fix DiscordFakePlayers showing up in !online list
|
||||
|
||||
### 0.1.0
|
||||
# Changelog
|
||||
|
||||
## 1.0.0 - Out of Alpha!
|
||||
![RELEASE](https://media.giphy.com/media/duGmnxv5TZDy/giphy.gif)
|
||||
- Improved the `!tps` response text
|
||||
- Switched to asynchronous sending messages to Discord
|
||||
|
||||
### 0.6.0
|
||||
- Added ability for message when detecting server crashing
|
||||
- Added support for other Discord formatting for `_Italic_`
|
||||
- Improved handling of `!unstuck` command
|
||||
|
||||
#### 0.5.1
|
||||
- Fix color of Discord usernames
|
||||
- Added `usernameColor` to Minecraft chat config
|
||||
- Fix missing characters after MC => Discord mention in Discord message
|
||||
|
||||
### 0.5.0
|
||||
- Added ability for command aliases
|
||||
- Added `!unstuck <player>` command to send a player to spawn
|
||||
- Works for both online and offline players
|
||||
- Will kick online players, as the client doesn't always update location
|
||||
- Changed the way all messages are handled
|
||||
- Now supports some of Discord's formatting (`**Bold**`, `*Italic*` and `__Underline__`)
|
||||
- Removes formatting from `~~Line through~~` and ``` `code` ```
|
||||
- Mention a Discord user by clicking the name
|
||||
|
||||
### 0.4.0
|
||||
- Added max length on relayed Discord messages (Default -1, meaning disabled)
|
||||
- Added limit of commands to roles (by role name)
|
||||
- Improved Discord user mentions (Prevents wrong mention in case of both `User1` and `User1_`)
|
||||
- Replaced placeholders in strings (**BREAKS ALL CURRENT CONFIGS**)
|
||||
- `%USER%` Name of user (Chat, Death, Achievement, Join, Leave)
|
||||
- `%MESSAGE%` Message (Chat, Death)
|
||||
- `%ACHIEVEMENT%` Name of achievement (Achievement)
|
||||
- Returned player names from `!online` is now packed in like `this`
|
||||
- Remove Minecraft formatting (1 character prefixed with §) from `/say` and chat messages
|
||||
|
||||
### 0.3.0
|
||||
- Added `!tps` command for Discord
|
||||
- Highlight player's name in Discord messages
|
||||
- Highlight `@everyone` (Only from people with permission to mention everyone)
|
||||
|
||||
### 0.2.0
|
||||
- Added command
|
||||
- If ChikachiLib is detected, `/chikachi discord`
|
||||
- Otherwise, `/discord`
|
||||
- Broadcast messages (`/say`) is now also relayed
|
||||
- Made Discord mentions case-insensitive
|
||||
|
||||
#### 0.1.3
|
||||
- Fix NullPointerException on startup
|
||||
- Added experimental fake players (CAN FILL YOUR SERVER UP WITH FAKE PLAYERS)
|
||||
![Example](https://ss.chikachi.net/2016-05-05_03-10-13_7109d217-ef20-4979-a5a4-0baa8c8a46c4.png)
|
||||
- Call proper shutdown of Discord connection
|
||||
|
||||
#### 0.1.2
|
||||
- Improve Discord mentioning
|
||||
|
||||
#### 0.1.1
|
||||
- Fix DiscordFakePlayers showing up in !online list
|
||||
|
||||
### 0.1.0
|
||||
- Initial alpha version
|
279
build.gradle
279
build.gradle
|
@ -1,140 +1,141 @@
|
|||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
name = "forge"
|
||||
url = "http://files.minecraftforge.net/maven"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "com.github.johnrengelman.shadow" version "1.2.2"
|
||||
}
|
||||
|
||||
repositories {
|
||||
ivy {
|
||||
name "CurseForge"
|
||||
artifactPattern 'http://addons-origin.cursecdn.com/files/[organisation]/[module]-[revision].[ext]'
|
||||
}
|
||||
flatDir {
|
||||
dirs "libs"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||
|
||||
def mcVersion = '1.9.4'
|
||||
def forgeVersion = '12.17.0.1910'
|
||||
|
||||
version = "1.0.0"
|
||||
group = "chikachi.discord"
|
||||
archivesBaseName = "ChikachiDiscord"
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
||||
minecraft {
|
||||
version = mcVersion + '-' + forgeVersion + '-' + mcVersion
|
||||
|
||||
if (file('../run').exists()) {
|
||||
runDir = '../run'
|
||||
} else {
|
||||
runDir = 'run'
|
||||
}
|
||||
|
||||
mappings = "snapshot_20160520"
|
||||
}
|
||||
|
||||
def printDebug(message) {
|
||||
println '[' + archivesBaseName + '] ' + message
|
||||
}
|
||||
|
||||
class CurseForgeDependencyInfo {
|
||||
public String module, version, ext;
|
||||
private String fileid;
|
||||
|
||||
public CurseForgeDependencyInfo(String module, String version, String ext, String fileid) {
|
||||
this.module = module;
|
||||
this.version = version;
|
||||
this.ext = ext;
|
||||
this.fileid = fileid;
|
||||
}
|
||||
|
||||
public String GetFileId() {
|
||||
return Integer.parseInt(fileid.substring(0, 4)) + "/" + Integer.parseInt(fileid.substring(4));
|
||||
}
|
||||
}
|
||||
|
||||
// Dependencies on CurseForge
|
||||
List<CurseForgeDependencyInfo> curseForgeDependencies = new ArrayList<CurseForgeDependencyInfo>();
|
||||
curseForgeDependencies.add(new CurseForgeDependencyInfo("ChikachiLib", "1.7.10-0.1.0", "jar", "2269757"));
|
||||
|
||||
dependencies {
|
||||
compile 'net.dv8tion:JDA:2.0.0_242:withDependencies'
|
||||
|
||||
for (CurseForgeDependencyInfo dependency : curseForgeDependencies) {
|
||||
if (file('../' + dependency.module).exists()) {
|
||||
printDebug 'Using local ' + dependency.module + ' project'
|
||||
compile project(':' + dependency.module)
|
||||
continue;
|
||||
}
|
||||
if (file('./' + dependency.module + '.jar').exists()) {
|
||||
printDebug 'Using local ' + dependency.module + ' compiled jar'
|
||||
compile files('./' + dependency.module + '.jar')
|
||||
continue;
|
||||
}
|
||||
compile group: dependency.GetFileId(), name: dependency.module, version: dependency.version, ext: dependency.ext
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
classifier = ""
|
||||
relocate "com.mashape.unirest", "chikachi.discord.repack.com.mashape.unirest"
|
||||
relocate "com.neovisionaries.ws.client", "chikachi.discord.repack.com.neovisionaries.ws.client"
|
||||
relocate "com.sun.jna", "chikachi.discord.repack.com.sun.jna"
|
||||
relocate "javax.sound", "chikachi.discord.repack.javax.sound"
|
||||
relocate "javazoom", "chikachi.discord.repack.javazoom"
|
||||
relocate "net.dv8tion.jda", "chikachi.discord.repack.net.dv8tion.jda"
|
||||
relocate "net.sourceforge.jaad", "chikachi.discord.repack.net.sourceforge.jaad"
|
||||
relocate "org.apache.commons.codec", "chikachi.discord.repack.org.apache.commons.codec"
|
||||
relocate "org.apache.commons.lang3", "chikachi.discord.repack.org.apache.commons.lang3"
|
||||
relocate "org.json", "chikachi.discord.repack.org.json"
|
||||
relocate "org.kc7bfi.jflac", "chikachi.discord.repack.orgkc7bfi.jflac"
|
||||
relocate "org.tritonus", "chikachi.discord.repack.org.tritonus"
|
||||
relocate "tomp2p.opuswrapper", "chikachi.discord.repack.tomp2p.opuswrapper"
|
||||
|
||||
relocate "org.apache.http", "chikachi.discord.repack.org.apache.http"
|
||||
relocate "org.apache.commons.logging", "chikachi.discord.repack.org.apache.commons.logging"
|
||||
|
||||
dependencies {
|
||||
include(dependency('net.dv8tion:JDA:2.0.0_242:withDependencies'))
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
// this will ensure that this task is redone when the versions change.
|
||||
inputs.property "version", project.version
|
||||
inputs.property "mcversion", project.minecraft.version
|
||||
|
||||
// replace stuff in mcmod.info, nothing else
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include 'mcmod.info'
|
||||
|
||||
// replace version and mcversion
|
||||
expand 'version': project.version, 'mcversion': project.minecraft.version
|
||||
}
|
||||
|
||||
// copy everything else, thats not the mcmod.info
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude 'mcmod.info'
|
||||
}
|
||||
}
|
||||
|
||||
reobf { shadowJar { mappingType = "SEARGE" } }
|
||||
tasks.reobfShadowJar.mustRunAfter shadowJar
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
name = "forge"
|
||||
url = "http://files.minecraftforge.net/maven"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "com.github.johnrengelman.shadow" version "1.2.2"
|
||||
}
|
||||
|
||||
repositories {
|
||||
ivy {
|
||||
name "CurseForge"
|
||||
artifactPattern 'http://addons-origin.cursecdn.com/files/[organisation]/[module]-[revision].[ext]'
|
||||
}
|
||||
flatDir {
|
||||
dirs "libs"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||
|
||||
def mcVersion = '1.9.4'
|
||||
def forgeVersion = '12.17.0.1922'
|
||||
def modVersion = '1.0.0'
|
||||
|
||||
version = 'mc' + mcVersion + '-' + modVersion
|
||||
group = "chikachi.discord"
|
||||
archivesBaseName = "ChikachiDiscord"
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
||||
minecraft {
|
||||
version = mcVersion + '-' + forgeVersion + '-' + mcVersion
|
||||
|
||||
if (file('../run').exists()) {
|
||||
runDir = '../run'
|
||||
} else {
|
||||
runDir = 'run'
|
||||
}
|
||||
|
||||
mappings = "snapshot_20160526"
|
||||
}
|
||||
|
||||
def printDebug(message) {
|
||||
println '[' + archivesBaseName + '] ' + message
|
||||
}
|
||||
|
||||
class CurseForgeDependencyInfo {
|
||||
public String module, version, ext;
|
||||
private String fileid;
|
||||
|
||||
public CurseForgeDependencyInfo(String module, String version, String ext, String fileid) {
|
||||
this.module = module;
|
||||
this.version = version;
|
||||
this.ext = ext;
|
||||
this.fileid = fileid;
|
||||
}
|
||||
|
||||
public String GetFileId() {
|
||||
return Integer.parseInt(fileid.substring(0, 4)) + "/" + Integer.parseInt(fileid.substring(4));
|
||||
}
|
||||
}
|
||||
|
||||
// Dependencies on CurseForge
|
||||
List<CurseForgeDependencyInfo> curseForgeDependencies = new ArrayList<CurseForgeDependencyInfo>();
|
||||
curseForgeDependencies.add(new CurseForgeDependencyInfo("ChikachiLib", "1.7.10-0.1.0", "jar", "2269757"));
|
||||
|
||||
dependencies {
|
||||
compile 'net.dv8tion:JDA:2.0.0_242:withDependencies'
|
||||
|
||||
for (CurseForgeDependencyInfo dependency : curseForgeDependencies) {
|
||||
if (file('../' + dependency.module).exists()) {
|
||||
printDebug 'Using local ' + dependency.module + ' project'
|
||||
compile project(':' + dependency.module)
|
||||
continue;
|
||||
}
|
||||
if (file('./' + dependency.module + '.jar').exists()) {
|
||||
printDebug 'Using local ' + dependency.module + ' compiled jar'
|
||||
compile files('./' + dependency.module + '.jar')
|
||||
continue;
|
||||
}
|
||||
compile group: dependency.GetFileId(), name: dependency.module, version: dependency.version, ext: dependency.ext
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
classifier = ""
|
||||
relocate "com.mashape.unirest", "chikachi.discord.repack.com.mashape.unirest"
|
||||
relocate "com.neovisionaries.ws.client", "chikachi.discord.repack.com.neovisionaries.ws.client"
|
||||
relocate "com.sun.jna", "chikachi.discord.repack.com.sun.jna"
|
||||
relocate "javax.sound", "chikachi.discord.repack.javax.sound"
|
||||
relocate "javazoom", "chikachi.discord.repack.javazoom"
|
||||
relocate "net.dv8tion.jda", "chikachi.discord.repack.net.dv8tion.jda"
|
||||
relocate "net.sourceforge.jaad", "chikachi.discord.repack.net.sourceforge.jaad"
|
||||
relocate "org.apache.commons.codec", "chikachi.discord.repack.org.apache.commons.codec"
|
||||
relocate "org.apache.commons.lang3", "chikachi.discord.repack.org.apache.commons.lang3"
|
||||
relocate "org.json", "chikachi.discord.repack.org.json"
|
||||
relocate "org.kc7bfi.jflac", "chikachi.discord.repack.orgkc7bfi.jflac"
|
||||
relocate "org.tritonus", "chikachi.discord.repack.org.tritonus"
|
||||
relocate "tomp2p.opuswrapper", "chikachi.discord.repack.tomp2p.opuswrapper"
|
||||
|
||||
relocate "org.apache.http", "chikachi.discord.repack.org.apache.http"
|
||||
relocate "org.apache.commons.logging", "chikachi.discord.repack.org.apache.commons.logging"
|
||||
|
||||
dependencies {
|
||||
include(dependency('net.dv8tion:JDA:2.0.0_242:withDependencies'))
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
// this will ensure that this task is redone when the versions change.
|
||||
inputs.property "version", project.version
|
||||
inputs.property "mcversion", project.minecraft.version
|
||||
|
||||
// replace stuff in mcmod.info, nothing else
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include 'mcmod.info'
|
||||
|
||||
// replace version and mcversion
|
||||
expand 'version': project.version, 'mcversion': project.minecraft.version
|
||||
}
|
||||
|
||||
// copy everything else, thats not the mcmod.info
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude 'mcmod.info'
|
||||
}
|
||||
}
|
||||
|
||||
reobf { shadowJar { mappingType = "SEARGE" } }
|
||||
tasks.reobfShadowJar.mustRunAfter shadowJar
|
||||
|
||||
idea { module { inheritOutputDirs = true } }
|
|
@ -1,90 +1,90 @@
|
|||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="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!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="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!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
include ':ChikachiLib'
|
||||
include ':ChikachiLib'
|
||||
project(':ChikachiLib').projectDir = new File(settingsDir, '../ChikachiLib')
|
|
@ -1,107 +1,107 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord;
|
||||
|
||||
import chikachi.discord.command.NonLibCommandHandler;
|
||||
import chikachi.discord.config.Configuration;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.*;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@Mod(modid = Constants.MODID, name = Constants.MODNAME, version = Constants.VERSION, serverSideOnly = true, acceptableRemoteVersions = "*")
|
||||
public class ChikachiDiscord {
|
||||
private static Proxy proxy = new Proxy();
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(Constants.MODID);
|
||||
|
||||
private static boolean receivedStoppingEvent = false;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onPreInit(FMLPreInitializationEvent event) {
|
||||
proxy.onPreInit(event);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerAboutToStart(FMLServerAboutToStartEvent event) {
|
||||
Configuration.onServerStarting(event);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerStarting(FMLServerStartingEvent event) {
|
||||
if (Loader.isModLoaded("ChikachiLib")) {
|
||||
Log("Trying to hook into ChikachiLib", false);
|
||||
try {
|
||||
Class subCommandHandlerClass = Class.forName("chikachi.discord.command.LibCommandHandler");
|
||||
Class libClass = Class.forName("chikachi.lib.ChikachiLib");
|
||||
Class commandClass = Class.forName("chikachi.lib.common.command.sub.CommandChikachiBase");
|
||||
if (subCommandHandlerClass != null && libClass != null && commandClass != null) {
|
||||
Field commandHandlerField = libClass.getField("commandHandler");
|
||||
if (commandHandlerField != null) {
|
||||
Object obj = commandHandlerField.get(null);
|
||||
if (obj != null) {
|
||||
Method registerCommandHandlerMethod = obj.getClass().getMethod("RegisterSubCommandHandler", commandClass);
|
||||
if (registerCommandHandlerMethod != null) {
|
||||
registerCommandHandlerMethod.invoke(obj, subCommandHandlerClass.newInstance());
|
||||
Log("Hooked into ChikachiLib", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
|
||||
Log("Failed to hook into ChikachiLib", false);
|
||||
event.registerServerCommand(new NonLibCommandHandler());
|
||||
}
|
||||
} else {
|
||||
event.registerServerCommand(new NonLibCommandHandler());
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerStarted(FMLServerStartedEvent event) {
|
||||
proxy.onServerStarted();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerShutdown(FMLServerStoppingEvent event) {
|
||||
proxy.onServerShutdown();
|
||||
receivedStoppingEvent = true;
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerStopped(FMLServerStoppedEvent event) {
|
||||
if (!receivedStoppingEvent) {
|
||||
proxy.onServerCrash();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public static void Log(String message) {
|
||||
Log(message, false);
|
||||
}
|
||||
|
||||
public static void Log(String message, boolean warning) {
|
||||
logger.log(warning ? Level.WARN : Level.INFO, String.format("[%s] %s", Constants.VERSION, message));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord;
|
||||
|
||||
import chikachi.discord.command.NonLibCommandHandler;
|
||||
import chikachi.discord.config.Configuration;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.*;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@Mod(modid = Constants.MODID, name = Constants.MODNAME, version = Constants.VERSION, serverSideOnly = true, acceptableRemoteVersions = "*")
|
||||
public class ChikachiDiscord {
|
||||
private static Proxy proxy = new Proxy();
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(Constants.MODID);
|
||||
|
||||
private static boolean receivedStoppingEvent = false;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onPreInit(FMLPreInitializationEvent event) {
|
||||
proxy.onPreInit(event);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerAboutToStart(FMLServerAboutToStartEvent event) {
|
||||
Configuration.onServerStarting(event);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerStarting(FMLServerStartingEvent event) {
|
||||
if (Loader.isModLoaded("ChikachiLib")) {
|
||||
Log("Trying to hook into ChikachiLib", false);
|
||||
try {
|
||||
Class subCommandHandlerClass = Class.forName("chikachi.discord.command.LibCommandHandler");
|
||||
Class libClass = Class.forName("chikachi.lib.ChikachiLib");
|
||||
Class commandClass = Class.forName("chikachi.lib.common.command.sub.CommandChikachiBase");
|
||||
if (subCommandHandlerClass != null && libClass != null && commandClass != null) {
|
||||
Field commandHandlerField = libClass.getField("commandHandler");
|
||||
if (commandHandlerField != null) {
|
||||
Object obj = commandHandlerField.get(null);
|
||||
if (obj != null) {
|
||||
Method registerCommandHandlerMethod = obj.getClass().getMethod("RegisterSubCommandHandler", commandClass);
|
||||
if (registerCommandHandlerMethod != null) {
|
||||
registerCommandHandlerMethod.invoke(obj, subCommandHandlerClass.newInstance());
|
||||
Log("Hooked into ChikachiLib", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
|
||||
Log("Failed to hook into ChikachiLib", false);
|
||||
event.registerServerCommand(new NonLibCommandHandler());
|
||||
}
|
||||
} else {
|
||||
event.registerServerCommand(new NonLibCommandHandler());
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerStarted(FMLServerStartedEvent event) {
|
||||
proxy.onServerStarted();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerShutdown(FMLServerStoppingEvent event) {
|
||||
proxy.onServerShutdown();
|
||||
receivedStoppingEvent = true;
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerStopped(FMLServerStoppedEvent event) {
|
||||
if (!receivedStoppingEvent) {
|
||||
proxy.onServerCrash();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public static void Log(String message) {
|
||||
Log(message, false);
|
||||
}
|
||||
|
||||
public static void Log(String message, boolean warning) {
|
||||
logger.log(warning ? Level.WARN : Level.INFO, String.format("[%s] %s", Constants.VERSION, message));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord;
|
||||
|
||||
public class Constants {
|
||||
public static final String MODID = "ChikachiDiscord";
|
||||
public static final String MODNAME = "Chikachi's Discord integration mod";
|
||||
public static final String VERSION = "1.0.0";
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord;
|
||||
|
||||
public class Constants {
|
||||
public static final String MODID = "ChikachiDiscord";
|
||||
public static final String MODNAME = "Chikachi's Discord integration mod";
|
||||
public static final String VERSION = "1.0.0";
|
||||
}
|
||||
|
|
|
@ -1,129 +1,129 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord;
|
||||
|
||||
import chikachi.discord.config.Configuration;
|
||||
import chikachi.discord.config.experimental.ExperimentalDiscordListener;
|
||||
import chikachi.discord.config.listener.DiscordListener;
|
||||
import net.dv8tion.jda.JDA;
|
||||
import net.dv8tion.jda.JDABuilder;
|
||||
import net.dv8tion.jda.entities.TextChannel;
|
||||
import net.dv8tion.jda.entities.User;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DiscordClient {
|
||||
private static DiscordClient instance;
|
||||
private JDA jda;
|
||||
private TextChannel channel;
|
||||
public List<String> queue = new ArrayList<>();
|
||||
|
||||
public static DiscordClient getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new DiscordClient();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
private DiscordClient() {
|
||||
|
||||
}
|
||||
|
||||
public void connect(MinecraftServer minecraftServer) {
|
||||
if (this.jda != null) {
|
||||
ChikachiDiscord.Log("Is already connected", true);
|
||||
return;
|
||||
}
|
||||
|
||||
String token = Configuration.getToken();
|
||||
|
||||
if (token.isEmpty()) {
|
||||
ChikachiDiscord.Log("Missing token", true);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.jda = new JDABuilder()
|
||||
.setBotToken(token)
|
||||
.addListener(new DiscordListener(minecraftServer))
|
||||
.addListener(new ExperimentalDiscordListener(minecraftServer))
|
||||
.buildAsync();
|
||||
} catch (LoginException e) {
|
||||
ChikachiDiscord.Log("Failed to connect to Discord", true);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void disconnect() {
|
||||
if (this.jda == null) {
|
||||
ChikachiDiscord.Log("Is already disconnected", true);
|
||||
return;
|
||||
}
|
||||
|
||||
this.jda.shutdown();
|
||||
this.jda = null;
|
||||
}
|
||||
|
||||
public TextChannel getChannel() {
|
||||
if (this.channel == null) {
|
||||
this.channel = this.jda.getTextChannelById(Configuration.getChannel());
|
||||
if (this.channel == null) {
|
||||
ChikachiDiscord.Log("Failed to find channel", true);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return this.channel;
|
||||
}
|
||||
|
||||
public boolean sendMessage(String message) {
|
||||
if (this.jda == null) {
|
||||
this.queue.add(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
TextChannel channel = getChannel();
|
||||
if (channel == null) {
|
||||
this.queue.add(message);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (message.contains("@")) {
|
||||
message = " " + message + " ";
|
||||
|
||||
List<User> users = new ArrayList<>(this.channel.getGuild().getUsers());
|
||||
users.sort((o1, o2) -> o2.getUsername().length() - o1.getUsername().length());
|
||||
|
||||
for (User user : users) {
|
||||
if (message.toLowerCase().contains("@" + user.getUsername().toLowerCase())) {
|
||||
message = message.replaceAll("(?i)@" + user.getUsername() + "(\\W)", user.getAsMention() + "$1");
|
||||
}
|
||||
}
|
||||
|
||||
message = message.trim();
|
||||
}
|
||||
|
||||
this.channel.sendMessageAsync(message, sentMessage -> {
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord;
|
||||
|
||||
import chikachi.discord.config.Configuration;
|
||||
import chikachi.discord.config.experimental.ExperimentalDiscordListener;
|
||||
import chikachi.discord.config.listener.DiscordListener;
|
||||
import net.dv8tion.jda.JDA;
|
||||
import net.dv8tion.jda.JDABuilder;
|
||||
import net.dv8tion.jda.entities.TextChannel;
|
||||
import net.dv8tion.jda.entities.User;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DiscordClient {
|
||||
private static DiscordClient instance;
|
||||
private JDA jda;
|
||||
private TextChannel channel;
|
||||
public List<String> queue = new ArrayList<>();
|
||||
|
||||
public static DiscordClient getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new DiscordClient();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
private DiscordClient() {
|
||||
|
||||
}
|
||||
|
||||
public void connect(MinecraftServer minecraftServer) {
|
||||
if (this.jda != null) {
|
||||
ChikachiDiscord.Log("Is already connected", true);
|
||||
return;
|
||||
}
|
||||
|
||||
String token = Configuration.getToken();
|
||||
|
||||
if (token.isEmpty()) {
|
||||
ChikachiDiscord.Log("Missing token", true);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.jda = new JDABuilder()
|
||||
.setBotToken(token)
|
||||
.addListener(new DiscordListener(minecraftServer))
|
||||
.addListener(new ExperimentalDiscordListener(minecraftServer))
|
||||
.buildAsync();
|
||||
} catch (LoginException e) {
|
||||
ChikachiDiscord.Log("Failed to connect to Discord", true);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void disconnect() {
|
||||
if (this.jda == null) {
|
||||
ChikachiDiscord.Log("Is already disconnected", true);
|
||||
return;
|
||||
}
|
||||
|
||||
this.jda.shutdown();
|
||||
this.jda = null;
|
||||
}
|
||||
|
||||
public TextChannel getChannel() {
|
||||
if (this.channel == null) {
|
||||
this.channel = this.jda.getTextChannelById(Configuration.getChannel());
|
||||
if (this.channel == null) {
|
||||
ChikachiDiscord.Log("Failed to find channel", true);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return this.channel;
|
||||
}
|
||||
|
||||
public boolean sendMessage(String message) {
|
||||
if (this.jda == null) {
|
||||
this.queue.add(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
TextChannel channel = getChannel();
|
||||
if (channel == null) {
|
||||
this.queue.add(message);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (message.contains("@")) {
|
||||
message = " " + message + " ";
|
||||
|
||||
List<User> users = new ArrayList<>(this.channel.getGuild().getUsers());
|
||||
users.sort((o1, o2) -> o2.getUsername().length() - o1.getUsername().length());
|
||||
|
||||
for (User user : users) {
|
||||
if (message.toLowerCase().contains("@" + user.getUsername().toLowerCase())) {
|
||||
message = message.replaceAll("(?i)@" + user.getUsername() + "(\\W)", user.getAsMention() + "$1");
|
||||
}
|
||||
}
|
||||
|
||||
message = message.trim();
|
||||
}
|
||||
|
||||
this.channel.sendMessageAsync(message, sentMessage -> {
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,68 +1,68 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.world.Teleporter;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
public class DiscordTeleporter extends Teleporter {
|
||||
private boolean forcePos = false;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
|
||||
public DiscordTeleporter(WorldServer world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public DiscordTeleporter(WorldServer world, double x, double y, double z) {
|
||||
super(world);
|
||||
|
||||
this.forcePos = true;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean makePortal(Entity entity) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeInExistingPortal(Entity entity, float r) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeStalePortalLocations(long worldTime) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeInPortal(Entity entity, float r) {
|
||||
if (this.forcePos) {
|
||||
entity.setLocationAndAngles(this.x, this.y, this.z, entity.rotationYaw, entity.rotationPitch);
|
||||
}
|
||||
|
||||
entity.motionX = 0;
|
||||
entity.motionY = 0;
|
||||
entity.motionZ = 0;
|
||||
entity.fallDistance = 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.world.Teleporter;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
public class DiscordTeleporter extends Teleporter {
|
||||
private boolean forcePos = false;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
|
||||
public DiscordTeleporter(WorldServer world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public DiscordTeleporter(WorldServer world, double x, double y, double z) {
|
||||
super(world);
|
||||
|
||||
this.forcePos = true;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean makePortal(Entity entity) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeInExistingPortal(Entity entity, float r) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeStalePortalLocations(long worldTime) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeInPortal(Entity entity, float r) {
|
||||
if (this.forcePos) {
|
||||
entity.setLocationAndAngles(this.x, this.y, this.z, entity.rotationYaw, entity.rotationPitch);
|
||||
}
|
||||
|
||||
entity.motionX = 0;
|
||||
entity.motionY = 0;
|
||||
entity.motionZ = 0;
|
||||
entity.fallDistance = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,54 +1,54 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord;
|
||||
|
||||
import chikachi.discord.config.Configuration;
|
||||
import chikachi.discord.config.listener.MinecraftListener;
|
||||
import chikachi.discord.config.message.GenericMessageConfig;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
|
||||
class Proxy {
|
||||
void onPreInit(FMLPreInitializationEvent event) {
|
||||
Configuration.onPreInit(event);
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new MinecraftListener());
|
||||
}
|
||||
|
||||
void onServerStarted() {
|
||||
GenericMessageConfig setting = Configuration.getDiscordStartup();
|
||||
|
||||
setting.sendMessage();
|
||||
}
|
||||
|
||||
void onServerShutdown() {
|
||||
GenericMessageConfig setting = Configuration.getDiscordShutdown();
|
||||
|
||||
setting.sendMessage();
|
||||
|
||||
DiscordClient.getInstance().disconnect();
|
||||
}
|
||||
|
||||
void onServerCrash() {
|
||||
GenericMessageConfig setting = Configuration.getDiscordCrash();
|
||||
|
||||
setting.sendMessage();
|
||||
|
||||
DiscordClient.getInstance().disconnect();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord;
|
||||
|
||||
import chikachi.discord.config.Configuration;
|
||||
import chikachi.discord.config.listener.MinecraftListener;
|
||||
import chikachi.discord.config.message.GenericMessageConfig;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
|
||||
class Proxy {
|
||||
void onPreInit(FMLPreInitializationEvent event) {
|
||||
Configuration.onPreInit(event);
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new MinecraftListener());
|
||||
}
|
||||
|
||||
void onServerStarted() {
|
||||
GenericMessageConfig setting = Configuration.getDiscordStartup();
|
||||
|
||||
setting.sendMessage();
|
||||
}
|
||||
|
||||
void onServerShutdown() {
|
||||
GenericMessageConfig setting = Configuration.getDiscordShutdown();
|
||||
|
||||
setting.sendMessage();
|
||||
|
||||
DiscordClient.getInstance().disconnect();
|
||||
}
|
||||
|
||||
void onServerCrash() {
|
||||
GenericMessageConfig setting = Configuration.getDiscordCrash();
|
||||
|
||||
setting.sendMessage();
|
||||
|
||||
DiscordClient.getInstance().disconnect();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,44 +1,44 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.command;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
import chikachi.discord.config.Configuration;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
|
||||
class CommandProcessor {
|
||||
static void processCommand(ICommandSender sender, String[] args) {
|
||||
if (args.length > 0) {
|
||||
switch (args[0]) {
|
||||
case "reload":
|
||||
boolean shouldTryConnect = Configuration.getToken().length() == 0;
|
||||
|
||||
Configuration.load();
|
||||
sender.addChatMessage(new TextComponentString("Config reloaded"));
|
||||
|
||||
if (shouldTryConnect && Configuration.getToken().length() > 0) {
|
||||
DiscordClient.getInstance().connect(sender.getServer());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
sender.addChatMessage(new TextComponentString("Unknown command - Available commands: reload"));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.command;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
import chikachi.discord.config.Configuration;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
|
||||
class CommandProcessor {
|
||||
static void processCommand(ICommandSender sender, String[] args) {
|
||||
if (args.length > 0) {
|
||||
switch (args[0]) {
|
||||
case "reload":
|
||||
boolean shouldTryConnect = Configuration.getToken().length() == 0;
|
||||
|
||||
Configuration.load();
|
||||
sender.addChatMessage(new TextComponentString("Config reloaded"));
|
||||
|
||||
if (shouldTryConnect && Configuration.getToken().length() > 0) {
|
||||
DiscordClient.getInstance().connect(sender.getServer());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
sender.addChatMessage(new TextComponentString("Unknown command - Available commands: reload"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,40 +1,40 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.command;
|
||||
|
||||
import chikachi.lib.common.command.sub.CommandChikachiBase;
|
||||
import chikachi.lib.common.utils.PlayerUtils;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class LibCommandHandler extends CommandChikachiBase {
|
||||
public LibCommandHandler() {
|
||||
super("discord");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(ICommandSender sender, String[] args) {
|
||||
CommandProcessor.processCommand(sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender) {
|
||||
return !(sender instanceof EntityPlayer) || PlayerUtils.IsOP((EntityPlayer) sender);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.command;
|
||||
|
||||
import chikachi.lib.common.command.sub.CommandChikachiBase;
|
||||
import chikachi.lib.common.utils.PlayerUtils;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class LibCommandHandler extends CommandChikachiBase {
|
||||
public LibCommandHandler() {
|
||||
super("discord");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(ICommandSender sender, String[] args) {
|
||||
CommandProcessor.processCommand(sender, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(ICommandSender sender) {
|
||||
return !(sender instanceof EntityPlayer) || PlayerUtils.IsOP((EntityPlayer) sender);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,40 +1,40 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.command;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class NonLibCommandHandler extends CommandBase {
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "discord";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "/discord [reload]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
||||
CommandProcessor.processCommand(sender, args);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.command;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class NonLibCommandHandler extends CommandBase {
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "discord";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "/discord [reload]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
|
||||
CommandProcessor.processCommand(sender, args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,307 +1,307 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config;
|
||||
|
||||
import chikachi.discord.ChikachiDiscord;
|
||||
import chikachi.discord.Constants;
|
||||
import chikachi.discord.DiscordClient;
|
||||
import chikachi.discord.config.command.OnlineCommandConfig;
|
||||
import chikachi.discord.config.command.TpsCommandConfig;
|
||||
import chikachi.discord.config.command.UnstuckCommandConfig;
|
||||
import chikachi.discord.config.message.AchievementMessageConfig;
|
||||
import chikachi.discord.config.message.DiscordChatMessageConfig;
|
||||
import chikachi.discord.config.message.GenericMessageConfig;
|
||||
import chikachi.discord.config.message.MinecraftChatMessageConfig;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerAboutToStartEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStartedEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Configuration {
|
||||
private static File config;
|
||||
private static String token = "";
|
||||
private static String channel = "";
|
||||
|
||||
private static OnlineCommandConfig commandOnline = new OnlineCommandConfig();
|
||||
private static TpsCommandConfig commandTps = new TpsCommandConfig();
|
||||
private static UnstuckCommandConfig commandUnstuck = new UnstuckCommandConfig();
|
||||
|
||||
private static boolean experimentalFakePlayers = false;
|
||||
|
||||
private static MinecraftChatMessageConfig discordChat;
|
||||
private static GenericMessageConfig discordDeath;
|
||||
private static AchievementMessageConfig discordAchievement;
|
||||
private static GenericMessageConfig discordJoin;
|
||||
private static GenericMessageConfig discordLeave;
|
||||
private static GenericMessageConfig discordStartup;
|
||||
private static GenericMessageConfig discordShutdown;
|
||||
private static GenericMessageConfig discordCrash;
|
||||
|
||||
private static DiscordChatMessageConfig minecraftChat;
|
||||
|
||||
public static void onPreInit(FMLPreInitializationEvent event) {
|
||||
File directory = new File(event.getModConfigurationDirectory().getAbsolutePath() + File.separator + "Chikachi");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
directory.mkdirs();
|
||||
|
||||
config = new File(directory, Constants.MODID + ".json");
|
||||
}
|
||||
|
||||
public static void onServerStarting(FMLServerAboutToStartEvent event) {
|
||||
discordChat = new MinecraftChatMessageConfig(true, "<__%USER%__> %MESSAGE%");
|
||||
discordDeath = new GenericMessageConfig("death", true, "__%USER%__ %MESSAGE%");
|
||||
discordAchievement = new AchievementMessageConfig(true, "Congrats to __%USER%__ for earning the achievement **[%ACHIEVEMENT%]**");
|
||||
discordJoin = new GenericMessageConfig("join", true, "__%USER%__ has joined the server!");
|
||||
discordLeave = new GenericMessageConfig("leave", true, "__%USER%__ left the server!");
|
||||
discordStartup = new GenericMessageConfig("startup", false, "**Server started**");
|
||||
discordShutdown = new GenericMessageConfig("shutdown", false, "**Server shutdown**");
|
||||
discordCrash = new GenericMessageConfig("crash", true, "**Server crash detected**");
|
||||
|
||||
minecraftChat = new DiscordChatMessageConfig(event.getServer(), true, "<__%USER%__> %MESSAGE%");
|
||||
|
||||
load();
|
||||
|
||||
DiscordClient.getInstance().connect(event.getServer());
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
if (config == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!config.exists()) {
|
||||
try {
|
||||
JsonWriter writer = new JsonWriter(new FileWriter(config));
|
||||
|
||||
writer.beginObject();
|
||||
|
||||
writer.name("discord");
|
||||
writer.beginObject();
|
||||
writer.name("token");
|
||||
writer.value(token);
|
||||
writer.name("channel");
|
||||
writer.value(channel);
|
||||
|
||||
writer.name("commands");
|
||||
writer.beginObject();
|
||||
commandOnline.write(writer);
|
||||
commandTps.write(writer);
|
||||
commandUnstuck.write(writer);
|
||||
writer.endObject();
|
||||
writer.endObject();
|
||||
|
||||
writer.name("messages");
|
||||
writer.beginObject();
|
||||
writer.name("discord");
|
||||
writer.beginObject();
|
||||
discordChat.write(writer);
|
||||
discordDeath.write(writer);
|
||||
discordAchievement.write(writer);
|
||||
discordJoin.write(writer);
|
||||
discordLeave.write(writer);
|
||||
discordStartup.write(writer);
|
||||
discordShutdown.write(writer);
|
||||
writer.endObject();
|
||||
|
||||
writer.name("minecraft");
|
||||
writer.beginObject();
|
||||
minecraftChat.write(writer);
|
||||
writer.endObject();
|
||||
writer.endObject();
|
||||
|
||||
writer.name("experimental");
|
||||
writer.beginObject();
|
||||
writer.name("fakePlayers");
|
||||
writer.value(experimentalFakePlayers);
|
||||
writer.endObject();
|
||||
|
||||
writer.endObject();
|
||||
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
ChikachiDiscord.Log("Error generating default config file", true);
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
JsonReader reader = new JsonReader(new FileReader(config));
|
||||
String name;
|
||||
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("discord") && reader.peek() == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("token") && reader.peek() == JsonToken.STRING) {
|
||||
token = reader.nextString();
|
||||
} else if (name.equalsIgnoreCase("channel") && reader.peek() == JsonToken.STRING) {
|
||||
channel = reader.nextString();
|
||||
} else if (name.equalsIgnoreCase("commands") && reader.peek() == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase(commandOnline.getName())) {
|
||||
commandOnline.read(reader);
|
||||
} else if (name.equalsIgnoreCase(commandTps.getName())) {
|
||||
commandTps.read(reader);
|
||||
} else if (name.equalsIgnoreCase(commandUnstuck.getName())) {
|
||||
commandUnstuck.read(reader);
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} else if (name.equalsIgnoreCase("messages") && reader.peek() == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("discord") && reader.peek() == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("chat")) {
|
||||
discordChat.read(reader);
|
||||
} else if (name.equalsIgnoreCase("death")) {
|
||||
discordDeath.read(reader);
|
||||
} else if (name.equalsIgnoreCase("achievement")) {
|
||||
discordAchievement.read(reader);
|
||||
} else if (name.equalsIgnoreCase("join")) {
|
||||
discordJoin.read(reader);
|
||||
} else if (name.equalsIgnoreCase("leave")) {
|
||||
discordLeave.read(reader);
|
||||
} else if (name.equalsIgnoreCase("startup")) {
|
||||
discordStartup.read(reader);
|
||||
} else if (name.equalsIgnoreCase("shutdown")) {
|
||||
discordShutdown.read(reader);
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} else if (name.equalsIgnoreCase("minecraft") && reader.peek() == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("chat")) {
|
||||
minecraftChat.read(reader);
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} else if (name.equalsIgnoreCase("experimental") && reader.peek() == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("fakePlayers") && reader.peek() == JsonToken.BOOLEAN) {
|
||||
experimentalFakePlayers = reader.nextBoolean();
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public static String getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public static OnlineCommandConfig getCommandOnline() {
|
||||
return commandOnline;
|
||||
}
|
||||
|
||||
public static TpsCommandConfig getCommandTps() {
|
||||
return commandTps;
|
||||
}
|
||||
|
||||
public static UnstuckCommandConfig getCommandUnstuck() {
|
||||
return commandUnstuck;
|
||||
}
|
||||
|
||||
public static boolean isExperimentalFakePlayersEnabled() {
|
||||
return experimentalFakePlayers;
|
||||
}
|
||||
|
||||
public static MinecraftChatMessageConfig getDiscordChat() {
|
||||
return discordChat;
|
||||
}
|
||||
|
||||
public static GenericMessageConfig getDiscordDeath() {
|
||||
return discordDeath;
|
||||
}
|
||||
|
||||
public static AchievementMessageConfig getDiscordAchievement() {
|
||||
return discordAchievement;
|
||||
}
|
||||
|
||||
public static GenericMessageConfig getDiscordJoin() {
|
||||
return discordJoin;
|
||||
}
|
||||
|
||||
public static GenericMessageConfig getDiscordLeave() {
|
||||
return discordLeave;
|
||||
}
|
||||
|
||||
public static GenericMessageConfig getDiscordStartup() {
|
||||
return discordStartup;
|
||||
}
|
||||
|
||||
public static GenericMessageConfig getDiscordShutdown() {
|
||||
return discordShutdown;
|
||||
}
|
||||
|
||||
public static DiscordChatMessageConfig getMinecraftChat() {
|
||||
return minecraftChat;
|
||||
}
|
||||
|
||||
public static GenericMessageConfig getDiscordCrash() {
|
||||
return discordCrash;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config;
|
||||
|
||||
import chikachi.discord.ChikachiDiscord;
|
||||
import chikachi.discord.Constants;
|
||||
import chikachi.discord.DiscordClient;
|
||||
import chikachi.discord.config.command.OnlineCommandConfig;
|
||||
import chikachi.discord.config.command.TpsCommandConfig;
|
||||
import chikachi.discord.config.command.UnstuckCommandConfig;
|
||||
import chikachi.discord.config.message.AchievementMessageConfig;
|
||||
import chikachi.discord.config.message.DiscordChatMessageConfig;
|
||||
import chikachi.discord.config.message.GenericMessageConfig;
|
||||
import chikachi.discord.config.message.MinecraftChatMessageConfig;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerAboutToStartEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStartedEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Configuration {
|
||||
private static File config;
|
||||
private static String token = "";
|
||||
private static String channel = "";
|
||||
|
||||
private static OnlineCommandConfig commandOnline = new OnlineCommandConfig();
|
||||
private static TpsCommandConfig commandTps = new TpsCommandConfig();
|
||||
private static UnstuckCommandConfig commandUnstuck = new UnstuckCommandConfig();
|
||||
|
||||
private static boolean experimentalFakePlayers = false;
|
||||
|
||||
private static MinecraftChatMessageConfig discordChat;
|
||||
private static GenericMessageConfig discordDeath;
|
||||
private static AchievementMessageConfig discordAchievement;
|
||||
private static GenericMessageConfig discordJoin;
|
||||
private static GenericMessageConfig discordLeave;
|
||||
private static GenericMessageConfig discordStartup;
|
||||
private static GenericMessageConfig discordShutdown;
|
||||
private static GenericMessageConfig discordCrash;
|
||||
|
||||
private static DiscordChatMessageConfig minecraftChat;
|
||||
|
||||
public static void onPreInit(FMLPreInitializationEvent event) {
|
||||
File directory = new File(event.getModConfigurationDirectory().getAbsolutePath() + File.separator + "Chikachi");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
directory.mkdirs();
|
||||
|
||||
config = new File(directory, Constants.MODID + ".json");
|
||||
}
|
||||
|
||||
public static void onServerStarting(FMLServerAboutToStartEvent event) {
|
||||
discordChat = new MinecraftChatMessageConfig(true, "<__%USER%__> %MESSAGE%");
|
||||
discordDeath = new GenericMessageConfig("death", true, "__%USER%__ %MESSAGE%");
|
||||
discordAchievement = new AchievementMessageConfig(true, "Congrats to __%USER%__ for earning the achievement **[%ACHIEVEMENT%]**");
|
||||
discordJoin = new GenericMessageConfig("join", true, "__%USER%__ has joined the server!");
|
||||
discordLeave = new GenericMessageConfig("leave", true, "__%USER%__ left the server!");
|
||||
discordStartup = new GenericMessageConfig("startup", false, "**Server started**");
|
||||
discordShutdown = new GenericMessageConfig("shutdown", false, "**Server shutdown**");
|
||||
discordCrash = new GenericMessageConfig("crash", true, "**Server crash detected**");
|
||||
|
||||
minecraftChat = new DiscordChatMessageConfig(event.getServer(), true, "<__%USER%__> %MESSAGE%");
|
||||
|
||||
load();
|
||||
|
||||
DiscordClient.getInstance().connect(event.getServer());
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
if (config == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!config.exists()) {
|
||||
try {
|
||||
JsonWriter writer = new JsonWriter(new FileWriter(config));
|
||||
|
||||
writer.beginObject();
|
||||
|
||||
writer.name("discord");
|
||||
writer.beginObject();
|
||||
writer.name("token");
|
||||
writer.value(token);
|
||||
writer.name("channel");
|
||||
writer.value(channel);
|
||||
|
||||
writer.name("commands");
|
||||
writer.beginObject();
|
||||
commandOnline.write(writer);
|
||||
commandTps.write(writer);
|
||||
commandUnstuck.write(writer);
|
||||
writer.endObject();
|
||||
writer.endObject();
|
||||
|
||||
writer.name("messages");
|
||||
writer.beginObject();
|
||||
writer.name("discord");
|
||||
writer.beginObject();
|
||||
discordChat.write(writer);
|
||||
discordDeath.write(writer);
|
||||
discordAchievement.write(writer);
|
||||
discordJoin.write(writer);
|
||||
discordLeave.write(writer);
|
||||
discordStartup.write(writer);
|
||||
discordShutdown.write(writer);
|
||||
writer.endObject();
|
||||
|
||||
writer.name("minecraft");
|
||||
writer.beginObject();
|
||||
minecraftChat.write(writer);
|
||||
writer.endObject();
|
||||
writer.endObject();
|
||||
|
||||
writer.name("experimental");
|
||||
writer.beginObject();
|
||||
writer.name("fakePlayers");
|
||||
writer.value(experimentalFakePlayers);
|
||||
writer.endObject();
|
||||
|
||||
writer.endObject();
|
||||
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
ChikachiDiscord.Log("Error generating default config file", true);
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
JsonReader reader = new JsonReader(new FileReader(config));
|
||||
String name;
|
||||
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("discord") && reader.peek() == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("token") && reader.peek() == JsonToken.STRING) {
|
||||
token = reader.nextString();
|
||||
} else if (name.equalsIgnoreCase("channel") && reader.peek() == JsonToken.STRING) {
|
||||
channel = reader.nextString();
|
||||
} else if (name.equalsIgnoreCase("commands") && reader.peek() == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase(commandOnline.getName())) {
|
||||
commandOnline.read(reader);
|
||||
} else if (name.equalsIgnoreCase(commandTps.getName())) {
|
||||
commandTps.read(reader);
|
||||
} else if (name.equalsIgnoreCase(commandUnstuck.getName())) {
|
||||
commandUnstuck.read(reader);
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} else if (name.equalsIgnoreCase("messages") && reader.peek() == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("discord") && reader.peek() == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("chat")) {
|
||||
discordChat.read(reader);
|
||||
} else if (name.equalsIgnoreCase("death")) {
|
||||
discordDeath.read(reader);
|
||||
} else if (name.equalsIgnoreCase("achievement")) {
|
||||
discordAchievement.read(reader);
|
||||
} else if (name.equalsIgnoreCase("join")) {
|
||||
discordJoin.read(reader);
|
||||
} else if (name.equalsIgnoreCase("leave")) {
|
||||
discordLeave.read(reader);
|
||||
} else if (name.equalsIgnoreCase("startup")) {
|
||||
discordStartup.read(reader);
|
||||
} else if (name.equalsIgnoreCase("shutdown")) {
|
||||
discordShutdown.read(reader);
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} else if (name.equalsIgnoreCase("minecraft") && reader.peek() == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("chat")) {
|
||||
minecraftChat.read(reader);
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} else if (name.equalsIgnoreCase("experimental") && reader.peek() == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("fakePlayers") && reader.peek() == JsonToken.BOOLEAN) {
|
||||
experimentalFakePlayers = reader.nextBoolean();
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public static String getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public static OnlineCommandConfig getCommandOnline() {
|
||||
return commandOnline;
|
||||
}
|
||||
|
||||
public static TpsCommandConfig getCommandTps() {
|
||||
return commandTps;
|
||||
}
|
||||
|
||||
public static UnstuckCommandConfig getCommandUnstuck() {
|
||||
return commandUnstuck;
|
||||
}
|
||||
|
||||
public static boolean isExperimentalFakePlayersEnabled() {
|
||||
return experimentalFakePlayers;
|
||||
}
|
||||
|
||||
public static MinecraftChatMessageConfig getDiscordChat() {
|
||||
return discordChat;
|
||||
}
|
||||
|
||||
public static GenericMessageConfig getDiscordDeath() {
|
||||
return discordDeath;
|
||||
}
|
||||
|
||||
public static AchievementMessageConfig getDiscordAchievement() {
|
||||
return discordAchievement;
|
||||
}
|
||||
|
||||
public static GenericMessageConfig getDiscordJoin() {
|
||||
return discordJoin;
|
||||
}
|
||||
|
||||
public static GenericMessageConfig getDiscordLeave() {
|
||||
return discordLeave;
|
||||
}
|
||||
|
||||
public static GenericMessageConfig getDiscordStartup() {
|
||||
return discordStartup;
|
||||
}
|
||||
|
||||
public static GenericMessageConfig getDiscordShutdown() {
|
||||
return discordShutdown;
|
||||
}
|
||||
|
||||
public static DiscordChatMessageConfig getMinecraftChat() {
|
||||
return minecraftChat;
|
||||
}
|
||||
|
||||
public static GenericMessageConfig getDiscordCrash() {
|
||||
return discordCrash;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,150 +1,150 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.command;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import net.dv8tion.jda.entities.Role;
|
||||
import net.dv8tion.jda.entities.User;
|
||||
import net.dv8tion.jda.events.message.MessageReceivedEvent;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CommandConfig {
|
||||
private String name;
|
||||
private boolean enabled;
|
||||
private List<String> aliases = new ArrayList<>();
|
||||
private List<String> roles = new ArrayList<>();
|
||||
|
||||
CommandConfig(String name) {
|
||||
this(name, true);
|
||||
}
|
||||
|
||||
CommandConfig(String name, boolean defaultEnabled) {
|
||||
this.name = name;
|
||||
this.enabled = defaultEnabled;
|
||||
}
|
||||
|
||||
CommandConfig(String name, boolean defaultEnabled, String... defaultRoles) {
|
||||
this(name, defaultEnabled);
|
||||
Collections.addAll(this.roles, defaultRoles);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public boolean shouldExecute(String command, MessageReceivedEvent event) {
|
||||
return this.isEnabled() && this.checkCommand(command) && this.checkPermission(event);
|
||||
}
|
||||
|
||||
public abstract void execute(MinecraftServer minecraftServer, List<String> args);
|
||||
|
||||
private boolean checkCommand(String command) {
|
||||
return this.name.equalsIgnoreCase(command) || this.aliases.contains(command.toLowerCase());
|
||||
}
|
||||
|
||||
private boolean checkPermission(MessageReceivedEvent event) {
|
||||
if (this.roles.size() == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
User user = event.getAuthor();
|
||||
|
||||
if (user.getId().equals("86368887284719616")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<Role> roles = event.getGuild().getRolesForUser(user);
|
||||
|
||||
for (Role role : roles) {
|
||||
if (this.roles.contains(role.getName().toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void read(JsonReader reader) throws IOException {
|
||||
JsonToken type = reader.peek();
|
||||
|
||||
if (type == JsonToken.BOOLEAN) {
|
||||
this.enabled = reader.nextBoolean();
|
||||
} else if (type == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
String name;
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("enabled") && reader.peek() == JsonToken.BOOLEAN) {
|
||||
this.enabled = reader.nextBoolean();
|
||||
} else if (name.equalsIgnoreCase("roles") && reader.peek() == JsonToken.BEGIN_ARRAY) {
|
||||
this.roles.clear();
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
if (reader.peek() == JsonToken.STRING) {
|
||||
this.roles.add(reader.nextString().toLowerCase());
|
||||
}
|
||||
}
|
||||
reader.endArray();
|
||||
} else if (name.equalsIgnoreCase("aliases") && reader.peek() == JsonToken.BEGIN_ARRAY) {
|
||||
this.aliases.clear();
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
if (reader.peek() == JsonToken.STRING) {
|
||||
this.aliases.add(reader.nextString().toLowerCase());
|
||||
}
|
||||
}
|
||||
reader.endArray();
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JsonWriter writer) throws IOException {
|
||||
writer.name(this.name);
|
||||
writer.beginObject();
|
||||
writer.name("enabled");
|
||||
writer.value(this.enabled);
|
||||
writer.name("roles");
|
||||
writer.beginArray();
|
||||
for (String role : this.roles) {
|
||||
writer.value(role);
|
||||
}
|
||||
writer.endArray();
|
||||
writer.name("aliases");
|
||||
writer.beginArray();
|
||||
for (String alias : this.aliases) {
|
||||
writer.value(alias);
|
||||
}
|
||||
writer.endArray();
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.command;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import net.dv8tion.jda.entities.Role;
|
||||
import net.dv8tion.jda.entities.User;
|
||||
import net.dv8tion.jda.events.message.MessageReceivedEvent;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CommandConfig {
|
||||
private String name;
|
||||
private boolean enabled;
|
||||
private List<String> aliases = new ArrayList<>();
|
||||
private List<String> roles = new ArrayList<>();
|
||||
|
||||
CommandConfig(String name) {
|
||||
this(name, true);
|
||||
}
|
||||
|
||||
CommandConfig(String name, boolean defaultEnabled) {
|
||||
this.name = name;
|
||||
this.enabled = defaultEnabled;
|
||||
}
|
||||
|
||||
CommandConfig(String name, boolean defaultEnabled, String... defaultRoles) {
|
||||
this(name, defaultEnabled);
|
||||
Collections.addAll(this.roles, defaultRoles);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public boolean shouldExecute(String command, MessageReceivedEvent event) {
|
||||
return this.isEnabled() && this.checkCommand(command) && this.checkPermission(event);
|
||||
}
|
||||
|
||||
public abstract void execute(MinecraftServer minecraftServer, List<String> args);
|
||||
|
||||
private boolean checkCommand(String command) {
|
||||
return this.name.equalsIgnoreCase(command) || this.aliases.contains(command.toLowerCase());
|
||||
}
|
||||
|
||||
private boolean checkPermission(MessageReceivedEvent event) {
|
||||
if (this.roles.size() == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
User user = event.getAuthor();
|
||||
|
||||
if (user.getId().equals("86368887284719616")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<Role> roles = event.getGuild().getRolesForUser(user);
|
||||
|
||||
for (Role role : roles) {
|
||||
if (this.roles.contains(role.getName().toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void read(JsonReader reader) throws IOException {
|
||||
JsonToken type = reader.peek();
|
||||
|
||||
if (type == JsonToken.BOOLEAN) {
|
||||
this.enabled = reader.nextBoolean();
|
||||
} else if (type == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
String name;
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("enabled") && reader.peek() == JsonToken.BOOLEAN) {
|
||||
this.enabled = reader.nextBoolean();
|
||||
} else if (name.equalsIgnoreCase("roles") && reader.peek() == JsonToken.BEGIN_ARRAY) {
|
||||
this.roles.clear();
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
if (reader.peek() == JsonToken.STRING) {
|
||||
this.roles.add(reader.nextString().toLowerCase());
|
||||
}
|
||||
}
|
||||
reader.endArray();
|
||||
} else if (name.equalsIgnoreCase("aliases") && reader.peek() == JsonToken.BEGIN_ARRAY) {
|
||||
this.aliases.clear();
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
if (reader.peek() == JsonToken.STRING) {
|
||||
this.aliases.add(reader.nextString().toLowerCase());
|
||||
}
|
||||
}
|
||||
reader.endArray();
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JsonWriter writer) throws IOException {
|
||||
writer.name(this.name);
|
||||
writer.beginObject();
|
||||
writer.name("enabled");
|
||||
writer.value(this.enabled);
|
||||
writer.name("roles");
|
||||
writer.beginArray();
|
||||
for (String role : this.roles) {
|
||||
writer.value(role);
|
||||
}
|
||||
writer.endArray();
|
||||
writer.name("aliases");
|
||||
writer.beginArray();
|
||||
for (String alias : this.aliases) {
|
||||
writer.value(alias);
|
||||
}
|
||||
writer.endArray();
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,71 +1,71 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.command;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
import com.google.common.base.Joiner;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OnlineCommandConfig extends CommandConfig {
|
||||
public OnlineCommandConfig() {
|
||||
super("online");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer minecraftServer, List<String> args) {
|
||||
List<String> playerNames = new ArrayList<>();
|
||||
|
||||
List<EntityPlayerMP> players = minecraftServer.getPlayerList().getPlayerList();
|
||||
|
||||
for (EntityPlayerMP player : players) {
|
||||
String playerName = player.getDisplayNameString();
|
||||
if (playerName.startsWith("@")) {
|
||||
continue;
|
||||
}
|
||||
playerNames.add(playerName);
|
||||
}
|
||||
|
||||
int playersOnline = playerNames.size();
|
||||
if (playersOnline == 0) {
|
||||
DiscordClient.getInstance().sendMessage("No players online");
|
||||
return;
|
||||
}
|
||||
|
||||
if (playersOnline == 1) {
|
||||
DiscordClient.getInstance().sendMessage(
|
||||
String.format(
|
||||
"Currently 1 player online: `%s`",
|
||||
Joiner.on(", ").join(playerNames)
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordClient.getInstance().sendMessage(
|
||||
String.format(
|
||||
"Currently %d players online:\n`%s`",
|
||||
playersOnline,
|
||||
Joiner.on("`, `").join(playerNames)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.command;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
import com.google.common.base.Joiner;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OnlineCommandConfig extends CommandConfig {
|
||||
public OnlineCommandConfig() {
|
||||
super("online");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer minecraftServer, List<String> args) {
|
||||
List<String> playerNames = new ArrayList<>();
|
||||
|
||||
List<EntityPlayerMP> players = minecraftServer.getPlayerList().getPlayerList();
|
||||
|
||||
for (EntityPlayerMP player : players) {
|
||||
String playerName = player.getDisplayNameString();
|
||||
if (playerName.startsWith("@")) {
|
||||
continue;
|
||||
}
|
||||
playerNames.add(playerName);
|
||||
}
|
||||
|
||||
int playersOnline = playerNames.size();
|
||||
if (playersOnline == 0) {
|
||||
DiscordClient.getInstance().sendMessage("No players online");
|
||||
return;
|
||||
}
|
||||
|
||||
if (playersOnline == 1) {
|
||||
DiscordClient.getInstance().sendMessage(
|
||||
String.format(
|
||||
"Currently 1 player online: `%s`",
|
||||
Joiner.on(", ").join(playerNames)
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordClient.getInstance().sendMessage(
|
||||
String.format(
|
||||
"Currently %d players online:\n`%s`",
|
||||
playersOnline,
|
||||
Joiner.on("`, `").join(playerNames)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,170 +1,177 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.command;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
import com.google.common.base.Joiner;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
public class TpsCommandConfig extends CommandConfig {
|
||||
private static final DecimalFormat timeFormatter = new DecimalFormat("########0.000");
|
||||
|
||||
public TpsCommandConfig() {
|
||||
super("tps", false);
|
||||
}
|
||||
|
||||
private Integer getMinValue(Set<Integer> values) {
|
||||
if (values.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Integer value = null;
|
||||
for (Integer val : values) {
|
||||
if (value == null) {
|
||||
value = val;
|
||||
} else if (val < value) {
|
||||
value = val;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private Integer getMaxValue(Set<Integer> values) {
|
||||
if (values.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Integer value = null;
|
||||
for (Integer val : values) {
|
||||
if (value == null) {
|
||||
value = val;
|
||||
} else if (value < val) {
|
||||
value = val;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private Integer getMinLength(Collection<String> strings) {
|
||||
if (strings.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Integer length = null;
|
||||
for (String string : strings) {
|
||||
int stringLength = string.length();
|
||||
if (length == null) {
|
||||
length = stringLength;
|
||||
} else if (stringLength < length) {
|
||||
length = stringLength;
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
private Integer getMaxLength(Collection<String> strings) {
|
||||
if (strings.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Integer length = null;
|
||||
for (String string : strings) {
|
||||
int stringLength = string.length();
|
||||
if (length == null) {
|
||||
length = stringLength;
|
||||
} else if (length < stringLength) {
|
||||
length = stringLength;
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer minecraftServer, List<String> args) {
|
||||
List<String> tpsTimes = new ArrayList<>();
|
||||
|
||||
Integer[] dimensionIds = DimensionManager.getIDs();
|
||||
HashMap<Integer, String> dimensionMap = new HashMap<>();
|
||||
|
||||
for (Integer dimensionId : dimensionIds) {
|
||||
dimensionMap.put(dimensionId, DimensionManager.getProviderType(dimensionId).getName());
|
||||
}
|
||||
|
||||
int maxDimensionIdLength = Math.max(getMinValue(dimensionMap.keySet()).toString().length(), getMaxValue(dimensionMap.keySet()).toString().length());
|
||||
int maxDimensionNameLength = Math.max(getMinLength(dimensionMap.values()), getMaxLength(dimensionMap.values()));
|
||||
|
||||
Set<Map.Entry<Integer, String>> entries = dimensionMap.entrySet();
|
||||
|
||||
for (Map.Entry<Integer, String> entry : entries) {
|
||||
Integer dimensionId = entry.getKey();
|
||||
String dimensionName = entry.getValue();
|
||||
|
||||
String dimensionIdPrefixString = new String(new char[maxDimensionIdLength - dimensionId.toString().length()]).replace("\0", " ");
|
||||
String dimensionNamePostfixString = new String(new char[maxDimensionNameLength - dimensionName.length()]).replace("\0", " ");
|
||||
|
||||
double worldTickTime = this.mean(minecraftServer.worldTickTimes.get(dimensionId)) * 1.0E-6D;
|
||||
double worldTPS = Math.min(1000.0 / worldTickTime, 20);
|
||||
|
||||
tpsTimes.add(
|
||||
String.format(
|
||||
"%s : Mean tick time: %s ms. Mean TPS: %s",
|
||||
String.format(
|
||||
"Dim %s%d (%s)%s",
|
||||
dimensionIdPrefixString,
|
||||
dimensionId,
|
||||
dimensionName,
|
||||
dimensionNamePostfixString
|
||||
),
|
||||
timeFormatter.format(worldTickTime),
|
||||
timeFormatter.format(worldTPS)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
double meanTickTime = this.mean(minecraftServer.tickTimeArray) * 1.0E-6D;
|
||||
double meanTPS = Math.min(1000.0 / meanTickTime, 20);
|
||||
tpsTimes.add(
|
||||
String.format(
|
||||
"%s : Mean tick time: %s ms. Mean TPS: %s",
|
||||
String.format(
|
||||
"Overall%s",
|
||||
new String(new char[maxDimensionIdLength + maxDimensionNameLength]).replace("\0", " ")
|
||||
),
|
||||
timeFormatter.format(meanTickTime),
|
||||
timeFormatter.format(meanTPS)
|
||||
)
|
||||
);
|
||||
|
||||
DiscordClient.getInstance().sendMessage(
|
||||
String.format(
|
||||
"\n```\n%s\n```",
|
||||
Joiner.on("\n").join(tpsTimes)
|
||||
).replace("\\:", ":")
|
||||
);
|
||||
}
|
||||
|
||||
private long mean(long[] values) {
|
||||
return LongStream.of(values).sum() / values.length;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.command;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
import com.google.common.base.Joiner;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
public class TpsCommandConfig extends CommandConfig {
|
||||
private static final DecimalFormat timeFormatter = new DecimalFormat("########0.000");
|
||||
|
||||
public TpsCommandConfig() {
|
||||
super("tps", false);
|
||||
}
|
||||
|
||||
private static String padLeft(String s, int n) {
|
||||
return String.format("%1$#" + n + "s", s);
|
||||
}
|
||||
|
||||
private static String padRight(String s, int n) {
|
||||
return String.format("%1$-" + n + "s", s);
|
||||
}
|
||||
|
||||
private static Integer getMinValue(Set<Integer> values) {
|
||||
if (values.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Integer value = null;
|
||||
for (Integer val : values) {
|
||||
if (value == null) {
|
||||
value = val;
|
||||
} else if (val < value) {
|
||||
value = val;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static Integer getMaxValue(Set<Integer> values) {
|
||||
if (values.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Integer value = null;
|
||||
for (Integer val : values) {
|
||||
if (value == null) {
|
||||
value = val;
|
||||
} else if (value < val) {
|
||||
value = val;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static Integer getMinLength(Collection<String> strings) {
|
||||
if (strings.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Integer length = null;
|
||||
for (String string : strings) {
|
||||
int stringLength = string.length();
|
||||
if (length == null) {
|
||||
length = stringLength;
|
||||
} else if (stringLength < length) {
|
||||
length = stringLength;
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
private static Integer getMaxLength(Collection<String> strings) {
|
||||
if (strings.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Integer length = null;
|
||||
for (String string : strings) {
|
||||
int stringLength = string.length();
|
||||
if (length == null) {
|
||||
length = stringLength;
|
||||
} else if (length < stringLength) {
|
||||
length = stringLength;
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer minecraftServer, List<String> args) {
|
||||
List<String> tpsTimes = new ArrayList<>();
|
||||
|
||||
Integer[] dimensionIds = DimensionManager.getIDs();
|
||||
HashMap<Integer, String> dimensionMap = new HashMap<>();
|
||||
|
||||
for (Integer dimensionId : dimensionIds) {
|
||||
dimensionMap.put(dimensionId, DimensionManager.getProviderType(dimensionId).getName());
|
||||
}
|
||||
|
||||
int maxDimensionIdLength = Math.max(getMinValue(dimensionMap.keySet()).toString().length(), getMaxValue(dimensionMap.keySet()).toString().length());
|
||||
int maxDimensionNameLength = Math.max(getMinLength(dimensionMap.values()), getMaxLength(dimensionMap.values()));
|
||||
|
||||
Set<Map.Entry<Integer, String>> entries = dimensionMap.entrySet();
|
||||
|
||||
for (Map.Entry<Integer, String> entry : entries) {
|
||||
Integer dimensionId = entry.getKey();
|
||||
String dimensionName = entry.getValue();
|
||||
|
||||
String dimensionIdPrefixString = new String(new char[maxDimensionIdLength - dimensionId.toString().length()]).replace("\0", " ");
|
||||
String dimensionNamePostfixString = new String(new char[maxDimensionNameLength - dimensionName.length()]).replace("\0", " ");
|
||||
|
||||
double worldTickTime = this.mean(minecraftServer.worldTickTimes.get(dimensionId)) * 1.0E-6D;
|
||||
double worldTPS = Math.min(1000.0 / worldTickTime, 20);
|
||||
|
||||
tpsTimes.add(
|
||||
String.format(
|
||||
"%s : Mean tick time: %s ms. Mean TPS: %s",
|
||||
String.format(
|
||||
"Dim %s%d (%s)%s",
|
||||
dimensionIdPrefixString,
|
||||
dimensionId,
|
||||
dimensionName,
|
||||
dimensionNamePostfixString
|
||||
),
|
||||
timeFormatter.format(worldTickTime),
|
||||
timeFormatter.format(worldTPS)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
double meanTickTime = this.mean(minecraftServer.tickTimeArray) * 1.0E-6D;
|
||||
double meanTPS = Math.min(1000.0 / meanTickTime, 20);
|
||||
tpsTimes.add(
|
||||
String.format(
|
||||
"%s : Mean tick time: %s ms. Mean TPS: %s",
|
||||
String.format(
|
||||
"Overall%s",
|
||||
new String(new char[maxDimensionIdLength + maxDimensionNameLength]).replace("\0", " ")
|
||||
),
|
||||
timeFormatter.format(meanTickTime),
|
||||
timeFormatter.format(meanTPS)
|
||||
)
|
||||
);
|
||||
|
||||
DiscordClient.getInstance().sendMessage(
|
||||
String.format(
|
||||
"\n```\n%s\n```",
|
||||
Joiner.on("\n").join(tpsTimes)
|
||||
).replace("\\:", ":")
|
||||
);
|
||||
}
|
||||
|
||||
private long mean(long[] values) {
|
||||
return LongStream.of(values).sum() / values.length;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,111 +1,111 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.command;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
import chikachi.discord.DiscordTeleporter;
|
||||
import chikachi.discord.config.experimental.DiscordFakePlayer;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.management.PlayerList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.storage.IPlayerFileData;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UnstuckCommandConfig extends CommandConfig {
|
||||
public UnstuckCommandConfig() {
|
||||
super("unstuck", false, "AdminRoleHere");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer minecraftServer, List<String> args) {
|
||||
if (args.size() == 0) {
|
||||
DiscordClient.getInstance().sendMessage("Missing player");
|
||||
return;
|
||||
}
|
||||
String playerName = args.remove(0);
|
||||
if (playerName.length() == 0) {
|
||||
DiscordClient.getInstance().sendMessage("Missing player");
|
||||
return;
|
||||
}
|
||||
|
||||
WorldServer overworld = DimensionManager.getWorld(0);
|
||||
BlockPos spawnpoint = overworld.getSpawnPoint();
|
||||
IBlockState blockState = overworld.getBlockState(spawnpoint);
|
||||
|
||||
while (blockState.getBlock().isOpaqueCube(blockState)) {
|
||||
spawnpoint = spawnpoint.up(2);
|
||||
blockState = overworld.getBlockState(spawnpoint);
|
||||
}
|
||||
|
||||
double x = spawnpoint.getX() + 0.5;
|
||||
double y = spawnpoint.getY();
|
||||
double z = spawnpoint.getZ() + 0.5;
|
||||
|
||||
PlayerList playerList = minecraftServer.getPlayerList();
|
||||
EntityPlayerMP playerEntity = playerList.getPlayerByUsername(playerName);
|
||||
|
||||
if (playerEntity != null) {
|
||||
int fromDimId = playerEntity.dimension;
|
||||
|
||||
if (fromDimId != 0) {
|
||||
playerList.transferPlayerToDimension(playerEntity, 0, new DiscordTeleporter(overworld));
|
||||
|
||||
if (fromDimId == 1 && playerEntity.isEntityAlive()) {
|
||||
overworld.spawnEntityInWorld(playerEntity);
|
||||
overworld.updateEntityWithOptionalForce(playerEntity, false);
|
||||
}
|
||||
}
|
||||
|
||||
playerEntity.setPositionAndUpdate(x, y, z);
|
||||
playerEntity.connection.kickPlayerFromServer("You are getting sent to spawn, please connect again!");
|
||||
} else {
|
||||
GameProfile playerProfile = minecraftServer.getPlayerProfileCache().getGameProfileForUsername(playerName);
|
||||
|
||||
if (playerProfile == null || !playerProfile.isComplete()) {
|
||||
DiscordClient.getInstance().sendMessage("Player not found");
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordFakePlayer fakePlayer = new DiscordFakePlayer(minecraftServer.worldServers[0], playerProfile);
|
||||
IPlayerFileData saveHandler = minecraftServer.worldServers[0].getSaveHandler().getPlayerNBTManager();
|
||||
NBTTagCompound playerData = saveHandler.readPlayerData(fakePlayer);
|
||||
|
||||
if (playerData == null) {
|
||||
DiscordClient.getInstance().sendMessage("Player not found on server");
|
||||
return;
|
||||
}
|
||||
|
||||
fakePlayer.posX = x;
|
||||
fakePlayer.posY = y;
|
||||
fakePlayer.posZ = z;
|
||||
|
||||
fakePlayer.dimension = 0;
|
||||
|
||||
saveHandler.writePlayerData(fakePlayer);
|
||||
}
|
||||
|
||||
DiscordClient.getInstance().sendMessage("Player sent to spawn");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.command;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
import chikachi.discord.DiscordTeleporter;
|
||||
import chikachi.discord.config.experimental.DiscordFakePlayer;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.management.PlayerList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.storage.IPlayerFileData;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UnstuckCommandConfig extends CommandConfig {
|
||||
public UnstuckCommandConfig() {
|
||||
super("unstuck", false, "AdminRoleHere");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer minecraftServer, List<String> args) {
|
||||
if (args.size() == 0) {
|
||||
DiscordClient.getInstance().sendMessage("Missing player");
|
||||
return;
|
||||
}
|
||||
String playerName = args.remove(0);
|
||||
if (playerName.length() == 0) {
|
||||
DiscordClient.getInstance().sendMessage("Missing player");
|
||||
return;
|
||||
}
|
||||
|
||||
WorldServer overworld = DimensionManager.getWorld(0);
|
||||
BlockPos spawnpoint = overworld.getSpawnPoint();
|
||||
IBlockState blockState = overworld.getBlockState(spawnpoint);
|
||||
|
||||
while (blockState.getBlock().isOpaqueCube(blockState)) {
|
||||
spawnpoint = spawnpoint.up(2);
|
||||
blockState = overworld.getBlockState(spawnpoint);
|
||||
}
|
||||
|
||||
double x = spawnpoint.getX() + 0.5;
|
||||
double y = spawnpoint.getY();
|
||||
double z = spawnpoint.getZ() + 0.5;
|
||||
|
||||
PlayerList playerList = minecraftServer.getPlayerList();
|
||||
EntityPlayerMP playerEntity = playerList.getPlayerByUsername(playerName);
|
||||
|
||||
if (playerEntity != null) {
|
||||
int fromDimId = playerEntity.dimension;
|
||||
|
||||
if (fromDimId != 0) {
|
||||
playerList.transferPlayerToDimension(playerEntity, 0, new DiscordTeleporter(overworld));
|
||||
|
||||
if (fromDimId == 1 && playerEntity.isEntityAlive()) {
|
||||
overworld.spawnEntityInWorld(playerEntity);
|
||||
overworld.updateEntityWithOptionalForce(playerEntity, false);
|
||||
}
|
||||
}
|
||||
|
||||
playerEntity.setPositionAndUpdate(x, y, z);
|
||||
playerEntity.connection.kickPlayerFromServer("You are getting sent to spawn, please connect again!");
|
||||
} else {
|
||||
GameProfile playerProfile = minecraftServer.getPlayerProfileCache().getGameProfileForUsername(playerName);
|
||||
|
||||
if (playerProfile == null || !playerProfile.isComplete()) {
|
||||
DiscordClient.getInstance().sendMessage("Player not found");
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordFakePlayer fakePlayer = new DiscordFakePlayer(minecraftServer.worldServers[0], playerProfile);
|
||||
IPlayerFileData saveHandler = minecraftServer.worldServers[0].getSaveHandler().getPlayerNBTManager();
|
||||
NBTTagCompound playerData = saveHandler.readPlayerData(fakePlayer);
|
||||
|
||||
if (playerData == null) {
|
||||
DiscordClient.getInstance().sendMessage("Player not found on server");
|
||||
return;
|
||||
}
|
||||
|
||||
fakePlayer.posX = x;
|
||||
fakePlayer.posY = y;
|
||||
fakePlayer.posZ = z;
|
||||
|
||||
fakePlayer.dimension = 0;
|
||||
|
||||
saveHandler.writePlayerData(fakePlayer);
|
||||
}
|
||||
|
||||
DiscordClient.getInstance().sendMessage("Player sent to spawn");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,73 +1,73 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.experimental;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.client.*;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
class DiscordFakeNetServerHandler extends NetHandlerPlayServer {
|
||||
DiscordFakeNetServerHandler(MinecraftServer minecraftServer, NetworkManager networkManager, EntityPlayerMP player) {
|
||||
super(minecraftServer, networkManager, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(Packet packet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kickPlayerFromServer(String reason) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processKeepAlive(CPacketKeepAlive packet) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleResourcePackStatus(CPacketResourcePackStatus packet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processClickWindow(CPacketClickWindow packet) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processPlayerBlockPlacement(CPacketPlayerTryUseItem packet) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCustomPayload(CPacketCustomPayload packet) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.experimental;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.client.*;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
class DiscordFakeNetServerHandler extends NetHandlerPlayServer {
|
||||
DiscordFakeNetServerHandler(MinecraftServer minecraftServer, NetworkManager networkManager, EntityPlayerMP player) {
|
||||
super(minecraftServer, networkManager, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(Packet packet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kickPlayerFromServer(String reason) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processKeepAlive(CPacketKeepAlive packet) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleResourcePackStatus(CPacketResourcePackStatus packet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processClickWindow(CPacketClickWindow packet) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processPlayerBlockPlacement(CPacketPlayerTryUseItem packet) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCustomPayload(CPacketCustomPayload packet) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,41 +1,41 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.experimental;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.dv8tion.jda.entities.User;
|
||||
import net.minecraft.network.EnumPacketDirection;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class DiscordFakePlayer extends FakePlayer {
|
||||
public DiscordFakePlayer(WorldServer world, GameProfile name) {
|
||||
super(world, name);
|
||||
this.connection = new DiscordFakeNetServerHandler(world.getMinecraftServer(), new NetworkManager(EnumPacketDirection.SERVERBOUND), this);
|
||||
}
|
||||
|
||||
DiscordFakePlayer(MinecraftServer minecraftServer, User user) {
|
||||
this(minecraftServer.worldServers[0], new GameProfile(UUID.randomUUID(), "@" + user.getUsername()));
|
||||
|
||||
this.dimension = Integer.MIN_VALUE;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.experimental;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.dv8tion.jda.entities.User;
|
||||
import net.minecraft.network.EnumPacketDirection;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class DiscordFakePlayer extends FakePlayer {
|
||||
public DiscordFakePlayer(WorldServer world, GameProfile name) {
|
||||
super(world, name);
|
||||
this.connection = new DiscordFakeNetServerHandler(world.getMinecraftServer(), new NetworkManager(EnumPacketDirection.SERVERBOUND), this);
|
||||
}
|
||||
|
||||
DiscordFakePlayer(MinecraftServer minecraftServer, User user) {
|
||||
this(minecraftServer.worldServers[0], new GameProfile(UUID.randomUUID(), "@" + user.getUsername()));
|
||||
|
||||
this.dimension = Integer.MIN_VALUE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,97 +1,97 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.experimental;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
import chikachi.discord.config.Configuration;
|
||||
import net.dv8tion.jda.OnlineStatus;
|
||||
import net.dv8tion.jda.entities.TextChannel;
|
||||
import net.dv8tion.jda.entities.User;
|
||||
import net.dv8tion.jda.events.ReadyEvent;
|
||||
import net.dv8tion.jda.events.user.UserOnlineStatusUpdateEvent;
|
||||
import net.dv8tion.jda.hooks.ListenerAdapter;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class ExperimentalDiscordListener extends ListenerAdapter {
|
||||
private final MinecraftServer minecraftServer;
|
||||
private HashMap<String, FakePlayer> fakePlayers = new HashMap<>();
|
||||
|
||||
public ExperimentalDiscordListener(MinecraftServer minecraftServer) {
|
||||
this.minecraftServer = minecraftServer;
|
||||
}
|
||||
|
||||
private void userOnline(User user) {
|
||||
if (user == null) return;
|
||||
if (user.getOnlineStatus() == OnlineStatus.OFFLINE) return;
|
||||
if (!Configuration.isExperimentalFakePlayersEnabled()) return;
|
||||
|
||||
DiscordFakePlayer discordFakePlayer = new DiscordFakePlayer(this.minecraftServer, user);
|
||||
|
||||
this.minecraftServer.getPlayerList().playerLoggedIn(discordFakePlayer);
|
||||
|
||||
fakePlayers.put(user.getUsername(), discordFakePlayer);
|
||||
}
|
||||
|
||||
private void userOffline(User user) {
|
||||
if (user == null) return;
|
||||
if (user.getOnlineStatus() != OnlineStatus.OFFLINE) return;
|
||||
if (!Configuration.isExperimentalFakePlayersEnabled()) return;
|
||||
|
||||
if (fakePlayers.containsKey(user.getUsername())) {
|
||||
FakePlayer fakePlayer = fakePlayers.get(user.getUsername());
|
||||
if (fakePlayer != null) {
|
||||
this.minecraftServer.getPlayerList().playerLoggedOut(fakePlayer);
|
||||
fakePlayers.remove(user.getUsername());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady(ReadyEvent event) {
|
||||
DiscordClient client = DiscordClient.getInstance();
|
||||
|
||||
TextChannel channel = client.getChannel();
|
||||
if (channel == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Configuration.isExperimentalFakePlayersEnabled()) {
|
||||
List<User> users = channel.getUsers();
|
||||
users.forEach(this::userOnline);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserOnlineStatusUpdate(UserOnlineStatusUpdateEvent event) {
|
||||
if (!Configuration.isExperimentalFakePlayersEnabled()) return;
|
||||
|
||||
User user = event.getUser();
|
||||
OnlineStatus before = event.getPreviousOnlineStatus();
|
||||
OnlineStatus now = user.getOnlineStatus();
|
||||
|
||||
if (before == OnlineStatus.OFFLINE && now != OnlineStatus.OFFLINE) {
|
||||
userOnline(user);
|
||||
} else if (before != OnlineStatus.OFFLINE && now == OnlineStatus.OFFLINE) {
|
||||
userOffline(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.experimental;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
import chikachi.discord.config.Configuration;
|
||||
import net.dv8tion.jda.OnlineStatus;
|
||||
import net.dv8tion.jda.entities.TextChannel;
|
||||
import net.dv8tion.jda.entities.User;
|
||||
import net.dv8tion.jda.events.ReadyEvent;
|
||||
import net.dv8tion.jda.events.user.UserOnlineStatusUpdateEvent;
|
||||
import net.dv8tion.jda.hooks.ListenerAdapter;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class ExperimentalDiscordListener extends ListenerAdapter {
|
||||
private final MinecraftServer minecraftServer;
|
||||
private HashMap<String, FakePlayer> fakePlayers = new HashMap<>();
|
||||
|
||||
public ExperimentalDiscordListener(MinecraftServer minecraftServer) {
|
||||
this.minecraftServer = minecraftServer;
|
||||
}
|
||||
|
||||
private void userOnline(User user) {
|
||||
if (user == null) return;
|
||||
if (user.getOnlineStatus() == OnlineStatus.OFFLINE) return;
|
||||
if (!Configuration.isExperimentalFakePlayersEnabled()) return;
|
||||
|
||||
DiscordFakePlayer discordFakePlayer = new DiscordFakePlayer(this.minecraftServer, user);
|
||||
|
||||
this.minecraftServer.getPlayerList().playerLoggedIn(discordFakePlayer);
|
||||
|
||||
fakePlayers.put(user.getUsername(), discordFakePlayer);
|
||||
}
|
||||
|
||||
private void userOffline(User user) {
|
||||
if (user == null) return;
|
||||
if (user.getOnlineStatus() != OnlineStatus.OFFLINE) return;
|
||||
if (!Configuration.isExperimentalFakePlayersEnabled()) return;
|
||||
|
||||
if (fakePlayers.containsKey(user.getUsername())) {
|
||||
FakePlayer fakePlayer = fakePlayers.get(user.getUsername());
|
||||
if (fakePlayer != null) {
|
||||
this.minecraftServer.getPlayerList().playerLoggedOut(fakePlayer);
|
||||
fakePlayers.remove(user.getUsername());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady(ReadyEvent event) {
|
||||
DiscordClient client = DiscordClient.getInstance();
|
||||
|
||||
TextChannel channel = client.getChannel();
|
||||
if (channel == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Configuration.isExperimentalFakePlayersEnabled()) {
|
||||
List<User> users = channel.getUsers();
|
||||
users.forEach(this::userOnline);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserOnlineStatusUpdate(UserOnlineStatusUpdateEvent event) {
|
||||
if (!Configuration.isExperimentalFakePlayersEnabled()) return;
|
||||
|
||||
User user = event.getUser();
|
||||
OnlineStatus before = event.getPreviousOnlineStatus();
|
||||
OnlineStatus now = user.getOnlineStatus();
|
||||
|
||||
if (before == OnlineStatus.OFFLINE && now != OnlineStatus.OFFLINE) {
|
||||
userOnline(user);
|
||||
} else if (before != OnlineStatus.OFFLINE && now == OnlineStatus.OFFLINE) {
|
||||
userOffline(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,91 +1,91 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.listener;
|
||||
|
||||
import chikachi.discord.ChikachiDiscord;
|
||||
import chikachi.discord.DiscordClient;
|
||||
import chikachi.discord.config.Configuration;
|
||||
import chikachi.discord.config.message.DiscordChatMessageConfig;
|
||||
import net.dv8tion.jda.entities.TextChannel;
|
||||
import net.dv8tion.jda.events.ReadyEvent;
|
||||
import net.dv8tion.jda.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.hooks.ListenerAdapter;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class DiscordListener extends ListenerAdapter {
|
||||
private final MinecraftServer minecraftServer;
|
||||
|
||||
public DiscordListener(MinecraftServer minecraftServer) {
|
||||
this.minecraftServer = minecraftServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady(ReadyEvent event) {
|
||||
ChikachiDiscord.Log("Logged in as " + event.getJDA().getSelfInfo().getUsername());
|
||||
|
||||
DiscordClient client = DiscordClient.getInstance();
|
||||
|
||||
List<String> queue = client.queue;
|
||||
queue.forEach(client::sendMessage);
|
||||
client.queue.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
// Ignore bots
|
||||
if (event.getAuthor().isBot()) return;
|
||||
// Ignore private messages
|
||||
if (!(event.getChannel() instanceof TextChannel)) return;
|
||||
// Ignore other channels
|
||||
if (!event.getMessage().getChannelId().equals(Configuration.getChannel())) return;
|
||||
|
||||
String content = event.getMessage().getContent().trim();
|
||||
|
||||
if (content.startsWith("!")) {
|
||||
List<String> args = new ArrayList<>(Arrays.asList(content.substring(1).split(" ")));
|
||||
String cmd = args.remove(0);
|
||||
|
||||
// Online
|
||||
if (Configuration.getCommandOnline().shouldExecute(cmd, event)) {
|
||||
Configuration.getCommandOnline().execute(this.minecraftServer, args);
|
||||
return;
|
||||
}
|
||||
|
||||
// TPS
|
||||
if (Configuration.getCommandTps().shouldExecute(cmd, event)) {
|
||||
Configuration.getCommandTps().execute(this.minecraftServer, args);
|
||||
return;
|
||||
}
|
||||
|
||||
// Unstuck
|
||||
if (Configuration.getCommandUnstuck().shouldExecute(cmd, event)) {
|
||||
Configuration.getCommandUnstuck().execute(this.minecraftServer, args);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordChatMessageConfig messageConfig = Configuration.getMinecraftChat();
|
||||
messageConfig.handleEvent(event);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.listener;
|
||||
|
||||
import chikachi.discord.ChikachiDiscord;
|
||||
import chikachi.discord.DiscordClient;
|
||||
import chikachi.discord.config.Configuration;
|
||||
import chikachi.discord.config.message.DiscordChatMessageConfig;
|
||||
import net.dv8tion.jda.entities.TextChannel;
|
||||
import net.dv8tion.jda.events.ReadyEvent;
|
||||
import net.dv8tion.jda.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.hooks.ListenerAdapter;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class DiscordListener extends ListenerAdapter {
|
||||
private final MinecraftServer minecraftServer;
|
||||
|
||||
public DiscordListener(MinecraftServer minecraftServer) {
|
||||
this.minecraftServer = minecraftServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady(ReadyEvent event) {
|
||||
ChikachiDiscord.Log("Logged in as " + event.getJDA().getSelfInfo().getUsername());
|
||||
|
||||
DiscordClient client = DiscordClient.getInstance();
|
||||
|
||||
List<String> queue = client.queue;
|
||||
queue.forEach(client::sendMessage);
|
||||
client.queue.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
// Ignore bots
|
||||
if (event.getAuthor().isBot()) return;
|
||||
// Ignore private messages
|
||||
if (!(event.getChannel() instanceof TextChannel)) return;
|
||||
// Ignore other channels
|
||||
if (!event.getMessage().getChannelId().equals(Configuration.getChannel())) return;
|
||||
|
||||
String content = event.getMessage().getContent().trim();
|
||||
|
||||
if (content.startsWith("!")) {
|
||||
List<String> args = new ArrayList<>(Arrays.asList(content.substring(1).split(" ")));
|
||||
String cmd = args.remove(0);
|
||||
|
||||
// Online
|
||||
if (Configuration.getCommandOnline().shouldExecute(cmd, event)) {
|
||||
Configuration.getCommandOnline().execute(this.minecraftServer, args);
|
||||
return;
|
||||
}
|
||||
|
||||
// TPS
|
||||
if (Configuration.getCommandTps().shouldExecute(cmd, event)) {
|
||||
Configuration.getCommandTps().execute(this.minecraftServer, args);
|
||||
return;
|
||||
}
|
||||
|
||||
// Unstuck
|
||||
if (Configuration.getCommandUnstuck().shouldExecute(cmd, event)) {
|
||||
Configuration.getCommandUnstuck().execute(this.minecraftServer, args);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordChatMessageConfig messageConfig = Configuration.getMinecraftChat();
|
||||
messageConfig.handleEvent(event);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,104 +1,104 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.listener;
|
||||
|
||||
import chikachi.discord.config.Configuration;
|
||||
import chikachi.discord.config.message.AchievementMessageConfig;
|
||||
import chikachi.discord.config.message.GenericMessageConfig;
|
||||
import chikachi.discord.config.message.MinecraftChatMessageConfig;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.stats.StatisticsManagerServer;
|
||||
import net.minecraftforge.event.CommandEvent;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.player.AchievementEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
||||
|
||||
public class MinecraftListener {
|
||||
@SubscribeEvent
|
||||
public void onCommand(CommandEvent event) {
|
||||
String commandName = event.getCommand().getCommandName();
|
||||
|
||||
if (commandName.equalsIgnoreCase("say")) {
|
||||
MinecraftChatMessageConfig messageConfig = Configuration.getDiscordChat();
|
||||
messageConfig.handleCommandEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onChatMessage(ServerChatEvent event) {
|
||||
if (event.getPlayer() == null) return;
|
||||
|
||||
MinecraftChatMessageConfig messageConfig = Configuration.getDiscordChat();
|
||||
messageConfig.handleChatEvent(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerDeath(LivingDeathEvent event) {
|
||||
EntityLivingBase entityLiving = event.getEntityLiving();
|
||||
|
||||
if (entityLiving == null) return;
|
||||
|
||||
if (entityLiving instanceof EntityPlayer) {
|
||||
EntityPlayer entityPlayer = (EntityPlayer) entityLiving;
|
||||
|
||||
GenericMessageConfig messageConfig = Configuration.getDiscordDeath();
|
||||
messageConfig.sendMessage(
|
||||
entityPlayer.getDisplayNameString(),
|
||||
entityPlayer.getCombatTracker().getDeathMessage().getUnformattedText().replace(entityPlayer.getDisplayNameString(), "").trim()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerAchievement(AchievementEvent event) {
|
||||
EntityPlayer entityPlayer = event.getEntityPlayer();
|
||||
|
||||
if (entityPlayer == null) return;
|
||||
|
||||
if (entityPlayer instanceof EntityPlayerMP) {
|
||||
StatisticsManagerServer playerStats = ((EntityPlayerMP) entityPlayer).getStatFile();
|
||||
|
||||
if (playerStats.hasAchievementUnlocked(event.getAchievement()) || !playerStats.canUnlockAchievement(event.getAchievement())) {
|
||||
return;
|
||||
}
|
||||
|
||||
AchievementMessageConfig messageConfig = Configuration.getDiscordAchievement();
|
||||
messageConfig.handleEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
if (event.player == null) return;
|
||||
|
||||
GenericMessageConfig messageConfig = Configuration.getDiscordJoin();
|
||||
messageConfig.sendMessage(event.player.getDisplayNameString());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLeave(PlayerEvent.PlayerLoggedOutEvent event) {
|
||||
if (event.player == null) return;
|
||||
|
||||
GenericMessageConfig messageConfig = Configuration.getDiscordLeave();
|
||||
messageConfig.sendMessage(event.player.getDisplayNameString());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.listener;
|
||||
|
||||
import chikachi.discord.config.Configuration;
|
||||
import chikachi.discord.config.message.AchievementMessageConfig;
|
||||
import chikachi.discord.config.message.GenericMessageConfig;
|
||||
import chikachi.discord.config.message.MinecraftChatMessageConfig;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.stats.StatisticsManagerServer;
|
||||
import net.minecraftforge.event.CommandEvent;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.player.AchievementEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
||||
|
||||
public class MinecraftListener {
|
||||
@SubscribeEvent
|
||||
public void onCommand(CommandEvent event) {
|
||||
String commandName = event.getCommand().getCommandName();
|
||||
|
||||
if (commandName.equalsIgnoreCase("say")) {
|
||||
MinecraftChatMessageConfig messageConfig = Configuration.getDiscordChat();
|
||||
messageConfig.handleCommandEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onChatMessage(ServerChatEvent event) {
|
||||
if (event.getPlayer() == null) return;
|
||||
|
||||
MinecraftChatMessageConfig messageConfig = Configuration.getDiscordChat();
|
||||
messageConfig.handleChatEvent(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerDeath(LivingDeathEvent event) {
|
||||
EntityLivingBase entityLiving = event.getEntityLiving();
|
||||
|
||||
if (entityLiving == null) return;
|
||||
|
||||
if (entityLiving instanceof EntityPlayer) {
|
||||
EntityPlayer entityPlayer = (EntityPlayer) entityLiving;
|
||||
|
||||
GenericMessageConfig messageConfig = Configuration.getDiscordDeath();
|
||||
messageConfig.sendMessage(
|
||||
entityPlayer.getDisplayNameString(),
|
||||
entityPlayer.getCombatTracker().getDeathMessage().getUnformattedText().replace(entityPlayer.getDisplayNameString(), "").trim()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerAchievement(AchievementEvent event) {
|
||||
EntityPlayer entityPlayer = event.getEntityPlayer();
|
||||
|
||||
if (entityPlayer == null) return;
|
||||
|
||||
if (entityPlayer instanceof EntityPlayerMP) {
|
||||
StatisticsManagerServer playerStats = ((EntityPlayerMP) entityPlayer).getStatFile();
|
||||
|
||||
if (playerStats.hasAchievementUnlocked(event.getAchievement()) || !playerStats.canUnlockAchievement(event.getAchievement())) {
|
||||
return;
|
||||
}
|
||||
|
||||
AchievementMessageConfig messageConfig = Configuration.getDiscordAchievement();
|
||||
messageConfig.handleEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
if (event.player == null) return;
|
||||
|
||||
GenericMessageConfig messageConfig = Configuration.getDiscordJoin();
|
||||
messageConfig.sendMessage(event.player.getDisplayNameString());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLeave(PlayerEvent.PlayerLoggedOutEvent event) {
|
||||
if (event.player == null) return;
|
||||
|
||||
GenericMessageConfig messageConfig = Configuration.getDiscordLeave();
|
||||
messageConfig.sendMessage(event.player.getDisplayNameString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,39 +1,39 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.message;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
import net.minecraftforge.event.entity.player.AchievementEvent;
|
||||
|
||||
public class AchievementMessageConfig extends BaseMessageConfig {
|
||||
public AchievementMessageConfig(boolean enabled, String message) {
|
||||
super("achievement", enabled, message);
|
||||
}
|
||||
|
||||
public void handleEvent(AchievementEvent event) {
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordClient.getInstance().sendMessage(
|
||||
this.getMessage()
|
||||
.replace("%USER%", event.getEntityPlayer().getDisplayNameString())
|
||||
.replace("%ACHIEVEMENT%", event.getAchievement().getStatName().getUnformattedText())
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.message;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
import net.minecraftforge.event.entity.player.AchievementEvent;
|
||||
|
||||
public class AchievementMessageConfig extends BaseMessageConfig {
|
||||
public AchievementMessageConfig(boolean enabled, String message) {
|
||||
super("achievement", enabled, message);
|
||||
}
|
||||
|
||||
public void handleEvent(AchievementEvent event) {
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordClient.getInstance().sendMessage(
|
||||
this.getMessage()
|
||||
.replace("%USER%", event.getEntityPlayer().getDisplayNameString())
|
||||
.replace("%ACHIEVEMENT%", event.getAchievement().getStatName().getUnformattedText())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,90 +1,90 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.message;
|
||||
|
||||
import chikachi.discord.ChikachiDiscord;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class BaseMessageConfig {
|
||||
private final String name;
|
||||
private boolean enabled;
|
||||
protected String message;
|
||||
|
||||
BaseMessageConfig(String name, boolean enabled, String message) {
|
||||
this.name = name;
|
||||
this.enabled = enabled;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void read(JsonReader reader) throws IOException {
|
||||
String name;
|
||||
|
||||
JsonToken type = reader.peek();
|
||||
|
||||
if (type == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("enabled") && reader.peek() == JsonToken.BOOLEAN) {
|
||||
this.enabled = reader.nextBoolean();
|
||||
} else if (name.equalsIgnoreCase("message") && reader.peek() == JsonToken.STRING) {
|
||||
this.message = reader.nextString();
|
||||
} else {
|
||||
this.readExtra(reader, name);
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} else if (type == JsonToken.STRING) {
|
||||
this.message = reader.nextString();
|
||||
this.enabled = !this.message.equals("");
|
||||
} else {
|
||||
ChikachiDiscord.Log(String.format("Invalid value of message config for %s", this.name), true);
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JsonWriter writer) throws IOException {
|
||||
writer.name(this.name);
|
||||
writer.beginObject();
|
||||
writer.name("enabled");
|
||||
writer.value(this.enabled);
|
||||
writer.name("message");
|
||||
writer.value(this.message);
|
||||
this.writeExtra(writer);
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
protected void readExtra(JsonReader reader, String name) throws IOException {
|
||||
reader.skipValue();
|
||||
}
|
||||
|
||||
protected void writeExtra(JsonWriter writer) throws IOException {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.message;
|
||||
|
||||
import chikachi.discord.ChikachiDiscord;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class BaseMessageConfig {
|
||||
private final String name;
|
||||
private boolean enabled;
|
||||
protected String message;
|
||||
|
||||
BaseMessageConfig(String name, boolean enabled, String message) {
|
||||
this.name = name;
|
||||
this.enabled = enabled;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void read(JsonReader reader) throws IOException {
|
||||
String name;
|
||||
|
||||
JsonToken type = reader.peek();
|
||||
|
||||
if (type == JsonToken.BEGIN_OBJECT) {
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
name = reader.nextName();
|
||||
if (name.equalsIgnoreCase("enabled") && reader.peek() == JsonToken.BOOLEAN) {
|
||||
this.enabled = reader.nextBoolean();
|
||||
} else if (name.equalsIgnoreCase("message") && reader.peek() == JsonToken.STRING) {
|
||||
this.message = reader.nextString();
|
||||
} else {
|
||||
this.readExtra(reader, name);
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
} else if (type == JsonToken.STRING) {
|
||||
this.message = reader.nextString();
|
||||
this.enabled = !this.message.equals("");
|
||||
} else {
|
||||
ChikachiDiscord.Log(String.format("Invalid value of message config for %s", this.name), true);
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(JsonWriter writer) throws IOException {
|
||||
writer.name(this.name);
|
||||
writer.beginObject();
|
||||
writer.name("enabled");
|
||||
writer.value(this.enabled);
|
||||
writer.name("message");
|
||||
writer.value(this.message);
|
||||
this.writeExtra(writer);
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
protected void readExtra(JsonReader reader, String name) throws IOException {
|
||||
reader.skipValue();
|
||||
}
|
||||
|
||||
protected void writeExtra(JsonWriter writer) throws IOException {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,161 +1,161 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.message;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import net.dv8tion.jda.Permission;
|
||||
import net.dv8tion.jda.entities.TextChannel;
|
||||
import net.dv8tion.jda.events.message.MessageReceivedEvent;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.event.ClickEvent;
|
||||
import net.minecraft.util.text.event.HoverEvent;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class DiscordChatMessageConfig extends BaseMessageConfig {
|
||||
private final MinecraftServer minecraftServer;
|
||||
private int maxChatLength = -1;
|
||||
private TextFormatting usernameColor = TextFormatting.RED;
|
||||
|
||||
public DiscordChatMessageConfig(MinecraftServer minecraftServer, boolean enabled, String message) {
|
||||
super("chat", enabled, message);
|
||||
this.minecraftServer = minecraftServer;
|
||||
}
|
||||
|
||||
public void handleEvent(MessageReceivedEvent event) {
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String content = event.getMessage().getContent();
|
||||
if (this.maxChatLength > -1 && content.length() > this.maxChatLength) {
|
||||
content = content.substring(0, this.maxChatLength);
|
||||
}
|
||||
|
||||
TextChannel channel = event.getTextChannel();
|
||||
List<EntityPlayerMP> players = minecraftServer.getPlayerList().getPlayerList();
|
||||
if (players.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (content.contains("@everyone") && channel.checkPermission(event.getAuthor(), Permission.MESSAGE_MENTION_EVERYONE)) {
|
||||
content = Patterns.everyonePattern.matcher(content).replaceAll("$1" + TextFormatting.BLUE + "@everyone" + TextFormatting.RESET);
|
||||
}
|
||||
|
||||
content = Patterns.boldPattern.matcher(content).replaceAll(TextFormatting.BOLD + "$1" + TextFormatting.RESET);
|
||||
content = Patterns.italicPattern.matcher(content).replaceAll(TextFormatting.ITALIC + "$1" + TextFormatting.RESET);
|
||||
content = Patterns.italicMePattern.matcher(content).replaceAll(TextFormatting.ITALIC + "$1" + TextFormatting.RESET);
|
||||
content = Patterns.underlinePattern.matcher(content).replaceAll(TextFormatting.UNDERLINE + "$1" + TextFormatting.RESET);
|
||||
content = Patterns.lineThroughPattern.matcher(content).replaceAll("$1");
|
||||
content = Patterns.multiCodePattern.matcher(content).replaceAll("$1");
|
||||
content = Patterns.singleCodePattern.matcher(content).replaceAll("$1");
|
||||
|
||||
String[] messageParts = this.message
|
||||
.replace("%MESSAGE%",
|
||||
ForgeHooks.newChatWithLinks(
|
||||
content
|
||||
).getFormattedText()
|
||||
)
|
||||
.split("%USER%");
|
||||
|
||||
ITextComponent usernameComponent = new TextComponentString(event.getAuthor().getUsername());
|
||||
|
||||
HoverEvent usernameHoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Mention user (Clears current message)"));
|
||||
ClickEvent usernameClickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "@" + event.getAuthor().getUsername() + " ");
|
||||
|
||||
usernameComponent.getStyle()
|
||||
.setColor(this.usernameColor)
|
||||
.setClickEvent(usernameClickEvent)
|
||||
.setHoverEvent(usernameHoverEvent);
|
||||
|
||||
ITextComponent chatComponent = new TextComponentString(messageParts[0]);
|
||||
for (int i = 1, j = messageParts.length; i < j; i++) {
|
||||
chatComponent.appendSibling(
|
||||
usernameComponent
|
||||
).appendText(
|
||||
messageParts[i]
|
||||
);
|
||||
}
|
||||
|
||||
for (EntityPlayerMP player : players) {
|
||||
if (content.contains(player.getDisplayNameString())) {
|
||||
String playerName = player.getDisplayNameString();
|
||||
|
||||
String[] playerMessageParts = this.message
|
||||
.replace("%MESSAGE%",
|
||||
ForgeHooks.newChatWithLinks(
|
||||
content.replaceAll(
|
||||
"\\b" + playerName + "\\b",
|
||||
TextFormatting.BLUE + playerName + TextFormatting.RESET
|
||||
), false
|
||||
).getFormattedText()
|
||||
)
|
||||
.split("%USER%");
|
||||
|
||||
ITextComponent playerChatComponent = new TextComponentString(playerMessageParts[0]);
|
||||
for (int i = 1, j = playerMessageParts.length; i < j; i++) {
|
||||
playerChatComponent.appendSibling(
|
||||
usernameComponent
|
||||
).appendText(
|
||||
playerMessageParts[i]
|
||||
);
|
||||
}
|
||||
|
||||
player.addChatMessage(playerChatComponent);
|
||||
continue;
|
||||
}
|
||||
|
||||
player.addChatMessage(chatComponent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readExtra(JsonReader reader, String name) throws IOException {
|
||||
switch (name) {
|
||||
case "maxLength":
|
||||
if (reader.peek() == JsonToken.NUMBER) {
|
||||
this.maxChatLength = reader.nextInt();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "usernameColor":
|
||||
if (reader.peek() == JsonToken.STRING) {
|
||||
this.usernameColor = TextFormatting.getValueByName(reader.nextString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
reader.skipValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeExtra(JsonWriter writer) throws IOException {
|
||||
writer.name("maxLength");
|
||||
writer.value(this.maxChatLength);
|
||||
writer.name("usernameColor");
|
||||
writer.value(this.usernameColor.getFriendlyName());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.message;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import net.dv8tion.jda.Permission;
|
||||
import net.dv8tion.jda.entities.TextChannel;
|
||||
import net.dv8tion.jda.events.message.MessageReceivedEvent;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.event.ClickEvent;
|
||||
import net.minecraft.util.text.event.HoverEvent;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class DiscordChatMessageConfig extends BaseMessageConfig {
|
||||
private final MinecraftServer minecraftServer;
|
||||
private int maxChatLength = -1;
|
||||
private TextFormatting usernameColor = TextFormatting.RED;
|
||||
|
||||
public DiscordChatMessageConfig(MinecraftServer minecraftServer, boolean enabled, String message) {
|
||||
super("chat", enabled, message);
|
||||
this.minecraftServer = minecraftServer;
|
||||
}
|
||||
|
||||
public void handleEvent(MessageReceivedEvent event) {
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String content = event.getMessage().getContent();
|
||||
if (this.maxChatLength > -1 && content.length() > this.maxChatLength) {
|
||||
content = content.substring(0, this.maxChatLength);
|
||||
}
|
||||
|
||||
TextChannel channel = event.getTextChannel();
|
||||
List<EntityPlayerMP> players = minecraftServer.getPlayerList().getPlayerList();
|
||||
if (players.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (content.contains("@everyone") && channel.checkPermission(event.getAuthor(), Permission.MESSAGE_MENTION_EVERYONE)) {
|
||||
content = Patterns.everyonePattern.matcher(content).replaceAll("$1" + TextFormatting.BLUE + "@everyone" + TextFormatting.RESET);
|
||||
}
|
||||
|
||||
content = Patterns.boldPattern.matcher(content).replaceAll(TextFormatting.BOLD + "$1" + TextFormatting.RESET);
|
||||
content = Patterns.italicPattern.matcher(content).replaceAll(TextFormatting.ITALIC + "$1" + TextFormatting.RESET);
|
||||
content = Patterns.italicMePattern.matcher(content).replaceAll(TextFormatting.ITALIC + "$1" + TextFormatting.RESET);
|
||||
content = Patterns.underlinePattern.matcher(content).replaceAll(TextFormatting.UNDERLINE + "$1" + TextFormatting.RESET);
|
||||
content = Patterns.lineThroughPattern.matcher(content).replaceAll("$1");
|
||||
content = Patterns.multiCodePattern.matcher(content).replaceAll("$1");
|
||||
content = Patterns.singleCodePattern.matcher(content).replaceAll("$1");
|
||||
|
||||
String[] messageParts = this.message
|
||||
.replace("%MESSAGE%",
|
||||
ForgeHooks.newChatWithLinks(
|
||||
content
|
||||
).getFormattedText()
|
||||
)
|
||||
.split("%USER%");
|
||||
|
||||
ITextComponent usernameComponent = new TextComponentString(event.getAuthor().getUsername());
|
||||
|
||||
HoverEvent usernameHoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Mention user (Clears current message)"));
|
||||
ClickEvent usernameClickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "@" + event.getAuthor().getUsername() + " ");
|
||||
|
||||
usernameComponent.getStyle()
|
||||
.setColor(this.usernameColor)
|
||||
.setClickEvent(usernameClickEvent)
|
||||
.setHoverEvent(usernameHoverEvent);
|
||||
|
||||
ITextComponent chatComponent = new TextComponentString(messageParts[0]);
|
||||
for (int i = 1, j = messageParts.length; i < j; i++) {
|
||||
chatComponent.appendSibling(
|
||||
usernameComponent
|
||||
).appendText(
|
||||
messageParts[i]
|
||||
);
|
||||
}
|
||||
|
||||
for (EntityPlayerMP player : players) {
|
||||
if (content.contains(player.getDisplayNameString())) {
|
||||
String playerName = player.getDisplayNameString();
|
||||
|
||||
String[] playerMessageParts = this.message
|
||||
.replace("%MESSAGE%",
|
||||
ForgeHooks.newChatWithLinks(
|
||||
content.replaceAll(
|
||||
"\\b" + playerName + "\\b",
|
||||
TextFormatting.BLUE + playerName + TextFormatting.RESET
|
||||
), false
|
||||
).getFormattedText()
|
||||
)
|
||||
.split("%USER%");
|
||||
|
||||
ITextComponent playerChatComponent = new TextComponentString(playerMessageParts[0]);
|
||||
for (int i = 1, j = playerMessageParts.length; i < j; i++) {
|
||||
playerChatComponent.appendSibling(
|
||||
usernameComponent
|
||||
).appendText(
|
||||
playerMessageParts[i]
|
||||
);
|
||||
}
|
||||
|
||||
player.addChatMessage(playerChatComponent);
|
||||
continue;
|
||||
}
|
||||
|
||||
player.addChatMessage(chatComponent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readExtra(JsonReader reader, String name) throws IOException {
|
||||
switch (name) {
|
||||
case "maxLength":
|
||||
if (reader.peek() == JsonToken.NUMBER) {
|
||||
this.maxChatLength = reader.nextInt();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "usernameColor":
|
||||
if (reader.peek() == JsonToken.STRING) {
|
||||
this.usernameColor = TextFormatting.getValueByName(reader.nextString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
reader.skipValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeExtra(JsonWriter writer) throws IOException {
|
||||
writer.name("maxLength");
|
||||
writer.value(this.maxChatLength);
|
||||
writer.name("usernameColor");
|
||||
writer.value(this.usernameColor.getFriendlyName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,57 +1,57 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.message;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
|
||||
public class GenericMessageConfig extends BaseMessageConfig {
|
||||
public GenericMessageConfig(String name, boolean enabled, String message) {
|
||||
super(name, enabled, message);
|
||||
}
|
||||
|
||||
private void doSendMessage(String message) {
|
||||
DiscordClient.getInstance().sendMessage(
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public void sendMessage() {
|
||||
if (!this.isEnabled()) return;
|
||||
|
||||
doSendMessage(this.getMessage());
|
||||
}
|
||||
|
||||
public void sendMessage(String username) {
|
||||
if (!this.isEnabled()) return;
|
||||
|
||||
doSendMessage(
|
||||
this.getMessage()
|
||||
.replace("%USER%", username)
|
||||
);
|
||||
}
|
||||
|
||||
public void sendMessage(String username, String message) {
|
||||
if (!this.isEnabled()) return;
|
||||
|
||||
doSendMessage(
|
||||
this.getMessage()
|
||||
.replace("%USER%", username)
|
||||
.replace("%MESSAGE%", message)
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.message;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
|
||||
public class GenericMessageConfig extends BaseMessageConfig {
|
||||
public GenericMessageConfig(String name, boolean enabled, String message) {
|
||||
super(name, enabled, message);
|
||||
}
|
||||
|
||||
private void doSendMessage(String message) {
|
||||
DiscordClient.getInstance().sendMessage(
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
public void sendMessage() {
|
||||
if (!this.isEnabled()) return;
|
||||
|
||||
doSendMessage(this.getMessage());
|
||||
}
|
||||
|
||||
public void sendMessage(String username) {
|
||||
if (!this.isEnabled()) return;
|
||||
|
||||
doSendMessage(
|
||||
this.getMessage()
|
||||
.replace("%USER%", username)
|
||||
);
|
||||
}
|
||||
|
||||
public void sendMessage(String username, String message) {
|
||||
if (!this.isEnabled()) return;
|
||||
|
||||
doSendMessage(
|
||||
this.getMessage()
|
||||
.replace("%USER%", username)
|
||||
.replace("%MESSAGE%", message)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,60 +1,60 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.message;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
import com.google.common.base.Joiner;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.event.CommandEvent;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
|
||||
public class MinecraftChatMessageConfig extends BaseMessageConfig {
|
||||
public MinecraftChatMessageConfig(boolean enabled, String message) {
|
||||
super("chat", enabled, message);
|
||||
}
|
||||
|
||||
public void handleCommandEvent(CommandEvent event) {
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String message = Joiner.on(" ").join(event.getParameters());
|
||||
message = message.replaceAll("§.", "");
|
||||
|
||||
TextComponentString chatComponent = new TextComponentString(message);
|
||||
|
||||
DiscordClient.getInstance().sendMessage(
|
||||
this.getMessage()
|
||||
.replace("%USER%", event.getSender().getName())
|
||||
.replace("%MESSAGE%", chatComponent.getUnformattedText())
|
||||
);
|
||||
}
|
||||
|
||||
public void handleChatEvent(ServerChatEvent event) {
|
||||
if (!this.isEnabled()) return;
|
||||
|
||||
String message = event.getMessage();
|
||||
message = message.replaceAll("§.", "");
|
||||
|
||||
DiscordClient.getInstance().sendMessage(
|
||||
this.getMessage()
|
||||
.replace("%USER%", event.getUsername())
|
||||
.replace("%MESSAGE%", message)
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.message;
|
||||
|
||||
import chikachi.discord.DiscordClient;
|
||||
import com.google.common.base.Joiner;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.event.CommandEvent;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
|
||||
public class MinecraftChatMessageConfig extends BaseMessageConfig {
|
||||
public MinecraftChatMessageConfig(boolean enabled, String message) {
|
||||
super("chat", enabled, message);
|
||||
}
|
||||
|
||||
public void handleCommandEvent(CommandEvent event) {
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String message = Joiner.on(" ").join(event.getParameters());
|
||||
message = message.replaceAll("§.", "");
|
||||
|
||||
TextComponentString chatComponent = new TextComponentString(message);
|
||||
|
||||
DiscordClient.getInstance().sendMessage(
|
||||
this.getMessage()
|
||||
.replace("%USER%", event.getSender().getName())
|
||||
.replace("%MESSAGE%", chatComponent.getUnformattedText())
|
||||
);
|
||||
}
|
||||
|
||||
public void handleChatEvent(ServerChatEvent event) {
|
||||
if (!this.isEnabled()) return;
|
||||
|
||||
String message = event.getMessage();
|
||||
message = message.replaceAll("§.", "");
|
||||
|
||||
DiscordClient.getInstance().sendMessage(
|
||||
this.getMessage()
|
||||
.replace("%USER%", event.getUsername())
|
||||
.replace("%MESSAGE%", message)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,31 @@
|
|||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.message;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
class Patterns {
|
||||
static final Pattern everyonePattern = Pattern.compile("(^|\\W)@everyone\\b");
|
||||
static final Pattern boldPattern = Pattern.compile("\\*\\*(.*)\\*\\*");
|
||||
static final Pattern italicPattern = Pattern.compile("\\*(.*)\\*");
|
||||
static final Pattern italicMePattern = Pattern.compile("\\*(.*)\\*");
|
||||
static final Pattern underlinePattern = Pattern.compile("__(.*)__");
|
||||
static final Pattern lineThroughPattern = Pattern.compile("~~(.*)~~");
|
||||
static final Pattern singleCodePattern = Pattern.compile("`(.*)`");
|
||||
static final Pattern multiCodePattern = Pattern.compile("```(.*)```");
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2016 Chikachi
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package chikachi.discord.config.message;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
class Patterns {
|
||||
static final Pattern everyonePattern = Pattern.compile("(^|\\W)@everyone\\b");
|
||||
static final Pattern boldPattern = Pattern.compile("\\*\\*(.*)\\*\\*");
|
||||
static final Pattern italicPattern = Pattern.compile("\\*(.*)\\*");
|
||||
static final Pattern italicMePattern = Pattern.compile("\\*(.*)\\*");
|
||||
static final Pattern underlinePattern = Pattern.compile("__(.*)__");
|
||||
static final Pattern lineThroughPattern = Pattern.compile("~~(.*)~~");
|
||||
static final Pattern singleCodePattern = Pattern.compile("`(.*)`");
|
||||
static final Pattern multiCodePattern = Pattern.compile("```(.*)```");
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
[{
|
||||
"modid": "ChikachiDiscord",
|
||||
"name": "Chikachi's Discord Mod",
|
||||
"description": "MC <=> Discord communication",
|
||||
"version": "${version}",
|
||||
"mcversion": "${mcversion}",
|
||||
"url": "",
|
||||
"updateUrl": "",
|
||||
"authorList": ["Chikachi"],
|
||||
"credits": "",
|
||||
"logoFile": "",
|
||||
"screenshots": [],
|
||||
"dependencies": []
|
||||
[{
|
||||
"modid": "ChikachiDiscord",
|
||||
"name": "Chikachi's Discord Mod",
|
||||
"description": "MC <=> Discord communication",
|
||||
"version": "${version}",
|
||||
"mcversion": "${mcversion}",
|
||||
"url": "",
|
||||
"updateUrl": "",
|
||||
"authorList": ["Chikachi"],
|
||||
"credits": "",
|
||||
"logoFile": "",
|
||||
"screenshots": [],
|
||||
"dependencies": []
|
||||
}]
|
Loading…
Reference in New Issue