Compare commits
117 commits
Author | SHA1 | Date | |
---|---|---|---|
9eb2354b3f | |||
5615bbcb22 | |||
cde0d44b04 | |||
0d59dff86e | |||
222d393420 | |||
02e05e360e | |||
6bd1de6217 | |||
5d0bd37b28 | |||
f909eb4779 | |||
8d63394b55 | |||
ac3e6655e6 | |||
0610ee434b | |||
a4f1463314 | |||
6183c034c6 | |||
2a985509fb | |||
cafd8096fa | |||
9f3ca37929 | |||
263c652d68 | |||
7b27ec0ea3 | |||
c49fac5ce5 | |||
fd63e995ff | |||
ad3bd451ba | |||
74bce1ecf9 | |||
d80703ac68 | |||
470212411d | |||
5146fdf368 | |||
860dd66431 | |||
efa1dcfc8f | |||
3f6135f427 | |||
1b1a592a1e | |||
a84cd4e8e3 | |||
a0a7f756c4 | |||
7296ebd2f8 | |||
d416eef144 | |||
fce6b91b97 | |||
c57ac26b2d | |||
9f47509dcb | |||
428361c46c | |||
261725dc0f | |||
b18f6beba9 | |||
cbc9728c02 | |||
9576c0ba1d | |||
1fe367a96c | |||
28cff3ed43 | |||
491b5e4ee9 | |||
64994ee44e | |||
e57974ebcd | |||
324f5e756c | |||
2b549227a6 | |||
61986c9b51 | |||
4d234cf832 | |||
7866ddbe06 | |||
fdcab1acb2 | |||
40fe1093e0 | |||
d3ae53cd46 | |||
|
67a66c0c44 | ||
a27a262858 | |||
ccc15aa048 | |||
891be91d69 | |||
56d13ebf9f | |||
7cebb74835 | |||
3f2fa286fb | |||
beae6e6ce0 | |||
cd2132ba45 | |||
666f05ff12 | |||
d784d8b1e2 | |||
3ee1eb3dec | |||
80a0312b1f | |||
6bf91afab9 | |||
6b60135867 | |||
50500e87b9 | |||
ce71ff2dd6 | |||
4ecd32f0ad | |||
a9c71a3384 | |||
cce7f59f4a | |||
b484fe6f64 | |||
50cc0c8e61 | |||
1b747ab99f | |||
45a1ba4fe1 | |||
037ec3b9dd | |||
454265cd6f | |||
ffdf5a2f18 | |||
1fa2635317 | |||
d58a7e819a | |||
26971459ac | |||
940b601061 | |||
bcd7f7b810 | |||
de07503bc3 | |||
bdb7381ab4 | |||
703f1f8cd5 | |||
b481bb0aa9 | |||
3a94b6191b | |||
19463963e3 | |||
02f60c2162 | |||
30e2da094a | |||
0e4a9ff7e0 | |||
9caf4c54ed | |||
98ee2ce771 | |||
73fc4aedcc | |||
88c1d100e9 | |||
f1cec2ced1 | |||
3bd7b879c4 | |||
ef44aa8830 | |||
acd45ce4ae | |||
ea0ef88068 | |||
e4d5dcd0a2 | |||
91f1c8c4f7 | |||
2963990b5e | |||
c456b24333 | |||
42e91409c7 | |||
e88684a564 | |||
7a9e7de138 | |||
480032a3d6 | |||
7db3b17090 | |||
5a5f653b86 | |||
4082c2abbf | |||
0e24344efd |
101 changed files with 4136 additions and 7917 deletions
|
@ -4,6 +4,7 @@ end_of_line = lf
|
|||
insert_final_newline = false
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
ij_any_field_annotation_wrap = off
|
||||
|
||||
[*.json]
|
||||
indent_style = space
|
||||
|
@ -12,6 +13,8 @@ indent_size = 2
|
|||
[*.java]
|
||||
indent_style = tab
|
||||
tab_width = 4
|
||||
ij_java_do_not_wrap_after_single_annotation = true
|
||||
ij_java_field_annotation_wrap = off
|
||||
|
||||
[{*.yml, *.yaml}]
|
||||
indent_style = space
|
||||
|
|
451
.gitignore
vendored
451
.gitignore
vendored
|
@ -1,225 +1,226 @@
|
|||
#################
|
||||
## Eclipse
|
||||
#################
|
||||
|
||||
*.pydevproject
|
||||
.metadata/
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.classpath
|
||||
.settings/
|
||||
.loadpath
|
||||
target/
|
||||
.project
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# CDT-specific
|
||||
.cproject
|
||||
|
||||
# PDT-specific
|
||||
.buildpath
|
||||
|
||||
|
||||
#################
|
||||
## Visual Studio
|
||||
#################
|
||||
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.sln.docstates
|
||||
|
||||
# Build results
|
||||
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
x64/
|
||||
build/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.log
|
||||
*.scc
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# NCrunch
|
||||
*.ncrunch*
|
||||
.*crunch*.local.xml
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.Publish.xml
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# NuGet Packages Directory
|
||||
## TO!DO: If you have NuGet Package Restore enabled, uncomment the next line
|
||||
#packages/
|
||||
|
||||
# Windows Azure Build Output
|
||||
csx
|
||||
*.build.csdef
|
||||
|
||||
# Windows Store app package directory
|
||||
AppPackages/
|
||||
|
||||
# Others
|
||||
sql/
|
||||
*.Cache
|
||||
ClientBin/
|
||||
[Ss]tyle[Cc]op.*
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.[Pp]ublish.xml
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file to a newer
|
||||
# Visual Studio version. Backup files are not needed, because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
App_Data/*.mdf
|
||||
App_Data/*.ldf
|
||||
|
||||
#############
|
||||
## Windows detritus
|
||||
#############
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Mac crap
|
||||
.DS_Store
|
||||
|
||||
|
||||
#############
|
||||
## Python
|
||||
#############
|
||||
|
||||
*.py[cod]
|
||||
|
||||
# Packages
|
||||
*.egg
|
||||
*.egg-info
|
||||
dist/
|
||||
build/
|
||||
eggs/
|
||||
parts/
|
||||
var/
|
||||
sdist/
|
||||
develop-eggs/
|
||||
.installed.cfg
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
.coverage
|
||||
.tox
|
||||
|
||||
#Translations
|
||||
*.mo
|
||||
|
||||
#Mr Developer
|
||||
.mr.developer.cfg
|
||||
.metadata/*
|
||||
TheButtonAutoFlair/out/artifacts/Autoflair/Autoflair.jar
|
||||
*.iml
|
||||
*.name
|
||||
.idea/compiler.xml
|
||||
*.xml
|
||||
|
||||
Token.txt
|
||||
#################
|
||||
## Eclipse
|
||||
#################
|
||||
|
||||
*.pydevproject
|
||||
.metadata/
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.classpath
|
||||
.settings/
|
||||
.loadpath
|
||||
target/
|
||||
.project
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# CDT-specific
|
||||
.cproject
|
||||
|
||||
# PDT-specific
|
||||
.buildpath
|
||||
|
||||
|
||||
#################
|
||||
## Visual Studio
|
||||
#################
|
||||
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.sln.docstates
|
||||
|
||||
# Build results
|
||||
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
x64/
|
||||
build/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.log
|
||||
*.scc
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# NCrunch
|
||||
*.ncrunch*
|
||||
.*crunch*.local.xml
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.Publish.xml
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# NuGet Packages Directory
|
||||
## TO!DO: If you have NuGet Package Restore enabled, uncomment the next line
|
||||
#packages/
|
||||
|
||||
# Windows Azure Build Output
|
||||
csx
|
||||
*.build.csdef
|
||||
|
||||
# Windows Store app package directory
|
||||
AppPackages/
|
||||
|
||||
# Others
|
||||
sql/
|
||||
*.Cache
|
||||
ClientBin/
|
||||
[Ss]tyle[Cc]op.*
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.[Pp]ublish.xml
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file to a newer
|
||||
# Visual Studio version. Backup files are not needed, because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
App_Data/*.mdf
|
||||
App_Data/*.ldf
|
||||
|
||||
#############
|
||||
## Windows detritus
|
||||
#############
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Mac crap
|
||||
.DS_Store
|
||||
|
||||
|
||||
#############
|
||||
## Python
|
||||
#############
|
||||
|
||||
*.py[cod]
|
||||
|
||||
# Packages
|
||||
*.egg
|
||||
*.egg-info
|
||||
dist/
|
||||
build/
|
||||
eggs/
|
||||
parts/
|
||||
var/
|
||||
sdist/
|
||||
develop-eggs/
|
||||
.installed.cfg
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
.coverage
|
||||
.tox
|
||||
|
||||
#Translations
|
||||
*.mo
|
||||
|
||||
#Mr Developer
|
||||
.mr.developer.cfg
|
||||
.metadata/*
|
||||
TheButtonAutoFlair/out/artifacts/Autoflair/Autoflair.jar
|
||||
*.iml
|
||||
*.name
|
||||
.idea/compiler.xml
|
||||
*.xml
|
||||
|
||||
Token.txt
|
||||
.bsp
|
||||
|
|
21
.travis.yml
21
.travis.yml
|
@ -2,25 +2,24 @@ cache:
|
|||
directories:
|
||||
- $HOME/.m2/repository/org/
|
||||
before_install: | # Wget BuildTools and run if cached folder not found
|
||||
export JAVA_HOME=$HOME/oraclejdk8
|
||||
~/bin/install-jdk.sh --install oraclejdk8 --target $JAVA_HOME
|
||||
if [ ! -d "$HOME/.m2/repository/org/spigotmc/spigot/1.12.2-R0.1-SNAPSHOT" ]; then
|
||||
wget -O BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
|
||||
# grep so that download counts don't appear in log files
|
||||
java -jar BuildTools.jar --rev 1.12.2 | grep -vE "[^/ ]*/[^/ ]*\s*KB\s*$" | grep -v "^\s*$"
|
||||
fi
|
||||
export JAVA_HOME=$HOME/oraclejdk11
|
||||
~/bin/install-jdk.sh --install oraclejdk11 --target $JAVA_HOME
|
||||
language: java
|
||||
jdk:
|
||||
- oraclejdk8
|
||||
- oraclejdk11
|
||||
sudo: true
|
||||
deploy:
|
||||
# deploy develop to the staging environment
|
||||
- provider: script
|
||||
script: chmod +x deploy.sh && sh deploy.sh staging
|
||||
- provider: releases
|
||||
api_key:
|
||||
secure: "AnGhHbIFAdfFEtxuAv3Bue5n80JJi9FMyXc2rstg1zzBbuvaYqCUWcL7lB34Ffs9E6Mo5wfANnBRyXtdSfXWLLsb0k78vvlAwJyLP2s0V7r9LTvQWJEflslSDX6ySF0YIc3LR+XMYv+qj+e5XnWr6Kj6gRkaQPDzSIYRgvfKZv9fbo4lSqnp2OcOrn4sYyeV6+sLhARLaNTvbDOdLiMRP3JZUrKB4OCt8+XhrVMlwKhglJY8JVKx1uAFxeljfZ3WJ1WnJ6L8coyVR18HAl1/VHwn+a/jeGp9AygTPF2yJL3+TJs37afqG9jjbL0pneSUoyNenKkjD19pM2RgjGmW25kPEvnmGMaWn8UN8bbilB5k8sh27z+/6qNnvYbhJxJi9RJNASpd6JQ1cGZoBziKsvhkLXErRNCJ92wlgGOqE78UWf6dvzmVkQD/vaqXhHlmcVhpoUZUqsXGWw5gOw/Kxh90IUwsV6A2JXf1Q3YRPIfDin/tVpud6eB0hiRW2uLnAqDMUUsH6n8cqd2rzg/02uKD5rF5+amxfdUSf3m/Fh6lqklNlO1188rFULUPpyFRas59UpEIRqT2Ae9OJPg+1QrVln2Gd3l059MHumX2tidQl00GzXx4nB1NkxpKLl9JLf/n6A4MQodY5CkRELUTB8K3zHGhJdj1Dtmis5YwhXk="
|
||||
file: 'target/Chroma-Discord.jar'
|
||||
on:
|
||||
branch: dev
|
||||
skip_cleanup: true
|
||||
# deploy master to production
|
||||
- provider: script
|
||||
script: chmod +x deploy.sh && sh deploy.sh production
|
||||
on:
|
||||
branch: master
|
||||
tags: true
|
||||
skip_cleanup: true
|
||||
|
|
17
README.md
17
README.md
|
@ -1,11 +1,10 @@
|
|||
# DiscordPlugin
|
||||
A plugin that controls the ChromaBot Discord bot and provides Minecraft chat functionality and other features.
|
||||
# Chroma-Discord
|
||||
A plugin that provides Minecraft chat functionality and other features.
|
||||
|
||||
## Features
|
||||
### Announce new posts from /r/ChromaGamers
|
||||
If it's a (distinguished) moderator post, it'll be posted to the \#announcements channel, otherwise it'll be posted and pinned to \#general.
|
||||
## Setup
|
||||
This plugin needs Chroma-Core to work. If you have that and this plugin, start the server, and follow the instructions.
|
||||
You'll need a Discord application made, and a bot account created for it.
|
||||
You can restart the plugin using /discord restart without having to restart the whole server.
|
||||
|
||||
### Announce server restarts
|
||||
It announces server starts/stops and restarts, as well as if the server shut down unexpectedly.
|
||||
|
||||
**For more, see:** http://chromapedia.wikia.com/wiki/ChromaBot
|
||||
## Building
|
||||
Maven is used to build this project with all of its dependencies. You will need Spigot 1.12.2 and 1.14.4 built using BuildTools.
|
||||
|
|
67
build.sbt
Normal file
67
build.sbt
Normal file
|
@ -0,0 +1,67 @@
|
|||
name := "Chroma-Discord"
|
||||
|
||||
version := "1.1"
|
||||
|
||||
scalaVersion := "2.13.11"
|
||||
|
||||
resolvers += "jitpack.io" at "https://jitpack.io"
|
||||
resolvers += "paper-repo" at "https://papermc.io/repo/repository/maven-public/"
|
||||
resolvers += Resolver.mavenLocal
|
||||
|
||||
// assembly / assemblyOption := (assembly / assemblyOption).value.copy(includeScala = false)
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
"io.papermc.paper" % "paper-api" % "1.19-R0.1-SNAPSHOT" % Provided,
|
||||
|
||||
"com.discord4j" % "discord4j-core" % "3.2.3",
|
||||
"com.vdurmont" % "emoji-java" % "5.1.1",
|
||||
"io.projectreactor" % "reactor-scala-extensions_2.13" % "0.8.0",
|
||||
|
||||
"com.github.TBMCPlugins.ChromaCore" % "Chroma-Core" % "v2.0.0-SNAPSHOT" % Provided,
|
||||
"net.ess3" % "EssentialsX" % "2.17.1" % Provided,
|
||||
// https://mvnrepository.com/artifact/com.mojang/brigadier
|
||||
"com.mojang" % "brigadier" % "1.0.500" % "provided",
|
||||
// https://mvnrepository.com/artifact/net.kyori/examination-api
|
||||
"net.kyori" % "examination-api" % "1.3.0" % "provided",
|
||||
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib
|
||||
//"org.jetbrains.kotlin" % "kotlin-stdlib" % "1.8.20" % "provided",
|
||||
// https://mvnrepository.com/artifact/org.scalatest/scalatest
|
||||
"org.scalatest" %% "scalatest" % "3.2.16" % Test,
|
||||
// https://mvnrepository.com/artifact/com.github.seeseemelk/MockBukkit-v1.19
|
||||
"com.github.seeseemelk" % "MockBukkit-v1.19" % "2.29.0" % Test,
|
||||
"com.github.milkbowl" % "vault" % "master-SNAPSHOT" % Test
|
||||
)
|
||||
|
||||
assembly / assemblyJarName := "Chroma-Discord.jar"
|
||||
assembly / assemblyShadeRules := Seq(
|
||||
"io.netty", "com.fasterxml", "org.slf4j"
|
||||
).map { p =>
|
||||
ShadeRule.rename(s"$p.**" -> "btndvtm.dp.@0").inAll
|
||||
}
|
||||
|
||||
assembly / assemblyMergeStrategy := {
|
||||
case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.concat
|
||||
// https://stackoverflow.com/a/55557287/457612
|
||||
case "module-info.class" => MergeStrategy.discard
|
||||
case "META-INF/versions/9/module-info.class" => MergeStrategy.discard
|
||||
case x => (assembly / assemblyMergeStrategy).value(x)
|
||||
}
|
||||
|
||||
val saveConfigComments = TaskKey[Seq[File]]("saveConfigComments")
|
||||
saveConfigComments := {
|
||||
Commenter.saveConfigComments((Compile / sources).value)
|
||||
}
|
||||
|
||||
Compile / resourceGenerators += saveConfigComments
|
||||
//scalacOptions ++= Seq("-release", "17", "--verbose")
|
||||
scalacOptions ++= Seq("-release", "17")
|
||||
//Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat
|
||||
Test / fork := true // This changes the tests ran through sbt to work like IntelliJ tests, fixes mocking issues
|
||||
/*excludeDependencies ++= Seq(
|
||||
ExclusionRule("org.bukkit"),
|
||||
ExclusionRule("io.papermc.paper"),
|
||||
ExclusionRule("com.destroystokyo")
|
||||
)*/
|
||||
excludeDependencies ++= Seq(
|
||||
ExclusionRule("net.milkbowl.vault", "VaultAPI")
|
||||
)
|
|
@ -1 +0,0 @@
|
|||
lombok.var.flagUsage = ALLOW
|
275
pom.xml
275
pom.xml
|
@ -1,275 +0,0 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.github.TBMCPlugins</groupId>
|
||||
<artifactId>DiscordPlugin</artifactId>
|
||||
<version>master-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>DiscordPlugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<build>
|
||||
<!-- <sourceDirectory>target/generated-sources/delombok</sourceDirectory>
|
||||
<testSourceDirectory>target/generated-test-sources/delombok</testSourceDirectory> -->
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>*.properties</include>
|
||||
<include>*.yml</include>
|
||||
<include>*.csv</include>
|
||||
<include>*.txt</include>
|
||||
</includes>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<finalName>DiscordPlugin</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.2</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<!-- <compilerArgs>
|
||||
<arg>-processor</arg>
|
||||
<arg>buttondevteam.buttonproc.ButtonProcessor, lombok.core.AnnotationProcessor</arg>
|
||||
</compilerArgs> -->
|
||||
<!-- <annotationProcessors>
|
||||
<annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
|
||||
<annotationProcessor>buttondevteam.buttonproc.ButtonProcessor</annotationProcessor>
|
||||
</annotationProcessors> -->
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.4.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<excludes>
|
||||
<exclude>org.spigotmc:spigot-api</exclude>
|
||||
<exclude>com.github.TBMCPlugins.ButtonCore:ButtonCore</exclude>
|
||||
<exclude>net.ess3:Essentials</exclude>
|
||||
</excludes> <!-- http://stackoverflow.com/questions/28458058/maven-shade-plugin-exclude-a-dependency-and-all-its-transitive-dependencies -->
|
||||
</artifactSet>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>io.netty</pattern>
|
||||
<shadedPattern>btndvtm.dp.io.netty</shadedPattern>
|
||||
<excludes>
|
||||
</excludes>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>target</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- <plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId>
|
||||
<version>1.16.16.0</version> <executions> <execution> <id>delombok</id> <phase>generate-sources</phase>
|
||||
<goals> <goal>delombok</goal> </goals> <configuration> <addOutputDirectory>false</addOutputDirectory>
|
||||
<sourceDirectory>src/main/java</sourceDirectory> <verbose>true</verbose>
|
||||
</configuration> </execution> <execution> <id>test-delombok</id> <phase>generate-test-sources</phase>
|
||||
<goals> <goal>testDelombok</goal> </goals> <configuration> <addOutputDirectory>false</addOutputDirectory>
|
||||
<sourceDirectory>src/test/java</sourceDirectory> </configuration> </execution>
|
||||
</executions> </plugin> -->
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.4.2</version>
|
||||
<configuration>
|
||||
<useSystemClassLoader>false
|
||||
</useSystemClassLoader> <!-- https://stackoverflow.com/a/53012553/2703239 -->
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<branch>
|
||||
master
|
||||
</branch> <!-- Should be master if building ButtonCore locally - the CI will overwrite it (see below) -->
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository> <!-- This repo fixes issues with transitive dependencies -->
|
||||
<id>jcenter</id>
|
||||
<url>http://jcenter.bintray.com</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<!-- <repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
</repository> -->
|
||||
<repository>
|
||||
<id>Essentials</id>
|
||||
<url>http://repo.ess3.net/content/repositories/essrel/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>projectlombok.org</id>
|
||||
<url>http://projectlombok.org/mavenrepo</url>
|
||||
</repository>
|
||||
<!-- <repository>
|
||||
<id>pex-repo</id>
|
||||
<url>http://pex-repo.aoeu.xyz</url>
|
||||
</repository> -->
|
||||
<!-- <repository>
|
||||
<id>Reactor-Tools</id>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
</repository> -->
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.discord4j/Discord4J -->
|
||||
<dependency>
|
||||
<groupId>com.discord4j</groupId>
|
||||
<artifactId>discord4j-core</artifactId>
|
||||
<version>3.0.6</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jdk14</artifactId>
|
||||
<version>1.7.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||
<artifactId>ButtonCore</artifactId>
|
||||
<version>${branch}-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.milkbowl</groupId> <!-- net.milkbowl.vault -->
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>master-SNAPSHOT</version> <!-- 1.6 -->
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ess3</groupId>
|
||||
<artifactId>Essentials</artifactId>
|
||||
<version>2.13.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.16</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>ru.tehkode</groupId>
|
||||
<artifactId>PermissionsEx</artifactId>
|
||||
<version>1.23.1</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency> -->
|
||||
<!-- https://mvnrepository.com/artifact/org.objenesis/objenesis -->
|
||||
<dependency>
|
||||
<groupId>org.objenesis</groupId>
|
||||
<artifactId>objenesis</artifactId>
|
||||
<version>2.6</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vdurmont</groupId>
|
||||
<artifactId>emoji-java</artifactId>
|
||||
<version>4.0.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/io.projectreactor.tools/blockhound -->
|
||||
<!-- <dependency>
|
||||
<groupId>io.projectreactor.tools</groupId>
|
||||
<artifactId>blockhound</artifactId>
|
||||
<version>1.0.0.M3</version>
|
||||
</dependency> -->
|
||||
<dependency>
|
||||
<groupId>com.github.lucko</groupId>
|
||||
<artifactId>LuckPerms</artifactId>
|
||||
<version>v4.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>ci</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env.TRAVIS_BRANCH</name>
|
||||
</property>
|
||||
</activation>
|
||||
<properties>
|
||||
<!-- Override only if necessary -->
|
||||
<branch>${env.TRAVIS_BRANCH}</branch>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
96
project/Commenter.scala
Normal file
96
project/Commenter.scala
Normal file
|
@ -0,0 +1,96 @@
|
|||
import java.util.regex.Pattern
|
||||
import sbt.*
|
||||
import org.bukkit.configuration.file.YamlConfiguration
|
||||
import scala.io.Source
|
||||
import scala.util.Using
|
||||
|
||||
object Commenter {
|
||||
def saveConfigComments(sv: Seq[File]): Seq[File] = {
|
||||
val cdataRegex = Pattern.compile("(?:def|val|var) (\\w+)(?::[^=]+)? = (?:getI?Config|DPUtils.\\w+Data)") //Hack: DPUtils
|
||||
val clRegex = Pattern.compile("class (\\w+).* extends ((?:\\w|\\d)+)")
|
||||
val objRegex = Pattern.compile("object (\\w+)")
|
||||
val subRegex = Pattern.compile("def `?(\\w+)`?")
|
||||
val subParamRegex = Pattern.compile("((?:\\w|\\d)+): ((?:\\w|\\d)+)")
|
||||
val configConfig = new YamlConfiguration()
|
||||
val commandConfig = new YamlConfiguration()
|
||||
|
||||
def getConfigComments(line: String, clKey: String, comment: String, justCommented: Boolean): (String, String, Boolean) = {
|
||||
val clMatcher = clRegex.matcher(line)
|
||||
if (clKey == null && clMatcher.find()) { //First occurrence
|
||||
(if (clMatcher.group(2).contains("Component"))
|
||||
"components." + clMatcher.group(1)
|
||||
else "global", comment, justCommented)
|
||||
} else if (line.contains("/**")) {
|
||||
(clKey, "", false)
|
||||
} else if (line.contains("*/") && comment != null)
|
||||
(clKey, comment, true)
|
||||
else if (comment != null) {
|
||||
if (justCommented) {
|
||||
if (clKey != null) {
|
||||
val matcher = cdataRegex.matcher(line)
|
||||
if (matcher.find())
|
||||
configConfig.set(s"$clKey.${matcher.group(1)}", comment.trim)
|
||||
}
|
||||
else {
|
||||
val matcher = objRegex.matcher(line)
|
||||
if (matcher.find()) {
|
||||
val clName = matcher.group(1)
|
||||
val compKey = if (clName.contains("Module")) s"component.$clName"
|
||||
else if (clName.contains("Plugin")) "global"
|
||||
else null
|
||||
if (compKey != null)
|
||||
configConfig.set(s"$compKey.generalDescriptionInsteadOfAConfig", comment.trim)
|
||||
}
|
||||
}
|
||||
(clKey, null, false)
|
||||
}
|
||||
else (clKey, comment + line.replaceFirst("^\\s*\\*\\s+", "") + "\n", justCommented)
|
||||
}
|
||||
else (clKey, comment, justCommented)
|
||||
}
|
||||
|
||||
for (file <- sv) {
|
||||
Using(Source.fromFile(file)) { src =>
|
||||
var clKey: String = null
|
||||
var comment: String = null
|
||||
var justCommented: Boolean = false
|
||||
|
||||
var subCommand = false
|
||||
var pkg: String = null
|
||||
var clName: String = null
|
||||
for (line <- src.getLines) {
|
||||
val (clk, c, jc) = getConfigComments(line, clKey, comment, justCommented)
|
||||
clKey = clk; comment = c; justCommented = jc
|
||||
|
||||
val objMatcher = objRegex.matcher(line)
|
||||
val clMatcher = clRegex.matcher(line)
|
||||
if (pkg == null && line.startsWith("package "))
|
||||
pkg = line.substring("package ".length)
|
||||
else if (clName == null && objMatcher.find())
|
||||
clName = objMatcher.group(1)
|
||||
else if (clName == null && clMatcher.find())
|
||||
clName = clMatcher.group(1)
|
||||
val subMatcher = subRegex.matcher(line)
|
||||
val subParamMatcher = subParamRegex.matcher(line)
|
||||
val sub = line.contains("@Subcommand") || line.contains("@Command2.Subcommand")
|
||||
if (sub) subCommand = true
|
||||
else if (line.contains("}")) subCommand = false
|
||||
if (subCommand && subMatcher.find()) {
|
||||
/*val groups = (2 to subMatcher.groupCount()).map(subMatcher.group)
|
||||
val pairs = for (i <- groups.indices by 2) yield (groups(i), groups(i + 1))*/
|
||||
val mname = subMatcher.group(1)
|
||||
val params = Iterator.continually(()).takeWhile(_ => subParamMatcher.find())
|
||||
.map(_ => subParamMatcher.group(1)).drop(1)
|
||||
val section = commandConfig.createSection(s"$pkg.$clName.$mname")
|
||||
section.set("method", s"$mname()")
|
||||
section.set("params", params.mkString(" "))
|
||||
subCommand = false
|
||||
}
|
||||
}
|
||||
configConfig.save("target/configHelp.yml")
|
||||
commandConfig.save("target/commands.yml")
|
||||
}.recover[Unit]({ case t => t.printStackTrace() })
|
||||
}
|
||||
Seq(file("target/configHelp.yml"), file("target/commands.yml"))
|
||||
}
|
||||
}
|
2
project/build.properties
Normal file
2
project/build.properties
Normal file
|
@ -0,0 +1,2 @@
|
|||
sbt.version=1.8.2
|
||||
scala.version=2.13.11
|
7
project/build.sbt
Normal file
7
project/build.sbt
Normal file
|
@ -0,0 +1,7 @@
|
|||
//lazy val commenter = RootProject(file("../commenter"))
|
||||
//lazy val root = (project in file(".")).dependsOn(commenter)
|
||||
|
||||
resolvers += Resolver.mavenLocal
|
||||
resolvers += "paper-repo" at "https://papermc.io/repo/repository/maven-public/"
|
||||
|
||||
libraryDependencies += "io.papermc.paper" % "paper-api" % "1.19.4-R0.1-SNAPSHOT" % Compile
|
1
project/plugins.sbt
Normal file
1
project/plugins.sbt
Normal file
|
@ -0,0 +1 @@
|
|||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.1")
|
|
@ -1,15 +0,0 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
public enum ChannelconBroadcast {
|
||||
JOINLEAVE,
|
||||
AFK,
|
||||
RESTART,
|
||||
DEATH,
|
||||
BROADCAST;
|
||||
|
||||
public final int flag;
|
||||
|
||||
ChannelconBroadcast() {
|
||||
this.flag = 1 << this.ordinal();
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import buttondevteam.discordplugin.mcchat.MCChatUtils;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ChromaBot {
|
||||
/**
|
||||
* May be null if it's not initialized. Initialization happens after the server is done loading (using {@link BukkitScheduler#runTaskAsynchronously(org.bukkit.plugin.Plugin, Runnable)})
|
||||
*/
|
||||
private static @Getter ChromaBot instance;
|
||||
private DiscordPlugin dp;
|
||||
|
||||
/**
|
||||
* This will set the instance field.
|
||||
*
|
||||
* @param dp
|
||||
* The Discord plugin
|
||||
*/
|
||||
ChromaBot(DiscordPlugin dp) {
|
||||
instance = this;
|
||||
this.dp = dp;
|
||||
}
|
||||
|
||||
static void delete() {
|
||||
instance = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the chat channels and private chats.
|
||||
*
|
||||
* @param message
|
||||
* The message to send, duh (use {@link MessageChannel#createMessage(String)})
|
||||
*/
|
||||
public void sendMessage(Function<Mono<MessageChannel>, Mono<Message>> message) {
|
||||
MCChatUtils.forAllMCChat(ch -> message.apply(ch).subscribe());
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the chat channels, private chats and custom chats.
|
||||
*
|
||||
* @param message The message to send, duh
|
||||
* @param toggle The toggle type for channelcon
|
||||
*/
|
||||
public void sendMessageCustomAsWell(Function<Mono<MessageChannel>, Mono<Message>> message, @Nullable ChannelconBroadcast toggle) {
|
||||
MCChatUtils.forCustomAndAllMCChat(ch -> message.apply(ch).subscribe(), toggle, false);
|
||||
}
|
||||
|
||||
public void updatePlayerList() {
|
||||
MCChatUtils.updatePlayerList();
|
||||
}
|
||||
}
|
|
@ -1,166 +0,0 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.architecture.IHaveConfig;
|
||||
import buttondevteam.lib.architecture.ReadOnlyConfigData;
|
||||
import discord4j.core.object.entity.Guild;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.Role;
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import discord4j.core.spec.EmbedCreateSpec;
|
||||
import lombok.val;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
public final class DPUtils {
|
||||
|
||||
public static EmbedCreateSpec embedWithHead(EmbedCreateSpec ecs, String displayname, String playername, String profileUrl) {
|
||||
return ecs.setAuthor(displayname, profileUrl, "https://minotar.net/avatar/" + playername + "/32.png");
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes §[char] colour codes from strings & escapes them for Discord <br>
|
||||
* Ensure that this method only gets called once (escaping)
|
||||
*/
|
||||
public static String sanitizeString(String string) {
|
||||
return escape(sanitizeStringNoEscape(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes §[char] colour codes from strings
|
||||
*/
|
||||
public static String sanitizeStringNoEscape(String string) {
|
||||
StringBuilder sanitizedString = new StringBuilder();
|
||||
boolean random = false;
|
||||
for (int i = 0; i < string.length(); i++) {
|
||||
if (string.charAt(i) == '§') {
|
||||
i++;// Skips the data value, the 4 in "§4Alisolarflare"
|
||||
random = string.charAt(i) == 'k';
|
||||
} else {
|
||||
if (!random) // Skip random/obfuscated characters
|
||||
sanitizedString.append(string.charAt(i));
|
||||
}
|
||||
}
|
||||
return sanitizedString.toString();
|
||||
}
|
||||
|
||||
private static String escape(String message) {
|
||||
return message.replaceAll("([*_~])", Matcher.quoteReplacement("\\") + "$1");
|
||||
}
|
||||
|
||||
public static Logger getLogger() {
|
||||
if (DiscordPlugin.plugin == null || DiscordPlugin.plugin.getLogger() == null)
|
||||
return Logger.getLogger("DiscordPlugin");
|
||||
return DiscordPlugin.plugin.getLogger();
|
||||
}
|
||||
|
||||
public static ReadOnlyConfigData<Mono<MessageChannel>> channelData(IHaveConfig config, String key, long defID) {
|
||||
return config.getReadOnlyDataPrimDef(key, defID, id -> getMessageChannel(key, Snowflake.of((Long) id)), ch -> defID); //We can afford to search for the channel in the cache once (instead of using mainServer)
|
||||
}
|
||||
|
||||
public static ReadOnlyConfigData<Mono<Role>> roleData(IHaveConfig config, String key, String defName) {
|
||||
return roleData(config, key, defName, Mono.just(DiscordPlugin.mainServer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Needs to be a {@link ConfigData} for checking if it's set
|
||||
*/
|
||||
public static ReadOnlyConfigData<Mono<Role>> roleData(IHaveConfig config, String key, String defName, Mono<Guild> guild) {
|
||||
return config.getReadOnlyDataPrimDef(key, defName, name -> {
|
||||
if (!(name instanceof String)) return Mono.empty();
|
||||
return guild.flatMapMany(Guild::getRoles).filter(r -> r.getName().equals(name)).next();
|
||||
}, r -> defName);
|
||||
}
|
||||
|
||||
public static ConfigData<Snowflake> snowflakeData(IHaveConfig config, String key, long defID) {
|
||||
return config.getDataPrimDef(key, defID, id -> Snowflake.of((long) id), Snowflake::asLong);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mentions the <b>bot channel</b>. Useful for help texts.
|
||||
*
|
||||
* @return The string for mentioning the channel
|
||||
*/
|
||||
public static String botmention() {
|
||||
if (DiscordPlugin.plugin == null) return "#bot";
|
||||
return channelMention(DiscordPlugin.plugin.commandChannel().get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the component if one of the given configs return null. Useful for channel/role configs.
|
||||
*
|
||||
* @param component The component to disable if needed
|
||||
* @param configs The configs to check for null
|
||||
* @return Whether the component got disabled and a warning logged
|
||||
*/
|
||||
public static boolean disableIfConfigError(@Nullable Component<DiscordPlugin> component, ConfigData<?>... configs) {
|
||||
for (val config : configs) {
|
||||
Object v = config.get();
|
||||
if (disableIfConfigErrorRes(component, config, v))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the component if one of the given configs return null. Useful for channel/role configs.
|
||||
*
|
||||
* @param component The component to disable if needed
|
||||
* @param config The (snowflake) config to check for null
|
||||
* @param result The result of getting the value
|
||||
* @return Whether the component got disabled and a warning logged
|
||||
*/
|
||||
public static boolean disableIfConfigErrorRes(@Nullable Component<DiscordPlugin> component, ConfigData<?> config, Object result) {
|
||||
//noinspection ConstantConditions
|
||||
if (result == null || (result instanceof Mono<?> && !((Mono<?>) result).hasElement().block())) {
|
||||
String path = null;
|
||||
try {
|
||||
if (component != null)
|
||||
Component.setComponentEnabled(component, false);
|
||||
path = config.getPath();
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Failed to disable component after config error!", e);
|
||||
}
|
||||
getLogger().warning("The config value " + path + " isn't set correctly " + (component == null ? "in global settings!" : "for component " + component.getClass().getSimpleName() + "!"));
|
||||
getLogger().warning("Set the correct ID in the config" + (component == null ? "" : " or disable this component") + " to remove this message.");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Mono<Message> reply(Message original, @Nullable MessageChannel channel, String message) {
|
||||
Mono<MessageChannel> ch;
|
||||
if (channel == null)
|
||||
ch = original.getChannel();
|
||||
else
|
||||
ch = Mono.just(channel);
|
||||
return ch.flatMap(chan -> chan.createMessage((original.getAuthor().isPresent()
|
||||
? original.getAuthor().get().getMention() + ", " : "") + message));
|
||||
}
|
||||
|
||||
public static String nickMention(Snowflake userId) {
|
||||
return "<@!" + userId.asString() + ">";
|
||||
}
|
||||
|
||||
public static String channelMention(Snowflake channelId) {
|
||||
return "<#" + channelId.asString() + ">";
|
||||
}
|
||||
|
||||
public static Mono<MessageChannel> getMessageChannel(String key, Snowflake id) {
|
||||
return DiscordPlugin.dc.getChannelById(id).onErrorResume(e -> {
|
||||
getLogger().warning("Failed to get channel data for " + key + "=" + id + " - " + e.getMessage());
|
||||
return Mono.empty();
|
||||
}).filter(ch -> ch instanceof MessageChannel).cast(MessageChannel.class);
|
||||
}
|
||||
|
||||
public static Mono<MessageChannel> getMessageChannel(ConfigData<Snowflake> config) {
|
||||
return getMessageChannel(config.getPath(), config.get());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
||||
import buttondevteam.discordplugin.playerfaker.DiscordFakePlayer;
|
||||
import buttondevteam.discordplugin.playerfaker.VanillaCommandListener;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.User;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class DiscordConnectedPlayer extends DiscordFakePlayer implements IMCPlayer<DiscordConnectedPlayer> {
|
||||
private static int nextEntityId = 10000;
|
||||
private @Getter VanillaCommandListener<DiscordConnectedPlayer> vanillaCmdListener;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean loggedIn = false;
|
||||
|
||||
public DiscordConnectedPlayer(User user, MessageChannel channel, UUID uuid, String mcname, MinecraftChatModule module) {
|
||||
super(user, channel, nextEntityId++, uuid, mcname, module);
|
||||
vanillaCmdListener = new VanillaCommandListener<>(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import buttondevteam.discordplugin.mcchat.MCChatPrivate;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.UserClass;
|
||||
|
||||
@UserClass(foldername = "discord")
|
||||
public class DiscordPlayer extends ChromaGamerBase {
|
||||
private String did;
|
||||
// private @Getter @Setter boolean minecraftChatEnabled;
|
||||
|
||||
public DiscordPlayer() {
|
||||
}
|
||||
|
||||
public String getDiscordID() {
|
||||
if (did == null)
|
||||
did = plugindata.getString(getFolder() + "_id");
|
||||
return did;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if player has the private Minecraft chat enabled. For setting the value, see
|
||||
* {@link MCChatPrivate#privateMCChat(sx.blah.discord.handle.obj.MessageChannel, boolean, sx.blah.discord.handle.obj.User, DiscordPlayer)}
|
||||
*/
|
||||
public boolean isMinecraftChatEnabled() {
|
||||
return MCChatPrivate.isMinecraftChatEnabled(this);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,297 +0,0 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import buttondevteam.discordplugin.announcer.AnnouncerModule;
|
||||
import buttondevteam.discordplugin.broadcaster.GeneralEventBroadcasterModule;
|
||||
import buttondevteam.discordplugin.commands.*;
|
||||
import buttondevteam.discordplugin.exceptions.ExceptionListenerModule;
|
||||
import buttondevteam.discordplugin.fun.FunModule;
|
||||
import buttondevteam.discordplugin.listeners.CommonListeners;
|
||||
import buttondevteam.discordplugin.listeners.MCListener;
|
||||
import buttondevteam.discordplugin.mcchat.MCChatPrivate;
|
||||
import buttondevteam.discordplugin.mcchat.MCChatUtils;
|
||||
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
||||
import buttondevteam.discordplugin.mccommands.DiscordMCCommand;
|
||||
import buttondevteam.discordplugin.role.GameRoleModule;
|
||||
import buttondevteam.discordplugin.util.Timings;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.architecture.ButtonPlugin;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.architecture.IHaveConfig;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import com.google.common.io.Files;
|
||||
import discord4j.core.DiscordClient;
|
||||
import discord4j.core.DiscordClientBuilder;
|
||||
import discord4j.core.event.domain.guild.GuildCreateEvent;
|
||||
import discord4j.core.event.domain.lifecycle.ReadyEvent;
|
||||
import discord4j.core.object.entity.Guild;
|
||||
import discord4j.core.object.entity.Role;
|
||||
import discord4j.core.object.presence.Activity;
|
||||
import discord4j.core.object.presence.Presence;
|
||||
import discord4j.core.object.reaction.ReactionEmoji;
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import discord4j.store.jdk.JdkStoreService;
|
||||
import lombok.Getter;
|
||||
import lombok.val;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ButtonPlugin.ConfigOpts(disableConfigGen = true)
|
||||
public class DiscordPlugin extends ButtonPlugin {
|
||||
public static DiscordClient dc;
|
||||
public static DiscordPlugin plugin;
|
||||
public static boolean SafeMode = true;
|
||||
@Getter
|
||||
private Command2DC manager;
|
||||
|
||||
private ConfigData<Character> prefix() {
|
||||
return getIConfig().getData("prefix", '/', str -> ((String) str).charAt(0), Object::toString);
|
||||
}
|
||||
|
||||
public static char getPrefix() {
|
||||
if (plugin == null) return '/';
|
||||
return plugin.prefix().get();
|
||||
}
|
||||
|
||||
private ConfigData<Optional<Guild>> mainServer() {
|
||||
return getIConfig().getDataPrimDef("mainServer", 0L,
|
||||
id -> {
|
||||
//It attempts to get the default as well
|
||||
if ((long) id == 0L)
|
||||
return Optional.empty(); //Hack?
|
||||
return dc.getGuildById(Snowflake.of((long) id))
|
||||
.onErrorResume(t -> Mono.fromRunnable(() -> getLogger().warning("Failed to get guild: " + t.getMessage()))).blockOptional();
|
||||
},
|
||||
g -> g.map(gg -> gg.getId().asLong()).orElse(0L));
|
||||
}
|
||||
|
||||
public ConfigData<Snowflake> commandChannel() {
|
||||
return DPUtils.snowflakeData(getIConfig(), "commandChannel", 239519012529111040L);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the role doesn't exist, then it will only allow for the owner.
|
||||
*/
|
||||
public ConfigData<Mono<Role>> modRole() {
|
||||
return DPUtils.roleData(getIConfig(), "modRole", "Moderator");
|
||||
}
|
||||
|
||||
/**
|
||||
* The invite link to show by /discord invite. If empty, it defaults to the first invite if the bot has access.
|
||||
*/
|
||||
public ConfigData<String> inviteLink() {
|
||||
return getIConfig().getData("inviteLink", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pluginEnable() {
|
||||
try {
|
||||
getLogger().info("Initializing...");
|
||||
plugin = this;
|
||||
manager = new Command2DC();
|
||||
String token;
|
||||
File tokenFile = new File("TBMC", "Token.txt");
|
||||
if (tokenFile.exists()) //Legacy support
|
||||
//noinspection UnstableApiUsage
|
||||
token = Files.readFirstLine(tokenFile, StandardCharsets.UTF_8);
|
||||
else {
|
||||
File privateFile = new File(getDataFolder(), "private.yml");
|
||||
val conf = YamlConfiguration.loadConfiguration(privateFile);
|
||||
token = conf.getString("token");
|
||||
if (token == null || token.equalsIgnoreCase("Token goes here")) {
|
||||
conf.set("token", "Token goes here");
|
||||
conf.save(privateFile);
|
||||
|
||||
getLogger().severe("Token not found! Set it in private.yml");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
val cb = new DiscordClientBuilder(token);
|
||||
cb.setInitialPresence(Presence.doNotDisturb(Activity.playing("booting")));
|
||||
cb.setStoreService(new JdkStoreService()); //The default doesn't work for some reason - it's waaay faster now
|
||||
dc = cb.build();
|
||||
dc.getEventDispatcher().on(ReadyEvent.class) // Listen for ReadyEvent(s)
|
||||
.map(event -> event.getGuilds().size()) // Get how many guilds the bot is in
|
||||
.flatMap(size -> dc.getEventDispatcher()
|
||||
.on(GuildCreateEvent.class) // Listen for GuildCreateEvent(s)
|
||||
.take(size) // Take only the first `size` GuildCreateEvent(s) to be received
|
||||
.collectList()) // Take all received GuildCreateEvents and make it a List
|
||||
.subscribe(this::handleReady); /* All guilds have been received, client is fully connected */
|
||||
//dc.getEventDispatcher().on(DisconnectEvent.class);
|
||||
dc.login().subscribe();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static Guild mainServer;
|
||||
|
||||
private void handleReady(List<GuildCreateEvent> event) {
|
||||
try {
|
||||
if (mainServer != null) { //This is not the first ready event
|
||||
getLogger().info("Ready event already handled");
|
||||
return;
|
||||
}
|
||||
mainServer = mainServer().get().orElse(null); //Shouldn't change afterwards
|
||||
if (mainServer == null) {
|
||||
if (event.size() == 0) {
|
||||
getLogger().severe("Main server not found! Invite the bot and do /discord reset");
|
||||
saveConfig(); //Put default there
|
||||
return; //We should have all guilds by now, no need to retry
|
||||
}
|
||||
mainServer = event.get(0).getGuild();
|
||||
getLogger().warning("Main server set to first one: " + mainServer.getName());
|
||||
mainServer().set(Optional.of(mainServer)); //Save in config
|
||||
}
|
||||
SafeMode = false;
|
||||
DPUtils.disableIfConfigErrorRes(null, commandChannel(), DPUtils.getMessageChannel(commandChannel()));
|
||||
DPUtils.disableIfConfigError(null, modRole()); //Won't disable, just prints the warning here
|
||||
|
||||
Component.registerComponent(this, new GeneralEventBroadcasterModule());
|
||||
Component.registerComponent(this, new MinecraftChatModule());
|
||||
Component.registerComponent(this, new ExceptionListenerModule());
|
||||
Component.registerComponent(this, new GameRoleModule()); //Needs the mainServer to be set
|
||||
Component.registerComponent(this, new AnnouncerModule());
|
||||
Component.registerComponent(this, new FunModule());
|
||||
new ChromaBot(this).updatePlayerList(); //Initialize ChromaBot - The MCCHatModule is tested to be enabled
|
||||
|
||||
getManager().registerCommand(new VersionCommand());
|
||||
getManager().registerCommand(new UserinfoCommand());
|
||||
getManager().registerCommand(new HelpCommand());
|
||||
getManager().registerCommand(new DebugCommand());
|
||||
getManager().registerCommand(new ConnectCommand());
|
||||
if (DiscordMCCommand.resetting) //These will only execute if the chat is enabled
|
||||
ChromaBot.getInstance().sendMessageCustomAsWell(chan -> chan.flatMap(ch -> ch.createEmbed(ecs -> ecs.setColor(Color.CYAN)
|
||||
.setTitle("Discord plugin restarted - chat connected."))), ChannelconBroadcast.RESTART); //Really important to note the chat, hmm
|
||||
else if (getConfig().getBoolean("serverup", false)) {
|
||||
ChromaBot.getInstance().sendMessageCustomAsWell(chan -> chan.flatMap(ch -> ch.createEmbed(ecs -> ecs.setColor(Color.YELLOW)
|
||||
.setTitle("Server recovered from a crash - chat connected."))), ChannelconBroadcast.RESTART);
|
||||
val thr = new Throwable(
|
||||
"The server shut down unexpectedly. See the log of the previous run for more details.");
|
||||
thr.setStackTrace(new StackTraceElement[0]);
|
||||
TBMCCoreAPI.SendException("The server crashed!", thr);
|
||||
} else
|
||||
ChromaBot.getInstance().sendMessageCustomAsWell(chan -> chan.flatMap(ch -> ch.createEmbed(ecs -> ecs.setColor(Color.GREEN)
|
||||
.setTitle("Server started - chat connected."))), ChannelconBroadcast.RESTART);
|
||||
|
||||
DiscordMCCommand.resetting = false; //This is the last event handling this flag
|
||||
|
||||
getConfig().set("serverup", true);
|
||||
saveConfig();
|
||||
if (TBMCCoreAPI.IsTestServer() && !Objects.requireNonNull(dc.getSelf().block()).getUsername().toLowerCase().contains("test")) {
|
||||
TBMCCoreAPI.SendException(
|
||||
"Won't load because we're in testing mode and not using a separate account.",
|
||||
new Exception(
|
||||
"The plugin refuses to load until you change the token to a testing account. (The account needs to have \"test\" in its name.)"
|
||||
+ "\nYou can disable test mode in ThorpeCore config."));
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
}
|
||||
TBMCCoreAPI.SendUnsentExceptions();
|
||||
TBMCCoreAPI.SendUnsentDebugMessages();
|
||||
|
||||
CommonListeners.register(dc.getEventDispatcher());
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(), this);
|
||||
getCommand2MC().registerCommand(new DiscordMCCommand());
|
||||
TBMCCoreAPI.RegisterUserClass(DiscordPlayer.class);
|
||||
ChromaGamerBase.addConverter(sender -> Optional.ofNullable(sender instanceof DiscordSenderBase
|
||||
? ((DiscordSenderBase) sender).getChromaUser() : null));
|
||||
setupProviders();
|
||||
|
||||
IHaveConfig.pregenConfig(this, null);
|
||||
if (!TBMCCoreAPI.IsTestServer()) {
|
||||
dc.updatePresence(Presence.online(Activity.playing("Minecraft"))).subscribe();
|
||||
} else {
|
||||
dc.updatePresence(Presence.online(Activity.playing("testing"))).subscribe();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occurred while enabling DiscordPlugin!", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Always true, except when running "stop" from console
|
||||
*/
|
||||
public static boolean Restart;
|
||||
|
||||
@Override
|
||||
public void pluginPreDisable() {
|
||||
if (ChromaBot.getInstance() == null) return; //Failed to load
|
||||
Timings timings = new Timings();
|
||||
timings.printElapsed("Disable start");
|
||||
MCChatUtils.forCustomAndAllMCChat(chan -> chan.flatMap(ch -> ch.createEmbed(ecs -> {
|
||||
timings.printElapsed("Sending message to " + ch.getMention());
|
||||
if (DiscordMCCommand.resetting)
|
||||
ecs.setColor(Color.ORANGE).setTitle("Discord plugin restarting");
|
||||
else
|
||||
ecs.setColor(Restart ? Color.ORANGE : Color.RED)
|
||||
.setTitle(Restart ? "Server restarting" : "Server stopping")
|
||||
.setDescription(
|
||||
Bukkit.getOnlinePlayers().size() > 0
|
||||
? (DPUtils
|
||||
.sanitizeString(Bukkit.getOnlinePlayers().stream()
|
||||
.map(Player::getDisplayName).collect(Collectors.joining(", ")))
|
||||
+ (Bukkit.getOnlinePlayers().size() == 1 ? " was " : " were ")
|
||||
+ "kicked the hell out.") //TODO: Make configurable
|
||||
: ""); //If 'restart' is disabled then this isn't shown even if joinleave is enabled
|
||||
})).subscribe(), ChannelconBroadcast.RESTART, false);
|
||||
timings.printElapsed("Updating player list");
|
||||
ChromaBot.getInstance().updatePlayerList();
|
||||
timings.printElapsed("Done");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pluginDisable() {
|
||||
Timings timings = new Timings();
|
||||
timings.printElapsed("Actual disable start (logout)");
|
||||
MCChatPrivate.logoutAll();
|
||||
timings.printElapsed("Config setup");
|
||||
getConfig().set("serverup", false);
|
||||
if (ChromaBot.getInstance() == null) return; //Failed to load
|
||||
|
||||
saveConfig();
|
||||
try {
|
||||
SafeMode = true; // Stop interacting with Discord
|
||||
ChromaBot.delete();
|
||||
timings.printElapsed("Updating presence...");
|
||||
dc.updatePresence(Presence.idle(Activity.playing("Chromacraft"))).block(); //No longer using the same account for testing
|
||||
timings.printElapsed("Logging out...");
|
||||
dc.logout().block();
|
||||
mainServer = null; //Allow ReadyEvent again
|
||||
//Configs are emptied so channels and servers are fetched again
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while disabling DiscordPlugin!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static final ReactionEmoji DELIVERED_REACTION = ReactionEmoji.unicode("✅");
|
||||
|
||||
public static Permission perms;
|
||||
|
||||
private boolean setupProviders() {
|
||||
try {
|
||||
Class.forName("net.milkbowl.vault.permission.Permission");
|
||||
Class.forName("net.milkbowl.vault.chat.Chat");
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RegisteredServiceProvider<Permission> permsProvider = Bukkit.getServer().getServicesManager()
|
||||
.getRegistration(Permission.class);
|
||||
perms = permsProvider.getProvider();
|
||||
return perms != null;
|
||||
}
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import discord4j.core.object.entity.Member;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.User;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissibleBase;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class DiscordSender extends DiscordSenderBase implements CommandSender {
|
||||
private PermissibleBase perm = new PermissibleBase(this);
|
||||
|
||||
private String name;
|
||||
|
||||
public DiscordSender(User user, MessageChannel channel) {
|
||||
super(user, channel);
|
||||
val def = "Discord user";
|
||||
name = user == null ? def : user.asMember(DiscordPlugin.mainServer.getId()).blockOptional().map(Member::getDisplayName).orElse(def);
|
||||
}
|
||||
|
||||
public DiscordSender(User user, MessageChannel channel, String name) {
|
||||
super(user, channel);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(String name) {
|
||||
return perm.isPermissionSet(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(Permission perm) {
|
||||
return this.perm.isPermissionSet(perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String name) {
|
||||
if (name.contains("essentials") && !name.equals("essentials.list"))
|
||||
return false;
|
||||
return perm.hasPermission(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Permission perm) {
|
||||
return this.perm.hasPermission(perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
|
||||
return perm.addAttachment(plugin, name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin) {
|
||||
return perm.addAttachment(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
|
||||
return perm.addAttachment(plugin, name, value, ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
|
||||
return perm.addAttachment(plugin, ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttachment(PermissionAttachment attachment) {
|
||||
perm.removeAttachment(attachment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculatePermissions() {
|
||||
perm.recalculatePermissions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||
return perm.getEffectivePermissions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server getServer() {
|
||||
return Bukkit.getServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spigot spigot() {
|
||||
return new CommandSender.Spigot();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.User;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public abstract class DiscordSenderBase implements CommandSender {
|
||||
/**
|
||||
* May be null.
|
||||
*/
|
||||
protected User user;
|
||||
protected MessageChannel channel;
|
||||
|
||||
protected DiscordSenderBase(User user, MessageChannel channel) {
|
||||
this.user = user;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
private volatile String msgtosend = "";
|
||||
private volatile BukkitTask sendtask;
|
||||
|
||||
/**
|
||||
* Returns the user. May be null.
|
||||
*
|
||||
* @return The user or null.
|
||||
*/
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public MessageChannel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
private DiscordPlayer chromaUser;
|
||||
|
||||
/**
|
||||
* Loads the user data on first query.
|
||||
*
|
||||
* @return A Chroma user of Discord or a Discord user of Chroma
|
||||
*/
|
||||
public DiscordPlayer getChromaUser() {
|
||||
if (chromaUser == null) chromaUser = DiscordPlayer.getUser(user.getId().asString(), DiscordPlayer.class);
|
||||
return chromaUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
try {
|
||||
final boolean broadcast = new Exception().getStackTrace()[2].getMethodName().contains("broadcast");
|
||||
//if (broadcast && DiscordPlugin.hooked) - TODO: What should happen if unhooked
|
||||
if (broadcast)
|
||||
return;
|
||||
final String sendmsg = DPUtils.sanitizeString(message);
|
||||
msgtosend += "\n" + sendmsg;
|
||||
if (sendtask == null)
|
||||
sendtask = Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, () -> {
|
||||
channel.createMessage((!broadcast && user != null ? user.getMention() + "\n" : "") + msgtosend.trim()).subscribe();
|
||||
sendtask = null;
|
||||
msgtosend = "";
|
||||
}, 4); // Waits a 0.2 second to gather all/most of the different messages
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while sending message to DiscordSender", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String[] messages) {
|
||||
sendMessage(String.join("\n", messages));
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import buttondevteam.discordplugin.playerfaker.VanillaCommandListener;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface IMCPlayer<T extends DiscordSenderBase & IMCPlayer<T>> extends Player {
|
||||
VanillaCommandListener<T> getVanillaCmdListener();
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
package buttondevteam.discordplugin.announcer;
|
||||
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.architecture.ReadOnlyConfigData;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import lombok.val;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class AnnouncerModule extends Component<DiscordPlugin> {
|
||||
/**
|
||||
* Channel to post new posts.
|
||||
*/
|
||||
public ReadOnlyConfigData<Mono<MessageChannel>> channel() {
|
||||
return DPUtils.channelData(getConfig(), "channel", 239519012529111040L);
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel where distinguished (moderator) posts go.
|
||||
*/
|
||||
public ReadOnlyConfigData<Mono<MessageChannel>> modChannel() {
|
||||
return DPUtils.channelData(getConfig(), "modChannel", 239519012529111040L);
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically unpins all messages except the last few. Set to 0 or >50 to disable
|
||||
*/
|
||||
public ConfigData<Short> keepPinned() {
|
||||
return getConfig().getData("keepPinned", (short) 40);
|
||||
}
|
||||
|
||||
private ConfigData<Long> lastAnnouncementTime() {
|
||||
return getConfig().getData("lastAnnouncementTime", 0L);
|
||||
}
|
||||
|
||||
private ConfigData<Long> lastSeenTime() {
|
||||
return getConfig().getData("lastSeenTime", 0L);
|
||||
}
|
||||
|
||||
private static final String SubredditURL = "https://www.reddit.com/r/ChromaGamers";
|
||||
private static boolean stop = false;
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
if (DPUtils.disableIfConfigError(this, channel(), modChannel())) return;
|
||||
stop = false; //If not the first time
|
||||
val keepPinned = keepPinned().get();
|
||||
if (keepPinned == 0) return;
|
||||
Flux<Message> msgs = channel().get().flatMapMany(MessageChannel::getPinnedMessages);
|
||||
msgs.subscribe(Message::unpin);
|
||||
val yc = YamlConfiguration.loadConfiguration(new File("plugins/DiscordPlugin", "config.yml")); //Name change
|
||||
if (lastAnnouncementTime().get() == 0) //Load old data
|
||||
lastAnnouncementTime().set(yc.getLong("lastannouncementtime"));
|
||||
if (lastSeenTime().get() == 0)
|
||||
lastSeenTime().set(yc.getLong("lastseentime"));
|
||||
new Thread(this::AnnouncementGetterThreadMethod).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
stop = true;
|
||||
}
|
||||
|
||||
private void AnnouncementGetterThreadMethod() {
|
||||
while (!stop) {
|
||||
try {
|
||||
if (!isEnabled()) {
|
||||
Thread.sleep(10000);
|
||||
continue;
|
||||
}
|
||||
String body = TBMCCoreAPI.DownloadString(SubredditURL + "/new/.json?limit=10");
|
||||
JsonArray json = new JsonParser().parse(body).getAsJsonObject().get("data").getAsJsonObject()
|
||||
.get("children").getAsJsonArray();
|
||||
StringBuilder msgsb = new StringBuilder();
|
||||
StringBuilder modmsgsb = new StringBuilder();
|
||||
long lastanntime = lastAnnouncementTime().get();
|
||||
for (int i = json.size() - 1; i >= 0; i--) {
|
||||
JsonObject item = json.get(i).getAsJsonObject();
|
||||
final JsonObject data = item.get("data").getAsJsonObject();
|
||||
String author = data.get("author").getAsString();
|
||||
JsonElement distinguishedjson = data.get("distinguished");
|
||||
String distinguished;
|
||||
if (distinguishedjson.isJsonNull())
|
||||
distinguished = null;
|
||||
else
|
||||
distinguished = distinguishedjson.getAsString();
|
||||
String permalink = "https://www.reddit.com" + data.get("permalink").getAsString();
|
||||
long date = data.get("created_utc").getAsLong();
|
||||
if (date > lastSeenTime().get())
|
||||
lastSeenTime().set(date);
|
||||
else if (date > lastAnnouncementTime().get()) {
|
||||
do {
|
||||
val reddituserclass = ChromaGamerBase.getTypeForFolder("reddit");
|
||||
if (reddituserclass == null)
|
||||
break;
|
||||
val user = ChromaGamerBase.getUser(author, reddituserclass);
|
||||
String id = user.getConnectedID(DiscordPlayer.class);
|
||||
if (id != null)
|
||||
author = "<@" + id + ">";
|
||||
} while (false);
|
||||
if (!author.startsWith("<"))
|
||||
author = "/u/" + author;
|
||||
(distinguished != null && distinguished.equals("moderator") ? modmsgsb : msgsb)
|
||||
.append("A new post was submitted to the subreddit by ").append(author).append("\n")
|
||||
.append(permalink).append("\n");
|
||||
lastanntime = date;
|
||||
}
|
||||
}
|
||||
if (msgsb.length() > 0)
|
||||
channel().get().flatMap(ch -> ch.createMessage(msgsb.toString()))
|
||||
.flatMap(Message::pin).subscribe();
|
||||
if (modmsgsb.length() > 0)
|
||||
modChannel().get().flatMap(ch -> ch.createMessage(modmsgsb.toString()))
|
||||
.flatMap(Message::pin).subscribe();
|
||||
if (lastAnnouncementTime().get() != lastanntime)
|
||||
lastAnnouncementTime().set(lastanntime); // If sending succeeded
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package buttondevteam.discordplugin.broadcaster;
|
||||
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import lombok.Getter;
|
||||
|
||||
public class GeneralEventBroadcasterModule extends Component<DiscordPlugin> {
|
||||
private static @Getter boolean hooked = false;
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
try {
|
||||
PlayerListWatcher.hookUp();
|
||||
DPUtils.getLogger().info("Finished hooking into the player list");
|
||||
hooked = true;
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Error while hacking the player list!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
try {
|
||||
if (PlayerListWatcher.hookDown())
|
||||
DPUtils.getLogger().info("Finished unhooking the player list!");
|
||||
else
|
||||
DPUtils.getLogger().info("Didn't have the player list hooked.");
|
||||
hooked = false;
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Error while hacking the player list!", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,362 +0,0 @@
|
|||
package buttondevteam.discordplugin.broadcaster;
|
||||
|
||||
import buttondevteam.discordplugin.mcchat.MCChatUtils;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import lombok.val;
|
||||
import net.minecraft.server.v1_12_R1.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.util.CraftChatMessage;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.objenesis.ObjenesisStd;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListWatcher extends DedicatedPlayerList {
|
||||
private DedicatedPlayerList plist;
|
||||
|
||||
public PlayerListWatcher(DedicatedServer minecraftserver) {
|
||||
super(minecraftserver); // <-- Does some init stuff and calls Bukkit.setServer() so we have to use Objenesis
|
||||
}
|
||||
|
||||
public void sendAll(Packet<?> packet) {
|
||||
plist.sendAll(packet);
|
||||
try { // Some messages get sent by directly constructing a packet
|
||||
if (packet instanceof PacketPlayOutChat) {
|
||||
Field msgf = PacketPlayOutChat.class.getDeclaredField("a");
|
||||
msgf.setAccessible(true);
|
||||
MCChatUtils.forAllMCChat(MCChatUtils.send(((IChatBaseComponent) msgf.get(packet)).toPlainText()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Failed to broadcast message sent to all players - hacking failed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(IChatBaseComponent ichatbasecomponent, boolean flag) { // Needed so it calls the overriden method
|
||||
plist.getServer().sendMessage(ichatbasecomponent);
|
||||
ChatMessageType chatmessagetype = flag ? ChatMessageType.SYSTEM : ChatMessageType.CHAT;
|
||||
|
||||
// CraftBukkit start - we run this through our processor first so we can get web links etc
|
||||
this.sendAll(new PacketPlayOutChat(CraftChatMessage.fixComponent(ichatbasecomponent), chatmessagetype));
|
||||
// CraftBukkit end
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(IChatBaseComponent ichatbasecomponent) { // Needed so it calls the overriden method
|
||||
this.sendMessage(ichatbasecomponent, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(IChatBaseComponent[] iChatBaseComponents) { // Needed so it calls the overridden method
|
||||
for (IChatBaseComponent component : iChatBaseComponents) {
|
||||
sendMessage(component, true);
|
||||
}
|
||||
}
|
||||
|
||||
static void hookUp() throws Exception {
|
||||
Field conf = CraftServer.class.getDeclaredField("console");
|
||||
conf.setAccessible(true);
|
||||
val server = (MinecraftServer) conf.get(Bukkit.getServer());
|
||||
val plw = new ObjenesisStd().newInstance(PlayerListWatcher.class); // Cannot call super constructor
|
||||
plw.plist = (DedicatedPlayerList) server.getPlayerList();
|
||||
plw.maxPlayers = plw.plist.getMaxPlayers();
|
||||
Field plf = plw.getClass().getField("players");
|
||||
plf.setAccessible(true);
|
||||
Field modf = plf.getClass().getDeclaredField("modifiers");
|
||||
modf.setAccessible(true);
|
||||
modf.set(plf, plf.getModifiers() & ~Modifier.FINAL);
|
||||
plf.set(plw, plw.plist.players);
|
||||
server.a(plw);
|
||||
Field pllf = CraftServer.class.getDeclaredField("playerList");
|
||||
pllf.setAccessible(true);
|
||||
pllf.set(Bukkit.getServer(), plw);
|
||||
}
|
||||
|
||||
static boolean hookDown() throws Exception {
|
||||
Field conf = CraftServer.class.getDeclaredField("console");
|
||||
conf.setAccessible(true);
|
||||
val server = (MinecraftServer) conf.get(Bukkit.getServer());
|
||||
val plist = (DedicatedPlayerList) server.getPlayerList();
|
||||
if (!(plist instanceof PlayerListWatcher))
|
||||
return false;
|
||||
server.a(((PlayerListWatcher) plist).plist);
|
||||
Field pllf = CraftServer.class.getDeclaredField("playerList");
|
||||
pllf.setAccessible(true);
|
||||
pllf.set(Bukkit.getServer(), ((PlayerListWatcher) plist).plist);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void a(EntityHuman entityhuman, IChatBaseComponent ichatbasecomponent) {
|
||||
plist.a(entityhuman, ichatbasecomponent);
|
||||
}
|
||||
|
||||
public void a(EntityPlayer entityplayer, int i) {
|
||||
plist.a(entityplayer, i);
|
||||
}
|
||||
|
||||
public void a(EntityPlayer entityplayer, WorldServer worldserver) {
|
||||
plist.a(entityplayer, worldserver);
|
||||
}
|
||||
|
||||
public NBTTagCompound a(EntityPlayer entityplayer) {
|
||||
return plist.a(entityplayer);
|
||||
}
|
||||
|
||||
public void a(int i) {
|
||||
plist.a(i);
|
||||
}
|
||||
|
||||
public void a(NetworkManager networkmanager, EntityPlayer entityplayer) {
|
||||
plist.a(networkmanager, entityplayer);
|
||||
}
|
||||
|
||||
public void a(Packet<?> packet, int i) {
|
||||
plist.a(packet, i);
|
||||
}
|
||||
|
||||
public EntityPlayer a(UUID uuid) {
|
||||
return plist.a(uuid);
|
||||
}
|
||||
|
||||
public void addOp(GameProfile gameprofile) {
|
||||
plist.addOp(gameprofile);
|
||||
}
|
||||
|
||||
public void addWhitelist(GameProfile gameprofile) {
|
||||
plist.addWhitelist(gameprofile);
|
||||
}
|
||||
|
||||
public EntityPlayer attemptLogin(LoginListener loginlistener, GameProfile gameprofile, String hostname) {
|
||||
return plist.attemptLogin(loginlistener, gameprofile, hostname);
|
||||
}
|
||||
|
||||
public String b(boolean flag) {
|
||||
return plist.b(flag);
|
||||
}
|
||||
|
||||
public void b(EntityHuman entityhuman, IChatBaseComponent ichatbasecomponent) {
|
||||
plist.b(entityhuman, ichatbasecomponent);
|
||||
}
|
||||
|
||||
public void b(EntityPlayer entityplayer, WorldServer worldserver) {
|
||||
plist.b(entityplayer, worldserver);
|
||||
}
|
||||
|
||||
public List<EntityPlayer> b(String s) {
|
||||
return plist.b(s);
|
||||
}
|
||||
|
||||
public Location calculateTarget(Location enter, World target) {
|
||||
return plist.calculateTarget(enter, target);
|
||||
}
|
||||
|
||||
public void changeDimension(EntityPlayer entityplayer, int i, TeleportCause cause) {
|
||||
plist.changeDimension(entityplayer, i, cause);
|
||||
}
|
||||
|
||||
public void changeWorld(Entity entity, int i, WorldServer worldserver, WorldServer worldserver1) {
|
||||
plist.changeWorld(entity, i, worldserver, worldserver1);
|
||||
}
|
||||
|
||||
public int d() {
|
||||
return plist.d();
|
||||
}
|
||||
|
||||
public void d(EntityPlayer entityplayer) {
|
||||
plist.d(entityplayer);
|
||||
}
|
||||
|
||||
public String disconnect(EntityPlayer entityplayer) {
|
||||
return plist.disconnect(entityplayer);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return plist.equals(obj);
|
||||
}
|
||||
|
||||
public String[] f() {
|
||||
return plist.f();
|
||||
}
|
||||
|
||||
public void f(EntityPlayer entityplayer) {
|
||||
plist.f(entityplayer);
|
||||
}
|
||||
|
||||
public boolean f(GameProfile gameprofile) {
|
||||
return plist.f(gameprofile);
|
||||
}
|
||||
|
||||
public GameProfile[] g() {
|
||||
return plist.g();
|
||||
}
|
||||
|
||||
public boolean getHasWhitelist() {
|
||||
return plist.getHasWhitelist();
|
||||
}
|
||||
|
||||
public IpBanList getIPBans() {
|
||||
return plist.getIPBans();
|
||||
}
|
||||
|
||||
public int getMaxPlayers() {
|
||||
return plist.getMaxPlayers();
|
||||
}
|
||||
|
||||
public OpList getOPs() {
|
||||
return plist.getOPs();
|
||||
}
|
||||
|
||||
public EntityPlayer getPlayer(String s) {
|
||||
return plist.getPlayer(s);
|
||||
}
|
||||
|
||||
public int getPlayerCount() {
|
||||
return plist.getPlayerCount();
|
||||
}
|
||||
|
||||
public GameProfileBanList getProfileBans() {
|
||||
return plist.getProfileBans();
|
||||
}
|
||||
|
||||
public String[] getSeenPlayers() {
|
||||
return plist.getSeenPlayers();
|
||||
}
|
||||
|
||||
public DedicatedServer getServer() {
|
||||
return plist.getServer();
|
||||
}
|
||||
|
||||
public WhiteList getWhitelist() {
|
||||
return plist.getWhitelist();
|
||||
}
|
||||
|
||||
public String[] getWhitelisted() {
|
||||
return plist.getWhitelisted();
|
||||
}
|
||||
|
||||
public AdvancementDataPlayer h(EntityPlayer entityplayer) {
|
||||
return plist.h(entityplayer);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return plist.hashCode();
|
||||
}
|
||||
|
||||
public boolean isOp(GameProfile gameprofile) {
|
||||
return plist.isOp(gameprofile);
|
||||
}
|
||||
|
||||
public boolean isWhitelisted(GameProfile gameprofile) {
|
||||
return plist.isWhitelisted(gameprofile);
|
||||
}
|
||||
|
||||
public EntityPlayer moveToWorld(EntityPlayer entityplayer, int i, boolean flag, Location location,
|
||||
boolean avoidSuffocation) {
|
||||
return plist.moveToWorld(entityplayer, i, flag, location, avoidSuffocation);
|
||||
}
|
||||
|
||||
public EntityPlayer moveToWorld(EntityPlayer entityplayer, int i, boolean flag) {
|
||||
return plist.moveToWorld(entityplayer, i, flag);
|
||||
}
|
||||
|
||||
public String[] n() {
|
||||
return plist.n();
|
||||
}
|
||||
|
||||
public void onPlayerJoin(EntityPlayer entityplayer, String joinMessage) {
|
||||
plist.onPlayerJoin(entityplayer, joinMessage);
|
||||
}
|
||||
|
||||
public EntityPlayer processLogin(GameProfile gameprofile, EntityPlayer player) {
|
||||
return plist.processLogin(gameprofile, player);
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
plist.reload();
|
||||
}
|
||||
|
||||
public void reloadWhitelist() {
|
||||
plist.reloadWhitelist();
|
||||
}
|
||||
|
||||
public void removeOp(GameProfile gameprofile) {
|
||||
plist.removeOp(gameprofile);
|
||||
}
|
||||
|
||||
public void removeWhitelist(GameProfile gameprofile) {
|
||||
plist.removeWhitelist(gameprofile);
|
||||
}
|
||||
|
||||
public void repositionEntity(Entity entity, Location exit, boolean portal) {
|
||||
plist.repositionEntity(entity, exit, portal);
|
||||
}
|
||||
|
||||
public int s() {
|
||||
return plist.s();
|
||||
}
|
||||
|
||||
public void savePlayers() {
|
||||
plist.savePlayers();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void sendAll(Packet packet, EntityHuman entityhuman) {
|
||||
plist.sendAll(packet, entityhuman);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void sendAll(Packet packet, World world) {
|
||||
plist.sendAll(packet, world);
|
||||
}
|
||||
|
||||
public void sendPacketNearby(EntityHuman entityhuman, double d0, double d1, double d2, double d3, int i,
|
||||
Packet<?> packet) {
|
||||
plist.sendPacketNearby(entityhuman, d0, d1, d2, d3, i, packet);
|
||||
}
|
||||
|
||||
public void sendScoreboard(ScoreboardServer scoreboardserver, EntityPlayer entityplayer) {
|
||||
plist.sendScoreboard(scoreboardserver, entityplayer);
|
||||
}
|
||||
|
||||
public void setHasWhitelist(boolean flag) {
|
||||
plist.setHasWhitelist(flag);
|
||||
}
|
||||
|
||||
public void setPlayerFileData(WorldServer[] aworldserver) {
|
||||
plist.setPlayerFileData(aworldserver);
|
||||
}
|
||||
|
||||
public NBTTagCompound t() {
|
||||
return plist.t();
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
plist.tick();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return plist.toString();
|
||||
}
|
||||
|
||||
public void u() {
|
||||
plist.u();
|
||||
}
|
||||
|
||||
public void updateClient(EntityPlayer entityplayer) {
|
||||
plist.updateClient(entityplayer);
|
||||
}
|
||||
|
||||
public List<EntityPlayer> v() {
|
||||
return plist.v();
|
||||
}
|
||||
|
||||
public ServerStatisticManager getStatisticManager(EntityPlayer entityhuman) {
|
||||
return plist.getStatisticManager(entityhuman);
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class Command2DC extends Command2<ICommand2DC, Command2DCSender> {
|
||||
@Override
|
||||
public void registerCommand(ICommand2DC command) {
|
||||
super.registerCommand(command, DiscordPlugin.getPrefix()); //Needs to be configurable for the helps
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Command2DCSender sender, ICommand2DC command, Method method) {
|
||||
//return !command.isModOnly() || sender.getMessage().getAuthor().hasRole(DiscordPlugin.plugin.modRole().get()); //TODO: modRole may be null; more customisable way?
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.lib.chat.Command2Sender;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class Command2DCSender implements Command2Sender {
|
||||
private final @Getter
|
||||
Message message;
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
if (message.length() == 0) return;
|
||||
message = DPUtils.sanitizeString(message);
|
||||
message = Character.toLowerCase(message.charAt(0)) + message.substring(1);
|
||||
val msg = message;
|
||||
/*this.message.getAuthorAsMember().flatMap(author ->
|
||||
this.message.getChannel().flatMap(ch ->
|
||||
ch.createMessage(author.getNicknameMention() + ", " + msg))).subscribe();*/
|
||||
this.message.getChannel().flatMap(ch ->
|
||||
ch.createMessage(this.message.getAuthor().map(u -> DPUtils.nickMention(u.getId()) + ", ").orElse("")
|
||||
+ msg)).subscribe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String[] message) {
|
||||
sendMessage(String.join("\n", message));
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandClass(helpText = {
|
||||
"Connect command", //
|
||||
"This command lets you connect your account with a Minecraft account. This allows using the Minecraft chat and other things.", //
|
||||
})
|
||||
public class ConnectCommand extends ICommand2DC {
|
||||
|
||||
/**
|
||||
* Key: Minecraft name<br>
|
||||
* Value: Discord ID
|
||||
*/
|
||||
public static HashBiMap<String, String> WaitingToConnect = HashBiMap.create();
|
||||
|
||||
@Command2.Subcommand
|
||||
public boolean def(Command2DCSender sender, String Minecraftname) {
|
||||
val message = sender.getMessage();
|
||||
val channel = message.getChannel().block();
|
||||
val author = message.getAuthor().orElse(null);
|
||||
if (author == null || channel == null) return true;
|
||||
if (WaitingToConnect.inverse().containsKey(author.getId().asString())) {
|
||||
channel.createMessage(
|
||||
"Replacing " + WaitingToConnect.inverse().get(author.getId().asString()) + " with " + Minecraftname).subscribe();
|
||||
WaitingToConnect.inverse().remove(author.getId().asString());
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(Minecraftname);
|
||||
if (p == null) {
|
||||
channel.createMessage("The specified Minecraft player cannot be found").subscribe();
|
||||
return true;
|
||||
}
|
||||
try (TBMCPlayer pl = TBMCPlayerBase.getPlayer(p.getUniqueId(), TBMCPlayer.class)) {
|
||||
DiscordPlayer dp = pl.getAs(DiscordPlayer.class);
|
||||
if (dp != null && author.getId().asString().equals(dp.getDiscordID())) {
|
||||
channel.createMessage("You already have this account connected.").subscribe();
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while connecting a Discord account!", e);
|
||||
channel.createMessage("An internal error occured!\n" + e).subscribe();
|
||||
}
|
||||
WaitingToConnect.put(p.getName(), author.getId().asString());
|
||||
channel.createMessage(
|
||||
"Alright! Now accept the connection in Minecraft from the account " + Minecraftname
|
||||
+ " before the next server restart. You can also adjust the Minecraft name you want to connect to with the same command.").subscribe();
|
||||
if (p.isOnline())
|
||||
((Player) p).sendMessage("§bTo connect with the Discord account " + author.getUsername() + "#"
|
||||
+ author.getDiscriminator() + " do /discord accept");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.listeners.CommonListeners;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@CommandClass(helpText = {
|
||||
"Switches debug mode."
|
||||
})
|
||||
public class DebugCommand extends ICommand2DC {
|
||||
@Command2.Subcommand
|
||||
public boolean def(Command2DCSender sender) {
|
||||
sender.getMessage().getAuthorAsMember()
|
||||
.switchIfEmpty(sender.getMessage().getAuthor() //Support DMs
|
||||
.map(u -> u.asMember(DiscordPlugin.mainServer.getId()))
|
||||
.orElse(Mono.empty()))
|
||||
.flatMap(m -> DiscordPlugin.plugin.modRole().get()
|
||||
.map(mr -> m.getRoleIds().stream().anyMatch(r -> r.equals(mr.getId())))
|
||||
.switchIfEmpty(Mono.fromSupplier(() -> DiscordPlugin.mainServer.getOwnerId().asLong() == m.getId().asLong()))) //Role not found
|
||||
.subscribe(success -> {
|
||||
if (success)
|
||||
sender.sendMessage("debug " + (CommonListeners.debug() ? "enabled" : "disabled"));
|
||||
else
|
||||
sender.sendMessage("you need to be a moderator to use this command.");
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
|
||||
@CommandClass(helpText = {
|
||||
"Help command", //
|
||||
"Shows some info about a command or lists the available commands.", //
|
||||
})
|
||||
public class HelpCommand extends ICommand2DC {
|
||||
@Command2.Subcommand
|
||||
public boolean def(Command2DCSender sender, @Command2.TextArg @Command2.OptionalArg String args) {
|
||||
if (args == null || args.length() == 0)
|
||||
sender.sendMessage(getManager().getCommandsText());
|
||||
else {
|
||||
String[] ht = getManager().getHelpText(args);
|
||||
if (ht == null)
|
||||
sender.sendMessage("Command not found: " + args);
|
||||
else
|
||||
sender.sendMessage(ht);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.ICommand2;
|
||||
import lombok.Getter;
|
||||
import lombok.val;
|
||||
|
||||
public abstract class ICommand2DC extends ICommand2<Command2DCSender> {
|
||||
public <T extends ICommand2> ICommand2DC() {
|
||||
super(DiscordPlugin.plugin.getManager());
|
||||
val ann = getClass().getAnnotation(CommandClass.class);
|
||||
if (ann == null)
|
||||
modOnly = false;
|
||||
else
|
||||
modOnly = ann.modOnly();
|
||||
}
|
||||
|
||||
private final @Getter boolean modOnly;
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.User;
|
||||
import lombok.val;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandClass(helpText = {
|
||||
"User information", //
|
||||
"Shows some information about users, from Discord, from Minecraft or from Reddit if they have these accounts connected.", //
|
||||
"If used without args, shows your info.", //
|
||||
})
|
||||
public class UserinfoCommand extends ICommand2DC {
|
||||
@Command2.Subcommand
|
||||
public boolean def(Command2DCSender sender, @Command2.OptionalArg @Command2.TextArg String user) {
|
||||
val message = sender.getMessage();
|
||||
User target = null;
|
||||
val channel = message.getChannel().block();
|
||||
assert channel != null;
|
||||
if (user == null || user.length() == 0)
|
||||
target = message.getAuthor().orElse(null);
|
||||
else {
|
||||
@SuppressWarnings("OptionalGetWithoutIsPresent") final User firstmention = message.getUserMentions()
|
||||
.filter(m -> !m.getId().asString().equals(DiscordPlugin.dc.getSelfId().get().asString())).blockFirst();
|
||||
if (firstmention != null)
|
||||
target = firstmention;
|
||||
else if (user.contains("#")) {
|
||||
String[] targettag = user.split("#");
|
||||
final List<User> targets = getUsers(message, targettag[0]);
|
||||
if (targets.size() == 0) {
|
||||
channel.createMessage("The user cannot be found (by name): " + user).subscribe();
|
||||
return true;
|
||||
}
|
||||
for (User ptarget : targets) {
|
||||
if (ptarget.getDiscriminator().equalsIgnoreCase(targettag[1])) {
|
||||
target = ptarget;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (target == null) {
|
||||
channel.createMessage("The user cannot be found (by discriminator): " + user + "(Found " + targets.size()
|
||||
+ " users with the name.)").subscribe();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
final List<User> targets = getUsers(message, user);
|
||||
if (targets.size() == 0) {
|
||||
channel.createMessage("The user cannot be found on Discord: " + user).subscribe();
|
||||
return true;
|
||||
}
|
||||
if (targets.size() > 1) {
|
||||
channel.createMessage("Multiple users found with that (nick)name. Please specify the whole tag, like ChromaBot#6338 or use a ping.").subscribe();
|
||||
return true;
|
||||
}
|
||||
target = targets.get(0);
|
||||
}
|
||||
}
|
||||
if (target == null) {
|
||||
sender.sendMessage("An error occurred.");
|
||||
return true;
|
||||
}
|
||||
try (DiscordPlayer dp = ChromaGamerBase.getUser(target.getId().asString(), DiscordPlayer.class)) {
|
||||
StringBuilder uinfo = new StringBuilder("User info for ").append(target.getUsername()).append(":\n");
|
||||
uinfo.append(dp.getInfo(InfoTarget.Discord));
|
||||
channel.createMessage(uinfo.toString()).subscribe();
|
||||
} catch (Exception e) {
|
||||
channel.createMessage("An error occured while getting the user!").subscribe();
|
||||
TBMCCoreAPI.SendException("Error while getting info about " + target.getUsername() + "!", e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private List<User> getUsers(Message message, String args) {
|
||||
final List<User> targets;
|
||||
val guild = message.getGuild().block();
|
||||
if (guild == null) //Private channel
|
||||
targets = DiscordPlugin.dc.getUsers().filter(u -> u.getUsername().equalsIgnoreCase(args))
|
||||
.collectList().block();
|
||||
else
|
||||
targets = guild.getMembers().filter(m -> m.getUsername().equalsIgnoreCase(args))
|
||||
.map(m -> (User) m).collectList().block();
|
||||
return targets;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import lombok.val;
|
||||
|
||||
@CommandClass(helpText = {
|
||||
"Version",
|
||||
"Returns the plugin's version"
|
||||
})
|
||||
public class VersionCommand extends ICommand2DC {
|
||||
@Command2.Subcommand
|
||||
public boolean def(Command2DCSender sender) {
|
||||
sender.sendMessage(getVersion());
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String[] getVersion() {
|
||||
val desc = DiscordPlugin.plugin.getDescription();
|
||||
return new String[]{ //
|
||||
desc.getFullName(), //
|
||||
desc.getWebsite() //
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package buttondevteam.discordplugin.exceptions;
|
||||
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.TBMCDebugMessageEvent;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class DebugMessageListener implements Listener {
|
||||
@EventHandler
|
||||
public void onDebugMessage(TBMCDebugMessageEvent e) {
|
||||
SendMessage(e.getDebugMessage());
|
||||
e.setSent();
|
||||
}
|
||||
|
||||
private static void SendMessage(String message) {
|
||||
if (DiscordPlugin.SafeMode || !ComponentManager.isEnabled(ExceptionListenerModule.class))
|
||||
return;
|
||||
try {
|
||||
Mono<MessageChannel> mc = ExceptionListenerModule.getChannel();
|
||||
if (mc == null) return;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("```").append("\n");
|
||||
if (message.length() > 2000)
|
||||
message = message.substring(0, 2000);
|
||||
sb.append(message).append("\n");
|
||||
sb.append("```");
|
||||
mc.flatMap(ch -> ch.createMessage(sb.toString())).subscribe();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
package buttondevteam.discordplugin.exceptions;
|
||||
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.TBMCExceptionEvent;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.architecture.ReadOnlyConfigData;
|
||||
import discord4j.core.object.entity.Guild;
|
||||
import discord4j.core.object.entity.GuildChannel;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.Role;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ExceptionListenerModule extends Component<DiscordPlugin> implements Listener {
|
||||
private List<Throwable> lastthrown = new ArrayList<>();
|
||||
private List<String> lastsourcemsg = new ArrayList<>();
|
||||
|
||||
@EventHandler
|
||||
public void onException(TBMCExceptionEvent e) {
|
||||
if (DiscordPlugin.SafeMode || !ComponentManager.isEnabled(getClass()))
|
||||
return;
|
||||
if (lastthrown.stream()
|
||||
.anyMatch(ex -> Arrays.equals(e.getException().getStackTrace(), ex.getStackTrace())
|
||||
&& (e.getException().getMessage() == null ? ex.getMessage() == null
|
||||
: e.getException().getMessage().equals(ex.getMessage()))) // e.Exception.Message==ex.Message
|
||||
&& lastsourcemsg.contains(e.getSourceMessage()))
|
||||
return;
|
||||
SendException(e.getException(), e.getSourceMessage());
|
||||
if (lastthrown.size() >= 10)
|
||||
lastthrown.remove(0);
|
||||
if (lastsourcemsg.size() >= 10)
|
||||
lastsourcemsg.remove(0);
|
||||
lastthrown.add(e.getException());
|
||||
lastsourcemsg.add(e.getSourceMessage());
|
||||
e.setHandled();
|
||||
}
|
||||
|
||||
private static void SendException(Throwable e, String sourcemessage) {
|
||||
if (instance == null) return;
|
||||
try {
|
||||
Mono<MessageChannel> channel = getChannel();
|
||||
assert channel != null;
|
||||
Mono<Role> coderRole;
|
||||
if (channel instanceof GuildChannel)
|
||||
coderRole = instance.pingRole(((GuildChannel) channel).getGuild()).get();
|
||||
else
|
||||
coderRole = Mono.empty();
|
||||
coderRole.map(role -> TBMCCoreAPI.IsTestServer() ? new StringBuilder()
|
||||
: new StringBuilder(role.getMention()).append("\n"))
|
||||
.defaultIfEmpty(new StringBuilder())
|
||||
.flatMap(sb -> {
|
||||
sb.append(sourcemessage).append("\n");
|
||||
sb.append("```").append("\n");
|
||||
String stackTrace = Arrays.stream(ExceptionUtils.getStackTrace(e).split("\\n"))
|
||||
.filter(s -> !s.contains("\tat ") || s.contains("\tat buttondevteam."))
|
||||
.collect(Collectors.joining("\n"));
|
||||
if (sb.length() + stackTrace.length() >= 1980)
|
||||
stackTrace = stackTrace.substring(0, 1980 - sb.length());
|
||||
sb.append(stackTrace).append("\n");
|
||||
sb.append("```");
|
||||
return channel.flatMap(ch -> ch.createMessage(sb.toString()));
|
||||
}).subscribe();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static ExceptionListenerModule instance;
|
||||
|
||||
public static Mono<MessageChannel> getChannel() {
|
||||
if (instance != null) return instance.channel().get();
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
private ReadOnlyConfigData<Mono<MessageChannel>> channel() {
|
||||
return DPUtils.channelData(getConfig(), "channel", 239519012529111040L);
|
||||
}
|
||||
|
||||
private ConfigData<Mono<Role>> pingRole(Mono<Guild> guild) {
|
||||
return DPUtils.roleData(getConfig(), "pingRole", "Coder", guild);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
if (DPUtils.disableIfConfigError(this, channel())) return;
|
||||
instance = this;
|
||||
Bukkit.getPluginManager().registerEvents(new ExceptionListenerModule(), getPlugin());
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(new DebugMessageListener(), getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
instance = null;
|
||||
}
|
||||
}
|
|
@ -1,156 +0,0 @@
|
|||
package buttondevteam.discordplugin.fun;
|
||||
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.architecture.ReadOnlyConfigData;
|
||||
import com.google.common.collect.Lists;
|
||||
import discord4j.core.event.domain.PresenceUpdateEvent;
|
||||
import discord4j.core.object.entity.*;
|
||||
import discord4j.core.object.presence.Status;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* The YEEHAW event uses an emoji named :YEEHAW: if available
|
||||
*/
|
||||
public class FunModule extends Component<DiscordPlugin> implements Listener {
|
||||
private static final String[] serverReadyStrings = new String[]{"In one week from now", // Ali
|
||||
"Between now and the heat-death of the universe.", // Ghostise
|
||||
"Soonâ„¢", "Ask again this time next month", // Ghostise
|
||||
"In about 3 seconds", // Nicolai
|
||||
"After we finish 8 plugins", // Ali
|
||||
"Tomorrow.", // Ali
|
||||
"After one tiiiny feature", // Ali
|
||||
"Next commit", // Ali
|
||||
"After we finish strangling Towny", // Ali
|
||||
"When we kill every *fucking* bug", // Ali
|
||||
"Once the server stops screaming.", // Ali
|
||||
"After HL3 comes out", // Ali
|
||||
"Next time you ask", // Ali
|
||||
"When will *you* be open?" // Ali
|
||||
};
|
||||
|
||||
/**
|
||||
* Questions that the bot will choose a random answer to give to.
|
||||
*/
|
||||
private ConfigData<String[]> serverReady() {
|
||||
return getConfig().getData("serverReady", () -> new String[]{"when will the server be open",
|
||||
"when will the server be ready", "when will the server be done", "when will the server be complete",
|
||||
"when will the server be finished", "when's the server ready", "when's the server open",
|
||||
"Vhen vill ze server be open?"});
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers for a recognized question. Selected randomly.
|
||||
*/
|
||||
private ConfigData<ArrayList<String>> serverReadyAnswers() {
|
||||
return getConfig().getData("serverReadyAnswers", () -> Lists.newArrayList(serverReadyStrings)); //TODO: Test
|
||||
}
|
||||
|
||||
private static final Random serverReadyRandom = new Random();
|
||||
private static final ArrayList<Short> usableServerReadyStrings = new ArrayList<>(0);
|
||||
|
||||
private void createUsableServerReadyStrings() {
|
||||
IntStream.range(0, serverReadyAnswers().get().size())
|
||||
.forEach(i -> FunModule.usableServerReadyStrings.add((short) i));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
registerListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
lastlist = lastlistp = ListC = 0;
|
||||
}
|
||||
|
||||
private static short lastlist = 0;
|
||||
private static short lastlistp = 0;
|
||||
|
||||
private static short ListC = 0;
|
||||
|
||||
public static boolean executeMemes(Message message) {
|
||||
val fm = ComponentManager.getIfEnabled(FunModule.class);
|
||||
if (fm == null) return false;
|
||||
String msglowercased = message.getContent().orElse("").toLowerCase();
|
||||
lastlist++;
|
||||
if (lastlist > 5) {
|
||||
ListC = 0;
|
||||
lastlist = 0;
|
||||
}
|
||||
if (msglowercased.equals("list") && Bukkit.getOnlinePlayers().size() == lastlistp && ListC++ > 2) // Lowered already
|
||||
{
|
||||
DPUtils.reply(message, null, "Stop it. You know the answer.").subscribe();
|
||||
lastlist = 0;
|
||||
lastlistp = (short) Bukkit.getOnlinePlayers().size();
|
||||
return true; //Handled
|
||||
}
|
||||
lastlistp = (short) Bukkit.getOnlinePlayers().size(); //Didn't handle
|
||||
if (!TBMCCoreAPI.IsTestServer()
|
||||
&& Arrays.stream(fm.serverReady().get()).anyMatch(msglowercased::contains)) {
|
||||
int next;
|
||||
if (usableServerReadyStrings.size() == 0)
|
||||
fm.createUsableServerReadyStrings();
|
||||
next = usableServerReadyStrings.remove(serverReadyRandom.nextInt(usableServerReadyStrings.size()));
|
||||
DPUtils.reply(message, null, fm.serverReadyAnswers().get().get(next)).subscribe();
|
||||
return false; //Still process it as a command/mcchat if needed
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
ListC = 0;
|
||||
}
|
||||
|
||||
private ConfigData<Mono<Role>> fullHouseDevRole(Mono<Guild> guild) {
|
||||
return DPUtils.roleData(getConfig(), "fullHouseDevRole", "Developer", guild);
|
||||
}
|
||||
|
||||
|
||||
private ReadOnlyConfigData<Mono<MessageChannel>> fullHouseChannel() {
|
||||
return DPUtils.channelData(getConfig(), "fullHouseChannel", 219626707458457603L);
|
||||
}
|
||||
|
||||
private static long lasttime = 0;
|
||||
|
||||
public static void handleFullHouse(PresenceUpdateEvent event) {
|
||||
val fm = ComponentManager.getIfEnabled(FunModule.class);
|
||||
if (fm == null) return;
|
||||
if (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) % 5 != 0) return;
|
||||
fm.fullHouseChannel().get()
|
||||
.filter(ch -> ch instanceof GuildChannel)
|
||||
.flatMap(channel -> fm.fullHouseDevRole(((GuildChannel) channel).getGuild()).get()
|
||||
.filter(role -> event.getOld().map(p -> p.getStatus().equals(Status.OFFLINE)).orElse(false))
|
||||
.filter(role -> !event.getCurrent().getStatus().equals(Status.OFFLINE))
|
||||
.filterWhen(devrole -> event.getMember().flatMap(m -> m.getRoles()
|
||||
.any(r -> r.getId().asLong() == devrole.getId().asLong())))
|
||||
.filterWhen(devrole ->
|
||||
event.getGuild().flatMapMany(g -> g.getMembers().filter(m -> m.getRoleIds().stream().anyMatch(s -> s.equals(devrole.getId()))))
|
||||
.flatMap(Member::getPresence).all(pr -> !pr.getStatus().equals(Status.OFFLINE)))
|
||||
.filter(devrole -> lasttime + 10 < TimeUnit.NANOSECONDS.toHours(System.nanoTime())) //This should stay so it checks this last
|
||||
.flatMap(devrole -> {
|
||||
lasttime = TimeUnit.NANOSECONDS.toHours(System.nanoTime());
|
||||
return channel.createMessage(mcs -> mcs.setContent("Full house!").setEmbed(ecs ->
|
||||
ecs.setImage(
|
||||
"https://cdn.discordapp.com/attachments/249295547263877121/249687682618359808/poker-hand-full-house-aces-kings-playing-cards-15553791.png")
|
||||
));
|
||||
})).subscribe();
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
package buttondevteam.discordplugin.listeners;
|
||||
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.commands.Command2DCSender;
|
||||
import buttondevteam.discordplugin.util.Timings;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.PrivateChannel;
|
||||
import discord4j.core.object.entity.Role;
|
||||
import lombok.val;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class CommandListener {
|
||||
/**
|
||||
* Runs a ChromaBot command. If mentionedonly is false, it will only execute the command if it was in #bot with the correct prefix or in private.
|
||||
*
|
||||
* @param message The Discord message
|
||||
* @param mentionedonly Only run the command if ChromaBot is mentioned at the start of the message
|
||||
* @return Whether it <b>did not run</b> the command
|
||||
*/
|
||||
public static Mono<Boolean> runCommand(Message message, MessageChannel commandChannel, boolean mentionedonly) {
|
||||
Timings timings = CommonListeners.timings;
|
||||
Mono<Boolean> ret = Mono.just(true);
|
||||
if (!message.getContent().isPresent())
|
||||
return ret; //Pin messages and such, let the mcchat listener deal with it
|
||||
val content = message.getContent().get();
|
||||
timings.printElapsed("A");
|
||||
return message.getChannel().flatMap(channel -> {
|
||||
Mono<?> tmp = ret;
|
||||
if (!mentionedonly) { //mentionedonly conditions are in CommonListeners
|
||||
timings.printElapsed("B");
|
||||
if (!(channel instanceof PrivateChannel)
|
||||
&& !(content.charAt(0) == DiscordPlugin.getPrefix()
|
||||
&& channel.getId().asLong() == commandChannel.getId().asLong())) //
|
||||
return ret;
|
||||
timings.printElapsed("C");
|
||||
tmp = ret.then(channel.type()).thenReturn(true); // Fun (this true is ignored - x)
|
||||
}
|
||||
final StringBuilder cmdwithargs = new StringBuilder(content);
|
||||
val gotmention = new AtomicBoolean();
|
||||
timings.printElapsed("Before self");
|
||||
return tmp.flatMapMany(x ->
|
||||
DiscordPlugin.dc.getSelf().flatMap(self -> self.asMember(DiscordPlugin.mainServer.getId()))
|
||||
.flatMapMany(self -> {
|
||||
timings.printElapsed("D");
|
||||
gotmention.set(checkanddeletemention(cmdwithargs, self.getMention(), message));
|
||||
gotmention.set(checkanddeletemention(cmdwithargs, self.getNicknameMention(), message) || gotmention.get());
|
||||
val mentions = message.getRoleMentions();
|
||||
return self.getRoles().filterWhen(r -> mentions.any(rr -> rr.getName().equals(r.getName())))
|
||||
.map(Role::getMention);
|
||||
}).map(mentionRole -> {
|
||||
timings.printElapsed("E");
|
||||
gotmention.set(checkanddeletemention(cmdwithargs, mentionRole, message) || gotmention.get()); // Delete all mentions
|
||||
return !mentionedonly || gotmention.get(); //Stops here if false
|
||||
}).switchIfEmpty(Mono.fromSupplier(() -> !mentionedonly || gotmention.get())))
|
||||
.filter(b -> b).last(false).filter(b -> b).doOnNext(b -> channel.type().subscribe()).flatMap(b -> {
|
||||
String cmdwithargsString = cmdwithargs.toString();
|
||||
try {
|
||||
timings.printElapsed("F");
|
||||
if (!DiscordPlugin.plugin.getManager().handleCommand(new Command2DCSender(message), cmdwithargsString))
|
||||
return DPUtils.reply(message, channel, "Unknown command. Do " + DiscordPlugin.getPrefix() + "help for help.\n" + cmdwithargsString)
|
||||
.map(m -> false);
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Failed to process Discord command: " + cmdwithargsString, e);
|
||||
}
|
||||
return Mono.just(false); //If the command succeeded or there was an error, return false
|
||||
}).defaultIfEmpty(true);
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean checkanddeletemention(StringBuilder cmdwithargs, String mention, Message message) {
|
||||
final char prefix = DiscordPlugin.getPrefix();
|
||||
if (message.getContent().orElse("").startsWith(mention)) // TODO: Resolve mentions: Compound arguments, either a mention or text
|
||||
if (cmdwithargs.length() > mention.length() + 1) {
|
||||
int i = cmdwithargs.indexOf(" ", mention.length());
|
||||
if (i == -1)
|
||||
i = mention.length();
|
||||
else
|
||||
//noinspection StatementWithEmptyBody
|
||||
for (; i < cmdwithargs.length() && cmdwithargs.charAt(i) == ' '; i++)
|
||||
; //Removes any space before the command
|
||||
cmdwithargs.delete(0, i);
|
||||
cmdwithargs.insert(0, prefix); //Always use the prefix for processing
|
||||
} else
|
||||
cmdwithargs.replace(0, cmdwithargs.length(), prefix + "help");
|
||||
else {
|
||||
if (cmdwithargs.length() == 0)
|
||||
cmdwithargs.replace(0, cmdwithargs.length(), prefix + "help");
|
||||
else if (cmdwithargs.charAt(0) != prefix)
|
||||
cmdwithargs.insert(0, prefix);
|
||||
return false; //Don't treat / as mention, mentions can be used in public mcchat
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
package buttondevteam.discordplugin.listeners;
|
||||
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.fun.FunModule;
|
||||
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
||||
import buttondevteam.discordplugin.role.GameRoleModule;
|
||||
import buttondevteam.discordplugin.util.Timings;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import discord4j.core.event.EventDispatcher;
|
||||
import discord4j.core.event.domain.PresenceUpdateEvent;
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import discord4j.core.event.domain.role.RoleCreateEvent;
|
||||
import discord4j.core.event.domain.role.RoleDeleteEvent;
|
||||
import discord4j.core.event.domain.role.RoleUpdateEvent;
|
||||
import discord4j.core.object.entity.PrivateChannel;
|
||||
import lombok.val;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class CommonListeners {
|
||||
|
||||
public static final Timings timings = new Timings();
|
||||
|
||||
/*
|
||||
MentionEvent:
|
||||
- CommandListener (starts with mention, only 'channelcon' and not in #bot)
|
||||
|
||||
MessageReceivedEvent:
|
||||
- v CommandListener (starts with mention, in #bot or a connected chat)
|
||||
- Minecraft chat (is enabled in the channel and message isn't [/]mcchat)
|
||||
- CommandListener (with the correct prefix in #bot, or in private)
|
||||
*/
|
||||
public static void register(EventDispatcher dispatcher) {
|
||||
dispatcher.on(MessageCreateEvent.class).flatMap(event -> {
|
||||
timings.printElapsed("Message received");
|
||||
val def = Mono.empty();
|
||||
if (DiscordPlugin.SafeMode)
|
||||
return def;
|
||||
val author = event.getMessage().getAuthor();
|
||||
if (!author.isPresent() || author.get().isBot())
|
||||
return def;
|
||||
if (FunModule.executeMemes(event.getMessage()))
|
||||
return def;
|
||||
val commandChannel = DiscordPlugin.plugin.commandChannel().get();
|
||||
val commandCh = DPUtils.getMessageChannel(DiscordPlugin.plugin.commandChannel());
|
||||
return commandCh.filterWhen(ch -> event.getMessage().getChannel().map(mch ->
|
||||
(commandChannel != null && mch.getId().asLong() == commandChannel.asLong()) //If mentioned, that's higher than chat
|
||||
|| mch instanceof PrivateChannel
|
||||
|| event.getMessage().getContent().orElse("").contains("channelcon")) //Only 'channelcon' is allowed in other channels
|
||||
.flatMap(shouldRun -> { //Only continue if this doesn't handle the event
|
||||
if (!shouldRun)
|
||||
return Mono.just(true); //The condition is only for the first command execution, not mcchat
|
||||
timings.printElapsed("Run command 1");
|
||||
return CommandListener.runCommand(event.getMessage(), ch, true); //#bot is handled here
|
||||
})).filterWhen(ch -> {
|
||||
timings.printElapsed("mcchat");
|
||||
val mcchat = Component.getComponents().get(MinecraftChatModule.class);
|
||||
if (mcchat != null && mcchat.isEnabled()) //ComponentManager.isEnabled() searches the component again
|
||||
return ((MinecraftChatModule) mcchat).getListener().handleDiscord(event); //Also runs Discord commands in chat channels
|
||||
return Mono.empty(); //Wasn't handled, continue
|
||||
}).filterWhen(ch -> {
|
||||
timings.printElapsed("Run command 2");
|
||||
return CommandListener.runCommand(event.getMessage(), ch, false);
|
||||
});
|
||||
}).onErrorContinue((err, obj) -> TBMCCoreAPI.SendException("An error occured while handling a message!", err))
|
||||
.subscribe();
|
||||
dispatcher.on(PresenceUpdateEvent.class).subscribe(event -> {
|
||||
if (DiscordPlugin.SafeMode)
|
||||
return;
|
||||
FunModule.handleFullHouse(event);
|
||||
});
|
||||
dispatcher.on(RoleCreateEvent.class).subscribe(GameRoleModule::handleRoleEvent);
|
||||
dispatcher.on(RoleDeleteEvent.class).subscribe(GameRoleModule::handleRoleEvent);
|
||||
dispatcher.on(RoleUpdateEvent.class).subscribe(GameRoleModule::handleRoleEvent);
|
||||
|
||||
}
|
||||
|
||||
private static boolean debug = false;
|
||||
|
||||
public static void debug(String debug) {
|
||||
if (CommonListeners.debug) //Debug
|
||||
DPUtils.getLogger().info(debug);
|
||||
}
|
||||
|
||||
public static boolean debug() {
|
||||
return debug = !debug;
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package buttondevteam.discordplugin.listeners;
|
||||
|
||||
public interface DiscordListener {
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package buttondevteam.discordplugin.listeners;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.commands.ConnectCommand;
|
||||
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
|
||||
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
||||
import discord4j.core.object.entity.Member;
|
||||
import discord4j.core.object.entity.User;
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import lombok.val;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerCommandEvent;
|
||||
|
||||
public class MCListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(TBMCPlayerJoinEvent e) {
|
||||
if (ConnectCommand.WaitingToConnect.containsKey(e.GetPlayer().PlayerName().get())) {
|
||||
@SuppressWarnings("ConstantConditions") User user = DiscordPlugin.dc
|
||||
.getUserById(Snowflake.of(ConnectCommand.WaitingToConnect.get(e.GetPlayer().PlayerName().get()))).block();
|
||||
if (user == null) return;
|
||||
e.getPlayer().sendMessage("§bTo connect with the Discord account @" + user.getUsername() + "#" + user.getDiscriminator()
|
||||
+ " do /discord accept");
|
||||
e.getPlayer().sendMessage("§bIf it wasn't you, do /discord decline");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onGetInfo(TBMCPlayerGetInfoEvent e) {
|
||||
if (DiscordPlugin.SafeMode)
|
||||
return;
|
||||
DiscordPlayer dp = e.getPlayer().getAs(DiscordPlayer.class);
|
||||
if (dp == null || dp.getDiscordID() == null || dp.getDiscordID().equals(""))
|
||||
return;
|
||||
User user = DiscordPlugin.dc.getUserById(Snowflake.of(dp.getDiscordID())).block();
|
||||
if (user == null) return;
|
||||
e.addInfo("Discord tag: " + user.getUsername() + "#" + user.getDiscriminator());
|
||||
Member member = user.asMember(DiscordPlugin.mainServer.getId()).block();
|
||||
if (member == null) return;
|
||||
val pr = member.getPresence().block();
|
||||
if (pr == null) return;
|
||||
e.addInfo(pr.getStatus().toString());
|
||||
if (pr.getActivity().isPresent()) {
|
||||
val activity = pr.getActivity().get();
|
||||
e.addInfo(activity.getType() + ": " + activity.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerCommand(ServerCommandEvent e) {
|
||||
DiscordPlugin.Restart = !e.getCommand().equalsIgnoreCase("stop"); // The variable is always true except if stopped
|
||||
}
|
||||
}
|
|
@ -1,157 +0,0 @@
|
|||
package buttondevteam.discordplugin.mcchat;
|
||||
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.core.component.channel.ChatRoom;
|
||||
import buttondevteam.discordplugin.*;
|
||||
import buttondevteam.discordplugin.commands.Command2DCSender;
|
||||
import buttondevteam.discordplugin.commands.ICommand2DC;
|
||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.util.Permission;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandClass(helpText = {"Channel connect", //
|
||||
"This command allows you to connect a Minecraft channel to a Discord channel (just like how the global chat is connected to #minecraft-chat).", //
|
||||
"You need to have access to the MC channel and have manage permissions on the Discord channel.", //
|
||||
"You also need to have your Minecraft account connected. In #bot use /connect <mcname>.", //
|
||||
"Call this command from the channel you want to use.", //
|
||||
"Usage: @Bot channelcon <mcchannel>", //
|
||||
"Use the ID (command) of the channel, for example `g` for the global chat.", //
|
||||
"To remove a connection use @ChromaBot channelcon remove in the channel.", //
|
||||
"Mentioning the bot is needed in this case because the / prefix only works in #bot.", //
|
||||
"Invite link: <https://discordapp.com/oauth2/authorize?client_id=226443037893591041&scope=bot&permissions=268509264>" //
|
||||
})
|
||||
@RequiredArgsConstructor
|
||||
public class ChannelconCommand extends ICommand2DC {
|
||||
private final MinecraftChatModule module;
|
||||
@Command2.Subcommand
|
||||
public boolean remove(Command2DCSender sender) {
|
||||
val message = sender.getMessage();
|
||||
if (checkPerms(message)) return true;
|
||||
if (MCChatCustom.removeCustomChat(message.getChannelId()))
|
||||
DPUtils.reply(message, null, "channel connection removed.").subscribe();
|
||||
else
|
||||
DPUtils.reply(message, null, "this channel isn't connected.").subscribe();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Command2.Subcommand
|
||||
public boolean toggle(Command2DCSender sender, @Command2.OptionalArg String toggle) {
|
||||
val message = sender.getMessage();
|
||||
if (checkPerms(message)) return true;
|
||||
val cc = MCChatCustom.getCustomChat(message.getChannelId());
|
||||
if (cc == null)
|
||||
return respond(sender, "this channel isn't connected.");
|
||||
Supplier<String> togglesString = () -> Arrays.stream(ChannelconBroadcast.values()).map(t -> t.toString().toLowerCase() + ": " + ((cc.toggles & t.flag) == 0 ? "disabled" : "enabled")).collect(Collectors.joining("\n"))
|
||||
+ "\n\n" + TBMCSystemChatEvent.BroadcastTarget.stream().map(target -> target.getName() + ": " + (cc.brtoggles.contains(target) ? "enabled" : "disabled")).collect(Collectors.joining("\n"));
|
||||
if (toggle == null) {
|
||||
DPUtils.reply(message, null, "toggles:\n" + togglesString.get()).subscribe();
|
||||
return true;
|
||||
}
|
||||
String arg = toggle.toUpperCase();
|
||||
val b = Arrays.stream(ChannelconBroadcast.values()).filter(t -> t.toString().equals(arg)).findAny();
|
||||
if (!b.isPresent()) {
|
||||
val bt = TBMCSystemChatEvent.BroadcastTarget.get(arg);
|
||||
if (bt == null) {
|
||||
DPUtils.reply(message, null, "cannot find toggle. Toggles:\n" + togglesString.get()).subscribe();
|
||||
return true;
|
||||
}
|
||||
final boolean add;
|
||||
if (add = !cc.brtoggles.contains(bt))
|
||||
cc.brtoggles.add(bt);
|
||||
else
|
||||
cc.brtoggles.remove(bt);
|
||||
return respond(sender, "'" + bt.getName() + "' " + (add ? "en" : "dis") + "abled");
|
||||
}
|
||||
//A B | F
|
||||
//------- A: original - B: mask - F: new
|
||||
//0 0 | 0
|
||||
//0 1 | 1
|
||||
//1 0 | 1
|
||||
//1 1 | 0
|
||||
// XOR
|
||||
cc.toggles ^= b.get().flag;
|
||||
DPUtils.reply(message, null, "'" + b.get().toString().toLowerCase() + "' " + ((cc.toggles & b.get().flag) == 0 ? "disabled" : "enabled")).subscribe();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Command2.Subcommand
|
||||
public boolean def(Command2DCSender sender, String channelID) {
|
||||
val message = sender.getMessage();
|
||||
if (checkPerms(message)) return true;
|
||||
if (MCChatCustom.hasCustomChat(message.getChannelId()))
|
||||
return respond(sender, "this channel is already connected to a Minecraft channel. Use `@ChromaBot channelcon remove` to remove it.");
|
||||
val chan = Channel.getChannels().filter(ch -> ch.ID.equalsIgnoreCase(channelID) || (Arrays.stream(ch.IDs().get()).anyMatch(cid -> cid.equalsIgnoreCase(channelID)))).findAny();
|
||||
if (!chan.isPresent()) { //TODO: Red embed that disappears over time (kinda like the highlight messages in OW)
|
||||
DPUtils.reply(message, null, "MC channel with ID '" + channelID + "' not found! The ID is the command for it without the /.").subscribe();
|
||||
return true;
|
||||
}
|
||||
if (!message.getAuthor().isPresent()) return true;
|
||||
val author = message.getAuthor().get();
|
||||
val dp = DiscordPlayer.getUser(author.getId().asString(), DiscordPlayer.class);
|
||||
val chp = dp.getAs(TBMCPlayer.class);
|
||||
if (chp == null) {
|
||||
DPUtils.reply(message, null, "you need to connect your Minecraft account. On our server in " + DPUtils.botmention() + " do " + DiscordPlugin.getPrefix() + "connect <MCname>").subscribe();
|
||||
return true;
|
||||
}
|
||||
val channel = message.getChannel().block();
|
||||
DiscordConnectedPlayer dcp = new DiscordConnectedPlayer(message.getAuthor().get(), channel, chp.getUUID(), Bukkit.getOfflinePlayer(chp.getUUID()).getName(), module);
|
||||
//Using a fake player with no login/logout, should be fine for this event
|
||||
String groupid = chan.get().getGroupID(dcp);
|
||||
if (groupid == null && !(chan.get() instanceof ChatRoom)) { //ChatRooms don't allow it unless the user joins, which happens later
|
||||
DPUtils.reply(message, null, "sorry, you cannot use that Minecraft channel.").subscribe();
|
||||
return true;
|
||||
}
|
||||
if (chan.get() instanceof ChatRoom) { //ChatRooms don't work well
|
||||
DPUtils.reply(message, null, "chat rooms are not supported yet.").subscribe();
|
||||
return true;
|
||||
}
|
||||
/*if (MCChatListener.getCustomChats().stream().anyMatch(cc -> cc.groupID.equals(groupid) && cc.mcchannel.ID.equals(chan.get().ID))) {
|
||||
DPUtils.reply(message, null, "sorry, this MC chat is already connected to a different channel, multiple channels are not supported atm.");
|
||||
return true;
|
||||
}*/ //TODO: "Channel admins" that can connect channels?
|
||||
MCChatCustom.addCustomChat(channel, groupid, chan.get(), author, dcp, 0, new HashSet<>());
|
||||
if (chan.get() instanceof ChatRoom)
|
||||
DPUtils.reply(message, null, "alright, connection made to the room!").subscribe();
|
||||
else
|
||||
DPUtils.reply(message, null, "alright, connection made to group `" + groupid + "`!").subscribe();
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
private boolean checkPerms(Message message) {
|
||||
if (!message.getAuthorAsMember().block().getBasePermissions().block().contains(Permission.MANAGE_CHANNELS)) {
|
||||
DPUtils.reply(message, null, "you need to have manage permissions for this channel!").subscribe();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getHelpText(Method method, Command2.Subcommand ann) {
|
||||
return new String[]{ //
|
||||
"Channel connect", //
|
||||
"This command allows you to connect a Minecraft channel to a Discord channel (just like how the global chat is connected to #minecraft-chat).", //
|
||||
"You need to have access to the MC channel and have manage permissions on the Discord channel.", //
|
||||
"You also need to have your Minecraft account connected. In " + DPUtils.botmention() + " use " + DiscordPlugin.getPrefix() + "connect <mcname>.", //
|
||||
"Call this command from the channel you want to use.", //
|
||||
"Usage: " + Objects.requireNonNull(DiscordPlugin.dc.getSelf().block()).getMention() + " channelcon <mcchannel>", //
|
||||
"Use the ID (command) of the channel, for example `g` for the global chat.", //
|
||||
"To remove a connection use @ChromaBot channelcon remove in the channel.", //
|
||||
"Mentioning the bot is needed in this case because the " + DiscordPlugin.getPrefix() + " prefix only works in " + DPUtils.botmention() + ".", //
|
||||
"Invite link: <https://discordapp.com/oauth2/authorize?client_id=226443037893591041&scope=bot&permissions=268509264>" // TODO: Set correct client ID
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package buttondevteam.discordplugin.mcchat;
|
||||
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.commands.Command2DCSender;
|
||||
import buttondevteam.discordplugin.commands.ICommand2DC;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import discord4j.core.object.entity.PrivateChannel;
|
||||
import lombok.val;
|
||||
|
||||
@CommandClass(helpText = {
|
||||
"MC Chat",
|
||||
"This command enables or disables the Minecraft chat in private messages.", //
|
||||
"It can be useful if you don't want your messages to be visible, for example when talking in a private channel.", //
|
||||
"You can also run all of the ingame commands you have access to using this command, if you have your accounts connected." //
|
||||
})
|
||||
public class MCChatCommand extends ICommand2DC {
|
||||
|
||||
@Command2.Subcommand
|
||||
public boolean def(Command2DCSender sender) {
|
||||
val message = sender.getMessage();
|
||||
val channel = message.getChannel().block();
|
||||
@SuppressWarnings("OptionalGetWithoutIsPresent") val author = message.getAuthor().get();
|
||||
if (!(channel instanceof PrivateChannel)) {
|
||||
DPUtils.reply(message, null, "this command can only be issued in a direct message with the bot.").subscribe();
|
||||
return true;
|
||||
}
|
||||
try (final DiscordPlayer user = DiscordPlayer.getUser(author.getId().asString(), DiscordPlayer.class)) {
|
||||
boolean mcchat = !user.isMinecraftChatEnabled();
|
||||
MCChatPrivate.privateMCChat(channel, mcchat, author, user);
|
||||
DPUtils.reply(message, null, "Minecraft chat " + (mcchat //
|
||||
? "enabled. Use '" + DiscordPlugin.getPrefix() + "mcchat' again to turn it off." //
|
||||
: "disabled.")).subscribe();
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Error while setting mcchat for user " + author.getUsername() + "#" + author.getDiscriminator(), e);
|
||||
}
|
||||
return true;
|
||||
} // TODO: Pin channel switching to indicate the current channel
|
||||
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
package buttondevteam.discordplugin.mcchat;
|
||||
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.core.component.channel.ChatRoom;
|
||||
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.User;
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import lombok.NonNull;
|
||||
import lombok.val;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MCChatCustom {
|
||||
/**
|
||||
* Used for town or nation chats or anything else
|
||||
*/
|
||||
static ArrayList<CustomLMD> lastmsgCustom = new ArrayList<>();
|
||||
|
||||
public static void addCustomChat(MessageChannel channel, String groupid, Channel mcchannel, User user, DiscordConnectedPlayer dcp, int toggles, Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles) {
|
||||
if (mcchannel instanceof ChatRoom) {
|
||||
((ChatRoom) mcchannel).joinRoom(dcp);
|
||||
if (groupid == null) groupid = mcchannel.getGroupID(dcp);
|
||||
}
|
||||
val lmd = new CustomLMD(channel, user, groupid, mcchannel, dcp, toggles, brtoggles);
|
||||
lastmsgCustom.add(lmd);
|
||||
}
|
||||
|
||||
public static boolean hasCustomChat(Snowflake channel) {
|
||||
return lastmsgCustom.stream().anyMatch(lmd -> lmd.channel.getId().asLong() == channel.asLong());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CustomLMD getCustomChat(Snowflake channel) {
|
||||
return lastmsgCustom.stream().filter(lmd -> lmd.channel.getId().asLong() == channel.asLong()).findAny().orElse(null);
|
||||
}
|
||||
|
||||
public static boolean removeCustomChat(Snowflake channel) {
|
||||
MCChatUtils.lastmsgfromd.remove(channel.asLong());
|
||||
return lastmsgCustom.removeIf(lmd -> {
|
||||
if (lmd.channel.getId().asLong() != channel.asLong())
|
||||
return false;
|
||||
if (lmd.mcchannel instanceof ChatRoom)
|
||||
((ChatRoom) lmd.mcchannel).leaveRoom(lmd.dcp);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public static List<CustomLMD> getCustomChats() {
|
||||
return Collections.unmodifiableList(lastmsgCustom);
|
||||
}
|
||||
|
||||
public static class CustomLMD extends MCChatUtils.LastMsgData {
|
||||
public final String groupID;
|
||||
public final Channel mcchannel;
|
||||
public final DiscordConnectedPlayer dcp;
|
||||
public int toggles;
|
||||
public Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles;
|
||||
|
||||
private CustomLMD(@NonNull MessageChannel channel, @NonNull User user,
|
||||
@NonNull String groupid, @NonNull Channel mcchannel, @NonNull DiscordConnectedPlayer dcp, int toggles, Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles) {
|
||||
super(channel, user);
|
||||
groupID = groupid;
|
||||
this.mcchannel = mcchannel;
|
||||
this.dcp = dcp;
|
||||
this.toggles = toggles;
|
||||
this.brtoggles = brtoggles;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,415 +0,0 @@
|
|||
package buttondevteam.discordplugin.mcchat;
|
||||
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.core.component.channel.ChatRoom;
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.DiscordSender;
|
||||
import buttondevteam.discordplugin.DiscordSenderBase;
|
||||
import buttondevteam.discordplugin.listeners.CommandListener;
|
||||
import buttondevteam.discordplugin.listeners.CommonListeners;
|
||||
import buttondevteam.discordplugin.playerfaker.VanillaCommandListener;
|
||||
import buttondevteam.discordplugin.util.Timings;
|
||||
import buttondevteam.lib.*;
|
||||
import buttondevteam.lib.chat.ChatMessage;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import com.vdurmont.emoji.EmojiParser;
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import discord4j.core.object.Embed;
|
||||
import discord4j.core.object.entity.*;
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import discord4j.core.spec.EmbedCreateSpec;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.awt.*;
|
||||
import java.time.Instant;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MCChatListener implements Listener {
|
||||
private BukkitTask sendtask;
|
||||
private LinkedBlockingQueue<AbstractMap.SimpleEntry<TBMCChatEvent, Instant>> sendevents = new LinkedBlockingQueue<>();
|
||||
private Runnable sendrunnable;
|
||||
private static Thread sendthread;
|
||||
private final MinecraftChatModule module;
|
||||
|
||||
public MCChatListener(MinecraftChatModule minecraftChatModule) {
|
||||
module = minecraftChatModule;
|
||||
}
|
||||
|
||||
@EventHandler // Minecraft
|
||||
public void onMCChat(TBMCChatEvent ev) {
|
||||
if (!ComponentManager.isEnabled(MinecraftChatModule.class) || ev.isCancelled()) //SafeMode: Needed so it doesn't restart after server shutdown
|
||||
return;
|
||||
sendevents.add(new AbstractMap.SimpleEntry<>(ev, Instant.now()));
|
||||
if (sendtask != null)
|
||||
return;
|
||||
sendrunnable = () -> {
|
||||
sendthread = Thread.currentThread();
|
||||
processMCToDiscord();
|
||||
if (DiscordPlugin.plugin.isEnabled()) //Don't run again if shutting down
|
||||
sendtask = Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin, sendrunnable);
|
||||
};
|
||||
sendtask = Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin, sendrunnable);
|
||||
}
|
||||
|
||||
private void processMCToDiscord() {
|
||||
try {
|
||||
TBMCChatEvent e;
|
||||
Instant time;
|
||||
val se = sendevents.take(); // Wait until an element is available
|
||||
e = se.getKey();
|
||||
time = se.getValue();
|
||||
|
||||
final String authorPlayer = "[" + DPUtils.sanitizeStringNoEscape(e.getChannel().DisplayName().get()) + "] " //
|
||||
+ ("Minecraft".equals(e.getOrigin()) ? "" : "[" + e.getOrigin().substring(0, 1) + "]") //
|
||||
+ (DPUtils.sanitizeStringNoEscape(ThorpeUtils.getDisplayName(e.getSender())));
|
||||
val color = e.getChannel().Color().get();
|
||||
final Consumer<EmbedCreateSpec> embed = ecs -> {
|
||||
ecs.setDescription(e.getMessage()).setColor(new Color(color.getRed(),
|
||||
color.getGreen(), color.getBlue()));
|
||||
if (e.getSender() instanceof Player)
|
||||
DPUtils.embedWithHead(ecs, authorPlayer, e.getSender().getName(),
|
||||
"https://tbmcplugins.github.io/profile.html?type=minecraft&id="
|
||||
+ ((Player) e.getSender()).getUniqueId());
|
||||
else if (e.getSender() instanceof DiscordSenderBase)
|
||||
ecs.setAuthor(authorPlayer, "https://tbmcplugins.github.io/profile.html?type=discord&id=" // TODO: Constant/method to get URLs like this
|
||||
+ ((DiscordSenderBase) e.getSender()).getUser().getId().asString(),
|
||||
((DiscordSenderBase) e.getSender()).getUser().getAvatarUrl());
|
||||
else
|
||||
DPUtils.embedWithHead(ecs, authorPlayer, e.getSender().getName(), null);
|
||||
ecs.setTimestamp(time);
|
||||
};
|
||||
final long nanoTime = System.nanoTime();
|
||||
InterruptibleConsumer<MCChatUtils.LastMsgData> doit = lastmsgdata -> {
|
||||
if (lastmsgdata.message == null
|
||||
|| !authorPlayer.equals(lastmsgdata.message.getEmbeds().get(0).getAuthor().map(Embed.Author::getName).orElse(null))
|
||||
|| lastmsgdata.time / 1000000000f < nanoTime / 1000000000f - 120
|
||||
|| !lastmsgdata.mcchannel.ID.equals(e.getChannel().ID)) {
|
||||
lastmsgdata.message = lastmsgdata.channel.createEmbed(embed).block();
|
||||
lastmsgdata.time = nanoTime;
|
||||
lastmsgdata.mcchannel = e.getChannel();
|
||||
lastmsgdata.content = e.getMessage();
|
||||
} else {
|
||||
lastmsgdata.content = lastmsgdata.content + "\n"
|
||||
+ e.getMessage(); // The message object doesn't get updated
|
||||
lastmsgdata.message.edit(mes -> mes.setEmbed(embed.andThen(ecs ->
|
||||
ecs.setDescription(lastmsgdata.content)))).block();
|
||||
}
|
||||
};
|
||||
// Checks if the given channel is different than where the message was sent from
|
||||
// Or if it was from MC
|
||||
Predicate<Snowflake> isdifferentchannel = id -> !(e.getSender() instanceof DiscordSenderBase)
|
||||
|| ((DiscordSenderBase) e.getSender()).getChannel().getId().asLong() != id.asLong();
|
||||
|
||||
if (e.getChannel().isGlobal()
|
||||
&& (e.isFromCommand() || isdifferentchannel.test(module.chatChannel().get())))
|
||||
doit.accept(MCChatUtils.lastmsgdata == null
|
||||
? MCChatUtils.lastmsgdata = new MCChatUtils.LastMsgData(module.chatChannelMono().block(), null)
|
||||
: MCChatUtils.lastmsgdata);
|
||||
|
||||
for (MCChatUtils.LastMsgData data : MCChatPrivate.lastmsgPerUser) {
|
||||
if ((e.isFromCommand() || isdifferentchannel.test(data.channel.getId()))
|
||||
&& e.shouldSendTo(MCChatUtils.getSender(data.channel.getId(), data.user)))
|
||||
doit.accept(data);
|
||||
}
|
||||
|
||||
val iterator = MCChatCustom.lastmsgCustom.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
val lmd = iterator.next();
|
||||
if ((e.isFromCommand() || isdifferentchannel.test(lmd.channel.getId())) //Test if msg is from Discord
|
||||
&& e.getChannel().ID.equals(lmd.mcchannel.ID) //If it's from a command, the command msg has been deleted, so we need to send it
|
||||
&& e.getGroupID().equals(lmd.groupID)) { //Check if this is the group we want to test - #58
|
||||
if (e.shouldSendTo(lmd.dcp)) //Check original user's permissions
|
||||
doit.accept(lmd);
|
||||
else {
|
||||
iterator.remove(); //If the user no longer has permission, remove the connection
|
||||
lmd.channel.createMessage("The user no longer has permission to view the channel, connection removed.").subscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException ex) { //Stop if interrupted anywhere
|
||||
sendtask.cancel();
|
||||
sendtask = null;
|
||||
} catch (Exception ex) {
|
||||
TBMCCoreAPI.SendException("Error while sending message to Discord!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChatPreprocess(TBMCChatPreprocessEvent event) {
|
||||
int start = -1;
|
||||
while ((start = event.getMessage().indexOf('@', start + 1)) != -1) {
|
||||
int mid = event.getMessage().indexOf('#', start + 1);
|
||||
if (mid == -1)
|
||||
return;
|
||||
int end_ = event.getMessage().indexOf(' ', mid + 1);
|
||||
if (end_ == -1)
|
||||
end_ = event.getMessage().length();
|
||||
final int end = end_;
|
||||
final int startF = start;
|
||||
val user = DiscordPlugin.dc.getUsers().filter(u -> u.getUsername().equals(event.getMessage().substring(startF + 1, mid)))
|
||||
.filter(u -> u.getDiscriminator().equals(event.getMessage().substring(mid + 1, end))).blockFirst();
|
||||
if (user != null) //TODO: Nicknames
|
||||
event.setMessage(event.getMessage().substring(0, startF) + "@" + user.getUsername()
|
||||
+ (event.getMessage().length() > end ? event.getMessage().substring(end) : "")); // TODO: Add formatting
|
||||
start = end; // Skip any @s inside the mention
|
||||
}
|
||||
}
|
||||
|
||||
// ......................DiscordSender....DiscordConnectedPlayer.DiscordPlayerSender
|
||||
// Offline public chat......x............................................
|
||||
// Online public chat.......x...........................................x
|
||||
// Offline private chat.....x.......................x....................
|
||||
// Online private chat......x.......................x...................x
|
||||
// If online and enabling private chat, don't login
|
||||
// If leaving the server and private chat is enabled (has ConnectedPlayer), call login in a task on lowest priority
|
||||
// If private chat is enabled and joining the server, logout the fake player on highest priority
|
||||
// If online and disabling private chat, don't logout
|
||||
// The maps may not contain the senders for UnconnectedSenders
|
||||
|
||||
/**
|
||||
* Stop the listener. Any calls to onMCChat will restart it as long as we're not in safe mode.
|
||||
*
|
||||
* @param wait Wait 5 seconds for the threads to stop
|
||||
*/
|
||||
public static void stop(boolean wait) {
|
||||
if (sendthread != null) sendthread.interrupt();
|
||||
if (recthread != null) recthread.interrupt();
|
||||
try {
|
||||
if (sendthread != null) {
|
||||
sendthread.interrupt();
|
||||
if (wait)
|
||||
sendthread.join(5000);
|
||||
}
|
||||
if (recthread != null) {
|
||||
recthread.interrupt();
|
||||
if (wait)
|
||||
recthread.join(5000);
|
||||
}
|
||||
MCChatUtils.lastmsgdata = null;
|
||||
MCChatPrivate.lastmsgPerUser.clear();
|
||||
MCChatCustom.lastmsgCustom.clear();
|
||||
MCChatUtils.lastmsgfromd.clear();
|
||||
MCChatUtils.ConnectedSenders.clear();
|
||||
MCChatUtils.UnconnectedSenders.clear();
|
||||
recthread = sendthread = null;
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace(); //This thread shouldn't be interrupted
|
||||
}
|
||||
}
|
||||
|
||||
private BukkitTask rectask;
|
||||
private LinkedBlockingQueue<MessageCreateEvent> recevents = new LinkedBlockingQueue<>();
|
||||
private Runnable recrun;
|
||||
private static Thread recthread;
|
||||
|
||||
// Discord
|
||||
public Mono<Boolean> handleDiscord(MessageCreateEvent ev) {
|
||||
val ret = Mono.just(true);
|
||||
if (!ComponentManager.isEnabled(MinecraftChatModule.class))
|
||||
return ret;
|
||||
Timings timings = CommonListeners.timings;
|
||||
timings.printElapsed("Chat event");
|
||||
val author = ev.getMessage().getAuthor();
|
||||
final boolean hasCustomChat = MCChatCustom.hasCustomChat(ev.getMessage().getChannelId());
|
||||
return ev.getMessage().getChannel().filter(channel -> {
|
||||
timings.printElapsed("Filter 1");
|
||||
return !(ev.getMessage().getChannelId().asLong() != module.chatChannel().get().asLong()
|
||||
&& !(channel instanceof PrivateChannel
|
||||
&& author.map(u -> MCChatPrivate.isMinecraftChatEnabled(u.getId().asString())).orElse(false)
|
||||
&& !hasCustomChat)); //Chat isn't enabled on this channel
|
||||
}).filter(channel -> {
|
||||
timings.printElapsed("Filter 2");
|
||||
return !(channel instanceof PrivateChannel //Only in private chat
|
||||
&& ev.getMessage().getContent().isPresent()
|
||||
&& ev.getMessage().getContent().get().length() < "/mcchat<>".length()
|
||||
&& ev.getMessage().getContent().get().replace("/", "")
|
||||
.equalsIgnoreCase("mcchat")); //Either mcchat or /mcchat
|
||||
//Allow disabling the chat if needed
|
||||
}).filterWhen(channel -> CommandListener.runCommand(ev.getMessage(), channel, true))
|
||||
//Allow running commands in chat channels
|
||||
.filter(channel -> {
|
||||
MCChatUtils.resetLastMessage(channel);
|
||||
recevents.add(ev);
|
||||
timings.printElapsed("Message event added");
|
||||
if (rectask != null)
|
||||
return true;
|
||||
recrun = () -> { //Don't return in a while loop next time
|
||||
recthread = Thread.currentThread();
|
||||
processDiscordToMC();
|
||||
if (DiscordPlugin.plugin.isEnabled()) //Don't run again if shutting down
|
||||
rectask = Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin, recrun); //Continue message processing
|
||||
};
|
||||
rectask = Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin, recrun); //Start message processing
|
||||
return true;
|
||||
}).map(b -> false).defaultIfEmpty(true);
|
||||
}
|
||||
|
||||
private void processDiscordToMC() {
|
||||
MessageCreateEvent event;
|
||||
try {
|
||||
event = recevents.take();
|
||||
} catch (InterruptedException e1) {
|
||||
rectask.cancel();
|
||||
return;
|
||||
}
|
||||
val sender = event.getMessage().getAuthor().orElse(null);
|
||||
String dmessage = event.getMessage().getContent().orElse("");
|
||||
try {
|
||||
final DiscordSenderBase dsender = MCChatUtils.getSender(event.getMessage().getChannelId(), sender);
|
||||
val user = dsender.getChromaUser();
|
||||
|
||||
for (User u : event.getMessage().getUserMentions().toIterable()) { //TODO: Role mentions
|
||||
dmessage = dmessage.replace(u.getMention(), "@" + u.getUsername()); // TODO: IG Formatting
|
||||
val m = u.asMember(DiscordPlugin.mainServer.getId()).block();
|
||||
if (m != null) {
|
||||
final String nick = m.getDisplayName();
|
||||
dmessage = dmessage.replace(m.getNicknameMention(), "@" + nick);
|
||||
}
|
||||
}
|
||||
for (GuildChannel ch : event.getGuild().flux().flatMap(Guild::getChannels).toIterable()) {
|
||||
dmessage = dmessage.replace(ch.getMention(), "#" + ch.getName()); // TODO: IG Formatting
|
||||
}
|
||||
|
||||
dmessage = EmojiParser.parseToAliases(dmessage, EmojiParser.FitzpatrickAction.PARSE); //Converts emoji to text- TODO: Add option to disable (resource pack?)
|
||||
dmessage = dmessage.replaceAll(":(\\S+)\\|type_(?:(\\d)|(1)_2):", ":$1::skin-tone-$2:"); //Convert to Discord's format so it still shows up
|
||||
|
||||
Function<String, String> getChatMessage = msg -> //
|
||||
msg + (event.getMessage().getAttachments().size() > 0 ? "\n" + event.getMessage()
|
||||
.getAttachments().stream().map(Attachment::getUrl).collect(Collectors.joining("\n"))
|
||||
: "");
|
||||
|
||||
MCChatCustom.CustomLMD clmd = MCChatCustom.getCustomChat(event.getMessage().getChannelId());
|
||||
|
||||
boolean react = false;
|
||||
|
||||
val sendChannel = event.getMessage().getChannel().block();
|
||||
boolean isPrivate = sendChannel instanceof PrivateChannel;
|
||||
if (dmessage.startsWith("/")) { // Ingame command
|
||||
if (!isPrivate)
|
||||
event.getMessage().delete().subscribe();
|
||||
final String cmd = dmessage.substring(1);
|
||||
final String cmdlowercased = cmd.toLowerCase();
|
||||
if (dsender instanceof DiscordSender && module.whitelistedCommands().get().stream()
|
||||
.noneMatch(s -> cmdlowercased.equals(s) || cmdlowercased.startsWith(s + " "))) {
|
||||
// Command not whitelisted
|
||||
dsender.sendMessage("Sorry, you can only access these commands:\n"
|
||||
+ module.whitelistedCommands().get().stream().map(uc -> "/" + uc)
|
||||
.collect(Collectors.joining(", "))
|
||||
+ (user.getConnectedID(TBMCPlayer.class) == null
|
||||
? "\nTo access your commands, first please connect your accounts, using /connect in "
|
||||
+ DPUtils.botmention()
|
||||
+ "\nThen y"
|
||||
: "\nY")
|
||||
+ "ou can access all of your regular commands (even offline) in private chat: DM me `mcchat`!");
|
||||
return;
|
||||
}
|
||||
val ev = new TBMCCommandPreprocessEvent(dsender, dmessage);
|
||||
Bukkit.getPluginManager().callEvent(ev);
|
||||
if (ev.isCancelled())
|
||||
return;
|
||||
int spi = cmdlowercased.indexOf(' ');
|
||||
final String topcmd = spi == -1 ? cmdlowercased : cmdlowercased.substring(0, spi);
|
||||
Optional<Channel> ch = Channel.getChannels()
|
||||
.filter(c -> c.ID.equalsIgnoreCase(topcmd)
|
||||
|| (c.IDs().get().length > 0
|
||||
&& Arrays.stream(c.IDs().get()).anyMatch(id -> id.equalsIgnoreCase(topcmd)))).findAny();
|
||||
if (!ch.isPresent()) //TODO: What if talking in the public chat while we have it on a different one
|
||||
Bukkit.getScheduler().runTask(DiscordPlugin.plugin, //Commands need to be run sync
|
||||
() -> { //TODO: Better handling...
|
||||
val channel = user.channel();
|
||||
val chtmp = channel.get();
|
||||
if (clmd != null) {
|
||||
channel.set(clmd.mcchannel); //Hack to send command in the channel
|
||||
} //TODO: Permcheck isn't implemented for commands
|
||||
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd);
|
||||
Bukkit.getLogger().info(dsender.getName() + " issued command from Discord: /" + cmdlowercased);
|
||||
if (clmd != null)
|
||||
channel.set(chtmp);
|
||||
});
|
||||
else {
|
||||
Channel chc = ch.get();
|
||||
if (!chc.isGlobal() && !isPrivate)
|
||||
dsender.sendMessage(
|
||||
"You can only talk in a public chat here. DM `mcchat` to enable private chat to talk in the other channels.");
|
||||
else {
|
||||
if (spi == -1) // Switch channels
|
||||
{
|
||||
val channel = dsender.getChromaUser().channel();
|
||||
val oldch = channel.get();
|
||||
if (oldch instanceof ChatRoom)
|
||||
((ChatRoom) oldch).leaveRoom(dsender);
|
||||
if (!oldch.ID.equals(chc.ID)) {
|
||||
channel.set(chc);
|
||||
if (chc instanceof ChatRoom)
|
||||
((ChatRoom) chc).joinRoom(dsender);
|
||||
} else
|
||||
channel.set(Channel.GlobalChat);
|
||||
dsender.sendMessage("You're now talking in: "
|
||||
+ DPUtils.sanitizeString(channel.get().DisplayName().get()));
|
||||
} else { // Send single message
|
||||
final String msg = cmd.substring(spi + 1);
|
||||
val cmb = ChatMessage.builder(dsender, user, getChatMessage.apply(msg)).fromCommand(true);
|
||||
if (clmd == null)
|
||||
TBMCChatAPI.SendChatMessage(cmb.build(), chc);
|
||||
else
|
||||
TBMCChatAPI.SendChatMessage(cmb.permCheck(clmd.dcp).build(), chc);
|
||||
react = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {// Not a command
|
||||
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0
|
||||
&& !isPrivate && event.getMessage().getType() == Message.Type.CHANNEL_PINNED_MESSAGE) {
|
||||
val rtr = clmd != null ? clmd.mcchannel.getRTR(clmd.dcp)
|
||||
: dsender.getChromaUser().channel().get().getRTR(dsender);
|
||||
TBMCChatAPI.SendSystemMessage(clmd != null ? clmd.mcchannel : dsender.getChromaUser().channel().get(), rtr,
|
||||
(dsender instanceof Player ? ((Player) dsender).getDisplayName()
|
||||
: dsender.getName()) + " pinned a message on Discord.", TBMCSystemChatEvent.BroadcastTarget.ALL);
|
||||
} else {
|
||||
val cmb = ChatMessage.builder(dsender, user, getChatMessage.apply(dmessage)).fromCommand(false);
|
||||
if (clmd != null)
|
||||
TBMCChatAPI.SendChatMessage(cmb.permCheck(clmd.dcp).build(), clmd.mcchannel);
|
||||
else
|
||||
TBMCChatAPI.SendChatMessage(cmb.build());
|
||||
react = true;
|
||||
}
|
||||
}
|
||||
if (react) {
|
||||
try {
|
||||
val lmfd = MCChatUtils.lastmsgfromd.get(event.getMessage().getChannelId().asLong());
|
||||
if (lmfd != null) {
|
||||
lmfd.removeSelfReaction(DiscordPlugin.DELIVERED_REACTION).subscribe(); // Remove it no matter what, we know it's there 99.99% of the time
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while removing reactions from chat!", e);
|
||||
}
|
||||
MCChatUtils.lastmsgfromd.put(event.getMessage().getChannelId().asLong(), event.getMessage());
|
||||
event.getMessage().addReaction(DiscordPlugin.DELIVERED_REACTION).subscribe();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while handling message \"" + dmessage + "\"!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface InterruptibleConsumer<T> {
|
||||
void accept(T value) throws TimeoutException, InterruptedException;
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
package buttondevteam.discordplugin.mcchat;
|
||||
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.PrivateChannel;
|
||||
import discord4j.core.object.entity.User;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MCChatPrivate {
|
||||
|
||||
/**
|
||||
* Used for messages in PMs (mcchat).
|
||||
*/
|
||||
static ArrayList<MCChatUtils.LastMsgData> lastmsgPerUser = new ArrayList<>();
|
||||
|
||||
public static boolean privateMCChat(MessageChannel channel, boolean start, User user, DiscordPlayer dp) {
|
||||
TBMCPlayer mcp = dp.getAs(TBMCPlayer.class);
|
||||
if (mcp != null) { // If the accounts aren't connected, can't make a connected sender
|
||||
val p = Bukkit.getPlayer(mcp.getUUID());
|
||||
val op = Bukkit.getOfflinePlayer(mcp.getUUID());
|
||||
val mcm = ComponentManager.getIfEnabled(MinecraftChatModule.class);
|
||||
if (start) {
|
||||
val sender = new DiscordConnectedPlayer(user, channel, mcp.getUUID(), op.getName(), mcm);
|
||||
MCChatUtils.addSender(MCChatUtils.ConnectedSenders, user, sender);
|
||||
if (p == null)// Player is offline - If the player is online, that takes precedence
|
||||
MCChatUtils.callLoginEvents(sender);
|
||||
} else {
|
||||
val sender = MCChatUtils.removeSender(MCChatUtils.ConnectedSenders, channel.getId(), user);
|
||||
assert sender != null;
|
||||
if (p == null // Player is offline - If the player is online, that takes precedence
|
||||
&& sender.isLoggedIn()) //Don't call the quit event if login failed
|
||||
MCChatUtils.callLogoutEvent(sender, true);
|
||||
sender.setLoggedIn(false);
|
||||
}
|
||||
} // ---- PermissionsEx warning is normal on logout ----
|
||||
if (!start)
|
||||
MCChatUtils.lastmsgfromd.remove(channel.getId().asLong());
|
||||
return start //
|
||||
? lastmsgPerUser.add(new MCChatUtils.LastMsgData(channel, user)) // Doesn't support group DMs
|
||||
: lastmsgPerUser.removeIf(lmd -> lmd.channel.getId().asLong() == channel.getId().asLong());
|
||||
}
|
||||
|
||||
public static boolean isMinecraftChatEnabled(DiscordPlayer dp) {
|
||||
return isMinecraftChatEnabled(dp.getDiscordID());
|
||||
}
|
||||
|
||||
public static boolean isMinecraftChatEnabled(String did) { // Don't load the player data just for this
|
||||
return lastmsgPerUser.stream()
|
||||
.anyMatch(lmd -> ((PrivateChannel) lmd.channel)
|
||||
.getRecipientIds().stream().anyMatch(u -> u.asString().equals(did)));
|
||||
}
|
||||
|
||||
public static void logoutAll() {
|
||||
for (val entry : MCChatUtils.ConnectedSenders.entrySet())
|
||||
for (val valueEntry : entry.getValue().entrySet())
|
||||
if (MCChatUtils.getSender(MCChatUtils.OnlineSenders, valueEntry.getKey(), valueEntry.getValue().getUser()) == null) //If the player is online then the fake player was already logged out
|
||||
MCChatUtils.callLogoutEvent(valueEntry.getValue(), false); //This is sync
|
||||
MCChatUtils.ConnectedSenders.clear();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,367 +0,0 @@
|
|||
package buttondevteam.discordplugin.mcchat;
|
||||
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.discordplugin.*;
|
||||
import buttondevteam.discordplugin.broadcaster.GeneralEventBroadcasterModule;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||
import com.google.common.collect.Sets;
|
||||
import discord4j.core.object.entity.*;
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import io.netty.util.collection.LongObjectHashMap;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.var;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.AuthorNagException;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredListener;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class MCChatUtils {
|
||||
/**
|
||||
* May contain P<DiscordID> as key for public chat
|
||||
*/
|
||||
public static final HashMap<String, HashMap<Snowflake, DiscordSender>> UnconnectedSenders = new HashMap<>();
|
||||
public static final HashMap<String, HashMap<Snowflake, DiscordConnectedPlayer>> ConnectedSenders = new HashMap<>();
|
||||
/**
|
||||
* May contain P<DiscordID> as key for public chat
|
||||
*/
|
||||
public static final HashMap<String, HashMap<Snowflake, DiscordPlayerSender>> OnlineSenders = new HashMap<>();
|
||||
static @Nullable LastMsgData lastmsgdata;
|
||||
static LongObjectHashMap<Message> lastmsgfromd = new LongObjectHashMap<>(); // Last message sent by a Discord user, used for clearing checkmarks
|
||||
private static MinecraftChatModule module;
|
||||
private static HashMap<Class<? extends Event>, HashSet<String>> staticExcludedPlugins = new HashMap<>();
|
||||
|
||||
public static void updatePlayerList() {
|
||||
if (notEnabled()) return;
|
||||
if (lastmsgdata != null)
|
||||
updatePL(lastmsgdata);
|
||||
MCChatCustom.lastmsgCustom.forEach(MCChatUtils::updatePL);
|
||||
}
|
||||
|
||||
private static boolean notEnabled() {
|
||||
return getModule() == null;
|
||||
}
|
||||
|
||||
private static MinecraftChatModule getModule() {
|
||||
if (module == null) module = ComponentManager.getIfEnabled(MinecraftChatModule.class);
|
||||
else if (!module.isEnabled()) module = null; //Reset if disabled
|
||||
return module;
|
||||
}
|
||||
|
||||
private static void updatePL(LastMsgData lmd) {
|
||||
if (!(lmd.channel instanceof TextChannel)) {
|
||||
TBMCCoreAPI.SendException("Failed to update player list for channel " + lmd.channel.getId(),
|
||||
new Exception("The channel isn't a (guild) text channel."));
|
||||
return;
|
||||
}
|
||||
String topic = ((TextChannel) lmd.channel).getTopic().orElse("");
|
||||
if (topic.length() == 0)
|
||||
topic = ".\n----\nMinecraft chat\n----\n.";
|
||||
String[] s = topic.split("\\n----\\n");
|
||||
if (s.length < 3)
|
||||
return;
|
||||
s[0] = Bukkit.getOnlinePlayers().size() + " player" + (Bukkit.getOnlinePlayers().size() != 1 ? "s" : "")
|
||||
+ " online";
|
||||
s[s.length - 1] = "Players: " + Bukkit.getOnlinePlayers().stream()
|
||||
.map(p -> DPUtils.sanitizeString(p.getDisplayName())).collect(Collectors.joining(", "));
|
||||
((TextChannel) lmd.channel).edit(tce -> tce.setTopic(String.join("\n----\n", s)).setReason("Player list update")).subscribe(); //Don't wait
|
||||
}
|
||||
|
||||
public static <T extends DiscordSenderBase> T addSender(HashMap<String, HashMap<Snowflake, T>> senders,
|
||||
User user, T sender) {
|
||||
return addSender(senders, user.getId().asString(), sender);
|
||||
}
|
||||
|
||||
public static <T extends DiscordSenderBase> T addSender(HashMap<String, HashMap<Snowflake, T>> senders,
|
||||
String did, T sender) {
|
||||
var map = senders.get(did);
|
||||
if (map == null)
|
||||
map = new HashMap<>();
|
||||
map.put(sender.getChannel().getId(), sender);
|
||||
senders.put(did, map);
|
||||
return sender;
|
||||
}
|
||||
|
||||
public static <T extends DiscordSenderBase> T getSender(HashMap<String, HashMap<Snowflake, T>> senders,
|
||||
Snowflake channel, User user) {
|
||||
var map = senders.get(user.getId().asString());
|
||||
if (map != null)
|
||||
return map.get(channel);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T extends DiscordSenderBase> T removeSender(HashMap<String, HashMap<Snowflake, T>> senders,
|
||||
Snowflake channel, User user) {
|
||||
var map = senders.get(user.getId().asString());
|
||||
if (map != null)
|
||||
return map.remove(channel);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void forAllMCChat(Consumer<Mono<MessageChannel>> action) {
|
||||
if (notEnabled()) return;
|
||||
action.accept(module.chatChannelMono());
|
||||
for (LastMsgData data : MCChatPrivate.lastmsgPerUser)
|
||||
action.accept(Mono.just(data.channel));
|
||||
// lastmsgCustom.forEach(cc -> action.accept(cc.channel)); - Only send relevant messages to custom chat
|
||||
}
|
||||
|
||||
/**
|
||||
* For custom and all MC chat
|
||||
*
|
||||
* @param action The action to act
|
||||
* @param toggle The toggle to check
|
||||
* @param hookmsg Whether the message is also sent from the hook
|
||||
*/
|
||||
public static void forCustomAndAllMCChat(Consumer<Mono<MessageChannel>> action, @Nullable ChannelconBroadcast toggle, boolean hookmsg) {
|
||||
if (notEnabled()) return;
|
||||
if (!GeneralEventBroadcasterModule.isHooked() || !hookmsg)
|
||||
forAllMCChat(action);
|
||||
final Consumer<MCChatCustom.CustomLMD> customLMDConsumer = cc -> action.accept(Mono.just(cc.channel));
|
||||
if (toggle == null)
|
||||
MCChatCustom.lastmsgCustom.forEach(customLMDConsumer);
|
||||
else
|
||||
MCChatCustom.lastmsgCustom.stream().filter(cc -> (cc.toggles & toggle.flag) != 0).forEach(customLMDConsumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the {@code action} for each custom chat the {@code sender} have access to and has that broadcast type enabled.
|
||||
*
|
||||
* @param action The action to do
|
||||
* @param sender The sender to check perms of or null to send to all that has it toggled
|
||||
* @param toggle The toggle to check or null to send to all allowed
|
||||
*/
|
||||
public static void forAllowedCustomMCChat(Consumer<Mono<MessageChannel>> action, @Nullable CommandSender sender, @Nullable ChannelconBroadcast toggle) {
|
||||
if (notEnabled()) return;
|
||||
MCChatCustom.lastmsgCustom.stream().filter(clmd -> {
|
||||
//new TBMCChannelConnectFakeEvent(sender, clmd.mcchannel).shouldSendTo(clmd.dcp) - Thought it was this simple hehe - Wait, it *should* be this simple
|
||||
if (toggle != null && (clmd.toggles & toggle.flag) == 0)
|
||||
return false; //If null then allow
|
||||
if (sender == null)
|
||||
return true;
|
||||
return clmd.groupID.equals(clmd.mcchannel.getGroupID(sender));
|
||||
}).forEach(cc -> action.accept(Mono.just(cc.channel))); //TODO: Send error messages on channel connect
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the {@code action} for each custom chat the {@code sender} have access to and has that broadcast type enabled.
|
||||
*
|
||||
* @param action The action to do
|
||||
* @param sender The sender to check perms of or null to send to all that has it toggled
|
||||
* @param toggle The toggle to check or null to send to all allowed
|
||||
* @param hookmsg Whether the message is also sent from the hook
|
||||
*/
|
||||
public static void forAllowedCustomAndAllMCChat(Consumer<Mono<MessageChannel>> action, @Nullable CommandSender sender, @Nullable ChannelconBroadcast toggle, boolean hookmsg) {
|
||||
if (notEnabled()) return;
|
||||
if (!GeneralEventBroadcasterModule.isHooked() || !hookmsg)
|
||||
forAllMCChat(action);
|
||||
forAllowedCustomMCChat(action, sender, toggle);
|
||||
}
|
||||
|
||||
public static Consumer<Mono<MessageChannel>> send(String message) {
|
||||
return ch -> ch.flatMap(mc -> mc.createMessage(DPUtils.sanitizeString(message))).subscribe();
|
||||
}
|
||||
|
||||
public static void forAllowedMCChat(Consumer<Mono<MessageChannel>> action, TBMCSystemChatEvent event) {
|
||||
if (notEnabled()) return;
|
||||
if (event.getChannel().isGlobal())
|
||||
action.accept(module.chatChannelMono());
|
||||
for (LastMsgData data : MCChatPrivate.lastmsgPerUser)
|
||||
if (event.shouldSendTo(getSender(data.channel.getId(), data.user)))
|
||||
action.accept(Mono.just(data.channel)); //TODO: Only store ID?
|
||||
MCChatCustom.lastmsgCustom.stream().filter(clmd -> {
|
||||
if (!clmd.brtoggles.contains(event.getTarget()))
|
||||
return false;
|
||||
return event.shouldSendTo(clmd.dcp);
|
||||
}).map(clmd -> Mono.just(clmd.channel)).forEach(action);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will find the best sender to use: if the player is online, use that, if not but connected then use that etc.
|
||||
*/
|
||||
static DiscordSenderBase getSender(Snowflake channel, final User author) {
|
||||
//noinspection OptionalGetWithoutIsPresent
|
||||
return Stream.<Supplier<Optional<DiscordSenderBase>>>of( // https://stackoverflow.com/a/28833677/2703239
|
||||
() -> Optional.ofNullable(getSender(OnlineSenders, channel, author)), // Find first non-null
|
||||
() -> Optional.ofNullable(getSender(ConnectedSenders, channel, author)), // This doesn't support the public chat, but it'll always return null for it
|
||||
() -> Optional.ofNullable(getSender(UnconnectedSenders, channel, author)), //
|
||||
() -> Optional.of(addSender(UnconnectedSenders, author,
|
||||
new DiscordSender(author, (MessageChannel) DiscordPlugin.dc.getChannelById(channel).block())))).map(Supplier::get).filter(Optional::isPresent).map(Optional::get).findFirst().get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the last message, so it will start a new one instead of appending to it.
|
||||
* This is used when someone (even the bot) sends a message to the channel.
|
||||
*
|
||||
* @param channel The channel to reset in - the process is slightly different for the public, private and custom chats
|
||||
*/
|
||||
public static void resetLastMessage(Channel channel) {
|
||||
if (notEnabled()) return;
|
||||
if (channel.getId().asLong() == module.chatChannel().get().asLong()) {
|
||||
(lastmsgdata == null ? lastmsgdata = new LastMsgData(module.chatChannelMono().block(), null)
|
||||
: lastmsgdata).message = null;
|
||||
return;
|
||||
} // Don't set the whole object to null, the player and channel information should be preserved
|
||||
for (LastMsgData data : channel instanceof PrivateChannel ? MCChatPrivate.lastmsgPerUser : MCChatCustom.lastmsgCustom) {
|
||||
if (data.channel.getId().asLong() == channel.getId().asLong()) {
|
||||
data.message = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
//If it gets here, it's sending a message to a non-chat channel
|
||||
}
|
||||
|
||||
public static void addStaticExcludedPlugin(Class<? extends Event> event, String plugin) {
|
||||
staticExcludedPlugins.compute(event, (e, hs) -> hs == null
|
||||
? Sets.newHashSet(plugin)
|
||||
: (hs.add(plugin) ? hs : hs));
|
||||
}
|
||||
|
||||
public static void callEventExcludingSome(Event event) {
|
||||
if (notEnabled()) return;
|
||||
val second = staticExcludedPlugins.get(event.getClass());
|
||||
String[] first = module.excludedPlugins().get();
|
||||
String[] both = second == null ? first
|
||||
: Arrays.copyOf(first, first.length + second.size());
|
||||
int i = first.length;
|
||||
if (second != null)
|
||||
for (String plugin : second)
|
||||
both[i++] = plugin;
|
||||
callEventExcluding(event, false, both);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls an event with the given details.
|
||||
* <p>
|
||||
* This method only synchronizes when the event is not asynchronous.
|
||||
*
|
||||
* @param event Event details
|
||||
* @param only Flips the operation and <b>includes</b> the listed plugins
|
||||
* @param plugins The plugins to exclude. Not case sensitive.
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public static void callEventExcluding(Event event, boolean only, String... plugins) { // Copied from Spigot-API and modified a bit
|
||||
if (event.isAsynchronous()) {
|
||||
if (Thread.holdsLock(Bukkit.getPluginManager())) {
|
||||
throw new IllegalStateException(
|
||||
event.getEventName() + " cannot be triggered asynchronously from inside synchronized code.");
|
||||
}
|
||||
if (Bukkit.getServer().isPrimaryThread()) {
|
||||
throw new IllegalStateException(
|
||||
event.getEventName() + " cannot be triggered asynchronously from primary server thread.");
|
||||
}
|
||||
fireEventExcluding(event, only, plugins);
|
||||
} else {
|
||||
synchronized (Bukkit.getPluginManager()) {
|
||||
fireEventExcluding(event, only, plugins);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void fireEventExcluding(Event event, boolean only, String... plugins) {
|
||||
HandlerList handlers = event.getHandlers(); // Code taken from SimplePluginManager in Spigot-API
|
||||
RegisteredListener[] listeners = handlers.getRegisteredListeners();
|
||||
val server = Bukkit.getServer();
|
||||
|
||||
for (RegisteredListener registration : listeners) {
|
||||
if (!registration.getPlugin().isEnabled()
|
||||
|| Arrays.stream(plugins).anyMatch(p -> only ^ p.equalsIgnoreCase(registration.getPlugin().getName())))
|
||||
continue; // Modified to exclude plugins
|
||||
|
||||
try {
|
||||
registration.callEvent(event);
|
||||
} catch (AuthorNagException ex) {
|
||||
Plugin plugin = registration.getPlugin();
|
||||
|
||||
if (plugin.isNaggable()) {
|
||||
plugin.setNaggable(false);
|
||||
|
||||
server.getLogger().log(Level.SEVERE,
|
||||
String.format("Nag author(s): '%s' of '%s' about the following: %s",
|
||||
plugin.getDescription().getAuthors(), plugin.getDescription().getFullName(),
|
||||
ex.getMessage()));
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
server.getLogger().log(Level.SEVERE, "Could not pass event " + event.getEventName() + " to "
|
||||
+ registration.getPlugin().getDescription().getFullName(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call it from an async thread.
|
||||
*/
|
||||
public static void callLoginEvents(DiscordConnectedPlayer dcp) {
|
||||
Consumer<Supplier<String>> loginFail = kickMsg -> {
|
||||
dcp.sendMessage("Minecraft chat disabled, as the login failed: " + kickMsg.get());
|
||||
MCChatPrivate.privateMCChat(dcp.getChannel(), false, dcp.getUser(), dcp.getChromaUser());
|
||||
}; //Probably also happens if the user is banned or so
|
||||
val event = new AsyncPlayerPreLoginEvent(dcp.getName(), InetAddress.getLoopbackAddress(), dcp.getUniqueId());
|
||||
callEventExcludingSome(event);
|
||||
if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
||||
loginFail.accept(event::getKickMessage);
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTask(DiscordPlugin.plugin, () -> {
|
||||
val ev = new PlayerLoginEvent(dcp, "localhost", InetAddress.getLoopbackAddress());
|
||||
callEventExcludingSome(ev);
|
||||
if (ev.getResult() != PlayerLoginEvent.Result.ALLOWED) {
|
||||
loginFail.accept(ev::getKickMessage);
|
||||
return;
|
||||
}
|
||||
callEventExcludingSome(new PlayerJoinEvent(dcp, ""));
|
||||
dcp.setLoggedIn(true);
|
||||
DPUtils.getLogger().info(dcp.getName() + " (" + dcp.getUniqueId() + ") logged in from Discord");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Only calls the events if the player is actually logged in
|
||||
*
|
||||
* @param dcp The player
|
||||
* @param needsSync Whether we're in an async thread
|
||||
*/
|
||||
public static void callLogoutEvent(DiscordConnectedPlayer dcp, boolean needsSync) {
|
||||
if (!dcp.isLoggedIn()) return;
|
||||
val event = new PlayerQuitEvent(dcp, "");
|
||||
if (needsSync) callEventSync(event);
|
||||
else callEventExcludingSome(event);
|
||||
dcp.setLoggedIn(false);
|
||||
DPUtils.getLogger().info(dcp.getName() + " (" + dcp.getUniqueId() + ") logged out from Discord");
|
||||
}
|
||||
|
||||
static void callEventSync(Event event) {
|
||||
Bukkit.getScheduler().runTask(DiscordPlugin.plugin, () -> callEventExcludingSome(event));
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public static class LastMsgData {
|
||||
public Message message;
|
||||
public long time;
|
||||
public String content;
|
||||
public final MessageChannel channel;
|
||||
public buttondevteam.core.component.channel.Channel mcchannel;
|
||||
public final User user;
|
||||
}
|
||||
}
|
|
@ -1,157 +0,0 @@
|
|||
package buttondevteam.discordplugin.mcchat;
|
||||
|
||||
import buttondevteam.discordplugin.*;
|
||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.player.*;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import discord4j.core.object.entity.Role;
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import net.ess3.api.events.MuteStatusChangeEvent;
|
||||
import net.ess3.api.events.NickChangeEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||
import org.bukkit.event.server.BroadcastMessageEvent;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
class MCListener implements Listener {
|
||||
private final MinecraftChatModule module;
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerLogin(PlayerLoginEvent e) {
|
||||
if (e.getResult() != Result.ALLOWED)
|
||||
return;
|
||||
if (e.getPlayer() instanceof DiscordConnectedPlayer)
|
||||
return;
|
||||
MCChatUtils.ConnectedSenders.values().stream().flatMap(v -> v.values().stream()) //Only private mcchat should be in ConnectedSenders
|
||||
.filter(s -> s.getUniqueId().equals(e.getPlayer().getUniqueId())).findAny()
|
||||
.ifPresent(dcp -> MCChatUtils.callLogoutEvent(dcp, false));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerJoin(TBMCPlayerJoinEvent e) {
|
||||
if (e.getPlayer() instanceof DiscordConnectedPlayer)
|
||||
return; // Don't show the joined message for the fake player
|
||||
Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin, () -> {
|
||||
final Player p = e.getPlayer();
|
||||
DiscordPlayer dp = e.GetPlayer().getAs(DiscordPlayer.class);
|
||||
if (dp != null) {
|
||||
val user = DiscordPlugin.dc.getUserById(Snowflake.of(dp.getDiscordID())).block();
|
||||
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(),
|
||||
new DiscordPlayerSender(user, Objects.requireNonNull(user).getPrivateChannel().block(), p)); //TODO: Don't block
|
||||
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID(),
|
||||
new DiscordPlayerSender(user, module.chatChannelMono().block(), p)); //Stored per-channel
|
||||
}
|
||||
final String message = e.GetPlayer().PlayerName().get() + " joined the game";
|
||||
MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(message), e.getPlayer(), ChannelconBroadcast.JOINLEAVE, true);
|
||||
ChromaBot.getInstance().updatePlayerList();
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerLeave(TBMCPlayerQuitEvent e) {
|
||||
if (e.getPlayer() instanceof DiscordConnectedPlayer)
|
||||
return; // Only care about real users
|
||||
MCChatUtils.OnlineSenders.entrySet()
|
||||
.removeIf(entry -> entry.getValue().entrySet().stream().anyMatch(p -> p.getValue().getUniqueId().equals(e.getPlayer().getUniqueId())));
|
||||
Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin,
|
||||
() -> MCChatUtils.ConnectedSenders.values().stream().flatMap(v -> v.values().stream())
|
||||
.filter(s -> s.getUniqueId().equals(e.getPlayer().getUniqueId())).findAny()
|
||||
.ifPresent(MCChatUtils::callLoginEvents));
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin,
|
||||
ChromaBot.getInstance()::updatePlayerList, 5);
|
||||
final String message = e.GetPlayer().PlayerName().get() + " left the game";
|
||||
MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(message), e.getPlayer(), ChannelconBroadcast.JOINLEAVE, true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerKick(PlayerKickEvent e) {
|
||||
/*if (!DiscordPlugin.hooked && !e.getReason().equals("The server is restarting")
|
||||
&& !e.getReason().equals("Server closed")) // The leave messages errored with the previous setup, I could make it wait since I moved it here, but instead I have a special
|
||||
MCChatListener.forAllowedCustomAndAllMCChat(e.getPlayer().getName() + " left the game"); // message for this - Oh wait this doesn't even send normally because of the hook*/
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(e.getDeathMessage()), e.getEntity(), ChannelconBroadcast.DEATH, true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerAFK(AfkStatusChangeEvent e) {
|
||||
final Player base = e.getAffected().getBase();
|
||||
if (e.isCancelled() || !base.isOnline())
|
||||
return;
|
||||
final String msg = base.getDisplayName()
|
||||
+ " is " + (e.getValue() ? "now" : "no longer") + " AFK.";
|
||||
MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(msg), base, ChannelconBroadcast.AFK, false);
|
||||
}
|
||||
|
||||
private ConfigData<Mono<Role>> muteRole() {
|
||||
return DPUtils.roleData(module.getConfig(), "muteRole", "Muted");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMute(MuteStatusChangeEvent e) {
|
||||
final Mono<Role> role = muteRole().get();
|
||||
if (role == null) return;
|
||||
final CommandSource source = e.getAffected().getSource();
|
||||
if (!source.isPlayer())
|
||||
return;
|
||||
final DiscordPlayer p = TBMCPlayerBase.getPlayer(source.getPlayer().getUniqueId(), TBMCPlayer.class)
|
||||
.getAs(DiscordPlayer.class);
|
||||
if (p == null) return;
|
||||
DiscordPlugin.dc.getUserById(Snowflake.of(p.getDiscordID()))
|
||||
.flatMap(user -> user.asMember(DiscordPlugin.mainServer.getId()))
|
||||
.flatMap(user -> role.flatMap(r -> {
|
||||
if (e.getValue())
|
||||
user.addRole(r.getId());
|
||||
else
|
||||
user.removeRole(r.getId());
|
||||
val modlog = module.modlogChannel().get();
|
||||
String msg = (e.getValue() ? "M" : "Unm") + "uted user: " + user.getUsername() + "#" + user.getDiscriminator();
|
||||
DPUtils.getLogger().info(msg);
|
||||
if (modlog != null)
|
||||
return modlog.flatMap(ch -> ch.createMessage(msg));
|
||||
return Mono.empty();
|
||||
})).subscribe();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChatSystemMessage(TBMCSystemChatEvent event) {
|
||||
MCChatUtils.forAllowedMCChat(MCChatUtils.send(event.getMessage()), event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBroadcastMessage(BroadcastMessageEvent event) {
|
||||
MCChatUtils.forCustomAndAllMCChat(MCChatUtils.send(event.getMessage()), ChannelconBroadcast.BROADCAST, false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onYEEHAW(TBMCYEEHAWEvent event) { //TODO: Inherit from the chat event base to have channel support
|
||||
String name = event.getSender() instanceof Player ? ((Player) event.getSender()).getDisplayName()
|
||||
: event.getSender().getName();
|
||||
//Channel channel = ChromaGamerBase.getFromSender(event.getSender()).channel().get(); - TODO
|
||||
DiscordPlugin.mainServer.getEmojis().filter(e -> "YEEHAW".equals(e.getName()))
|
||||
.take(1).singleOrEmpty().map(Optional::of).defaultIfEmpty(Optional.empty()).subscribe(yeehaw ->
|
||||
MCChatUtils.forAllMCChat(MCChatUtils.send(name + (yeehaw.map(guildEmoji -> " <:YEEHAW:" + guildEmoji.getId().asString() + ">s").orElse(" YEEHAWs")))));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onNickChange(NickChangeEvent event) {
|
||||
MCChatUtils.updatePlayerList();
|
||||
}
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
package buttondevteam.discordplugin.mcchat;
|
||||
|
||||
import buttondevteam.core.MainPlugin;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.playerfaker.perm.LPInjector;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.architecture.ReadOnlyConfigData;
|
||||
import com.google.common.collect.Lists;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import lombok.Getter;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Provides Minecraft chat connection to Discord. Commands may be used either in a public chat (limited) or in a DM.
|
||||
*/
|
||||
public class MinecraftChatModule extends Component<DiscordPlugin> {
|
||||
private @Getter
|
||||
MCChatListener listener;
|
||||
|
||||
/*public MCChatListener getListener() { //It doesn't want to generate
|
||||
return listener; - And now ButtonProcessor didn't look beyond this - return instead of continue...
|
||||
}*/
|
||||
|
||||
/**
|
||||
* A list of commands that can be used in public chats - Warning: Some plugins will treat players as OPs, always test before allowing a command!
|
||||
*/
|
||||
public ConfigData<ArrayList<String>> whitelistedCommands() {
|
||||
return getConfig().getData("whitelistedCommands", () -> Lists.newArrayList("list", "u", "shrug", "tableflip", "unflip", "mwiki",
|
||||
"yeehaw", "lenny", "rp", "plugins"));
|
||||
}
|
||||
|
||||
/**
|
||||
* The channel to use as the public Minecraft chat - everything public gets broadcasted here
|
||||
*/
|
||||
public ConfigData<Snowflake> chatChannel() {
|
||||
return DPUtils.snowflakeData(getConfig(), "chatChannel", 239519012529111040L);
|
||||
}
|
||||
|
||||
public Mono<MessageChannel> chatChannelMono() {
|
||||
return DPUtils.getMessageChannel(chatChannel().getPath(), chatChannel().get());
|
||||
}
|
||||
|
||||
/**
|
||||
* The channel where the plugin can log when it mutes a player on Discord because of a Minecraft mute
|
||||
*/
|
||||
public ReadOnlyConfigData<Mono<MessageChannel>> modlogChannel() {
|
||||
return DPUtils.channelData(getConfig(), "modlogChannel", 283840717275791360L);
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugins to exclude from fake player events used for the 'mcchat' command - some plugins may crash, add them here
|
||||
*/
|
||||
public ConfigData<String[]> excludedPlugins() {
|
||||
return getConfig().getData("excludedPlugins", new String[]{"ProtocolLib", "LibsDisguises", "JourneyMapServer"});
|
||||
}
|
||||
|
||||
/**
|
||||
* If this setting is on then players logged in through the 'mcchat' command will be able to teleport using plugin commands.
|
||||
* They can then use commands like /tpahere to teleport others to that place.<br />
|
||||
* If this is off, then teleporting will have no effect.
|
||||
*/
|
||||
public ConfigData<Boolean> allowFakePlayerTeleports() {
|
||||
return getConfig().getData("allowFakePlayerTeleports", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
if (DPUtils.disableIfConfigErrorRes(this, chatChannel(), chatChannelMono()))
|
||||
return;
|
||||
listener = new MCChatListener(this);
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(listener, getPlugin());
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(this), getPlugin());//These get undone if restarting/resetting - it will ignore events if disabled
|
||||
getPlugin().getManager().registerCommand(new MCChatCommand());
|
||||
getPlugin().getManager().registerCommand(new ChannelconCommand(this));
|
||||
|
||||
val chcons = getConfig().getConfig().getConfigurationSection("chcons");
|
||||
if (chcons == null) //Fallback to old place
|
||||
getConfig().getConfig().getRoot().getConfigurationSection("chcons");
|
||||
if (chcons != null) {
|
||||
val chconkeys = chcons.getKeys(false);
|
||||
for (val chconkey : chconkeys) {
|
||||
val chcon = chcons.getConfigurationSection(chconkey);
|
||||
val mcch = Channel.getChannels().filter(ch -> ch.ID.equals(chcon.getString("mcchid"))).findAny();
|
||||
val ch = DiscordPlugin.dc.getChannelById(Snowflake.of(chcon.getLong("chid"))).block();
|
||||
val did = chcon.getLong("did");
|
||||
val user = DiscordPlugin.dc.getUserById(Snowflake.of(did)).block();
|
||||
val groupid = chcon.getString("groupid");
|
||||
val toggles = chcon.getInt("toggles");
|
||||
val brtoggles = chcon.getStringList("brtoggles");
|
||||
if (!mcch.isPresent() || ch == null || user == null || groupid == null)
|
||||
continue;
|
||||
Bukkit.getScheduler().runTask(getPlugin(), () -> { //<-- Needed because of occasional ConcurrentModificationExceptions when creating the player (PermissibleBase)
|
||||
val dcp = new DiscordConnectedPlayer(user, (MessageChannel) ch, UUID.fromString(chcon.getString("mcuid")), chcon.getString("mcname"), this);
|
||||
MCChatCustom.addCustomChat((MessageChannel) ch, groupid, mcch.get(), user, dcp, toggles, brtoggles.stream().map(TBMCSystemChatEvent.BroadcastTarget::get).filter(Objects::nonNull).collect(Collectors.toSet()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
new LPInjector(MainPlugin.Instance);
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Failed to init LuckPerms injector", e);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
getPlugin().getLogger().info("No LuckPerms, not injecting");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
val chcons = MCChatCustom.getCustomChats();
|
||||
val chconsc = getConfig().getConfig().createSection("chcons");
|
||||
for (val chcon : chcons) {
|
||||
val chconc = chconsc.createSection(chcon.channel.getId().asString());
|
||||
chconc.set("mcchid", chcon.mcchannel.ID);
|
||||
chconc.set("chid", chcon.channel.getId().asLong());
|
||||
chconc.set("did", chcon.user.getId().asLong());
|
||||
chconc.set("mcuid", chcon.dcp.getUniqueId().toString());
|
||||
chconc.set("mcname", chcon.dcp.getName());
|
||||
chconc.set("groupid", chcon.groupID);
|
||||
chconc.set("toggles", chcon.toggles);
|
||||
chconc.set("brtoggles", chcon.brtoggles.stream().map(TBMCSystemChatEvent.BroadcastTarget::getName).collect(Collectors.toList()));
|
||||
}
|
||||
MCChatListener.stop(true);
|
||||
}
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
package buttondevteam.discordplugin.mccommands;
|
||||
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.DiscordSenderBase;
|
||||
import buttondevteam.discordplugin.commands.ConnectCommand;
|
||||
import buttondevteam.discordplugin.commands.VersionCommand;
|
||||
import buttondevteam.discordplugin.mcchat.MCChatUtils;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.ICommand2MC;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@CommandClass(path = "discord", helpText = {
|
||||
"Discord",
|
||||
"This command allows performing Discord-related actions."
|
||||
})
|
||||
public class DiscordMCCommand extends ICommand2MC {
|
||||
@Command2.Subcommand
|
||||
public boolean accept(Player player) {
|
||||
String did = ConnectCommand.WaitingToConnect.get(player.getName());
|
||||
if (did == null) {
|
||||
player.sendMessage("§cYou don't have a pending connection to Discord.");
|
||||
return true;
|
||||
}
|
||||
DiscordPlayer dp = ChromaGamerBase.getUser(did, DiscordPlayer.class);
|
||||
TBMCPlayer mcp = TBMCPlayerBase.getPlayer(player.getUniqueId(), TBMCPlayer.class);
|
||||
dp.connectWith(mcp);
|
||||
dp.save();
|
||||
mcp.save();
|
||||
ConnectCommand.WaitingToConnect.remove(player.getName());
|
||||
MCChatUtils.UnconnectedSenders.remove(did); //Remove all unconnected, will be recreated where needed
|
||||
player.sendMessage("§bAccounts connected.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Command2.Subcommand
|
||||
public boolean decline(Player player) {
|
||||
String did = ConnectCommand.WaitingToConnect.remove(player.getName());
|
||||
if (did == null) {
|
||||
player.sendMessage("§cYou don't have a pending connection to Discord.");
|
||||
return true;
|
||||
}
|
||||
player.sendMessage("§bPending connection declined.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Command2.Subcommand(permGroup = Command2.Subcommand.MOD_GROUP, helpText = {
|
||||
"Reload Discord plugin",
|
||||
"Reloads the config. To apply some changes, you may need to also run /discord reset."
|
||||
})
|
||||
public void reload(CommandSender sender) {
|
||||
if (DiscordPlugin.plugin.tryReloadConfig())
|
||||
sender.sendMessage("§bConfig reloaded.");
|
||||
else
|
||||
sender.sendMessage("§cFailed to reload config.");
|
||||
}
|
||||
|
||||
public static boolean resetting = false;
|
||||
|
||||
@Command2.Subcommand(permGroup = Command2.Subcommand.MOD_GROUP, helpText = {
|
||||
"Reset ChromaBot", //
|
||||
"This command disables and then enables the plugin." //
|
||||
})
|
||||
public void reset(CommandSender sender) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin, () -> {
|
||||
resetting = true; //Turned off after sending enable message (ReadyEvent)
|
||||
sender.sendMessage("§bDisabling DiscordPlugin...");
|
||||
Bukkit.getPluginManager().disablePlugin(DiscordPlugin.plugin);
|
||||
if (!(sender instanceof DiscordSenderBase)) //Sending to Discord errors
|
||||
sender.sendMessage("§bEnabling DiscordPlugin...");
|
||||
Bukkit.getPluginManager().enablePlugin(DiscordPlugin.plugin);
|
||||
if (!(sender instanceof DiscordSenderBase)) //Sending to Discord errors
|
||||
sender.sendMessage("§bReset finished!");
|
||||
});
|
||||
}
|
||||
|
||||
@Command2.Subcommand(helpText = {
|
||||
"Version command",
|
||||
"Prints the plugin version"
|
||||
})
|
||||
public void version(CommandSender sender) {
|
||||
sender.sendMessage(VersionCommand.getVersion());
|
||||
}
|
||||
|
||||
@Command2.Subcommand(helpText = {
|
||||
"Invite",
|
||||
"Shows an invite link to the server"
|
||||
})
|
||||
public void invite(CommandSender sender) {
|
||||
String invi = DiscordPlugin.plugin.inviteLink().get();
|
||||
if (invi.length() > 0) {
|
||||
sender.sendMessage("§bInvite link: " + invi);
|
||||
return;
|
||||
}
|
||||
DiscordPlugin.mainServer.getInvites().limitRequest(1)
|
||||
.switchIfEmpty(Mono.fromRunnable(() -> sender.sendMessage("§cNo invites found for the server.")))
|
||||
.subscribe(inv -> {
|
||||
sender.sendMessage("§bInvite link: https://discord.gg/" + inv.getCode());
|
||||
}, e -> sender.sendMessage("§cThe invite link is not set and the bot has no permission to get it."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getHelpText(Method method, Command2.Subcommand ann) {
|
||||
switch (method.getName()) {
|
||||
case "accept":
|
||||
return new String[]{ //
|
||||
"Accept Discord connection", //
|
||||
"Accept a pending connection between your Discord and Minecraft account.", //
|
||||
"To start the connection process, do §b/connect <MCname>§r in the " + DPUtils.botmention() + " channel on Discord", //
|
||||
};
|
||||
case "decline":
|
||||
return new String[]{ //
|
||||
"Decline Discord connection", //
|
||||
"Decline a pending connection between your Discord and Minecraft account.", //
|
||||
"To start the connection process, do §b/connect <MCname>§r in the " + DPUtils.botmention() + " channel on Discord", //
|
||||
};
|
||||
default:
|
||||
return super.getHelpText(method, ann);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,308 +0,0 @@
|
|||
package buttondevteam.discordplugin.playerfaker;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.DiscordSenderBase;
|
||||
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.User;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.PistonMoveReaction;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuppressWarnings("deprecated")
|
||||
public abstract class DiscordEntity extends DiscordSenderBase implements Entity {
|
||||
protected DiscordEntity(User user, MessageChannel channel, int entityId, UUID uuid, MinecraftChatModule module) {
|
||||
super(user, channel);
|
||||
this.entityId = entityId;
|
||||
uniqueId = uuid;
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
private HashMap<String, MetadataValue> metadata = new HashMap<String, MetadataValue>();
|
||||
|
||||
private Location location = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
|
||||
private Vector velocity;
|
||||
private final int entityId;
|
||||
private EntityDamageEvent lastDamageCause;
|
||||
private final Set<String> scoreboardTags = new HashSet<String>();
|
||||
private final UUID uniqueId;
|
||||
private final MinecraftChatModule module;
|
||||
|
||||
@Override
|
||||
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
|
||||
metadata.put(metadataKey, newMetadataValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MetadataValue> getMetadata(String metadataKey) {
|
||||
return Collections.singletonList(metadata.get(metadataKey)); // Who needs multiple data anyways
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMetadata(String metadataKey) {
|
||||
return metadata.containsKey(metadataKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMetadata(String metadataKey, Plugin owningPlugin) {
|
||||
metadata.remove(metadataKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation(Location loc) {
|
||||
if (loc != null) {
|
||||
loc.setWorld(getWorld());
|
||||
loc.setX(location.getX());
|
||||
loc.setY(location.getY());
|
||||
loc.setZ(location.getZ());
|
||||
loc.setYaw(location.getYaw());
|
||||
loc.setPitch(location.getPitch());
|
||||
}
|
||||
|
||||
return loc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getWidth() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnGround() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return location.getWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(Location location) {
|
||||
if (module.allowFakePlayerTeleports().get())
|
||||
this.location = location;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(Location location, TeleportCause cause) {
|
||||
if (module.allowFakePlayerTeleports().get())
|
||||
this.location = location;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(Entity destination) {
|
||||
if (module.allowFakePlayerTeleports().get())
|
||||
this.location = destination.getLocation();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(Entity destination, TeleportCause cause) {
|
||||
if (module.allowFakePlayerTeleports().get())
|
||||
this.location = destination.getLocation();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entity> getNearbyEntities(double x, double y, double z) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFireTicks() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxFireTicks() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFireTicks(int ticks) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDead() { // Impossible to kill
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server getServer() {
|
||||
return Bukkit.getServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getPassenger() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setPassenger(Entity passenger) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entity> getPassengers() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addPassenger(Entity passenger) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePassenger(Entity passenger) { // Don't support passengers
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean eject() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFallDistance() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFallDistance(float distance) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTicksLived() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTicksLived(int value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playEffect(EntityEffect type) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInsideVehicle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean leaveVehicle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getVehicle() { // Don't support vehicles
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomNameVisible(boolean flag) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCustomNameVisible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGlowing(boolean flag) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGlowing() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInvulnerable(boolean flag) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvulnerable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSilent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSilent(boolean flag) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGravity() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGravity(boolean gravity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPortalCooldown() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPortalCooldown(int cooldown) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addScoreboardTag(String tag) {
|
||||
return scoreboardTags.add(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeScoreboardTag(String tag) {
|
||||
return scoreboardTags.remove(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PistonMoveReaction getPistonMoveReaction() {
|
||||
return PistonMoveReaction.IGNORE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity.Spigot spigot() {
|
||||
return new Entity.Spigot();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,733 +0,0 @@
|
|||
package buttondevteam.discordplugin.playerfaker;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.User;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Delegate;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.advancement.Advancement;
|
||||
import org.bukkit.advancement.AdvancementProgress;
|
||||
import org.bukkit.conversations.Conversation;
|
||||
import org.bukkit.conversations.ConversationAbandonedEvent;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.map.MapView;
|
||||
import org.bukkit.permissions.PermissibleBase;
|
||||
import org.bukkit.permissions.ServerOperator;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class DiscordFakePlayer extends DiscordHumanEntity implements Player {
|
||||
protected DiscordFakePlayer(User user, MessageChannel channel, int entityId, UUID uuid, String mcname, MinecraftChatModule module) {
|
||||
super(user, channel, entityId, uuid, module);
|
||||
origPerm = perm = new PermissibleBase(basePlayer = Bukkit.getOfflinePlayer(uuid));
|
||||
name = mcname;
|
||||
}
|
||||
|
||||
@Delegate(excludes = ServerOperator.class)
|
||||
private PermissibleBase origPerm;
|
||||
|
||||
private @Getter String name;
|
||||
|
||||
private @Getter OfflinePlayer basePlayer;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private PermissibleBase perm;
|
||||
|
||||
public void setOp(boolean value) { //CraftPlayer-compatible implementation
|
||||
this.origPerm.setOp(value);
|
||||
this.perm.recalculatePermissions();
|
||||
}
|
||||
|
||||
public boolean isOp() { return this.origPerm.isOp(); }
|
||||
|
||||
@Override
|
||||
public EntityType getType() {
|
||||
return EntityType.PLAYER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCustomName() {
|
||||
return user.getUsername();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(String name) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConversing() {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptConversationInput(String input) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean beginConversation(Conversation conversation) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abandonConversation(Conversation conversation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abandonConversation(Conversation conversation, ConversationAbandonedEvent details) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return true;// Let's pretend
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBanned() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWhitelisted() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWhitelisted(boolean value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFirstPlayed() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastPlayed() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPlayedBefore() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPluginMessage(Plugin source, String channel, byte[] message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getListeningPluginChannels() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return Objects.requireNonNull(user.asMember(DiscordPlugin.mainServer.getId()).block()).getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayName(String name) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerListName() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerListName(String name) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompassTarget(Location loc) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getCompassTarget() {
|
||||
return new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getAddress() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRawMessage(String message) {
|
||||
sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kickPlayer(String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chat(String msg) {
|
||||
Bukkit.getPluginManager()
|
||||
.callEvent(new AsyncPlayerChatEvent(true, this, msg, new HashSet<>(Bukkit.getOnlinePlayers())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performCommand(String command) {
|
||||
return Bukkit.getServer().dispatchCommand(this, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneaking() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSneaking(boolean sneak) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSprinting() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSprinting(boolean sprinting) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveData() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadData() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSleepingIgnored(boolean isSleeping) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSleepingIgnored() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playNote(Location loc, byte instrument, byte note) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playNote(Location loc, Instrument instrument, Note note) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(Location location, Sound sound, float volume, float pitch) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(Location location, String sound, float volume, float pitch) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(Location location, Sound sound, SoundCategory category, float volume, float pitch) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(Location location, String sound, SoundCategory category, float volume, float pitch) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopSound(Sound sound) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopSound(String sound) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopSound(Sound sound, SoundCategory category) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopSound(String sound, SoundCategory category) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playEffect(Location loc, Effect effect, int data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void playEffect(Location loc, Effect effect, T data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendBlockChange(Location loc, Material material, byte data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendChunkChange(Location loc, int sx, int sy, int sz, byte[] data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendBlockChange(Location loc, int material, byte data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSignChange(Location loc, String[] lines) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMap(MapView map) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void awardAchievement(@SuppressWarnings("deprecation") Achievement achievement) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAchievement(@SuppressWarnings("deprecation") Achievement achievement) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAchievement(@SuppressWarnings("deprecation") Achievement achievement) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementStatistic(Statistic statistic) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(Statistic statistic) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementStatistic(Statistic statistic, int amount) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(Statistic statistic, int amount) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatistic(Statistic statistic, int newValue) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatistic(Statistic statistic) throws IllegalArgumentException {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementStatistic(Statistic statistic, Material material) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(Statistic statistic, Material material) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatistic(Statistic statistic, Material material) throws IllegalArgumentException {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementStatistic(Statistic statistic, Material material, int amount) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(Statistic statistic, Material material, int amount) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatistic(Statistic statistic, Material material, int newValue) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementStatistic(Statistic statistic, EntityType entityType) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(Statistic statistic, EntityType entityType) throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatistic(Statistic statistic, EntityType entityType) throws IllegalArgumentException {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementStatistic(Statistic statistic, EntityType entityType, int amount)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementStatistic(Statistic statistic, EntityType entityType, int amount) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatistic(Statistic statistic, EntityType entityType, int newValue) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerTime(long time, boolean relative) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPlayerTime() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPlayerTimeOffset() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerTimeRelative() {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetPlayerTime() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerWeather(WeatherType type) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public WeatherType getPlayerWeather() {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetPlayerWeather() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveExp(int amount) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveExpLevels(int amount) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExp() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExp(float exp) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLevel(int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalExperience() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTotalExperience(int exp) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExhaustion() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExhaustion(float value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSaturation() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSaturation(float value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFoodLevel() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFoodLevel(int value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getBedSpawnLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBedSpawnLocation(Location location) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBedSpawnLocation(Location location, boolean force) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAllowFlight() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAllowFlight(boolean flight) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hidePlayer(Player player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showPlayer(Player player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSee(Player player) { // Nobody can see them
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFlying() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlying(boolean value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlySpeed(float value) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWalkSpeed(float value) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFlySpeed() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWalkSpeed() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTexturePack(String url) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResourcePack(String url) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResourcePack(String url, byte[] hash) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Scoreboard getScoreboard() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScoreboard(Scoreboard scoreboard) throws IllegalArgumentException, IllegalStateException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHealthScaled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHealthScaled(boolean scale) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHealthScale(double scale) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHealthScale() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getSpectatorTarget() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpectatorTarget(Entity entity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitle(String title, String subtitle) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitle(String title, String subtitle, int fadeIn, int stay, int fadeOut) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTitle() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnParticle(Particle particle, Location location, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnParticle(Particle particle, double x, double y, double z, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void spawnParticle(Particle particle, Location location, int count, T data) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, T data) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY,
|
||||
double offsetZ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX,
|
||||
double offsetY, double offsetZ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY,
|
||||
double offsetZ, T data) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX,
|
||||
double offsetY, double offsetZ, T data) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY,
|
||||
double offsetZ, double extra) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX,
|
||||
double offsetY, double offsetZ, double extra) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY,
|
||||
double offsetZ, double extra, T data) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX,
|
||||
double offsetY, double offsetZ, double extra, T data) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public AdvancementProgress getAdvancementProgress(Advancement advancement) { // TODO: Test
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocale() {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player.Spigot spigot() {
|
||||
return new Player.Spigot();
|
||||
}
|
||||
}
|
|
@ -1,168 +0,0 @@
|
|||
package buttondevteam.discordplugin.playerfaker;
|
||||
|
||||
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.User;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.inventory.*;
|
||||
import org.bukkit.inventory.InventoryView.Property;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class DiscordHumanEntity extends DiscordLivingEntity implements HumanEntity {
|
||||
protected DiscordHumanEntity(User user, MessageChannel channel, int entityId, UUID uuid, MinecraftChatModule module) {
|
||||
super(user, channel, entityId, uuid, module);
|
||||
}
|
||||
|
||||
private PlayerInventory inv = new DiscordPlayerInventory(this);
|
||||
|
||||
@Override
|
||||
public PlayerInventory getInventory() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
private Inventory enderchest = new DiscordInventory(this);
|
||||
|
||||
@Override
|
||||
public Inventory getEnderChest() {
|
||||
return enderchest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MainHand getMainHand() {
|
||||
return MainHand.RIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setWindowProperty(Property prop, int value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryView getOpenInventory() { // TODO: Test
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryView openInventory(Inventory inventory) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryView openWorkbench(Location location, boolean force) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryView openEnchanting(Location location, boolean force) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(InventoryView inventory) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryView openMerchant(Villager trader, boolean force) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryView openMerchant(Merchant merchant, boolean force) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemInHand() { // TODO: Test all ItemStack methods
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInHand(ItemStack item) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemOnCursor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemOnCursor(ItemStack item) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCooldown(Material material) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCooldown(Material material) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCooldown(Material material, int ticks) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSleeping() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSleepTicks() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameMode getGameMode() {
|
||||
return GameMode.SPECTATOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGameMode(GameMode mode) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlocking() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHandRaised() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getExpToLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getShoulderEntityLeft() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShoulderEntityLeft(Entity entity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getShoulderEntityRight() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShoulderEntityRight(Entity entity) {
|
||||
}
|
||||
|
||||
}
|
|
@ -1,212 +0,0 @@
|
|||
package buttondevteam.discordplugin.playerfaker;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class DiscordInventory implements Inventory {
|
||||
public DiscordInventory(DiscordHumanEntity holder) {
|
||||
this.holder = holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Player inventory";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> addItem(ItemStack... items) throws IllegalArgumentException { // Can't add anything
|
||||
return new HashMap<>(
|
||||
IntStream.range(0, items.length).boxed().collect(Collectors.toMap(i -> i, i -> items[i])));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> removeItem(ItemStack... items) throws IllegalArgumentException {
|
||||
return new HashMap<>(
|
||||
IntStream.range(0, items.length).boxed().collect(Collectors.toMap(i -> i, i -> items[i])));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return new ItemStack[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContents(ItemStack[] items) throws IllegalArgumentException {
|
||||
if (items.length > 0)
|
||||
throw new IllegalArgumentException("This inventory does not support items");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getStorageContents() {
|
||||
return new ItemStack[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStorageContents(ItemStack[] items) throws IllegalArgumentException {
|
||||
if (items.length > 0)
|
||||
throw new IllegalArgumentException("This inventory does not support items");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(int materialId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Material material) throws IllegalArgumentException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(ItemStack item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(int materialId, int amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Material material, int amount) throws IllegalArgumentException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(ItemStack item, int amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAtLeast(ItemStack item, int amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ? extends ItemStack> all(int materialId) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ? extends ItemStack> all(Material material) throws IllegalArgumentException {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ? extends ItemStack> all(ItemStack item) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(int materialId) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(Material material) throws IllegalArgumentException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(ItemStack item) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int firstEmpty() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(int materialId) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Material material) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(ItemStack item) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(int index) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return new ArrayList<>(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return "Player inventory";
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryType getType() {
|
||||
return InventoryType.PLAYER;
|
||||
}
|
||||
|
||||
private ListIterator<ItemStack> iterator = new ArrayList<ItemStack>(0).listIterator();
|
||||
|
||||
@Override
|
||||
public ListIterator<ItemStack> iterator() {
|
||||
return iterator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<ItemStack> iterator(int index) {
|
||||
return iterator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return holder.getLocation();
|
||||