Compare commits
104 commits
Author | SHA1 | Date | |
---|---|---|---|
d1515c2ab2 | |||
512a62d75c | |||
b5fd834dc7 | |||
e35e94e87c | |||
51cf31713b | |||
2242655c41 | |||
522f29ba58 | |||
10bf0e98df | |||
6c1378f370 | |||
56b9296fbb | |||
|
5c399a08ad | ||
724858ac70 | |||
9a10dcd1fc | |||
dc6df53c96 | |||
7646db4487 | |||
8e9989caee | |||
77b5a069c5 | |||
c52a6873fe | |||
c6ba0ec607 | |||
|
737016bf00 | ||
a63f2bb256 | |||
59dbc78b52 | |||
b483b7df0c | |||
4d4448fca1 | |||
02423153de | |||
ce4f40c2c4 | |||
|
372b2f49b3 | ||
7448eb7e3a | |||
c688ec9243 | |||
e4b47efd3f | |||
43525bd93c | |||
052149bcb7 | |||
5d8ae7fbd0 | |||
f3ec9e7870 | |||
0421cc6d16 | |||
aad65e0222 | |||
03b91d2fdb | |||
661534b92d | |||
6af2ad79a7 | |||
f19aa41205 | |||
4952923f9b | |||
4d0c7c170e | |||
0dbfaa65a5 | |||
30ee99d495 | |||
1dc801575a | |||
0a4cdd01ce | |||
b452170ff7 | |||
c66b212b0c | |||
2d874d7bc9 | |||
cda2a36da1 | |||
d5f500aece | |||
2a9bc58157 | |||
22c7fed75d | |||
825e327903 | |||
fd3d3df108 | |||
c0128831a7 | |||
013287cb47 | |||
cc6c477add | |||
a91ee1b842 | |||
aa455e373d | |||
6a16a3a1d5 | |||
750b71de65 | |||
bd656015bf | |||
fa375c4912 | |||
a964ce6595 | |||
4a456d9b1e | |||
a4b7f689c0 | |||
b3939f3c92 | |||
1275cdafd0 | |||
f3904a8448 | |||
415e61a401 | |||
7b2ecdbf7b | |||
4956837e5d | |||
3ad2346990 | |||
8907d5308f | |||
bbe9a8c146 | |||
80e45aa1a9 | |||
c25097b525 | |||
049ad55168 | |||
c7f04b8731 | |||
073346eb7f | |||
5b5252382e | |||
e510667215 | |||
ae49777007 | |||
8ff45ad676 | |||
4744f2edf9 | |||
f7c1106d1c | |||
40a1739951 | |||
c5e33a93ba | |||
26b44fbfe1 | |||
36655dfd84 | |||
df7f8bca5e | |||
e2a6afd16a | |||
21bf41db2b | |||
185b0df8e0 | |||
f12912c735 | |||
d0e4447126 | |||
3a29010042 | |||
0802de4b6f | |||
3f387a9775 | |||
25ce2a4c9f | |||
8ccf3ee9d7 | |||
bfe7d48760 | |||
be29caa904 |
105 changed files with 4797 additions and 4523 deletions
445
.gitignore
vendored
445
.gitignore
vendored
|
@ -1,224 +1,221 @@
|
|||
#################
|
||||
## 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
|
||||
/.apt_generated/
|
||||
#################
|
||||
## 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_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.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/
|
||||
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
|
||||
/.apt_generated/
|
||||
|
|
0
.idea/ButtonChat.iml
generated
Normal file
0
.idea/ButtonChat.iml
generated
Normal file
46
.project
46
.project
|
@ -1,23 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ButtonChat</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Chroma-Chat</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
17
.travis.yml
17
.travis.yml
|
@ -9,18 +9,13 @@ before_install: | # Wget BuildTools and run if cached folder not found
|
|||
fi
|
||||
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: "F5YiEuD6LyRENUDMCslcSl0O0dg4IDk+nNeb4X2VLYlmb8dW9beMuIgjH8efTMeaQ3D/ntIkN0Dtf2GKvpOduhwkSbAgw4WM028X60SY9f2hmpEO3LmM4T1tKoDlI1T3BmhYP4KeTKBYn+etV1mSPbT07vUybCm/vGzvr96yMZGNFEoKsWLaEu7dZfBFULj4tXOwrLh/KO6BsdAHvZcGKWNVupPq3YoUVT0dpGcUudf5cpn+aaqMwyd709zgMbyCuqf+c5Udps43q4EKvr9z7TWxFUkGTPVVAcUVygJsi2ytuyA8TLMPq/KhYe9htnkNUnizbqv/j49xww0gVaD7OJXENJ4hAUTV4sdn1DXG45JXW+dir3V7YzbRYn3M+eCuKB2O77SXRZBkxcGtTMtCmghP9/tcRAQlXDXnxu7oAnlUVp17g/+aFApvlzZEZVx2N+fkyEe7JrUFlRCixtHyrmTLWhyV0Px9p0FHJpvSSCL0S0UKVAT/sNHYHhD5gouK7owEomEbG58XCsRDH6Et7RuDksB98ekK8brZp6S7dNIS2CVuVx1vIkXC8PzUGcpJQoztvEYUE20Axahh5s8AkE9n/O9jzs9ajcfYaHhWzYeUZzHdHllOYF9l6VoCUitTk4Sl8eJifSq3GzI+T6wGMBepZHLpe230MvBIrqGZ+Vg="
|
||||
file: 'target/Chroma-Chat.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
|
||||
|
|
1
Mvn.txt
1
Mvn.txt
|
@ -1 +0,0 @@
|
|||
apache-maven-3.2.5/bin/mvn install:install-file -Dfile=Towny.jar -DgroupId=com.palmergames -DartifactId=Towny -Dversion=0.90.0.0 -Dpackaging=jar
|
143
README.md
143
README.md
|
@ -1,133 +1,28 @@
|
|||
# The Button Minecraft server chat plugin
|
||||
# Chroma-Chat plugin
|
||||
A plugin that provides markdown formatting, name mentioning and other chat features.
|
||||
|
||||
## How to use
|
||||
### Players
|
||||
#### Obtaining the flair (/u accept)
|
||||
At first, you need to connect your Reddit account with your Minecraft account. This is done by writing your Minecraft name to [this thread](https://www.reddit.com/r/Chromagamers/comments/51ys94/flair_thread_for_the_mc_server/), following the instructions in the post.
|
||||
## Components
|
||||
|
||||
When you're done, connect to the server, if you aren't already on. You should see a message after a while (max. 10 seconds) asking if you're the correct Reddit user. Type /u accept to confirm it and accept your flair.
|
||||
### Announcer
|
||||
This component simply sends messages globally based on a configurable list in a given interval.
|
||||
|
||||
__Note__: You can comment your ingame name from multiple Reddit accounts. In this case, you'll need to specify the exact username you want to pair with your Minecraft account. For example:
|
||||
### Append text
|
||||
This component allows the players to put tableflips and other texts after their messages using /tableflip and other commands.
|
||||
|
||||
/u accept NorbiPeti
|
||||
### Chat-only
|
||||
This component lets a player become invincible at the cost of not being able to move. It was made for chat clients.
|
||||
|
||||
#### Hiding the message (/u ignore)
|
||||
You can use this command to hide the notice showing up after you log in if you don't have a flair accepted.
|
||||
### Flair
|
||||
This component downloads /r/TheButton flairs from Reddit for users who comment in a specific thread. This was the original function of the plugin.
|
||||
|
||||
#### Flair not showing up
|
||||
Please note that in some cases your flair cannot be obtained (specifically, if it's not stored by karmadecay.com, in which case possibly Karmancer can't show it as well). In this case, there are two possibilities.
|
||||
### Formatter
|
||||
This component provides the Markdown and other formatting and name mentioning.
|
||||
|
||||
If you're a non-presser or a can't press and only your time is recorded, it will automatically decide based on your account creation date.
|
||||
### Fun
|
||||
This component has some random things I added for fun, including "Press F to pay respects" and rainbow chat.
|
||||
|
||||
If nothing is known about your flair, you need to ask an admin to set the flair for you. Please prepare a link to a comment you made on /r/thebutton, if possible.
|
||||
### Town colors
|
||||
This component allows mayors and kings to set a color for their town/nation, which sets each resident's name colors and also shows on Dynmap.
|
||||
|
||||
#### Getting someone's Reddit username (/u name)
|
||||
You can see a player's username if they have a flair shown.
|
||||
|
||||
#### Name mentioning
|
||||
If you simply say any online player's full playername or nickname, it'll highlight it and play a sound for the target player.
|
||||
|
||||
If you say a nickname, it'll show it's original colors, if you say a username, then it will choose based on flair color if known, otherwise it'll use the aqua color.
|
||||
|
||||
You can also use @console to ping the console. If someone is there, they'll receive an audible bell signal.
|
||||
|
||||
#### RP/OOC mode (/nrp or /ooc)
|
||||
You can use /ooc <message> to say something Out-of-Character. Otherwise everything you speak should be treated as said in RP, except when it is obvious it's not in RP (like talking about the server).
|
||||
|
||||
#### Greentext support (>message)
|
||||
Start your message with '>' to make it green.
|
||||
|
||||
#### Hashtags (#hashtag)
|
||||
If you say a hashtag in global chat, it'll highlight it and makes it clickable, linking to the hashtag page on Twitter.
|
||||
|
||||
#### Paying respects (F)
|
||||
If a player dies, sometimes the plugin will tell everyone "Press F to pay respects.". After a few seconds, a message will tell everyone how many people paid their respects.
|
||||
|
||||
If you hover over a player's name in chat, you can see how much respect they gained this way, divided by the number of eligible deaths.
|
||||
|
||||
#### Copy messages
|
||||
To copy a message from chat, click the channel identifier (for example: [g] or [TC]) at the beginning of the message.
|
||||
|
||||
#### Tableflipping (/tableflip and /unflip) and shrug (/shrug)
|
||||
The idea of this command came from Discord.
|
||||
|
||||
Examples:
|
||||
|
||||
/tableflip - (╯°□°)╯︵ ┻━┻
|
||||
/tableflip test - test(╯°□°)╯︵ ┻━┻
|
||||
/unflip - ┬─┬ ノ( ゜-゜ノ)
|
||||
/unflip test - test┬─┬ ノ( ゜-゜ノ)
|
||||
|
||||
#### Chat only (/chatonly)
|
||||
You can use this mode to protect yourself if you connect from a chat-only client. This will make you invincible, but unable to move, teleport or interact with the world in any way.
|
||||
|
||||
#### Rainbow chat (/u c)
|
||||
Chat in rainbow/Presser colors.
|
||||
|
||||
### Admins
|
||||
Type /u admin for a list of the commands.
|
||||
#### Seeing player information (/u admin playerinfo)
|
||||
You can check someone's flair status and other infos in case something goes wrong.
|
||||
|
||||
It outputs the player name (useful if something goes *really* wrong), the player's current ingame flair, the Reddit username, and their flair status:
|
||||
|
||||
* Accepted: The user has a flair shown after their name.
|
||||
* Ignored: The user chose to hide their flair, but they have one.
|
||||
* Recognised: The user has recognised flair(s) but haven't accepted any.
|
||||
* Commented: The user commented, but their flair isn't known.
|
||||
* NoComment: The user haven't commented in the thread.
|
||||
|
||||
#### Reloading the plugin (/u admin reload)
|
||||
This is useful if you want to change a file related to the plugin.
|
||||
|
||||
Be careful and make sure you do /u admin save before you reload the plugin. You need to confirm your action (/u admin confirm) to make sure no setting is lost.
|
||||
|
||||
If you want to edit a file, you need to do /u admin save, then edit the file you want, then do /u admin reload.
|
||||
|
||||
#### Setting the flair by hand (/u admin setflair)
|
||||
This allows you to set any flair you want to any player. This will override the automatic flairs, though it's not recommended to do so. However, the player can reset the automatic flair at any time (see /u accept).
|
||||
|
||||
* To remove a user's flair:
|
||||
|
||||
/u admin setflair <playername> none false
|
||||
|
||||
* To set a non-presser or can't press flair:
|
||||
|
||||
/u admin setflair <playername> non-presser/cant-press false
|
||||
|
||||
* To set a cheater flair:
|
||||
|
||||
/u admin setflair <playername> <time> true
|
||||
|
||||
* To also set the username for the flair:
|
||||
|
||||
/u admin setflair <playername> <time> <cheater> <username>
|
||||
|
||||
Usage:
|
||||
|
||||
/u admin setflair <playername> <time (without s) or non-presser, can't press, none> <cheater (true/false)>> [username]
|
||||
|
||||
#### Updating the plugin (/u admin updateplugin)
|
||||
I've made a simple command to allow updating the plugin easily. After running this command, the server needs to get restarted for the changes to take effect.
|
||||
|
||||
This command will not do any other thing than downloading the JAR file from here to the plugins directory. Do not spam it, because it will then generate unnecessary network traffic on the server.
|
||||
|
||||
#### Toggle settings
|
||||
|
||||
/u admin togglerpshow - Toggles [RP] tag shown at each message except /ooc or /nrp.
|
||||
/u admin debug - Toggles debug mode. Currently it outputs a lot of info about the chat formatting.
|
||||
|
||||
#### Setting the sound played on name mentioning
|
||||
You can set the sound played by editing "notificationsound" and "notificationpitch" in the config file (thebuttonmc.yml).
|
||||
|
||||
#### Announcements (/u announce)
|
||||
You can make announcements broadcasted every n minutes where you can set n and it defaults to 15.
|
||||
|
||||
/u announce add <message> - Adds a new announcement. It supports formatting codes with &.
|
||||
/u announce remove <index> - Remove announcement by index (see below).
|
||||
/u announce list - List announcements with indexes.
|
||||
/u announce settime <minutes> - Set the time between announcements in minutes.
|
||||
/u announce edit <index> <message> - Directly edits the announcement at the specified index. If there are less announcements than index, it'll create enough announcements.
|
||||
|
||||
#### Color modes (/u c)
|
||||
Use /u c \<colorname\> to set the color of your messages.
|
||||
### Towny
|
||||
This component is needed by the town colors component. Besides, it reads Towny events to be broadcasted to Discord, if that plugin is used.
|
||||
|
|
10
deploy.sh
10
deploy.sh
|
@ -1,10 +0,0 @@
|
|||
#!/bin/sh
|
||||
FILENAME=$(find target/ -maxdepth 1 ! -name '*original*' -name '*.jar')
|
||||
echo Found file: $FILENAME
|
||||
|
||||
if [ $1 = 'production' ]; then
|
||||
echo Production mode
|
||||
echo $UPLOAD_KEY > upload_key
|
||||
chmod 400 upload_key
|
||||
yes | scp -B -i upload_key -o StrictHostKeyChecking=no $FILENAME travis@server.figytuna.com:/minecraft/main/TBMC/pluginupdates
|
||||
fi
|
471
pom.xml
471
pom.xml
|
@ -1,263 +1,210 @@
|
|||
<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>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>The Button Minecraft Chat Plugin</name>
|
||||
<description>The Button Minecraft Chat Plugin</description>
|
||||
<build>
|
||||
<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>ButtonChat</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</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>
|
||||
<includes>
|
||||
<include>net.sourceforge.htmlcleaner:htmlcleaner</include>
|
||||
<include>org.javassist:javassist</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
</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.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
<phase>test</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
<useSystemClassLoader>false
|
||||
</useSystemClassLoader> <!-- https://stackoverflow.com/a/53012553/2703239 -->
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- <plugin>
|
||||
<groupId>pl.project13.maven</groupId>
|
||||
<artifactId>git-commit-id-plugin</artifactId>
|
||||
<version>2.2.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>get-the-git-infos</id>
|
||||
<goals>
|
||||
<goal>revision</goal>
|
||||
</goals>
|
||||
*NOTE*: The default phase of revision is initialize, but in case you want to change it, you can do so by adding the phase here
|
||||
<phase>initialize</phase>
|
||||
<configuration>
|
||||
<injectAllReactorProjects>true</injectAllReactorProjects>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>validate-the-git-infos</id>
|
||||
<goals>
|
||||
<goal>validateRevision</goal>
|
||||
</goals>
|
||||
*NOTE*: The default phase of validateRevision is verify, but in case you want to change it, you can do so by adding the phase here
|
||||
<phase>package</phase>
|
||||
<configuration>
|
||||
<validationProperties>
|
||||
- <validationProperty>
|
||||
<name>validating git dirty</name>
|
||||
<value>${git.branch}</value>
|
||||
<shouldMatchTo>dev</shouldMatchTo>
|
||||
</validationProperty> -
|
||||
</validationProperties>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<injectAllReactorProjects>true</injectAllReactorProjects>
|
||||
<verbose>true</verbose>
|
||||
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
|
||||
</configuration>
|
||||
</plugin> -->
|
||||
<!-- <plugin> <groupId>org.basepom.maven</groupId> <artifactId>duplicate-finder-maven-plugin</artifactId>
|
||||
<version>1.2.1</version> <executions> <execution> <goals> <goal>check</goal>
|
||||
</goals> </execution> </executions> </plugin> -->
|
||||
</plugins>
|
||||
</build>
|
||||
<groupId>buttondevteam</groupId>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack</id>
|
||||
<url>https://jitpack.io/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Essentials</id>
|
||||
<url>http://repo.ess3.net/content/repositories/essrel/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Votifier</id>
|
||||
<url>https://dl.bintray.com/nuvotifier/maven/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Minigames</id>
|
||||
<url>http://maven.addstar.com.au/artifactory/release</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
<!-- <repository> <id>WorldEdit</id> <url>http://maven.sk89q.com/artifactory/repo</url>
|
||||
</repository> -->
|
||||
<repository>
|
||||
<id>projectlombok.org</id>
|
||||
<url>http://projectlombok.org/mavenrepo</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||
<artifactId>ButtonCore</artifactId>
|
||||
<version>${env.TRAVIS_BRANCH}-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/net.sourceforge.htmlcleaner/htmlcleaner -->
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.htmlcleaner</groupId>
|
||||
<artifactId>htmlcleaner</artifactId>
|
||||
<version>2.16</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.reflections/reflections -->
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ess3</groupId>
|
||||
<artifactId>Essentials</artifactId>
|
||||
<version>2.13.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||
<artifactId>Towny</artifactId>
|
||||
<version>8d3b6b6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vexsoftware</groupId>
|
||||
<artifactId>nuvotifier-universal</artifactId>
|
||||
<version>2.3.4</version>
|
||||
</dependency>
|
||||
<!-- <dependency> <groupId>au.com.mineauz</groupId> <artifactId>Minigames</artifactId>
|
||||
<version>1.8.0</version> </dependency> -->
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.16</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>
|
||||
<dependency>
|
||||
<groupId>com.github.webbukkit</groupId>
|
||||
<artifactId>Dynmap-Towny</artifactId>
|
||||
<version>master-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.webbukkit</groupId>
|
||||
<artifactId>Dynmap</artifactId>
|
||||
<version>v2.5</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/junit/junit -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<artifactId>ButtonChat</artifactId>
|
||||
<organization>
|
||||
<name>TBMCPlugins</name>
|
||||
<url>https://github.com/TBMCPlugins</url>
|
||||
</organization>
|
||||
<properties>
|
||||
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
|
||||
<github.global.server>githubo</github.global.server>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<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>
|
||||
<parent>
|
||||
<groupId>com.github.TBMCPlugins.ChromaCore</groupId>
|
||||
<artifactId>CorePOM</artifactId>
|
||||
<version>master-SNAPSHOT</version>
|
||||
</parent>
|
||||
<version>v${noprefix.version}-SNAPSHOT</version>
|
||||
<name>Chroma-Chat Plugin</name>
|
||||
<description>Chroma-Chat Plugin</description>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
<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>Chroma-Chat</finalName>
|
||||
<plugins>
|
||||
<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.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
<phase>test</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
<useSystemClassLoader>false
|
||||
</useSystemClassLoader> <!-- https://stackoverflow.com/a/53012553/2703239 -->
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<groupId>buttondevteam</groupId>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack</id>
|
||||
<url>https://jitpack.io/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>ess-repo</id>
|
||||
<url>https://repo.essentialsx.net/releases/</url>
|
||||
</repository>
|
||||
<!-- <repository>
|
||||
<id>Minigames</id>
|
||||
<url>http://maven.addstar.com.au/artifactory/release</url>
|
||||
</repository> -->
|
||||
<!-- <repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
</repository> -->
|
||||
<!-- <repository> <id>WorldEdit</id> <url>http://maven.sk89q.com/artifactory/repo</url>
|
||||
</repository> -->
|
||||
<repository>
|
||||
<id>projectlombok.org</id>
|
||||
<url>https://projectlombok.org/mavenrepo</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Dynmap</id>
|
||||
<url>https://repo.mikeprimm.com</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency> <!-- TODO: Can't update MockBukkit because of a ByteBuddy exception and the old version relies on 1.19.1 -->
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.19.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.TBMCPlugins.ChromaCore</groupId>
|
||||
<artifactId>Chroma-Core</artifactId>
|
||||
<version>v2.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.essentialsx</groupId>
|
||||
<artifactId>EssentialsX</artifactId>
|
||||
<version>2.19.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.TownyAdvanced</groupId>
|
||||
<artifactId>Towny</artifactId>
|
||||
<!-- <version>8d3b6b6</version> ButtonCore repo -->
|
||||
<version>0.98.6.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- <dependency> <groupId>au.com.mineauz</groupId> <artifactId>Minigames</artifactId>
|
||||
<version>1.8.0</version> </dependency> -->
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.22</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.16.4-R0.1-SNAPSHOT</version>
|
||||
</dependency> -->
|
||||
<dependency>
|
||||
<groupId>com.github.TownyAdvanced</groupId>
|
||||
<artifactId>Dynmap-Towny</artifactId>
|
||||
<version>0.89</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>us.dynmap</groupId>
|
||||
<artifactId>dynmap-api</artifactId>
|
||||
<version>3.2-beta-1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/junit/junit -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- Included in vanilla minecraft's JAR -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.17.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- TestPrepare also needs it (ChromaCore) so the versions should match -->
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.mojang/brigadier -->
|
||||
<dependency>
|
||||
<groupId>com.mojang</groupId>
|
||||
<artifactId>brigadier</artifactId>
|
||||
<version>1.0.500</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.seeseemelk</groupId>
|
||||
<artifactId>MockBukkit-v1.19</artifactId>
|
||||
<version>2.29.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<artifactId>Chroma-Chat</artifactId>
|
||||
<organization>
|
||||
<name>TBMCPlugins</name>
|
||||
<url>https://github.com/TBMCPlugins</url>
|
||||
</organization>
|
||||
<properties>
|
||||
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
|
||||
<github.global.server>githubo</github.global.server>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<noprefix.version>1.0.0</noprefix.version>
|
||||
</properties>
|
||||
</project>
|
|
@ -1,25 +0,0 @@
|
|||
package buttondevteam.chat;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class AnnouncerThread implements Runnable {
|
||||
private static int AnnounceMessageIndex = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (!PluginMain.Instance.stop) {
|
||||
try {
|
||||
Thread.sleep(PluginMain.AnnounceTime);
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
if (Bukkit.getOnlinePlayers().size() == 0) continue; //Don't post to Discord if nobody is on
|
||||
if (PluginMain.AnnounceMessages.size() > AnnounceMessageIndex) {
|
||||
Bukkit.broadcastMessage(PluginMain.AnnounceMessages.get(AnnounceMessageIndex));
|
||||
AnnounceMessageIndex++;
|
||||
if (AnnounceMessageIndex == PluginMain.AnnounceMessages.size())
|
||||
AnnounceMessageIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,135 +1,116 @@
|
|||
package buttondevteam.chat;
|
||||
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.player.EnumPlayerData;
|
||||
import buttondevteam.lib.player.PlayerClass;
|
||||
import buttondevteam.lib.player.PlayerData;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@PlayerClass(pluginname = "Button1Chat")
|
||||
public class ChatPlayer extends TBMCPlayerBase {
|
||||
public PlayerData<String> UserName() {
|
||||
return data(null);
|
||||
}
|
||||
|
||||
public List<String> UserNames() {
|
||||
return data(new ArrayList<String>()).get();
|
||||
}
|
||||
|
||||
public PlayerData<Integer> FlairTime() {
|
||||
return data(FlairTimeNone);
|
||||
}
|
||||
|
||||
public EnumPlayerData<FlairStates> FlairState() {
|
||||
return dataEnum(FlairStates.class, FlairStates.NoComment);
|
||||
}
|
||||
|
||||
public PlayerData<Integer> FCount() {
|
||||
return data(0);
|
||||
}
|
||||
|
||||
public PlayerData<Integer> FDeaths() {
|
||||
return data(0);
|
||||
}
|
||||
|
||||
public PlayerData<Boolean> FlairCheater() {
|
||||
return data(false);
|
||||
}
|
||||
|
||||
public PlayerData<ArrayList<Integer>> NameColorLocations() { // No byte[], no TIntArrayList
|
||||
return data(null);
|
||||
}
|
||||
|
||||
public Location SavedLocation;
|
||||
public boolean Working;
|
||||
// public int Tables = 10;
|
||||
public boolean SendingLink = false;
|
||||
public boolean RainbowPresserColorMode = false;
|
||||
public Color OtherColorMode = null;
|
||||
public boolean ChatOnly = false;
|
||||
public int LoginWarningCount = 0;
|
||||
|
||||
public static final int FlairTimeNonPresser = -1;
|
||||
public static final int FlairTimeCantPress = -2;
|
||||
public static final int FlairTimeNone = -3;
|
||||
|
||||
/**
|
||||
* Gets the player's flair, optionally formatting for Minecraft.
|
||||
*
|
||||
* @param noformats
|
||||
* The MC formatting codes will be only applied if false
|
||||
* @return The flair
|
||||
*/
|
||||
public String GetFormattedFlair(boolean noformats) {
|
||||
int time = FlairTime().get();
|
||||
if (time == FlairTimeCantPress)
|
||||
return noformats ? "(can't press)" : "§r(--s)§r";
|
||||
if (time == FlairTimeNonPresser)
|
||||
return noformats ? "(non-presser)" : "§7(--s)§r";
|
||||
if (time == FlairTimeNone)
|
||||
return "";
|
||||
return noformats ? String.format("(%ds)", time) : String.format("§%x(%ds)§r", GetFlairColor(), time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player's flair, formatted for Minecraft.
|
||||
*
|
||||
* @return The flair
|
||||
*/
|
||||
public String GetFormattedFlair() {
|
||||
return GetFormattedFlair(false);
|
||||
}
|
||||
|
||||
public void SetFlair(int time) {
|
||||
FlairTime().set(time);
|
||||
FlairUpdate();
|
||||
}
|
||||
|
||||
public void SetFlair(int time, boolean cheater) {
|
||||
FlairTime().set(time);
|
||||
FlairCheater().set(cheater);
|
||||
FlairUpdate();
|
||||
}
|
||||
|
||||
public void FlairUpdate() {
|
||||
|
||||
// Flairs from Command Block The Button - Teams
|
||||
// PluginMain.Instance.getServer().getScoreboardManager().getMainScoreboard().getTeams().add()
|
||||
Player p = Bukkit.getPlayer(uuid);
|
||||
if (p != null)
|
||||
p.setPlayerListName(String.format("%s%s", p.getDisplayName(), GetFormattedFlair()));
|
||||
}
|
||||
|
||||
public short GetFlairColor() {
|
||||
if (FlairCheater().get())
|
||||
return 0x5;
|
||||
final int flairTime = FlairTime().get();
|
||||
if (flairTime == FlairTimeNonPresser)
|
||||
return 0x7;
|
||||
else if (flairTime == FlairTimeCantPress)
|
||||
return 0xf;
|
||||
else if (flairTime <= 60 && flairTime >= 52)
|
||||
return 0x5;
|
||||
else if (flairTime <= 51 && flairTime >= 42)
|
||||
return 0x9;
|
||||
else if (flairTime <= 41 && flairTime >= 32)
|
||||
return 0xa;
|
||||
else if (flairTime <= 31 && flairTime >= 22)
|
||||
return 0xe;
|
||||
else if (flairTime <= 21 && flairTime >= 11)
|
||||
return 0x6;
|
||||
else if (flairTime <= 11 && flairTime >= 0)
|
||||
return 0xc;
|
||||
return 0x00; //Return 0 if none or too high, so names will get aqua default color, not white
|
||||
}
|
||||
|
||||
public double getF() {
|
||||
return (double) FCount().get() / (double) FDeaths().get();
|
||||
}
|
||||
}
|
||||
package buttondevteam.chat;
|
||||
|
||||
import buttondevteam.chat.components.flair.FlairStates;
|
||||
import buttondevteam.lib.architecture.config.IConfigData;
|
||||
import buttondevteam.lib.architecture.config.IListConfigData;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.player.PlayerClass;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@PlayerClass(pluginname = "Chroma-Chat")
|
||||
public class ChatPlayer extends TBMCPlayerBase {
|
||||
public final IConfigData<String> UserName = getConfig().getData("UserName", "");
|
||||
|
||||
public final IListConfigData<String> UserNames = getConfig().getListData("UserNames", Collections.emptyList());
|
||||
|
||||
public final IConfigData<Integer> FlairTime = getConfig().getData("FlairTime", FlairTimeNone);
|
||||
|
||||
public final IConfigData<FlairStates> FlairState = getConfig().getData("FlairState", FlairStates.NoComment,
|
||||
fs -> FlairStates.valueOf((String) fs), FlairStates::toString);
|
||||
|
||||
public final IConfigData<Integer> FCount = getConfig().getData("FCount", 0);
|
||||
|
||||
public final IConfigData<Integer> FDeaths = getConfig().getData("FDeaths", 0);
|
||||
|
||||
public final IConfigData<Boolean> FlairCheater = getConfig().getData("FlairCheater", false);
|
||||
|
||||
public final IListConfigData<Integer> NameColorLocations = getConfig().getListData("NameColorLocations", Collections.emptyList()); // No byte[], no TIntArrayList
|
||||
|
||||
public boolean Working;
|
||||
// public int Tables = 10;
|
||||
public boolean RainbowPresserColorMode = false;
|
||||
public Color OtherColorMode = null;
|
||||
public boolean ChatOnly = false;
|
||||
public long LastMessageTime = 0L;
|
||||
|
||||
public static final int FlairTimeNonPresser = -1;
|
||||
public static final int FlairTimeCantPress = -2;
|
||||
public static final int FlairTimeNone = -3;
|
||||
|
||||
/**
|
||||
* Gets the player's flair, optionally formatting for Minecraft.
|
||||
*
|
||||
* @param noformats The MC formatting codes will be only applied if false
|
||||
* @return The flair
|
||||
*/
|
||||
public String GetFormattedFlair(boolean noformats) {
|
||||
int time = FlairTime.get();
|
||||
if (time == FlairTimeCantPress)
|
||||
return noformats ? "(can't press)" : "§r(--s)§r";
|
||||
if (time == FlairTimeNonPresser)
|
||||
return noformats ? "(non-presser)" : "§7(--s)§r";
|
||||
if (time == FlairTimeNone)
|
||||
return "";
|
||||
return noformats ? String.format("(%ds)", time) : String.format("§%x(%ds)§r", GetFlairColor(), time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player's flair, formatted for Minecraft.
|
||||
*
|
||||
* @return The flair
|
||||
*/
|
||||
public String GetFormattedFlair() {
|
||||
return GetFormattedFlair(false);
|
||||
}
|
||||
|
||||
public void SetFlair(int time) {
|
||||
FlairTime.set(time);
|
||||
FlairUpdate();
|
||||
}
|
||||
|
||||
public void SetFlair(int time, boolean cheater) {
|
||||
FlairTime.set(time);
|
||||
FlairCheater.set(cheater);
|
||||
FlairUpdate();
|
||||
}
|
||||
|
||||
public void FlairUpdate() {
|
||||
|
||||
// Flairs from Command Block The Button - Teams
|
||||
// PluginMain.Instance.getServer().getScoreboardManager().getMainScoreboard().getTeams().add()
|
||||
Player p = Bukkit.getPlayer(getUniqueId());
|
||||
if (p != null)
|
||||
p.setPlayerListName(String.format("%s%s", p.getDisplayName(), GetFormattedFlair()));
|
||||
}
|
||||
|
||||
public short GetFlairColor() {
|
||||
if (FlairCheater.get())
|
||||
return 0x5;
|
||||
final int flairTime = FlairTime.get();
|
||||
if (flairTime == FlairTimeNonPresser)
|
||||
return 0x7;
|
||||
else if (flairTime == FlairTimeCantPress)
|
||||
return 0xf;
|
||||
else if (flairTime <= 60 && flairTime >= 52)
|
||||
return 0x5;
|
||||
else if (flairTime <= 51 && flairTime >= 42)
|
||||
return 0x9;
|
||||
else if (flairTime <= 41 && flairTime >= 32)
|
||||
return 0xa;
|
||||
else if (flairTime <= 31 && flairTime >= 22)
|
||||
return 0xe;
|
||||
else if (flairTime <= 21 && flairTime >= 11)
|
||||
return 0x6;
|
||||
else if (flairTime <= 11 && flairTime >= 0)
|
||||
return 0xc;
|
||||
return 0x00; //Return 0 if none or too high, so names will get aqua default color, not white
|
||||
}
|
||||
|
||||
public double getF() {
|
||||
return (double) FCount.get() / (double) FDeaths.get();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,345 +0,0 @@
|
|||
package buttondevteam.chat;
|
||||
|
||||
import buttondevteam.chat.commands.UnlolCommand;
|
||||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||
import buttondevteam.chat.formatting.ChatFormatter;
|
||||
import buttondevteam.chat.formatting.TellrawEvent;
|
||||
import buttondevteam.chat.formatting.TellrawPart;
|
||||
import buttondevteam.chat.formatting.TellrawSerializer;
|
||||
import buttondevteam.chat.listener.PlayerListener;
|
||||
import buttondevteam.lib.TBMCChatEvent;
|
||||
import buttondevteam.lib.TBMCChatEventBase;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.chat.Priority;
|
||||
import buttondevteam.lib.chat.TellrawSerializableEnum;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ChatProcessing {
|
||||
private static final Pattern NULL_MENTION_PATTERN = Pattern.compile("null");
|
||||
private static final Pattern CYAN_PATTERN = Pattern.compile("cyan");
|
||||
private static final Pattern ESCAPE_PATTERN = Pattern.compile("\\\\");
|
||||
private static final Pattern CONSOLE_PING_PATTERN = Pattern.compile("(?i)" + Pattern.quote("@console"));
|
||||
private static final Pattern HASHTAG_PATTERN = Pattern.compile("#(\\w+)");
|
||||
private static final Pattern URL_PATTERN = Pattern.compile("(http[\\w:/?=$\\-_.+!*'(),&]+(?:#[\\w]+)?)");
|
||||
public static final Pattern ENTIRE_MESSAGE_PATTERN = Pattern.compile(".+");
|
||||
private static final Pattern UNDERLINED_PATTERN = Pattern.compile("_");
|
||||
private static final Pattern ITALIC_PATTERN = Pattern.compile("\\*");
|
||||
private static final Pattern BOLD_PATTERN = Pattern.compile("\\*\\*");
|
||||
private static final Pattern CODE_PATTERN = Pattern.compile("`");
|
||||
private static final Pattern MASKED_LINK_PATTERN = Pattern.compile("\\[([^\\[\\]])\\]\\(([^()])\\)");
|
||||
private static final Pattern SOMEONE_PATTERN = Pattern.compile("@someone"); //TODO
|
||||
private static final Pattern STRIKETHROUGH_PATTERN = Pattern.compile("~~");
|
||||
private static final Color[] RainbowPresserColors = new Color[]{Color.Red, Color.Gold, Color.Yellow, Color.Green,
|
||||
Color.Blue, Color.DarkPurple};
|
||||
private static boolean pingedconsole = false;
|
||||
|
||||
public static final ChatFormatter ESCAPE_FORMATTER = ChatFormatter.builder().regex(ESCAPE_PATTERN).build();
|
||||
|
||||
private static ArrayList<ChatFormatter> commonFormatters = Lists.newArrayList(
|
||||
ChatFormatter.builder().regex(BOLD_PATTERN).bold(true).removeCharCount((short) 2).type(ChatFormatter.Type.Range)
|
||||
.priority(Priority.High).build(),
|
||||
ChatFormatter.builder().regex(ITALIC_PATTERN).italic(true).removeCharCount((short) 1).type(ChatFormatter.Type.Range).build(),
|
||||
ChatFormatter.builder().regex(UNDERLINED_PATTERN).underlined(true).removeCharCount((short) 1).type(ChatFormatter.Type.Range)
|
||||
.build(),
|
||||
ChatFormatter.builder().regex(STRIKETHROUGH_PATTERN).strikethrough(true).removeCharCount((short) 2).type(ChatFormatter.Type.Range)
|
||||
.build(),
|
||||
ESCAPE_FORMATTER, ChatFormatter.builder().regex(URL_PATTERN).underlined(true).openlink("$1").type(ChatFormatter.Type.Excluder).build(),
|
||||
ChatFormatter.builder().regex(NULL_MENTION_PATTERN).color(Color.DarkRed).build(), // Properly added a bug as a feature
|
||||
ChatFormatter.builder().regex(CONSOLE_PING_PATTERN).color(Color.Aqua).onmatch((match, builder) -> {
|
||||
if (!pingedconsole) {
|
||||
System.out.print("\007");
|
||||
pingedconsole = true; // Will set it to false in ProcessChat
|
||||
}
|
||||
return match;
|
||||
}).priority(Priority.High).build(),
|
||||
|
||||
ChatFormatter.builder().regex(HASHTAG_PATTERN).color(Color.Blue).openlink("https://twitter.com/hashtag/$1")
|
||||
.priority(Priority.High).build(),
|
||||
ChatFormatter.builder().regex(CYAN_PATTERN).color(Color.Aqua).build(), // #55
|
||||
ChatFormatter.builder().regex(CODE_PATTERN).color(Color.DarkGray).removeCharCount((short) 1).type(ChatFormatter.Type.Range)
|
||||
.build(),
|
||||
ChatFormatter.builder().regex(MASKED_LINK_PATTERN).underlined(true).onmatch((match, builder) -> {
|
||||
return match; // TODO!
|
||||
}).build());
|
||||
private static Gson gson = new GsonBuilder()
|
||||
.registerTypeHierarchyAdapter(TellrawSerializableEnum.class, new TellrawSerializer.TwEnum())
|
||||
.registerTypeHierarchyAdapter(Collection.class, new TellrawSerializer.TwCollection())
|
||||
.registerTypeAdapter(Boolean.class, new TellrawSerializer.TwBool())
|
||||
.registerTypeAdapter(boolean.class, new TellrawSerializer.TwBool()).disableHtmlEscaping().create();
|
||||
private static final String[] testPlayers = {"Koiiev", "iie", "Alisolarflare", "NorbiPeti", "Arsen_Derby_FTW", "carrot_lynx"};
|
||||
static final String MCORIGIN = "Minecraft"; //Shouldn't change, like ever - TBMCPlayer.getFolderForType(TBMCPlayer.class) capitalized
|
||||
|
||||
private ChatProcessing() {
|
||||
}
|
||||
|
||||
public static boolean ProcessChat(TBMCChatEvent e) {
|
||||
Channel channel = e.getChannel();
|
||||
CommandSender sender = e.getSender();
|
||||
String message = e.getMessage();
|
||||
long processstart = System.nanoTime();
|
||||
Player player = (sender instanceof Player ? (Player) sender : null);
|
||||
User user = PluginMain.essentials.getUser(player);
|
||||
|
||||
if (player != null) {
|
||||
user.updateActivity(true); //Could talk in a private channel, so broadcast
|
||||
if (user.isMuted())
|
||||
return true;
|
||||
}
|
||||
|
||||
doFunStuff(sender, e, message);
|
||||
|
||||
ChatPlayer mp;
|
||||
if (player != null)
|
||||
mp = TBMCPlayerBase.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
else //Due to the online player map, getPlayer() can be more efficient than getAs()
|
||||
mp = e.getUser().getAs(ChatPlayer.class); //May be null
|
||||
|
||||
Color colormode = channel.color;
|
||||
if (mp != null && mp.OtherColorMode != null)
|
||||
colormode = mp.OtherColorMode;
|
||||
if (message.startsWith(">"))
|
||||
colormode = Color.Green;
|
||||
// If greentext, ignore channel or player colors
|
||||
|
||||
ArrayList<ChatFormatter> formatters = addFormatters(colormode);
|
||||
if (colormode == channel.color && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
|
||||
final AtomicInteger rpc = new AtomicInteger(0);
|
||||
formatters.add(ChatFormatter.builder().color(colormode).onmatch((match, cf) -> {
|
||||
cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]);
|
||||
return match;
|
||||
}).build());
|
||||
}
|
||||
pingedconsole = false; // Will set it to true onmatch (static constructor)
|
||||
final String channelidentifier = getChannelID(channel, sender, e.getOrigin());
|
||||
|
||||
TellrawPart json = createTellraw(sender, message, player, mp, e.getUser(), channelidentifier, e.getOrigin());
|
||||
long combinetime = System.nanoTime();
|
||||
ChatFormatter.Combine(formatters, message, json);
|
||||
combinetime = System.nanoTime() - combinetime;
|
||||
String jsonstr = toJson(json);
|
||||
if (jsonstr.length() >= 32767) {
|
||||
sender.sendMessage(
|
||||
"§cError: Message too long. Try shortening it, or remove hashtags and other formatting.");
|
||||
return true;
|
||||
}
|
||||
DebugCommand.SendDebugMessage(jsonstr);
|
||||
|
||||
try {
|
||||
if (!channel.isGlobal()) {
|
||||
Objective obj = PluginMain.SB.getObjective(channel.ID);
|
||||
int score = -1;
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
final int mcScore;
|
||||
if (player != null
|
||||
&& PluginMain.essentials.getUser(p).isIgnoredPlayer(PluginMain.essentials.getUser(player)))
|
||||
mcScore = -1; // Don't send the message to them
|
||||
else
|
||||
mcScore = VanillaUtils.getMCScoreIfChatOn(p, e);
|
||||
obj.getScore(p.getName())
|
||||
.setScore(p.getUniqueId().equals(player == null ? null : player.getUniqueId()) // p.UniqueID==player?.UniqueID
|
||||
? score = mcScore : mcScore);
|
||||
}
|
||||
if (score == -1) // Even if the player object isn't null, it may not be in OnlinePlayers
|
||||
score = e.getMCScore(sender);
|
||||
if (score < 0) // Never send messages to score below 0
|
||||
sender.sendMessage("§cYou don't have permission to send this message or something went wrong");
|
||||
else {
|
||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
||||
String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID,
|
||||
score, jsonstr));
|
||||
if (e.getChannel().ID.equals(PluginMain.TownChat.ID)
|
||||
|| e.getChannel().ID.equals(PluginMain.NationChat.ID)) {
|
||||
((List<TellrawPart>) json.getExtra()).add(0, new TellrawPart("[SPY]"));
|
||||
jsonstr = toJson(json);
|
||||
Bukkit.getServer().dispatchCommand(PluginMain.Console, String.format(
|
||||
"tellraw @a[score_%s=1000,score_%s_min=1000] %s", channel.ID, channel.ID, jsonstr));
|
||||
}
|
||||
}
|
||||
} else
|
||||
PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console,
|
||||
String.format("tellraw @a %s", jsonstr));
|
||||
} catch (Exception ex) {
|
||||
TBMCCoreAPI.SendException("An error occured while sending a chat message!", ex);
|
||||
sender.sendMessage("§cAn error occured while sending the message.");
|
||||
return true;
|
||||
}
|
||||
PluginMain.Instance.getServer().getConsoleSender()
|
||||
.sendMessage(String.format("%s <%s§r> %s", channelidentifier, getSenderName(sender, player), message));
|
||||
DebugCommand.SendDebugMessage(
|
||||
"-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms");
|
||||
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms");
|
||||
return false;
|
||||
}
|
||||
|
||||
static String toJson(TellrawPart json) {
|
||||
return gson.toJson(json);
|
||||
}
|
||||
|
||||
static TellrawPart createTellraw(CommandSender sender, String message, @Nullable Player player,
|
||||
@Nullable ChatPlayer mp, @Nullable ChromaGamerBase cg, final String channelidentifier,
|
||||
String origin) {
|
||||
TellrawPart json = new TellrawPart("");
|
||||
if (mp != null && mp.ChatOnly) {
|
||||
json.addExtra(new TellrawPart("[C]")
|
||||
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
|
||||
}
|
||||
json.addExtra(
|
||||
new TellrawPart(channelidentifier)
|
||||
.setHoverEvent(
|
||||
TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT,
|
||||
new TellrawPart((MCORIGIN.equals(origin) ? "" : "From " + origin + "n")
|
||||
+ "Copy message").setColor(Color.Blue)))
|
||||
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAction.SUGGEST_COMMAND, message)));
|
||||
if (PluginMain.permission.has(sender, "tbmc.badge.diamond"))
|
||||
json.addExtra(new TellrawPart("[P]").setColor(Color.Aqua).setBold(true)
|
||||
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Diamond Patreon supporter")));
|
||||
else if (PluginMain.permission.has(sender, "tbmc.badge.gold"))
|
||||
json.addExtra(new TellrawPart("[P]").setColor(Color.Gold).setBold(true)
|
||||
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Gold Patreon supporter")));
|
||||
json.addExtra(new TellrawPart(" <"));
|
||||
TellrawPart hovertp = new TellrawPart("");
|
||||
if (cg != null)
|
||||
hovertp.addExtra(new TellrawPart(cg.getInfo(ChromaGamerBase.InfoTarget.MCHover)));
|
||||
json.addExtra(new TellrawPart(getSenderName(sender, player))
|
||||
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, hovertp)));
|
||||
json.addExtra(new TellrawPart("> "));
|
||||
return json;
|
||||
}
|
||||
|
||||
private static String getSenderName(CommandSender sender, Player player) {
|
||||
if (player == null)
|
||||
return sender.getName();
|
||||
return player.getDisplayName();
|
||||
}
|
||||
|
||||
static String getChannelID(Channel channel, CommandSender sender, String origin) {
|
||||
return ("[" + (MCORIGIN.equals(origin) ? "" : "§8" + origin.substring(0, 1) + "§r|") + channel.DisplayName)
|
||||
+ "]";
|
||||
}
|
||||
|
||||
static ArrayList<ChatFormatter> addFormatters(Color colormode) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ArrayList<ChatFormatter> formatters = (ArrayList<ChatFormatter>) commonFormatters.clone();
|
||||
|
||||
formatters.add(
|
||||
ChatFormatter.builder().regex(ENTIRE_MESSAGE_PATTERN).color(colormode).priority(Priority.Low).build());
|
||||
|
||||
boolean nottest; //Not assigning a default value, so that it can only be used in the if
|
||||
if ((nottest = Bukkit.getOnlinePlayers().size() > 0) || Bukkit.getVersion().equals("test")) {
|
||||
StringBuilder namesb = new StringBuilder("(?i)(");
|
||||
if (nottest)
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
namesb.append(p.getName()).append("|");
|
||||
else
|
||||
for (String testPlayer : testPlayers)
|
||||
namesb.append(testPlayer).append("|");
|
||||
namesb.deleteCharAt(namesb.length() - 1);
|
||||
namesb.append(")");
|
||||
StringBuilder nicksb = new StringBuilder("(?i)(");
|
||||
boolean addNickFormatter = false;
|
||||
int index = 0;
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
final String nick = PlayerListener.nicknames.inverse().get(p.getUniqueId());
|
||||
if (nick != null) {
|
||||
nicksb.append(nick).append("|");
|
||||
addNickFormatter = true; //Add it even if there's only 1 player online (it was in the if)
|
||||
}
|
||||
index++;
|
||||
}
|
||||
nicksb.deleteCharAt(nicksb.length() - 1);
|
||||
nicksb.append(")");
|
||||
|
||||
Consumer<String> error = message -> {
|
||||
if (PluginMain.Instance != null)
|
||||
PluginMain.Instance.getLogger().warning(message);
|
||||
else
|
||||
System.out.println(message);
|
||||
};
|
||||
|
||||
formatters.add(ChatFormatter.builder().regex(Pattern.compile(namesb.toString())).color(Color.Aqua)
|
||||
.onmatch((match, builder) -> {
|
||||
Player p = Bukkit.getPlayer(match);
|
||||
Optional<String> pn = nottest ? Optional.empty()
|
||||
: Arrays.stream(testPlayers).filter(tp -> tp.equalsIgnoreCase(match)).findAny();
|
||||
if (nottest ? p == null : !pn.isPresent()) {
|
||||
error.accept("Error: Can't find player " + match + " but was reported as online.");
|
||||
return "§c" + match + "§r";
|
||||
}
|
||||
ChatPlayer mpp = TBMCPlayer.getPlayer(nottest ? p.getUniqueId() : new UUID(0, 0), ChatPlayer.class);
|
||||
if (nottest) {
|
||||
if (PlayerListener.NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn
|
||||
else
|
||||
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
||||
(float) PlayerListener.NotificationPitch);
|
||||
}
|
||||
String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor()));
|
||||
return color + (nottest ? p.getName() : pn.get()) + "§r"; //Fix name casing, except when testing
|
||||
}).priority(Priority.High).type(ChatFormatter.Type.Excluder).build());
|
||||
|
||||
if (addNickFormatter)
|
||||
formatters.add(ChatFormatter.builder().regex((Pattern.compile(nicksb.toString()))).color(Color.Aqua)
|
||||
.onmatch((match, builder) -> {
|
||||
if (PlayerListener.nicknames.containsKey(match.toLowerCase())) { //Made a stream and all that but I can actually store it lowercased
|
||||
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match.toLowerCase()));
|
||||
if (p == null) {
|
||||
error.accept("Error: Can't find player nicknamed "
|
||||
+ match.toLowerCase() + " but was reported as online.");
|
||||
return "§c" + match + "§r";
|
||||
}
|
||||
if (PlayerListener.NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f);
|
||||
else
|
||||
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
||||
(float) PlayerListener.NotificationPitch);
|
||||
return PluginMain.essentials.getUser(p).getNickname();
|
||||
}
|
||||
error.accept("Player nicknamed " + match.toLowerCase()
|
||||
+ " not found in nickname map but was reported as online.");
|
||||
return "§c" + match + "§r";
|
||||
}).priority(Priority.High).type(ChatFormatter.Type.Excluder).build());
|
||||
}
|
||||
return formatters;
|
||||
}
|
||||
|
||||
static void doFunStuff(CommandSender sender, TBMCChatEventBase event, String message) {
|
||||
if (PlayerListener.ActiveF && !PlayerListener.Fs.contains(sender) && message.equalsIgnoreCase("F"))
|
||||
PlayerListener.Fs.add(sender);
|
||||
|
||||
String msg = message.toLowerCase();
|
||||
val lld = new UnlolCommand.LastlolData(sender, event, System.nanoTime());
|
||||
boolean add;
|
||||
if (add = msg.contains("lol"))
|
||||
lld.setLolornot(true);
|
||||
else {
|
||||
for (int i = 0; i < PlayerListener.LaughStrings.length; i++) {
|
||||
if (add = msg.contains(PlayerListener.LaughStrings[i])) {
|
||||
lld.setLolornot(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (add)
|
||||
UnlolCommand.Lastlol.put(event.getChannel(), lld);
|
||||
}
|
||||
}
|
65
src/main/java/buttondevteam/chat/ChatUtils.java
Normal file
65
src/main/java/buttondevteam/chat/ChatUtils.java
Normal file
|
@ -0,0 +1,65 @@
|
|||
package buttondevteam.chat;
|
||||
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.lib.TBMCChatEvent;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public final class ChatUtils {
|
||||
public static final String MCORIGIN = "Minecraft"; //Shouldn't change, like ever - TBMCPlayer.getFolderForType(TBMCPlayer.class) capitalized
|
||||
|
||||
private ChatUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a console command.
|
||||
*
|
||||
* @param command The command
|
||||
* @param async Whether the caller is async
|
||||
*/
|
||||
public static void dispatchConsoleCommand(String command, boolean async) {
|
||||
if (async)
|
||||
Bukkit.getScheduler().runTask(PluginMain.Instance, () -> Bukkit.dispatchCommand(PluginMain.Console, command));
|
||||
else
|
||||
Bukkit.dispatchCommand(PluginMain.Console, command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string between the start and end strings (exclusive).
|
||||
*
|
||||
* @param str The original string
|
||||
* @param start The start string
|
||||
* @param end The end string
|
||||
* @return The result string
|
||||
*/
|
||||
public static Optional<String> coolSubstring(String str, String start, String end) {
|
||||
int a = str.indexOf(start) + start.length();
|
||||
int b = str.indexOf(end, a);
|
||||
return a != -1 && b != -1 ? Optional.of(str.substring(a, b)) : Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a regular (non-Markdown) chat message. Used as a fallback if the chat processing fails.
|
||||
*
|
||||
* @param e The chat event
|
||||
*/
|
||||
public static void sendChatMessage(TBMCChatEvent e) {
|
||||
var str = getMessageString(e.getChannel(), e.getUser(), e.getMessage());
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
if (e.shouldSendTo(ChromaGamerBase.getFromSender(p)))
|
||||
p.sendMessage(str);
|
||||
Bukkit.getConsoleSender().sendMessage(str);
|
||||
}
|
||||
|
||||
public static String getMessageString(Channel channel, ChromaGamerBase sender, String message) {
|
||||
return "§c!§r[" + channel.displayName.get() + "] <" + sender.getName() + "> " + message;
|
||||
}
|
||||
|
||||
public static void sendChatMessage(Channel channel, ChromaGamerBase sender, String message, CommandSender to) {
|
||||
to.sendMessage(getMessageString(channel, sender, message));
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
package buttondevteam.chat;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
public class JarUtils {
|
||||
|
||||
public static boolean extractFromJar(final String fileName,
|
||||
final String dest) throws IOException {
|
||||
if (getRunningJar() == null) {
|
||||
return false;
|
||||
}
|
||||
final File file = new File(dest);
|
||||
if (file.isDirectory()) {
|
||||
file.mkdir();
|
||||
return false;
|
||||
}
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
final JarFile jar = getRunningJar();
|
||||
final Enumeration<JarEntry> e = jar.entries();
|
||||
while (e.hasMoreElements()) {
|
||||
final JarEntry je = e.nextElement();
|
||||
if (!je.getName().contains(fileName)) {
|
||||
continue;
|
||||
}
|
||||
final InputStream in = new BufferedInputStream(
|
||||
jar.getInputStream(je));
|
||||
final OutputStream out = new BufferedOutputStream(
|
||||
new FileOutputStream(file));
|
||||
copyInputStream(in, out);
|
||||
jar.close();
|
||||
return true;
|
||||
}
|
||||
jar.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
private final static void copyInputStream(final InputStream in,
|
||||
final OutputStream out) throws IOException {
|
||||
try {
|
||||
final byte[] buff = new byte[4096];
|
||||
int n;
|
||||
while ((n = in.read(buff)) > 0) {
|
||||
out.write(buff, 0, n);
|
||||
}
|
||||
} finally {
|
||||
out.flush();
|
||||
out.close();
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static URL getJarUrl(final File file) throws IOException {
|
||||
return new URL("jar:" + file.toURI().toURL().toExternalForm() + "!/");
|
||||
}
|
||||
|
||||
public static JarFile getRunningJar() throws IOException {
|
||||
if (!RUNNING_FROM_JAR) {
|
||||
return null; // null if not running from jar
|
||||
}
|
||||
String path = new File(JarUtils.class.getProtectionDomain()
|
||||
.getCodeSource().getLocation().getPath()).getAbsolutePath();
|
||||
path = URLDecoder.decode(path, "UTF-8");
|
||||
return new JarFile(path);
|
||||
}
|
||||
|
||||
private static boolean RUNNING_FROM_JAR = false;
|
||||
|
||||
static {
|
||||
final URL resource = JarUtils.class.getClassLoader().getResource(
|
||||
"plugin.yml");
|
||||
if (resource != null) {
|
||||
RUNNING_FROM_JAR = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,426 +1,96 @@
|
|||
package buttondevteam.chat;
|
||||
|
||||
import buttondevteam.chat.commands.YeehawCommand;
|
||||
import buttondevteam.chat.commands.ucmds.TownColorCommand;
|
||||
import buttondevteam.chat.listener.PlayerJoinLeaveListener;
|
||||
import buttondevteam.chat.listener.PlayerListener;
|
||||
import buttondevteam.chat.listener.TownyListener;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.lib.chat.Channel.RecipientTestResult;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
import lombok.val;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.dynmap.towny.DTBridge;
|
||||
import org.dynmap.towny.DynmapTownyPlugin;
|
||||
import org.htmlcleaner.HtmlCleaner;
|
||||
import org.htmlcleaner.TagNode;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||
// A user, which flair isn't obtainable:
|
||||
// https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||
public static PluginMain Instance;
|
||||
public static ConsoleCommandSender Console;
|
||||
private final static String FlairThreadURL = "https://www.reddit.com/r/Chromagamers/comments/51ys94/flair_thread_for_the_mc_server/";
|
||||
|
||||
public static Scoreboard SB;
|
||||
public static TownyUniverse TU;
|
||||
private static ArrayList<Town> Towns;
|
||||
private static ArrayList<Nation> Nations;
|
||||
|
||||
public static Channel TownChat;
|
||||
public static Channel NationChat;
|
||||
private static Channel RPChannel;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This variable is used as a cache for flair state checking when reading the flair thread.
|
||||
* </p>
|
||||
* <p>
|
||||
* It's used because normally it has to load all associated player files every time to read the flair state
|
||||
* </p>
|
||||
*/
|
||||
private Set<String> PlayersWithFlairs = new HashSet<>();
|
||||
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Instance = this;
|
||||
PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
|
||||
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this);
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerJoinLeaveListener(), this);
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(new TownyListener(), this);
|
||||
TBMCChatAPI.AddCommands(this, YeehawCommand.class);
|
||||
Console = this.getServer().getConsoleSender();
|
||||
LoadFiles();
|
||||
|
||||
SB = getServer().getScoreboardManager().getMainScoreboard(); // Main can be detected with @a[score_...]
|
||||
TU = ((Towny) Bukkit.getPluginManager().getPlugin("Towny")).getTownyUniverse();
|
||||
Towns = new ArrayList<>(TU.getTownsMap().values()); // Creates a snapshot of towns, new towns will be added when needed
|
||||
Nations = new ArrayList<>(TU.getNationsMap().values()); // Same here but with nations
|
||||
|
||||
TownColors.keySet().removeIf(t -> !TU.getTownsMap().containsKey(t)); // Removes town colors for deleted/renamed towns
|
||||
NationColor.keySet().removeIf(n -> !TU.getNationsMap().containsKey(n)); // Removes nation colors for deleted/renamed nations
|
||||
|
||||
TBMCChatAPI.RegisterChatChannel(
|
||||
TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false)));
|
||||
TBMCChatAPI.RegisterChatChannel(
|
||||
NationChat = new Channel("§6NC§f", Color.Gold, "nc", s -> checkTownNationChat(s, true)));
|
||||
TBMCChatAPI.RegisterChatChannel(RPChannel = new Channel("§7RP§f", Color.Gray, "rp", null)); //Since it's null, it's recognised as global
|
||||
|
||||
Bukkit.getScheduler().runTask(this, () -> {
|
||||
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
||||
if (dtp == null)
|
||||
return;
|
||||
for (val entry : TownColors.entrySet())
|
||||
setTownColor(dtp, buttondevteam.chat.commands.ucmds.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue());
|
||||
});
|
||||
|
||||
if (!setupEconomy() || !setupPermissions())
|
||||
TBMCCoreAPI.SendException("We're in trouble", new Exception("Failed to set up economy or permissions!"));
|
||||
|
||||
new Thread(this::FlairGetterThreadMethod).start();
|
||||
new Thread(new AnnouncerThread()).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a town's color on Dynmap.
|
||||
*
|
||||
* @param dtp A reference for the Dynmap-Towny plugin
|
||||
* @param town The town's name using the correct casing
|
||||
* @param colors The town's colors
|
||||
*/
|
||||
public static void setTownColor(DynmapTownyPlugin dtp, String town, Color[] colors) {
|
||||
Function<Color, Integer> c2i = c -> c.getRed() << 16 | c.getGreen() << 8 | c.getBlue();
|
||||
try {
|
||||
DTBridge.setTownColor(dtp, town, c2i.apply(colors[0]),
|
||||
c2i.apply(colors.length > 1 ? colors[1] : colors[0]));
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Failed to set town color for town " + town + "!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean stop = false;
|
||||
public static Essentials essentials = null;
|
||||
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable() {
|
||||
SaveFiles();
|
||||
stop = true;
|
||||
}
|
||||
|
||||
private void FlairGetterThreadMethod() {
|
||||
int errorcount = 0;
|
||||
while (!stop) {
|
||||
try {
|
||||
String body = TBMCCoreAPI.DownloadString(FlairThreadURL + ".json?limit=1000");
|
||||
JsonArray json = new JsonParser().parse(body).getAsJsonArray().get(1).getAsJsonObject().get("data")
|
||||
.getAsJsonObject().get("children").getAsJsonArray();
|
||||
for (Object obj : json) {
|
||||
JsonObject item = (JsonObject) obj;
|
||||
String author = item.get("data").getAsJsonObject().get("author").getAsString();
|
||||
String ign = item.get("data").getAsJsonObject().get("body").getAsString();
|
||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||
if (start == -1 + "IGN:".length())
|
||||
continue;
|
||||
int end = ign.indexOf(' ', start);
|
||||
if (end == -1 || end == start)
|
||||
end = ign.indexOf('\n', start);
|
||||
if (end == -1 || end == start)
|
||||
ign = ign.substring(start);
|
||||
else
|
||||
ign = ign.substring(start, end);
|
||||
ign = ign.trim();
|
||||
if (PlayersWithFlairs.contains(ign))
|
||||
continue;
|
||||
try (ChatPlayer mp = TBMCPlayerBase.getFromName(ign, ChatPlayer.class)) { // Loads player file
|
||||
if (mp == null)
|
||||
continue;
|
||||
/*
|
||||
* if (!JoinedBefore(mp, 2015, 6, 5)) continue;
|
||||
*/
|
||||
if (!mp.UserNames().contains(author))
|
||||
mp.UserNames().add(author);
|
||||
if (mp.FlairState().get().equals(FlairStates.NoComment)) {
|
||||
mp.FlairState().set(FlairStates.Commented);
|
||||
ConfirmUserMessage(mp);
|
||||
}
|
||||
PlayersWithFlairs.add(ign); // Don't redownload even if flair isn't accepted
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errorcount++;
|
||||
if (errorcount >= 10) {
|
||||
errorcount = 0;
|
||||
if (!e.getMessage().contains("Server returned HTTP response code")
|
||||
&& !(e instanceof UnknownHostException))
|
||||
TBMCCoreAPI.SendException("Error while getting flairs from Reddit!", e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DownloadFlair(ChatPlayer mp) throws IOException {
|
||||
String[] flairdata = TBMCCoreAPI
|
||||
.DownloadString("http://karmadecay.com/thebutton-data.php?users=" + mp.UserName().get())
|
||||
.replace("\"", "").split(":");
|
||||
String flair;
|
||||
if (flairdata.length > 1)
|
||||
flair = flairdata[1];
|
||||
else
|
||||
flair = "";
|
||||
String flairclass;
|
||||
if (flairdata.length > 2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass = "unknown";
|
||||
SetFlair(mp, flair, flairclass, mp.UserName().get());
|
||||
}
|
||||
|
||||
private void SetFlair(ChatPlayer p, String text, String flairclass, String username) {
|
||||
p.UserName().set(username);
|
||||
p.FlairState().set(FlairStates.Recognised);
|
||||
switch (flairclass) {
|
||||
case "cheater":
|
||||
p.SetFlair(Short.parseShort(text), true);
|
||||
return;
|
||||
case "unknown":
|
||||
try {
|
||||
if (CheckForJoinDate(p)) {
|
||||
if (text.equals("-1")) // If true, only non-presser/can't press; if false, any flair (but we can still detect can't press)
|
||||
p.SetFlair(ChatPlayer.FlairTimeNonPresser);
|
||||
else
|
||||
p.SetFlair(ChatPlayer.FlairTimeNone); // Flair unknown
|
||||
} else {
|
||||
p.SetFlair(ChatPlayer.FlairTimeCantPress);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
p.FlairState().set(FlairStates.Commented); // Flair unknown
|
||||
p.SetFlair(ChatPlayer.FlairTimeNone);
|
||||
TBMCCoreAPI.SendException("Error while checking join date for player " + p.PlayerName() + "!", e);
|
||||
}
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
p.SetFlair(Short.parseShort(text));
|
||||
}
|
||||
|
||||
private static boolean CheckForJoinDate(ChatPlayer mp) throws Exception {
|
||||
return JoinedBefore(mp, 2015, 4, 1);
|
||||
}
|
||||
|
||||
private static boolean JoinedBefore(ChatPlayer mp, int year, int month, int day) throws Exception {
|
||||
URL url = new URL("https://www.reddit.com/u/" + mp.UserName());
|
||||
URLConnection con = url.openConnection();
|
||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||
InputStream in = con.getInputStream();
|
||||
HtmlCleaner cleaner = new HtmlCleaner();
|
||||
TagNode node = cleaner.clean(in);
|
||||
|
||||
node = node.getElementsByAttValue("class", "age", true, true)[0];
|
||||
node = node.getElementsByName("time", false)[0];
|
||||
String joindate = node.getAttributeByName("datetime");
|
||||
SimpleDateFormat parserSDF = new SimpleDateFormat("yyyy-MM-dd");
|
||||
joindate = joindate.split("T")[0];
|
||||
Date date = parserSDF.parse(joindate);
|
||||
return date.before(new Calendar.Builder().setTimeZone(TimeZone.getTimeZone("UTC")).setDate(year, month, day)
|
||||
.build().getTime());
|
||||
}
|
||||
|
||||
public static void ConfirmUserMessage(ChatPlayer mp) {
|
||||
Player p = Bukkit.getPlayer(mp.getUUID());
|
||||
if (mp.FlairState().get().equals(FlairStates.Commented) && p != null)
|
||||
if (mp.UserNames().size() > 1)
|
||||
p.sendMessage(
|
||||
"§9Multiple Reddit users commented your name. You can select with /u accept.§r §6Type /u accept or /u ignore§r");
|
||||
else
|
||||
p.sendMessage("§9A Reddit user commented your name. Is that you?§r §6Type /u accept or /u ignore§r");
|
||||
}
|
||||
|
||||
public static ArrayList<String> AnnounceMessages = new ArrayList<>();
|
||||
public static int AnnounceTime = 15 * 60 * 1000;
|
||||
/**
|
||||
* Names lowercased
|
||||
*/
|
||||
public static Map<String, Color[]> TownColors = new HashMap<>();
|
||||
/**
|
||||
* Names lowercased - nation color gets added to town colors when needed
|
||||
*/
|
||||
public static Map<String, Color> NationColor = new HashMap<>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void LoadFiles() {
|
||||
PluginMain.Instance.getLogger().info("Loading files...");
|
||||
try {
|
||||
File file = new File("TBMC/chatsettings.yml");
|
||||
if (file.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
yc.load(file);
|
||||
PlayerListener.NotificationSound = yc.getString("notificationsound");
|
||||
PlayerListener.NotificationPitch = yc.getDouble("notificationpitch");
|
||||
AnnounceTime = yc.getInt("announcetime", 15 * 60 * 1000);
|
||||
AnnounceMessages.addAll(yc.getStringList("announcements"));
|
||||
PlayerListener.AlphaDeaths = yc.getInt("alphadeaths");
|
||||
val cs = yc.getConfigurationSection("towncolors");
|
||||
if (cs != null)
|
||||
TownColors.putAll(cs.getValues(true).entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, v -> ((List<String>) v.getValue()).stream()
|
||||
.map(Color::valueOf).toArray(Color[]::new))));
|
||||
TownColorCommand.ColorCount = (byte) yc.getInt("towncolorcount", 1);
|
||||
val ncs = yc.getConfigurationSection("nationcolors");
|
||||
if (ncs != null)
|
||||
NationColor.putAll(ncs.getValues(true).entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, v -> Color.valueOf((String) v.getValue()))));
|
||||
PluginMain.Instance.getLogger().info("Loaded files!");
|
||||
} else
|
||||
PluginMain.Instance.getLogger().info("No files to load, first run probably.");
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Error while loading chat files!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveFiles() {
|
||||
PluginMain.Instance.getLogger().info("Saving files...");
|
||||
try {
|
||||
File file = new File("TBMC/chatsettings.yml");
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
yc.set("notificationsound", PlayerListener.NotificationSound);
|
||||
yc.set("notificationpitch", PlayerListener.NotificationPitch);
|
||||
yc.set("announcetime", AnnounceTime);
|
||||
yc.set("announcements", AnnounceMessages);
|
||||
yc.set("alphadeaths", PlayerListener.AlphaDeaths);
|
||||
yc.createSection("towncolors", TownColors.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
|
||||
v -> Arrays.stream(v.getValue()).map(Enum::toString).toArray(String[]::new))));
|
||||
yc.set("towncolorcount", TownColorCommand.ColorCount);
|
||||
yc.createSection("nationcolors", NationColor.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
|
||||
v -> v.getValue().toString())));
|
||||
yc.save(file);
|
||||
PluginMain.Instance.getLogger().info("Saved files!");
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Error while loading chat files!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Permission permission = null;
|
||||
public static Economy economy = null;
|
||||
public static Chat chat = null;
|
||||
|
||||
private boolean setupPermissions() {
|
||||
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager()
|
||||
.getRegistration(net.milkbowl.vault.permission.Permission.class);
|
||||
if (permissionProvider != null) {
|
||||
permission = permissionProvider.getProvider();
|
||||
}
|
||||
return (permission != null);
|
||||
}
|
||||
|
||||
private boolean setupChat() {
|
||||
RegisteredServiceProvider<Chat> chatProvider = getServer().getServicesManager()
|
||||
.getRegistration(net.milkbowl.vault.chat.Chat.class);
|
||||
if (chatProvider != null) {
|
||||
chat = chatProvider.getProvider();
|
||||
}
|
||||
|
||||
return (chat != null);
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager()
|
||||
.getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if (economyProvider != null) {
|
||||
economy = economyProvider.getProvider();
|
||||
}
|
||||
|
||||
return (economy != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the error message for the message sender if they can't send it and the score
|
||||
*/
|
||||
private static RecipientTestResult checkTownNationChat(CommandSender sender, boolean nationchat) {
|
||||
if (!(sender instanceof Player))
|
||||
return new RecipientTestResult("§cYou are not a player!");
|
||||
Resident resident = PluginMain.TU.getResidentMap().get(sender.getName().toLowerCase());
|
||||
RecipientTestResult result = checkTownNationChatInternal(sender, nationchat, resident);
|
||||
if (result.errormessage != null && resident != null && resident.getModes().contains("spy")) // Only use spy if they wouldn't see it
|
||||
result = new RecipientTestResult(1000, "allspies"); // There won't be more than a thousand towns/nations probably
|
||||
return result;
|
||||
}
|
||||
|
||||
private static RecipientTestResult checkTownNationChatInternal(CommandSender sender, boolean nationchat,
|
||||
Resident resident) {
|
||||
try {
|
||||
/*
|
||||
* p.sendMessage(String.format("[SPY-%s] - %s: %s", channel.DisplayName, ((Player) sender).getDisplayName(), message));
|
||||
*/
|
||||
Town town = null;
|
||||
if (resident != null && resident.hasTown())
|
||||
town = resident.getTown();
|
||||
if (town == null)
|
||||
return new RecipientTestResult("You aren't in a town.");
|
||||
Nation nation = null;
|
||||
int index;
|
||||
if (nationchat) {
|
||||
if (town.hasNation())
|
||||
nation = town.getNation();
|
||||
if (nation == null)
|
||||
return new RecipientTestResult("Your town isn't in a nation.");
|
||||
index = PluginMain.Nations.indexOf(nation);
|
||||
if (index < 0) {
|
||||
PluginMain.Nations.add(nation);
|
||||
index = PluginMain.Nations.size() - 1;
|
||||
}
|
||||
} else {
|
||||
index = PluginMain.Towns.indexOf(town);
|
||||
if (index < 0) {
|
||||
PluginMain.Towns.add(town);
|
||||
index = PluginMain.Towns.size() - 1;
|
||||
}
|
||||
}
|
||||
return new RecipientTestResult(index, nationchat ? nation.getName() : town.getName());
|
||||
} catch (NotRegisteredException e) {
|
||||
return new RecipientTestResult("You (probably) aren't knwon by Towny! (Not in a town)");
|
||||
}
|
||||
}
|
||||
}
|
||||
package buttondevteam.chat;
|
||||
|
||||
import buttondevteam.chat.commands.MWikiCommand;
|
||||
import buttondevteam.chat.commands.MeCommand;
|
||||
import buttondevteam.chat.commands.SnapCommand;
|
||||
import buttondevteam.chat.commands.ucmds.HelpCommand;
|
||||
import buttondevteam.chat.commands.ucmds.HistoryCommand;
|
||||
import buttondevteam.chat.commands.ucmds.InfoCommand;
|
||||
import buttondevteam.chat.commands.ucmds.ReloadCommand;
|
||||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||
import buttondevteam.chat.components.announce.AnnouncerComponent;
|
||||
import buttondevteam.chat.components.appendext.AppendTextComponent;
|
||||
import buttondevteam.chat.components.flair.FlairComponent;
|
||||
import buttondevteam.chat.components.formatter.FormatterComponent;
|
||||
import buttondevteam.chat.components.fun.FunComponent;
|
||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||
import buttondevteam.chat.components.towny.TownyComponent;
|
||||
import buttondevteam.chat.listener.PlayerJoinLeaveListener;
|
||||
import buttondevteam.chat.listener.PlayerListener;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.architecture.ButtonPlugin;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.config.IConfigData;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15.
|
||||
public static PluginMain Instance;
|
||||
public static ConsoleCommandSender Console;
|
||||
|
||||
/**
|
||||
* If enabled, stores and displays the last 10 messages the player can see (public, their town chat etc.)
|
||||
* Can be used with the Discord plugin so players can see some of the conversation they missed that's visible on Discord anyways.
|
||||
*/
|
||||
public IConfigData<Boolean> storeChatHistory = getIConfig().getData("storeChatHistory", true);
|
||||
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void pluginEnable() {
|
||||
Instance = this;
|
||||
PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
|
||||
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this);
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerJoinLeaveListener(), this);
|
||||
Console = this.getServer().getConsoleSender();
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Towny"))
|
||||
Component.registerComponent(this, new TownyComponent());
|
||||
|
||||
TBMCChatAPI.registerChatChannel(new Channel("§7RP§f", Color.Gray, "rp", null)); //Since it's null, it's recognised as global
|
||||
|
||||
if (!setupPermissions())
|
||||
TBMCCoreAPI.SendException("We're in trouble", new Exception("Failed to set up permissions!"), this);
|
||||
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("Towny"))
|
||||
Component.registerComponent(this, new TownColorComponent());
|
||||
Component.registerComponent(this, new FlairComponent()); //The original purpose of this plugin
|
||||
Component.registerComponent(this, new AnnouncerComponent());
|
||||
Component.registerComponent(this, new FunComponent());
|
||||
Component.registerComponent(this, new AppendTextComponent());
|
||||
Component.registerComponent(this, new FormatterComponent());
|
||||
registerCommand(new DebugCommand());
|
||||
registerCommand(new HelpCommand());
|
||||
registerCommand(new HistoryCommand());
|
||||
registerCommand(new InfoCommand());
|
||||
registerCommand(new MWikiCommand());
|
||||
registerCommand(new ReloadCommand());
|
||||
registerCommand(new SnapCommand());
|
||||
registerCommand(new MeCommand());
|
||||
}
|
||||
|
||||
public static Essentials essentials = null;
|
||||
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void pluginDisable() {
|
||||
}
|
||||
|
||||
public static Permission permission = null;
|
||||
|
||||
private boolean setupPermissions() {
|
||||
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager()
|
||||
.getRegistration(net.milkbowl.vault.permission.Permission.class);
|
||||
if (permissionProvider != null) {
|
||||
permission = permissionProvider.getProvider();
|
||||
}
|
||||
return (permission != null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,141 @@
|
|||
package buttondevteam.chat;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||
import buttondevteam.core.MainPlugin;
|
||||
import buttondevteam.lib.TBMCChatEvent;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import lombok.val;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import buttondevteam.lib.TBMCChatEvent;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.minecraft.server.v1_12_R1.EntityHuman.EnumChatVisibility;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@UtilityClass
|
||||
public class VanillaUtils {
|
||||
public int getMCScoreIfChatOn(Player p, TBMCChatEvent e) {
|
||||
if (!(p instanceof CraftPlayer) || ((CraftPlayer) p).getHandle().getChatFlags() == EnumChatVisibility.FULL) // Only send if client allows chat
|
||||
return e.getMCScore(p);
|
||||
else
|
||||
return -1;
|
||||
public String getGroupIfChatOn(Player p, TBMCChatEvent e) {
|
||||
try {
|
||||
if (!isChatOn(p)) // Only send if client allows chat
|
||||
return null;
|
||||
} catch (NoClassDefFoundError ex) {
|
||||
MainPlugin.getInstance().getLogger().warning("Compatibility error, can't check if the chat is hidden by the player.");
|
||||
}
|
||||
return e.getGroupID(ChromaGamerBase.getFromSender(p));
|
||||
}
|
||||
|
||||
private Predicate<Player> isChatOn;
|
||||
|
||||
private boolean isChatOn(Player p) {
|
||||
try {
|
||||
if (isChatOn == null) {
|
||||
val cl = p.getClass();
|
||||
if (notCraftPlayer(cl)) return true; // p instanceof CraftPlayer
|
||||
val hm = cl.getMethod("getHandle");
|
||||
val handle = hm.invoke(p); //p.getHandle()
|
||||
val vpcl = handle.getClass();
|
||||
val gcfm = vpcl.getMethod("getChatFlags");
|
||||
Class<?> encl;
|
||||
try {
|
||||
encl = Class.forName(handle.getClass().getPackage().getName() + ".EnumChatVisibility");
|
||||
} catch (ClassNotFoundException e) {
|
||||
encl = Class.forName(handle.getClass().getPackage().getName() + ".EntityHuman$EnumChatVisibility");
|
||||
}
|
||||
val ff = encl.getField("FULL");
|
||||
val full = ff.get(null); // EnumChatVisibility.FULL
|
||||
isChatOn = pl -> {
|
||||
try {
|
||||
if (notCraftPlayer(pl.getClass())) return true; //Need to check each time
|
||||
val ph = hm.invoke(pl); //pl.getHandle()
|
||||
val flags = gcfm.invoke(ph); //handle.getChatFlags()
|
||||
return flags == full;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
return isChatOn.test(p);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*private String version;
|
||||
|
||||
public short getMCVersion() {
|
||||
if (version != null) return version;
|
||||
val v = ChatUtils.coolSubstring(Bukkit.getServer().getVersion().getClass().getPackage().getName(),
|
||||
"org.bukkit.craftbukkit.v", "_R1").orElse("1_8").replace("_", "");
|
||||
return Short.parseShort(v);
|
||||
}*/
|
||||
|
||||
private BiPredicate<Player, String> tellRaw;
|
||||
|
||||
public boolean tellRaw(Player p, String json) {
|
||||
try {
|
||||
if (tellRaw == null) {
|
||||
val pcl = p.getClass();
|
||||
if (notCraftPlayer(pcl)) return false;
|
||||
val hm = pcl.getMethod("getHandle");
|
||||
val handle = hm.invoke(p);
|
||||
var nmsOrChat = handle.getClass().getPackage().getName();
|
||||
if (!nmsOrChat.contains(".v1_"))
|
||||
nmsOrChat = "net.minecraft.network.chat";
|
||||
val chatcompcl = Class.forName(nmsOrChat + ".IChatBaseComponent");
|
||||
//val chatcomarrcl = Class.forName("[L" + chatcompcl.getName() + ";");
|
||||
val chatcomparr = Array.newInstance(chatcompcl, 1);
|
||||
final Method sendmsg;
|
||||
{
|
||||
Method sendmsg1;
|
||||
try {
|
||||
sendmsg1 = handle.getClass().getMethod("sendMessage", UUID.class, chatcomparr.getClass());
|
||||
} catch (NoSuchMethodException e) {
|
||||
sendmsg1 = handle.getClass().getMethod("sendMessage", chatcomparr.getClass());
|
||||
}
|
||||
sendmsg = sendmsg1;
|
||||
}
|
||||
|
||||
/*val ccucl = Class.forName(nms + ".ChatComponentUtils");
|
||||
val iclcl = Class.forName(nms + ".ICommandListener");
|
||||
val encl = Class.forName(nms + ".Entity");
|
||||
val ffdm = ccucl.getMethod("filterForDisplay", iclcl, chatcompcl, encl);*/
|
||||
|
||||
val cscl = Class.forName(chatcompcl.getName() + "$ChatSerializer");
|
||||
val am = cscl.getMethod("a", String.class);
|
||||
|
||||
tellRaw = (pl, jsonStr) -> {
|
||||
if (notCraftPlayer(pl.getClass())) return false;
|
||||
try {
|
||||
val hhandle = hm.invoke(pl);
|
||||
val deserialized = am.invoke(null, jsonStr);
|
||||
//val filtered = ffdm.invoke(null, hhandle, deserialized, hhandle);
|
||||
Array.set(chatcomparr, 0, deserialized);
|
||||
if (sendmsg.getParameterCount() == 2)
|
||||
sendmsg.invoke(hhandle, null, chatcomparr); //
|
||||
else
|
||||
sendmsg.invoke(hhandle, chatcomparr);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*((CraftPlayer) p).getHandle().sendMessage(ChatComponentUtils
|
||||
.filterForDisplay(((CraftPlayer) p).getHandle(),
|
||||
IChatBaseComponent.ChatSerializer.a(json), ((CraftPlayer) p).getHandle()));*/
|
||||
return tellRaw.test(p, json);
|
||||
} catch (Exception e) {
|
||||
PluginMain.Instance.getLogger().warning("Could not use tellRaw: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean notCraftPlayer(Class<?> cl) {
|
||||
return !cl.getSimpleName().contains("CraftPlayer");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
package buttondevteam.chat.commands;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.PlayerCommandBase;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
|
||||
@CommandClass(modOnly = false)
|
||||
public final class ChatonlyCommand extends PlayerCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Chat-only mode ----", //
|
||||
"This mode makes you invincible but unable to move, teleport or interact with the world in any way", //
|
||||
"It was designed for chat clients", //
|
||||
"Once enabled, the only way of disabling it is by relogging to the server" //
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(Player player, String alias, String[] args) {
|
||||
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
p.ChatOnly = true;
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
player.sendMessage("§bChat-only mode enabled. You are now invincible.");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
package buttondevteam.chat.commands;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandClass
|
||||
public class FTopCommand extends TBMCCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String arg0) {
|
||||
return new String[]{ //
|
||||
"§6---- F Top ----", //
|
||||
"Shows the respect leaderboard" //
|
||||
};
|
||||
}
|
||||
|
||||
private final File playerdir = new File(TBMCPlayerBase.TBMC_PLAYERS_DIR);
|
||||
private ChatPlayer[] cached;
|
||||
private long lastcache = 0;
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender arg0, String arg1, String[] arg2) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
|
||||
if (cached == null || lastcache < System.nanoTime() - 60000000000L) { // 1m - (no guarantees of nanoTime's relation to 0, so we need the null check too)
|
||||
cached = Arrays.stream(Objects.requireNonNull(playerdir.listFiles())).sequential()
|
||||
.filter(f -> f.getName().length() > 4)
|
||||
.map(f -> {
|
||||
try {
|
||||
return TBMCPlayerBase.getPlayer(
|
||||
UUID.fromString(f.getName().substring(0, f.getName().length() - 4)), ChatPlayer.class);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.sorted((cp1, cp2) -> Double.compare(cp2.getF(), cp1.getF()))
|
||||
.toArray(ChatPlayer[]::new); // TODO: Properly implement getting all players
|
||||
lastcache = System.nanoTime();
|
||||
}
|
||||
int i;
|
||||
try {
|
||||
i = arg2.length > 0 ? Integer.parseInt(arg2[0]) : 1;
|
||||
if (i < 1)
|
||||
i = 1; //i=1
|
||||
} catch (Exception e) {
|
||||
i = 1;
|
||||
}
|
||||
val ai = new AtomicInteger();
|
||||
arg0.sendMessage("§6---- Top Fs ----");
|
||||
arg0.sendMessage(Arrays.stream(cached).skip((i - 1) * 10).limit(i * 10)
|
||||
.map(cp -> String.format("%d. %s - %f.2", ai.incrementAndGet(), cp.PlayerName().get(), cp.getF()))
|
||||
.collect(Collectors.joining("\n")));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +1,33 @@
|
|||
package buttondevteam.chat.commands;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
|
||||
@CommandClass(modOnly = false)
|
||||
public class MWikiCommand extends TBMCCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Minecraft Wiki linker ----", //
|
||||
"Use without parameters to get a link to the wiki", //
|
||||
"You can also search the wiki, for example:", //
|
||||
" /" + alias + " beacon - Provides a link that redirects to the beacon's wiki page" //
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
String query = "";
|
||||
for (int i = 0; i < args.length; i++)
|
||||
query += args[i] + " ";
|
||||
query = query.trim();
|
||||
try {
|
||||
if (query.length() == 0)
|
||||
sender.sendMessage(new String[] { "§bMinecraft Wiki link: http://minecraft.gamepedia.com/",
|
||||
"You can also search on it using /mwiki <query>" });
|
||||
else
|
||||
sender.sendMessage("§bMinecraft Wiki link: http://minecraft.gamepedia.com/index.php?search="
|
||||
+ URLEncoder.encode(query, "UTF-8") + "&title=Special%3ASearch&go=Go");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
package buttondevteam.chat.commands;
|
||||
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.ICommand2MC;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
@CommandClass(modOnly = false, helpText = {
|
||||
"Minecraft Wiki linker", //
|
||||
"Use without parameters to get a link to the wiki", //
|
||||
"You can also search the wiki, for example:", //
|
||||
" /mwiki beacon - Provides a link that redirects to the beacon's wiki page" //
|
||||
})
|
||||
public class MWikiCommand extends ICommand2MC {
|
||||
@Command2.Subcommand
|
||||
public boolean def(CommandSender sender, @Command2.OptionalArg @Command2.TextArg String query) {
|
||||
try {
|
||||
if (query == null)
|
||||
sender.sendMessage(new String[]{"§bMinecraft Wiki link: http://minecraft.gamepedia.com/",
|
||||
"You can also search on it using /mwiki <query>"});
|
||||
else
|
||||
sender.sendMessage("§bMinecraft Wiki link: http://minecraft.gamepedia.com/index.php?search="
|
||||
+ URLEncoder.encode(query, "UTF-8") + "&title=Special%3ASearch&go=Go");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
15
src/main/java/buttondevteam/chat/commands/MeCommand.java
Normal file
15
src/main/java/buttondevteam/chat/commands/MeCommand.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package buttondevteam.chat.commands;
|
||||
|
||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||
import buttondevteam.lib.chat.*;
|
||||
|
||||
@CommandClass(helpText = {
|
||||
"Me",
|
||||
"Displays a message starting with your name in your current channel."
|
||||
})
|
||||
public class MeCommand extends ICommand2MC {
|
||||
@Command2.Subcommand
|
||||
public void def(Command2MCSender sender, @Command2.TextArg String message) {
|
||||
TBMCChatAPI.SendSystemMessage(sender.getChannel(), sender.getChannel().getRTR(sender.getPermCheck()), "§5* " + sender.getSender().getName() + " " + message, TBMCSystemChatEvent.BroadcastTarget.ALL);
|
||||
}
|
||||
}
|
30
src/main/java/buttondevteam/chat/commands/SnapCommand.java
Normal file
30
src/main/java/buttondevteam/chat/commands/SnapCommand.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package buttondevteam.chat.commands;
|
||||
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.ICommand2MC;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
@CommandClass(modOnly = true, helpText = {
|
||||
"Snap",
|
||||
"Perfectly balanced as all things should be."
|
||||
})
|
||||
public class SnapCommand extends ICommand2MC {
|
||||
@Command2.Subcommand
|
||||
public void def(CommandSender sender) {
|
||||
val pls = new ArrayList<>(Bukkit.getOnlinePlayers());
|
||||
int target = pls.size() / 2;
|
||||
Random rand = new Random();
|
||||
//noinspection SuspiciousMethodCalls
|
||||
if (pls.remove(sender) && target > 0)
|
||||
target--; //The sender isn't kicked, so kick someone else
|
||||
while (pls.size() > target)
|
||||
pls.remove(rand.nextInt(pls.size())).kickPlayer("You were saved by Thanos.");
|
||||
sender.sendMessage(target + " grateful players remain.");
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package buttondevteam.chat.commands;
|
||||
|
||||
import buttondevteam.lib.TBMCChatEventBase;
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
import lombok.Data;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@CommandClass(modOnly = false)
|
||||
public final class UnlolCommand extends TBMCCommandBase {
|
||||
|
||||
public static Map<Channel, LastlolData> Lastlol = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Unlol/unlaugh ----",
|
||||
"This command is based on a joke between NorbiPeti and Ghostise",
|
||||
"It will make the last person saying one of the recognized laugh strings blind for a few seconds",
|
||||
"Note that you can only unlaugh laughs that weren't unlaughed before" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
LastlolData lol = Lastlol.values().stream().filter(lld -> lld.Chatevent.shouldSendTo(sender))
|
||||
.max(Comparator.comparingLong(lld -> lld.Loltime)).orElse(null);
|
||||
if (lol == null)
|
||||
return true;
|
||||
if (lol.Lolowner instanceof Player)
|
||||
((Player) lol.Lolowner)
|
||||
.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 2 * 20, 5, false, false));
|
||||
String msg = (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName())
|
||||
+ (lol.Lolornot ? " unlolled " : " unlaughed ")
|
||||
+ (lol.Lolowner instanceof Player ? ((Player) lol.Lolowner).getDisplayName() : lol.Lolowner.getName());
|
||||
Bukkit.broadcastMessage(msg);
|
||||
Lastlol.remove(lol.Chatevent.getChannel());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class LastlolData {
|
||||
private boolean Lolornot;
|
||||
private final CommandSender Lolowner;
|
||||
private final TBMCChatEventBase Chatevent;
|
||||
private final long Loltime;
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package buttondevteam.chat.commands.appendtext;
|
||||
|
||||
import buttondevteam.lib.chat.ChatMessage;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@CommandClass(modOnly = false, excludeFromPath = true)
|
||||
public abstract class AppendTextCommandBase extends TBMCCommandBase {
|
||||
|
||||
public abstract String[] GetHelpText(String alias);
|
||||
|
||||
public abstract String GetAppendedText();
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
for (String arg : args) msg.append(arg).append(" ");
|
||||
msg.append(GetAppendedText());
|
||||
TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender,
|
||||
ChromaGamerBase.getFromSender(sender), msg.toString())
|
||||
.fromCommand(true).build());
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package buttondevteam.chat.commands.appendtext;
|
||||
|
||||
public final class LennyCommand extends AppendTextCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Lenny ----", //
|
||||
"This command appends a Lenny face after your message", //
|
||||
"Or just sends one", //
|
||||
"Use either /" + alias + " <message> or just /" + alias }; //
|
||||
}
|
||||
|
||||
@Override
|
||||
public String GetAppendedText() {
|
||||
return "( ͡° ͜ʖ ͡°)";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package buttondevteam.chat.commands.appendtext;
|
||||
|
||||
public final class ShrugCommand extends AppendTextCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Shrug ----", //
|
||||
"This command appends a shrug after your message", //
|
||||
"Or just makes you shrug", //
|
||||
"Use either /" + alias + " <message> or just /" + alias }; //
|
||||
}
|
||||
|
||||
@Override
|
||||
public String GetAppendedText() {
|
||||
return "¯\\\\\\_(ツ)\\_/¯";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package buttondevteam.chat.commands.appendtext;
|
||||
|
||||
public final class TableflipCommand extends AppendTextCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Tableflip ----", //
|
||||
"This command appends a tableflip after your message", //
|
||||
"Or just makes you tableflip", //
|
||||
"Use either /" + alias + " <message> or just /" + alias };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String GetAppendedText() {
|
||||
return "(╯°□°)╯︵ ┻━┻";
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package buttondevteam.chat.commands.appendtext;
|
||||
|
||||
public final class UnflipCommand extends AppendTextCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Unflip ----", //
|
||||
"This command appends an unflip after your message", //
|
||||
"Or just unflips as you", //
|
||||
"Use either /" + alias + " <message> or just /" + alias };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String GetAppendedText() {
|
||||
return "┬─┬ ノ( ゜-゜ノ)";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package buttondevteam.chat.commands.appendtext;
|
||||
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
|
||||
@CommandClass(modOnly = false)
|
||||
public class WaitWhatCommand extends AppendTextCommandBase {
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { //
|
||||
"§6--- Wait what ----", //
|
||||
"Wait what" //
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String GetAppendedText() {
|
||||
return "wait what";
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import java.util.Timer;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.FlairStates;
|
||||
import buttondevteam.chat.PlayerJoinTimerTask;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
|
||||
@CommandClass(modOnly = false)
|
||||
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||
public class AcceptCommand extends UCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Accept flair ----", //
|
||||
"Accepts a flair from Reddit", //
|
||||
"Use /u accept <username> if you commented from multiple accounts" //
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
final Player player = (Player) sender;
|
||||
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
if (args.length < 1 && p.UserNames().size() > 1) {
|
||||
player.sendMessage("§9Multiple users commented your name. §bPlease pick one using /u accept <username>");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("§6Usernames:");
|
||||
for (String username : p.UserNames())
|
||||
sb.append(" ").append(username);
|
||||
player.sendMessage(sb.toString());
|
||||
return true;
|
||||
}
|
||||
if (p.FlairState().get().equals(FlairStates.NoComment) || p.UserNames().size() == 0) {
|
||||
player.sendMessage("§cError: You need to write your username to the reddit thread at /r/ChromaGamers§r");
|
||||
return true;
|
||||
}
|
||||
if (args.length > 0 && !p.UserNames().contains(args[0])) {
|
||||
player.sendMessage("§cError: Unknown name: " + args[0] + "§r");
|
||||
return true;
|
||||
}
|
||||
if (p.Working) {
|
||||
player.sendMessage("§cError: Something is already in progress.§r");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((args.length > 0 ? args[0] : p.UserNames().get(0)).equals(p.UserName().get())) {
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
return true;
|
||||
}
|
||||
if (args.length > 0)
|
||||
p.UserName().set(args[0]);
|
||||
else
|
||||
p.UserName().set(p.UserNames().get(0));
|
||||
|
||||
player.sendMessage("§bObtaining flair...");
|
||||
p.Working = true;
|
||||
Timer timer = new Timer();
|
||||
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
PluginMain.Instance.DownloadFlair(mp);
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException(
|
||||
"An error occured while downloading flair for " + player.getCustomName() + "!", e);
|
||||
player.sendMessage(
|
||||
"Sorry, but an error occured while trying to get your flair. Please contact a mod.");
|
||||
mp.Working = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mp.FlairState().get().equals(FlairStates.Commented)) {
|
||||
player.sendMessage(
|
||||
"Sorry, but your flair isn't recorded. Please ask an admin to set it for you. Also, prepare a comment on /r/thebutton, if possible.");
|
||||
mp.Working = false;
|
||||
return;
|
||||
}
|
||||
String flair = mp.GetFormattedFlair();
|
||||
mp.FlairState().set(FlairStates.Accepted);
|
||||
PluginMain.ConfirmUserMessage(mp);
|
||||
player.sendMessage("§bYour flair has been set:§r " + flair);
|
||||
mp.Working = false;
|
||||
}
|
||||
};
|
||||
tt.mp = p;
|
||||
timer.schedule(tt, 20);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.chat.*;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
|
||||
@CommandClass(modOnly = false)
|
||||
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||
public class CCommand extends UCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Rainbow mode ----", "This command allows you to talk in rainbow colors",
|
||||
"You need to be a donator or a mod to use this command" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
Player player = (Player) sender;
|
||||
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
if (args.length < 1) {
|
||||
if (PluginMain.permission.has(player, "tbmc.rainbow")) {
|
||||
p.RainbowPresserColorMode = !p.RainbowPresserColorMode;
|
||||
p.OtherColorMode = null;
|
||||
if (p.RainbowPresserColorMode)
|
||||
player.sendMessage("§eRainbow colors §aenabled.");
|
||||
else
|
||||
player.sendMessage("§eRainbow colors §cdisabled.");
|
||||
} else {
|
||||
player.sendMessage("§cYou don't have permission for this command. Donate to get it!");
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (PluginMain.permission.has(player, "tbmc.admin")) {
|
||||
p.RainbowPresserColorMode = false;
|
||||
p.OtherColorMode = null;
|
||||
try {
|
||||
p.OtherColorMode = Color.valueOf(args[0].toLowerCase());
|
||||
} catch (Exception e) {
|
||||
player.sendMessage("§cUnknown message color: " + args[0]);
|
||||
player.sendMessage("§cUse color names, like blue, or dark_aqua");
|
||||
}
|
||||
if (p.OtherColorMode != null)
|
||||
player.sendMessage(String.format("§eMessage color set to %s", p.OtherColorMode));
|
||||
else
|
||||
player.sendMessage("§eMessage color reset.");
|
||||
} else {
|
||||
player.sendMessage("§cYou don't have permission for this command.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,84 +1,63 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
|
||||
@CommandClass(modOnly = false)
|
||||
public final class HelpCommand extends UCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Help ----", "Prints out help messages for the TBMC plugins" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(new String[] { "§6---- TBMC Help ----", "Do /u help <topic> for more info",
|
||||
"Do /u help <commandname> [subcommands] for more info about a command", "Topics:",
|
||||
"commands: See all the commands from this plugin",
|
||||
"chat: Shows some info about custom chat features", "colors: Shows Minecraft color codes" });
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("chat"))
|
||||
sender.sendMessage(new String[] { "§6---- Chat features ----",
|
||||
"- [g] Channel identifier: Click it to copy message", "-- [g]: Global chat (/g)",
|
||||
"-- [TC] Town chat (/tc)", "-- [NC] Nation chat (/nc)",
|
||||
"- Playernames: Hover over them to get some player info",
|
||||
"-- Respect: This is the number of paid respects divided by eliglble deaths. This is a reference to CoD:AW's \"Press F to pay respects\"" });
|
||||
else if (args[0].equalsIgnoreCase("commands")) {
|
||||
ArrayList<String> text = new ArrayList<String>();
|
||||
text.add("§6---- Command list ----");
|
||||
for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values())
|
||||
if (!cmd.getClass().getAnnotation(CommandClass.class).modOnly() || PluginMain.permission.has(sender, "tbmc.admin"))
|
||||
if (!cmd.isPlayerOnly() || sender instanceof Player)
|
||||
if (!cmd.GetCommandPath().contains(" "))
|
||||
text.add("/" + cmd.GetCommandPath());
|
||||
else {
|
||||
final String topcmd = cmd.GetCommandPath().substring(0, cmd.GetCommandPath().indexOf(' '));
|
||||
if (!text.contains("/" + topcmd))
|
||||
text.add("/" + topcmd);
|
||||
}
|
||||
sender.sendMessage(text.toArray(new String[text.size()]));
|
||||
} else if (args[0].equalsIgnoreCase("colors")) {
|
||||
sender.sendMessage(new String[] { "§6---- Chat colors/formats ----", //
|
||||
"Tellraw name - Code | Tellraw name - Code", //
|
||||
"§0black - &0 | §1dark_blue - &1", //
|
||||
"§2dark_green - &2 | §3dark_aqua - &3", //
|
||||
"§4dark_red - &4 | §5dark_purple - &5", //
|
||||
"§6gold - &6 | §7gray - &7", //
|
||||
"§8dark_gray - &8 | §9blue - &9", //
|
||||
"§agreen - &a | §baqua - &b", //
|
||||
"§cred - &c | §dlight_purple - &d", //
|
||||
"§eyellow - &e | §fwhite - &f", //
|
||||
"§rreset - &r | §kk§robfuscated - &k", //
|
||||
"§lbold - &l | §mstrikethrough - &m", //
|
||||
"§nunderline - &n | §oitalic - &o", //
|
||||
"The format codes in tellraw should be used like \"italic\":\"true\"" }); //
|
||||
} else {
|
||||
String path = args[0];
|
||||
for (int i = 1; i < args.length; i++)
|
||||
path += " " + args[i];
|
||||
TBMCCommandBase cmd = TBMCChatAPI.GetCommands().get(path);
|
||||
if (cmd == null) {
|
||||
String[] subcmds = TBMCChatAPI.GetSubCommands(path, sender);
|
||||
if (subcmds.length > 0)
|
||||
sender.sendMessage(subcmds);
|
||||
else
|
||||
sender.sendMessage(
|
||||
new String[] { "§cError: Command not found or you don't have permission for it: " + path,
|
||||
"Usage example: /u accept --> /u help u accept" });
|
||||
} else
|
||||
sender.sendMessage(cmd.GetHelpText(args[0]));
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.CustomTabComplete;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@CommandClass(modOnly = false, helpText = {
|
||||
"Help",
|
||||
"Prints out help messages for the TBMC plugins"
|
||||
})
|
||||
public final class HelpCommand extends UCommandBase {
|
||||
@Command2.Subcommand
|
||||
public boolean def(CommandSender sender, @Command2.TextArg @Command2.OptionalArg
|
||||
@CustomTabComplete({"commands", "chat", "colors"}) String topicOrCommand) {
|
||||
if (topicOrCommand == null) {
|
||||
sender.sendMessage(new String[]{
|
||||
"§6---- Chroma Help ----",
|
||||
"Do /u help <topic> for more info",
|
||||
"Do /u help <commandname> [subcommands] for more info about a command",
|
||||
"Topics:",
|
||||
"commands: See all the commands from this plugin",
|
||||
"chat: Shows some info about custom chat features",
|
||||
"colors: Shows Minecraft color codes"
|
||||
});
|
||||
return true;
|
||||
}
|
||||
if (topicOrCommand.equalsIgnoreCase("chat"))
|
||||
sender.sendMessage(new String[]{"§6---- Chat features ----",
|
||||
"- [g] Channel identifier: Click it to copy message", "-- [g] Global chat (/g)",
|
||||
"-- [TC] Town chat (/tc)", "-- [NC] Nation chat (/nc)",
|
||||
"- Playernames: Hover over them to get some player info",
|
||||
"-- Respect: This is the number of paid respects divided by eligible deaths. This is a reference to CoD:AW's \"Press F to pay respects\""});
|
||||
else if (topicOrCommand.equalsIgnoreCase("commands")) {
|
||||
sender.sendMessage(getManager().getCommandsText());
|
||||
} else if (topicOrCommand.equalsIgnoreCase("colors")) {
|
||||
sender.sendMessage(new String[]{"§6---- Chat colors/formats ----", //
|
||||
"Tellraw name - Code | Tellraw name - Code", //
|
||||
"§0black - &0§r | §1dark_blue - &1§r", //
|
||||
"§2dark_green - &2§r | §3dark_aqua - &3§r", //
|
||||
"§4dark_red - &4§r | §5dark_purple - &5§r", //
|
||||
"§6gold - &6§r | §7gray - &7§r", //
|
||||
"§8dark_gray - &8§r | §9blue - &9§r", //
|
||||
"§agreen - &a§r | §baqua - &b§r", //
|
||||
"§cred - &c§r | §dlight_purple - &d§r", //
|
||||
"§eyellow - &e§r | §fwhite - &f§r", //
|
||||
"§rreset - &r§r | §kk§robfuscated - &k§r", //
|
||||
"§lbold - &l§r | §mstrikethrough - &m§r", //
|
||||
"§nunderline - &n§r | §oitalic - &o§r", //
|
||||
"The format codes in tellraw should be used like \"italic\":\"true\""}); //
|
||||
} else {
|
||||
String[] text = getManager().getCommandNode(topicOrCommand).getData().getHelpText(sender); // TODO: This only works for the main command, not subcommands
|
||||
if (text == null) // TODO: Null check for command node
|
||||
sender.sendMessage(
|
||||
new String[]{"§cError: Command not found: " + topicOrCommand,
|
||||
"Usage example: /u accept --> /u help u accept"});
|
||||
else
|
||||
sender.sendMessage(text);
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,83 +1,88 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.lib.chat.ChatMessage;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.var;
|
||||
import buttondevteam.lib.chat.CustomTabCompleteMethod;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import lombok.val;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@CommandClass
|
||||
@CommandClass(helpText = {
|
||||
"Chat History", //
|
||||
"Returns the last 10 messages the player can see." //
|
||||
})
|
||||
public class HistoryCommand extends UCommandBase {
|
||||
/**
|
||||
* Key: ChannelID_groupID
|
||||
*/
|
||||
private static HashMap<String, LinkedList<HistoryEntry>> messages = new HashMap<>();
|
||||
private static final HashMap<String, LinkedList<HistoryEntry>> messages = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[]{ //
|
||||
"§6--- Chat History ----", //
|
||||
"Returns the last 10 messages the player can see." //
|
||||
};
|
||||
@Command2.Subcommand
|
||||
public boolean def(ChromaGamerBase sender, @Command2.OptionalArg String channel) {
|
||||
return showHistory(sender, channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
return showHistory(sender, alias, args, this);
|
||||
}
|
||||
|
||||
public static boolean showHistory(CommandSender sender, String alias, String[] args, @Nullable HistoryCommand hc) {
|
||||
Function<Channel, LinkedList<HistoryEntry>> getThem = ch -> messages.get(ch.ID + "_" + ch.getGroupID(sender)); //If can't see, groupID is null, and that shouldn't be in the map
|
||||
public static boolean showHistory(ChromaGamerBase sender, String channel) {
|
||||
if (!PluginMain.Instance.storeChatHistory.get()) {
|
||||
sender.sendMessage("§6Chat history is disabled");
|
||||
return true;
|
||||
}
|
||||
Function<Channel, LinkedList<HistoryEntry>> getThem = ch -> messages.get(ch.getIdentifier() + "_" + ch.getGroupID(sender)); //If can't see, groupID is null, and that shouldn't be in the map
|
||||
sender.sendMessage("§6---- Chat History ----");
|
||||
Stream<Channel> stream;
|
||||
if (args.length == 0) {
|
||||
stream = Channel.getChannels().stream();
|
||||
if (channel == null) {
|
||||
stream = Channel.getChannels();
|
||||
} else {
|
||||
Optional<Channel> och = Channel.getChannels().stream().filter(chan -> chan.ID.equalsIgnoreCase(args[0])).findAny();
|
||||
Optional<Channel> och = Channel.getChannels().filter(chan -> chan.getIdentifier().equalsIgnoreCase(channel)).findAny();
|
||||
if (!och.isPresent()) {
|
||||
sender.sendMessage("§cChannel not found. Use the ID, for example: /" + (hc == null ? "u history" : hc.GetCommandPath()) + " ooc");
|
||||
sender.sendMessage("§cChannel not found. Use the ID, for example: /u history g");
|
||||
return true;
|
||||
}
|
||||
stream = Stream.of(och.get());
|
||||
}
|
||||
AtomicBoolean sent = new AtomicBoolean();
|
||||
val arr = stream.map(getThem).filter(Objects::nonNull).flatMap(Collection::stream)
|
||||
synchronized (messages) {
|
||||
val arr = stream.map(getThem).filter(Objects::nonNull).flatMap(Collection::stream)
|
||||
.sorted(Comparator.comparingLong(he -> he.timestamp)).toArray(HistoryEntry[]::new);
|
||||
for (int i = Math.max(0, arr.length - 10); i < arr.length; i++) {
|
||||
HistoryEntry e = arr[i];
|
||||
val cm = e.chatMessage;
|
||||
sender.sendMessage("[" + e.channel.DisplayName + "] " + cm.getSender().getName() + ": " + cm.getMessage());
|
||||
sent.set(true);
|
||||
for (int i = Math.max(0, arr.length - 10); i < arr.length; i++) {
|
||||
HistoryEntry e = arr[i];
|
||||
val cm = e.chatMessage;
|
||||
sender.sendMessage("[" + e.channel.displayName.get() + "] " + cm.getUser().getName() + ": " + cm.getMessage());
|
||||
sent.set(true);
|
||||
}
|
||||
}
|
||||
if (!sent.get())
|
||||
sender.sendMessage("No messages can be found.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
private static class HistoryEntry {
|
||||
/**
|
||||
* System.nanoTime()
|
||||
*/
|
||||
private final long timestamp;
|
||||
private final ChatMessage chatMessage;
|
||||
private final Channel channel;
|
||||
@CustomTabCompleteMethod(param = "channel")
|
||||
public Iterable<String> def() {
|
||||
return Channel.getChannels().map(Channel::getIdentifier)::iterator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param timestamp System.nanoTime()
|
||||
*/
|
||||
private record HistoryEntry(long timestamp, ChatMessage chatMessage, Channel channel) {
|
||||
}
|
||||
|
||||
public static void addChatMessage(ChatMessage chatMessage, Channel channel) {
|
||||
if (!PluginMain.Instance.storeChatHistory.get()) return;
|
||||
val groupID = channel.getGroupID(chatMessage.getPermCheck());
|
||||
if (groupID == null) return; //Just to be sure
|
||||
var ll = messages.computeIfAbsent(channel.ID + "_" + groupID, k -> new LinkedList<>()); //<-- TIL
|
||||
ll.add(new HistoryEntry(System.nanoTime(), chatMessage, channel)); //Adds as last element
|
||||
while (ll.size() > 10)
|
||||
ll.remove(); //Removes the first element
|
||||
synchronized (messages) {
|
||||
var ll = messages.computeIfAbsent(channel.getIdentifier() + "_" + groupID, k -> new LinkedList<>()); //<-- TIL
|
||||
ll.add(new HistoryEntry(System.nanoTime(), chatMessage, channel)); //Adds as last element
|
||||
while (ll.size() > 10)
|
||||
ll.remove(); //Removes the first element
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.FlairStates;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
|
||||
@CommandClass(modOnly = false)
|
||||
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||
public final class IgnoreCommand extends UCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Ignore flair ----",
|
||||
"Stop the \"write your name in the thread\" message from showing up" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
final Player player = (Player) sender;
|
||||
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
if (p.FlairState().get().equals(FlairStates.Accepted)) {
|
||||
player.sendMessage("§cYou can only ignore the \"write your name in the thread\" message.");
|
||||
return true;
|
||||
}
|
||||
if (p.FlairState().get().equals(FlairStates.Commented)) {
|
||||
player.sendMessage("Sorry, but your flair isn't recorded. Please ask a mod to set it for you.");
|
||||
return true;
|
||||
}
|
||||
if (!p.FlairState().get().equals(FlairStates.Ignored)) {
|
||||
p.FlairState().set(FlairStates.Ignored);
|
||||
p.SetFlair(ChatPlayer.FlairTimeNone);
|
||||
p.UserName().set("");
|
||||
player.sendMessage("§bYou have ignored the message.§r");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored the message.§r");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,44 +1,30 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
|
||||
@CommandClass(modOnly = false)
|
||||
public class InfoCommand extends UCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { //
|
||||
"§6---- User information ----", //
|
||||
"Get some information known about the user.", //
|
||||
"Usage: /" + alias + " info <playername>" //
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
if (args.length == 0)
|
||||
return false;
|
||||
if (args[0].equalsIgnoreCase("console") || args[0].equalsIgnoreCase("server")
|
||||
|| args[0].equalsIgnoreCase("@console")) {
|
||||
sender.sendMessage("The server console.");
|
||||
return true;
|
||||
}
|
||||
try (TBMCPlayer p = TBMCPlayerBase.getFromName(args[0], TBMCPlayer.class)) {
|
||||
if (p == null) {
|
||||
sender.sendMessage("§cThe specified player cannot be found");
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(p.getInfo(InfoTarget.MCCommand));
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Error while getting player information!", e);
|
||||
sender.sendMessage("§cError while getting player information!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@CommandClass(modOnly = false, helpText = {
|
||||
"User information", //
|
||||
"Get some information known about the user.", //
|
||||
})
|
||||
public class InfoCommand extends UCommandBase {
|
||||
@Command2.Subcommand
|
||||
public boolean def(CommandSender sender, OfflinePlayer player) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
|
||||
TBMCPlayer p = TBMCPlayerBase.getPlayer(player.getUniqueId(), TBMCPlayer.class);
|
||||
if (p == null) {
|
||||
sender.sendMessage("§cThe specified player cannot be found");
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(p.getInfo(InfoTarget.MCCommand));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.listener.PlayerJoinLeaveListener;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||
@CommandClass
|
||||
public class NColorCommand extends UCommandBase {
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { //
|
||||
"§6---- Name color ----", //
|
||||
"This command allows you to set how the town colors look on your name.", //
|
||||
"To use this command, you need to be in a town which has town colors set.", //
|
||||
"Use a vertical line as a separator between the colors.", //
|
||||
"Example: /u ncolor Norbi|Peti --> §6Norbi§ePeti" //
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(Player player, String alias, String[] args) {
|
||||
Resident res;
|
||||
Town town;
|
||||
try {
|
||||
if ((res = PluginMain.TU.getResidentMap().get(player.getName().toLowerCase())) == null || !res.hasTown()
|
||||
|| (town = res.getTown()) == null) {
|
||||
player.sendMessage("§cYou need to be in a town.");
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
player.sendMessage("§cYou need to be in a town. (" + e + ")");
|
||||
return true;
|
||||
}
|
||||
if (args.length == 0)
|
||||
return false;
|
||||
final String name = ChatColor.stripColor(player.getDisplayName()).replace("~", ""); //Remove ~
|
||||
String arg = args[0]; //Don't add ~ for nicknames
|
||||
if (!arg.replace("|", "").replace(":", "").equalsIgnoreCase(name)) {
|
||||
player.sendMessage("§cThe name you gave doesn't match your name. Make sure to use "
|
||||
+ name + "§c with added vertical lines (|) or colons (:).");
|
||||
return true;
|
||||
}
|
||||
String[] nameparts = arg.split("[|:]");
|
||||
Color[] towncolors = PluginMain.TownColors.get(town.getName().toLowerCase());
|
||||
if (towncolors == null) {
|
||||
player.sendMessage("§cYour town doesn't have a color set. The town mayor can set it using /u towncolor.");
|
||||
return true;
|
||||
}
|
||||
if (nameparts.length < towncolors.length + 1) { //+1: Nation color
|
||||
player.sendMessage("§cYou need more vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1 + 1) + ")"); //Nation color
|
||||
return true;
|
||||
}
|
||||
if (nameparts.length > (towncolors.length + 1) * 2) {
|
||||
player.sendMessage("§cYou have waay too many vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1 + 1) + ")");
|
||||
return true;
|
||||
}
|
||||
if (nameparts.length > towncolors.length + 1) {
|
||||
player.sendMessage("§cYou have too many vertical lines (|) or colons (:) in your name. (Should have " + (towncolors.length - 1 + 1) + ")");
|
||||
return true;
|
||||
}
|
||||
ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations()
|
||||
.set(new ArrayList<>(Arrays.stream(nameparts).map(np -> np.length()).collect(Collectors.toList()))); // No byte[], no TIntArrayList
|
||||
PlayerJoinLeaveListener.updatePlayerColors(player);
|
||||
player.sendMessage("§bName colors set: " + player.getDisplayName());
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandClass
|
||||
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||
public class NationColorCommand extends UCommandBase {
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[]{ //
|
||||
"§6---- Nation Color ----", //
|
||||
"This command allows setting a color for a nation.", //
|
||||
"Each town in the nation will have it's first color (border) set to this color.", //
|
||||
"See the help text for /u towncolor for more details.", //
|
||||
"Usage: /" + GetCommandPath() + " <colorname>", //
|
||||
"Example: /" + GetCommandPath() + " blue" //
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(Player player, String alias, String[] args) {
|
||||
Resident res;
|
||||
if (!(PluginMain.TU.getResidentMap().containsKey(player.getName().toLowerCase())
|
||||
&& (res = PluginMain.TU.getResidentMap().get(player.getName().toLowerCase())).isKing())) {
|
||||
player.sendMessage("§cYou need to be the king of a nation to set it's colors.");
|
||||
return true;
|
||||
}
|
||||
if (args.length > 1) {
|
||||
player.sendMessage("You can only use one color.");
|
||||
return true;
|
||||
}
|
||||
String[] a = new String[args.length + 1];
|
||||
System.arraycopy(args, 0, a, 1, args.length);
|
||||
try {
|
||||
a[0] = res.getTown().getNation().getName();
|
||||
} catch (NotRegisteredException e) {
|
||||
TBMCCoreAPI.SendException("Failed to set nation color for player " + player + "!", e);
|
||||
player.sendMessage("§cCouldn't find your town/nation... Error reported.");
|
||||
return true;
|
||||
}
|
||||
return buttondevteam.chat.commands.ucmds.admin.NationColorCommand.SetNationColor(player, alias, a);
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
|
||||
@CommandClass(modOnly = false)
|
||||
public class OpmeCommand extends UCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- OP me ----", "Totally makes you OP" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
sender.sendMessage("It would be nice, wouldn't it?");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@CommandClass(helpText = {
|
||||
"Reload",
|
||||
"Reloads the config"
|
||||
}, modOnly = true)
|
||||
public class ReloadCommand extends UCommandBase {
|
||||
@Command2.Subcommand
|
||||
public void def(CommandSender sender) {
|
||||
if (PluginMain.Instance.tryReloadConfig())
|
||||
sender.sendMessage("§bReloaded config");
|
||||
else
|
||||
sender.sendMessage("§cFailed to reload config.");
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandClass // TODO: /u u when annotation not present
|
||||
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||
public class TownColorCommand extends UCommandBase {
|
||||
@Override
|
||||
public String GetHelpText(String alias)[] {
|
||||
StringBuilder cns = new StringBuilder(" <colorname1>");
|
||||
for (int i = 2; i <= ColorCount; i++)
|
||||
cns.append(" [colorname").append(i).append("]");
|
||||
return new String[] { //
|
||||
"§6---- Town Color ----", //
|
||||
"This command allows setting a color for a town.", //
|
||||
"The town will be shown with this color on Dynmap and all players in the town will appear in chat with these colors.", //
|
||||
"The colors will split the name evenly.", //
|
||||
"Usage: /" + GetCommandPath() + cns, //
|
||||
"Example: /" + GetCommandPath() + " blue" //
|
||||
};
|
||||
}
|
||||
|
||||
public static byte ColorCount;
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(Player player, String alias, String[] args) {
|
||||
Resident res;
|
||||
if (!(PluginMain.TU.getResidentMap().containsKey(player.getName().toLowerCase())
|
||||
&& (res = PluginMain.TU.getResidentMap().get(player.getName().toLowerCase())).isMayor())) {
|
||||
player.sendMessage("§cYou need to be the mayor of a town to set it's colors.");
|
||||
return true;
|
||||
}
|
||||
if (args.length > ColorCount) {
|
||||
player.sendMessage("You can only use " + ColorCount + " color" + (ColorCount > 1 ? "s" : "") + ".");
|
||||
return true;
|
||||
}
|
||||
String[] a = new String[args.length + 1];
|
||||
System.arraycopy(args, 0, a, 1, args.length);
|
||||
try {
|
||||
a[0] = res.getTown().getName();
|
||||
} catch (NotRegisteredException e) {
|
||||
TBMCCoreAPI.SendException("Failed to set town color for player " + player + "!", e);
|
||||
player.sendMessage("§cCouldn't find your town... Error reported.");
|
||||
return true;
|
||||
}
|
||||
return buttondevteam.chat.commands.ucmds.admin.TownColorCommand.SetTownColor(player, alias, a);
|
||||
}
|
||||
}
|
|
@ -1,13 +1,8 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.OptionallyPlayerCommandBase;
|
||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||
|
||||
@CommandClass(modOnly = false, path = "u")
|
||||
@OptionallyPlayerCommandClass(playerOnly = false)
|
||||
public abstract class UCommandBase extends OptionallyPlayerCommandBase {
|
||||
|
||||
public abstract String[] GetHelpText(String alias);
|
||||
|
||||
}
|
||||
package buttondevteam.chat.commands.ucmds;
|
||||
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.ICommand2MC;
|
||||
|
||||
@CommandClass(modOnly = false, path = "u")
|
||||
public abstract class UCommandBase extends ICommand2MC {
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
|
||||
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
|
||||
@CommandClass(modOnly = true)
|
||||
public abstract class AdminCommandBase extends UCommandBase {
|
||||
|
||||
public abstract String[] GetHelpText(String alias);
|
||||
|
||||
}
|
||||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
|
||||
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
|
||||
@CommandClass(modOnly = true)
|
||||
public abstract class AdminCommandBase extends UCommandBase {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,29 +1,28 @@
|
|||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
|
||||
public class DebugCommand extends AdminCommandBase {
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Debug mode ----",
|
||||
"Toggles debug mode, which prints debug messages to the console." };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
sender.sendMessage("§eDebug mode " + ((DebugMode = !DebugMode) ? "§aenabled." : "§cdisabled."));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void SendDebugMessage(String message) {
|
||||
if (DebugMode)
|
||||
if (PluginMain.Instance != null)
|
||||
PluginMain.Instance.getLogger().info(message);
|
||||
else
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@CommandClass(helpText = {
|
||||
"Debug mode",
|
||||
"Toggles debug mode, which prints debug messages to the console."
|
||||
})
|
||||
public class DebugCommand extends AdminCommandBase {
|
||||
public static boolean DebugMode = false;
|
||||
|
||||
@Command2.Subcommand
|
||||
public boolean def(CommandSender sender) {
|
||||
sender.sendMessage("§eDebug mode " + ((DebugMode = !DebugMode) ? "§aenabled." : "§cdisabled."));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void SendDebugMessage(String message) {
|
||||
if (DebugMode)
|
||||
if (PluginMain.Instance != null)
|
||||
PluginMain.Instance.getLogger().info(message);
|
||||
else
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.listener.TownyListener;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class NationColorCommand extends AdminCommandBase {
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[]{ //
|
||||
"§6---- Nation color ----", //
|
||||
"Sets the color of the nation.", //
|
||||
"Usage: /u admin nationcolor <color>" //
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
return SetNationColor(sender, alias, args);
|
||||
}
|
||||
|
||||
public static boolean SetNationColor(CommandSender sender, String alias, String[] args) {
|
||||
if (args.length < 2)
|
||||
return false;
|
||||
if (args.length > 2) {
|
||||
sender.sendMessage("§cYou can only use one color as a nation color.");
|
||||
return true;
|
||||
}
|
||||
final Nation nation = PluginMain.TU.getNationsMap().get(args[0].toLowerCase());
|
||||
if (nation == null) {
|
||||
sender.sendMessage("§cThe nation '" + args[0] + "' cannot be found.");
|
||||
return true;
|
||||
}
|
||||
val c = TownColorCommand.getColorOrSendError(args[1], sender);
|
||||
if (!c.isPresent()) return true;
|
||||
if (!c.get().getName().equals(Color.White.getName())) { //Default nation color
|
||||
for (val nc : PluginMain.NationColor.values()) {
|
||||
if (nc.getName().equals(c.get().getName())) {
|
||||
sender.sendMessage("§cAnother nation already uses this color!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
PluginMain.NationColor.put(args[0].toLowerCase(), c.get());
|
||||
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
|
||||
for (Town t : nation.getTowns())
|
||||
TownyListener.updateTownMembers(t);
|
||||
});
|
||||
sender.sendMessage("§bNation color set to §" + TownColorCommand.getColorText(c.get()));
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
|
||||
public class PlayerInfoCommand extends AdminCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Player info ----",
|
||||
"Shows some info about the player's flair, Reddit username(s) and other data known by the plugin",
|
||||
"Usage: /u admin playerinfo <player>" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
}
|
||||
ChatPlayer p = TBMCPlayerBase.getFromName(args[0], ChatPlayer.class);
|
||||
if (p == null) {
|
||||
sender.sendMessage("§cPlayer not found: " + args[0] + "§r");
|
||||
return true;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("§6Usernames:");
|
||||
for (String username : p.UserNames())
|
||||
sb.append(" ").append(username);
|
||||
sender.sendMessage(new String[] { //
|
||||
"Player name: " + p.PlayerName(), //
|
||||
"User flair: " + p.GetFormattedFlair(), //
|
||||
"Username: " + p.UserName(), //
|
||||
"Flair state: " + p.FlairState(), //
|
||||
sb.toString(), //
|
||||
"FCount: " + p.FCount(), //
|
||||
"FDeaths: " + p.FDeaths() //
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
|
||||
public class SaveCommand extends AdminCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Save config ----",
|
||||
"This command saves the config file(s)" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias,
|
||||
String[] args) {
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
sender.sendMessage("§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.FlairStates;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
|
||||
public class SetFlairCommand extends AdminCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Set flair -----", "Set a flair for a player",
|
||||
"Usage: /u admin setflair <player> <flairtime (or non-presser, cant-press, none)> <cheater(true/false)> [username]",
|
||||
"Example 1: /u admin setflair NorbiPeti 19 false NorbiPeti --> orange (19s)",
|
||||
"Example 2: /u admin setflair iie 0 true asde --> purple (0s)" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
if (args.length < 3) {
|
||||
return false;
|
||||
}
|
||||
Player p = Bukkit.getPlayer(args[0]);
|
||||
if (p == null) {
|
||||
sender.sendMessage("§cPlayer not found.&r");
|
||||
return true;
|
||||
}
|
||||
short flairtime = 0x00;
|
||||
if (args[1].equalsIgnoreCase("non-presser"))
|
||||
flairtime = ChatPlayer.FlairTimeNonPresser;
|
||||
else if (args[1].equalsIgnoreCase("cant-press"))
|
||||
flairtime = ChatPlayer.FlairTimeCantPress;
|
||||
else if (args[1].equalsIgnoreCase("none"))
|
||||
flairtime = ChatPlayer.FlairTimeNone;
|
||||
else {
|
||||
try {
|
||||
flairtime = Short.parseShort(args[1]);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(
|
||||
"§cFlairtime must be a number, \"non-presser\", \"cant-press\" or \"none\". Run without args to see usage.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
boolean cheater = false;
|
||||
if (args[2].equalsIgnoreCase("true"))
|
||||
cheater = true;
|
||||
else if (args[2].equalsIgnoreCase("false"))
|
||||
cheater = false;
|
||||
else {
|
||||
sender.sendMessage("§cUnknown value for cheater parameter. Run without args to see usage.");
|
||||
return true;
|
||||
}
|
||||
ChatPlayer mp = TBMCPlayerBase.getPlayer(p.getUniqueId(), ChatPlayer.class);
|
||||
mp.SetFlair(flairtime, cheater);
|
||||
mp.FlairState().set(FlairStates.Accepted);
|
||||
if (args.length < 4)
|
||||
mp.UserName().set("");
|
||||
else {
|
||||
mp.UserName().set(args[3]);
|
||||
if (!mp.UserNames().contains(args[3]))
|
||||
mp.UserNames().add(args[3]);
|
||||
}
|
||||
sender.sendMessage(
|
||||
"§bThe flair has been set. Player: " + mp.PlayerName() + " Flair: " + mp.GetFormattedFlair() + "§r");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class TCCount extends AdminCommandBase {
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { //
|
||||
"§6---- Town Color Count", //
|
||||
"Sets how many colors can be used for a town." //
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
byte count;
|
||||
try {
|
||||
if (args.length == 0 || (count = Byte.parseByte(args[0])) <= 0)
|
||||
return false;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
buttondevteam.chat.commands.ucmds.TownColorCommand.ColorCount = count;
|
||||
sender.sendMessage("Color count set to " + count);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.listener.TownyListener;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.dynmap.towny.DynmapTownyPlugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TownColorCommand extends AdminCommandBase {
|
||||
@Override
|
||||
public String GetHelpText(String alias)[] { // TODO: Command path aliases
|
||||
return new String[]{ //
|
||||
"§6---- Town Color ----", //
|
||||
"This command allows setting a color for a town.", //
|
||||
"The town will be shown with this color on Dynmap and all players in the town will appear in chat with these colors.", //
|
||||
"The colors will split the name evenly.", //
|
||||
"Usage: /" + GetCommandPath() + " <town> <colorname1> [colorname2...]", //
|
||||
"Example: /" + GetCommandPath() + " Alderon blue gray" //
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
return SetTownColor(sender, alias, args);
|
||||
}
|
||||
|
||||
public static boolean SetTownColor(CommandSender sender, String alias, String[] args) {
|
||||
if (args.length < 2)
|
||||
return false;
|
||||
if (!PluginMain.TU.getTownsMap().containsKey(args[0].toLowerCase())) {
|
||||
sender.sendMessage("§cThe town '" + args[0] + "' cannot be found.");
|
||||
return true;
|
||||
}
|
||||
Color[] clrs = new Color[args.length - 1];
|
||||
Town targetTown = PluginMain.TU.getTownsMap().get(args[0].toLowerCase());
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
val c = getColorOrSendError(args[i], sender);
|
||||
if (!c.isPresent())
|
||||
return true;
|
||||
clrs[i - 1] = c.get();
|
||||
}
|
||||
for (Map.Entry<String, Color[]> other : PluginMain.TownColors.entrySet()) {
|
||||
Color nc, tnc;
|
||||
try {
|
||||
nc = PluginMain.NationColor.get(PluginMain.TU.getTownsMap().get(other.getKey()).getNation().getName().toLowerCase());
|
||||
} catch (Exception e) { //Too lazy for lots of null-checks and it may throw exceptions anyways
|
||||
nc = null;
|
||||
}
|
||||
if (nc == null) nc = Color.White; //Default nation color
|
||||
try {
|
||||
tnc = PluginMain.NationColor.get(targetTown.getNation().getName().toLowerCase());
|
||||
} catch (Exception e) {
|
||||
tnc = null;
|
||||
}
|
||||
if (tnc == null) tnc = Color.White; //Default nation color - TODO: Make configurable
|
||||
if (nc.getName().equals(tnc.getName())) {
|
||||
int C = 0;
|
||||
if (clrs.length == other.getValue().length)
|
||||
for (int i = 0; i < clrs.length; i++)
|
||||
if (clrs[i].getName().equals(other.getValue()[i].getName()))
|
||||
C++;
|
||||
else break;
|
||||
if (C == clrs.length) {
|
||||
sender.sendMessage("§cThis town color combination is already used!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
PluginMain.TownColors.put(args[0].toLowerCase(), clrs);
|
||||
TownyListener.updateTownMembers(targetTown);
|
||||
|
||||
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
||||
if (dtp == null) {
|
||||
sender.sendMessage("§cDynmap-Towny couldn't be found §6but otherwise §btown color set.");
|
||||
PluginMain.Instance.getLogger().warning("Dynmap-Towny not found for setting town color!");
|
||||
return true;
|
||||
}
|
||||
PluginMain.setTownColor(dtp, targetTown.getName(), clrs);
|
||||
sender.sendMessage("§bColor(s) set.");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Optional<Color> getColorOrSendError(String name, CommandSender sender) {
|
||||
val c = Arrays.stream(Color.values()).skip(1).filter(cc -> cc.getName().equalsIgnoreCase(name)).findAny();
|
||||
if (!c.isPresent()) { //^^ Skip black
|
||||
sender.sendMessage("§cThe color '" + name + "' cannot be found."); //ˇˇ Skip black
|
||||
sender.sendMessage("§cAvailable colors: " + Arrays.stream(Color.values()).skip(1).map(TownColorCommand::getColorText).collect(Collectors.joining(", ")));
|
||||
sender.sendMessage("§cMake sure to type them exactly as shown above.");
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
public static String getColorText(Color col) {
|
||||
return String.format("§%x%s§r", col.ordinal(), col.getName());
|
||||
}
|
||||
|
||||
public static String getTownNameCased(String name) {
|
||||
return PluginMain.TU.getTownsMap().get(name.toLowerCase()).getName();
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.component.updater.PluginUpdater;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class UpdatePlugin extends AdminCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { //
|
||||
"§6---- Update plugin ----", //
|
||||
"This command downloads the latest version of a TBMC plugin from GitHub", //
|
||||
"To update a plugin: /" + alias + " <plugin>", //
|
||||
"To list the plugin names: /" + alias //
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage("Downloading plugin names...");
|
||||
boolean first = true;
|
||||
for (String plugin : PluginUpdater.GetPluginNames()) {
|
||||
if (first) {
|
||||
sender.sendMessage("§6---- Plugin names ----");
|
||||
first = false;
|
||||
}
|
||||
sender.sendMessage("- " + plugin);
|
||||
}
|
||||
} else
|
||||
TBMCCoreAPI.UpdatePlugin(args[0], sender, args.length == 1 ? "master" : args[1]);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds.announce;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
|
||||
public class AddCommand extends AnnounceCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] {
|
||||
"§6---- Add announcement ----",
|
||||
"This command adds a new announcement",
|
||||
"Note: Please avoid using this command, if possible",
|
||||
"Instead, use the command blocks in flatworld to set announcements",
|
||||
"This makes editing announcements easier" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias,
|
||||
String[] args) {
|
||||
if (args.length < 1) {
|
||||
return false;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
sb.append(args[i]);
|
||||
if (i != args.length - 1)
|
||||
sb.append(" ");
|
||||
}
|
||||
String finalmessage = sb.toString().replace('&', '§');
|
||||
PluginMain.AnnounceMessages.add(finalmessage);
|
||||
sender.sendMessage("§bAnnouncement added. - Plase avoid using this command if possible, see /u announce add without args.§r");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds.announce;
|
||||
|
||||
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||
|
||||
@CommandClass(modOnly = true)
|
||||
@OptionallyPlayerCommandClass(playerOnly = false)
|
||||
public abstract class AnnounceCommandBase extends UCommandBase {
|
||||
|
||||
public abstract String[] GetHelpText(String alias);
|
||||
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds.announce;
|
||||
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
|
||||
public class EditCommand extends AnnounceCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Edit announcement ----",
|
||||
"This command can only be used in a command block.",
|
||||
"Usage: /u annonunce edit <index> <text>" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias,
|
||||
String[] args) {
|
||||
if (!(sender instanceof BlockCommandSender)) {
|
||||
sender.sendMessage("§cError: This command can only be used from a command block. You can use add and remove, though it's not recommended.");
|
||||
return true;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
return false;
|
||||
}
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (int i1 = 1; i1 < args.length; i1++) {
|
||||
sb1.append(args[i1]);
|
||||
if (i1 != args.length - 1)
|
||||
sb1.append(" ");
|
||||
}
|
||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
||||
int index = Integer.parseInt(args[0]);
|
||||
if (index > 100)
|
||||
return false;
|
||||
while (PluginMain.AnnounceMessages.size() <= index)
|
||||
PluginMain.AnnounceMessages.add("");
|
||||
PluginMain.AnnounceMessages.set(Integer.parseInt(args[0]),
|
||||
finalmessage1);
|
||||
sender.sendMessage("Announcement edited.");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds.announce;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
|
||||
public class ListCommand extends AnnounceCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- List announcements ----",
|
||||
"This command lists the announcements and the time between them" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias,
|
||||
String[] args) {
|
||||
sender.sendMessage("§bList of announce messages:§r");
|
||||
sender.sendMessage("§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : PluginMain.AnnounceMessages)
|
||||
sender.sendMessage("[" + i++ + "] " + message);
|
||||
sender.sendMessage("§bCurrent wait time between announcements: "
|
||||
+ PluginMain.AnnounceTime / 60 / 1000 + " minute(s)§r");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds.announce;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
|
||||
public class RemoveCommand extends AnnounceCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] {
|
||||
"§6---- Remove announcement ----",
|
||||
"This command removes an announcement",
|
||||
"Note: Please avoid using this command, if possible",
|
||||
"Instead, use the command blocks in flatworld to set announcements",
|
||||
"This makes editing announcements easier" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias,
|
||||
String[] args) {
|
||||
if (args.length < 1) {
|
||||
sender.sendMessage("§cUsage: /u announce remove <index>");
|
||||
return true;
|
||||
}
|
||||
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[0]));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds.announce;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
|
||||
public class SetTimeCommand extends AnnounceCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Set time ----",
|
||||
"This command sets the time between the announcements",
|
||||
"Usage: /u anonunce settime <minutes>", "Default: 15" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias,
|
||||
String[] args) {
|
||||
if (args.length < 1) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
PluginMain.AnnounceTime = Integer.parseInt(args[0]) * 60 * 1000;
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage("§cMinutes argument must be a number. Got: "
|
||||
+ args[0]);
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage("Time set between announce messages");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package buttondevteam.chat.components;
|
||||
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
|
||||
public class TownColorComponent extends Component {
|
||||
public ConfigData<Byte> colorCount() { //TODO
|
||||
return getData("colorCount", (byte) 1, cc -> (byte) cc, cc -> (int) cc);
|
||||
}
|
||||
|
||||
public ConfigData<Boolean> useNationColors() { //TODO
|
||||
return getData("useNationColors", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
//TODO: Don't register all commands automatically (welp)
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package buttondevteam.chat.components.announce;
|
||||
|
||||
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
||||
import buttondevteam.chat.components.formatter.FormatterComponent;
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.event.ClickEvent.Action.SUGGEST_COMMAND;
|
||||
import static net.kyori.adventure.text.event.ClickEvent.clickEvent;
|
||||
import static net.kyori.adventure.text.event.HoverEvent.Action.SHOW_TEXT;
|
||||
import static net.kyori.adventure.text.event.HoverEvent.hoverEvent;
|
||||
|
||||
@CommandClass(modOnly = true)
|
||||
@RequiredArgsConstructor
|
||||
public class AnnounceCommand extends UCommandBase {
|
||||
private final AnnouncerComponent component;
|
||||
|
||||
@Command2.Subcommand(helpText = {
|
||||
"Add announcement",
|
||||
"This command adds a new announcement",
|
||||
})
|
||||
public boolean add(CommandSender sender, @Command2.TextArg String text) {
|
||||
String finalmessage = text.replace('&', '§');
|
||||
component.announceMessages.get().add(finalmessage);
|
||||
sender.sendMessage("§bAnnouncement added.§r");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Command2.Subcommand(helpText = {
|
||||
"Edit announcement",
|
||||
"This command lets you edit an announcement by its index.",
|
||||
"Shouldn't be used directly, use either command blocks or click on an announcement in /u announce list instead."
|
||||
})
|
||||
public boolean edit(CommandSender sender, byte index, @Command2.TextArg String text) {
|
||||
String finalmessage1 = text.replace('&', '§');
|
||||
if (index > 100)
|
||||
return false;
|
||||
while (component.announceMessages.get().size() <= index)
|
||||
component.announceMessages.get().add("");
|
||||
component.announceMessages.get().set(index, finalmessage1);
|
||||
sender.sendMessage("Announcement edited.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Command2.Subcommand(helpText = {
|
||||
"List announcements",
|
||||
"This command lists the announcements and the time between them"
|
||||
})
|
||||
public boolean list(CommandSender sender) {
|
||||
sender.sendMessage("§bList of announce messages:§r");
|
||||
sender.sendMessage("§bFormat: [index] message§r");
|
||||
int i = 0;
|
||||
for (String message : component.announceMessages.get()) {
|
||||
String msg = "[" + i++ + "] " + message;
|
||||
//noinspection SuspiciousMethodCalls
|
||||
if (!ComponentManager.isEnabled(FormatterComponent.class) || !Bukkit.getOnlinePlayers().contains(sender)) {
|
||||
sender.sendMessage(msg);
|
||||
continue;
|
||||
}
|
||||
sender.sendMessage(text(msg)
|
||||
.hoverEvent(hoverEvent(SHOW_TEXT, text("Click to edit")))
|
||||
.clickEvent(clickEvent(SUGGEST_COMMAND, "/" + getCommandPath() + " edit " + (i - 1) + " " + message.replace('§', '&'))));
|
||||
}
|
||||
sender.sendMessage("§bCurrent wait time between announcements: "
|
||||
+ component.announceTime.get() / 60 / 1000 + " minute(s)§r");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Command2.Subcommand(helpText = {
|
||||
"Remove announcement",
|
||||
"This command removes an announcement"
|
||||
})
|
||||
public boolean remove(CommandSender sender, int index) {
|
||||
val msgs = component.announceMessages.get();
|
||||
if (index < 0 || index > msgs.size()) return false;
|
||||
msgs.remove(index);
|
||||
sender.sendMessage("Announcement removed.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Command2.Subcommand(helpText = {
|
||||
"Set time",
|
||||
"This command sets the time between the announcements"
|
||||
})
|
||||
public boolean settime(CommandSender sender, int minutes) {
|
||||
component.announceTime.set(minutes * 60 * 1000);
|
||||
sender.sendMessage("Time set between announce messages to " + minutes + " minutes");
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package buttondevteam.chat.components.announce;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ComponentMetadata;
|
||||
import buttondevteam.lib.architecture.config.IConfigData;
|
||||
import buttondevteam.lib.architecture.config.IListConfigData;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Displays the configured messages at the set interval when someone is online.
|
||||
*/
|
||||
@ComponentMetadata(enabledByDefault = false)
|
||||
public class AnnouncerComponent extends Component<PluginMain> implements Runnable {
|
||||
/**
|
||||
* The messages to display to players.
|
||||
*/
|
||||
public IListConfigData<String> announceMessages = getConfig().getListData("announceMessages", Collections.emptyList());
|
||||
|
||||
/**
|
||||
* The time in milliseconds between the messages. Use /u announce settime to set minutes.
|
||||
*/
|
||||
public IConfigData<Integer> announceTime = getConfig().getData("announceTime", 15 * 60 * 1000);
|
||||
|
||||
private TBMCSystemChatEvent.BroadcastTarget target;
|
||||
|
||||
private int AnnounceMessageIndex = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (isEnabled()) {
|
||||
try {
|
||||
Thread.sleep(announceTime.get());
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
if (Bukkit.getOnlinePlayers().size() == 0) continue; //Don't post to Discord if nobody is on
|
||||
if (announceMessages.get().size() > AnnounceMessageIndex) {
|
||||
TBMCChatAPI.SendSystemMessage(Channel.globalChat, Channel.RecipientTestResult.ALL, announceMessages.get().get(AnnounceMessageIndex), target);
|
||||
AnnounceMessageIndex++;
|
||||
if (AnnounceMessageIndex == announceMessages.get().size())
|
||||
AnnounceMessageIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
target = TBMCSystemChatEvent.BroadcastTarget.add("announcements");
|
||||
registerCommand(new AnnounceCommand(this));
|
||||
new Thread(this).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
package buttondevteam.chat.components.appendext;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.IHaveConfig;
|
||||
import buttondevteam.lib.architecture.config.IConfigData;
|
||||
import buttondevteam.lib.chat.*;
|
||||
import lombok.val;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Allows players to append tableflips and other things to their messages. Everything is configurable here.
|
||||
*/
|
||||
public class AppendTextComponent extends Component<PluginMain> {
|
||||
private Map<String, IHaveConfig> appendTexts;
|
||||
|
||||
private IConfigData<String[]> helpText(IHaveConfig config) {
|
||||
return config.getData("helpText", new String[]{
|
||||
"Tableflip", //
|
||||
"This command appends a tableflip after your message", //
|
||||
"Or just makes you tableflip", //
|
||||
});
|
||||
}
|
||||
|
||||
private IConfigData<String> appendedText(IHaveConfig config) {
|
||||
return config.getData("appendedText", "tableflip");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
val map = new HashMap<String, Consumer<IHaveConfig>>();
|
||||
map.put("tableflip", conf -> {
|
||||
helpText(conf).set(new String[]{
|
||||
"Tableflip", //
|
||||
"This command appends a tableflip after your message", //
|
||||
"Or just makes you tableflip", //
|
||||
});
|
||||
appendedText(conf).set("(╯°□°)╯︵ ┻━┻");
|
||||
});
|
||||
map.put("unflip", conf -> {
|
||||
helpText(conf).set(new String[]{
|
||||
"Unflip", //
|
||||
"This command appends an unflip after your message", //
|
||||
"Or just unflips as you", //
|
||||
});
|
||||
appendedText(conf).set("┬─┬ ノ( ゜-゜ノ)");
|
||||
});
|
||||
map.put("shrug", conf -> {
|
||||
helpText(conf).set(new String[]{
|
||||
"Shrug", //
|
||||
"This command appends a shrug after your message", //
|
||||
"Or just makes you shrug", //
|
||||
});
|
||||
appendedText(conf).set("¯\\\\\\_(ツ)\\_/¯");
|
||||
});
|
||||
map.put("lenny", conf -> {
|
||||
helpText(conf).set(new String[]{
|
||||
"Lenny", //
|
||||
"This command appends a Lenny face after your message", //
|
||||
"Or just sends one", //
|
||||
});
|
||||
appendedText(conf).set("( ͡° ͜ʖ ͡°)");
|
||||
});
|
||||
map.put("waitwhat", conf -> {
|
||||
helpText(conf).set(new String[]{
|
||||
"Wait what", //
|
||||
"Wait what" //
|
||||
});
|
||||
appendedText(conf).set("wait what");
|
||||
});
|
||||
appendTexts = getConfigMap("texts", map);
|
||||
for (String cmd : appendTexts.keySet())
|
||||
registerCommand(new CommandHandler(cmd));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
|
||||
}
|
||||
|
||||
@CommandClass
|
||||
public class CommandHandler extends ICommand2MC {
|
||||
private final String path;
|
||||
private final String[] helpText;
|
||||
private final String appendedText;
|
||||
|
||||
CommandHandler(String command) {
|
||||
val conf = appendTexts.get(command);
|
||||
if (conf == null) throw new NoSuchElementException("AppendText command not found: " + command);
|
||||
path = command;
|
||||
helpText = helpText(conf).get();
|
||||
appendedText = appendedText(conf).get();
|
||||
|
||||
}
|
||||
|
||||
@Command2.Subcommand
|
||||
public void def(Command2MCSender sender, @Command2.OptionalArg @Command2.TextArg String message) {
|
||||
TBMCChatAPI.sendChatMessage(ChatMessage.builder(sender.getSender(),
|
||||
(message == null ? "" : message + " ") + appendedText).fromCommand(true).permCheck(sender.getPermCheck()).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getHelpText(Method method, Command2.Subcommand ann) {
|
||||
return helpText;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package buttondevteam.chat.components.chatonly;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ComponentMetadata;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import lombok.val;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.event.HoverEvent.Action.SHOW_TEXT;
|
||||
import static net.kyori.adventure.text.event.HoverEvent.hoverEvent;
|
||||
|
||||
/**
|
||||
* Allows players to enter chat-only mode which puts them into spectator mode and disallows moving.
|
||||
*/
|
||||
@ComponentMetadata(enabledByDefault = false)
|
||||
public class ChatOnlyComponent extends Component<PluginMain> implements Listener {
|
||||
@Override
|
||||
protected void enable() {
|
||||
registerListener(this);
|
||||
registerCommand(new ChatonlyCommand());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerJoin(PlayerJoinEvent event) {
|
||||
val p = event.getPlayer();
|
||||
val cp = TBMCPlayer.getPlayer(p.getUniqueId(), ChatPlayer.class);
|
||||
if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) {
|
||||
cp.ChatOnly = false;
|
||||
p.setGameMode(GameMode.SURVIVAL);
|
||||
}
|
||||
}
|
||||
|
||||
public static void tellrawCreate(ChatPlayer mp, TextComponent.Builder json) {
|
||||
if (!ComponentManager.isEnabled(ChatOnlyComponent.class))
|
||||
return;
|
||||
if (mp != null && mp.ChatOnly) {
|
||||
json.append(text("[C]").hoverEvent(hoverEvent(SHOW_TEXT, text("Chat only"))));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent e) {
|
||||
ChatPlayer mp = TBMCPlayer.getPlayer(e.getPlayer().getUniqueId(), ChatPlayer.class);
|
||||
if (mp.ChatOnly)
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent e) {
|
||||
if (TBMCPlayer.getPlayer(e.getPlayer().getUniqueId(), ChatPlayer.class).ChatOnly) {
|
||||
e.setCancelled(true);
|
||||
e.getPlayer().sendMessage("§cYou are not allowed to teleport while in chat-only mode.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package buttondevteam.chat.components.chatonly;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.ICommand2MC;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandClass(modOnly = false, helpText = {
|
||||
"Chat-only mode", //
|
||||
"This mode makes you invincible but unable to move, teleport or interact with the world in any way", //
|
||||
"It was designed for chat clients", //
|
||||
"Once enabled, the only way of disabling it is by relogging to the server" //
|
||||
})
|
||||
public final class ChatonlyCommand extends ICommand2MC {
|
||||
|
||||
@Command2.Subcommand
|
||||
public boolean def(Player player) {
|
||||
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
p.ChatOnly = true;
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
player.sendMessage("§bChat-only mode enabled. You are now invincible.");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package buttondevteam.chat.components.flair;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.PlayerJoinTimerTask;
|
||||
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Timer;
|
||||
|
||||
@CommandClass(modOnly = false, helpText = {
|
||||
"Accept flair", //
|
||||
"Accepts a flair from Reddit", //
|
||||
"Use /u accept <username> if you commented from multiple accounts"
|
||||
})
|
||||
@RequiredArgsConstructor
|
||||
public class AcceptCommand extends UCommandBase {
|
||||
private final FlairComponent component;
|
||||
|
||||
@Command2.Subcommand
|
||||
public boolean def(Player player, @Command2.OptionalArg String username) {
|
||||
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
if (username == null && p.UserNames.get().size() > 1) {
|
||||
player.sendMessage("§9Multiple users commented your name. §bPlease pick one using /u accept <username>");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("§6Usernames:");
|
||||
for (String name : p.UserNames.get())
|
||||
sb.append(" ").append(name);
|
||||
player.sendMessage(sb.toString());
|
||||
return true;
|
||||
}
|
||||
if (p.FlairState.get().equals(FlairStates.NoComment) || p.UserNames.get().size() == 0) {
|
||||
player.sendMessage("§cError: You need to write your username to the reddit thread§r");
|
||||
player.sendMessage(component.flairThreadURL.get());
|
||||
return true;
|
||||
}
|
||||
if (username != null && !p.UserNames.get().contains(username)) {
|
||||
player.sendMessage("§cError: Unknown name: " + username + "§r");
|
||||
return true;
|
||||
}
|
||||
if (p.Working) {
|
||||
player.sendMessage("§cError: Something is already in progress.§r");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((username != null ? username : p.UserNames.get().get(0)).equals(p.UserName.get())) {
|
||||
player.sendMessage("§cYou already have this user's flair.§r");
|
||||
return true;
|
||||
}
|
||||
if (username != null)
|
||||
p.UserName.set(username);
|
||||
else
|
||||
p.UserName.set(p.UserNames.get().get(0));
|
||||
|
||||
player.sendMessage("§bObtaining flair...");
|
||||
p.Working = true;
|
||||
Timer timer = new Timer();
|
||||
PlayerJoinTimerTask tt = new PlayerJoinTimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
component.DownloadFlair(mp);
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while downloading flair for " + player.getCustomName() + "!", e, component);
|
||||
player.sendMessage("Sorry, but an error occured while trying to get your flair. Please contact a mod.");
|
||||
mp.Working = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mp.FlairState.get().equals(FlairStates.Commented)) {
|
||||
player.sendMessage("Sorry, but your flair isn't recorded. Please ask an admin to set it for you. Also, prepare a comment on /r/thebutton, if possible.");
|
||||
mp.Working = false;
|
||||
return;
|
||||
}
|
||||
String flair = mp.GetFormattedFlair();
|
||||
mp.FlairState.set(FlairStates.Accepted);
|
||||
FlairComponent.ConfirmUserMessage(mp);
|
||||
player.sendMessage("§bYour flair has been set:§r " + flair);
|
||||
mp.Working = false;
|
||||
}
|
||||
};
|
||||
tt.mp = p;
|
||||
timer.schedule(tt, 20);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,189 @@
|
|||
package buttondevteam.chat.components.flair;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ComponentMetadata;
|
||||
import buttondevteam.lib.architecture.config.IConfigData;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This component checks a specific Reddit thread every 10 seconds for comments such as "IGN: NorbiPeti" to link Reddit accounts and to determine their /r/thebutton flair.
|
||||
* This was the original goal of this plugin when it was made.
|
||||
*/
|
||||
@ComponentMetadata(enabledByDefault = false)
|
||||
public class FlairComponent extends Component<PluginMain> {
|
||||
/**
|
||||
* The Reddit thread to check for account connections. Re-enable the component if this was empty.
|
||||
*/
|
||||
IConfigData<String> flairThreadURL = getConfig().getData("flairThreadURL", "");
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This variable is used as a cache for flair state checking when reading the flair thread.
|
||||
* </p>
|
||||
* <p>
|
||||
* It's used because normally it has to load all associated player files every time to read the flair state
|
||||
* </p>
|
||||
*/
|
||||
private final Set<String> PlayersWithFlairs = new HashSet<>();
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
registerCommand(new AcceptCommand(this));
|
||||
registerCommand(new IgnoreCommand());
|
||||
registerCommand(new SetFlairCommand());
|
||||
new Thread(this::FlairGetterThreadMethod).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
|
||||
}
|
||||
|
||||
private void FlairGetterThreadMethod() {
|
||||
int errorcount = 0;
|
||||
while (isEnabled() && flairThreadURL.get().length() > 0) {
|
||||
try {
|
||||
String body = TBMCCoreAPI.DownloadString(flairThreadURL.get() + ".json?limit=1000");
|
||||
JsonArray json = new JsonParser().parse(body).getAsJsonArray().get(1).getAsJsonObject().get("data")
|
||||
.getAsJsonObject().get("children").getAsJsonArray();
|
||||
for (Object obj : json) {
|
||||
JsonObject item = (JsonObject) obj;
|
||||
String author = item.get("data").getAsJsonObject().get("author").getAsString();
|
||||
String ign = item.get("data").getAsJsonObject().get("body").getAsString();
|
||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||
if (start == -1 + "IGN:".length())
|
||||
continue;
|
||||
int end = ign.indexOf(' ', start);
|
||||
if (end == -1 || end == start)
|
||||
end = ign.indexOf('\n', start);
|
||||
if (end == -1 || end == start)
|
||||
ign = ign.substring(start);
|
||||
else
|
||||
ign = ign.substring(start, end);
|
||||
ign = ign.trim();
|
||||
if (PlayersWithFlairs.contains(ign))
|
||||
continue;
|
||||
ChatPlayer mp = TBMCPlayerBase.getFromName(ign, ChatPlayer.class); // Loads player file
|
||||
if (mp == null)
|
||||
continue;
|
||||
/*
|
||||
* if (!JoinedBefore(mp, 2015, 6, 5)) continue;
|
||||
*/
|
||||
if (!mp.UserNames.get().contains(author))
|
||||
mp.UserNames.get().add(author);
|
||||
if (mp.FlairState.get().equals(FlairStates.NoComment)) {
|
||||
mp.FlairState.set(FlairStates.Commented);
|
||||
ConfirmUserMessage(mp);
|
||||
}
|
||||
PlayersWithFlairs.add(ign); // Don't redownload even if flair isn't accepted
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errorcount++;
|
||||
if (errorcount >= 10) {
|
||||
errorcount = 0;
|
||||
if (!e.getMessage().contains("Server returned HTTP response code")
|
||||
&& !(e instanceof UnknownHostException))
|
||||
TBMCCoreAPI.SendException("Error while getting flairs from Reddit!", e, this);
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DownloadFlair(ChatPlayer mp) throws IOException {
|
||||
String[] flairdata = TBMCCoreAPI
|
||||
.DownloadString("http://karmadecay.com/thebutton-data.php?users=" + mp.UserName.get())
|
||||
.replace("\"", "").split(":");
|
||||
String flair;
|
||||
if (flairdata.length > 1)
|
||||
flair = flairdata[1];
|
||||
else
|
||||
flair = "";
|
||||
String flairclass;
|
||||
if (flairdata.length > 2)
|
||||
flairclass = flairdata[2];
|
||||
else
|
||||
flairclass = "unknown";
|
||||
SetFlair(mp, flair, flairclass, mp.UserName.get());
|
||||
}
|
||||
|
||||
private void SetFlair(ChatPlayer p, String text, String flairclass, String username) {
|
||||
p.UserName.set(username);
|
||||
p.FlairState.set(FlairStates.Recognised);
|
||||
switch (flairclass) {
|
||||
case "cheater":
|
||||
p.SetFlair(Short.parseShort(text), true);
|
||||
return;
|
||||
case "unknown":
|
||||
try {
|
||||
if (CheckForJoinDate(p)) {
|
||||
if (text.equals("-1")) // If true, only non-presser/can't press; if false, any flair (but we can still detect can't press)
|
||||
p.SetFlair(ChatPlayer.FlairTimeNonPresser);
|
||||
else
|
||||
p.SetFlair(ChatPlayer.FlairTimeNone); // Flair unknown
|
||||
} else {
|
||||
p.SetFlair(ChatPlayer.FlairTimeCantPress);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
p.FlairState.set(FlairStates.Commented); // Flair unknown
|
||||
p.SetFlair(ChatPlayer.FlairTimeNone);
|
||||
TBMCCoreAPI.SendException("Error while checking join date for player " + p.getPlayerName() + "!", e, this);
|
||||
}
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
p.SetFlair(Short.parseShort(text));
|
||||
}
|
||||
|
||||
private static boolean CheckForJoinDate(ChatPlayer mp) throws Exception {
|
||||
return JoinedBefore(mp, 2015, 4, 1);
|
||||
}
|
||||
|
||||
private static boolean JoinedBefore(ChatPlayer mp, int year, int month, int day) throws Exception {
|
||||
/*URL url = new URL("https://www.reddit.com/u/" + mp.UserName());
|
||||
URLConnection con = url.openConnection();
|
||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||
InputStream in = con.getInputStream();
|
||||
HtmlCleaner cleaner = new HtmlCleaner();
|
||||
TagNode node = cleaner.clean(in);
|
||||
|
||||
node = node.getElementsByAttValue("class", "age", true, true)[0];
|
||||
node = node.getElementsByName("time", false)[0];
|
||||
String joindate = node.getAttributeByName("datetime");
|
||||
SimpleDateFormat parserSDF = new SimpleDateFormat("yyyy-MM-dd");
|
||||
joindate = joindate.split("T")[0];
|
||||
Date date = parserSDF.parse(joindate);
|
||||
return date.before(new Calendar.Builder().setTimeZone(TimeZone.getTimeZone("UTC")).setDate(year, month, day)
|
||||
.build().getTime());*/
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void ConfirmUserMessage(ChatPlayer mp) {
|
||||
Player p = Bukkit.getPlayer(mp.getUniqueId());
|
||||
if (mp.FlairState.get().equals(FlairStates.Commented) && p != null)
|
||||
if (mp.UserNames.get().size() > 1)
|
||||
p.sendMessage(
|
||||
"§9Multiple Reddit users commented your name. You can select with /u accept.§r §6Type /u accept or /u ignore§r");
|
||||
else
|
||||
p.sendMessage("§9A Reddit user commented your name. Is that you?§r §6Type /u accept or /u ignore§r");
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
package buttondevteam.chat;
|
||||
|
||||
public enum FlairStates {
|
||||
Accepted, Ignored, Recognised, Commented, NoComment
|
||||
}
|
||||
package buttondevteam.chat.components.flair;
|
||||
|
||||
public enum FlairStates {
|
||||
Accepted, Ignored, Recognised, Commented, NoComment
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package buttondevteam.chat.components.flair;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandClass(modOnly = false, helpText = {
|
||||
"Ignore flair",
|
||||
"Stop the \"write your name in the thread\" message from showing up"
|
||||
})
|
||||
public final class IgnoreCommand extends UCommandBase {
|
||||
@Command2.Subcommand
|
||||
public boolean def(Player player) {
|
||||
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
if (p.FlairState.get().equals(FlairStates.Accepted)) {
|
||||
player.sendMessage("§cYou can only ignore the \"write your name in the thread\" message.");
|
||||
return true;
|
||||
}
|
||||
if (p.FlairState.get().equals(FlairStates.Commented)) {
|
||||
player.sendMessage("Sorry, but your flair isn't recorded. Please ask a mod to set it for you.");
|
||||
return true;
|
||||
}
|
||||
if (!p.FlairState.get().equals(FlairStates.Ignored)) {
|
||||
p.FlairState.set(FlairStates.Ignored);
|
||||
p.SetFlair(ChatPlayer.FlairTimeNone);
|
||||
p.UserName.set("");
|
||||
player.sendMessage("§bYou have ignored the message.§r");
|
||||
} else
|
||||
player.sendMessage("§cYou already ignored the message.§r");
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package buttondevteam.chat.components.flair;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.commands.ucmds.admin.AdminCommandBase;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandClass(helpText = {
|
||||
"Set flair", "Set a flair for a player",
|
||||
"Usage: /u admin setflair <player> <flairtime (or non-presser, cant-press, none)> <cheater(true/false)> [username]",
|
||||
"Example 1: /u admin setflair NorbiPeti 19 false NorbiPeti --> orange (19s)",
|
||||
"Example 2: /u admin setflair iie 0 true asde --> purple (0s)"
|
||||
})
|
||||
public class SetFlairCommand extends AdminCommandBase {
|
||||
@Command2.Subcommand
|
||||
public boolean def(CommandSender sender, String player, String flairtime, boolean cheater, @Command2.OptionalArg String username) {
|
||||
Player p = Bukkit.getPlayer(player);
|
||||
if (p == null) {
|
||||
sender.sendMessage("§cPlayer not found.&r");
|
||||
return true;
|
||||
}
|
||||
short ft;
|
||||
if (flairtime.equalsIgnoreCase("non-presser"))
|
||||
ft = ChatPlayer.FlairTimeNonPresser;
|
||||
else if (flairtime.equalsIgnoreCase("cant-press"))
|
||||
ft = ChatPlayer.FlairTimeCantPress;
|
||||
else if (flairtime.equalsIgnoreCase("none"))
|
||||
ft = ChatPlayer.FlairTimeNone;
|
||||
else {
|
||||
try {
|
||||
ft = Short.parseShort(flairtime);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(
|
||||
"§cFlairtime must be a number, \"non-presser\", \"cant-press\" or \"none\". Run without args to see usage.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
ChatPlayer mp = TBMCPlayerBase.getPlayer(p.getUniqueId(), ChatPlayer.class);
|
||||
mp.SetFlair(ft, cheater);
|
||||
mp.FlairState.set(FlairStates.Accepted);
|
||||
if (username == null)
|
||||
mp.UserName.set("");
|
||||
else {
|
||||
mp.UserName.set(username);
|
||||
if (!mp.UserNames.get().contains(username))
|
||||
mp.UserNames.get().add(username);
|
||||
}
|
||||
sender.sendMessage("§bThe flair has been set. Player: " + mp.getPlayerName() + " Flair: " + mp.GetFormattedFlair() + "§r");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,318 @@
|
|||
package buttondevteam.chat.components.formatter;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.ChatUtils;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.VanillaUtils;
|
||||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||
import buttondevteam.chat.components.chatonly.ChatOnlyComponent;
|
||||
import buttondevteam.chat.components.formatter.formatting.*;
|
||||
import buttondevteam.chat.components.fun.FunComponent;
|
||||
import buttondevteam.chat.components.towny.TownyComponent;
|
||||
import buttondevteam.chat.listener.PlayerListener;
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.lib.ChromaUtils;
|
||||
import buttondevteam.lib.TBMCChatEvent;
|
||||
import buttondevteam.lib.TBMCChatEventBase;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.val;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.event.ClickEvent.suggestCommand;
|
||||
import static net.kyori.adventure.text.event.HoverEvent.Action.SHOW_TEXT;
|
||||
import static net.kyori.adventure.text.event.HoverEvent.hoverEvent;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.*;
|
||||
|
||||
public class ChatProcessing {
|
||||
private static final Pattern HASHTAG_PATTERN = Pattern.compile("#(\\w+)");
|
||||
private static final Pattern URL_PATTERN = Pattern.compile("(http[\\w:/?=$\\-_.+!*'(),&]+(?:#[\\w]+)?)");
|
||||
private static final Pattern MASKED_LINK_PATTERN = Pattern.compile("\\[([^\\[\\]]+)]\\(([^()]+)\\)");
|
||||
private static final NamedTextColor[] RainbowPresserColors = new NamedTextColor[]{RED, GOLD, YELLOW, GREEN,
|
||||
BLUE, DARK_PURPLE};
|
||||
private static final Pattern WORD_PATTERN = Pattern.compile("\\S+");
|
||||
private static final Pattern GREENTEXT_PATTERN = Pattern.compile("^>(?:.|\\s)*");
|
||||
private static boolean pingedconsole = false;
|
||||
|
||||
private static final ArrayList<MatchProviderBase> commonFormatters = Lists.newArrayList(
|
||||
new RangeMatchProvider("bold", "**", FormatSettings.builder().bold(true).build()),
|
||||
new RangeMatchProvider("italic", "*", FormatSettings.builder().italic(true).build()),
|
||||
new RangeMatchProvider("underlined", "__", FormatSettings.builder().underlined(true).build()),
|
||||
new RangeMatchProvider("italic2", "_", FormatSettings.builder().italic(true).build()),
|
||||
new RangeMatchProvider("strikethrough", "~~", FormatSettings.builder().strikethrough(true).build()),
|
||||
new RangeMatchProvider("spoiler", "||", FormatSettings.builder().obfuscated(true)
|
||||
.onmatch((match, cf, fs) -> {
|
||||
cf.setHoverText(match);
|
||||
return match;
|
||||
}).build()),
|
||||
new StringMatchProvider("nullMention", FormatSettings.builder().color(DARK_RED).build(), true, "null"), // Properly added a bug as a feature
|
||||
new StringMatchProvider("consolePing", FormatSettings.builder().color(AQUA)
|
||||
.onmatch((match, builder, section) -> {
|
||||
if (!pingedconsole) {
|
||||
System.out.print("\007");
|
||||
pingedconsole = true; // Will set it to false in ProcessChat
|
||||
}
|
||||
return "@console";
|
||||
}).build(), true, "@console"),
|
||||
|
||||
new StringMatchProvider("cyan", FormatSettings.builder().color(AQUA).build(), true, "cyan"), // #55
|
||||
new RangeMatchProvider("code", "`", FormatSettings.builder().color(DARK_GRAY).build()),
|
||||
new RegexMatchProvider("maskedLink", MASKED_LINK_PATTERN, FormatSettings.builder().underlined(true)
|
||||
.onmatch((match, builder, section) -> {
|
||||
String text, link;
|
||||
if (section.Matches.size() < 2 || (text = section.Matches.get(0)).length() == 0 || (link = section.Matches.get(1)).length() == 0)
|
||||
return "[MISSING LINK]"; //Doesn't actually happen, because of the regex
|
||||
builder.setOpenlink(link);
|
||||
return text;
|
||||
}).build()),
|
||||
new RegexMatchProvider("url", URL_PATTERN, FormatSettings.builder().underlined(true).openlink("$1").build()),
|
||||
new RegexMatchProvider("hashtag", HASHTAG_PATTERN, FormatSettings.builder().color(BLUE).openlink("https://twitter.com/hashtag/$1").build()),
|
||||
new StringMatchProvider("someone", FormatSettings.builder().color(AQUA)
|
||||
.onmatch((match, builder, section) -> {
|
||||
if (Bukkit.getOnlinePlayers().size() == 0) return match;
|
||||
var players = ImmutableList.copyOf(Bukkit.getOnlinePlayers());
|
||||
var playerC = new Random().nextInt(players.size());
|
||||
var player = players.get(playerC);
|
||||
playPingSound(player, ComponentManager.getIfEnabled(FormatterComponent.class));
|
||||
return "@someone (" + player.getDisplayName() + "§r)";
|
||||
}).build(), true, "@someone"),
|
||||
new RegexMatchProvider("greentext", GREENTEXT_PATTERN, FormatSettings.builder().color(GREEN).build()));
|
||||
private static final String[] testPlayers = {"Koiiev", "iie", "Alisolarflare", "NorbiPeti", "Arsen_Derby_FTW", "carrot_lynx"};
|
||||
|
||||
private ChatProcessing() {
|
||||
}
|
||||
|
||||
public static boolean ProcessChat(TBMCChatEvent e, FormatterComponent component) {
|
||||
Channel channel = e.getChannel();
|
||||
ChromaGamerBase cuser = e.getUser();
|
||||
String message = e.getMessage();
|
||||
long processstart = System.nanoTime();
|
||||
Player player = (cuser instanceof TBMCPlayerBase ? ((TBMCPlayerBase) cuser).getPlayer() : null);
|
||||
User user = PluginMain.essentials.getUser(player);
|
||||
|
||||
if (player != null && PluginMain.essentials.getSettings().cancelAfkOnInteract()) {
|
||||
user.updateActivity(true, AfkStatusChangeEvent.Cause.CHAT); //Could talk in a private channel, so broadcast
|
||||
if (user.isMuted())
|
||||
return true;
|
||||
}
|
||||
|
||||
ChatPlayer mp;
|
||||
if (player != null)
|
||||
mp = TBMCPlayerBase.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
else //Due to the online player map, getPlayer() can be more efficient than getAs()
|
||||
mp = e.getUser().getAs(ChatPlayer.class); //May be null
|
||||
|
||||
if (mp != null) {
|
||||
if (System.nanoTime() - mp.LastMessageTime < 1000L * 1000L * component.minTimeBetweenMessages.get()) { //0.1s by default
|
||||
cuser.sendMessage("§cYou are sending messages too quickly!");
|
||||
return true;
|
||||
}
|
||||
mp.LastMessageTime = System.nanoTime();
|
||||
}
|
||||
//DimensionManager.a()
|
||||
//IRegistry.ae
|
||||
//Bukkit.createWorld()
|
||||
//MinecraftServer.reload()
|
||||
//IRegistry
|
||||
//CraftServer
|
||||
|
||||
doFunStuff(cuser, e, message);
|
||||
|
||||
final String channelidentifier = getChannelID(channel, e.getOrigin());
|
||||
|
||||
PluginMain.Instance.getServer().getConsoleSender()
|
||||
.sendMessage(String.format("%s <%s§r> %s", channelidentifier, cuser.getName(), message));
|
||||
|
||||
if (Bukkit.getOnlinePlayers().size() == 0) return false; //Don't try to send to nobody (errors on 1.14)
|
||||
|
||||
TextColor colormode = NAMES.value(channel.color.get().getName());
|
||||
boolean colorModeChanged = false;
|
||||
if (mp != null && mp.OtherColorMode != null) {
|
||||
colormode = NAMES.value(mp.OtherColorMode.getName());
|
||||
colorModeChanged = true;
|
||||
}
|
||||
|
||||
ArrayList<MatchProviderBase> formatters;
|
||||
if (component.allowFormatting.get()) {
|
||||
formatters = addFormatters(sender -> e.shouldSendTo(ChromaGamerBase.getFromSender(sender)), component);
|
||||
if (colorModeChanged && mp.RainbowPresserColorMode) { // Only overwrite channel color
|
||||
createRPC(colormode, formatters);
|
||||
}
|
||||
pingedconsole = false; // Will set it to true onmatch (static constructor)
|
||||
} else
|
||||
formatters = Lists.newArrayList();
|
||||
|
||||
TextComponent.Builder builder = createEmptyMessageLine(cuser, message, player, channelidentifier, e.getOrigin());
|
||||
long combinetime = System.nanoTime();
|
||||
ChatFormatter.Combine(formatters, message, builder, component.getConfig(), FormatSettings.builder().color(colormode).build());
|
||||
combinetime = System.nanoTime() - combinetime;
|
||||
|
||||
try {
|
||||
if (!channel.isGlobal()) {
|
||||
String senderGroup = e.getGroupID(cuser);
|
||||
if (senderGroup == null) { // Never send messages if the group is null
|
||||
cuser.sendMessage("§cYou don't have permission to send this message or something went wrong");
|
||||
return true;
|
||||
}
|
||||
val tc = ComponentManager.getIfEnabled(TownyComponent.class);
|
||||
Consumer<Player> spyConsumer = null;
|
||||
if (tc != null)
|
||||
spyConsumer = tc.handleSpiesInit(channel, builder);
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
final String group;
|
||||
if (player != null
|
||||
&& PluginMain.essentials.getUser(p).isIgnoredPlayer(PluginMain.essentials.getUser(player)))
|
||||
group = null; // Don't send the message to them
|
||||
else
|
||||
group = VanillaUtils.getGroupIfChatOn(p, e);
|
||||
if (senderGroup.equals(group)) {
|
||||
p.sendMessage(builder.build());
|
||||
if (tc != null) spyConsumer.accept(p);
|
||||
}
|
||||
//Only sends if didn't send normally
|
||||
}
|
||||
} else
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
p.sendMessage(builder.build());
|
||||
} catch (Exception ex) {
|
||||
TBMCCoreAPI.SendException("An error occured while sending a chat message!", ex, PluginMain.Instance);
|
||||
cuser.sendMessage("§cAn error occured while sending the message.");
|
||||
return true;
|
||||
}
|
||||
DebugCommand.SendDebugMessage(
|
||||
"-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms");
|
||||
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms");
|
||||
return false;
|
||||
}
|
||||
|
||||
static void createRPC(TextColor colormode, ArrayList<MatchProviderBase> formatters) {
|
||||
final AtomicInteger rpc = new AtomicInteger(0);
|
||||
formatters.add(new RegexMatchProvider("rpc", WORD_PATTERN, FormatSettings.builder().color(colormode).onmatch((match, cf, s) -> {
|
||||
cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]);
|
||||
return match;
|
||||
}).build()));
|
||||
}
|
||||
|
||||
static TextComponent.Builder createEmptyMessageLine(ChromaGamerBase user, String message, @Nullable Player player,
|
||||
final String channelidentifier, String origin) {
|
||||
val json = text();
|
||||
ChatOnlyComponent.tellrawCreate(user.getAs(ChatPlayer.class), json);
|
||||
val channelHover = (ChatUtils.MCORIGIN.equals(origin) ? "" : "From " + origin + "\n") + "Copy message";
|
||||
json.append(text(channelidentifier)
|
||||
.hoverEvent(hoverEvent(SHOW_TEXT, text(channelHover).color(BLUE))).clickEvent(suggestCommand(message)));
|
||||
if (player != null) {
|
||||
if (PluginMain.permission.has(player, "tbmc.badge.diamond")) // TODO: Cross-platform permissions
|
||||
json.append(text("[P]").color(AQUA).decorate(TextDecoration.BOLD)
|
||||
.hoverEvent(hoverEvent(SHOW_TEXT, text("Diamond Patreon supporter"))));
|
||||
else if (PluginMain.permission.has(player, "tbmc.badge.gold"))
|
||||
json.append(text("[P]").color(GOLD).decorate(TextDecoration.BOLD)
|
||||
.hoverEvent(hoverEvent(SHOW_TEXT, text("Gold Patreon supporter"))));
|
||||
}
|
||||
json.append(text(" <"));
|
||||
json.append(text(user.getName()).hoverEvent(hoverEvent(SHOW_TEXT, text(user.getInfo(ChromaGamerBase.InfoTarget.MCHover)))));
|
||||
json.append(text("> "));
|
||||
return json;
|
||||
}
|
||||
|
||||
static String getChannelID(Channel channel, String origin) {
|
||||
return ("[" + (ChatUtils.MCORIGIN.equals(origin) ? "" : "§8" + origin.charAt(0) + "§r|") + channel.displayName.get())
|
||||
+ "]";
|
||||
}
|
||||
|
||||
static ArrayList<MatchProviderBase> addFormatters(Predicate<Player> canSee, @Nullable FormatterComponent component) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ArrayList<MatchProviderBase> formatters = (ArrayList<MatchProviderBase>) commonFormatters.clone();
|
||||
|
||||
boolean nottest; //Not assigning a default value, so that it can only be used in the if
|
||||
if ((nottest = Bukkit.getOnlinePlayers().size() > 0) || ChromaUtils.isTest()) {
|
||||
String[] names;
|
||||
if (nottest)
|
||||
names = Bukkit.getOnlinePlayers().stream().filter(canSee).map(CommandSender::getName).toArray(String[]::new);
|
||||
else {
|
||||
names = new String[testPlayers.length];
|
||||
System.arraycopy(testPlayers, 0, names, 0, testPlayers.length);
|
||||
}
|
||||
String[] nicknames = Bukkit.getOnlinePlayers().stream().filter(canSee).map(Player::getUniqueId).map(PlayerListener.nicknames.inverse()::get)
|
||||
.filter(Objects::nonNull).toArray(String[]::new);
|
||||
|
||||
Consumer<String> error = message -> {
|
||||
if (PluginMain.Instance != null)
|
||||
PluginMain.Instance.getLogger().warning(message);
|
||||
else
|
||||
System.out.println(message);
|
||||
};
|
||||
|
||||
if (names.length > 0) //Add as first so it handles special characters (_) - though the order of the different types are defined
|
||||
formatters.add(0, new StringMatchProvider("name", FormatSettings.builder().color(AQUA)
|
||||
.onmatch((match, builder, section) -> {
|
||||
Player p = Bukkit.getPlayer(match);
|
||||
Optional<String> pn = nottest ? Optional.empty()
|
||||
: Arrays.stream(testPlayers).filter(tp -> tp.equalsIgnoreCase(match)).findAny();
|
||||
if (nottest ? p == null : pn.isEmpty()) {
|
||||
error.accept("Error: Can't find player " + match + " but was reported as online.");
|
||||
return "§c" + match + "§r";
|
||||
}
|
||||
ChatPlayer mpp = TBMCPlayer.getPlayer(nottest ? p.getUniqueId() : new UUID(0, 0), ChatPlayer.class);
|
||||
if (nottest) {
|
||||
playPingSound(p, component);
|
||||
}
|
||||
String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor()));
|
||||
return color + (nottest ? p.getName() : pn.get()) + "§r"; //Fix name casing, except when testing
|
||||
}).build(), true, names));
|
||||
|
||||
if (nicknames.length > 0) //Add as first so it handles special characters
|
||||
formatters.add(0, new StringMatchProvider("nickname", FormatSettings.builder().color(AQUA)
|
||||
.onmatch((match, builder, section) -> {
|
||||
if (PlayerListener.nicknames.containsKey(match.toLowerCase())) { //Made a stream and all that but I can actually store it lowercased
|
||||
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match.toLowerCase()));
|
||||
if (p == null) {
|
||||
error.accept("Error: Can't find player nicknamed "
|
||||
+ match.toLowerCase() + " but was reported as online.");
|
||||
return "§c" + match + "§r";
|
||||
}
|
||||
playPingSound(p, component);
|
||||
return PluginMain.essentials.getUser(p).getNickname();
|
||||
}
|
||||
error.accept("Player nicknamed " + match.toLowerCase()
|
||||
+ " not found in nickname map but was reported as online.");
|
||||
return "§c" + match + "§r";
|
||||
}).build(), true, nicknames));
|
||||
}
|
||||
return formatters;
|
||||
}
|
||||
|
||||
private static void playPingSound(Player p, @Nullable FormatterComponent component) {
|
||||
if (component == null || component.notificationSound.get().length() == 0)
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn
|
||||
else
|
||||
p.playSound(p.getLocation(), component.notificationSound.get(), 1.0f,
|
||||
component.notificationPitch.get());
|
||||
}
|
||||
|
||||
static void doFunStuff(ChromaGamerBase user, TBMCChatEventBase event, String message) {
|
||||
val fc = ComponentManager.getIfEnabled(FunComponent.class);
|
||||
if (fc != null) fc.onChat(user, event, message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package buttondevteam.chat.components.formatter;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.core.MainPlugin;
|
||||
import buttondevteam.lib.TBMCChatEvent;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.config.IConfigData;
|
||||
|
||||
/**
|
||||
* This component handles the custom processing of chat messages. If this component is disabled channels won't be supported in Minecraft.
|
||||
* If you only want to disable the formatting features, set allowFormatting to false.
|
||||
* If you're using another chat plugin, you should disable the whole component but that will make it impossible to use channels.
|
||||
*/
|
||||
public class FormatterComponent extends Component<PluginMain> {
|
||||
/**
|
||||
* Determines whether Markdown formatting, name mentioning and similar features are enabled.
|
||||
*/
|
||||
IConfigData<Boolean> allowFormatting = getConfig().getData("allowFormatting", true);
|
||||
|
||||
/**
|
||||
* The sound to play when a player is mentioned. Leave empty to use default.
|
||||
*/
|
||||
public IConfigData<String> notificationSound = getConfig().getData("notificationSound", "");
|
||||
|
||||
/**
|
||||
* The pitch of the notification sound.
|
||||
*/
|
||||
public IConfigData<Float> notificationPitch = getConfig().getData("notificationPitch", 1.0f);
|
||||
|
||||
/**
|
||||
* The minimum time between messages in milliseconds.
|
||||
*/
|
||||
public IConfigData<Integer> minTimeBetweenMessages = getConfig().getData("minTimeBetweenMessages", 100);
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
MainPlugin.getInstance().setChatHandlerEnabled(false); //Disable Core chat handler - if this component is disabled then let it do its job
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
MainPlugin.getInstance().setChatHandlerEnabled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the chat if the component is enabled.
|
||||
*
|
||||
* @param event The chat event
|
||||
* @return Whether the chat message shouldn't be sent for some reason
|
||||
*/
|
||||
public static boolean handleChat(TBMCChatEvent event) {
|
||||
FormatterComponent component = ComponentManager.getIfEnabled(FormatterComponent.class);
|
||||
if (component == null) return false;
|
||||
return ChatProcessing.ProcessChat(event, component);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package buttondevteam.chat.components.formatter.formatting;
|
||||
|
||||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class ChatFormatUtils {
|
||||
private ChatFormatUtils() {}
|
||||
|
||||
static void sendMessageWithPointer(String str, int... pointer) {
|
||||
DebugCommand.SendDebugMessage(str);
|
||||
StringBuilder sb = new StringBuilder(str.length());
|
||||
Arrays.sort(pointer);
|
||||
for (int i = 0; i < pointer.length; i++) {
|
||||
for (int j = 0; j < pointer[i] - (i > 0 ? pointer[i - 1] + 1 : 0); j++)
|
||||
sb.append(' ');
|
||||
if (pointer[i] == (i > 0 ? pointer[i - 1] : -1))
|
||||
continue;
|
||||
sb.append('^');
|
||||
}
|
||||
DebugCommand.SendDebugMessage(sb.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given start and end position is inside any of the ranges
|
||||
*/
|
||||
static boolean isInRange(int start, int end, ArrayList<int[]> ranges) {
|
||||
return ranges.stream().anyMatch(range -> range[1] >= start && range[0] <= end);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,264 @@
|
|||
package buttondevteam.chat.components.formatter.formatting;
|
||||
|
||||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||
import buttondevteam.lib.architecture.IHaveConfig;
|
||||
import lombok.val;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.event.ClickEvent.Action.OPEN_URL;
|
||||
import static net.kyori.adventure.text.event.ClickEvent.clickEvent;
|
||||
import static net.kyori.adventure.text.event.HoverEvent.Action.SHOW_TEXT;
|
||||
import static net.kyori.adventure.text.event.HoverEvent.hoverEvent;
|
||||
|
||||
/**
|
||||
* A {@link MatchProvider} finds where the given {@link FormatSettings} need to be applied. {@link ChatFormatter#Combine(List, String, TextComponent.Builder, IHaveConfig, FormatSettings)}} is used to turn it into a {@link TellrawPart}, combining
|
||||
* intersecting parts found, for example when {@code _abc*def*ghi_} is said in chat, it'll turn it into an underlined part, then an underlined <i>and italics</i> part, finally an underlined part
|
||||
* again.
|
||||
*
|
||||
* @author NorbiPeti
|
||||
*/
|
||||
public final class ChatFormatter {
|
||||
private ChatFormatter() {
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TriFunc<T1, T2, T3, R> {
|
||||
R apply(T1 x1, T2 x2, T3 x3);
|
||||
}
|
||||
|
||||
//synchronized: Some of the formatters are reused, see createSections(...)
|
||||
public static synchronized void Combine(List<MatchProviderBase> formatters, String str, TextComponent.Builder tp, IHaveConfig config, FormatSettings defaults) {
|
||||
/*
|
||||
* A global formatter is no longer needed
|
||||
*/
|
||||
header("ChatFormatter.Combine begin");
|
||||
ArrayList<FormattedSection> sections = new ArrayList<>();
|
||||
|
||||
if (config != null) //null if testing
|
||||
formatters.removeIf(cf -> !cf.enabled(config).get()); //Remove disabled formatters
|
||||
var excluded = new ArrayList<int[]>();
|
||||
/*
|
||||
* 0: Start - 1: End index
|
||||
*/
|
||||
val remchars = new ArrayList<int[]>();
|
||||
|
||||
escapeThings(str, excluded, remchars);
|
||||
|
||||
sections.add(new FormattedSection(defaults, 0, str.length() - 1, Collections.emptyList())); //Add entire message
|
||||
var providers = formatters.stream().filter(mp -> mp instanceof RegexMatchProvider).collect(Collectors.toList());
|
||||
createSections(providers, str, sections, excluded, remchars);
|
||||
providers = formatters.stream().filter(mp -> mp instanceof StringMatchProvider).collect(Collectors.toList());
|
||||
createSections(providers, str, sections, excluded, remchars);
|
||||
providers = formatters.stream().filter(mp -> mp instanceof RangeMatchProvider).collect(Collectors.toList());
|
||||
createSections(providers, str, sections, excluded, remchars);
|
||||
sortSections(sections);
|
||||
|
||||
header("Section combining");
|
||||
combineSections(str, sections);
|
||||
|
||||
header("Section applying");
|
||||
applySections(str, tp, sections, remchars);
|
||||
header("ChatFormatter.Combine done");
|
||||
}
|
||||
|
||||
private static void escapeThings(String str, ArrayList<int[]> ignoredAreas, ArrayList<int[]> remchars) {
|
||||
boolean escaped = false;
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
if (str.charAt(i) == '\\') {
|
||||
remchars.add(new int[]{i, i});
|
||||
ignoredAreas.add(new int[]{i + 1, i + 1});
|
||||
i++; //Ignore a potential second slash
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void createSections(List<MatchProviderBase> formatters, String str, ArrayList<FormattedSection> sections,
|
||||
ArrayList<int[]> excludedAreas, ArrayList<int[]> removedCharacters) {
|
||||
formatters.forEach(MatchProviderBase::reset); //Reset state information, as we aren't doing deep cloning
|
||||
while (formatters.size() > 0) {
|
||||
for (var iterator = formatters.iterator(); iterator.hasNext(); ) {
|
||||
MatchProviderBase formatter = iterator.next();
|
||||
DebugCommand.SendDebugMessage("Checking provider: " + formatter);
|
||||
var sect = formatter.getNextSection(str, excludedAreas, removedCharacters);
|
||||
if (sect != null) //Not excluding the area here because the range matcher shouldn't take it all
|
||||
sections.add(sect);
|
||||
if (formatter.isFinished()) {
|
||||
DebugCommand.SendDebugMessage("Provider finished");
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void combineSections(String str, ArrayList<FormattedSection> sections) {
|
||||
for (int i = 1; i < sections.size(); i++) {
|
||||
DebugCommand.SendDebugMessage("i: " + i);
|
||||
final FormattedSection firstSection;
|
||||
final FormattedSection lastSection;
|
||||
{
|
||||
FormattedSection firstSect = sections.get(i - 1);
|
||||
FormattedSection lastSect = sections.get(i);
|
||||
if (firstSect.Start > lastSect.Start //The first can't start later
|
||||
|| (firstSect.Start == lastSect.Start && firstSect.End < lastSect.End)) {
|
||||
var section = firstSect;
|
||||
firstSect = lastSect;
|
||||
lastSect = section;
|
||||
}
|
||||
firstSection = firstSect;
|
||||
lastSection = lastSect;
|
||||
}
|
||||
DebugCommand.SendDebugMessage("Combining sections " + firstSection);
|
||||
ChatFormatUtils.sendMessageWithPointer(str, firstSection.Start, firstSection.End);
|
||||
DebugCommand.SendDebugMessage(" and " + lastSection);
|
||||
ChatFormatUtils.sendMessageWithPointer(str, lastSection.Start, lastSection.End);
|
||||
if (firstSection.Start == lastSection.Start && firstSection.End == lastSection.End) {
|
||||
firstSection.Settings.copyFrom(lastSection.Settings);
|
||||
firstSection.Matches.addAll(lastSection.Matches);
|
||||
DebugCommand.SendDebugMessage("To section " + firstSection);
|
||||
ChatFormatUtils.sendMessageWithPointer(str, firstSection.Start, firstSection.End);
|
||||
sections.remove(i);
|
||||
i = 0;
|
||||
sortSections(sections);
|
||||
continue;
|
||||
} else if (firstSection.End >= lastSection.Start && firstSection.Start <= lastSection.End) {
|
||||
int middleStart = lastSection.Start;
|
||||
// |----|-- |------|
|
||||
// --|----| -|----|-
|
||||
int middleEnd = Math.min(lastSection.End, firstSection.End);
|
||||
int lastSectEnd = Math.max(lastSection.End, firstSection.End);
|
||||
FormattedSection section = new FormattedSection(firstSection.Settings, middleStart, middleEnd,
|
||||
firstSection.Matches);
|
||||
section.Settings.copyFrom(lastSection.Settings);
|
||||
section.Matches.addAll(lastSection.Matches);
|
||||
sections.add(i, section);
|
||||
|
||||
if (firstSection.End > lastSection.End) { //Copy first section info to last as the lastSection initially cuts the firstSection in half
|
||||
lastSection.Settings = FormatSettings.builder().build();
|
||||
lastSection.Settings.copyFrom(firstSection.Settings);
|
||||
}
|
||||
|
||||
firstSection.End = middleStart - 1;
|
||||
lastSection.Start = middleEnd + 1;
|
||||
lastSection.End = lastSectEnd;
|
||||
|
||||
Predicate<FormattedSection> removeIfNeeded = s -> {
|
||||
if (s.Start < 0 || s.End < 0 || s.Start > s.End) {
|
||||
DebugCommand.SendDebugMessage(" Removed: " + s);
|
||||
ChatFormatUtils.sendMessageWithPointer(str, s.Start, s.End);
|
||||
sections.remove(s);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
DebugCommand.SendDebugMessage("To sections");
|
||||
if (!removeIfNeeded.test(firstSection)) {
|
||||
DebugCommand.SendDebugMessage(" 1:" + firstSection);
|
||||
ChatFormatUtils.sendMessageWithPointer(str, firstSection.Start, firstSection.End);
|
||||
}
|
||||
if (!removeIfNeeded.test(section)) {
|
||||
DebugCommand.SendDebugMessage(" 2:" + section);
|
||||
ChatFormatUtils.sendMessageWithPointer(str, section.Start, section.End);
|
||||
}
|
||||
if (!removeIfNeeded.test(lastSection)) {
|
||||
DebugCommand.SendDebugMessage(" 3:" + lastSection);
|
||||
ChatFormatUtils.sendMessageWithPointer(str, lastSection.Start, lastSection.End);
|
||||
}
|
||||
i = 0;
|
||||
}
|
||||
sortSections(sections);
|
||||
}
|
||||
}
|
||||
|
||||
private static void applySections(String str, TextComponent.Builder tp, ArrayList<FormattedSection> sections, ArrayList<int[]> remchars) {
|
||||
TextComponent lasttp = null;
|
||||
String lastlink = null;
|
||||
for (FormattedSection section : sections) {
|
||||
DebugCommand.SendDebugMessage("Applying section: " + section);
|
||||
String originaltext;
|
||||
int start = section.Start, end = section.End;
|
||||
DebugCommand.SendDebugMessage("Start: " + start + " - End: " + end);
|
||||
ChatFormatUtils.sendMessageWithPointer(str, start, end);
|
||||
val rci = remchars.stream().filter(rc -> (rc[0] <= start && rc[1] >= start)
|
||||
|| (rc[0] >= start && rc[1] <= end)
|
||||
|| (rc[0] <= end && rc[1] >= end)).sorted(Comparator.comparingInt(rc -> rc[0] * 10000 + rc[1])).toArray(int[][]::new);
|
||||
DebugCommand.SendDebugMessage("Applying RC: " + Arrays.stream(rci).map(Arrays::toString).collect(Collectors.joining(", ", "[", "]")));
|
||||
originaltext = str.substring(start, end + 1);
|
||||
val sb = new StringBuilder(originaltext);
|
||||
for (int x = rci.length - 1; x >= 0; x--)
|
||||
sb.delete(Math.max(rci[x][0] - start, 0), Math.min(rci[x][1] - start, end) + 1); //Delete going backwards
|
||||
originaltext = sb.toString();
|
||||
if (originaltext.length() == 0) {
|
||||
DebugCommand.SendDebugMessage("Skipping section because of remchars");
|
||||
continue;
|
||||
}
|
||||
DebugCommand.SendDebugMessage("Section text: " + originaltext);
|
||||
String openlink = null;
|
||||
var settings = section.Settings;
|
||||
DebugCommand.SendDebugMessage("Applying settings: " + settings);
|
||||
if (lasttp != null && hasSameDecorations(lasttp, settings) && Objects.equals(lastlink, settings.openlink)
|
||||
&& settings.onmatch == null) { // The onmatch function can change the settings
|
||||
DebugCommand.SendDebugMessage("This part has the same properties as the previous one, combining.");
|
||||
lasttp = lasttp.content(lasttp.content() + originaltext);
|
||||
continue; //Combine parts with the same properties
|
||||
}
|
||||
TextComponent.@NotNull Builder newtp = text();
|
||||
if (settings.onmatch != null)
|
||||
originaltext = settings.onmatch.apply(originaltext, settings, section);
|
||||
if (settings.color != null)
|
||||
newtp.color(settings.color);
|
||||
if (settings.bold)
|
||||
newtp.decorate(TextDecoration.BOLD);
|
||||
if (settings.italic)
|
||||
newtp.decorate(TextDecoration.ITALIC);
|
||||
if (settings.underlined)
|
||||
newtp.decorate(TextDecoration.UNDERLINED);
|
||||
if (settings.strikethrough)
|
||||
newtp.decorate(TextDecoration.STRIKETHROUGH);
|
||||
if (settings.obfuscated)
|
||||
newtp.decorate(TextDecoration.OBFUSCATED);
|
||||
if (settings.openlink != null)
|
||||
openlink = settings.openlink;
|
||||
if (settings.hoverText != null)
|
||||
newtp.hoverEvent(hoverEvent(SHOW_TEXT, text(settings.hoverText)));
|
||||
if (lasttp != null) tp.append(lasttp);
|
||||
lastlink = openlink;
|
||||
newtp.content(originaltext);
|
||||
if (openlink != null && openlink.length() > 0) {
|
||||
if (section.Matches.size() > 0)
|
||||
openlink = openlink.replace("$1", section.Matches.get(0));
|
||||
newtp.clickEvent(clickEvent(OPEN_URL, openlink)).hoverEvent(hoverEvent(SHOW_TEXT, text("Click to open").color(NamedTextColor.BLUE)));
|
||||
}
|
||||
lasttp = newtp.build();
|
||||
}
|
||||
if (lasttp != null) tp.append(lasttp);
|
||||
}
|
||||
|
||||
private static boolean hasSameDecorations(TextComponent c1, FormatSettings settings) {
|
||||
return Objects.equals(c1.color(), settings.color)
|
||||
&& c1.hasDecoration(TextDecoration.BOLD) == settings.bold
|
||||
&& c1.hasDecoration(TextDecoration.ITALIC) == settings.italic
|
||||
&& c1.hasDecoration(TextDecoration.UNDERLINED) == settings.underlined
|
||||
&& c1.hasDecoration(TextDecoration.STRIKETHROUGH) == settings.strikethrough
|
||||
&& c1.hasDecoration(TextDecoration.OBFUSCATED) == settings.obfuscated;
|
||||
}
|
||||
|
||||
private static void sortSections(ArrayList<FormattedSection> sections) {
|
||||
sections.sort(
|
||||
(s1, s2) -> s1.Start == s2.Start
|
||||
? s1.End == s2.End ? 0 : Integer.compare(s1.End, s2.End)
|
||||
: Integer.compare(s1.Start, s2.Start));
|
||||
}
|
||||
|
||||
private static void header(String message) {
|
||||
DebugCommand.SendDebugMessage("\n--------\n" + message + "\n--------\n");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package buttondevteam.chat.components.formatter.formatting;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
/**
|
||||
* Describes how a matched section of the message should look. May be combined with other format settings.
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class FormatSettings {
|
||||
boolean italic;
|
||||
boolean bold;
|
||||
boolean underlined;
|
||||
boolean strikethrough;
|
||||
boolean obfuscated;
|
||||
TextColor color;
|
||||
ChatFormatter.TriFunc<String, FormatSettings, FormattedSection, String> onmatch;
|
||||
String openlink;
|
||||
String hoverText;
|
||||
|
||||
public void copyFrom(FormatSettings settings) {
|
||||
try {
|
||||
for (var field : FormatSettings.class.getDeclaredFields()) {
|
||||
if (field.getType() == boolean.class) {
|
||||
if (field.getBoolean(settings))
|
||||
field.setBoolean(this, true); //Set to true if either of them are true
|
||||
} else if (field.get(settings) != null) {
|
||||
field.set(this, field.get(settings));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package buttondevteam.chat.components.formatter.formatting;
|
||||
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ToString
|
||||
public class FormattedSection {
|
||||
public int Start;
|
||||
public int End;
|
||||
public FormatSettings Settings;
|
||||
public List<String> Matches = new ArrayList<>();
|
||||
|
||||
FormattedSection(FormatSettings settings, int start, int end, List<String> matches) {
|
||||
Start = start;
|
||||
End = end;
|
||||
Settings = FormatSettings.builder().build();
|
||||
Settings.copyFrom(settings);
|
||||
Matches.addAll(matches);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package buttondevteam.chat.components.formatter.formatting;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Attempts to find a match for the provided message, returning null if none was found.
|
||||
*/
|
||||
public interface MatchProvider {
|
||||
@Nullable
|
||||
FormattedSection getNextSection(String message, ArrayList<int[]> ignoredAreas, ArrayList<int[]> removedCharacters);
|
||||
|
||||
boolean isFinished();
|
||||
|
||||
String getName();
|
||||
|
||||
@Override
|
||||
String toString();
|
||||
|
||||
void reset();
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package buttondevteam.chat.components.formatter.formatting;
|
||||
|
||||
import buttondevteam.lib.architecture.IHaveConfig;
|
||||
import buttondevteam.lib.architecture.config.IConfigData;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public abstract class MatchProviderBase implements MatchProvider {
|
||||
@Getter
|
||||
protected boolean finished;
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public abstract FormattedSection getNextSection(String message, ArrayList<int[]> ignoredAreas, ArrayList<int[]> removedCharacters);
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
protected abstract void resetSubclass();
|
||||
|
||||
public void reset() {
|
||||
finished = false;
|
||||
resetSubclass();
|
||||
}
|
||||
|
||||
IConfigData<Boolean> enabled(IHaveConfig config) {
|
||||
return config.getData(name + ".enabled", true);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package buttondevteam.chat.components.formatter.formatting;
|
||||
|
||||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
public class RangeMatchProvider extends MatchProviderBase {
|
||||
private final String pattern;
|
||||
@ToString.Exclude
|
||||
private final FormatSettings settings;
|
||||
private int nextIndex = 0;
|
||||
private FormattedSection startedSection;
|
||||
|
||||
public RangeMatchProvider(String name, String pattern, FormatSettings settings) {
|
||||
super(name);
|
||||
this.pattern = pattern;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormattedSection getNextSection(String message, ArrayList<int[]> ignoredAreas, ArrayList<int[]> removedCharacters) {
|
||||
int i, len;
|
||||
i = message.indexOf(pattern, nextIndex);
|
||||
len = pattern.length();
|
||||
nextIndex = i + len; //Set for the next method call
|
||||
if (i == -1) {
|
||||
finished = true; //Won't find any more - unfinished sections will be garbage collected
|
||||
return null;
|
||||
}
|
||||
if (ChatFormatUtils.isInRange(i, i + len - 1, ignoredAreas)) {
|
||||
DebugCommand.SendDebugMessage("Range start is in ignored area, skipping");
|
||||
return null; //Not setting finished to true, so it will go to the next match
|
||||
}
|
||||
ignoredAreas.add(new int[]{i, i + len - 1});
|
||||
if (startedSection == null) {
|
||||
DebugCommand.SendDebugMessage("Started range match from " + i + " to " + (i + len - 1));
|
||||
DebugCommand.SendDebugMessage("With settings: " + settings);
|
||||
ChatFormatUtils.sendMessageWithPointer(message, i, i + len - 1);
|
||||
startedSection = new FormattedSection(settings, i, i + len - 1, Collections.emptyList());
|
||||
return null;
|
||||
} else {
|
||||
var section = startedSection;
|
||||
DebugCommand.SendDebugMessage("Finished range match from " + section.Start + " to " + (i + len - 1));
|
||||
DebugCommand.SendDebugMessage("With settings: " + settings);
|
||||
ChatFormatUtils.sendMessageWithPointer(message, section.Start, i + len - 1);
|
||||
section.End = i + len - 1;
|
||||
removedCharacters.add(new int[]{section.Start, section.Start + len - 1});
|
||||
removedCharacters.add(new int[]{i, i + len - 1});
|
||||
startedSection = null; //Reset so next find creates a new one
|
||||
return section;
|
||||
}
|
||||
}
|
||||